PDA

View Full Version : Dumb question - changing an object's material at a given frame


amv256
06-03-2008, 03:22 AM
This sounds so simple but as always, the reference is a mess and I can't find exactly what I need with the CGtalk search.

What I want is VERY simple: to assign a material to an object at frame X, then assign a new material to that object at frame Y.

I've tried the following:


animate on
(
at time X obj.material = wood
at time Y obj.material = metal
)


The problem is, this approach doesn't apparently work with keyframes. I can set any material property this way, but the material itself can't seem to change on a per-frame basis (it simply changes for all frames).

One solution is to use the Material Modifier and put all of my materials into a multi/sub-object, then keyframe the ID property. But this is so much extra work for something that should be easy.

Summary: Is there or is there not a way to simply change an object's entire material from one to another, on a given keyframe?

Thanks!

Bobo
06-03-2008, 03:44 AM
Most node properties are not animatable (keyframeable), like Hidden/Frozen state, Renderable property, material property and so on. This is how Max works, MAXScript just gives you access to what Max does internally.

The Material ID approach would be a possibility if your object does not depend on multiple IDs already.

Animating a Blend Material between 0 and 100% blend to switch between two sub-materials is also a possibility. Just make sure that your keys are set to Step tangent type so the switching is instantenuous and does not blend.

amv256
06-03-2008, 04:12 AM
That's all I needed to know. Thanks Bobo!

shibumenon
06-03-2008, 10:50 AM
You could also create a preRender callback function as per your requirement, and add it to the callbacks:

callbacks.addScript #preRender "myMaterialChangeCallbackFn()" id:#changeMat

Note: Will work only during rendering

LoneRobot
06-03-2008, 11:43 AM
you could set up a multi-sub object with your materials and then use a Material modifier on the object. Then you can use any controller you like to animate the material ID of the object and swap this at certain times. I have done the same to enable a flat object with multiple tween materials be controlled by a CA slider.

PEN
06-03-2008, 01:59 PM
The material modifier system works well to a point. If you have a lot of materials and you need to see them in the viewport for animation purposes then it will get very slow as showing the multisub is not just trying to show the one map that is currently being used but all of them. To get around this I used a scripted material that switches the materials on the fly, either by streaming them off the drive or loading them all into memory.

LoneRobot
06-03-2008, 02:15 PM
Hi Paul,

that makes sense. I have set this up with a few materials and hadn't noticed the slowdown. It is something to bear in mind though, thanks. when you say scripted material, do you mean you build it on the fly and load any textures when it is defined?

CGTalk Moderation
06-03-2008, 02:15 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.