animate material question

animate material question

Anonymous
Not applicable
3,513 Views
41 Replies
Message 1 of 42

animate material question

Anonymous
Not applicable

I have 18 keyframes and 18 materials

What would be the best method to assign each to there respective keyframes?

I would be ideal if it could be accomplished like this.

 

0 Likes
Accepted solutions (4)
3,514 Views
41 Replies
Replies (41)
Message 2 of 42

leeminardi
Mentor
Mentor

You could use a script something like the following in which material 1 is assigned to cylinder001 for frames 0 through 10, material 3 frames 11 through 15, and material 2 thereafter.

 

fn time_p  = 
(select $Cylinder001
	(if sliderTime >= 0f do
	$.material = meditMaterials[1]	
	)
	(if sliderTime > 10f do
	$.material = meditMaterials[3]	
	)
	(if sliderTime > 15f do
	$.material = meditMaterials[2]	
	)
)
registerTimeCallback time_p

~Lee

lee.minardi
0 Likes
Message 3 of 42

RGhost77
Advisor
Advisor
Accepted solution

If you have identical 18 materials with different bitmaps, will be easiest way to use this workflow:

1. Use only one material

2. Make .ifl with all images

2. Use .ifl in bitmap

When frame is changed will be changed image in material.


Royal Ghost | veda3d.com
Message 4 of 42

Anonymous
Not applicable

Thank for all of your help guys. I like both methods. I think a script may be the ticket in the long run because i will need to eventually call up different images based on what is going on at a particular frame of the animation.

I am have trouble getting either methiod to work.

If i try the script as @leeminardi suggestion I don't grasp the syntax.  In" meditMaterials[1] "is "1" the materiel name?

If i try the IFL Manager method as @RGhost77 suggested i get an error when i select the first and choose open of the sequential images "No list created"

 

 

 

 

0 Likes
Message 5 of 42

Anonymous
Not applicable

After further examination I am realizing that my images are not sequential images and that is why IFL dosn't work

 

0 Likes
Message 6 of 42

Anonymous
Not applicable

Ok i got the IFL manager to work. I had to trick it out in thinking the files were sequential. Cool stuff that has potential

 

 

0 Likes
Message 7 of 42

leeminardi
Mentor
Mentor

@Anonymous to determine a material number just turn of Max Listener (Scripting, MAXScript Listener...) or F11, and apply a material to a selected object. You will see statements like the following:

select $Teapot001
$.material = meditMaterials[8]

This shows you the material number to use.

 

After you make the changes to the script to reflect your materials, objects, and frame numbers save it with a .ms extension. Then open the script file and execute (Ctrl-E).   YOu should see the materials change as you move the time slider. If an object becomes invisible wait a second to give Max a chance to catch up.

 

Let me know if you have any q's.

lee.minardi
0 Likes
Message 8 of 42

Anonymous
Not applicable

Hi @leeminardi

Listener is not picking it up.

 

0 Likes
Message 9 of 42

leeminardi
Mentor
Mentor
Accepted solution

Try using the Compact Material Editor insead of the Slate editor or you could just use the name of the material in quotes as in this example:

 

	$.material = meditMaterials["My Mat B"]	
lee.minardi
Message 10 of 42

leeminardi
Mentor
Mentor

@Anonymous  Here's a much better script for changing materials by frame number.  The sample data in this script changes the material of Cylinder001 to "My Red" at frame 7, to "My Cyan" at frame 12, etc.  You can add to and edit this list as you need.  I hope you find it useful.

~Lee

 

fn time_p  = 
-- change material by frame number,  12/17/2018  LRM
-- The array TheData list the frame number of the change and the material material to use
(select $Cylinder001
TheData  = #(
	#(7,"My Red"),
	#(12,"My Cyan"),
	#(25,"My Green"),
	#(31,"My Red") -- do not include a comma after last material
	)
local n = TheData.count
for i = 1 to n do
(
	if  (sliderTime.frame as integer ) == TheData[i][1] then
		($.material = meditMaterials[TheData[i][2]]	
		)	
) -- end for	
)  -- end select
registerTimeCallback time_p

lee.minardi
0 Likes
Message 11 of 42

Anonymous
Not applicable

It is strange that it works with the compact material editor and not the Slate material editor.  When you try do do the same in Slate editor it reply's "underfined"

Do you think that should be reported as a bug?

 

 

