- Home /
Bringing visibilty and material animation from Max to Unity
I have been researching this throughout the past week or so and haven't been able to find much useful out there. I was hoping someone might have written a script on the Max or Unity side to do this but haven't found one so far.
That being said I am eager to try to tackle this with my pathetically novice coding skills, but I don't even know where to start. So I was hoping someone might be able to point me in the right direction.
Specifically I am looking for a way to take keyframed diffuse and visibility animation (weather it's shader opacity or object visibility) and translate that to renderer.material.color and renderer.material.color.a or renderer.enabled animations in Unity.
I know enough to work out how to recreate these animations in Unity, however I will potentially be dealing with a large volume of these kinds of animations and recreating them all by hand will not be feasible.
So... Can anyone help me with where to start? First off is this not something I would do on the Unity side at all, should I be looking into writing a Max script? If this can be done on the unity side, I am guessing that I need to acccess the code within the fbx on import and translate the embeded animation from autodesk terms to Unity terms. If so where might I be able to learn more about that?
Sorry for the long winded question. I would appreciate any help anyone could give in pointing me in the right direction.
Answer by Baroque · Mar 02, 2014 at 04:29 AM
As far as I know, there's no way for Unity to directly use imported animation channels from e.g. FBX files for things other than transformation (rotation, position, scale) and for blend shapes. However, there are a few ways you could do it ranging from kinda easy to crazy complicated.
Probably the easiest way is to add some extra joints to your animation rig that aren't weighted to any vertices. You can then use the x,y,z position to animate different parameters. In Max, you can drive the position of the joint from your material properties using **wire parameters**. (I'm more familiar with Maya, where they're called Driven Keys). Call the joint something like MaterialDriver.
Once you import the animation into Unity you'll have these extra joints moving around in your character. Then you write a super simple script in Unity that takes those transform positions and drives the corresponding property in the material. Something like:
public class MaterialDriver : MonoBehaviour
{
Transform MaterialDriver;
void Update()
{
// Get the current color
Color materialColor = renderer.material.color;
// Set the alpha of the material from the local (animated) x position of the transform
materialColor.a = MaterialDriver.localPosition.x;
// Set the new color
renderer.material.color = materialColor;
}
}
Add this Component to the object you're animating and set its MaterialDriver
to the MaterialDriver child object. Assuming you've exported the animation correctly so that its scale and axes are consistent with Unity, you'll get animated materials.
Actually rereading what you wrote, this might work. I just need to figure out how to use max script to create all the joints and connects the wire parameters. There are a lot of objects in the scene and doing it manually would take too much time. Thanks again for the suggestion.
Answer by kamullis · Mar 03, 2014 at 03:57 PM
Thanks for the response Baroque. That's a really clever work around! I will keep that in mind for other circumstance. Unfortunately that won't work for what I need the animation isn't actually created in Max. The animations are created in a construction scheduling software called Synchro, with which I am not super familiar. However, when I bring the animations into Max all the material and visibility animation is retained in the fbx from Synchro. I am asking about 3ds max because that is what I generally work with and I know that I can get the animations into Max without having to deal with Synchro.
So I love your work around, but won't work in this instance. I will really need a way to actually script an exporter in Max or an importer in Unity. I am not interested in getting to in depth into Sychro.
Answer by edfreeform3d · Jul 10, 2017 at 10:14 AM
Sorry to bring up an old thread, I was wondering if you got anywhere with this kamullis?
I am also trying to bring 4d models from synchro into unity.
Thanks,
i coded a plugin in to take color change, appearance on!= off ect from synchro into unity, using the Xml from the FBX export. works well i also got the cutting plane to work from synchro.
Dear limaoscar, i'll be glad to know more about the way you did this plug-in. I'm also working with Synchro and i was wondering on exporting my synchro animation into unity to get a better animation. I'm thinking of using the X$$anonymous$$L file, but i'm not so sure about the parsing method to use in unity.