예제 #1
0
std::vector<std::wstring> ManipulatorEffect::GetLocatorNames() const
{
	Ogre::Entity* ent = ManipulatorSystem.GetObject().GetSelection();
	assert(ent);

	std::vector<std::wstring> ret;
	//M3模型从max导出时locator命名为Ref_xxx形式
	Ogre::SkeletonPtr skel = ent->getMesh()->getSkeleton();
	Ogre::Skeleton::BoneIterator iter = skel->getBoneIterator();

	while (iter.hasMoreElements())
	{
		Ogre::Bone* pBone = iter.peekNext();
		if(pBone->getName().find("Ref_") != Ogre::String::npos)
			ret.push_back(Utility::EngineToUnicode(pBone->getName()));

		iter.getNext();
	}

	return std::move(ret);
}
예제 #2
0
파일: IKChain.cpp 프로젝트: sandsmark/loom
void IKChain::Initialize()
{
	// Get skeleton root Ogre::Bone
	Ogre::Bone* oBoneRoot = mOgreSkeleton->getRootBone();
	Ogre::Vector3 vecBonePos = oBoneRoot->getPosition();
	oBoneRoot->setManuallyControlled(true);
	// Create IK root
	mIKRoot = new IKJoint(oBoneRoot, NULL, oBoneRoot->getPosition().x + mMeshNode->getPosition().x, oBoneRoot->getPosition().y + mMeshNode->getPosition().y, oBoneRoot->getPosition().z + mMeshNode->getPosition().z);
	// Keep track of previously processed Ogre::Bone
	IKJoint* oLastIKJoint = mIKRoot;
	// Current Ogre::Bone
	Ogre::Bone* oCurrentBone = oBoneRoot;
	cout << "Current Ogre::Bone: " << oCurrentBone->getName() << endl;
	mJointCount = 1;
	// Ogre::Bone iterator
	Ogre::Node::ChildNodeIterator oIterator = oCurrentBone->getChildIterator();
	Ogre::Vector3 vecParent = oBoneRoot->_getDerivedPosition();
	while ( oIterator.hasMoreElements() ) 
	{
		oCurrentBone = (Ogre::Bone*)oIterator.getNext();
		oCurrentBone->setManuallyControlled(true);
		cout << "Current Ogre::Bone: " << oCurrentBone->getName() << endl;
		Ogre::Vector3 vecDerived = oCurrentBone->_getDerivedPosition();
		Ogre::Vector3 vecJointPos = oCurrentBone->_getDerivedPosition() + mMeshNode->getPosition();
		vecBonePos = oCurrentBone->getPosition();
		IKJoint* oNewJoint = new IKJoint(oCurrentBone, oLastIKJoint, vecJointPos.x, vecJointPos.y, vecJointPos.z);
		oLastIKJoint->SetChild(oNewJoint);
		oLastIKJoint = oNewJoint;
		oIterator = oCurrentBone->getChildIterator();
		mJointCount++;
		mChainLength += vecParent.distance(oCurrentBone->_getDerivedPosition());
		vecParent = oCurrentBone->_getDerivedPosition();
	}
	mChainLength = mChainLength;
	mIKEffector = oLastIKJoint;
	cout << "Ogre::Bone count is " << mJointCount << endl;
}
예제 #3
0
void SkeletonDebug::SetSkeletonDebug(
    Ogre::Entity* entity,
    Ogre::SceneManager* sceneManager,
    const bool enable,
    Ogre::Real boneSize,
    Ogre::Real axisSize)
{
    if (!HasSkeletonDebug(entity))
    {
        GetAxesMaterial();
        GetBoneMaterial();
        GetAxesMesh();
        GetBoneMesh(boneSize);

        const int numBones = entity->getSkeleton()->getNumBones();

        for(unsigned short int iBone = 0; iBone < numBones; ++iBone)
        {
            Ogre::Bone* pBone = entity->getSkeleton()->getBone(iBone);
            if ( !pBone )
            {
                assert(false);
                continue;
            }

            Ogre::Entity *ent;
            Ogre::TagPoint *tp;

            // Absolutely HAVE to create bone representations first. Otherwise we
            // would get the wrong child count because an attached object counts as
            // a child would be nice to have a function that only gets the children
            // that are bones...
            unsigned short numChildren = pBone->numChildren();
            if (numChildren == 0)
            {
                // There are no children, but we should still represent the bone
                // Creates a bone of length 1 for leaf bones (bones without children)
                ent = sceneManager->createEntity(boneName);
                ent->setCastShadows(false);
                tp = entity->attachObjectToBone(
                    pBone->getName(),
                    (Ogre::MovableObject*)ent,
                    Ogre::Quaternion(Ogre::Degree(270.0f), Ogre::Vector3::UNIT_Z));

                const Ogre::Real modBoneSize =
                    boneSize + boneSize * boneSize * 15.0f;

                tp->setScale(modBoneSize, boneSize, modBoneSize);
            }
            else
            {
                for(unsigned short i = 0; i < numChildren; ++i)
                {
                    if (dynamic_cast<Ogre::Bone*>(pBone->getChild(i)))
                    {
                        Ogre::Vector3 childPosition = pBone->getChild(i)->getPosition();
                        // If the length is zero, no point in creating the bone representation
                        float length = childPosition.length();
                        if(length < 0.00001f)
                            continue;

                        Ogre::Quaternion rotation = Ogre::Vector3::UNIT_Y.getRotationTo(
                            childPosition);

                        ent = sceneManager->createEntity(boneName);
                        ent->setCastShadows(false);
                        tp = entity->attachObjectToBone(
                            pBone->getName(),
                            (Ogre::MovableObject*)ent,
                            rotation);

                        const Ogre::Real modBoneSize =
                            boneSize + boneSize * length * 15.0f;

                        tp->setScale(modBoneSize, length, modBoneSize);
                    }
                }
            }

            ent = sceneManager->createEntity(axesName);
            ent->setCastShadows(false);
            tp = entity->attachObjectToBone(pBone->getName(), (Ogre::MovableObject*)ent);
            // Make sure we don't wind up with tiny/giant axes and that one axis doesnt get squashed
            tp->setScale(
                (axisSize/entity->getParentSceneNode()->getScale().x),
                (axisSize/entity->getParentSceneNode()->getScale().y),
                (axisSize/entity->getParentSceneNode()->getScale().z));
        }
    }

    if (enable)
    {
        ShowSkeletonDebug(entity);
    }
    else
    {
        HideSkeletonDebug(entity);
    }
}
PhysicsRagDoll::RagBone* PhysicsRagDoll::_addAllBones(PhysicsRagDoll::RagBone* parent, TiXmlElement* boneElement, Actor* parentActor)
{
	// get the information for the bone represented by this element.
    Ogre::Vector3 dir = getAttributeValueAsVector3(boneElement, "dir");
	Ogre::Real length = getAttributeValueAsReal(boneElement, "length");
		
	Ogre::Vector3 size = getAttributeValueAsVector3(boneElement, "size");
	
	
	Ogre::String skeleton_bone = getAttributeValueAsStdString(boneElement, "skeleton_bone");
	Ogre::Bone* ogrebone = mSkeleton->getBone(skeleton_bone);


	Ogre::String shapestr = getAttributeValueAsStdString(boneElement, "shape");
	PhysicsRagDoll::RagBone::BoneShape shape = PhysicsRagDoll::RagBone::BS_BOX;

	if (shapestr=="box")
		shape = PhysicsRagDoll::RagBone::BS_BOX;
	
	if (shapestr=="capsule")
		shape = PhysicsRagDoll::RagBone::BS_CAPSULE;
	
	if (shapestr=="cylinder")
		shape = PhysicsRagDoll::RagBone::BS_CYLINDER;
	
	if (shapestr=="cone")
		shape = PhysicsRagDoll::RagBone::BS_CONE;
	
	if (shapestr=="ellipsoid")
		shape = PhysicsRagDoll::RagBone::BS_ELLIPSOID;

	if (shapestr=="hull")
		shape = PhysicsRagDoll::RagBone::BS_CONVEXHULL;

	Ogre::Real mass = getAttributeValueAsReal(boneElement, "mass");
	
	///////////////////////////////////////////////////////////////////////////////
	RagBone* me = _addBone(mWorld, parent, dir, shape, size, mass, ogrebone,  parentActor);
	///////////////////////////////////////////////////////////////////////////////

	// position the bone.
	Ogre::Quaternion boneorient = mNode->_getDerivedOrientation() * ogrebone->_getDerivedOrientation();
	Ogre::Vector3 bonepos;
	if (shape != PhysicsRagDoll::RagBone::BS_CONVEXHULL)
		bonepos = mNode->_getFullTransform() * ogrebone->_getDerivedPosition() + (boneorient * (dir * (length*0.5f)));
	else
		bonepos = mNode->_getFullTransform() * ogrebone->_getDerivedPosition();

    if (me->getBody())
    	me->getBody()->setPositionOrientation(bonepos, boneorient);

	// set offsets
	if (!parent)
	{
		Ogre::Quaternion offsetorient = (boneorient.Inverse()) * mNode->_getDerivedOrientation();
		Ogre::Vector3 offsetpos = boneorient.Inverse() * (mNode->_getDerivedPosition() - bonepos);
		me->setOffset(offsetorient, offsetpos);
	}


	// get the joint to connect this bone with it's parent.
	if (parent && me->getBody())
	{
		TiXmlElement* jointElement = getChildNamed(boneElement, "Joint");
		if (!jointElement)
		{
			// error!
            LOG_ERROR(Logger::CORE, " Joint not found while creating Ragdoll! ");
			return me;
		}

		Ogre::Vector3 jointpin = getAttributeValueAsVector3(jointElement, "pin");
		Ogre::String jointtypestr = getAttributeValueAsStdString(jointElement, "type");
		PhysicsRagDoll::JointType jointtype = PhysicsRagDoll::JT_BALLSOCKET;

		if (jointtypestr == "ballsocket")
			jointtype = PhysicsRagDoll::JT_BALLSOCKET;

		if (jointtypestr == "hinge")
			jointtype = PhysicsRagDoll::JT_HINGE;


		Ogre::Real limit1 = getAttributeValueAsReal(jointElement, "limit1");
		Ogre::Real limit2 = getAttributeValueAsReal(jointElement, "limit2");

		Ogre::Vector3 jpos = mNode->_getFullTransform() * ogrebone->_getDerivedPosition();
		Ogre::Vector3 jpin = (mNode->_getDerivedOrientation() * parent->getOgreBone()->_getDerivedOrientation()) * jointpin;

		_joinBones(jointtype, parent, me, jpos, jpin, limit1, limit2, mWorld);
	}
	
    LOG_MESSAGE(Logger::CORE, " added bone from '"+ogrebone->getName()+"'.");

	///////////////////////////////////////////////////////////////////////////////
	///////////////////////////////////////////////////////////////////////////////
	// add all children of this bone.
    for (TiXmlNode* cur = boneElement->FirstChild(); cur; cur = cur->NextSibling())
    {
        if (cur->Type() == TiXmlNode::ELEMENT && hasNodeName(cur, "Bone"))
        {
		    _addAllBones(me, cur->ToElement(), parentActor);
        }
	}

    return me;
}