MStatus OParticleCmd::redoIt() { MStatus status; MObject tr = dgMod.createNode("transform"); MObject op = dgMod.createNode(OParticleNode::typeId,tr,&status); static int count=0; if(status==MS::kSuccess)count++; MString name = "transformOfOParticles"; name += count; dgMod.renameNode(tr,name); MString command = "select -add "; command += name; dgMod.commandToExecute( command); MFnTransform fn(tr); fn.setTranslation(MVector(x,y,z),MSpace::kTransform); MPlug radius(op,OParticleNode::radius); radius.setValue(r); bool update; MPlug(op,OParticleNode::Param).getValue(update); MPlug(op,OParticleNode::Pattribute).getValue(update); return dgMod.doIt(); }
MStatus recoverVisibleCmd::doIt(const MArgList&) { MStatus status; MItDag dagItr(MItDag::kDepthFirst, MFn::kInvalid,&status); if(status!=MS::kSuccess){MGlobal::displayError(" Failure in DAG iterator");return status;} for(;!dagItr.isDone();dagItr.next()) { MDagPath dagPath; status = dagItr.getPath(dagPath); if(status!=MS::kSuccess){MGlobal::displayError(" Failure in getting path");return status;} MFnDagNode dagNode(dagPath,&status); if(dagNode.isIntermediateObject())continue; if(!dagPath.hasFn(MFn::kDependencyNode))continue; MObject mObj=dagNode.object(&status); if(status!=MS::kSuccess){MGlobal::displayError(" Failure in getting object");return status;} //getParticle MFnDependencyNode fnNode(mObj, &status); if(status!=MS::kSuccess){MGlobal::displayError(" Failure in getting dependency node");return status;} if(fnNode.typeId() == OParticleNode::typeId) MPlug(mObj, OParticleNode::isVisible).setValue(true); if(fnNode.typeId() == edgeNode::typeId) MPlug(mObj, edgeNode::isVisible).setValue(true); } return status; }
void curvedArrows::draw( M3dView & view, const MDagPath & /*path*/, M3dView::DisplayStyle style, M3dView::DisplayStatus status ) { // Get the size // MObject thisNode = thisMObject(); MPlug tPlug = MPlug( thisNode, aTransparency ); MPlug cPlug = MPlug( thisNode, aTheColor ); float r, g, b, a; MObject color; cPlug.getValue( color ); MFnNumericData data( color ); data.getData( r, g, b ); tPlug.getValue( a ); view.beginGL(); if( (style == M3dView::kFlatShaded) || (style == M3dView::kGouraudShaded) ) { // Push the color settings // glPushAttrib( GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT | GL_ENABLE_BIT | GL_PIXEL_MODE_BIT ); if ( a < 1.0f ) { glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); } glColor4f( r, g, b, a ); glBegin( GL_TRIANGLES ); unsigned int i; for ( i = 0; i < fsFaceListSize; i ++ ) { unsigned int *vid = fsFaceList[i]; unsigned int *nid = fsFaceVertexNormalList[i]; for ( unsigned int j = 0; j < 3; j ++ ) { glNormal3d( fsNormalList[nid[j]-1][0], fsNormalList[nid[j]-1][1], fsNormalList[nid[j]-1][2] ); glVertex3d( fsVertexList[vid[j]-1][0], fsVertexList[vid[j]-1][1], fsVertexList[vid[j]-1][2] ); } } glEnd(); glPopAttrib(); drawEdgeLoop( view, status ); } else { drawEdgeLoop( view, status ); } view.endGL(); }
collision_shape_t::pointer collisionShapeNode::collisionShape() { MObject thisObject(thisMObject()); MObject update; MPlug(thisObject, oa_collisionShape).getValue(update); MPlug(thisObject, ca_collisionShapeParam).getValue(update); return m_collision_shape; }
soft_body_t::pointer SoftBodyNode::soft_body() { MObject thisObject(thisMObject()); MObject update; MPlug(thisObject, ca_softBody).getValue(update); MPlug(thisObject, ca_softBodyParam).getValue(update); return this->m_soft_body; }
void nailConstraintNode::update() { MObject thisObject(thisMObject()); MObject update; MPlug(thisObject, ca_constraint).getValue(update); MPlug(thisObject, ca_constraintParam).getValue(update); MPlug(thisObject, worldMatrix).elementByLogicalIndex(0).getValue(update); }
nail_constraint_t::pointer nailConstraintNode::constraint() { // std::cout << "nailConstraintNode::rigid_body" << std::endl; MObject thisObject(thisMObject()); MObject update; MPlug(thisObject, ca_constraint).getValue(update); MPlug(thisObject, ca_constraintParam).getValue(update); return m_constraint; }
rigid_body_t::pointer rigidBodyNode::rigid_body() { // std::cout << "rigidBodyNode::rigid_body" << std::endl; MObject thisObject(thisMObject()); MObject update; MPlug(thisObject, ca_rigidBody).getValue(update); MPlug(thisObject, ca_rigidBodyParam).getValue(update); return m_rigid_body; }
void rigidBodyNode::update() { MObject thisObject(thisMObject()); MObject update; MPlug(thisObject, ca_rigidBody).getValue(update); MPlug(thisObject, ca_rigidBodyParam).getValue(update); MPlug(thisObject, ca_solver).getValue(update); MPlug(thisObject, worldMatrix).elementByLogicalIndex(0).getValue(update); }
void SoftBodyNode::update() { MObject thisObject(this->thisMObject()); MObject update; MPlug(thisObject, inputMesh).getValue(update); MPlug(thisObject, ca_softBody).getValue(update); MPlug(thisObject, ca_softBodyParam).getValue(update); MPlug(thisObject, ca_solver).getValue(update); // MPlug(thisObject, worldMatrix).elementByLogicalIndex(0).getValue(update); }
void collisionShapeNode::computeOutputShape(const MPlug& plug, MDataBlock& data) { // std::cout << "collisionShapeNode::computeOutputShape" << std::endl; MObject thisObject(thisMObject()); MObject update; MPlug(thisObject, ca_collisionShape).getValue(update); MPlug(thisObject, ca_collisionShapeParam).getValue(update); data.setClean(plug); }
MStatus linearFrictionCmd::doIt(const MArgList& args) { MStatus stat; MArgDatabase argData(syntax(),args,&stat); if(argData.isFlagSet(lfFlag))argData.getFlagArgument(lfFlag,0,linearFriction); MSelectionList activeSelect; MGlobal::getActiveSelectionList(activeSelect); for(int i=0;i<activeSelect.length();i++) { MObject tNode; activeSelect.getDependNode(i,tNode); MFnDagNode fnDagNode(tNode); MObject pNode=fnDagNode.child(0); MFnDependencyNode fnNode(pNode); //MString name=fnNode1.name().asChar(); if(fnNode.typeId() == particleNode::typeId) { //get solver message attribute from particleNode MPlug(pNode, particleNode::linearFriction).setValue(linearFriction); } } return dgMod.doIt(); }
void rigidBodyNode::computeRigidBodyParam(const MPlug& plug, MDataBlock& data) { // std::cout << "(rigidBodyNode::computeRigidBodyParam) | " << std::endl; if (!m_rigid_body) return; MObject thisObject(thisMObject()); MObject update; MPlug(thisObject, ca_rigidBody).getValue(update); double mass = data.inputValue(ia_mass).asDouble(); bool changedMassStatus= false; float curMass = m_rigid_body->get_mass(); if ((curMass > 0.f) != (mass > 0.f)) { changedMassStatus = true; } if (changedMassStatus) solver_t::remove_rigid_body(m_rigid_body); m_rigid_body->set_mass((float)mass); m_rigid_body->set_inertia((float)mass * m_rigid_body->collision_shape()->local_inertia()); if (changedMassStatus) solver_t::add_rigid_body(m_rigid_body,name().asChar()); m_rigid_body->set_restitution((float)data.inputValue(ia_restitution).asDouble()); m_rigid_body->set_friction((float)data.inputValue(ia_friction).asDouble()); m_rigid_body->set_linear_damping((float)data.inputValue(ia_linearDamping).asDouble()); m_rigid_body->set_angular_damping((float)data.inputValue(ia_angularDamping).asDouble()); data.outputValue(ca_rigidBodyParam).set(true); data.setClean(plug); }
void hingeConstraintNode::computeConstraintParam(const MPlug& plug, MDataBlock& data) { //std::cout << "hingeConstraintNode::computeRigidBodyParam data.className=" << std::endl; MObject thisObject(thisMObject()); MObject update; MPlug(thisObject, ca_constraint).getValue(update); if(m_constraint) { float damping = (float) data.inputValue(ia_damping).asDouble(); m_constraint->set_damping(damping); float lower = (float) data.inputValue(ia_lowerLimit).asDouble(); float upper = (float) data.inputValue(ia_upperLimit).asDouble(); float limit_softness = (float) data.inputValue(ia_limitSoftness).asDouble(); float bias_factor = (float) data.inputValue(ia_biasFactor).asDouble(); float relaxation_factor = (float) data.inputValue(ia_relaxationFactor).asDouble(); m_constraint->set_limit(lower, upper, limit_softness, bias_factor, relaxation_factor); float* axis = data.inputValue(ia_hingeAxis).asFloat3(); m_constraint->set_axis(vec3f(axis[0], axis[1], axis[2])); bool enable_motor = data.inputValue(ia_enableAngularMotor).asBool(); float motorTargetVelocity = (float) data.inputValue(ia_motorTargetVelocity).asDouble(); float maxMotorImpulse = (float) data.inputValue(ia_maxMotorImpulse).asDouble(); m_constraint->enable_motor(enable_motor, motorTargetVelocity, maxMotorImpulse); } data.outputValue(ca_constraintParam).set(true); data.setClean(plug); }
void collisionShapeNode::computeCollisionShapeParam(const MPlug& plug, MDataBlock& data) { // std::cout << "collisionShapeNode::computeCollisionShapeParam" << std::endl; MObject thisObject(thisMObject()); MObject update; MPlug(thisObject, ia_shape).getValue(update); MPlug(thisObject, ia_type).getValue(update); float3& scale = data.inputValue(ia_scale).asFloat3(); m_collision_shape->set_scale(vec3f(scale[0], scale[1], scale[2])); data.setClean(plug); }
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- AlembicCurves::AlembicCurves(SceneNodePtr eNode, AlembicWriteJob *in_Job, Abc::OObject oParent) : AlembicObject(eNode, in_Job, oParent) { MObject nRef = GetRef(); MFnNurbsCurve node(nRef); MStatus status; MObject abcCurveId = node.attribute("abcCurveId", &status); if (status == MStatus::kSuccess) { const int cId = MPlug(nRef, abcCurveId).asInt(); if (cId != 0) { this->accumRef = AlembicCurveAccumulator::GetAccumulator(cId, nRef, eNode, in_Job, oParent); return; } } const bool animTS = (GetJob()->GetAnimatedTs() > 0); mObject = AbcG::OCurves(GetMyParent(), eNode->name, animTS); mSchema = mObject.getSchema(); // create all properties Abc::OCompoundProperty comp = mSchema.getArbGeomParams(); mRadiusProperty = Abc::OFloatArrayProperty(comp, ".radius", mSchema.getMetaData(), animTS); mColorProperty = Abc::OC4fArrayProperty(comp, ".color", mSchema.getMetaData(), animTS); mFaceIndexProperty = Abc::OInt32ArrayProperty(comp, ".face_index", mSchema.getMetaData(), animTS); mVertexIndexProperty = Abc::OInt32ArrayProperty( comp, ".vertex_index", mSchema.getMetaData(), animTS); mKnotVectorProperty = Abc::OFloatArrayProperty(comp, ".knot_vector", mSchema.getMetaData(), animTS); }
void SoftBodyNode::computeSoftBodyParam(const MPlug &plug, MDataBlock &data) { MObject thisObject(thisMObject()); MObject update; // update mass MPlug(thisObject, ca_softBody).getValue(update); float mass = static_cast<float>( data.inputValue(ia_mass).asDouble() ); this->m_soft_body->set_mass(mass); // update dynamic friction coefficient float dynFrictionCoeff = static_cast<float>( data.inputValue(ia_dynamicFrictionCoeff).asDouble() ); this->m_soft_body->set_dynamic_friction_coeff(dynFrictionCoeff); data.outputValue(ca_softBodyParam).set(true); // update collision margin float collisionMargin = data.inputValue(ia_collisionMargin).asFloat(); this->m_soft_body->set_collision_margin(collisionMargin); data.setClean(plug); // number of collision clusters int numClust = data.inputValue(ia_numClusters).asInt(); // this->m_soft_body->set_ }
MStatus radiusCmd::doIt(const MArgList&args) { MStatus status=MStatus::kSuccess; MArgDatabase argData(syntax(),args,&status); if(argData.isFlagSet(rFlag))argData.getFlagArgument(rFlag,0,radius); MItDag dagItr(MItDag::kDepthFirst, MFn::kInvalid,&status); if(status!=MS::kSuccess){MGlobal::displayError(" Failure in DAG iterator");return status;} for(;!dagItr.isDone();dagItr.next()) { MDagPath dagPath; status = dagItr.getPath(dagPath); if(status!=MS::kSuccess){MGlobal::displayError(" Failure in getting path");return status;} MFnDagNode dagNode(dagPath,&status); if(dagNode.isIntermediateObject())continue; if(!dagPath.hasFn(MFn::kDependencyNode))continue; MObject mObj=dagNode.object(&status); if(status!=MS::kSuccess){MGlobal::displayError(" Failure in getting object");return status;} //getParticle MFnDependencyNode fnNode(mObj, &status); if(status!=MS::kSuccess){MGlobal::displayError(" Failure in getting dependency node");return status;} if(fnNode.typeId() == OParticleNode::typeId) MPlug(mObj, OParticleNode::radius).setValue(radius); } return status; }
void sixdofConstraintNode::computeConstraintParam(const MPlug& plug, MDataBlock& data) { // std::cout << "sixdofConstraintNode::computeRigidBodyParam" << std::endl; MObject thisObject(thisMObject()); MObject update; MPlug(thisObject, ca_constraint).getValue(update); if(m_constraint) { m_constraint->set_damping((float) data.inputValue(ia_damping).asDouble()); m_constraint->set_breakThreshold((float) data.inputValue(ia_breakThreshold).asDouble()); vec3f lowLin, uppLin, lowAng, uppAng; float3& mLowLin = data.inputValue(ia_lowerLinLimit).asFloat3(); float3& mUppLin = data.inputValue(ia_upperLinLimit).asFloat3(); float3& mLowAng = data.inputValue(ia_lowerAngLimit).asFloat3(); float3& mUppAng = data.inputValue(ia_upperAngLimit).asFloat3(); for(int j = 0; j < 3; j++) { lowLin[j] = mLowLin[j]; uppLin[j] = mUppLin[j]; lowAng[j] = deg2rad(mLowAng[j]); uppAng[j] = deg2rad(mUppAng[j]); } m_constraint->set_LinLimit(lowLin, uppLin); m_constraint->set_AngLimit(lowAng, uppAng); } data.outputValue(ca_constraintParam).set(true); data.setClean(plug); }
void mpBox::draw( M3dView & view, const MDagPath & path, M3dView::DisplayStyle style, M3dView::DisplayStatus status ) { float xsize, ysize, zsize; MObject thisNode = thisMObject(); float r, g, b, a; float rotx, roty, rotz, ba; int lw, dt; MObject color; MObject rotate; _COMMON_ATTR_READ_; //zsize MPlug xsPlug = MPlug( thisNode, aXsize ); xsPlug.getValue( xsize ); //ysize MPlug ysPlug = MPlug( thisNode, aYsize ); ysPlug.getValue( ysize ); //zsize MPlug zsPlug = MPlug( thisNode, aZsize ); zsPlug.getValue( zsize ); //drawType MPlug drPlug = MPlug( thisNode, aDrawType ); drPlug.getValue( dt ); view.beginGL(); glPushMatrix(); glRotatef(rotx ,1.0,0.0,0.0); glRotatef(roty ,0.0,1.0,0.0); glRotatef(rotz ,0.0,0.0,1.0); glPushAttrib(GL_ALL_ATTRIB_BITS); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); //draw Infront glDepthFunc(GL_LESS); glColor4f( r, g, b, a ); drawStyle(style, dt, lw); drawCube(xsize, ysize, zsize); //draw Behind glDepthFunc(GL_GREATER); glColor4f( r, g, b, ba ); drawStyle(style, dt, lw); drawCube(xsize, ysize, zsize); glPopAttrib(); glPopMatrix(); view.endGL(); }
MBoundingBox mpBox::boundingBox() const { MObject thisNode = thisMObject(); float x, y, z; MPlug xsize = MPlug( thisNode, aXsize ); xsize.getValue(x); MPlug ysize = MPlug( thisNode, aYsize ); ysize.getValue(y); MPlug zsize = MPlug( thisNode, aZsize ); zsize.getValue(z); MPoint corner1(x, y, z); MPoint corner2(-x, -y, -z); MBoundingBox bbox = MBoundingBox( corner1, corner2 ); return bbox; }
// the postConstructor() function is called immediately after the objects // constructor. It is not safe to call MPxNode member functions from the // constructor, instead they should be called here. // void inSpecular::postConstructor( ) { MStatus stat; // setMPSafe indicates that this shader can be used for multiprocessor // rendering. For a shading node to be MP safe, it cannot access any // shared global data and should only use attributes in the datablock // to get input data and store output data. // setMPSafe( true ); MDGModifier modifier; MPlug sourcePlug = MPlug(this->thisMObject(), emission); MPlug destPlug = MPlug(this->thisMObject(), aIncandescence); if( !destPlug.isConnected() ) stat = modifier.connect(sourcePlug, destPlug); stat = modifier.doIt(); }
void ProxyViz::updateGeomBox(ExampVox * dst, MObject & node) { dst->setGeomSizeMult(MPlug(node, aradiusMult).asFloat() ); dst->setGeomBox(MPlug(node, abboxminx).asFloat(), MPlug(node, abboxminy).asFloat(), MPlug(node, abboxminz).asFloat(), MPlug(node, abboxmaxx).asFloat(), MPlug(node, abboxmaxy).asFloat(), MPlug(node, abboxmaxz).asFloat()); }
void nailConstraintNode::computeWorldMatrix(const MPlug& plug, MDataBlock& data) { // std::cout << "nailConstraintNode::computeWorldMatrix" << std::endl; MObject thisObject(thisMObject()); MFnDagNode fnDagNode(thisObject); MObject update; MPlug(thisObject, ca_constraint).getValue(update); MPlug(thisObject, ca_constraintParam).getValue(update); MStatus status; MFnTransform fnParentTransform(fnDagNode.parent(0, &status)); MVector mtranslation = fnParentTransform.getTranslation(MSpace::kTransform, &status); // MQuaternion mrotation; // fnParentTransform.getRotation(mrotation, MSpace::kTransform); if(m_constraint) { vec3f world; m_constraint->get_world(world); if(world[0] != float(mtranslation.x) || world[1] != float(mtranslation.y) || world[2] != float(mtranslation.z)) { /* mat4x4f xform; m_constraint->rigid_body()->get_transform(xform); vec4f pivot = prod(trans(xform), vec4f(mtranslation.x, mtranslation.y, mtranslation.z, 1.0)); std::cout << "pivot (" << pivot[0] << "," << pivot[0] << "," << pivot[0] << ")" << std::endl; */ // std::cout << "mtranslation (" << mtranslation[0] << "," << mtranslation[0] << "," << mtranslation[0] << ")" << std::endl; m_constraint->set_world(vec3f((float) mtranslation[0], (float) mtranslation[1], (float) mtranslation[2])); } } data.setClean(plug); }
void nailConstraintNode::computeConstraintParam(const MPlug& plug, MDataBlock& data) { // std::cout << "nailConstraintNode::computeRigidBodyParam" << std::endl; MObject thisObject(thisMObject()); MObject update; MPlug(thisObject, ca_constraint).getValue(update); if(m_constraint) { m_constraint->set_damping((float) data.inputValue(ia_damping).asDouble()); } data.outputValue(ca_constraintParam).set(true); data.setClean(plug); }
void sixdofConstraintNode::computeConstraintParam(const MPlug& plug, MDataBlock& data) { // std::cout << "sixdofConstraintNode::computeRigidBodyParam" << std::endl; MObject thisObject(thisMObject()); MObject update; MPlug(thisObject, ca_constraint).getValue(update); if(m_constraint) { m_constraint->set_damping((float) data.inputValue(ia_damping).asDouble()); float lin_lower = (float) data.inputValue(ia_lowerLinLimit).asDouble(); float lin_upper = (float) data.inputValue(ia_upperLinLimit).asDouble(); m_constraint->set_LinLimit(lin_lower, lin_upper); float ang_lower = (float) data.inputValue(ia_lowerAngLimit).asDouble(); float ang_upper = (float) data.inputValue(ia_upperAngLimit).asDouble(); m_constraint->set_AngLimit(ang_lower, ang_upper); } data.outputValue(ca_constraintParam).set(true); data.setClean(plug); }
void sixdofConstraintNode::computeWorldMatrix(const MPlug& plug, MDataBlock& data) { MObject thisObject(thisMObject()); MFnDagNode fnDagNode(thisObject); MObject update; MPlug(thisObject, ca_constraint).getValue(update); MPlug(thisObject, ca_constraintParam).getValue(update); MStatus status; MFnTransform fnParentTransform(fnDagNode.parent(0, &status)); double fixScale[3] = { 1., 1., 1. }; // lock scale fnParentTransform.setScale(fixScale); MVector mtranslation = fnParentTransform.getTranslation(MSpace::kTransform, &status); if(bSolverNode::isStartTime) { // allow to edit pivots MPlug plgRigidBodyA(thisObject, ia_rigidBodyA); MPlug plgRigidBodyB(thisObject, ia_rigidBodyB); MObject update; //force evaluation of the rigidBody plgRigidBodyA.getValue(update); if(plgRigidBodyA.isConnected()) { MPlugArray connections; plgRigidBodyA.connectedTo(connections, true, true); if(connections.length() != 0) { MFnDependencyNode fnNode(connections[0].node()); if(fnNode.typeId() == boingRBNode::typeId) { MObject rbAObj = fnNode.object(); boingRBNode *pRigidBodyNodeA = static_cast<boingRBNode*>(fnNode.userNode()); MPlug(rbAObj, pRigidBodyNodeA->worldMatrix).elementByLogicalIndex(0).getValue(update); } } } plgRigidBodyB.getValue(update); if(plgRigidBodyB.isConnected()) { MPlugArray connections; plgRigidBodyB.connectedTo(connections, true, true); if(connections.length() != 0) { MFnDependencyNode fnNode(connections[0].node()); if(fnNode.typeId() == boingRBNode::typeId) { MObject rbBObj = fnNode.object(); boingRBNode *pRigidBodyNodeB = static_cast<boingRBNode*>(fnNode.userNode()); MPlug(rbBObj, pRigidBodyNodeB->worldMatrix).elementByLogicalIndex(0).getValue(update); } } } if(m_constraint) { MQuaternion mrotation; fnParentTransform.getRotation(mrotation, MSpace::kTransform); bool doUpdatePivot = m_constraint->getPivotChanged(); if(!doUpdatePivot) { vec3f worldP; quatf worldR; m_constraint->get_world(worldP, worldR); float deltaPX = worldP[0] - float(mtranslation.x); float deltaPY = worldP[1] - float(mtranslation.y); float deltaPZ = worldP[2] - float(mtranslation.z); float deltaRX = (float)mrotation.x - worldR[1]; float deltaRY = (float)mrotation.y - worldR[2]; float deltaRZ = (float)mrotation.z - worldR[3]; float deltaRW = (float)mrotation.w - worldR[0]; float deltaSq = deltaPX * deltaPX + deltaPY * deltaPY + deltaPZ * deltaPZ + deltaRX * deltaRX + deltaRY * deltaRY + deltaRZ * deltaRZ + deltaRW * deltaRW; doUpdatePivot = (deltaSq > FLT_EPSILON); } if(doUpdatePivot) { m_constraint->set_world(vec3f((float) mtranslation[0], (float) mtranslation[1], (float) mtranslation[2]), quatf((float)mrotation.w, (float)mrotation.x, (float)mrotation.y, (float)mrotation.z)); vec3f pivInA, pivInB; quatf rotInA, rotInB; m_constraint->get_frameA(pivInA, rotInA); m_constraint->get_frameB(pivInB, rotInB); MDataHandle hPivInA = data.outputValue(ia_pivotInA); float3 &ihPivInA = hPivInA.asFloat3(); MDataHandle hPivInB = data.outputValue(ia_pivotInB); float3 &ihPivInB = hPivInB.asFloat3(); for(int i = 0; i < 3; i++) { ihPivInA[i] = pivInA[i]; ihPivInB[i] = pivInB[i]; } MDataHandle hRotInA = data.outputValue(ia_rotationInA); float3 &hrotInA = hRotInA.asFloat3(); MQuaternion mrotA(rotInA[1], rotInA[2], rotInA[3], rotInA[0]); MEulerRotation newrotA(mrotA.asEulerRotation()); hrotInA[0] = rad2deg((float)newrotA.x); hrotInA[1] = rad2deg((float)newrotA.y); hrotInA[2] = rad2deg((float)newrotA.z); MDataHandle hRotInB = data.outputValue(ia_rotationInB); float3 &hrotInB = hRotInB.asFloat3(); MQuaternion mrotB(rotInB[1], rotInB[2], rotInB[3], rotInB[0]); MEulerRotation newrotB(mrotB.asEulerRotation()); hrotInB[0] = rad2deg((float)newrotB.x); hrotInB[1] = rad2deg((float)newrotB.y); hrotInB[2] = rad2deg((float)newrotB.z); m_constraint->setPivotChanged(false); m_constraint->get_local_frameA(m_PivInA, m_RotInA); m_constraint->get_local_frameB(m_PivInB, m_RotInB); } } } else { // if not start time, lock position and rotation if(m_constraint) { vec3f worldP; quatf worldR; m_constraint->get_world(worldP, worldR); fnParentTransform.setTranslation(MVector(worldP[0], worldP[1], worldP[2]), MSpace::kTransform); fnParentTransform.setRotation(MQuaternion(worldR[1], worldR[2], worldR[3], worldR[0])); } } m_initialized = true; data.setClean(plug); }
//standard attributes void sixdofConstraintNode::reComputeConstraint(const MPlug& plug, MDataBlock& data1) { if (!m_initialized) return; // std::cout << "sixdofConstraintNode::computeConstraint" << std::endl; m_disableCollision = data1.inputValue(ia_disableCollide).asBool(); MObject thisObject(thisMObject()); MPlug plgRigidBodyA(thisObject, ia_rigidBodyA); MPlug plgRigidBodyB(thisObject, ia_rigidBodyB); MObject update; //force evaluation of the rigidBody plgRigidBodyA.getValue(update); plgRigidBodyB.getValue(update); rigid_body_t::pointer rigid_bodyA; if(plgRigidBodyA.isConnected()) { MPlugArray connections; plgRigidBodyA.connectedTo(connections, true, true); if(connections.length() != 0) { MFnDependencyNode fnNodeA(connections[0].node()); if(fnNodeA.typeId() == boingRBNode::typeId) { boingRBNode *pRigidBodyNodeA = static_cast<boingRBNode*>(fnNodeA.userNode()); rigid_bodyA = pRigidBodyNodeA->rigid_body(); } else { std::cout << "sixdofConstraintNode connected to a non-rigidbody node!" << std::endl; } } } rigid_body_t::pointer rigid_bodyB; if(plgRigidBodyB.isConnected()) { MPlugArray connections; plgRigidBodyB.connectedTo(connections, true, true); if(connections.length() != 0) { MFnDependencyNode fnNodeB(connections[0].node()); if(fnNodeB.typeId() == boingRBNode::typeId) { boingRBNode *pRigidBodyNodeB = static_cast<boingRBNode*>(fnNodeB.userNode()); rigid_bodyB = pRigidBodyNodeB->rigid_body(); } else { std::cout << "sixdofConstraintNode connected to a non-rigidbody node!" << std::endl; } } } if((rigid_bodyA != NULL) && (rigid_bodyB != NULL)) { constraint_t::pointer constraint = static_cast<constraint_t::pointer>(m_constraint); bt_sixdof_constraint_t* sixdof_impl = dynamic_cast<bt_sixdof_constraint_t*>(constraint->pubImpl()); rigid_bodyA->remove_constraint(sixdof_impl); rigid_bodyB->remove_constraint(sixdof_impl); solver_t::remove_constraint(constraint); m_constraint = solver_t::create_sixdof_constraint(rigid_bodyA, m_PivInA, m_RotInA, rigid_bodyB, m_PivInB, m_RotInB); constraint = static_cast<constraint_t::pointer>(m_constraint); solver_t::add_constraint(constraint, m_disableCollision); } else if(rigid_bodyA != NULL) { //not connected to a rigid body, put a default one constraint_t::pointer constraint = static_cast<constraint_t::pointer>(m_constraint); bt_sixdof_constraint_t* sixdof_impl = dynamic_cast<bt_sixdof_constraint_t*>(constraint->pubImpl()); rigid_bodyA->remove_constraint(sixdof_impl); solver_t::remove_constraint(constraint); m_constraint = solver_t::create_sixdof_constraint(rigid_bodyA, m_PivInB, m_RotInB); constraint = static_cast<constraint_t::pointer>(m_constraint); solver_t::add_constraint(constraint, m_disableCollision); }else if(rigid_bodyB != NULL) { //not connected to a rigid body, put a default one constraint_t::pointer constraint = static_cast<constraint_t::pointer>(m_constraint); bt_sixdof_constraint_t* sixdof_impl = dynamic_cast<bt_sixdof_constraint_t*>(constraint->pubImpl()); rigid_bodyB->remove_constraint(sixdof_impl); solver_t::remove_constraint(constraint); m_constraint = solver_t::create_sixdof_constraint(rigid_bodyB, m_PivInA, m_RotInA); constraint = static_cast<constraint_t::pointer>(m_constraint); solver_t::add_constraint(constraint, m_disableCollision); } float val = 0.f; MPlug(thisObject, sixdofConstraintNode::ia_damping).getValue(val); m_constraint->set_damping(val); MPlug(thisObject, sixdofConstraintNode::ia_breakThreshold).getValue(val); m_constraint->set_breakThreshold(val); vec3f lowLin, uppLin, lowAng, uppAng; for (int i=0;i<3;i++) { lowLin[i] = 0.f; uppLin[i] = 0.f; lowAng[i] = 0.f; uppAng[i] = 0.f; } { MPlug ll(thisObject, sixdofConstraintNode::ia_lowerLinLimit); if (ll.isCompound()) { for (int i=0;i<3;i++) { ll.child(i).getValue(lowLin[i]); } } } { MPlug ul(thisObject, sixdofConstraintNode::ia_upperLinLimit); if (ul.isCompound()) { for (int i=0;i<3;i++) { ul.child(i).getValue(uppLin[i]); } } } { MPlug all(thisObject, sixdofConstraintNode::ia_lowerAngLimit); if (all.isCompound()) { for (int i=0;i<3;i++) { float f; all.child(i).getValue(f); lowAng[i] = deg2rad(f); } } } { MPlug aul(thisObject, sixdofConstraintNode::ia_upperAngLimit); if (aul.isCompound()) { for (int i=0;i<3;i++) { float f; aul.child(i).getValue(f); uppAng[i] = deg2rad(f); } } } m_constraint->set_LinLimit(lowLin, uppLin); m_constraint->set_AngLimit(lowAng, uppAng); data1.outputValue(ca_constraint).set(true); data1.setClean(plug); }
//THIS FUNCTION IS QUITE COMPLICATED BECAUSE //IT HAS TO DEAL WITH MAYA NAME MANGLING! //tokenize the path. //add each token into the element list which tracks the attributes and indices //for each entry added make sure there are no parents left out from maya name mangling. //after the list is populated and missing elements area added //we reiterate and produce the final result. MPlug FxInternal::DecodePlug(const CStringA& plugStr) { MPlug result; MFnDependencyNode depNode(GetSite()); CAtlList<PathDecodeElement> elementList; //tokenize the path int iLastPos=0; int iThisPos=0; CStringA subStr; while( iLastPos= iThisPos, subStr=plugStr.Tokenize(".[]", iThisPos), iThisPos != -1 ) { //char lastChar= subStr[iLastPos]; //char thisChar= subStr[iThisPos]; //are we looking at a named portion? if(iLastPos == 0 || plugStr[iLastPos-1]=='.' || (plugStr[iLastPos-1]==']' && plugStr[iLastPos]=='.')) { //if the name is length zero then it must be the case when // you do last[#]. The situation is caused by the sequence "]." //if we dont have a name we can skip since only 1d arrays are allowed. if(subStr.GetLength() > 0) { //everything we add is going to be based on the current tail. //because we are adding parents, as we find parents we can continue //to add them to this position so that they will order themselves properly POSITION insertPos= elementList.GetTailPosition(); //calculate the cancel condition. //it is the current tail's object if a tail exists otherwise NULL //NULL indicates go all the way to the root MObject cancelObj= MObject::kNullObj; if(elementList.GetCount() > 0) { cancelObj= elementList.GetTail().Attribute.object(); } //get the object we are currently working with MObject thisObj= depNode.attribute(subStr.GetString()); if(thisObj.isNull()) return MPlug();//Critical element of the path was not found...return NULL //add it to the list so that we have something to insertBefore elementList.AddTail(); elementList.GetTail().Name= subStr; elementList.GetTail().Attribute.setObject(thisObj); //walk through all of the parents until we reach cancel condition. //we can add the current element onto the list in the same way. for( MFnAttribute itrAttr( elementList.GetTail().Attribute.parent() ); !itrAttr.object().isNull() && (cancelObj != itrAttr.object()); itrAttr.setObject(itrAttr.parent())) { PathDecodeElement element; element.Attribute.setObject( itrAttr.object() ); //we change the position so that the grandparent is inserted before the parent insertPos= elementList.InsertBefore( insertPos, element); } } } //are we looking at a numbered portion? else if(plugStr[iLastPos-1]=='[' && plugStr[iThisPos-1]==']') { //if so change the array index. elementList.GetTail().IsArray= true; elementList.GetTail().Index = atoi( subStr.GetString() ); } else DXCC_ASSERT(false);//VERY POORLY FORMED STRING } //produce the result plug off of the elementList. bool first= true; for(POSITION pos= elementList.GetHeadPosition(); pos != NULL; elementList.GetNext(pos)) { PathDecodeElement& element= elementList.GetAt(pos); if(first) {//on first one we initialize the result first= false; result= MPlug( GetSite(), element.Attribute.object() ); } else { result= result.child( element.Attribute.object() ); } if(element.IsArray) { result= result.elementByLogicalIndex(element.Index); } if(result.isNull()) return MPlug();//Critical element of the path was not found...return NULL } return result; }
MStatus TestDeformer::deform(MDataBlock& data, MItGeometry& iter, const MMatrix& localToWorldMatrix, unsigned int mIndex) { MStatus status; // get the current node state short initialized_mapping = data.inputValue( initialized_data, &status).asShort(); CHECK_MSTATUS(status); __debug("%s(), initialized_mapping=%d, mIndex=%d", __FUNCTION__, initialized_mapping, mIndex); if( initialized_mapping == 1 ) { initVertMapping(data, iter, localToWorldMatrix, mIndex); // set initialized_data to 2 automatically. User don't have to set it manully. MObject tObj = thisMObject(); MPlug setInitMode = MPlug( tObj, initialized_data ); setInitMode.setShort( 2 ); // and sync initialized_mapping from initialized_data // so, the code section: // if (initialized_mapping == 2) // { // ... // } // will be executed when this deform() function is called next time. initialized_mapping = data.inputValue( initialized_data, &status ).asShort(); CHECK_MSTATUS(status); } if( initialized_mapping == 2 ) { envelope = MPxDeformerNode::envelope; MDataHandle envelopeHandle = data.inputValue( envelope, &status ); CHECK_MSTATUS( status ); MArrayDataHandle vertMapArrayData = data.inputArrayValue( vert_map, &status ); CHECK_MSTATUS( status ); MArrayDataHandle meshAttrHandle = data.inputArrayValue( driver_mesh, &status ); CHECK_MSTATUS( status ); /// 1. init tempOutputPts to zero points MPointArray tempOutputPts; iter.reset(); while( !iter.isDone(&status) ) { CHECK_MSTATUS(tempOutputPts.append(MPoint(0, 0, 0))); CHECK_MSTATUS(iter.next()); } assert(tempOutputPts.length() == iter.count()); /// 2. set tempOutputPts to deform values which comes from each driver mesh iter.reset(); int numMeshes = meshAttrHandle.elementCount(); __debug("%s(), numMeshes=%d", __FUNCTION__, numMeshes); CHECK_MSTATUS(meshAttrHandle.jumpToElement(0)); // for each driver mesh for( int count=0; count < numMeshes; ++count ) { __debug("%s(), count=%d", __FUNCTION__, count); // for one driver mesh: currentMesh MDataHandle currentMesh = meshAttrHandle.inputValue(&status); CHECK_MSTATUS( status ); MObject meshMobj = currentMesh.asMesh(); __debugMeshInfo(__FUNCTION__, meshMobj); // accumulate deform values of currentMesh to tempOutputPts _deform_on_one_mesh(data, iter, localToWorldMatrix, mIndex, meshMobj, envelopeHandle, vertMapArrayData, tempOutputPts ); if( !meshAttrHandle.next() ) { break; } }// for each driver mesh /// 3. add deform value to this geometry(driven mesh) int i = 0; iter.reset(); while( !iter.isDone(&status) ) { MPoint p = iter.position(MSpace::kObject, &status); CHECK_MSTATUS(status); // add the deform value to this vertex CHECK_MSTATUS(iter.setPosition( p + tempOutputPts[i]/numMeshes )); CHECK_MSTATUS(iter.next()); ++i; } assert(tempOutputPts.length() == iter.count()); }// if return( MS::kSuccess ); }