Notifications
Clear all

[Closed] Material Switcher for 2d facial animation

Hi everybody. I´m trying to do a material switcher for a 3d character with textured face. I´m trying to do a custom attribute modifier and assign a material for each value of a spinner. Any idea for doing this? Any non script method? I have done some experiments but I´m not a scripter :).

plugin modifier 'Material Switcher'
 	name:"Material Switcher"
 	classID:#(601007,801001)
 	version:1
 (
 	local newMaterial
 
 	rollout rollout_Options "Options"
 	(
 		spinner spinner_materialNumb "Material" type:#integer range:[1, 3, 0]
 		
 		on spinner_materialNumb changed val do
 		(
 			newMaterial = case spinner_materialNumb.value of
 			(
 				1: "Pose1"
 				2: "Pose2"
 				3: "Pose3"
 			)
 			$.material = sceneMaterials[newMaterial]
 		)
 	)
 
 	parameters MatSwitcherParameters rollout:rollout_Options
 	(
 		materialNumb type:#integer ui:spinner_materialNumb
 	)
 )
5 Replies

You could probably do this with the morpher material. Perhaps check that out as well!

Morpher material does the work, but it does´t reflect or refresh the viewport. It shows only the first material. Any solution or alternative?

Hi Aritz, I did something similar some time ago, But I´m using another aproach

I´m using a mult/subobj material with different “textures of faces” in each ID, then , using a “material” modifier I´m able to choose witch face will be displayed in viewport.

id 1 = texture of a smiled face
id 2 = texture of a sad face
id 3 = texture of a bored face

If you turn ANIMATE and change the ID value on the “Material” modifier you can animate the faces changing.

The problem is that you need to set those keys to be steped, if not , you won´t have total control over the exact frame the IDs will change.

Ex: With animate on , in the “material” modifeir you Set a key for the ID 1 in the Frame 1 , then you move to the frame 10 and change the ID spinner to 2. When you scrobbled the timeslider you´ll see in the viewport that the change of the ID will hapend in the frame 5.

my script solution basically do the following:

Add an empty modifier to the obj that will have the mult/subobject material
Add an Material modifier
Create some named Radio Buttons , with the names you set in the material editor that will drive the Material modifier.

Now you just need to change the radio buttons over time and It will automaticaly set a step key !!
And there´s also a “REDEFINE” button in the empty modifier that will of course, redefine the modifier if you add or remove some ID´s

Sorry about my english and I hope it helps!

Here´s the code:

if selection.count == 0 do (messageBox “Select an Object” beep:off)

if selection.count >= 1 and (classOf $.material != Multimaterial) do (messageBox “Object has no Multi ID Material”)

if selection.count >= 1 and (classOf $.material == Multimaterial) do

(

try

(

setCommandPanelTaskMode mode:#modify

modPanel.addModToSelection (Materialmodifier())

modPanel.addModToSelection (EmptyModifier())

$.modifiers[1].name = “2d_Map_animation”

xCustAtb = Attributes AnimationCtrl

(

parameters Main rollout:AniCtrls

(

)

rollout AniCtrls “Animation Controls”

(

button bnt1 “Redefine”

group “Animation Controls”

(

radioButtons rdo1 “” align:#left labels: (($.material.names) as array) default:1 columns:1

)

on rdo1 changed state do

(

$.modifiers[#Material].materialId = rdo1.state

try

(

$.modifiers[#material].materialID.controller.keys.outTangentType = #step

) catch()

)

on bnt1 pressed do

(

deleteModifier $ (modPanel.getModifierIndex $ ($.modifiers[#2d_Map_animation]))

modPanel.addModToSelection (EmptyModifier())

$.modifiers[1].name = “2d_Map_animation”

custAttributes.add $.modifiers[1] xCustAtb #unique

)

)

)

custAttributes.add $.modifiers[1] xCustAtb #unique

)

catch()

)

:applause: Oh my god!! I never noticed in the Material modifier. That is exactly what I was trying to do :), thank you very much. For the animation problem I think it is enought to set the default In/Out tangets to “Step” mode; key in frame 10 and chage only in frame 10. Thanks again Fabio. Thanks erilaz.

There´s always a diferent way to do the same thing

Glad to help you

See ya