Working with objects

Scene objects are objects that you can create and manipulate in the viewport.

They can be: geometry (GeomObject), lights (LightObject), cameras (CameraObject), and even particles and world space modifiers.

You must create a node for your object for it to appear in the scene. Nodes are implemented by the INode class.

Creating an object

Use the Factory.CreateObject() and Factory.CreateGeomObject() methods to create your object. Then create the node for your object with the Factory.CreateNode() method using your object as an input parameter.

Create more than one instance of your object by creating multiple nodes for your object.

See demoMakeInstances.py for an example of how to create an object, and then create multiple nodes to create multiple instances of the object.

Setting the parameters for your object

Set your parameters via the ParameterBlock class. For more information regarding the ParameterBlock class, see Working with parameters and the ParameterBlock class.

Modifying your object

A modifier transforms an object. Most modifiers are object modifiers that are applied to objects in their own local transform space and perform deformations such as bend, taper, and twist.

A modifier takes an object and either modifies it directly, or creates a new object from the input object. Many modifiers only apply to certain characteristics (that is, channels) of an object such as the vertices or the faces.

Modifiers can be specific to certain types of object, for example, the Volume Select Modifier only works on triangle mesh objects (TriObject).

First create the modifier; then set its parameters via the parameter block, and then apply the modifier to the node of the object. The demoBentCylinder.py example demonstrates how to bend a cylinder by 45 degrees using the bend object space modifier.

obj = MaxPlus.Factory.CreateGeomObject(MaxPlus.ClassIds.Cylinder)
obj.ParameterBlock.Radius.Value = 10.0
obj.ParameterBlock.Height.Value = 30.0
node = MaxPlus.Factory.CreateNode(obj)
mod = MaxPlus.Factory.CreateObjectModifier(MaxPlus.ClassIds.Bend)
mod.ParameterBlock.BendAngle.Value = 45.0
node.AddModifier(mod)

Editing a mesh

If you want to edit the faces and vertices of a mesh, you must first create a geometry object, then cast it from the geometry object to a TriObject and then obtain the Mesh by using the TriObject.GetMesh() method as follows:

geom = MaxPlus.Factory.CreateGeomObject(MaxPlus.ClassIds.TriMeshGeometry)
tri = MaxPlus.TriObject._CastFrom(geom)
mesh = tri.GetMesh()

See demoMeshAndCPV.py for more information.

Transforming: Scale, Rotate and Position

You can scale, rotate, or move an object to a different position via its node. Use the Point3 class to set the scale and position as follows:

node.Scaling = MaxPlus.Point3(3, 3, 3)
node.Position = MaxPlus.Point3(20, 20, 20)

To set the rotation, use INode.Rotation and provide a quaternion as your input parameter. The quaternion you provide specifies the rotation components for the matrix, and in addition, the translation and scale components of your node are reset to match this matrix.

Note: Translation and rotation values on an INode do not work the same as in MAXScript. These are non-normalized values, whereas in MAXScript they always are. To get expected values (ie, values similar to MAXScript), you will need to re-scale the transform matrix to scale (1,1,1). For example, box001 has been rotated:

print 'Transform python pre scale: {0}'.format(MaxPlus.INode.GetINodeByName('box001').Transform)
scaledMatrix = (MaxPlus.INode.GetINodeByName('box001').Transform)
setToScale = MaxPlus.Point3(1,1,1) / scaledMatrix.Scale
scaledMatrix.PreScale(setToScale)
print 'Rotation python post rescaled to 1 1 1 matrix: {0}'.format(scaledMatrix.Rotation)