public static MPlug getConnection(this MFnDependencyNode mFnDependencyNode, string name) { MPlugArray connections = new MPlugArray(); mFnDependencyNode.getConnections(connections); foreach (MPlug connection in connections) { if (connection.name == (mFnDependencyNode.name + "." + name)) { return(connection); } } return(null); }
void Print(MFnDependencyNode dependencyNode, int logRank, string title) { // prints RaiseVerbose(title, logRank); PrintAttributes(dependencyNode, logRank + 1); RaiseVerbose("Connections", logRank + 1); MPlugArray connections = new MPlugArray(); try { dependencyNode.getConnections(connections); RaiseVerbose("connections.Count=" + connections.Count, logRank + 2); foreach (MPlug connection in connections) { MObject source = connection.source.node; MPlugArray destinations = new MPlugArray(); connection.destinations(destinations); if (source != null && source.hasFn(MFn.Type.kDependencyNode)) { MFnDependencyNode node = new MFnDependencyNode(source); RaiseVerbose("name=" + connection.name + " partialName=" + connection.partialName(false, false, false, true) + " source=" + node.name + " source.apiType=" + source.apiType, logRank + 2); } else { RaiseVerbose("name=" + connection.name, logRank + 2); } RaiseVerbose("destinations.Count=" + destinations.Count, logRank + 3); foreach (MPlug destination in destinations) { MObject destinationObject = destination.node; if (destinationObject != null && destinationObject.hasFn(MFn.Type.kDependencyNode)) { MFnDependencyNode node = new MFnDependencyNode(destinationObject); RaiseVerbose("destination=" + node.name + " destination.apiType=" + destinationObject.apiType, logRank + 3); if (destinationObject.hasFn(MFn.Type.kShadingEngine)) { PrintAttributes(node, logRank + 4); } } } } } catch {} }
private MFnSkinCluster getMFnSkinCluster(MObject mObject) { MFnSkinCluster mFnSkinCluster = null; MFnDependencyNode mFnDependencyNode = new MFnDependencyNode(mObject); MPlugArray connections = new MPlugArray(); mFnDependencyNode.getConnections(connections); for (int index = 0; index < connections.Count && mFnSkinCluster == null; index++) { MObject source = connections[index].source.node; if (source != null && source.hasFn(MFn.Type.kSkinClusterFilter)) { mFnSkinCluster = new MFnSkinCluster(source); } } return(mFnSkinCluster); }
void Print(MFnDependencyNode dependencyNode, int logRank, string title) { // prints RaiseVerbose(title, logRank); RaiseVerbose("Attributes", logRank + 1); for (uint i = 0; i < dependencyNode.attributeCount; i++) { MObject attribute = dependencyNode.attribute(i); if (attribute.hasFn(MFn.Type.kAttribute)) { MFnAttribute mFnAttribute = new MFnAttribute(attribute); RaiseVerbose("name=" + mFnAttribute.name, logRank + 2); } } RaiseVerbose("Connections", logRank + 1); MPlugArray connections = new MPlugArray(); try { dependencyNode.getConnections(connections); RaiseVerbose("connections.Count=" + connections.Count, logRank + 2); foreach (MPlug connection in connections) { MObject source = connection.source.node; if (source != null && source.hasFn(MFn.Type.kDependencyNode)) { MFnDependencyNode node = new MFnDependencyNode(source); RaiseVerbose("name=" + connection.name + " source=" + node.name, logRank + 2); } else { RaiseVerbose("name=" + connection.name, logRank + 2); } } } catch (Exception e) { } }
/// <summary> /// /// </summary> /// <param name="mDagPath">DAG path to the transform above camera</param> /// <param name="babylonScene"></param> /// <returns></returns> private BabylonNode ExportCamera(MDagPath mDagPath, BabylonScene babylonScene) { RaiseMessage(mDagPath.partialPathName, 1); // Transform above camera MFnTransform mFnTransform = new MFnTransform(mDagPath); // Camera direct child of the transform MFnCamera mFnCamera = null; for (uint i = 0; i < mFnTransform.childCount; i++) { MObject childObject = mFnTransform.child(i); if (childObject.apiType == MFn.Type.kCamera) { var _mFnCamera = new MFnCamera(childObject); if (!_mFnCamera.isIntermediateObject) { mFnCamera = _mFnCamera; } } } if (mFnCamera == null) { RaiseError("No camera found has child of " + mDagPath.fullPathName); return(null); } // --- prints --- #region prints RaiseVerbose("BabylonExporter.Camera | mFnCamera data", 2); RaiseVerbose("BabylonExporter.Camera | mFnCamera.eyePoint(MSpace.Space.kWorld).toString()=" + mFnCamera.eyePoint(MSpace.Space.kTransform).toString(), 3); RaiseVerbose("BabylonExporter.Camera | mFnCamera.viewDirection(MSpace.Space.kWorld).toString()=" + mFnCamera.viewDirection(MSpace.Space.kTransform).toString(), 3); RaiseVerbose("BabylonExporter.Camera | mFnCamera.upDirection(MSpace.Space.kWorld).toString()=" + mFnCamera.upDirection(MSpace.Space.kTransform).toString(), 3); RaiseVerbose("BabylonExporter.Camera | mFnCamera.rightDirection(MSpace.Space.kWorld).toString()=" + mFnCamera.rightDirection(MSpace.Space.kTransform).toString(), 3); RaiseVerbose("BabylonExporter.Camera | mFnCamera.centerOfInterestPoint(MSpace.Space.kWorld).toString()=" + mFnCamera.centerOfInterestPoint(MSpace.Space.kTransform).toString(), 3); RaiseVerbose("BabylonExporter.Camera | mFnCamera.centerOfInterest=" + mFnCamera.centerOfInterest, 3); RaiseVerbose("BabylonExporter.Camera | mFnCamera.aspectRatio=" + mFnCamera.aspectRatio, 3); RaiseVerbose("BabylonExporter.Camera | mFnCamera.horizontalFieldOfView=" + mFnCamera.horizontalFieldOfView, 3); RaiseVerbose("BabylonExporter.Camera | mFnCamera.verticalFieldOfView=" + mFnCamera.verticalFieldOfView, 3); RaiseVerbose("BabylonExporter.Camera | mFnCamera.horizontalFieldOfView / mFnCamera.verticalFieldOfView=" + mFnCamera.horizontalFieldOfView / mFnCamera.verticalFieldOfView, 3); RaiseVerbose("BabylonExporter.Camera | mFnCamera.focalLength=" + mFnCamera.focalLength, 3); RaiseVerbose("BabylonExporter.Camera | mFnCamera.nearFocusDistance=" + mFnCamera.nearFocusDistance, 3); RaiseVerbose("BabylonExporter.Camera | mFnCamera.nearClippingPlane=" + mFnCamera.nearClippingPlane, 3); RaiseVerbose("BabylonExporter.Camera | mFnCamera.unnormalizedNearClippingPlane=" + mFnCamera.unnormalizedNearClippingPlane, 3); RaiseVerbose("BabylonExporter.Camera | mFnCamera.farFocusDistance=" + mFnCamera.farFocusDistance, 3); RaiseVerbose("BabylonExporter.Camera | mFnCamera.farClippingPlane=" + mFnCamera.farClippingPlane, 3); RaiseVerbose("BabylonExporter.Camera | mFnCamera.unnormalizedFarClippingPlane=" + mFnCamera.unnormalizedFarClippingPlane, 3); RaiseVerbose("BabylonExporter.Camera | mFnCamera.isClippingPlanes=" + mFnCamera.isClippingPlanes, 3); RaiseVerbose("BabylonExporter.Camera | mFnCamera.isIntermediateObject=" + mFnCamera.isIntermediateObject, 3); RaiseVerbose("BabylonExporter.Camera | mFnCamera.focusDistance=" + mFnCamera.focusDistance, 3); RaiseVerbose("BabylonExporter.Camera | mFnCamera.isStereo=" + mFnCamera.isStereo, 3); RaiseVerbose("BabylonExporter.Camera | mFnCamera.eyeOffset=" + mFnCamera.eyeOffset, 3); RaiseVerbose("BabylonExporter.Camera | mFnCamera.shutterAngle=" + mFnCamera.shutterAngle, 3); RaiseVerbose("BabylonExporter.Camera | mFnCamera.isDepthOfField=" + mFnCamera.isDepthOfField, 3); RaiseVerbose("BabylonExporter.Camera | mFnCamera.renderPanZoom=" + mFnCamera.renderPanZoom, 3); Print(mFnTransform, 2, "Print ExportCamera mFnTransform"); Print(mFnCamera, 2, "Print ExportCamera mFnCamera"); #endregion if (IsCameraExportable(mFnCamera, mDagPath) == false) { return(null); } var babylonCamera = new BabylonCamera { name = mFnTransform.name, id = mFnTransform.uuid().asString() }; // Hierarchy ExportHierarchy(babylonCamera, mFnTransform); // Position / rotation RaiseVerbose("BabylonExporter.Camera | ExportTransform", 2); float[] position = null; float[] rotationQuaternion = null; float[] rotation = null; float[] scaling = null; GetTransform(mFnTransform, ref position, ref rotationQuaternion, ref rotation, ref scaling); babylonCamera.position = position; if (_exportQuaternionsInsteadOfEulers) { babylonCamera.rotationQuaternion = rotationQuaternion; } babylonCamera.rotation = rotation; // Field of view of babylon is the vertical one babylonCamera.fov = (float)mFnCamera.verticalFieldOfView; // Clipping planes babylonCamera.minZ = (float)mFnCamera.nearClippingPlane; babylonCamera.maxZ = (float)mFnCamera.farClippingPlane; // Constraints on near clipping plane if (babylonCamera.minZ == 0.0f) { babylonCamera.minZ = 0.1f; } // TODO - Retreive from Maya //// Type //babylonCamera.type = cameraNode.MaxNode.GetStringProperty("babylonjs_type", "FreeCamera"); //// Control //babylonCamera.speed = cameraNode.MaxNode.GetFloatProperty("babylonjs_speed", 1.0f); //babylonCamera.inertia = cameraNode.MaxNode.GetFloatProperty("babylonjs_inertia", 0.9f); //// Collisions //babylonCamera.checkCollisions = cameraNode.MaxNode.GetBoolProperty("babylonjs_checkcollisions"); //babylonCamera.applyGravity = cameraNode.MaxNode.GetBoolProperty("babylonjs_applygravity"); //babylonCamera.ellipsoid = cameraNode.MaxNode.GetVector3Property("babylonjs_ellipsoid"); // Target MFnTransform target = null; MObject cameraGroupObject = mFnCamera.findPlug("centerOfInterest").source.node; if (cameraGroupObject.apiType == MFn.Type.kLookAt) { MFnDependencyNode cameraGroup = new MFnDependencyNode(cameraGroupObject); // Retreive the camera aim transform MPlugArray connections = new MPlugArray(); cameraGroup.getConnections(connections); foreach (MPlug connection in connections) { if (connection.name.EndsWith("targetParentMatrix")) // ugly { MObject connectionSourceObject = connection.source.node; target = new MFnTransform(connectionSourceObject); break; } } } if (target != null) { babylonCamera.lockedTargetId = target.uuid().asString(); } //// TODO - Check if should be local or world //var vDir = new MVector(0, 0, -1); //var transformationMatrix = new MTransformationMatrix(mFnTransform.transformationMatrix); //vDir *= transformationMatrix.asMatrix(1); //vDir = vDir.Add(position); //babylonCamera.target = new[] { vDir.X, vDir.Y, vDir.Z }; // Animations if (target == null) { ExportNodeAnimation(babylonCamera, mFnTransform); } else { ExportNodeAnimationFrameByFrame(babylonCamera, mFnTransform); } babylonScene.CamerasList.Add(babylonCamera); RaiseMessage("BabylonExporter.Camera | done", 2); return(babylonCamera); }
// // Write the 'connectAttr' commands for all of a node's incoming // connections. // protected void writeNodeConnections(FileStream f, MObject node) { MFnDependencyNode nodeFn = new MFnDependencyNode(node); MPlugArray plugs = new MPlugArray(); try { nodeFn.getConnections(plugs); } catch (Exception) { } uint numBrokenConns = fBrokenConnSrcs.length; uint numPlugs = plugs.length; int i; string result = ""; for (i = 0; i < numPlugs; i++) { // // We only care about connections where we are the destination. // MPlug destPlug = plugs[i]; MPlugArray srcPlug = new MPlugArray(); destPlug.connectedTo(srcPlug, true, false); if (srcPlug.length > 0) { MObject srcNode = srcPlug[0].node; MFnDependencyNode srcNodeFn = new MFnDependencyNode(srcNode); // // Don't write the connection if the source is not writable... // if (!srcNodeFn.canBeWritten) continue; // // or the connection was made in a referenced file... // if (destPlug.isFromReferencedFile) continue; // // or the plug is procedural... // if (destPlug.isProcedural) continue; // // or it is a connection between a default node and a shared // node (because those will get set up automatically). // if (srcNodeFn.isDefaultNode && nodeFn.isShared) continue; result += "connectAttr \""; // // Default nodes get a colon at the start of their names. // if (srcNodeFn.isDefaultNode) result += ":"; result += (srcPlug[0].partialName(true) + "\" \""); if (nodeFn.isDefaultNode) result += ":"; result += (destPlug.partialName(true) + "\""); // // If the src plug is also one from which a broken // connection originated, then add the "-rd/referenceDest" flag // to the command. That will help Maya to better adjust if the // referenced file has changed the next time it is loaded. // if (srcNodeFn.isFromReferencedFile) { int j; for (j = 0; j < numBrokenConns; j++) { if (fBrokenConnSrcs[j] == srcPlug[0]) { result += (" -rd \"" + fBrokenConnDests[j].partialName(true) + "\""); break; } } } // // If the plug is locked, then add a "-l/lock" flag to the // command. // if (destPlug.isLocked) result += " -l on"; // // If the destination attribute is a multi for which index // does not matter, then we must add the "-na/nextAvailable" // flag to the command. // MObject attr = destPlug.attribute; MFnAttribute attrFn = new MFnAttribute(attr); if (!attrFn.indexMatters) result += " -na"; result += (";" + "\n"); } } writeString(f, result); }
/// <summary> /// Convert the Maya texture animation of a MFnDependencyNode in Babylon animations /// </summary> /// <param name="textureDependencyNode">The MFnDependencyNode of the texture</param> /// <returns>A list of texture animation</returns> public List <BabylonAnimation> GetTextureAnimations(MFnDependencyNode textureDependencyNode) { List <BabylonAnimation> animations = new List <BabylonAnimation>(); // Look for a "place2dTexture" object in the connections of the node. // The "place2dTexture" object contains the animation parameters MPlugArray connections = new MPlugArray(); textureDependencyNode.getConnections(connections); int index = 0; string place2dTexture = null; while (index < connections.Count && place2dTexture == null) { MPlug connection = connections[index]; MObject source = connection.source.node; if (source != null && source.hasFn(MFn.Type.kPlace2dTexture)) { MFnDependencyNode node = new MFnDependencyNode(source); place2dTexture = node.name; } index++; } if (place2dTexture != null) { IDictionary <string, string> properties = new Dictionary <string, string> { ["offsetU"] = "uOffset", ["offsetU"] = "uOffset", ["offsetV"] = "vOffset", ["repeatU"] = "uScale", ["repeatV"] = "vScale" }; // Get the animation for each properties for (index = 0; index < properties.Count; index++) { KeyValuePair <string, string> property = properties.ElementAt(index); BabylonAnimation animation = GetAnimationFloat(place2dTexture, property.Key, property.Value); if (animation != null) { animations.Add(animation); } } // For the rotation, convert degree to radian BabylonAnimation rotationAnimation = GetAnimationFloat(place2dTexture, "rotateFrame", "wAng"); if (rotationAnimation != null) { BabylonAnimationKey[] keys = rotationAnimation.keys; for (index = 0; index < keys.Length; index++) { var key = keys[index]; key.values[0] *= (float)(Math.PI / 180d); } animations.Add(rotationAnimation); } } return(animations); }
// // Description: // Overloaded function from MPxDragAndDropBehavior // this method will handle the connection between the slopeShaderNodeCSharp and the shader it is // assigned to as well as any meshes that it is assigned to. // public override void connectNodeToNode(MObject sourceNode, MObject destinationNode, bool force) { MFnDependencyNode src = new MFnDependencyNode(sourceNode); //if we are dragging from a lambert //we want to check what we are dragging //onto. if(sourceNode.hasFn(MFn.Type.kLambert)) { //MObject shaderNode; MPlugArray connections = new MPlugArray(); MObjectArray shaderNodes = new MObjectArray(); shaderNodes.clear(); //if the source node was a lambert //than we will check the downstream connections to see //if a slope shader is assigned to it. // src.getConnections(connections); int i; for(i = 0; i < connections.length; i++) { //check the incoming connections to this plug // MPlugArray connectedPlugs = new MPlugArray(); connections[i].connectedTo(connectedPlugs, true, false); for(uint j = 0; j < connectedPlugs.length; j++) { //if the incoming node is a slope shader than //append the node to the shaderNodes array // MObject currentnode = connectedPlugs[i].node; if (new MFnDependencyNode(currentnode).typeName == "slopeShaderNodeCSharp") { shaderNodes.append(currentnode); } } } //if we found a shading node //than check the destination node //type to see if it is a mesh // if(shaderNodes.length > 0) { MFnDependencyNode dest = new MFnDependencyNode(destinationNode); if(destinationNode.hasFn(MFn.Type.kMesh)) { //if the node is a mesh than for each slopeShaderNodeCSharp //connect the worldMesh attribute to the dirtyShaderPlug //attribute to force an evaluation of the node when the mesh //changes // for(i = 0; i < shaderNodes.length; i++) { MPlug srcPlug = dest.findPlug("worldMesh"); MPlug destPlug = new MFnDependencyNode(shaderNodes[i]).findPlug("dirtyShaderPlug"); if(!srcPlug.isNull && !destPlug.isNull) { string cmd = "connectAttr -na "; cmd += srcPlug.name + " "; cmd += destPlug.name; try { // in slopeShaderBehavior.cpp, this may excute failed but continue on the following code, so we catch it. MGlobal.executeCommand(cmd); } catch (System.Exception) { MGlobal.displayError("ExcuteCommand (" + cmd + ") failed."); } } } //get the shading engine so we can assign the shader //to the mesh after doing the connection // MObject shadingEngine = findShadingEngine(sourceNode); //if there is a valid shading engine than make //the connection // if(!shadingEngine.isNull) { string cmd = "sets -edit -forceElement "; cmd += new MFnDependencyNode(shadingEngine).name + " "; cmd += new MFnDagNode(destinationNode).partialPathName; MGlobal.executeCommand(cmd); } } } } else if (src.typeName == "slopeShaderNodeCSharp") //if we are dragging from a slope shader //than we want to see what we are dragging onto // { if(destinationNode.hasFn(MFn.Type.kMesh)) { //if the user is dragging onto a mesh //than make the connection from the worldMesh //to the dirtyShader plug on the slopeShaderNodeCSharp // MFnDependencyNode dest = new MFnDependencyNode(destinationNode); MPlug srcPlug = dest.findPlug("worldMesh"); MPlug destPlug = src.findPlug("dirtyShaderPlug"); if(!srcPlug.isNull && !destPlug.isNull) { string cmd = "connectAttr -na "; cmd += srcPlug.name + " "; cmd += destPlug.name; MGlobal.executeCommand(cmd); } } } return; }
public override bool shouldBeUsedFor(MObject sourceNode, MObject destinationNode, MPlug sourcePlug, MPlug destinationPlug) { bool result = false; if(sourceNode.hasFn(MFn.Type.kLambert)) { //if the source node was a lambert //than we will check the downstream connections to see //if a slope shader is assigned to it. // MObject shaderNode = new MObject(); MFnDependencyNode src = new MFnDependencyNode(sourceNode); MPlugArray connections = new MPlugArray(); src.getConnections(connections); for(int i = 0; i < connections.length; i++) { //check the incoming connections to this plug // MPlugArray connectedPlugs = new MPlugArray(); connections[i].connectedTo(connectedPlugs, true, false); for(int j = 0; j < connectedPlugs.length; j++) { //if the incoming node is a slope shader than //set shaderNode equal to it and break out of the inner //loop // if(new MFnDependencyNode(connectedPlugs[j].node).typeName == "slopeShaderNodeCSharp") { shaderNode = connectedPlugs[j].node; break; } } //if the shaderNode is not null //than we have found a slopeShaderNodeCSharp // if(!shaderNode.isNull) { //if the destination node is a mesh than we will take //care of this connection so set the result to true //and break out of the outer loop // if(destinationNode.hasFn(MFn.Type.kMesh)) result = true; break; } } } if (new MFnDependencyNode(sourceNode).typeName == "slopeShaderNodeCSharp") //if the sourceNode is a slope shader than check what we //are dropping on to // { if(destinationNode.hasFn(MFn.Type.kLambert)) result = true; else if (destinationNode.hasFn(MFn.Type.kMesh)) result = true; } return result; }
public override void doIt(MArgList args) { MArgDatabase argData; MPxCommandSyntaxFlagAttribute MyAttribute = (MPxCommandSyntaxFlagAttribute)Attribute.GetCustomAttribute(typeof(NodeInfoCmd), typeof(MPxCommandSyntaxFlagAttribute)); MSyntax syntax = new MSyntax(); if (MyAttribute != null) { syntax.addFlag(MyAttribute.ShortFlag, MyAttribute.LongFlag); } else { syntax.addFlag(kQuietFlag, kQuietFlagLong); } try { argData = new MArgDatabase(syntax, args); } catch (System.Exception ex) { MGlobal.displayInfo(ex.Message); } MSelectionList selectList = MGlobal.activeSelectionList; foreach (MObject node in selectList.DependNodes()) { MFnDependencyNode depFn = new MFnDependencyNode(); depFn.setObject(node); string nodename = depFn.name; nodename +=":"; printType(node, nodename); MPlugArray connectedPlugs = new MPlugArray(); try { depFn.getConnections(connectedPlugs); } catch (System.Exception ex) { MGlobal.displayInfo(ex.Message); } uint numberOfPlugs = connectedPlugs.length; string msgFmt = MStringResource.getString(NodeInfoCmd.rConnFound); MGlobal.displayInfo( String.Format(msgFmt, Convert.ToString(numberOfPlugs)) ); string pInfoMsg = MStringResource.getString(NodeInfoCmd.rPlugInfo); for (int i = 0; i < numberOfPlugs; i++ ) { MPlug plug = connectedPlugs[i]; string pInfo = plug.info; MGlobal.displayInfo(pInfoMsg+pInfo); MPlugArray array = new MPlugArray(); plug.connectedTo(array, true, false); string dInfoMsg = MStringResource.getString(rPlugDestOf); for (int j = 0; j < array.length; j++ ) { MObject mnode = array[j].node; printType(mnode, dInfoMsg); } } } return; }
public override bool shouldBeUsedFor(MObject sourceNode, MObject destinationNode, MPlug sourcePlug, MPlug destinationPlug) { bool result = false; if (sourceNode.hasFn(MFn.Type.kLambert)) { //if the source node was a lambert //than we will check the downstream connections to see //if a slope shader is assigned to it. // MObject shaderNode = new MObject(); MFnDependencyNode src = new MFnDependencyNode(sourceNode); MPlugArray connections = new MPlugArray(); src.getConnections(connections); for (int i = 0; i < connections.length; i++) { //check the incoming connections to this plug // MPlugArray connectedPlugs = new MPlugArray(); connections[i].connectedTo(connectedPlugs, true, false); for (int j = 0; j < connectedPlugs.length; j++) { //if the incoming node is a slope shader than //set shaderNode equal to it and break out of the inner //loop // if (new MFnDependencyNode(connectedPlugs[j].node).typeName == "slopeShaderNodeCSharp") { shaderNode = connectedPlugs[j].node; break; } } //if the shaderNode is not null //than we have found a slopeShaderNodeCSharp // if (!shaderNode.isNull) { //if the destination node is a mesh than we will take //care of this connection so set the result to true //and break out of the outer loop // if (destinationNode.hasFn(MFn.Type.kMesh)) { result = true; } break; } } } if (new MFnDependencyNode(sourceNode).typeName == "slopeShaderNodeCSharp") //if the sourceNode is a slope shader than check what we //are dropping on to // { if (destinationNode.hasFn(MFn.Type.kLambert)) { result = true; } else if (destinationNode.hasFn(MFn.Type.kMesh)) { result = true; } } return(result); }
// // Description: // Overloaded function from MPxDragAndDropBehavior // this method will handle the connection between the slopeShaderNodeCSharp and the shader it is // assigned to as well as any meshes that it is assigned to. // public override void connectNodeToNode(MObject sourceNode, MObject destinationNode, bool force) { MFnDependencyNode src = new MFnDependencyNode(sourceNode); //if we are dragging from a lambert //we want to check what we are dragging //onto. if (sourceNode.hasFn(MFn.Type.kLambert)) { //MObject shaderNode; MPlugArray connections = new MPlugArray(); MObjectArray shaderNodes = new MObjectArray(); shaderNodes.clear(); //if the source node was a lambert //than we will check the downstream connections to see //if a slope shader is assigned to it. // src.getConnections(connections); int i; for (i = 0; i < connections.length; i++) { //check the incoming connections to this plug // MPlugArray connectedPlugs = new MPlugArray(); connections[i].connectedTo(connectedPlugs, true, false); for (uint j = 0; j < connectedPlugs.length; j++) { //if the incoming node is a slope shader than //append the node to the shaderNodes array // MObject currentnode = connectedPlugs[i].node; if (new MFnDependencyNode(currentnode).typeName == "slopeShaderNodeCSharp") { shaderNodes.append(currentnode); } } } //if we found a shading node //than check the destination node //type to see if it is a mesh // if (shaderNodes.length > 0) { MFnDependencyNode dest = new MFnDependencyNode(destinationNode); if (destinationNode.hasFn(MFn.Type.kMesh)) { //if the node is a mesh than for each slopeShaderNodeCSharp //connect the worldMesh attribute to the dirtyShaderPlug //attribute to force an evaluation of the node when the mesh //changes // for (i = 0; i < shaderNodes.length; i++) { MPlug srcPlug = dest.findPlug("worldMesh"); MPlug destPlug = new MFnDependencyNode(shaderNodes[i]).findPlug("dirtyShaderPlug"); if (!srcPlug.isNull && !destPlug.isNull) { string cmd = "connectAttr -na "; cmd += srcPlug.name + " "; cmd += destPlug.name; try { // in slopeShaderBehavior.cpp, this may excute failed but continue on the following code, so we catch it. MGlobal.executeCommand(cmd); } catch (System.Exception) { MGlobal.displayError("ExcuteCommand (" + cmd + ") failed."); } } } //get the shading engine so we can assign the shader //to the mesh after doing the connection // MObject shadingEngine = findShadingEngine(sourceNode); //if there is a valid shading engine than make //the connection // if (!shadingEngine.isNull) { string cmd = "sets -edit -forceElement "; cmd += new MFnDependencyNode(shadingEngine).name + " "; cmd += new MFnDagNode(destinationNode).partialPathName; MGlobal.executeCommand(cmd); } } } } else if (src.typeName == "slopeShaderNodeCSharp") //if we are dragging from a slope shader //than we want to see what we are dragging onto // { if (destinationNode.hasFn(MFn.Type.kMesh)) { //if the user is dragging onto a mesh //than make the connection from the worldMesh //to the dirtyShader plug on the slopeShaderNodeCSharp // MFnDependencyNode dest = new MFnDependencyNode(destinationNode); MPlug srcPlug = dest.findPlug("worldMesh"); MPlug destPlug = src.findPlug("dirtyShaderPlug"); if (!srcPlug.isNull && !destPlug.isNull) { string cmd = "connectAttr -na "; cmd += srcPlug.name + " "; cmd += destPlug.name; MGlobal.executeCommand(cmd); } } } return; }
override public void doIt(MArgList args) { MArgDatabase argData; MPxCommandSyntaxFlagAttribute MyAttribute = (MPxCommandSyntaxFlagAttribute)Attribute.GetCustomAttribute(typeof(NodeInfoCmd), typeof(MPxCommandSyntaxFlagAttribute)); MSyntax syntax = new MSyntax(); if (MyAttribute != null) { syntax.addFlag(MyAttribute.ShortFlag, MyAttribute.LongFlag); } else { syntax.addFlag(kQuietFlag, kQuietFlagLong); } try { argData = new MArgDatabase(syntax, args); } catch (System.Exception ex) { MGlobal.displayInfo(ex.Message); } MSelectionList selectList = MGlobal.activeSelectionList; foreach (MObject node in selectList.DependNodes()) { MFnDependencyNode depFn = new MFnDependencyNode(); depFn.setObject(node); string nodename = depFn.name; nodename += ":"; printType(node, nodename); MPlugArray connectedPlugs = new MPlugArray(); try { depFn.getConnections(connectedPlugs); } catch (System.Exception ex) { MGlobal.displayInfo(ex.Message); } uint numberOfPlugs = connectedPlugs.length; string msgFmt = MStringResource.getString(NodeInfoCmd.rConnFound); MGlobal.displayInfo(String.Format(msgFmt, Convert.ToString(numberOfPlugs))); string pInfoMsg = MStringResource.getString(NodeInfoCmd.rPlugInfo); for (int i = 0; i < numberOfPlugs; i++) { MPlug plug = connectedPlugs[i]; string pInfo = plug.info; MGlobal.displayInfo(pInfoMsg + pInfo); MPlugArray array = new MPlugArray(); plug.connectedTo(array, true, false); string dInfoMsg = MStringResource.getString(rPlugDestOf); for (int j = 0; j < array.length; j++) { MObject mnode = array[j].node; printType(mnode, dInfoMsg); } } } return; }