0 Likes
Message 12 of 42

leeminardi
Mentor
Mentor

I don't understand your reference to the slate editor.  My script works regardless of which material editor mode is being used.  It is perhaps better to use the material name rather than its number.

 

Open the attached max file then run the maxscript MatByFrame08.ms.

 

If you scrub the timeline you will see the cylinder change colors as specified in the script. If you hit play you may not see it happen as there is a small lag for the screen image to update.

 

I took the script approach for your request rather than an IFL file as I thought it might be easier to set up the frames you wanted to switch for the panel display.

 

Let me know if it the script is not working for you. 

 

lee.minardi
0 Likes
Message 13 of 42

Anonymous
Not applicable

Thanks @leeminardi for all your willingness to help me! Your right Slate editor does work as well. I not sure what I was doing wrong before. What is the best way to get a handle on scripting? I used to do some basic programing and the syntax made more sense the the scripting does. Any suggestions? How did you get a grip on it?  Alot of trial and error?

Is there a good "scripting for dumbies" some where you can refer me to?

 

 

0 Likes
Message 14 of 42

leeminardi
Mentor
Mentor

@Anonymous you are welcome.

As for learning maxscripts I find it is best to have a specific program I want to create to help me learn.  My programming background is Fortran, Basic, VBA, and Autolisp.  I am not up with the more modern languages.  I have very little experience with Maxscripts and struggle a bit with maxscript syntax. Unlike the old days of programming where you started with a blank sheet of paper today you can google to find some code that does something similar to what you want to do as a place to start.  For your material-by-frame program I started by using the Maxscript listener to see what commands would be needed to assign a material to an object. That gave me:

$.material = meditMaterials[3]

My next challenge was how to determine the current frame and have the display update when the change was made. This took a few google searches and I stumbled onto the “registerTimeCallback” function. The languages I am most familiar with do not make a distinction between equal and assignment. Maxscript does. = is used for assignment and == is used for a logical equal.  Not remembering this caused me some problems.  The use of parentheses is also an issue for identifying the parts of an if, do and for structure. Get familiar with the print and format statements for outputting intermediate results. This is a big help in debugging.  Check out the Maxscript Debugger.   One thing that threw me for a while with the material script was that I thought sliderTime was giving me the current frame. I later learned that I needed sliderTime.frame from a print out of the sliderTime value.  Do not try to do too much in a single statement.  Using several variables lets you print out intermediate results and verify your code.  I find that detailed google searches usually produce good examples of code.  If you get really lost you can always post a question on the Maxscript programming forum.

lee.minardi
Message 15 of 42

Anonymous
Not applicable

Thanks @leeminardi great info!

 

0 Likes
Message 16 of 42

Anonymous
Not applicable

@leeminardi can you talk a look at this and tell me what i am missing?

This has really got me stumped.

Here is another example of how this is not working.

 

 

0 Likes
Message 17 of 42

leeminardi
Mentor
Mentor

Mark @Anonymous,

 

I cannot verify much from the mp4 files you like to post.  The text in the images is too fuzzy to read.

Two potential problems come to mind assuming you do not have any typos.  

1.  Do not scrub the timeline so fast. STop at frame 10, 12, and 13 to give the computer a chance to catch up.  

2. You may not have the materials' "Show Shaded Material in Viewport" button on so you are not seeing the bitmap.  Render frame 10 then 12.  DO they show the correct results?

 

Note, you do not need to assign any material to the object except for the starting frame.

 

Post the mac file (2018 compatible) and the image files and I will look at it if the above doesn't address the problem.

lee.minardi
0 Likes
Message 18 of 42

Anonymous
Not applicable

check this out Lee

Also i will downsize the file and send.

 

0 Likes
Message 19 of 42

Anonymous
Not applicable

here is the 2018 file

 fn time_p =
-- change material by frame number, 12/17/2018 LRM
-- The array TheData list the frame number of the change and the material material to use
(select $ui_screen
TheData = #(
#(2,"AD1"),
#(12,"AD2")
)
local n = TheData.count
for i = 1 to n do
(
if (sliderTime.frame as integer ) == TheData[i][1] then
($.material = meditMaterials[TheData[i][2]]
)
) -- end for
) -- end select
registerTimeCallback time_p

0 Likes
Message 20 of 42

Anonymous
Not applicable

i would be real courious why i am getting a undefined message.

meditMaterials.png

0 Likes