[Closed] Add Xform
when I add Xform modifier from modify panel, gizmo is located at the pivot pos. but when I add modifier by code, gizmo goes in unknown location. how I can add modifier just like what modify panel does?
I don’t want to refresh modify panel. Actually I’m looking for fastest way.
What Denis has suggested is what you would need if you want to use addmodifier() function.
You also have all these properties:
xform.center
xform.gizmo
xform.gizmo.position
xform.gizmo.rotation
xform.gizmo.scale
But AFAIK that won’t be what you described as “…just like what modify panel does…” because adding the modifier from Modify Panel sets the gizmo transform to an identity matrix I think.
So it would be similar but not exactly the same. Anyway, the tasks seems now to be “the fastest way” instead, so setting the gizmo transform might be it.
xmod = xform()
addmodifier <node> xmod
xmod.gizmo.transform = matrix3 1
but maybe you want to do anything else. please explain it better
ahh… i see. probably you want to align to not reset object. in this case you have to reset objectoffsetpos (if you want to align center only)
(
fn AddXformModifier node =
(
theMod = xform()
addmodifier node theMod
pos = node.objectoffsetpos * inverse (node.objectoffsetrot as quat)
theMod.center = pos
theMod.gizmo.pos = -pos
)
AddXformModifier $
)
Thank you! This is exactly what I’ve been looking for. do you think is not better to construct xform before adding to the object?
fn AddXformModifier Obj Name: =
(
pos = Obj.objectoffsetpos * inverse (Obj.objectoffsetrot as quat)
theMod = xform gizmo:(matrix3 [1,0,0] [0,1,0] [0,0,1] -Pos) center:pos
addmodifier Obj theMod
)
As far as functionality, I don’t think one is better than the other.
As far as readability, I prefer to set the properties after, it is easier to understand for me.
As far as performance, creating the modifier with its properties already setup, might be faster and save some memory for lot of objects (thousands).
this is not exactly the same as what max does do when you apply xform modifier manually.
you can check it… just look at .gizmo.pos and .center values for both cases. and you will see the difference. also you can check getModContextTM
honestly i don’t know yet how to mimic exactly the system’s solution. and i’m not sure what is better (or more correct) – origin center or origin context transform
Yes Denis, I noticed that, and mentioned it before. So my first suggestion was to use modPanel.addModToSelection().
Apparently, it was not needed to be “exactly what Max does” (as described originally) but similar.