User Tools

Site Tools


Create Geometry Shell

Summary

Below is an example demonstrating how you can create a geometry shell and set the offset distance of the push modifier, via script.

API Areas of Interest

Example

Create_Geometry_Shell.dsa
// Define an anonymous function;
// serves as our main loop,
// limits the scope of variables
(function(){
 
	/*********************************************************************/
	// String : A function for getting a unique node name
	function getUniqueName( sOriginalName )
	{
		// Initialize to the same name passed in
		var sUniqueName = sOriginalName;
		// If we do not already have a node in the scene with the name we want
		if( !Scene.findNode( sOriginalName ) ){
			// We're done...
			return sOriginalName;
		}
 
		// Initialize the count to 2
		var nCount = 2;
		// Keep incrementing the count until we find one that doesn't already exist
		while( Scene.findNode( String("%1 %2").arg( sOriginalName ).arg( nCount ) ) ){
			nCount += 1;
		}
 
		// Construct the unique name
		sUniqueName = String("%1 %2").arg( sOriginalName ).arg( nCount );
 
		// Return the unique name
		return sUniqueName;
	};
 
	/*********************************************************************/
	// DzGeometryShellNode : A function for creating a geometry shell for
	// an item with geometry in the scene
	function createShell( oNode )
	{
		// If we don't have a node
		if( !oNode ){
			// We're done... we need a node
			return undefined;
		}
 
		// If the source node is a bone
		if( oNode.inherits( "DzBone" ) ){
			// We want the skeleton that owns the bone
			oNode = oNode.getSkeleton();
		}
 
		// Get the node's object
		var oObject = oNode.getObject();
		// If we don't have an object
		if( !oObject ){
			// We're done... we need an object
			return undefined;
		}
 
		// Get the object's cached geometry
		var oGeometry = oObject.getCachedGeom();
		// If we don't have geometry
		if( !oGeometry ){
			// We're done... we need geometry
			return undefined;
		}
 
		// Create a new geometry shell node
		var oShellNode = new DzGeometryShellNode();
 
		// Get the target property of the shell
		var oProperty = oShellNode.getShellNodeControl();
 
		// Exclude the shell node from the
		// list of nodes that can be targeted
		oProperty.exclude( oShellNode );
 
		// Set the target to the source node
		oProperty.setValue( oNode );
 
		// Construct a base name from the source node name
		var sBaseName = String("%1 Shell").arg( oNode.objectName );
 
		// Get a unique name
		var sUniqueName = getUniqueName( sBaseName );
 
		// Set the name and label of the instance node
		oShellNode.setName( sUniqueName );
		oShellNode.setLabel( sUniqueName );
 
		// Add the node to the scene
		Scene.addNode( oShellNode );
 
		// Return the shell node
		return oShellNode;
	};
 
	/*********************************************************************/
	// Get the primary selection
	var oNode = Scene.getPrimarySelection();
	// If nothing is selected
	if( !oNode ){
		// We're done...
		return;
	}
 
	// Create a shell of the node
	var oShellNode = createShell( oNode );
	// If a shell was not created
	if( !oShellNode ){
		// We're done...
		return;
	}
 
	// Get the shell's object
	var oObject = oShellNode.getObject();
	// If we do not have an object
	if( !oObject ){
		// We're done...
		return;
	}
 
	// Get the offset modifier
	var oModifier = oObject.findModifier( "Offset" );
	// If we do not have a modifier
	if( !oModifier ){
		// We're done...
		return;
	}
 
	// Get the property that controls distance
	var oProperty = oModifier.getValueChannel();
	// If we do not have a property
	if( !oProperty ){
		// We're done...
		return;
	}
 
	// Set the distance
	oProperty.setValue( 0.3 );
 
// Finalize the function and invoke
})();