Setting position, rotation, and scale of nodes


#1

Apologies if this has already been answered. It seems like such a foundational question, but I’ve spent an hour searching here and on Google and I’ve come up empty.

Given a node, how do I change the world-space position, rotation, and scale of the node in C#? In other words, how can I achieve the same effect of entering a number in the Transform Type-In?

I immediately ran across IINode.ObjOffsetPos, however this is for changing the object offset transform, not the node transform. In other words, you can’t use it to change the node position relative to the parent or world.

The only examples I could find in the C++ SDK examples are directly manipulating the node TM IMatrix3. I can try to figure out the math there, but I’m really hoping there’s an easier way.


#2

Welp, as expected, 15 minutes after posting here, I figured it out.

I hadn’t even looked at the IMatrix3 interface - from working in other systems, I’m used to that just being a wrapper around a matrix. Apparently in Max, that’s where all the of the translation / rotation / scale functions are kept.

So this appears to work:

IMatrix3 nodeTM = rootNode.GetNodeTM(0, null);
nodeTM.NoTrans();
nodeTM.Translate(model.Position.ToIpoint3());
rootNode.SetNodeTM(0, nodeTM);

(The last SetNodeTM call seems to be necessary, even though the other operations change the nodeTM reference. I guess calling GetNodeTM actually returns a copy of the matrix vs a reference to the matrix?)

Even though this ended up being a stupid question, I’m going to leave it up because there are no search results for this. Hopefully my stupidity (and eventual eureka moment) can help someone else in the future!