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); }
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 void sendCurveToMaya(string node_name, Point3DCollection controlVertices, List <double> knots, int degree, MFnNurbsCurveForm form) { var dn = new MFnDagNode(getDagNode(node_name)); var plCreate = dn.findPlug("create"); var plDynamoCreate = new MPlug(); try { plDynamoCreate = dn.findPlug("dynamoCreate"); } catch { var tAttr = new MFnTypedAttribute(); var ldaDynamoCreate = tAttr.create("dynamoCreate", "dc", MFnData.Type.kNurbsCurve, MObject.kNullObj); try { dn.addAttribute(ldaDynamoCreate, MFnDependencyNode.MAttrClass.kLocalDynamicAttr); plDynamoCreate = dn.findPlug(ldaDynamoCreate); var dagm = new MDagModifier(); dagm.connect(plDynamoCreate, plCreate); dagm.doIt(); } catch { return; } } var ncd = new MFnNurbsCurveData(); var oOwner = ncd.create(); var nc = new MFnNurbsCurve(); var p_aControlVertices = new MPointArray(); foreach (var p in controlVertices) { p_aControlVertices.Add(new MPoint(p.X, p.Y, p.Z)); } var d_aKnots = new MDoubleArray(); for (var i = 1; i < knots.Count - 1; ++i) { d_aKnots.Add(knots[i]); } nc.create(p_aControlVertices, d_aKnots, (uint)degree, (MFnNurbsCurve.Form)form, false, true, oOwner); plDynamoCreate.setMObject(oOwner); MGlobal.executeCommandOnIdle(string.Format("dgdirty {0}.create;", node_name)); }
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); }
private void setMeshData(MObject transform, MObject dataWrapper) { // Get the mesh node. MFnDagNode dagFn = new MFnDagNode(transform); MObject mesh = dagFn.child(0); // The mesh node has two geometry inputs: 'inMesh' and 'cachedInMesh'. // 'inMesh' is only used when it has an incoming connection, otherwise // 'cachedInMesh' is used. Unfortunately, the docs say that 'cachedInMesh' // is for internal use only and that changing it may render Maya // unstable. // // To get around that, we do the little dance below... // Use a temporary MDagModifier to create a temporary mesh attribute on // the node. MFnTypedAttribute tAttr = new MFnTypedAttribute(); MObject tempAttr = tAttr.create("tempMesh", "tmpm", MFnData.Type.kMesh); MDagModifier tempMod = new MDagModifier(); tempMod.addAttribute(mesh, tempAttr); tempMod.doIt(); // Set the geometry data onto the temp attribute. dagFn.setObject(mesh); MPlug tempPlug = dagFn.findPlug(tempAttr); tempPlug.setValue(dataWrapper); // Use the temporary MDagModifier to connect the temp attribute to the // node's 'inMesh'. MPlug inMeshPlug = dagFn.findPlug("inMesh"); tempMod.connect(tempPlug, inMeshPlug); tempMod.doIt(); // Force the mesh to update by grabbing its output geometry. dagFn.findPlug("outMesh").asMObject(); // Undo the temporary modifier. tempMod.undoIt(); }
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 ); }
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); }
public void sendCurveToMaya(string node_name, Point3DCollection controlVertices, List<double> knots, int degree, MFnNurbsCurveForm form) { MFnDagNode dn = new MFnDagNode(getDagNode(node_name)); MPlug plCreate = dn.findPlug("create"); MPlug plDynamoCreate = new MPlug(); try { plDynamoCreate = dn.findPlug("dynamoCreate"); } catch { MFnTypedAttribute tAttr = new MFnTypedAttribute(); MObject ldaDynamoCreate = tAttr.create("dynamoCreate", "dc", MFnData.Type.kNurbsCurve, MObject.kNullObj); try { dn.addAttribute(ldaDynamoCreate, MFnDependencyNode.MAttrClass.kLocalDynamicAttr); plDynamoCreate = dn.findPlug(ldaDynamoCreate); MDagModifier dagm = new MDagModifier(); dagm.connect(plDynamoCreate, plCreate); dagm.doIt(); } catch { return; } } MFnNurbsCurveData ncd = new MFnNurbsCurveData(); MObject oOwner = ncd.create(); MFnNurbsCurve nc = new MFnNurbsCurve(); MPointArray p_aControlVertices = new MPointArray(); foreach (Point3D p in controlVertices) { p_aControlVertices.Add(new MPoint(p.X, p.Y, p.Z)); } MDoubleArray d_aKnots = new MDoubleArray(); for (int i = 1; i < knots.Count - 1; ++i ) { d_aKnots.Add(knots[i]); } nc.create(p_aControlVertices, d_aKnots, (uint)degree, (MFnNurbsCurve.Form)form, false, true, oOwner); plDynamoCreate.setMObject(oOwner); MGlobal.executeCommandOnIdle(String.Format("dgdirty {0}.create;", node_name)); }
public override void redoIt() { MObject dependNode = new MObject(); MOStream stdoutstream = MStreamUtils.stdOutStream(); for (; !iter.isDone; iter.next()) { // Get the selected dependency node and create // a function set for it // try { iter.getDependNode(dependNode); } catch (System.Exception) { MStreamUtils.writeCharBuffer(MStreamUtils.stdErrorStream(), "Error getting the dependency node"); continue; } MFnDependencyNode fnDN; try { fnDN = new MFnDependencyNode(dependNode); } catch (System.Exception) { MStreamUtils.writeCharBuffer(MStreamUtils.stdErrorStream(), "Error creating MFnDependencyNode"); continue; } MFnTypedAttribute fnAttr = new MFnTypedAttribute(); MObject newAttr = fnAttr.create("blindDoubleData", "BDD", blindDoubleData.tid); try { fnDN.addAttribute(newAttr, MFnDependencyNode.MAttrClass.kLocalDynamicAttr); } catch (System.Exception) { // do nothing // addAttribute only need call once, the redundant calls will return false (throw exception) } // Create a plug to set and retrieve value off the node. // MPlug plug = new MPlug(dependNode, newAttr); // ----------------------------------- Attention ------------------------------------ // --------------------------------- Downcast Begin ----------------------------------- // the following codes are used to get the c# object // MFnPluginData pdFnCreator = new MFnPluginData(); // 1. you cannot gain blindDoubleData by the following code // {code} // blindDoubleData newData = new blindDoubleData() // {code} // As we need to keep the relationship between c# impl and c++ instance pointer // We cannot use the above ctor codes, otherwise, the mandatory information used for down casting is omitted // 2. you cannot use the tempData gained by the following code // {code} // MObject tempData = pdFnCreator.create(blindDoubleData.tid); // {code} // reason: // tempData is useless, we cannot use tempData to do downcast // the create function gains the tempData by the following code // // {code} // newHandle = new MObject(mayaHandle); // {code} // // the mayaHandle is the actual pointer, which we store. But we have no information about the newHandle // the return object is useless. the data we needed is stored in pdFnCreator pdFnCreator.create(blindDoubleData.tid); // 3. get "the data" we needed blindDoubleData newData = pdFnCreator.data() as blindDoubleData; // ---------------------------------- Downcast End ----------------------------------- if (newData == null) { continue; } newData.value = 3.2; plug.setValue(newData); // Now try to retrieve the value of the plug as an MObject. // MObject sData = new MObject(); try { plug.getValue(sData); } catch (System.Exception) { continue; } // Convert the data back to MPxData. // MFnPluginData pdFn = new MFnPluginData(sData); blindDoubleData data = pdFn.data() as blindDoubleData; // Get the value. // if (null == data) { // error MStreamUtils.writeCharBuffer(MStreamUtils.stdErrorStream(), "error: failed to retrieve data."); } MStreamUtils.writeLine(stdoutstream); MStreamUtils.writeCharBuffer(stdoutstream, ">>>>>>>>>>>>>>>>>>>>>>>> blindDoubleData binary >>>>>>>>>>>>>>>>>>>>"); MStreamUtils.writeLine(stdoutstream); data.writeBinary(stdoutstream); MStreamUtils.writeLine(stdoutstream); MStreamUtils.writeCharBuffer(stdoutstream, ">>>>>>>>>>>>>>>>>>>>>>>> blindDoubleData ascii >>>>>>>>>>>>>>>>>>>>"); MStreamUtils.writeLine(stdoutstream); data.writeASCII(stdoutstream); } return; }
public override void redoIt() { MObject dependNode = new MObject(); MOStream stdoutstream = MStreamUtils.stdOutStream(); for(; !iter.isDone; iter.next()) { // Get the selected dependency node and create // a function set for it // try { iter.getDependNode(dependNode); } catch (System.Exception) { MStreamUtils.writeCharBuffer(MStreamUtils.stdErrorStream(), "Error getting the dependency node"); continue; } MFnDependencyNode fnDN; try { fnDN = new MFnDependencyNode(dependNode); } catch(System.Exception) { MStreamUtils.writeCharBuffer(MStreamUtils.stdErrorStream(), "Error creating MFnDependencyNode"); continue; } MFnTypedAttribute fnAttr = new MFnTypedAttribute(); MObject newAttr = fnAttr.create("blindDoubleData", "BDD", blindDoubleData.tid); try { fnDN.addAttribute(newAttr, MFnDependencyNode.MAttrClass.kLocalDynamicAttr); } catch (System.Exception) { // do nothing // addAttribute only need call once, the redundant calls will return false (throw exception) } // Create a plug to set and retrieve value off the node. // MPlug plug = new MPlug(dependNode, newAttr); // ----------------------------------- Attention ------------------------------------ // --------------------------------- Downcast Begin ----------------------------------- // the following codes are used to get the c# object // MFnPluginData pdFnCreator = new MFnPluginData(); // 1. you cannot gain blindDoubleData by the following code // {code} // blindDoubleData newData = new blindDoubleData() // {code} // As we need to keep the relationship between c# impl and c++ instance pointer // We cannot use the above ctor codes, otherwise, the mandatory information used for down casting is omitted // 2. you cannot use the tempData gained by the following code // {code} // MObject tempData = pdFnCreator.create(blindDoubleData.tid); // {code} // reason: // tempData is useless, we cannot use tempData to do downcast // the create function gains the tempData by the following code // // {code} // newHandle = new MObject(mayaHandle); // {code} // // the mayaHandle is the actual pointer, which we store. But we have no information about the newHandle // the return object is useless. the data we needed is stored in pdFnCreator pdFnCreator.create(blindDoubleData.tid); // 3. get "the data" we needed blindDoubleData newData = pdFnCreator.data() as blindDoubleData; // ---------------------------------- Downcast End ----------------------------------- if (newData == null) continue; newData.value = 3.2; plug.setValue(newData); // Now try to retrieve the value of the plug as an MObject. // MObject sData = new MObject(); try { plug.getValue( sData ); } catch (System.Exception) { continue; } // Convert the data back to MPxData. // MFnPluginData pdFn = new MFnPluginData( sData ); blindDoubleData data = pdFn.data() as blindDoubleData; // Get the value. // if ( null == data ) { // error MStreamUtils.writeCharBuffer(MStreamUtils.stdErrorStream(), "error: failed to retrieve data."); } MStreamUtils.writeLine(stdoutstream); MStreamUtils.writeCharBuffer(stdoutstream, ">>>>>>>>>>>>>>>>>>>>>>>> blindDoubleData binary >>>>>>>>>>>>>>>>>>>>"); MStreamUtils.writeLine(stdoutstream); data.writeBinary(stdoutstream); MStreamUtils.writeLine(stdoutstream); MStreamUtils.writeCharBuffer(stdoutstream, ">>>>>>>>>>>>>>>>>>>>>>>> blindDoubleData ascii >>>>>>>>>>>>>>>>>>>>"); MStreamUtils.writeLine(stdoutstream); data.writeASCII(stdoutstream); } return; }
public static void InitializeAnimClips() { var tAttr = new MFnTypedAttribute(); var nAttr = new MFnNumericAttribute(); var cAttr = new MFnCompoundAttribute(); var eAttr = new MFnEnumAttribute(); Name = tAttr.create("animClipName", "acn", MFnData.Type.kString); addAttribute(Name); Start = nAttr.create("animClipStart", "acs", MFnNumericData.Type.kInt); nAttr.setMin(0); addAttribute(Start); End = nAttr.create("animClipEnd", "ace", MFnNumericData.Type.kInt); nAttr.setMin(0); addAttribute(End); Type = eAttr.create("animClipType", "act"); foreach (var entry in AnimationData.NameToId) { eAttr.addField(entry.Key, (short)entry.Value); //TODO check performance } eAttr.setDefault(0); addAttribute(Type); LoopingFlag = nAttr.create("animClipLooping", "acl", MFnNumericData.Type.kBoolean); nAttr.setDefault(true); addAttribute(LoopingFlag); LowPriorityFlag = nAttr.create("animClipLowPriority", "aclp", MFnNumericData.Type.kBoolean); nAttr.setDefault(false); addAttribute(LowPriorityFlag); RepetitionsMin = nAttr.create("animClipRepMin", "acrepmin", MFnNumericData.Type.kFloat); nAttr.setDefault((float)0); nAttr.setMin(0); addAttribute(RepetitionsMin); RepetitionsMax = nAttr.create("animClipRepMax", "acrepmax", MFnNumericData.Type.kFloat); nAttr.setDefault((float)0); nAttr.setMin(0); addAttribute(RepetitionsMax); BlendingFlag = nAttr.create("animClipBlending", "acb", MFnNumericData.Type.kBoolean); nAttr.setDefault(true); addAttribute(BlendingFlag); BlendTimeStart = nAttr.create("animClipBlendTimeStart", "acbts", MFnNumericData.Type.kInt); nAttr.setDefault(150); nAttr.setMin(0); addAttribute(BlendTimeStart); BlendTimeEnd = nAttr.create("animClipBlendTimeEnd", "acbte", MFnNumericData.Type.kInt); nAttr.setDefault(150); nAttr.setMin(0); addAttribute(BlendTimeEnd); Rarity = nAttr.create("animClipRarity", "acra", MFnNumericData.Type.kFloat); nAttr.setDefault((float)100); nAttr.setMin(0); nAttr.setMax(100); addAttribute(Rarity); Export = nAttr.create("exportAnimClip", "eac", MFnNumericData.Type.kBoolean); nAttr.setDefault(true); addAttribute(Export); AnimClips = cAttr.create("animClips", "clips"); cAttr.addChild(Name); cAttr.addChild(Start); cAttr.addChild(End); cAttr.addChild(Type); cAttr.addChild(LoopingFlag); cAttr.addChild(LowPriorityFlag); cAttr.addChild(RepetitionsMin); cAttr.addChild(RepetitionsMax); cAttr.addChild(BlendingFlag); cAttr.addChild(BlendTimeStart); cAttr.addChild(BlendTimeEnd); cAttr.addChild(Rarity); cAttr.addChild(Export); cAttr.isArray = true; addAttribute(AnimClips); }