//--------------------------------------------------- bool DagHelper::setPlugValue ( MPlug& plug, MStringArray& stringArray ) { MObject obj; MFnStringArrayData fstr; obj = fstr.create ( stringArray ); return plug.setValue ( obj ); }
void rigidBodyNode::clearContactInfo() { MObject thisObject(thisMObject()); // contactCount m_contactCount = 0; MPlug plugContactCount(thisObject, rigidBodyNode::oa_contactCount); plugContactCount.setValue(m_contactCount); // contactName MStringArray stringArray; stringArray.clear(); MFnStringArrayData stringArrayData; MObject strArrObject = stringArrayData.create(stringArray); MPlug plugContactName(thisObject, rigidBodyNode::oa_contactName); if ( !plugContactName.isNull() ) plugContactName.setValue(strArrObject); // contactPosition MPlug plugContactPosition(thisObject, rigidBodyNode::oa_contactPosition); bool isArray = plugContactPosition.isArray(); MVectorArray vectorArray; vectorArray.clear(); MFnVectorArrayData vectorArrayData; MObject arrObject = vectorArrayData.create(vectorArray); if ( !plugContactPosition.isNull() ) plugContactPosition.setValue(arrObject); }
void rigidBodyNode::addContactInfo(const MString& contactObjectName, const MVector& point) { MObject thisObject(thisMObject()); // contactCount m_contactCount++; MPlug plugContactCount(thisObject, rigidBodyNode::oa_contactCount); plugContactCount.setValue(m_contactCount); // contactName MPlug plugContactName(thisObject, rigidBodyNode::oa_contactName); if ( !plugContactName.isNull() ) { MObject strArrObject; plugContactName.getValue(strArrObject); MFnStringArrayData stringArrayData(strArrObject); MStringArray stringArray = stringArrayData.array(); stringArray.append(contactObjectName); MFnStringArrayData newStringArrayData; MObject newStrArrObject = newStringArrayData.create(stringArray); plugContactName.setValue(newStrArrObject); } // contactPosition MPlug plugContactPosition(thisObject, rigidBodyNode::oa_contactPosition); if ( !plugContactPosition.isNull() ) { MObject arrObject; plugContactPosition.getValue(arrObject); MFnVectorArrayData vectorArrayData(arrObject); MVectorArray vectorArray = vectorArrayData.array(); vectorArray.append(point); MFnVectorArrayData newVectorArrayData; MObject newArrObject = newVectorArrayData.create(vectorArray); plugContactPosition.setValue(newArrObject); } }
MStatus rigidBodyNode::initialize() { MStatus status; MFnMessageAttribute fnMsgAttr; MFnNumericAttribute fnNumericAttr; MFnMatrixAttribute fnMatrixAttr; MFnTypedAttribute typedAttr; ia_collisionShape = fnMsgAttr.create("inCollisionShape", "incs", &status); MCHECKSTATUS(status, "creating inCollisionShape attribute") status = addAttribute(ia_collisionShape); MCHECKSTATUS(status, "adding inCollisionShape attribute") ia_solver = fnMsgAttr.create("solver", "solv", &status); MCHECKSTATUS(status, "creating solver attribute") status = addAttribute(ia_solver); MCHECKSTATUS(status, "adding solver attribute") ia_mass = fnNumericAttr.create("mass", "ma", MFnNumericData::kDouble, 1.0, &status); MCHECKSTATUS(status, "creating mass attribute") fnNumericAttr.setKeyable(true); status = addAttribute(ia_mass); MCHECKSTATUS(status, "adding mass attribute") ia_restitution = fnNumericAttr.create("restitution", "rst", MFnNumericData::kDouble, 0.1, &status); MCHECKSTATUS(status, "creating restitution attribute") fnNumericAttr.setKeyable(true); status = addAttribute(ia_restitution); MCHECKSTATUS(status, "adding restitution attribute") ia_friction = fnNumericAttr.create("friction", "fc", MFnNumericData::kDouble, 0.5, &status); MCHECKSTATUS(status, "creating friction attribute") fnNumericAttr.setKeyable(true); status = addAttribute(ia_friction); MCHECKSTATUS(status, "adding friction attribute") ia_linearDamping = fnNumericAttr.create("linearDamping", "ld", MFnNumericData::kDouble, 0.3, &status); MCHECKSTATUS(status, "creating linearDamping attribute") fnNumericAttr.setKeyable(true); status = addAttribute(ia_linearDamping); MCHECKSTATUS(status, "adding linearDamping attribute") ia_angularDamping = fnNumericAttr.create("angularDamping", "ad", MFnNumericData::kDouble, 0.3, &status); MCHECKSTATUS(status, "creating angularDamping attribute") fnNumericAttr.setKeyable(true); status = addAttribute(ia_angularDamping); MCHECKSTATUS(status, "adding angularDamping attribute") ia_initialPosition = fnNumericAttr.createPoint("initialPosition", "inpo", &status); MCHECKSTATUS(status, "creating initialPosition attribute") status = addAttribute(ia_initialPosition); MCHECKSTATUS(status, "adding initialPosition attribute") ia_initialRotation = fnNumericAttr.createPoint("initialRotation", "inro", &status); MCHECKSTATUS(status, "creating initialRotation attribute") status = addAttribute(ia_initialRotation); MCHECKSTATUS(status, "adding initialRotation attribute") ia_initialVelocity = fnNumericAttr.createPoint("initialVelocity", "inve", &status); MCHECKSTATUS(status, "creating initialVelocity attribute") status = addAttribute(ia_initialVelocity); MCHECKSTATUS(status, "adding initialVelocity attribute") ia_initialSpin = fnNumericAttr.createPoint("initialSpin", "insp", &status); MCHECKSTATUS(status, "creating initialSpin attribute") status = addAttribute(ia_initialSpin); MCHECKSTATUS(status, "adding initialSpin attribute") ia_externalForce = fnNumericAttr.createPoint("externalForce", "exfo", &status); MCHECKSTATUS(status, "creating externalForce attribute") status = addAttribute(ia_externalForce); MCHECKSTATUS(status, "adding externalForce attribute") ia_externalTorque = fnNumericAttr.createPoint("externalTorque", "exto", &status); MCHECKSTATUS(status, "creating externalTorque attribute") status = addAttribute(ia_externalTorque); MCHECKSTATUS(status, "adding externalTorque attribute") ca_rigidBody = fnNumericAttr.create("ca_rigidBody", "carb", MFnNumericData::kBoolean, 0, &status); MCHECKSTATUS(status, "creating ca_rigidBody attribute") fnNumericAttr.setConnectable(false); fnNumericAttr.setHidden(true); fnNumericAttr.setStorable(false); fnNumericAttr.setKeyable(false); status = addAttribute(ca_rigidBody); MCHECKSTATUS(status, "adding ca_rigidBody attribute") ca_rigidBodyParam = fnNumericAttr.create("ca_rigidBodyParam", "carbp", MFnNumericData::kBoolean, 0, &status); MCHECKSTATUS(status, "creating ca_rigidBodyParam attribute") fnNumericAttr.setConnectable(false); fnNumericAttr.setHidden(true); fnNumericAttr.setStorable(false); fnNumericAttr.setKeyable(false); status = addAttribute(ca_rigidBodyParam); MCHECKSTATUS(status, "adding ca_rigidBodyParam attribute") ca_solver = fnNumericAttr.create("ca_solver", "caso", MFnNumericData::kBoolean, 0, &status); MCHECKSTATUS(status, "creating ca_solver attribute") fnNumericAttr.setConnectable(false); fnNumericAttr.setHidden(true); fnNumericAttr.setStorable(false); fnNumericAttr.setKeyable(false); status = addAttribute(ca_solver); MCHECKSTATUS(status, "adding ca_solver attribute") oa_contactCount = fnNumericAttr.create("contactCount", "contactCount", MFnNumericData::kInt, 0, &status); MCHECKSTATUS(status, "creating oa_contactCount attribute") fnNumericAttr.setConnectable(true); fnNumericAttr.setHidden(true); fnNumericAttr.setStorable(false); fnNumericAttr.setKeyable(false); status = addAttribute(oa_contactCount); MCHECKSTATUS(status, "adding oa_contactCount attribute"); MFnStringArrayData stringArrayData; oa_contactName = typedAttr.create("contactName", "contactName", MFnData::kStringArray, stringArrayData.create(), &status); MCHECKSTATUS(status, "creating oa_contactName attribute") typedAttr.setHidden(true); status = addAttribute(oa_contactName); MCHECKSTATUS(status, "adding oa_contactName attribute"); oa_contactPosition = typedAttr.create("contactPosition", "contactPosition", MFnVectorArrayData::kVectorArray, &status); MCHECKSTATUS(status, "creating oa_contactPosition attribute") typedAttr.setHidden(true); status = addAttribute(oa_contactPosition); MCHECKSTATUS(status, "adding oa_contactPosition attribute"); status = attributeAffects(ia_mass, ca_rigidBody); MCHECKSTATUS(status, "adding attributeAffects(ia_mass, ca_rigidBodyParam)") status = attributeAffects(ia_collisionShape, ca_rigidBody); MCHECKSTATUS(status, "adding attributeAffects(ia_collisionShape, ca_rigidBody)") status = attributeAffects(ia_collisionShape, ca_rigidBodyParam); MCHECKSTATUS(status, "adding attributeAffects(ia_collisionShape, ca_rigidBodyParam)") status = attributeAffects(ia_mass, ca_rigidBodyParam); MCHECKSTATUS(status, "adding attributeAffects(ia_mass, ca_rigidBodyParam)") status = attributeAffects(ia_restitution, ca_rigidBodyParam); MCHECKSTATUS(status, "adding attributeAffects(ia_restitution, ca_rigidBodyParam)") status = attributeAffects(ia_friction, ca_rigidBodyParam); MCHECKSTATUS(status, "adding attributeAffects(ia_friction, ca_rigidBodyParam)") status = attributeAffects(ia_linearDamping, ca_rigidBodyParam); MCHECKSTATUS(status, "adding attributeAffects(ia_linearDamping, ca_rigidBodyParam)") status = attributeAffects(ia_angularDamping, ca_rigidBodyParam); MCHECKSTATUS(status, "adding attributeAffects(ia_angularDamping, ca_rigidBodyParam)") status = attributeAffects(ia_initialPosition, ca_rigidBodyParam); MCHECKSTATUS(status, "adding attributeAffects(ia_initialPosition, ca_rigidBodyParam)") status = attributeAffects(ia_solver, ca_solver); MCHECKSTATUS(status, "adding attributeAffects(ia_solver, ca_solver)") return MS::kSuccess; }
MStatus AlembicNode::initialize() { MStatus status; MFnUnitAttribute uAttr; MFnTypedAttribute tAttr, tAttr2; MFnNumericAttribute nAttr; MFnGenericAttribute gAttr; MFnEnumAttribute eAttr; // add the input attributes: time, file, sequence time mTimeAttr = uAttr.create("time", "tm", MFnUnitAttribute::kTime, 0.0); status = uAttr.setStorable(true); status = addAttribute(mTimeAttr); // input file name MFnStringData fileFnStringData; MObject fileNameDefaultObject = fileFnStringData.create(""); mAbcFileNameAttr = tAttr.create("abc_File", "fn", MFnData::kString, fileNameDefaultObject); status = tAttr.setStorable(true); status = tAttr.setUsedAsFilename(true); status = addAttribute(mAbcFileNameAttr); // input layer file names MFnStringArrayData fileFnStringArrayData; MStringArray dummyStringArray; MObject layerFileNamesDefaultObject = fileFnStringArrayData.create(dummyStringArray); mAbcLayerFileNamesAttr = tAttr2.create("abc_layerFiles", "fns", MFnData::kStringArray, layerFileNamesDefaultObject); status = tAttr2.setStorable(true); status = tAttr2.setUsedAsFilename(true); status = tAttr2.setKeyable(false); status = tAttr2.setWritable(true); status = addAttribute(mAbcLayerFileNamesAttr); // playback speed mSpeedAttr = nAttr.create("speed", "sp", MFnNumericData::kDouble, 1.0, &status); status = nAttr.setWritable(true); status = nAttr.setStorable(true); status = nAttr.setKeyable(true); status = addAttribute(mSpeedAttr); // frame offset mOffsetAttr = nAttr.create("offset", "of", MFnNumericData::kDouble, 0, &status); status = nAttr.setWritable(true); status = nAttr.setStorable(true); status = nAttr.setKeyable(true); status = addAttribute(mOffsetAttr); // cycle type mCycleTypeAttr = eAttr.create("cycleType", "ct", 0, &status ); status = eAttr.addField("Hold", PLAYTYPE_HOLD); status = eAttr.addField("Loop", PLAYTYPE_LOOP); status = eAttr.addField("Reverse", PLAYTYPE_REVERSE); status = eAttr.addField("Bounce", PLAYTYPE_BOUNCE); status = eAttr.setWritable(true); status = eAttr.setStorable(true); status = eAttr.setKeyable(true); status = addAttribute(mCycleTypeAttr); // Regex Filter // This is a hidden variable to preserve a regexIncludefilter string // into a .ma file. mIncludeFilterAttr = tAttr.create("regexIncludeFilter", "ift", MFnData::kString); status = tAttr.setStorable(true); status = tAttr.setHidden(true); status = addAttribute(mIncludeFilterAttr); // Regex Filter // This is a hidden variable to preserve a regexExcludefilter string // into a .ma file. mExcludeFilterAttr = tAttr.create("regexExcludeFilter", "eft", MFnData::kString); status = tAttr.setStorable(true); status = tAttr.setHidden(true); status = addAttribute(mExcludeFilterAttr); // sequence min and max in frames mStartFrameAttr = nAttr.create("startFrame", "sf", MFnNumericData::kDouble, 0, &status); status = nAttr.setWritable(false); status = nAttr.setStorable(true); status = addAttribute(mStartFrameAttr); mEndFrameAttr = nAttr.create("endFrame", "ef", MFnNumericData::kDouble, 0, &status); status = nAttr.setWritable(false); status = nAttr.setStorable(true); status = addAttribute(mEndFrameAttr); // add the output attributes // sampled subD mesh MFnMeshData fnMeshData; MObject meshDefaultObject = fnMeshData.create(&status); mOutSubDArrayAttr = tAttr.create("outSubDMesh", "osubd", MFnData::kMesh, meshDefaultObject); status = tAttr.setStorable(false); status = tAttr.setWritable(false); status = tAttr.setKeyable(false); status = tAttr.setArray(true); status = tAttr.setUsesArrayDataBuilder(true); status = addAttribute(mOutSubDArrayAttr); // sampled poly mesh mOutPolyArrayAttr = tAttr.create("outPolyMesh", "opoly", MFnData::kMesh, meshDefaultObject); status = tAttr.setStorable(false); status = tAttr.setWritable(false); status = tAttr.setKeyable(false); status = tAttr.setArray(true); status = tAttr.setUsesArrayDataBuilder(true); status = addAttribute(mOutPolyArrayAttr); // sampled nurbs surface MFnNurbsSurfaceData fnNSData; MObject nsDefaultObject = fnNSData.create(&status); mOutNurbsSurfaceArrayAttr = tAttr.create("outNSurface", "ons", MFnData::kNurbsSurface, nsDefaultObject); status = tAttr.setStorable(false); status = tAttr.setWritable(false); status = tAttr.setKeyable(false); status = tAttr.setArray(true); status = tAttr.setUsesArrayDataBuilder(true); status = addAttribute(mOutNurbsSurfaceArrayAttr); // sampled nurbs curve group MFnNurbsCurveData fnNCData; MObject ncDefaultObject = fnNCData.create(&status); mOutNurbsCurveGrpArrayAttr = tAttr.create("outNCurveGrp", "onc", MFnData::kNurbsCurve, ncDefaultObject); status = tAttr.setStorable(false); status = tAttr.setWritable(false); status = tAttr.setKeyable(false); status = tAttr.setArray(true); status = tAttr.setUsesArrayDataBuilder(true); status = addAttribute(mOutNurbsCurveGrpArrayAttr); // sampled locator mOutLocatorPosScaleArrayAttr = nAttr.create("outLoc", "olo", MFnNumericData::kDouble, 0.0, &status); status = nAttr.setStorable(false); status = nAttr.setWritable(false); status = nAttr.setArray(true); status = nAttr.setUsesArrayDataBuilder(true); status = addAttribute(mOutLocatorPosScaleArrayAttr); // sampled transform operations mOutTransOpArrayAttr = nAttr.create("transOp", "to", MFnNumericData::kDouble, 0.0, &status); status = nAttr.setStorable(false); status = nAttr.setWritable(false); status = nAttr.setArray(true); status = nAttr.setUsesArrayDataBuilder(true); status = addAttribute(mOutTransOpArrayAttr); // sampled camera // assume the boolean variables cannot be keyed mOutCameraArrayAttr = nAttr.create("outCamera", "ocam", MFnNumericData::kDouble, 0.0, &status); status = nAttr.setStorable(false); status = nAttr.setWritable(false); status = nAttr.setArray(true); status = nAttr.setUsesArrayDataBuilder(true); status = addAttribute(mOutCameraArrayAttr); // sampled custom-attributes mOutPropArrayAttr = gAttr.create("prop", "pr", &status); status = gAttr.addNumericDataAccept(MFnNumericData::kBoolean); status = gAttr.addNumericDataAccept(MFnNumericData::kByte); status = gAttr.addNumericDataAccept(MFnNumericData::kShort); status = gAttr.addNumericDataAccept(MFnNumericData::k2Short); status = gAttr.addNumericDataAccept(MFnNumericData::k3Short); status = gAttr.addNumericDataAccept(MFnNumericData::kInt); status = gAttr.addNumericDataAccept(MFnNumericData::k2Int); status = gAttr.addNumericDataAccept(MFnNumericData::k3Int); status = gAttr.addNumericDataAccept(MFnNumericData::kFloat); status = gAttr.addNumericDataAccept(MFnNumericData::k2Float); status = gAttr.addNumericDataAccept(MFnNumericData::k3Float); status = gAttr.addNumericDataAccept(MFnNumericData::kDouble); status = gAttr.addNumericDataAccept(MFnNumericData::k2Double); status = gAttr.addNumericDataAccept(MFnNumericData::k3Double); status = gAttr.addNumericDataAccept(MFnNumericData::k4Double); status = gAttr.addDataAccept(MFnData::kString); status = gAttr.addDataAccept(MFnData::kIntArray); status = gAttr.addDataAccept(MFnData::kDoubleArray); status = gAttr.addDataAccept(MFnData::kVectorArray); status = gAttr.addDataAccept(MFnData::kPointArray); status = gAttr.setWritable(false); status = gAttr.setKeyable(false); status = gAttr.setArray(true); status = gAttr.setUsesArrayDataBuilder(true); status = addAttribute(mOutPropArrayAttr); // set up affection relationships status = attributeAffects(mTimeAttr, mOutSubDArrayAttr); status = attributeAffects(mTimeAttr, mOutPolyArrayAttr); status = attributeAffects(mTimeAttr, mOutNurbsSurfaceArrayAttr); status = attributeAffects(mTimeAttr, mOutNurbsCurveGrpArrayAttr); status = attributeAffects(mTimeAttr, mOutTransOpArrayAttr); status = attributeAffects(mTimeAttr, mOutCameraArrayAttr); status = attributeAffects(mTimeAttr, mOutPropArrayAttr); status = attributeAffects(mTimeAttr, mOutLocatorPosScaleArrayAttr); status = attributeAffects(mSpeedAttr, mOutSubDArrayAttr); status = attributeAffects(mSpeedAttr, mOutPolyArrayAttr); status = attributeAffects(mSpeedAttr, mOutNurbsSurfaceArrayAttr); status = attributeAffects(mSpeedAttr, mOutNurbsCurveGrpArrayAttr); status = attributeAffects(mSpeedAttr, mOutTransOpArrayAttr); status = attributeAffects(mSpeedAttr, mOutCameraArrayAttr); status = attributeAffects(mSpeedAttr, mOutPropArrayAttr); status = attributeAffects(mSpeedAttr, mOutLocatorPosScaleArrayAttr); status = attributeAffects(mOffsetAttr, mOutSubDArrayAttr); status = attributeAffects(mOffsetAttr, mOutPolyArrayAttr); status = attributeAffects(mOffsetAttr, mOutNurbsSurfaceArrayAttr); status = attributeAffects(mOffsetAttr, mOutNurbsCurveGrpArrayAttr); status = attributeAffects(mOffsetAttr, mOutTransOpArrayAttr); status = attributeAffects(mOffsetAttr, mOutCameraArrayAttr); status = attributeAffects(mOffsetAttr, mOutPropArrayAttr); status = attributeAffects(mOffsetAttr, mOutLocatorPosScaleArrayAttr); status = attributeAffects(mCycleTypeAttr, mOutSubDArrayAttr); status = attributeAffects(mCycleTypeAttr, mOutPolyArrayAttr); status = attributeAffects(mCycleTypeAttr, mOutNurbsSurfaceArrayAttr); status = attributeAffects(mCycleTypeAttr, mOutNurbsCurveGrpArrayAttr); status = attributeAffects(mCycleTypeAttr, mOutTransOpArrayAttr); status = attributeAffects(mCycleTypeAttr, mOutCameraArrayAttr); status = attributeAffects(mCycleTypeAttr, mOutPropArrayAttr); status = attributeAffects(mCycleTypeAttr, mOutLocatorPosScaleArrayAttr); MGlobal::executeCommand( UITemplateMELScriptStr ); return status; }