public apiMeshGeomIterator(object userGeometry, MObject component) : base(userGeometry, component) { meshGeometry = (apiMeshGeom)userGeometry; reset(); }
public static MDagPath CreateJoint(string jtName) { MFnIkJoint joint = new MFnIkJoint(); MObject jtObject = joint.create(); return(MDagPath.getAPathTo(jtObject)); }
/// <summary> /// Init the two list influentNodesBySkin and revelantNodesBySkin of a skin cluster. /// By getting the parents of the influent nodes. /// </summary> /// <param name="skin">the skin cluster</param> /// <returns> /// The list of nodes that form the skeleton /// </returns> private List <MObject> GetRevelantNodes(MFnSkinCluster skin) { if (revelantNodesBySkin.ContainsKey(skin)) { return(revelantNodesBySkin[skin]); } List <MObject> influentNodes = GetInfluentNodes(skin); List <MObject> revelantNodes = new List <MObject>(); // Add parents until it's a kWorld foreach (MObject node in influentNodes) { MObject currentNode = node; //MObject parent = findValidParent(node); // A node can have several parents. Which one is the right one ? It seems that the first one is most likely a transform while (!currentNode.apiType.Equals(MFn.Type.kWorld)) { MFnDagNode dagNode = new MFnDagNode(currentNode); if (revelantNodes.Count(revelantNode => Equals(revelantNode, currentNode)) == 0) { revelantNodes.Add(currentNode); } // iter MObject firstParent = dagNode.parent(0); currentNode = firstParent; } } revelantNodesBySkin.Add(skin, revelantNodes); return(revelantNodes); }
// // Description: // Overloaded function from MPxDragAndDropBehavior // this method will assign the correct output from the slope shader // onto the given attribute. // public override void connectNodeToAttr(MObject sourceNode, MPlug destinationPlug, bool force) { MFnDependencyNode src = new MFnDependencyNode(sourceNode); //if we are dragging from a slopeShaderNodeCSharp //to a shader than connect the outColor //plug to the plug being passed in // if(destinationPlug.node.hasFn(MFn.Type.kLambert)) { if (src.typeName == "slopeShaderNodeCSharp") { MPlug srcPlug = src.findPlug("outColor"); if(!srcPlug.isNull && !destinationPlug.isNull) { string cmd = "connectAttr "; cmd += srcPlug.name + " "; cmd += destinationPlug.name; MGlobal.executeCommand(cmd); } } } else { //in all of the other cases we do not need the plug just the node //that it is on // MObject destinationNode = destinationPlug.node; connectNodeToNode(sourceNode, destinationNode, force); } }
public MSelectionList RestoreSelectionOnList(MSelectionList targetList = null, bool selectResult = false) { if (targetList == null || targetList.length == 0) { targetList = BasicFunc.GetSelectedList(); } MSelectionList resultSelection = new MSelectionList(); for (int i = 0; i < targetList.length; i++) { if (i >= selectedIndicesList.Count) { break; } MDagPath dag = new MDagPath(); targetList.getDagPath((uint)i, dag); MFnSingleIndexedComponent sic = new MFnSingleIndexedComponent(); MObject components = sic.create(MFn.Type.kMeshPolygonComponent); sic.addElements(new MIntArray(selectedIndicesList[i])); resultSelection.add(dag, components); //resultSelection.add(dag); } if (selectResult) { BasicFunc.Select(resultSelection); } return(resultSelection); }
/// <summary> /// Return the type of the direct descendants of the node /// </summary> /// <param name="mDagPath"></param> /// <returns> Return Mesh, Camera, Light or Unknown</returns> private MFn.Type getApiTypeOfDirectDescendants(MDagPath mDagPath) { for (uint i = 0; i < mDagPath.childCount; i++) { MObject childObject = mDagPath.child(i); MFnDagNode nodeObject = new MFnDagNode(childObject); switch (childObject.apiType) { case MFn.Type.kMesh: if (IsMeshExportable(nodeObject, mDagPath)) { return(MFn.Type.kMesh); } break; case MFn.Type.kCamera: if (IsCameraExportable(nodeObject, mDagPath)) { return(MFn.Type.kCamera); } break; } // Lights api type are kPointLight, kSpotLight... // Easier to check if has generic light function set rather than check all cases if (mDagPath.hasFn(MFn.Type.kLight) && IsLightExportable(nodeObject, mDagPath)) { // Return generic kLight api type return(MFn.Type.kLight); } } return(MFn.Type.kUnknown); }
// Adds a generic attribute that accepts a float, float2, float3 public static void addComplexFloatGenericAttribute(ref MObject attrObject, string longName, string shortName) { // Create the generic attribute and set the 3 accepts types MFnGenericAttribute gAttr = new MFnGenericAttribute(); attrObject = gAttr.create( longName, shortName ); try { gAttr.addAccept(MFnNumericData.Type.kFloat); gAttr.addAccept(MFnNumericData.Type.k2Float); gAttr.addAccept(MFnNumericData.Type.k3Float); } catch (System.Exception) { MGlobal.displayError("error happens in addAccept"); } gAttr.isWritable = false; gAttr.isStorable = false; // Add the attribute to the node try { addAttribute(attrObject); } catch (System.Exception) { MGlobal.displayError("error happens in addAttribute"); } }
public static void initialize() { MFnNumericAttribute nAttr = new MFnNumericAttribute(); // single float attribute affecting a generic attribute try{ gInputInt = nAttr.create( "gInputInt", "gii", MFnNumericData.Type.kInt, 0 ); } catch (System.Exception) { MGlobal.displayError("error happens in addAccept"); } nAttr.isStorable = true; nAttr.isKeyable = true; try{ addAttribute( gInputInt ); } catch (System.Exception) { MGlobal.displayError("error happens in addAccept"); } addComplexFloatGenericAttribute(ref gOutputFloat_2Float_3Float, "gOutputFloat_2Float_3Float", "gof2f3f" ); try{ attributeAffects( gInputInt, gOutputFloat_2Float_3Float ); } catch (System.Exception) { MGlobal.displayError("error happens in addAccept"); } return; }
public static MFnBlendShapeDeformer GetBlendShape(MObject targetObject = null) { if (targetObject == null) { targetObject = BasicFunc.GetSelectedObject(0); } MDagPath dag_target = MDagPath.getAPathTo(targetObject); MFnDependencyNode node_target = new MFnDependencyNode(targetObject); MPlug plug = node_target.findPlug("inMesh"); Debug.Log("node_target:" + node_target.name + " plug:" + plug.name); MItDependencyGraph mit = new MItDependencyGraph(plug, MFn.Type.kBlendShape, MItDependencyGraph.Direction.kUpstream); //MDagPath dagPath = new MDagPath(); //MItDependencyNodes mitnode = new MItDependencyNodes(MFn.Type.kBlendShape); while (!mit.isDone) { MObject mo = mit.currentItem(); MFnDependencyNode dnode = new MFnDependencyNode(mo); Debug.Log("moing:" + dnode.absoluteName); if (mo.hasFn(MFn.Type.kBlendShape)) { Debug.Log("find blendshape"); return(new MFnBlendShapeDeformer(mo)); } mit.next(); } return(null); }
public override void doIt(MArgList args) { MArgDatabase argData = new MArgDatabase(syntax, args); bool creating = true; if (argData.isFlagSet(kCreateFlag)) { creating = true; } else if (argData.isFlagSet(kDeleteFlag)) { creating = false; } else { throw new ArgumentException("Command Syntax is incorrect", "args"); } if (creating) { lineManipObj = modifier.createNode("simpleLineManipCSharp", MObject.kNullObj); } else { if (lineManipObj != null) { modifier.deleteNode(lineManipObj); } lineManipObj = null; } redoIt(); }
public void RenderPick(Matrix4d viewproj, MObject Root) { GL.Viewport(0, 0, MScreen.Width, MScreen.Height); // Globals.Index = 0; if (pickmaterial == null) { Console.Error.WriteLine("PickMaterial is NULL"); return; } Globals.ShaderOverride = pickmaterial.shader; pickmaterial.shader.Bind(); GL.ClearColor(Color4.White); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); Globals.Index++; Root.Index = Index; Vector3 rgb = IntToRgb(Index); int ccc = RGBtoInt(rgb); Matrix4d offsetmat = Matrix4d.CreateTranslation(-Globals.GlobalOffset); pickmaterial.shader.SetVec3("object_index", rgb); Root.Render(viewproj, offsetmat); Globals.ShaderOverride = null; }
void SetMaterial(MSceneObject mo, string sMaterialID) { if (sMaterialID == null) { sMaterialID = MMaterial.DEFAULT_MATERIAL; } //MSceneObject mo = (MSceneObject)MScene.ModelRoot.FindModuleByInstanceID(e.InstanceID); MObject o = MScene.MaterialRoot.FindModuleByName(sMaterialID); MMaterial mat = null; if (o != null && o.Type == MObject.EType.Material) { mat = (MMaterial)o; if (mat != null) { mo.SetMaterial(mat); mat.MaterialID = sMaterialID; } } if (MassiveTools.IsURL(sMaterialID)) { mat = (MMaterial) new MMaterial("URLShader"); MShader DefaultShader = (MShader)MScene.MaterialRoot.FindModuleByName(MShader.DEFAULT_SHADER); mat.AddShader(DefaultShader); mat.ReplaceTexture(Globals.TexturePool.GetTexture(sMaterialID)); mat.MaterialID = sMaterialID; MScene.MaterialRoot.Add(mat); mo.SetMaterial(mat); mo.material.Setup(); } }
public void Paint(MObject obj) { int x2 = Math.Min(obj.X - obj.Center.X + obj.Width + obj.Parent.X - X, Width); int y2 = Math.Min(obj.Y - obj.Center.Y + obj.Height + obj.Parent.Y - Y, Height); int x; int y = -Math.Min(0, obj.Y - obj.Center.Y + obj.Parent.Y - Y); for (int i = Math.Max(obj.Y - obj.Center.Y + obj.Parent.Y - Y, 0); i < y2; i++) { x = -Math.Min(0, obj.X - obj.Center.X + obj.Parent.X - X); for (int j = Math.Max(obj.X - obj.Center.X + obj.Parent.X - X, 0); j < x2; j++) { if (obj.Char(y, x) != ' ') { if (obj.Char(y, x) == '') { matrix[i, j].S = ' '; } else { matrix[i, j].S = obj.Char(y, x); } } x++; } y++; } for (int i = 0; i < obj.Posterity.Count; i++) { Paint(obj.Posterity[i]); } }
public override void writer(MFileObject file, string optionsString, MPxFileTranslator.FileAccessMode mode) { string fullName = file.fullName; StreamWriter sWriter = new StreamWriter(fullName); sWriter.Write("# Simple text file of custom node information" + Environment.NewLine); MItDependencyNodes iterator = new MItDependencyNodes(); while (!iterator.isDone) { MObject obj = iterator.thisNode; try { MFnDependencyNode dnFn = new MFnDependencyNode(obj); MPxNode userNode = dnFn.userNode; if (userNode != null) { sWriter.Write("# custom node: " + dnFn.name + Environment.NewLine); } } catch (System.Exception) { } iterator.next(); } sWriter.Close(); return; }
//This is a potentially slow operation and can be called every nth frame. void CalcObject(MObject moParent) { Array ar = moParent.Modules.ToArray(); for (int i = 0; i < ar.Length; i++) { MObject m = (MObject)ar.GetValue(i); if (m == null) { continue; } if (m.Renderable) { MSceneObject mo = (MSceneObject)m; //meshes use their parent's transforms if ((mo.Type != EType.Mesh) && (mo.Type != EType.BoneMesh)) { mo.DistanceFromAvatar = Vector3d.Distance(mo.transform.Position, AvatarPos); } if (mo.DistanceFromAvatar > mo.DistanceThreshold) { mo.Index = -2; mo.Clipped = true; //return; } else { mo.Clipped = false; } } CalcObject(m); } }
private void button1_Click(object sender, EventArgs e) { //测试 ManagementBaseObject myInMBO = null; ManagementBaseObject myOutMBO = null; ManagementClass myMClass = new ManagementClass("Win32_NetWorkAdapterConfiguration"); ManagementObjectCollection myMOCollection = myMClass.GetInstances(); foreach (ManagementObject MObject in myMOCollection) { if (!(bool)MObject["IPEnabled"]) { continue; } myInMBO = MObject.GetMethodParameters("EnableStatic"); myInMBO["IPAddress"] = new string[] { textBox1.Text }; myInMBO["SubnetMask"] = new string[] { textBox2.Text }; myOutMBO = MObject.InvokeMethod("EnableStatic", myInMBO, null); //设置网关地址 myInMBO = MObject.GetMethodParameters("SetGateways"); myInMBO["DefaultIPGateway"] = new string[] { textBox3.Text }; myOutMBO = MObject.InvokeMethod("SetGateways", myInMBO, null); //设置DNS myInMBO = MObject.GetMethodParameters("SetDNSServerSearchOrder"); myInMBO["DNSServerSearchOrder"] = new string[] { textBox4.Text, textBox5.Text }; myOutMBO = MObject.InvokeMethod("SetDNSServerSearchOrder", myInMBO, null); break; } ShowInfo(); MessageBox.Show("IP地址设置成功!"); }
/// <summary> /// /// </summary> /// <param name="isFull">If true all nodes are printed, otherwise only relevant ones</param> private void PrintDAG(bool isFull, MObject root = null) { var dagIterator = new MItDag(MItDag.TraversalType.kDepthFirst); if (root != null) { dagIterator.reset(root); } RaiseMessage("DAG: " + (isFull ? "full" : "relevant")); while (!dagIterator.isDone) { MDagPath mDagPath = new MDagPath(); dagIterator.getPath(mDagPath); if (isFull || isNodeRelevantToExportRec(mDagPath) || mDagPath.apiType == MFn.Type.kMesh || mDagPath.apiType == MFn.Type.kCamera || mDagPath.hasFn(MFn.Type.kLight) || mDagPath.apiType == MFn.Type.kLocator) { RaiseMessage("name=" + mDagPath.partialPathName + "\t type=" + mDagPath.apiType, (int)dagIterator.depth + 1); } else { dagIterator.prune(); } dagIterator.next(); } }
public static void NotifyChange(object sender, MObject mo, GraphChangedEvent.ChangeType Reason) { if (GraphChangeHandler != null) { GraphChangeHandler(sender, new GraphChangedEvent(mo, Reason)); } }
// // Takes the nodes that are on the active selection list and adds an // attribute changed callback to each one. // public override void doIt(MArgList args) { MObject node = new MObject(); MSelectionList list = new MSelectionList(); // Register node callbacks for all nodes on the active list. // MGlobal.getActiveSelectionList( list ); for ( uint i=0; i<list.length; i++ ) { list.getDependNode( i, node ); try { node.AttributeChanged += userCB; } catch (Exception) { MGlobal.displayInfo("MNodeMessage.addCallback failed\n"); continue; } // C# SDK will cleanup events, when this plugin is unloaded // callbacks.append(node); } return; }
/// <summary> /// Find a bone in the skin cluster connections. /// From this bone travel the Dag up to the root node. /// </summary> /// <param name="skin">The skin cluster</param> /// <returns> /// The root node of the skeleton. /// </returns> private MObject GetRootNode(MFnSkinCluster skin) { MObject rootJoint = null; if (rootBySkin.ContainsKey(skin)) { return(rootBySkin[skin]); } // Get a joint of the skin rootJoint = GetInfluentNodes(skin)[0]; // Check the joint parent until it's a kWorld MFnDagNode mFnDagNode = new MFnDagNode(rootJoint); MObject firstParent = mFnDagNode.parent(0); MFnDependencyNode node = new MFnDependencyNode(firstParent); while (!firstParent.apiType.Equals(MFn.Type.kWorld)) { rootJoint = firstParent; mFnDagNode = new MFnDagNode(rootJoint); firstParent = mFnDagNode.parent(0); node = new MFnDependencyNode(firstParent); } rootBySkin.Add(skin, rootJoint); return(rootJoint); }
private float getMultiplier(MDagPath objPath) { // Retrieve value of the size attribute from the node MObject footprintNode = objPath.node; if (!footprintNode.isNull) { MPlug plug = new MPlug(footprintNode, footPrint.size); if (!plug.isNull) { MDistance sizeVal = new MDistance(); try { plug.getValue(sizeVal); return((float)sizeVal.asCentimeters); } catch (Exception) { MGlobal.displayInfo("Error doing getValue on plugin"); } } } return(1.0f); }
//====================================================================== // // Check the parsed arguments and do/undo/redo the command as appropriate // void checkArgs(ref MArgDatabase argsDb) { MSelectionList objects = new MSelectionList(); argsDb.getObjects(objects); for (uint i = 0; i < objects.length; ++i) { MDagPath dagPath = new MDagPath(); objects.getDagPath((uint)i, dagPath); MFnDagNode dagNode = new MFnDagNode(dagPath.node); MObject obj = dagNode.child(0); if (obj.apiTypeStr == "kMesh") { fMesh = new MFnMesh(obj); fObj = obj; fObjTransform = dagPath.node; } } if( fMesh == null || fObj == null || fObjTransform == null ) { string errMsg = MStringResource.getString(MetaDataRegisterMStringResources.kObjectNotFoundError); throw new ArgumentException(errMsg, "argsDb"); } }
/// <summary> /// Originally written in C++ by RobTheBloke. /// See https://nccastaff.bournemouth.ac.uk/jmacey/RobTheBloke/www/research/maya/mfnmesh.htm /// </summary> /// <param name="shadingEngine"></param> /// <returns>The shader name.</returns> private static MObjectArray GetMaterials(MObject shadingEngine) { // attach a function set to the shading engine var fn = new MFnDependencyNode(shadingEngine); // get access to the surfaceShader attribute. This will be connected to // lambert , phong nodes etc. var sShader = fn.findPlug("surfaceShader"); // will hold the connections to the surfaceShader attribute var materials = new MPlugArray(); // get the material connected to the surface shader sShader.connectedTo(materials, true, false); var materialsObjects = new MObjectArray(); if (materials.Count <= 0) { return(materialsObjects); } // if we found a material foreach (var plug in materials) { materialsObjects.Add(plug.node); } return(materialsObjects); }
public override bool updateCompleteVertexGroup(MObject component) // // Description // Make sure complete vertex group data is up-to-date. // Returns true if the component was updated, false if it was already ok. // // This is used by deformers when deforming the "whole" object and // not just selected components. // { MFnSingleIndexedComponent fnComponent = new MFnSingleIndexedComponent(component); // Make sure there is non-null geometry and that the component // is "complete". A "complete" component represents every // vertex in the shape. // if ((null != fGeometry) && (fnComponent.isComplete)) { int maxVerts; fnComponent.getCompleteData(out maxVerts); int numVertices = (int)fGeometry.vertices.length; if ((numVertices > 0) && (maxVerts != numVertices)) { // Set the component to be complete, i.e. the elements in // the component will be [0:numVertices-1] // fnComponent.setCompleteData(numVertices); return(true); } } return(false); }
public override bool doRelease(M3dView view) { // Scale nodes on the selection list. // Simple implementation that does not // support undo. MSelectionList list = new MSelectionList(); MGlobal.getActiveSelectionList(list); MObject node = new MObject(); for (MItSelectionList iter = new MItSelectionList(list); !iter.isDone; iter.next()) { iter.getDependNode(node); MFnTransform xform; try { xform = new MFnTransform(node); } catch (System.Exception) { continue; } double[] newScale = new double[3]; newScale[0] = mousePointGlName.x + 1; newScale[1] = mousePointGlName.y + 1; newScale[2] = mousePointGlName.z + 1; xform.setScale(newScale); } return(true); }
public static void RemoveUnusedTextures(MSelectionList list) { if (list == null) { Debug.Log("list null"); return; } List <MObject> deleteList = new List <MObject>(); for (int i = 0; i < list.length; i++) { MObject mo = new MObject(); list.getDependNode((uint)i, mo); MFnDependencyNode imageNode = new MFnDependencyNode(mo); MPlug texOutputPlug = imageNode.findPlug(ConstantValue.plugName_fileTexOutputColor); MPlugArray destPlugs = new MPlugArray(); texOutputPlug.destinations(destPlugs); if (destPlugs.Count == 0) { deleteList.Add(mo); Debug.Log("remove no use:" + imageNode.absoluteName); } else { Debug.Log("still used:" + imageNode.absoluteName); for (int j = 0; j < destPlugs.length; j++) { Debug.Log(" by:" + destPlugs[0].partialName(true)); } } } BasicFunc.DeleteObjects(deleteList); }
public static Dictionary <string, object> getSmoothMesh(MFnMesh mayaMesh) { MObject tempMesh = new MObject(); MFnMeshData meshData = new MFnMeshData(); MObject dataObject; MObject smoothedObj = new MObject(); dataObject = meshData.create(); smoothedObj = mayaMesh.generateSmoothMesh(dataObject); MFnMesh meshFn = new MFnMesh(smoothedObj); // var smoothMeshObj = mayaMesh.generateSmoothMesh(); // MFnDependencyNode mfnDn = new MFnDependencyNode(smoothedObj); // var meshDag = DMInterop.getDagNode(mfnDn.name); Mesh dynamoMesh = DMMesh.MTDMeshFromMayaMesh(meshFn, MSpace.Space.kObject); //MGlobal.displayInfo(smoothedObj.apiTypeStr); //MGlobal.deleteNode(smoothedObj); return(new Dictionary <string, object> { { "mesh", dynamoMesh }, { "mayaMesh", meshFn } }); }
// Adds a generic attribute that accepts a float, float2, float3 public static void addComplexFloatGenericAttribute(ref MObject attrObject, string longName, string shortName) { // Create the generic attribute and set the 3 accepts types MFnGenericAttribute gAttr = new MFnGenericAttribute(); attrObject = gAttr.create(longName, shortName); try { gAttr.addAccept(MFnNumericData.Type.kFloat); gAttr.addAccept(MFnNumericData.Type.k2Float); gAttr.addAccept(MFnNumericData.Type.k3Float); } catch (System.Exception) { MGlobal.displayError("error happens in addAccept"); } gAttr.isWritable = false; gAttr.isStorable = false; // Add the attribute to the node try { addAttribute(attrObject); } catch (System.Exception) { MGlobal.displayError("error happens in addAttribute"); } }
public void OnEnter(StateMachine machine, IState prevState, object param) { sceneManager.rightEvents.TriggerPressed += rightTriggerPressed; sceneManager.rightEvents.GripPressed += rightGripPressed; status = STATUS.SELECT; curObj = null; }
//====================================================================== // // Check the parsed arguments and do/undo/redo the command as appropriate // void checkArgs(ref MArgDatabase argsDb) { MSelectionList objects = new MSelectionList(); argsDb.getObjects(objects); for (uint i = 0; i < objects.length; ++i) { MDagPath dagPath = new MDagPath(); objects.getDagPath((uint)i, dagPath); MFnDagNode dagNode = new MFnDagNode(dagPath.node); MObject obj = dagNode.child(0); if (obj.apiTypeStr == "kMesh") { fMesh = new MFnMesh(obj); fObj = obj; fObjTransform = dagPath.node; } } if (fMesh == null || fObj == null || fObjTransform == null) { string errMsg = MStringResource.getString(MetaDataRegisterMStringResources.kObjectNotFoundError); throw new ArgumentException(errMsg, "argsDb"); } }
private MFnSkinCluster getMFnSkinCluster(MFnMesh mFnMesh) { MFnSkinCluster mFnSkinCluster = null; MPlugArray connections = new MPlugArray(); mFnMesh.getConnections(connections); foreach (MPlug connection in connections) { MObject source = connection.source.node; if (source != null) { if (source.hasFn(MFn.Type.kSkinClusterFilter)) { mFnSkinCluster = new MFnSkinCluster(source); } if ((mFnSkinCluster == null) && (source.hasFn(MFn.Type.kSet) || source.hasFn(MFn.Type.kPolyNormalPerVertex))) { mFnSkinCluster = getMFnSkinCluster(source); } } } return(mFnSkinCluster); }
public static void DeleteUnusedShadingNode(MSelectionList list) { if (list == null) { Debug.Log("list null"); return; } List <MFnDependencyNode> deleteList = new List <MFnDependencyNode>(); for (int i = 0; i < list.length; i++) { MObject mo = new MObject(); list.getDependNode((uint)i, mo); if (mo.hasFn(MFn.Type.kShadingEngine)) { MFnDependencyNode sgNode = new MFnDependencyNode(mo); MPlug plug_dagSetMemebers = sgNode.findPlug(ConstantValue.plugName_dagSetMembers); Debug.Log("numelements:" + plug_dagSetMemebers.numElements); if (plug_dagSetMemebers.numElements == 0) { deleteList.Add(sgNode); } } //Debug.Log(sgNode.name); } BasicFunc.DeleteObjects(deleteList); }
private bool isAiStandardSurfaceNotStdNotPBS(MFnDependencyNode materialDependencyNode) { // TODO - This is a fix until found a better way to identify AiStandardSurface material MObject materialObject = materialDependencyNode.objectProperty; return(!materialObject.hasFn(MFn.Type.kLambert) && !isStingrayPBSMaterial(materialDependencyNode) && isAiStandardSurface(materialDependencyNode)); }
public void receiveCurveFromMaya(string node_name, out Point3DCollection controlVertices, out List<double> weights, out List<double> knots, out int degree, out bool closed, out bool rational) { MPlug plLocal = getPlug(node_name, "local"); MObject oLocal = new MObject(); plLocal.getValue(oLocal); MFnNurbsCurve nc = new MFnNurbsCurve(oLocal); MPointArray p_aCVs = new MPointArray(); nc.getCVs(p_aCVs, MSpace.Space.kWorld); controlVertices = new Point3DCollection(); weights = new List<double>(); foreach (MPoint p in p_aCVs) { controlVertices.Add(new Point3D(p.x, p.y, p.z)); weights.Add(1.0); } double min = 0, max = 0; nc.getKnotDomain(ref min, ref max); MDoubleArray d_aKnots = new MDoubleArray(); nc.getKnots(d_aKnots); knots = new List<double>(); knots.Add(min); foreach (double d in d_aKnots) { knots.Add(d); } knots.Add(max); degree = nc.degree; closed = nc.form == MFnNurbsCurve.Form.kClosed ? true : false; rational = true; }
protected override void Awake() { base.Awake(); if (_rTrans == null) _rTrans = GetComponent<RectTransform>(); if (_mObj == null) _mObj = transform.GetComponentInParentRecursively<MObject>(); }
/// <summary> /// Init the list influentNodesBySkin of a skin cluster. /// By find the kjoint that are connected to the skin. /// </summary> /// <param name="skin">the skin cluster</param> /// <returns> /// The list of skin kjoint /// </returns> private List <MObject> GetInfluentNodes(MFnSkinCluster skin) { if (influentNodesBySkin.ContainsKey(skin)) { return(influentNodesBySkin[skin]); } List <MObject> influentNodes = new List <MObject>(); // Get all influenting nodes MPlugArray connections = new MPlugArray(); skin.getConnections(connections); foreach (MPlug connection in connections) { MObject source = connection.source.node; if (source != null && source.hasFn(MFn.Type.kJoint)) { if (influentNodes.Count(node => Equals(node, source)) == 0) { influentNodes.Add(source); } } } influentNodesBySkin.Add(skin, influentNodes); return(influentNodes); }
public static void initialize() { MFnNumericAttribute nAttr = new MFnNumericAttribute(); // single float attribute affecting a generic attribute try{ gInputInt = nAttr.create("gInputInt", "gii", MFnNumericData.Type.kInt, 0); } catch (System.Exception) { MGlobal.displayError("error happens in addAccept"); } nAttr.isStorable = true; nAttr.isKeyable = true; try{ addAttribute(gInputInt); } catch (System.Exception) { MGlobal.displayError("error happens in addAccept"); } addComplexFloatGenericAttribute(ref gOutputFloat_2Float_3Float, "gOutputFloat_2Float_3Float", "gof2f3f"); try{ attributeAffects(gInputInt, gOutputFloat_2Float_3Float); } catch (System.Exception) { MGlobal.displayError("error happens in addAccept"); } return; }
public override void connectToDependNode(MObject node) { // Find the rotate and rotatePivot plugs on the node. These plugs will // be attached either directly or indirectly to the manip values on the // rotate manip. // MFnDependencyNode nodeFn = new MFnDependencyNode(node); MPlug rPlug = nodeFn.findPlug("rotate"); MPlug rcPlug = nodeFn.findPlug("rotatePivot"); // If the translate pivot exists, it will be used to move the state manip // to a convenient location. // MPlug tPlug = nodeFn.findPlug("translate"); // To avoid having the object jump back to the default rotation when the // manipulator is first used, extract the existing rotation from the node // and set it as the initial rotation on the manipulator. // MEulerRotation existingRotation = new MEulerRotation(vectorPlugValue(rPlug)); MVector existingTranslation = new MVector(vectorPlugValue(tPlug)); // // The following code configures default settings for the rotate // manipulator. // MFnRotateManip rotateManip = new MFnRotateManip(fRotateManip); rotateManip.setInitialRotation(existingRotation); rotateManip.setRotateMode(MFnRotateManip.RotateMode.kObjectSpace); rotateManip.displayWithNode(node); // Add a callback function to be called when the rotation value changes // //rotatePlugIndex = addManipToPlugConversionCallback( rPlug, (manipToPlugConversionCallback)&exampleRotateManip::rotationChangedCallback ); ManipToPlugConverion[rPlug] = rotationChangedCallback; // get the index of plug rotatePlugIndex = this[rPlug]; // Create a direct (1-1) connection to the rotation center plug // rotateManip.connectToRotationCenterPlug(rcPlug); // Place the state manip at a distance of 2.0 units away from the object // along the X-axis. // MFnStateManip stateManip = new MFnStateManip(fStateManip); MVector delta = new MVector(2, 0, 0); stateManip.setTranslation(existingTranslation + delta, MSpace.Space.kTransform); finishAddingManips(); base.connectToDependNode(node); }
public static bool initialize() { MFnUnitAttribute unitFn = new MFnUnitAttribute(); size = unitFn.create( "size", "sz", MFnUnitAttribute.Type.kDistance ); unitFn.setDefault( 1.0 ); addAttribute( size ); return true; }
public TrackingObject(MObject source) { this.Position = new Vector2D((double)source.X(), (double)source.Y()); this.Area = source.Area(); this.Width = source.Width(); this.Height = source.Height(); this.Left = source.Left(); this.Right = source.Right(); this.Top = source.Top(); this.Bottom = source.Bottom(); }
protected MObject createMesh(MTime time, ref MObject outData) { int numVertices, frame; float cubeSize; MFloatPointArray points = new MFloatPointArray(); MFnMesh meshFS = new MFnMesh(); // Scale the cube on the frame number, wrap every 10 frames. frame = (int)time.asUnits(MTime.Unit.kFilm); if (frame == 0) frame = 1; cubeSize = 0.5f * (float)(frame % 10); const int numFaces = 6; numVertices = 8; MFloatPoint vtx_1 = new MFloatPoint(-cubeSize, -cubeSize, -cubeSize); MFloatPoint vtx_2 = new MFloatPoint(cubeSize, -cubeSize, -cubeSize); MFloatPoint vtx_3 = new MFloatPoint(cubeSize, -cubeSize, cubeSize); MFloatPoint vtx_4 = new MFloatPoint(-cubeSize, -cubeSize, cubeSize); MFloatPoint vtx_5 = new MFloatPoint(-cubeSize, cubeSize, -cubeSize); MFloatPoint vtx_6 = new MFloatPoint(-cubeSize, cubeSize, cubeSize); MFloatPoint vtx_7 = new MFloatPoint(cubeSize, cubeSize, cubeSize); MFloatPoint vtx_8 = new MFloatPoint(cubeSize, cubeSize, -cubeSize); points.append(vtx_1); points.append(vtx_2); points.append(vtx_3); points.append(vtx_4); points.append(vtx_5); points.append(vtx_6); points.append(vtx_7); points.append(vtx_8); // Set up an array containing the number of vertices // for each of the 6 cube faces (4 verticies per face) // int[] face_counts = { 4, 4, 4, 4, 4, 4 }; MIntArray faceCounts = new MIntArray(face_counts); // Set up and array to assign vertices from points to each face // int[] face_connects = { 0, 1, 2, 3, 4, 5, 6, 7, 3, 2, 6, 5, 0, 3, 5, 4, 0, 4, 7, 1, 1, 7, 6, 2 }; MIntArray faceConnects = new MIntArray(face_connects); MObject newMesh = meshFS.create(numVertices, numFaces, points, faceCounts, faceConnects, outData); return newMesh; }
public override MPxGeometryIterator geometryIteratorSetup(MObjectArray componentList, MObject components, bool forReadOnly) { apiSimpleShapeIterator result; if (components.isNull) { result = new apiSimpleShapeIterator(controlPoints, componentList); } else { result = new apiSimpleShapeIterator(controlPoints, components); } return result; }
////////////////////////////////////////////////////////////////// // // Overrides from MPxGeometryData // ////////////////////////////////////////////////////////////////// public override MPxGeometryIterator iterator( MObjectArray componentList, MObject component, bool useComponents) { apiMeshGeomIterator result = null; if ( useComponents ) { result = new apiMeshGeomIterator( fGeometry, componentList ); } else { result = new apiMeshGeomIterator( fGeometry, component ); } return result; }
public override void createVertexStream(MObject objPath, MVertexBuffer vertexBuffer, MComponentDataIndexing targetIndexing, MComponentDataIndexing sharedIndexing, MVertexBufferArray sourceStreams) { // get the descriptor from the vertex buffer. // It describes the format and layout of the stream. MVertexBufferDescriptor descriptor = vertexBuffer.descriptor; // we are expecting a float stream. if (descriptor.dataType != Autodesk.Maya.OpenMayaRender.MHWRender.MGeometry.DataType.kFloat) return; // we are expecting a float2 if (descriptor.dimension != 2) return; // we are expecting a texture channel if (descriptor.semantic != Autodesk.Maya.OpenMayaRender.MHWRender.MGeometry.Semantic.kTexture) return; // get the mesh from the current path, if it is not a mesh we do nothing. MFnMesh mesh = null; try { mesh = new MFnMesh(objPath); } catch(System.Exception) { return; // failed } MUintArray indices = targetIndexing.indicesProperty; uint vertexCount = indices.length; if (vertexCount <= 0) return; unsafe { // acquire the buffer to fill with data. float * buffer = (float *)vertexBuffer.acquire(vertexCount); for (int i = 0; i < vertexCount; i++) { // Here we are embedding some custom data into the stream. // The included effects (vertexBufferGeneratorGL.cgfx and // vertexBufferGeneratorDX11.fx) will alternate // red, green, and blue vertex colored triangles based on this input. *(buffer++) = 1.0f; *(buffer++) = (float)indices[i]; // color index } // commit the buffer to signal completion. vertexBuffer.commit( (byte *)buffer); } }
public Point3DCollection receiveVertexPositionsFromMaya(string node_name) { MPlug plLocal = getPlug(node_name, "outMesh"); MObject oOutMesh = new MObject(); plLocal.getValue(oOutMesh); MFnMesh m = new MFnMesh(oOutMesh); MPointArray p_aVertices = new MPointArray(); m.getPoints(p_aVertices, MSpace.Space.kWorld); Point3DCollection vertices = new Point3DCollection(); foreach (MPoint p in p_aVertices) { vertices.Add(new Point3D(p.x, p.y, p.z)); } return vertices; }
public static void initialize() { MFnUnitAttribute unitAttr = new MFnUnitAttribute(); MFnTypedAttribute typedAttr = new MFnTypedAttribute(); animCube.time = unitAttr.create("time", "tm", MFnUnitAttribute.Type.kTime, 0.0); animCube.outputMesh = typedAttr.create("outputMesh", "out", MFnData.Type.kMesh); typedAttr.isStorable = false; addAttribute(animCube.time); addAttribute(animCube.outputMesh); attributeAffects(animCube.time, animCube.outputMesh); }
public static bool initializer() { MFnEnumAttribute enumAttr = new MFnEnumAttribute(); // Create the layerType attribute and define its enum values. // exCameraSet.layerTypeAttr = enumAttr.create("layerType", "lt", 0); enumAttr.addField("Mono", 0); enumAttr.addField("Left", 1); enumAttr.addField("Right", 2); // Make this attribute a multi so it can store a value per camera layer. // enumAttr.isArray = true; return true; }
public static void initialize() // // Description // // Attribute (static) initialization. // { MFnNumericAttribute numAttr = new MFnNumericAttribute(); MFnEnumAttribute enumAttr = new MFnEnumAttribute(); MFnTypedAttribute typedAttr = new MFnTypedAttribute(); // ----------------------- INPUTS ------------------------- size = numAttr.create("size", "sz", MFnNumericData.Type.kDouble, 1.0); numAttr.isArray = false; numAttr.usesArrayDataBuilder = false; numAttr.isHidden = false; numAttr.isKeyable = true; addAttribute(size); shapeType = enumAttr.create("shapeType", "st", 0); enumAttr.addField("cube", 0); enumAttr.addField("sphere", 1); enumAttr.isHidden = false; enumAttr.isKeyable = true; addAttribute(shapeType); inputMesh = typedAttr.create("inputMesh", "im", MFnData.Type.kMesh); typedAttr.isHidden = true; addAttribute(inputMesh); // ----------------------- OUTPUTS ------------------------- outputSurface = typedAttr.create("outputSurface", "os", new MTypeId(apiMeshData.id)); typedAttr.isWritable = false; addAttribute(outputSurface); // ---------- Specify what inputs affect the outputs ---------- // attributeAffects(inputMesh, outputSurface); attributeAffects(size, outputSurface); attributeAffects(shapeType, outputSurface); }
public override bool getSourceIndexing(MObject obj, MComponentDataIndexing sourceIndexing) { // get the mesh from the current path, if it is not a mesh we do nothing. MFnMesh mesh = null; try { mesh = new MFnMesh(obj); } catch(System.Exception) { return false; } // if it is an empty mesh we do nothing. int numPolys = mesh.numPolygons; if (numPolys <= 0) return false; // for each face MUintArray vertToFaceVertIDs = sourceIndexing.indicesProperty; uint faceNum = 0; for (int i = 0; i < numPolys; i++) { // assign a color ID to all vertices in this face. uint faceColorID = faceNum % 3; int vertexCount = mesh.polygonVertexCount(i); for (int j = 0; j < vertexCount; j++) { // set each face vertex to the face color vertToFaceVertIDs.append(faceColorID); } faceNum++; } // assign the source indexing sourceIndexing.setComponentType(MComponentDataIndexing.MComponentType.kFaceVertex); return true; }
public static void initialize() { MFnNumericAttribute numAttr = new MFnNumericAttribute(); MFnTypedAttribute typedAttr = new MFnTypedAttribute(); // ----------------------- INPUTS -------------------------- inputSurface = typedAttr.create("inputSurface", "is", new MTypeId(apiMeshData.id)); typedAttr.isStorable = false; addAttribute( inputSurface ); // ----------------------- OUTPUTS ------------------------- // bbox attributes // bboxCorner1 = numAttr.create( "bboxCorner1", "bb1", MFnNumericData.Type.k3Double, 0 ); numAttr.isArray = false; numAttr.usesArrayDataBuilder = false; numAttr.isHidden = false; numAttr.isKeyable = false; addAttribute( bboxCorner1 ); bboxCorner2 = numAttr.create( "bboxCorner2", "bb2", MFnNumericData.Type.k3Double, 0 ); numAttr.isArray = false; numAttr.usesArrayDataBuilder = false; numAttr.isHidden = false; numAttr.isKeyable = false; addAttribute( bboxCorner2 ); // local/world output surface attributes // outputSurface = typedAttr.create("outputSurface", "os", new MTypeId(apiMeshData.id)); addAttribute( outputSurface ); typedAttr.isWritable = false; worldSurface = typedAttr.create("worldSurface", "ws", new MTypeId(apiMeshData.id)); typedAttr.isCached = false; typedAttr.isWritable = false; typedAttr.isArray = true; typedAttr.usesArrayDataBuilder = true; typedAttr.disconnectBehavior = MFnAttribute.DisconnectBehavior.kDelete; typedAttr.isWorldSpace = true; addAttribute( worldSurface ); // Cached surface used for file IO // cachedSurface = typedAttr.create("cachedSurface", "cs", new MTypeId(apiMeshData.id)); typedAttr.isReadable = true; typedAttr.isWritable = true; typedAttr.isStorable = true; addAttribute( cachedSurface ); // ---------- Specify what inputs affect the outputs ---------- // attributeAffects( inputSurface, outputSurface ); attributeAffects( inputSurface, worldSurface ); attributeAffects( outputSurface, worldSurface ); attributeAffects( inputSurface, bboxCorner1 ); attributeAffects( inputSurface, bboxCorner2 ); attributeAffects( cachedSurface, outputSurface ); attributeAffects( cachedSurface, worldSurface ); attributeAffects( mControlPoints, outputSurface ); attributeAffects( mControlValueX, outputSurface ); attributeAffects( mControlValueY, outputSurface ); attributeAffects( mControlValueZ, outputSurface ); attributeAffects( mControlPoints, cachedSurface ); attributeAffects( mControlValueX, cachedSurface ); attributeAffects( mControlValueY, cachedSurface ); attributeAffects( mControlValueZ, cachedSurface ); attributeAffects( mControlPoints, worldSurface ); attributeAffects( mControlValueX, worldSurface ); attributeAffects( mControlValueY, worldSurface ); attributeAffects( mControlValueZ, worldSurface ); }
// // Description // // Creates a geometry iterator compatible with his shape. // // Arguments // // componentList - list of components to be iterated // components - component to be iterator // forReadOnly - // // Returns // // An iterator for the components // // Associates a user defined iterator with the shape (components) // public override MPxGeometryIterator geometryIteratorSetup( MObjectArray componentList, MObject components, bool forReadOnly = false) { apiMeshGeomIterator result = null; if ( components.isNull ) { result = new apiMeshGeomIterator( meshGeom(), componentList ); } else { result = new apiMeshGeomIterator( meshGeom(), components ); } return result; }
// // Description // // Converts the given component values into a selection list of plugs. // This method is used to map components to attributes. // // Arguments // // component - the component to be translated to a plug/attribute // list - a list of plugs representing the passed in component // public override void componentToPlugs(MObject component, MSelectionList list) { if ( component.hasFn(MFn.Type.kSingleIndexedComponent) ) { MFnSingleIndexedComponent fnVtxComp = new MFnSingleIndexedComponent( component ); MObject thisNode = thisMObject(); MPlug plug = new MPlug( thisNode, mControlPoints ); // If this node is connected to a tweak node, reset the // plug to point at the tweak node. // convertToTweakNodePlug(plug); int len = fnVtxComp.elementCount; for ( int i = 0; i < len; i++ ) { plug.selectAncestorLogicalIndex((uint)fnVtxComp.element(i), plug.attribute); list.add(plug); } } }
// // Description // // Returns the bounding box for this object. // It is a good idea not to recompute here as this funcion is called often. // public override MBoundingBox boundingBox() { MObject thisNode = thisMObject(); MPlug c1Plug = new MPlug( thisNode, bboxCorner1 ); MPlug c2Plug = new MPlug( thisNode, bboxCorner2 ); MObject corner1Object = new MObject(); MObject corner2Object = new MObject(); c1Plug.getValue( corner1Object ); c2Plug.getValue( corner2Object ); double[] corner1 = new double[3]; double[] corner2 = new double[3]; MFnNumericData fnData = new MFnNumericData(); fnData.setObject( corner1Object ); fnData.getData(out corner1[0], out corner1[1], out corner1[2]); fnData.setObject( corner2Object ); fnData.getData(out corner2[0], out corner2[1], out corner2[2]); MPoint corner1Point = new MPoint( corner1[0], corner1[1], corner1[2] ); MPoint corner2Point = new MPoint( corner2[0], corner2[1], corner2[2] ); return new MBoundingBox( corner1Point, corner2Point ); }
// // Description // // Specifies that this shape can provide an iterator for getting/setting // control point values. // // Arguments // // writable - Maya asks for an iterator that can set points if this is true // forReadOnly - Maya asking for an iterator for querying only // public override bool acceptsGeometryIterator( MObject obj, bool writeable = true, bool forReadOnly = false) { return true; }
// // Description // // Returns offsets for the given components to be used my the // move tool in normal/u/v mode. // // Arguments // // component - components to calculate offsets for // direction - array of offsets to be filled // mode - the type of offset to be calculated // normalize - specifies whether the offsets should be normalized // // Returns // // true if the offsets could be calculated, false otherwise // // Support the move tools normal/u/v mode (components) // public override bool vertexOffsetDirection( MObject component, MVectorArray direction, MVertexOffsetMode mode, bool normalize) { bool offsetOkay = false ; MFnSingleIndexedComponent fnComp = new MFnSingleIndexedComponent( component ); if ( component.apiType != MFn.Type.kMeshVertComponent ) { return false; } offsetOkay = true ; apiMeshGeom geomPtr = meshGeom(); if ( null == geomPtr ) { return false; } // For each vertex add the appropriate offset // int count = fnComp.elementCount; for ( int idx=0; idx<count; idx++ ) { MVector normal = geomPtr.normals[ fnComp.element(idx) ]; if( mode == MVertexOffsetMode.kNormal ) { if( normalize ) normal.normalize() ; direction.append( normal ); } else { // Construct an orthonormal basis from the normal // uAxis, and vAxis are the new vectors. // MVector uAxis = new MVector(); MVector vAxis = new MVector(); uint i, j, k; double a; normal.normalize(); i = 0; a = Math.Abs( normal[0] ); if ( a < Math.Abs(normal[1]) ) { i = 1; a = Math.Abs(normal[1]); } if ( a < Math.Abs(normal[2]) ) { i = 2; } j = (i+1)%3; k = (j+1)%3; a = Math.Sqrt(normal[i]*normal[i] + normal[j]*normal[j]); uAxis[i] = -normal[j]/a; uAxis[j] = normal[i]/a; uAxis[k] = 0.0; vAxis = normal.crossProduct( uAxis ); if ( mode == MVertexOffsetMode.kUTangent || mode == MVertexOffsetMode.kUVNTriad ) { if( normalize ) uAxis.normalize() ; direction.append( uAxis ); } if ( mode == MVertexOffsetMode.kVTangent || mode == MVertexOffsetMode.kUVNTriad ) { if( normalize ) vAxis.normalize() ; direction.append( vAxis ); } if ( mode == MVertexOffsetMode.kUVNTriad ) { if( normalize ) normal.normalize() ; direction.append( normal ); } } } return offsetOkay; }
// // Description // // During file save this method is called to determine which // attributes of this node should get written. The default behavior // is to only save attributes whose values differ from the default. // // // public override bool shouldSave(MPlug plug, ref bool result) { if( plug.attribute.equalEqual(mControlPoints) || plug.attribute.equalEqual(mControlValueX) || plug.attribute.equalEqual(mControlValueY) || plug.attribute.equalEqual(mControlValueZ) ) { if( hasHistory() ) { // Calling this will only write tweaks if they are // different than the default value. // return base.shouldSave( plug, ref result ); } else { result = false; } } else if ( plug.attribute.equalEqual(cachedSurface) ) { if ( hasHistory() ) { result = false; } else { MObject data = new MObject(); plug.getValue( data ); result = ( ! data.isNull ); } } else { return base.shouldSave( plug, ref result ); } return true; }
public static void initialize() { // constraint attributes { // Geometry: mesh, readable, not writable, delete on disconnect MFnTypedAttribute typedAttrNotWritable = new MFnTypedAttribute(); GeometrySurfaceConstraint.constraintGeometry = typedAttrNotWritable.create( "constraintGeometry", "cg", MFnData.Type.kMesh); typedAttrNotWritable.isReadable = true; typedAttrNotWritable.isWritable = false; typedAttrNotWritable.disconnectBehavior = MFnAttribute.DisconnectBehavior.kDelete; } { // Parent inverse matrix: delete on disconnect MFnTypedAttribute typedAttr = new MFnTypedAttribute(); GeometrySurfaceConstraint.constraintParentInverseMatrix = typedAttr.create( "constraintPim", "ci", MFnData.Type.kMatrix); typedAttr.disconnectBehavior = MFnAttribute.DisconnectBehavior.kDelete; // Target geometry: mesh, delete on disconnect GeometrySurfaceConstraint.targetGeometry = typedAttr.create( "targetGeometry", "tg", MFnData.Type.kMesh); typedAttr.disconnectBehavior = MFnAttribute.DisconnectBehavior.kDelete; } { // Target weight: double, min 0, default 1.0, keyable, delete on disconnect MFnNumericAttribute typedAttrKeyable = new MFnNumericAttribute(); GeometrySurfaceConstraint.targetWeight = typedAttrKeyable.create( "weight", "wt", MFnNumericData.Type.kDouble, 1.0); typedAttrKeyable.setMin( (double) 0 ); typedAttrKeyable.isKeyable = true; typedAttrKeyable.disconnectBehavior = MFnAttribute.DisconnectBehavior.kDelete; } { // Compound target(geometry,weight): array, delete on disconnect MFnCompoundAttribute compoundAttr = new MFnCompoundAttribute(); GeometrySurfaceConstraint.compoundTarget = compoundAttr.create( "target", "tgt"); compoundAttr.addChild(GeometrySurfaceConstraint.targetGeometry); compoundAttr.addChild(GeometrySurfaceConstraint.targetWeight); compoundAttr.isArray = true; compoundAttr.disconnectBehavior = MFnAttribute.DisconnectBehavior.kDelete; } addAttribute(GeometrySurfaceConstraint.constraintParentInverseMatrix); addAttribute(GeometrySurfaceConstraint.constraintGeometry); addAttribute(GeometrySurfaceConstraint.compoundTarget); attributeAffects(compoundTarget, constraintGeometry); attributeAffects(targetGeometry, constraintGeometry); attributeAffects(targetWeight, constraintGeometry); attributeAffects(constraintParentInverseMatrix, constraintGeometry); }
// The implementation here is a bit different from its counterpart C++ sample because // .NET SDK decides not to support the obsolete C++ API: // // bool connectTargetAttribute (void *opaqueTarget, int index, MObject &constraintAttr); // protected override bool connectTarget( MDagPath targetPath, int index ) { try { MObject targetObject = new MObject(targetPath.node); MFnDagNode targetDagNode = new MFnDagNode(targetObject); connectTargetAttribute(targetPath, index, targetDagNode.attribute("worldMesh"), GeometrySurfaceConstraint.targetGeometry); } catch (Exception) { MGlobal.displayError("Failed to connect target."); return false; } return true; }
// // Write out the 'addAttr' and 'setAttr' commands for a node. // protected void writeNodeAttrs(FileStream f, MObject node, bool isSelected) { MFnDependencyNode nodeFn = new MFnDependencyNode(node); if (nodeFn.canBeWritten) { MStringArray addAttrCmds = new MStringArray(); MStringArray setAttrCmds = new MStringArray(); getAddAttrCmds(node, addAttrCmds); getSetAttrCmds(node, setAttrCmds); uint numAddAttrCmds = addAttrCmds.length; uint numSetAttrCmds = setAttrCmds.length; if (numAddAttrCmds + numSetAttrCmds > 0) { // // If the node is not already selected, then issue a command to // select it. // if (!isSelected) writeSelectNode(f, node); int i; string result = ""; for (i = 0; i < numAddAttrCmds; i++) result += (addAttrCmds[i] + "\n"); for (i = 0; i < numSetAttrCmds; i++) result += (setAttrCmds[i] + "\n"); writeString(f, result); } } }