コード例 #1
0
//standard attributes
void sixdofConstraintNode::computeConstraint(const MPlug& plug, MDataBlock& data)
{
   // std::cout << "sixdofConstraintNode::computeConstraint" << std::endl;

    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() == rigidBodyNode::typeId) {
                rigidBodyNode *pRigidBodyNodeA = static_cast<rigidBodyNode*>(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() == rigidBodyNode::typeId) {
                rigidBodyNode *pRigidBodyNodeB = static_cast<rigidBodyNode*>(fnNodeB.userNode());
                rigid_bodyB = pRigidBodyNodeB->rigid_body();    
            } else {
                std::cout << "sixdofConstraintNode connected to a non-rigidbody node!" << std::endl;
            }
        }
    }

    if(rigid_bodyA && rigid_bodyB) {
        //not connected to a rigid body, put a default one
        constraint_t::pointer constraint = static_cast<constraint_t::pointer>(m_constraint);
        solver_t::remove_constraint(constraint);
        m_constraint = solver_t::create_sixdof_constraint(rigid_bodyA, vec3f(), rigid_bodyB, vec3f());
        constraint = static_cast<constraint_t::pointer>(m_constraint);
        solver_t::add_constraint(constraint);
    }

    data.outputValue(ca_constraint).set(true);
    data.setClean(plug);
}
コード例 #2
0
//standard attributes
void sixdofConstraintNode::computeConstraint(const MPlug& plug, MDataBlock& data)
{
   // std::cout << "sixdofConstraintNode::computeConstraint" << std::endl;

    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;
            }
        }
    }

        vec3f pivInA, pivInB;

        if((rigid_bodyA != NULL) && (rigid_bodyB != NULL))
        {
        constraint_t::pointer constraint = static_cast<constraint_t::pointer>(m_constraint);
        solver_t::remove_constraint(constraint);
                float3& mPivInA = data.inputValue(ia_pivotInA).asFloat3();
                float3& mPivInB = data.inputValue(ia_pivotInB).asFloat3();
                for(int i = 0; i < 3; i++)
                {
                        pivInA[i] = (float)mPivInA[i];
                        pivInB[i] = (float)mPivInB[i];
                }
                float3& mRotInA = data.inputValue(ia_rotationInA).asFloat3();
        MEulerRotation meulerA(deg2rad(mRotInA[0]), deg2rad(mRotInA[1]), deg2rad(mRotInA[2]));
        MQuaternion mquatA = meulerA.asQuaternion();
                quatf rotA((float)mquatA.w, (float)mquatA.x, (float)mquatA.y, (float)mquatA.z);
                float3& mRotInB = data.inputValue(ia_rotationInB).asFloat3();
        MEulerRotation meulerB(deg2rad(mRotInB[0]), deg2rad(mRotInB[1]), deg2rad(mRotInB[2]));
        MQuaternion mquatB = meulerB.asQuaternion();
                quatf rotB((float)mquatB.w, (float)mquatB.x, (float)mquatB.y, (float)mquatB.z);
        m_constraint = solver_t::create_sixdof_constraint(rigid_bodyA, pivInA, rotA, rigid_bodyB, pivInB, rotB);
        constraint = static_cast<constraint_t::pointer>(m_constraint);
        solver_t::add_constraint(constraint, data.inputValue(ia_disableCollide).asBool());
        }
    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);
        solver_t::remove_constraint(constraint);
                float3& mPivInA = data.inputValue(ia_pivotInA).asFloat3();
                for(int i = 0; i < 3; i++)
                {
                        pivInA[i] = (float)mPivInA[i];
                }
                float3& mRotInA = data.inputValue(ia_rotationInA).asFloat3();
        MEulerRotation meuler(deg2rad(mRotInA[0]), deg2rad(mRotInA[1]), deg2rad(mRotInA[2]));
        MQuaternion mquat = meuler.asQuaternion();
                quatf rotA((float)mquat.w, (float)mquat.x, (float)mquat.y, (float)mquat.z);
        m_constraint = solver_t::create_sixdof_constraint(rigid_bodyA, pivInA, rotA);
        constraint = static_cast<constraint_t::pointer>(m_constraint);
        solver_t::add_constraint(constraint, data.inputValue(ia_disableCollide).asBool());
    }


	if (m_constraint)
	{
		m_constraint->get_local_frameA(m_PivInA, m_RotInA);
		m_constraint->get_local_frameB(m_PivInB, m_RotInB);
	}
    data.outputValue(ca_constraint).set(true);
    data.setClean(plug);
}
コード例 #3
0
//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);
}
コード例 #4
0
//standard attributes
void sliderConstraintNode::reComputeConstraint()
{
	if (!m_initialized)
		return;
   // std::cout << "sliderConstraintNode::computeConstraint" << std::endl;

    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 << "sliderConstraintNode 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 << "sliderConstraintNode 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);
		if (constraint)
		{
			bt_slider_constraint_t* hinge_impl = dynamic_cast<bt_slider_constraint_t*>(constraint->pubImpl());
			rigid_bodyA->remove_constraint(hinge_impl);
			rigid_bodyB->remove_constraint(hinge_impl);
			solver_t::remove_constraint(constraint);
		}
		
        m_constraint = solver_t::create_slider_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);
        if (constraint)
		{
			bt_slider_constraint_t* hinge_impl = dynamic_cast<bt_slider_constraint_t*>(constraint->pubImpl());
			rigid_bodyA->remove_constraint(hinge_impl);
			solver_t::remove_constraint(constraint);
		}
        m_constraint = solver_t::create_slider_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);
		if (constraint)
		{
			bt_slider_constraint_t* hinge_impl = dynamic_cast<bt_slider_constraint_t*>(constraint->pubImpl());
			rigid_bodyB->remove_constraint(hinge_impl);
			solver_t::remove_constraint(constraint);
		}
        m_constraint = solver_t::create_slider_constraint(rigid_bodyB, m_PivInA, m_RotInA);
        constraint = static_cast<constraint_t::pointer>(m_constraint);
        solver_t::add_constraint(constraint, m_disableCollision);
		
	}

	if (m_constraint)
	{
		float val = 0.f;
		MPlug(thisObject, sliderConstraintNode::ia_damping).getValue(val);
		m_constraint->set_damping(val);
		MPlug(thisObject, sliderConstraintNode::ia_breakThreshold).getValue(val);
		m_constraint->set_breakThreshold(val);
		float lin_lower=0.f;
		float lin_upper=0.f;
		MPlug(thisObject, sliderConstraintNode::ia_lowerLinLimit).getValue(lin_lower);
		MPlug(thisObject, sliderConstraintNode::ia_upperLinLimit).getValue(lin_upper);
		m_constraint->set_LinLimit(lin_lower, lin_upper);
		float ang_lower=0.f;
		float ang_upper=0.f;
		MPlug(thisObject, sliderConstraintNode::ia_lowerAngLimit).getValue(ang_lower);
		MPlug(thisObject, sliderConstraintNode::ia_upperAngLimit).getValue(ang_upper);
		m_constraint->set_AngLimit(deg2rad(ang_lower), deg2rad(ang_upper));

		m_constraint->setPivotChanged(true);
	}
}