Notifications
Clear all

[Closed] Applying material within SimpleMeshMod

Is there a way to apply a material from within a SimpleMeshMod without triggering and recursive loop of the object changing?

When the Enable button is pressed, i want the material applied, otherwise I’m planning on then restoring the original material. But i can’t even get the temp material applied without it crashing. Do i need to store the material in a local variable and not the param block?

clearlistener()

plugin simpleMeshMod myMaterialModifier
name:"MaterialModifier"
classid:#(0x491fdf76, 0x7493038e)
(
    local tempMaterial = MultiSubMaterial()

    parameters MainParams rollout:MainRollout
    (
        isModifierActive type:#boolean ui:uiIsModifierActive
        previewMaterial type:#material
    )

    rollout MainRollout "Main" rolledUp:false
    (
        checkbutton uiIsModifierActive "Enable" width:160 align:#center
    )

    /* Actions */
    on create do
    (
        previewMaterial = MultiSubMaterial()
    )

    on modifyMesh do
    (
        if isModifierActive then
        (
            /* Material */
            format "Preview Material > %\n" previewMaterial
            format "Node Material > %\n" owningNode.material
            format "== %\n" (owningNode.material == previewMaterial)
            if owningNode.material != previewMaterial do 
            (
                /* causes endless update loop */
                -- owningNode.material = previewMaterial
            )
        )
    )
)
4 Replies

can you have a material set flag ?

if owningNode.material != previewMaterial  and  matset == false do 
            (
                    matset = true; .....
 MZ1

Why you need to check the node material in modifyMesh event?

Did you try this to see if it worked?

That’s actually a pretty good point. I may do it outside of it in a button press event instead