示例#1
0
void gkSkeletonLoader::makeManual(gkEntity* ent)
{

	Ogre::Entity* oent = ent->getEntity();
	if (!oent || !oent->hasSkeleton())
		return;


	Ogre::SkeletonInstance* inst = oent->getSkeleton();


	gkBone::BoneList::Iterator it = m_skeleton->getBoneList().iterator();
	while (it.hasMoreElements())
	{
		gkBone* bone = it.getNext();


		if (inst->hasBone(bone->getName()))
		{
			Ogre::Bone* obone = inst->getBone(bone->getName());
			bone->_setOgreBone(obone);

			obone->setManuallyControlled(true);
		}
	}
}
示例#2
0
void CreatureWeaponAnimation::updatePart(NifOgre::ObjectScenePtr& scene, int slot)
{
    MWWorld::InventoryStore& inv = mPtr.getClass().getInventoryStore(mPtr);
    MWWorld::ContainerStoreIterator it = inv.getSlot(slot);

    if (it == inv.end())
    {
        scene.setNull();
        return;
    }
    MWWorld::Ptr item = *it;

    std::string bonename;
    if (slot == MWWorld::InventoryStore::Slot_CarriedRight)
        bonename = "Weapon Bone";
    else
        bonename = "Shield Bone";

    scene = NifOgre::Loader::createObjects(mSkelBase, bonename, mInsert, item.getClass().getModel(item));
    Ogre::Vector3 glowColor = getEnchantmentColor(item);

    setRenderProperties(scene, RV_Actors, RQG_Main, RQG_Alpha, 0,
                        !item.getClass().getEnchantment(item).empty(), &glowColor);

    if(scene->mSkelBase)
    {
        Ogre::SkeletonInstance *skel = scene->mSkelBase->getSkeleton();
        if(scene->mSkelBase->isParentTagPoint())
        {
            Ogre::Node *root = scene->mSkelBase->getParentNode();
            if(skel->hasBone("BoneOffset"))
            {
                Ogre::Bone *offset = skel->getBone("BoneOffset");

                root->translate(offset->getPosition());

                // It appears that the BoneOffset rotation is completely bogus, at least for light models.
                //root->rotate(offset->getOrientation());
                root->pitch(Ogre::Degree(-90.0f));

                root->scale(offset->getScale());
                root->setInitialState();
            }
        }
        updateSkeletonInstance(mSkelBase->getSkeleton(), skel);
    }

    // TODO:
    // type == ESM::PRT_Weapon should get an animation source based on the current offset
    // of the weapon attack animation (from its beginning, or start marker?)
    std::vector<Ogre::Controller<Ogre::Real> >::iterator ctrl(scene->mControllers.begin());
    for(;ctrl != scene->mControllers.end();ctrl++)
    {
        if(ctrl->getSource().isNull())
            ctrl->setSource(Ogre::SharedPtr<NullAnimationTime>(new NullAnimationTime()));
    }
}
示例#3
0
Ogre::Node *Animation::getNode(const std::string &name)
{
    if(mSkelBase)
    {
        Ogre::SkeletonInstance *skel = mSkelBase->getSkeleton();
        if(skel->hasBone(name))
            return skel->getBone(name);
    }
    return NULL;
}
示例#4
0
	///Get the orientation of the wrist bone
	Ogre::Quaternion getWristOrientation()
	{
		Ogre::Entity* hand = this->Entity();
		assert(hand);

		Ogre::SkeletonInstance* ske;
		Ogre::Bone* wrist;
		if(ske = hand->getSkeleton())
			if(wrist = ske->getBone("Wrist"))
				return wrist->getOrientation();			
		return Ogre::Quaternion::IDENTITY;
	}
 /**
  * Attaches an empty object to the owner. This has no effect if the owner is a node since
  * there's no notion of an "empty" object for nodes. For entities, an "empty" object corresponds
  * to a tag point that has no attachment
  */
 void AttachEmpty(const Ogre::String& name = Ogre::StringUtil::BLANK) const
 {
     if (this->entity != 0 && !this->boneName.empty())
     {
         Ogre::SkeletonInstance* skeleton = this->entity->getSkeleton();
         Ogre::Bone* bone = skeleton->getBone(this->boneName);
         //TODO: Modify Ogre to accept name when creating TagPoint
         Ogre::TagPoint* tagPoint = skeleton->createTagPointOnBone(bone);
         tagPoint->setPosition(this->attachPosition);
         tagPoint->setScale(this->attachScale);
         tagPoint->setOrientation(this->attachRotation);
     }
 }
