This tutorial will walk through creating a simple clone utility made with MCG.
Open a new MCG graph, and add the Output: Utility operator, which is the final node in this graph. All utilities built with MCG use this output type.
Since we are cloning an object in the scene, add a Tool Input: SceneNode operator, which will allow the user to select a parent object to clone. The operator used to "clone" meshes is called Transform Mesh with Increment. Add this operator and note the inputs: a mesh to operate on, an integer (the number of times to apply the operation) and a transform matrix.
To connect our scene node to the mesh input of the Transform Mesh with Increment operator, we'll need to run it through a SceneNode Mesh operator to extract the mesh. We also need user inputs for the n count, so add a Tool Input: Integer operator and name it "Count". Finally, we need to supply a transform matrix. Conveniently, MCG has a Tool Input: Vector operator, which we can convert to a matrix using a Translation Matrix operator, and wire into the transform operator. Add these nodes, and your graph should look like this:
The last step will be to connect the Array[Mesh] output of the Transform Mesh with Increment operator to our utility output. However, we need to perform two steps first: combine the array of meshes into a single mesh, and then create the resulting mesh in the scene. Because utilities can peform any arbitrary action (not always altering the scene), we need to perform the creation explicitly in the graph. With other types of output, this is peformed by 3ds Max in the output operator.
Add an Attach All Meshes operator, and wire the Array[Mesh] output of the transform operator into it. Then wire this operator's output into a Create Editable Mesh operator, which can finally be wired into our output node.
Save the graph as "MCG_CloneUtility" and evaluate it. On the utility control panel, under MAXScript, select "MCG_CloneUtility" in the Utilities drop down:
Select a node in the scene, set the count to 5, and set the Transform matrix to non-zero numbers. Click Execute and notice that nothing has happened. This is a shortcoming in the MCG utility operator that we will address in the next step. When you force a redraw in the viewport by zooming or moving, you will see the new Editable Mesh appear.
We can improve our graph by forcing a viewport redraw. Although MCG does not have a native operator to do this, we can inject some MAXScript to achieve this. Go back to your graph, and add a new Evaluate MAXScript Operator. Into the code input, wire a Constant operator with the value redrawViews()
. Wire the Evaluate MAXScript output into the second input of an Ignore Second operator. This will cause the MAXScript command to evaluate, and then ignore (throw away) the result. Wire the Create Editable Mesh through the first slot of this node, and then wire the output to the Output: Utility operator. The end of the graph should look like this:
When you re-evaluate and test this version, you will the the clone results appear immediately in the viewport window.