MCG Projection Modifier | Paul Neale

3DS Max MCG Simple Projection Modifier

Click on the image above to enlarge it.

MCG in 3DS Max allows for plugins of different types to be created and used just like any standard feature.

This example shows how to create a simple projection modifier that projects the pivot of a mesh onto the surface of another along a given axis.

There are many mode features that could be added to such as rotating to the surface of the target mesh how ever this has been kept a simple as possible to illustrate how to build the basic flow.

Changsoo Eun has a extensive tutorial on getting you started with installing and network deployment of MCG tools. 

http://cganimator.com/how-to-share-your-awesome-mcgs-mcg-installation-and-network-deployment/

  

Let have a look at a break down of some of the nodes and what they are doing.

The Inputs group has five inputs but only three are visible to the end user. 

Tool Input: SceneNode
Allows users to add a scene node that will be used for collision detection. 

Modifier: Local to World Matrix
Converts the local space matrix of a modifier to world coordinates. Modifiers work in the local space of the node that they have been added to. If you have a node that has been rotated in the scene and check the rotation of the modifier on it the modifier will now show any rotation as it is aligned to its parent node. 

Tool Input: Boolean
Allows the user to check a check box in the modifier. A boolean is an on off value or true false. In this case we are using it to control if the direction the ray will be cast in is positive or negative. 

Tool Input: Integer
Creates a single spinner in the modifier panel with a minimum and maximum value and a default value set that the user can change.

Constant
This node is used for creating any constant data type for use in the flow. In this case we have set it to a float value of -1 and we are using it to multiply the direction vector for casting the ray to invert it. 

The Get Ray Direction Vector group creates the values that are used to create the Ray that defines a position the ray starts at and a direction vector that defines the direction it is fired in.

Matrix Translation Component
Takes input from the Local to World Matrix and outputs the Vector 3 value that defines its position.

Matrix Row
Takes input from the Local to World Matrix node and an integer from the Direction Axis Index spinner to define if it is using the X,Y or Z vector from the Transform Matrix. 

If
The If node takes the input from the boolean node to determine if the direction vector should be inverted. If true the returned Vector 3 value from the Matrix Row is multiplied by the Constant input of -1.

Normalize
Normalizing a vector means to set the length of the vector to a value of 1 so that it is not scaled. It is always best to normalize vectors when they will be used as direction vectors or in transform matrix values and other math solutions so that it is not considered scaled. This node is taking input from the If node directly.

The Create Ray Intersection group creates a Ray value and casts it at the Hit Node that was set by the user and returns information about where the Hit Node was hit by returning a Ray value that contains the position of the hit and the face normal at that point. 

Ray
The ray node takes input from the transform component of the world matrix and the normalized direction vector that it out put from the Normalize node. A two part Ray pair is returned.

Ray Intersection with SceneNode
The two inputs are the scene node the user set with the Tool Input: SceneNode and the Ray pair value output from the Ray node. This then returns a pair value that contains the resulting Ray pair and a Boolean that can be used to determine if the hit was successful. 

Pair Item 1
Takes input from the Ray Intersection with SceneNode and splits out the first item in the returned pair which is the Ray value.

The Build Matrix group creates the transform matrix that will be used to transform the vertices of the node to the surface that has been hit. 

Matrix Scaling Component
Takes input from the Local to World Matrix node and returns just the scaling portion of the matrix as a Vector 3 value.

Matrix Rotation Component
Takes input from the Local to World Matrix node and returns just the rotation part as a Quaternion.

Ray Position
Takes input from the Pair Item 1 node which is the Ray hit value that contains both the Position and Normal that was hit. It returns just the position as a Vector 3 value.

Translation Rotation Scaling Matrix
Takes the scale, rotation and position values and outputs a Transform Matrix. 

Return Identity Matrix group checks to see if the hit node is value and returns an identity matrix if it isn’t. 

SceneNode Is Valid
Takes input from the SceneNode Hit Node and returns a true if it is a valid node in the scene. 

Identity Matrix
If the hit node is not valid an Identity Matrix value is set. And Identity Matrix is a transform matrix value that has not been translated, rotated or scaled.

If
Checks if the boolean is true or false and returns the correct value. 

Put Matrix in space of modifier converts the world space values from the Local to World Matrix that we have been using to calculate the position of the mesh and converts it back to the space of the modifier that is local to the node. 

Matrix Inverse
To convert a world matrix to the local matrix we need to invert the world matrix value. 

Multiply
Multiplying matrix value is a noncommutative meaning that the order the multiplication is done is will change the result. In this case to convert the world matrix to local we must multiply the resulting matrix by the inverse of the modifiers matrix.

The final group that I forgot to name transforms the mesh from the stack by the transform matrix that we have created and outputs the result in the modifier stack.

Modifier: Mesh
Returns the mesh from the position in the modifier stack that the modifier has been added at. This input could have been added to the Inputs group but it would have been hard to see where it was connected. 

Transform Mesh
The Modifier Mesh is passed to the Transform Mesh node and all the vertices of the mesh are set using the matrix that has been calculated. 

Output: Modifier
The Output Modifier node creates a modifier that can be added to the modifier stack.  

This is the final advanced projection modifier where the meat of the modifier has been moved to a compound so that it can be reused in other tools. There are many compounds already available in MCG like the Matrix from Up Forward that is being used in the projection modifier. These save you time when developing more complex tools and clean up the graphs by breaking them into bit sized pieces.

The modifier above is using the compound below to handle the meat of the calculations. The compound can now be reused in other tools to simplify and speed up development. 

Below is the result of utilizing the Projection Compound in the Clone Modifier.