bool LIRenAttachmentEntity::create_skeleton ()
{
	Ogre::SkeletonInstance* skeleton = entity->getSkeleton ();
	if (skeleton == NULL)
		return false;

	/* Set the initial bone transformations. */
	/* The mesh may not have set these correctly if it depended on bones
	   in external skeletons. Because of external bones, we need to set
	   the transformations using the pose skeleton of the object. */
	LIRenModelData* model = get_model ();
	if (model != NULL && model->rest_pose_buffer != NULL)
	{
		for (int i = 0 ; i < model->rest_pose_buffer->bones.count ; i++)
		{
			const LIMdlPoseBufferBone* group = model->rest_pose_buffer->bones.array + i;
			if (!group->name)
				continue;
			LIMatTransform t;
			if (!object->get_node_transform (group->name, t))
				continue;
			Ogre::Bone* bone = skeleton->getBone (i);
			bone->setPosition (t.position.x, t.position.y, t.position.z);
			bone->setOrientation (t.rotation.w, t.rotation.x, t.rotation.y, t.rotation.z);
		}
	}

	/* Make all bones manually controlled. */
	for (int i = 0 ; i < skeleton->getNumBones () ; i++)
	{
		Ogre::Bone* bone = skeleton->getBone (i);
		bone->setManuallyControlled (true);
	}

	/* Set the binding pose. */
	skeleton->setBindingPose ();

	return true;
}
示例#7
0
 void Animation::handleAnimationTransforms(){


    Ogre::SkeletonInstance* skel = base->getSkeleton();


    Ogre::Bone* b = skel->getRootBone();
	    b->setOrientation(Ogre::Real(.3),Ogre::Real(.3),Ogre::Real(.3), Ogre::Real(.3));   //This is a trick

        skel->_updateTransforms();
	    //skel->_notifyManualBonesDirty();

         base->getAllAnimationStates()->_notifyDirty();
     //base->_updateAnimation();
   //base->_notifyMoved();




    std::vector<Nif::NiKeyframeData>::iterator iter;
    int slot = 0;
    if(transformations){
    for(iter = transformations->begin(); iter != transformations->end(); iter++){
        if(time < iter->getStartTime() || time < startTime || time > iter->getStopTime())
	    {
            slot++;
		    continue;
	    }

         float x;
		float x2;

	    const std::vector<Ogre::Quaternion> & quats = iter->getQuat();

        const std::vector<float> & ttime = iter->gettTime();


        const std::vector<float> & rtime = iter->getrTime();
        int rindexJ = rindexI[slot];

	    timeIndex(time, rtime, rindexI[slot], rindexJ, x2);
	    int tindexJ = tindexI[slot];


        const std::vector<Ogre::Vector3> & translist1 = iter->getTranslist1();

        timeIndex(time, ttime, tindexI[slot], tindexJ, x);

        Ogre::Vector3 t;
        Ogre::Quaternion r;

        bool bTrans = translist1.size() > 0;


        bool bQuats = quats.size() > 0;

    if(skel->hasBone(iter->getBonename())){
        Ogre::Bone* bone = skel->getBone(iter->getBonename());
        if(bTrans){
			 Ogre::Vector3 v1 = translist1[tindexI[slot]];
            Ogre::Vector3 v2 = translist1[tindexJ];
           t = (v1 + (v2 - v1) * x);
            bone->setPosition(t);

		}
        if(bQuats){
			 r = Ogre::Quaternion::Slerp(x2, quats[rindexI[slot]], quats[rindexJ], true);
            bone->setOrientation(r);
		}





	}


    slot++;
    }
	skel->_updateTransforms();
        base->getAllAnimationStates()->_notifyDirty();
}
}
ManuallyControlledBone::ManuallyControlledBone(Ogre::String boneName,Ogre::Entity *dstEnty)//创建来自dstEnty实体的名为bonaName的骨骼手动控制的骨骼,在createScene里调用
{
	Ogre::SkeletonInstance *skel = dstEnty->getSkeleton();//得到实体骨架
	ControlledBone = skel->getBone(boneName);//根据名字得到骨骼
}