SimpleMeshMod plugin stumped


#1

I want to add a modifier to a mesh within a custom plugin before attaching the modified mesh to actual node seen in the viewport.

I could have sworn back in the day Bobo demonstrated a way to add a modifier to a mesh within a plugin in order to modify and deform it. Here is my sample code demonstrating a very simple example. You’ll see im using createInstance to create a box which i then want to add a modifier to it before attaching the resulting mesh to the node.

plugin simpleMeshMod SampleMod
name:"Sample"
classid:#(0x487913d, 0x2f288a1b)
(
    parameters MainParams rollout:MainRollout
    (
        count type:#integer default:1 animatable:true ui:uiCount
    )

    rollout MainRollout "Main" rolledUp:false
    (
        spinner uiCount "Count" range:[0,4,0] type:#integer fieldwidth:55 align:#right 
    )

    on modifyMesh do
    (
        local tmpObj = createInstance Box length:40 height:40 width:40
        local sm = createInstance TurboSmooth iterations:count
        local sp = createInstance Spherify percent:100.0
        -- addModifier tmpObj sm

        meshop.attach mesh tmpObj.mesh
    )
)

fn test = 
(
    delete objects
    clearlistener()
    local obj = box width:90 height:15 length:15 widthsegs:0 heightsegs:0 lengthsegs:0 wirecolor:green
    addModifier obj (SampleMod())
)

test()

If i change the modifyMesh code to use this is crashes when changing any params in the modifier.

on modifyMesh do
    (
        local tmpObj = Box length:40 height:40 width:40
        local sm = createInstance TurboSmooth iterations:count
        local sp = createInstance Spherify percent:100.0
        addModifier tmpObj sm
        setMesh mesh tmpObj.mesh
        --meshop.attach mesh tmpObj.mesh
        delete tmpObj

    )