Ejemplo n.º 1
0
	//-----------------------------------------------------------------------
	void Animation::optimiseNodeTracks(bool discardIdentityTracks)
	{
		// Iterate over the node tracks and identify those with no useful keyframes
		std::list<unsigned short> tracksToDestroy;
		NodeTrackList::iterator i;
		for (i = mNodeTrackList.begin(); i != mNodeTrackList.end(); ++i)
		{
			NodeAnimationTrack* track = i->second;
			if (discardIdentityTracks && !track->hasNonZeroKeyFrames())
			{
				// mark the entire track for destruction
				tracksToDestroy.push_back(i->first);
			}
			else
			{
				track->optimise();
			}

		}

		// Now destroy the tracks we marked for death
		for(std::list<unsigned short>::iterator h = tracksToDestroy.begin();
			h != tracksToDestroy.end(); ++h)
		{
			destroyNodeTrack(*h);
		}
	}
Ejemplo n.º 2
0
    //---------------------------------------------------------------------
    NodeAnimationTrack* Animation::createNodeTrack(unsigned short handle, Node* node)
    {
        NodeAnimationTrack* ret = createNodeTrack(handle);

        ret->setAssociatedNode(node);

        return ret;
    }
Ejemplo n.º 3
0
	//---------------------------------------------------------------------
	NodeAnimationTrack* Animation::createNodeTrack(Node* node)
	{
		NodeAnimationTrack* ret = createNodeTrack();

		ret->setAssociatedNode(node);

		return ret;
	}
Ejemplo n.º 4
0
//-----------------------------------------------------------------------------
NodeAnimationTrack *Animation::CreateNodeTrack(unsigned short handle, const std::string &name)
{
	if(m_nodeTrackList.find(handle) != m_nodeTrackList.end()){
		fprintf(stderr, "Animation::CreateNodeTrack : Node track with the specified hangle %d already exists\n",handle);
			return NULL;
	}
	NodeAnimationTrack *ret = new NodeAnimationTrack(this, name);
	m_nodeTrackList.insert(std::make_pair(handle, ret));
	ret->CreateNodeKeyFrame(0);//д╛холМ╪с╣зр╩ж║
	return ret;
}
void FvXMLAnimationModelSerializerImpl::ReadAnimation( 
	FvXMLSectionPtr spSection, Ogre::SceneNode* pkNode, FvAnimationModel* pkDest )
{
	Ogre::SceneManager *pkSceneManager = Ogre::Root::getSingleton().
		_getCurrentSceneManager();
	FV_ASSERT(pkSceneManager);

	FvString kAnimationName = spSection->ReadString("name");
	bool bEnable = spSection->ReadBool("enable");
	bool bLoop = spSection->ReadBool("loop");
	FvString kIterpolationMode = spSection->ReadString("interpolationMode");
	FvString kRotationIterpolationMode = spSection->ReadString("rotationInterpolationMode");
	float fLength = spSection->ReadFloat("length");

	if(!pkSceneManager->hasAnimation(pkNode->getName() + kAnimationName))
	{
		std::vector<FvXMLSectionPtr> kKeyFrames;
		spSection->OpenSections("keyframe",kKeyFrames);

		Animation *pkAnimation = pkSceneManager->createAnimation(pkNode->getName() + kAnimationName, fLength);
		if(strcmp(kIterpolationMode.c_str(),"spline") == 0)
			pkAnimation->setInterpolationMode(Animation::IM_SPLINE);
		else
			pkAnimation->setInterpolationMode(Animation::IM_LINEAR);

		if(strcmp(kRotationIterpolationMode.c_str(),"spherical") == 0)
			pkAnimation->setRotationInterpolationMode(Animation::RIM_SPHERICAL);
		else
			pkAnimation->setRotationInterpolationMode(Animation::RIM_LINEAR);

		NodeAnimationTrack *pkAnimationTrack = pkAnimation->createNodeTrack(
			pkAnimation->getNumNodeTracks() + 1, pkNode);

		for (size_t stKeyframeIndex = 0; stKeyframeIndex < kKeyFrames.size(); stKeyframeIndex++)
		{
			float fTime = kKeyFrames[stKeyframeIndex]->ReadFloat("time");
			FvVector3 kPosition = kKeyFrames[stKeyframeIndex]->ReadVector3("translation");
			FvVector3 kScale = kKeyFrames[stKeyframeIndex]->ReadVector3("scale");
			FvQuaternion kQuaternion = kKeyFrames[stKeyframeIndex]->ReadQuaternion("rotation");
			TransformKeyFrame *pkKeyFrame = pkAnimationTrack->createNodeKeyFrame(fTime);
			pkKeyFrame->setTranslate(Vector3(kPosition.x,kPosition.y,kPosition.z));
			pkKeyFrame->setRotation(Quaternion(kQuaternion.w,kQuaternion.x,kQuaternion.y,kQuaternion.z));
			pkKeyFrame->setScale(Vector3(kScale.x,kScale.y,kScale.z));
		}

		AnimationState *pkAnimationState = pkSceneManager->createAnimationState(pkNode->getName() + kAnimationName);
		pkAnimationState->setEnabled(bEnable);
		pkAnimationState->setLoop(bLoop);
		pkDest->m_kModelAnimations.insert(std::make_pair(kAnimationName,pkAnimationState));
	}
}
Ejemplo n.º 6
0
    //-----------------------------------------------------------------------
	void Animation::_applyBaseKeyFrame()
	{
		if (mUseBaseKeyFrame)
		{
			Animation* baseAnim = this;
			if (mBaseKeyFrameAnimationName != StringUtil::BLANK && mContainer)
				baseAnim = mContainer->getAnimation(mBaseKeyFrameAnimationName);
			
			if (baseAnim)
			{
				for (NodeTrackList::iterator i = mNodeTrackList.begin(); i != mNodeTrackList.end(); ++i)
				{
					NodeAnimationTrack* track = i->second;
					
					NodeAnimationTrack* baseTrack;
					if (baseAnim == this)
						baseTrack = track;
					else
						baseTrack = baseAnim->getNodeTrack(track->getHandle());
					
					TransformKeyFrame kf(baseTrack, mBaseKeyFrameTime);
					baseTrack->getInterpolatedKeyFrame(baseAnim->_getTimeIndex(mBaseKeyFrameTime), &kf);
					track->_applyBaseKeyFrame(&kf);
				}
				
				for (VertexTrackList::iterator i = mVertexTrackList.begin(); i != mVertexTrackList.end(); ++i)
				{
					VertexAnimationTrack* track = i->second;
					
					if (track->getAnimationType() == VAT_POSE)
					{
						VertexAnimationTrack* baseTrack;
						if (baseAnim == this)
							baseTrack = track;
						else
							baseTrack = baseAnim->getVertexTrack(track->getHandle());
						
						VertexPoseKeyFrame kf(baseTrack, mBaseKeyFrameTime);
						baseTrack->getInterpolatedKeyFrame(baseAnim->_getTimeIndex(mBaseKeyFrameTime), &kf);
						track->_applyBaseKeyFrame(&kf);
						
					}
				}
				
			}
			
			// Re-base has been done, this is a one-way translation
			mUseBaseKeyFrame = false;
		}
		
	}
Ejemplo n.º 7
0
void OgreSample19App::tweakSneakAnim()
{
	SkeletonPtr skel = SkeletonManager::getSingleton().load("jaiqua.skeleton",ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
	Animation * anim = skel->getAnimation("Sneak");
	Animation::NodeTrackIterator tracks = anim->getNodeTrackIterator();
	
	while(tracks.hasMoreElements())
	{
		NodeAnimationTrack * track = tracks.getNext();
		TransformKeyFrame oldKf(0,0);
		track->getInterpolatedKeyFrame(ANIM_CHOP,&oldKf);
		while (track->getKeyFrame(track->getNumKeyFrames()-1)->getTime() >= ANIM_CHOP - 0.3f)
		{
			track->removeKeyFrame(track->getNumKeyFrames()-1);
		}

		TransformKeyFrame * newKf = track->createNodeKeyFrame(ANIM_CHOP);
		TransformKeyFrame * startKf = track->getNodeKeyFrame(0);

		Bone * bone = skel->getBone(track->getHandle());

		if (bone->getName() == "Spineroot")
		{
			mSneakStartPos = startKf->getTranslate() + bone->getInitialPosition();
			mSneakEndPos = oldKf.getTranslate() + bone->getInitialPosition();
			mSneakStartPos.y = mSneakEndPos.y;
			newKf->setTranslate(oldKf.getTranslate());
			newKf->setRotation(oldKf.getRotation());
			newKf->setScale(oldKf.getScale());
		}
		else
		{
			newKf->setTranslate(startKf->getTranslate());
			newKf->setRotation(startKf->getRotation());
			newKf->setScale(startKf->getScale());
		}
	}
}
	//-----------------------------------------------------------------------------
	void XsiSkeletonExporter::sampleAllBones(DeformerMap& deformers, 
		std::vector<NodeAnimationTrack*> deformerTracks, double frame, 
		Real time, float fps, AxisAlignedBox& AABBPadding)
	{
		CValueArray args;
		CValue dummy;
		args.Resize(2);
		// set the playcontrol 
		args[0] = L"PlayControl.Key";
		args[1] = frame;
		mXsiApp.ExecuteCommand(L"SetValue", args, dummy);
		args[0] = L"PlayControl.Current";
		mXsiApp.ExecuteCommand(L"SetValue", args, dummy);

		// Refresh
		mXsiApp.ExecuteCommand(L"Refresh", CValueArray(), dummy);
		// Sample all bones
		for (DeformerMap::iterator di = deformers.begin(); di != deformers.end(); ++di)
		{
			DeformerEntry* deformer = di->second;
			NodeAnimationTrack* track = deformerTracks[deformer->boneID];

			double initposx, initposy, initposz;
			deformer->initialXform.GetTranslationValues(initposx, initposy, initposz);
			double initrotx, initroty, initrotz;
			deformer->initialXform.GetRotation().GetXYZAngles(initrotx, initroty, initrotz);
			double initsclx, initscly, initsclz;
			deformer->initialXform.GetScalingValues(initsclx, initscly, initsclz);
			XSI::MATH::CMatrix4 invTrans = deformer->initialXform.GetMatrix4();
			invTrans.InvertInPlace();

			XSI::MATH::CTransformation transformation;
			if (deformer->pBone->getParent() == 0)
			{
				// Based on global
				transformation = 
					deformer->obj.GetKinematics().GetGlobal().GetTransform();
			}
			else
			{
				// Based on local
				transformation = 
					deformer->obj.GetKinematics().GetLocal().GetTransform();
			}

			double posx, posy, posz;
			transformation.GetTranslationValues(posx, posy, posz);
			double sclx, scly, sclz;
			transformation.GetScalingValues(sclx, scly, sclz);

			// Make relative to initial
			XSI::MATH::CMatrix4 transformationMatrix = transformation.GetMatrix4();
			transformationMatrix.MulInPlace(invTrans);
			transformation.SetMatrix4(transformationMatrix);

			// create keyframe
			TransformKeyFrame* kf = track->createNodeKeyFrame(time);
			// not sure why inverted transform doesn't work for position, but it doesn't
			// I thought XSI used same transform order as OGRE
			kf->setTranslate(Vector3(posx - initposx, posy - initposy, posz - initposz));
			kf->setRotation(XSItoOgre(transformation.GetRotationQuaternion()));
			kf->setScale(Vector3(sclx / initsclx, scly / initscly, sclz / initsclz));

			// Derive AABB of bone positions, for padding animated mesh AABB
			XSI::MATH::CVector3 bonePos = 
				deformer->obj.GetKinematics().GetGlobal().GetTransform().GetTranslation();
			AABBPadding.merge(XSItoOgre(bonePos));



		}

	}
Ejemplo n.º 9
0
    void Skeleton::_mergeSkeletonAnimations(const Skeleton* src,
        const BoneHandleMap& boneHandleMap,
        const StringVector& animations)
    {
        ushort handle;

        ushort numSrcBones = src->getNumBones();
        ushort numDstBones = this->getNumBones();

        if (boneHandleMap.size() != numSrcBones)
        {
            OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
                "Number of bones in the bone handle map must equal to "
                "number of bones in the source skeleton.",
                "Skeleton::_mergeSkeletonAnimations");
        }

        bool existsMissingBone = false;

        // Check source skeleton structures compatible with ourself (that means
        // identically bones with identical handles, and with same hierarchy, but
        // not necessary to have same number of bones and bone names).
        for (handle = 0; handle < numSrcBones; ++handle)
        {
            const Bone* srcBone = src->getBone(handle);
            ushort dstHandle = boneHandleMap[handle];

            // Does it exists in target skeleton?
            if (dstHandle < numDstBones)
            {
                Bone* destBone = this->getBone(dstHandle);

                // Check both bones have identical parent, or both are root bone.
                const Bone* srcParent = static_cast<Bone*>(srcBone->getParent());
                Bone* destParent = static_cast<Bone*>(destBone->getParent());
                if ((srcParent || destParent) &&
                    (!srcParent || !destParent ||
                     boneHandleMap[srcParent->getHandle()] != destParent->getHandle()))
                {
                    OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
                        "Source skeleton incompatible with this skeleton: "
                        "difference hierarchy between bone '" + srcBone->getName() +
                        "' and '" + destBone->getName() + "'.",
                        "Skeleton::_mergeSkeletonAnimations");
                }
            }
            else
            {
                existsMissingBone = true;
            }
        }

        // Clone bones if need
        if (existsMissingBone)
        {
            // Create missing bones
            for (handle = 0; handle < numSrcBones; ++handle)
            {
                const Bone* srcBone = src->getBone(handle);
                ushort dstHandle = boneHandleMap[handle];

                // The bone is missing in target skeleton?
                if (dstHandle >= numDstBones)
                {
                    Bone* dstBone = this->createBone(srcBone->getName(), dstHandle);
                    // Sets initial transform
                    dstBone->setPosition(srcBone->getInitialPosition());
                    dstBone->setOrientation(srcBone->getInitialOrientation());
                    dstBone->setScale(srcBone->getInitialScale());
                    dstBone->setInitialState();
                }
            }

            // Link new bones to parent
            for (handle = 0; handle < numSrcBones; ++handle)
            {
                const Bone* srcBone = src->getBone(handle);
                ushort dstHandle = boneHandleMap[handle];

                // Is new bone?
                if (dstHandle >= numDstBones)
                {
                    const Bone* srcParent = static_cast<Bone*>(srcBone->getParent());
                    if (srcParent)
                    {
                        Bone* destParent = this->getBone(boneHandleMap[srcParent->getHandle()]);
                        Bone* dstBone = this->getBone(dstHandle);
                        destParent->addChild(dstBone);
                    }
                }
            }

            // Derive root bones in case it was changed
            this->deriveRootBone();

            // Reset binding pose for new bones
            this->reset(true);
            this->setBindingPose();
        }

        //
        // We need to adapt animations from source to target skeleton, but since source
        // and target skeleton bones bind transform might difference, so we need to alter
        // keyframes in source to suit to target skeleton.
        //
        // For any given animation time, formula:
        //
        //      LocalTransform = BindTransform * KeyFrame;
        //      DerivedTransform = ParentDerivedTransform * LocalTransform
        //
        // And all derived transforms should be keep identically after adapt to
        // target skeleton, Then:
        //
        //      DestDerivedTransform == SrcDerivedTransform
        //      DestParentDerivedTransform == SrcParentDerivedTransform
        // ==>
        //      DestLocalTransform = SrcLocalTransform
        // ==>
        //      DestBindTransform * DestKeyFrame = SrcBindTransform * SrcKeyFrame
        // ==>
        //      DestKeyFrame = inverse(DestBindTransform) * SrcBindTransform * SrcKeyFrame
        //
        // We define (inverse(DestBindTransform) * SrcBindTransform) as 'delta-transform' here.
        //

        // Calculate delta-transforms for all source bones.
        vector<DeltaTransform>::type deltaTransforms(numSrcBones);
        for (handle = 0; handle < numSrcBones; ++handle)
        {
            const Bone* srcBone = src->getBone(handle);
            DeltaTransform& deltaTransform = deltaTransforms[handle];
            ushort dstHandle = boneHandleMap[handle];

            if (dstHandle < numDstBones)
            {
                // Common bone, calculate delta-transform

                Bone* dstBone = this->getBone(dstHandle);

                deltaTransform.translate = srcBone->getInitialPosition() - dstBone->getInitialPosition();
                deltaTransform.rotate = dstBone->getInitialOrientation().Inverse() * srcBone->getInitialOrientation();
                deltaTransform.scale = srcBone->getInitialScale() / dstBone->getInitialScale();

                // Check whether or not delta-transform is identity
                const Real tolerance = 1e-3f;
                Vector3 axis;
                Radian angle;
                deltaTransform.rotate.ToAngleAxis(angle, axis);
                deltaTransform.isIdentity =
                    deltaTransform.translate.positionEquals(Vector3::ZERO, tolerance) &&
                    deltaTransform.scale.positionEquals(Vector3::UNIT_SCALE, tolerance) &&
                    Math::RealEqual(angle.valueRadians(), 0.0f, tolerance);
            }
            else
            {
                // New bone, the delta-transform is identity

                deltaTransform.translate = Vector3::ZERO;
                deltaTransform.rotate = Quaternion::IDENTITY;
                deltaTransform.scale = Vector3::UNIT_SCALE;
                deltaTransform.isIdentity = true;
            }
        }

        // Now copy animations

        ushort numAnimations;
        if (animations.empty())
            numAnimations = src->getNumAnimations();
        else
            numAnimations = static_cast<ushort>(animations.size());
        for (ushort i = 0; i < numAnimations; ++i)
        {
            const Animation* srcAnimation;
            if (animations.empty())
            {
                // Get animation of source skeleton by the given index
                srcAnimation = src->getAnimation(i);
            }
            else
            {
                // Get animation of source skeleton by the given name
                const LinkedSkeletonAnimationSource* linker;
                srcAnimation = src->_getAnimationImpl(animations[i], &linker);
                if (!srcAnimation || linker)
                {
                    OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
                        "No animation entry found named " + animations[i],
                        "Skeleton::_mergeSkeletonAnimations");
                }
            }

            // Create target animation
            Animation* dstAnimation = this->createAnimation(srcAnimation->getName(), srcAnimation->getLength());

            // Copy interpolation modes
            dstAnimation->setInterpolationMode(srcAnimation->getInterpolationMode());
            dstAnimation->setRotationInterpolationMode(srcAnimation->getRotationInterpolationMode());

            // Copy track for each bone
            for (handle = 0; handle < numSrcBones; ++handle)
            {
                const DeltaTransform& deltaTransform = deltaTransforms[handle];
                ushort dstHandle = boneHandleMap[handle];

                if (srcAnimation->hasNodeTrack(handle))
                {
                    // Clone track from source animation

                    const NodeAnimationTrack* srcTrack = srcAnimation->getNodeTrack(handle);
                    NodeAnimationTrack* dstTrack = dstAnimation->createNodeTrack(dstHandle, this->getBone(dstHandle));
                    dstTrack->setUseShortestRotationPath(srcTrack->getUseShortestRotationPath());

                    ushort numKeyFrames = srcTrack->getNumKeyFrames();
                    for (ushort k = 0; k < numKeyFrames; ++k)
                    {
                        const TransformKeyFrame* srcKeyFrame = srcTrack->getNodeKeyFrame(k);
                        TransformKeyFrame* dstKeyFrame = dstTrack->createNodeKeyFrame(srcKeyFrame->getTime());

                        // Adjust keyframes to match target binding pose
                        if (deltaTransform.isIdentity)
                        {
                            dstKeyFrame->setTranslate(srcKeyFrame->getTranslate());
                            dstKeyFrame->setRotation(srcKeyFrame->getRotation());
                            dstKeyFrame->setScale(srcKeyFrame->getScale());
                        }
                        else
                        {
                            dstKeyFrame->setTranslate(deltaTransform.translate + srcKeyFrame->getTranslate());
                            dstKeyFrame->setRotation(deltaTransform.rotate * srcKeyFrame->getRotation());
                            dstKeyFrame->setScale(deltaTransform.scale * srcKeyFrame->getScale());
                        }
                    }
                }
                else if (!deltaTransform.isIdentity)
                {
                    // Create 'static' track for this bone

                    NodeAnimationTrack* dstTrack = dstAnimation->createNodeTrack(dstHandle, this->getBone(dstHandle));
                    TransformKeyFrame* dstKeyFrame;

                    dstKeyFrame = dstTrack->createNodeKeyFrame(0);
                    dstKeyFrame->setTranslate(deltaTransform.translate);
                    dstKeyFrame->setRotation(deltaTransform.rotate);
                    dstKeyFrame->setScale(deltaTransform.scale);

                    dstKeyFrame = dstTrack->createNodeKeyFrame(dstAnimation->getLength());
                    dstKeyFrame->setTranslate(deltaTransform.translate);
                    dstKeyFrame->setRotation(deltaTransform.rotate);
                    dstKeyFrame->setScale(deltaTransform.scale);
                }
            }
        }
    }
Ejemplo n.º 10
0
    //---------------------------------------------------------------------
    void Skeleton::_dumpContents(const String& filename)
    {
        std::ofstream of;

        Quaternion q;
        Radian angle;
        Vector3 axis;
        of.open(filename.c_str());

        of << "-= Debug output of skeleton " << mName << " =-" << std::endl << std::endl;
        of << "== Bones ==" << std::endl;
        of << "Number of bones: " << (unsigned int)mBoneList.size() << std::endl;
        
        BoneList::iterator bi;
        for (bi = mBoneList.begin(); bi != mBoneList.end(); ++bi)
        {
            Bone* bone = *bi;

            of << "-- Bone " << bone->getHandle() << " --" << std::endl;
            of << "Position: " << bone->getPosition();
            q = bone->getOrientation();
            of << "Rotation: " << q;
            q.ToAngleAxis(angle, axis);
            of << " = " << angle.valueRadians() << " radians around axis " << axis << std::endl << std::endl;
        }

        of << "== Animations ==" << std::endl;
        of << "Number of animations: " << (unsigned int)mAnimationsList.size() << std::endl;

        AnimationList::iterator ai;
        for (ai = mAnimationsList.begin(); ai != mAnimationsList.end(); ++ai)
        {
            Animation* anim = ai->second;

            of << "-- Animation '" << anim->getName() << "' (length " << anim->getLength() << ") --" << std::endl;
            of << "Number of tracks: " << anim->getNumNodeTracks() << std::endl;

            for (unsigned short ti = 0; ti < anim->getNumNodeTracks(); ++ti)
            {
                NodeAnimationTrack* track = anim->getNodeTrack(ti);
                of << "  -- AnimationTrack " << ti << " --" << std::endl;
                of << "  Affects bone: " << ((Bone*)track->getAssociatedNode())->getHandle() << std::endl;
                of << "  Number of keyframes: " << track->getNumKeyFrames() << std::endl;

                for (unsigned short ki = 0; ki < track->getNumKeyFrames(); ++ki)
                {
                    TransformKeyFrame* key = track->getNodeKeyFrame(ki);
                    of << "    -- KeyFrame " << ki << " --" << std::endl;
                    of << "    Time index: " << key->getTime(); 
                    of << "    Translation: " << key->getTranslate() << std::endl;
                    q = key->getRotation();
                    of << "    Rotation: " << q;
                    q.ToAngleAxis(angle, axis);
                    of << " = " << angle.valueRadians() << " radians around axis " << axis << std::endl;
                }

            }



        }

    }
Ejemplo n.º 11
0
	void createSampleLights()
	{
		// Create some lights		
		std::vector<MLight*> lights;
		SceneNode *parentNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("LightsParent");
		// Create light nodes
		std::vector<Node*> nodes;

		MLight *a = mSystem->createMLight();
		SceneNode *an = parentNode->createChildSceneNode();
		an->attachObject(a);
		a->setAttenuation(1.0f, 0.001f, 0.002f);
		//a->setAttenuation(1.0f, 0.000f, 0.000f);
		an->setPosition(0,0,25);
		a->setDiffuseColour(1,0,0);
		//a->setSpecularColour(0.5,0,0);
		lights.push_back(a);
		nodes.push_back(an);

		MLight *b = mSystem->createMLight();
		SceneNode *bn = parentNode->createChildSceneNode();
		bn->attachObject(b);
		b->setAttenuation(1.0f, 0.001f, 0.003f);
		bn->setPosition(25,0,0);
		b->setDiffuseColour(1,1,0);
		//b->setSpecularColour(0.5,0.5,0);
		lights.push_back(b);
		nodes.push_back(bn);

		MLight *c = mSystem->createMLight();
		SceneNode *cn = parentNode->createChildSceneNode();
		cn->attachObject(c);
		c->setAttenuation(1.0f, 0.001f, 0.004f);
		cn->setPosition(0,0,-25);
		c->setDiffuseColour(0,1,1);
		c->setSpecularColour(0.25,1.0,1.0); // Cyan light has specular component
		lights.push_back(c);
		nodes.push_back(cn);

		MLight *d = mSystem->createMLight();
		SceneNode *dn = parentNode->createChildSceneNode();
		dn->attachObject(d);
		d->setAttenuation(1.0f, 0.002f, 0.002f);
		dn->setPosition(-25,0,0);
		d->setDiffuseColour(1,0,1);
		d->setSpecularColour(0.0,0,0.0);
		lights.push_back(d);
		nodes.push_back(dn);

		MLight *e = mSystem->createMLight();
		SceneNode *en = parentNode->createChildSceneNode();
		en->attachObject(e);
		e->setAttenuation(1.0f, 0.002f, 0.0025f);
		en->setPosition(25,0,25);
		e->setDiffuseColour(0,0,1);
		e->setSpecularColour(0,0,0);
		lights.push_back(e);
		nodes.push_back(en);
		
		MLight *f = mSystem->createMLight();
		SceneNode *fn = parentNode->createChildSceneNode();
		fn->attachObject(f);
		f->setAttenuation(1.0f, 0.0015f, 0.0021f);
		fn->setPosition(-25,0,-25);
		f->setDiffuseColour(0,1,0);
		f->setSpecularColour(0,0.0,0.0);
		lights.push_back(f);
		nodes.push_back(fn);

		// Create marker meshes to show user where the lights are
		Entity *ent;
		GeomUtils::createSphere("PointLightMesh", 1.0f, 5, 5, true, true);
		for(std::vector<MLight*>::iterator i=lights.begin(); i!=lights.end(); ++i)
		{
			MLight* light = *i;
			ent = mSceneMgr->createEntity(light->getName()+"v", "PointLightMesh");
			String matname = light->getName()+"m";
			// Create coloured material
			MaterialPtr mat = MaterialManager::getSingleton().create(matname,
                ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
            Pass* pass = mat->getTechnique(0)->getPass(0);
            pass->setDiffuse(0.0f,0.0f,0.0f,1.0f);
			pass->setAmbient(0.0f,0.0f,0.0f);
			pass->setSelfIllumination(light->getDiffuseColour());

			ent->setMaterialName(matname);
			ent->setRenderQueueGroup(light->getRenderQueueGroup());
			static_cast<SceneNode*>(light->getParentNode())->attachObject(ent);
		}		

		// Store nodes for hiding/showing
		SharedData::getSingleton().mLightNodes = nodes;

		// Do some animation for node a-f
		// Generate helix structure
		float seconds_per_station = 1.0f;
		float r=35;
		//Vector3 base(0,-30,0);
		Vector3 base(-100, -30, 85);

		float h=120;
		const size_t s_to_top = 16;
		const size_t stations = s_to_top*2-1;
		float ascend = h/((float)s_to_top);
		float stations_per_revolution = 3.5f;
		size_t skip = 2; // stations between lights
		Vector3 station_pos[stations];
		for(int x=0; x<s_to_top; ++x)
		{
			float theta = ((float)x/stations_per_revolution)*2.0f*Math::PI;
			station_pos[x] = base+Vector3(Math::Sin(theta)*r, ascend*x, Math::Cos(theta)*r);
		}
		for(int x=s_to_top; x<stations; ++x)
		{
			float theta = ((float)x/stations_per_revolution)*2.0f*Math::PI;
			station_pos[x] = base+Vector3(Math::Sin(theta)*r, h-ascend*(x-s_to_top), Math::Cos(theta)*r);
		}
		// Create a track for the light swarm
		Animation* anim = mSceneMgr->createAnimation("LightSwarmTrack", stations*seconds_per_station);
		// Spline it for nice curves
		anim->setInterpolationMode(Animation::IM_SPLINE);
		for(unsigned int x=0; x<nodes.size(); ++x)
		{
			// Create a track to animate the camera's node
			NodeAnimationTrack* track = anim->createNodeTrack(x, nodes[x]);
			for(int y=0; y<=stations; ++y)
			{
				// Setup keyframes
				TransformKeyFrame* key = track->createNodeKeyFrame(y*seconds_per_station); // A start position
				key->setTranslate(station_pos[(x*skip+y)%stations]);
				// Make sure size of light doesn't change
				key->setScale(nodes[x]->getScale());
			}
		}
		// Create a new animation state to track this
		SharedData::getSingleton().mMLAnimState = mSceneMgr->createAnimationState("LightSwarmTrack");
		SharedData::getSingleton().mMLAnimState->setEnabled(true);
	}
Ejemplo n.º 12
0
    // Just override the mandatory create scene method
    void createScene(void)
    {
		RenderSystem *rs = Root::getSingleton().getRenderSystem();
		const RenderSystemCapabilities* caps = rs->getCapabilities();
        if (!caps->hasCapability(RSC_VERTEX_PROGRAM) || !(caps->hasCapability(RSC_FRAGMENT_PROGRAM)))
        {
            OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "Your card does not support vertex and fragment programs, so cannot "
                "run this demo. Sorry!", 
                "DeferredShading::createScene");
        }
		if (caps->getNumMultiRenderTargets()<2)
        {
            OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "Your card does not support at least two simultaneous render targets, so cannot "
                "run this demo. Sorry!", 
                "DeferredShading::createScene");
        }

		// Prepare athene mesh for normalmapping
        MeshPtr pAthene = MeshManager::getSingleton().load("athene.mesh", 
            ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
        unsigned short src, dest;
        if (!pAthene->suggestTangentVectorBuildParams(VES_TANGENT, src, dest))
            pAthene->buildTangentVectors(VES_TANGENT, src, dest);
		// Prepare knot mesh for normal mapping
		pAthene = MeshManager::getSingleton().load("knot.mesh", 
            ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
        if (!pAthene->suggestTangentVectorBuildParams(VES_TANGENT, src, dest))
            pAthene->buildTangentVectors(VES_TANGENT, src, dest);

        // Set ambient light
        mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.15));
        // Skybox
        mSceneMgr->setSkyBox(true, "DeferredDemo/SkyBox");

		// Create "root" node
		SceneNode* rootNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();

		Entity* athena = mSceneMgr->createEntity("Athena", "athene.mesh");
		athena->setMaterialName("DeferredDemo/DeferredAthena");
		SceneNode *aNode = rootNode->createChildSceneNode();
		aNode->attachObject( athena );
		aNode->setPosition(-100, 40, 100);

		// Create a prefab plane
		mPlane = new MovablePlane("ReflectPlane");
		mPlane->d = 0;
		mPlane->normal = Vector3::UNIT_Y;
		MeshManager::getSingleton().createCurvedPlane("ReflectionPlane", 
			ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, 
			*mPlane,
			2000, 2000, -1000,
			20, 20, 
			true, 1, 10, 10, Vector3::UNIT_Z);
		mPlaneEnt = mSceneMgr->createEntity( "Plane", "ReflectionPlane" );
		mPlaneNode = rootNode->createChildSceneNode();
		mPlaneNode->attachObject(mPlaneEnt);
		mPlaneNode->translate(-5, -30, 0);
		//mPlaneNode->roll(Degree(5));
		mPlaneEnt->setMaterialName("DeferredDemo/Ground");

		// Create an entity from a model (will be loaded automatically)
		Entity* knotEnt = mSceneMgr->createEntity("Knot", "knot.mesh");
		knotEnt->setMaterialName("DeferredDemo/RockWall");
		knotEnt->setMeshLodBias(0.25f);

		// Create an entity from a model (will be loaded automatically)
		Entity* ogreHead = mSceneMgr->createEntity("Head", "ogrehead.mesh");
		ogreHead->getSubEntity(0)->setMaterialName("DeferredDemo/Ogre/Eyes");// eyes
		ogreHead->getSubEntity(1)->setMaterialName("DeferredDemo/Ogre/Skin"); 
		ogreHead->getSubEntity(2)->setMaterialName("DeferredDemo/Ogre/EarRing"); // earrings
		ogreHead->getSubEntity(3)->setMaterialName("DeferredDemo/Ogre/Tusks"); // tusks
		rootNode->createChildSceneNode( "Head" )->attachObject( ogreHead );

		// Add a whole bunch of extra entities to fill the scene a bit
		Entity *cloneEnt;
		int N=4;
		for (int n = 0; n < N; ++n)
		{
			float theta = 2.0f*Math::PI*(float)n/(float)N;
			// Create a new node under the root
			SceneNode* node = mSceneMgr->createSceneNode();
			// Random translate
			Vector3 nodePos;
			nodePos.x = Math::SymmetricRandom() * 40.0 + Math::Sin(theta) * 500.0;
			nodePos.y = Math::SymmetricRandom() * 20.0 - 40.0;
			nodePos.z = Math::SymmetricRandom() * 40.0 + Math::Cos(theta) * 500.0;
			node->setPosition(nodePos);
			Quaternion orientation(Math::SymmetricRandom(),Math::SymmetricRandom(),Math::SymmetricRandom(),Math::SymmetricRandom());
			orientation.normalise();
			node->setOrientation(orientation);
			rootNode->addChild(node);
			// Clone knot
			char cloneName[12];
			sprintf(cloneName, "Knot%d", n);
			cloneEnt = knotEnt->clone(cloneName);
			// Attach to new node
			node->attachObject(cloneEnt);

		}

        mCamera->setPosition(-50, 100, 500);
        mCamera->lookAt(0,0,0);

		// show overlay
		Overlay* overlay = OverlayManager::getSingleton().getByName("Example/ShadowsOverlay");    
		overlay->show();

		mSystem = new DeferredShadingSystem(mWindow->getViewport(0), mSceneMgr, mCamera);

		// Create main, moving light
		MLight* l1 = mSystem->createMLight();//"MainLight");
        l1->setDiffuseColour(0.75f, 0.7f, 0.8f);
		l1->setSpecularColour(0.85f, 0.9f, 1.0f);
		
		SceneNode *lightNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
		lightNode->attachObject(l1);

		// Create a track for the light
        Animation* anim = mSceneMgr->createAnimation("LightTrack", 16);
        // Spline it for nice curves
        anim->setInterpolationMode(Animation::IM_SPLINE);
        // Create a track to animate the camera's node
        NodeAnimationTrack* track = anim->createNodeTrack(0, lightNode);
        // Setup keyframes
        TransformKeyFrame* key = track->createNodeKeyFrame(0); // A start position
        key->setTranslate(Vector3(300,300,-300));
        key = track->createNodeKeyFrame(4);//B
        key->setTranslate(Vector3(300,300,300));
        key = track->createNodeKeyFrame(8);//C
        key->setTranslate(Vector3(-300,300,300));
        key = track->createNodeKeyFrame(12);//D
        key->setTranslate(Vector3(-300,300,-300));
		key = track->createNodeKeyFrame(16);//D
        key->setTranslate(Vector3(300,300,-300));
        // Create a new animation state to track this
        SharedData::getSingleton().mAnimState = mSceneMgr->createAnimationState("LightTrack");
        SharedData::getSingleton().mAnimState->setEnabled(true);

		// Create some happy little lights
		createSampleLights();

		// safely setup application's (not postfilter!) shared data
		SharedData::getSingleton().iCamera = mCamera;
		SharedData::getSingleton().iRoot = mRoot;
		SharedData::getSingleton().iWindow = mWindow;
		SharedData::getSingleton().iActivate = true;
		SharedData::getSingleton().iGlobalActivate = true;
		SharedData::getSingleton().iSystem = mSystem;
		SharedData::getSingleton().iMainLight = l1;
	}
Ejemplo n.º 13
0
void ModelConverter::ExportSkeleton( const Ogre::Skeleton* pSkeleton, const Ogre::String& filename )
{
	LogManager::getSingleton().logMessage("Populating DOM...");

	// Write main skeleton data
	LogManager::getSingleton().logMessage("Exporting bones..");

	DiMotionPtr mt = Demi::DiAssetManager::GetInstancePtr(
		)->CreateOrReplaceAsset<DiMotion>(pSkeleton->getName().c_str());
	DiSkeleton* skeleton = mt->CreateSkeleton();
	
	// save bones
	WriteSkeleton(pSkeleton,skeleton);

	LogManager::getSingleton().logMessage("Bones exported.");

	unsigned short numAnims = pSkeleton->getNumAnimations();
	String msg = "Exporting animations, count=" + StringConverter::toString(numAnims);
	LogManager::getSingleton().logMessage(msg);

	// save animations
	for (unsigned short i = 0; i < numAnims; ++i)
	{
		Animation* pAnim = pSkeleton->getAnimation(i);
		msg = "Exporting animation: " + pAnim->getName();
		LogManager::getSingleton().logMessage(msg);

		Demi::DiAnimation* anim = mt->CreateAnimation(
			pAnim->getName().c_str(), pAnim->getLength());

		// save tracks
		Animation::NodeTrackIterator trackIt = pAnim->getNodeTrackIterator();
		size_t count = 0;
		while (trackIt.hasMoreElements())
		{
			NodeAnimationTrack* track = trackIt.getNext();

			Bone* bone = (Bone*)track->getAssociatedNode();
			Demi::DiNodeClip* clip = anim->CreateNodeClip(count++,skeleton->GetBone(bone->getHandle()));
			
			// save key frames
			for (unsigned short i = 0; i < track->getNumKeyFrames(); ++i)
			{
				TransformKeyFrame* kf = track->getNodeKeyFrame(i);

				Demi::DiTransformKeyFrame* pKeyframe = clip->CreateNodeKeyFrame(kf->getTime());

				pKeyframe->SetTranslate(Demi::DiVec3(kf->getTranslate().x,
										kf->getTranslate().y,kf->getTranslate().z));
				pKeyframe->SetRotation(Demi::DiQuat(kf->getRotation().w,
										kf->getRotation().x,kf->getRotation().y,kf->getRotation().z));
				pKeyframe->SetScale(Demi::DiVec3(kf->getScale().x,
										kf->getScale().y,kf->getScale().z));
			}
		}

		LogManager::getSingleton().logMessage("Animation exported.");
	}

	if (mt)
	{
		// save to file
		DiMotionSerializer ms;
		ms.ExportMotion(mt,filename);
	}
}
Ejemplo n.º 14
0
    SkeletonPtr MergeSkeleton::bake()
    {    
        MeshCombiner::getSingleton().log( 
             "Baking: New Skeleton started" );

        SkeletonPtr sp = SkeletonManager::getSingleton().create( "mergeSkeleton", 
             ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true );
        
        for( std::vector< Ogre::SkeletonPtr >::iterator it = m_Skeletons.begin();
             it != m_Skeletons.end(); ++it )
        {   
            if(  it == m_Skeletons.begin() )
            {
                MeshCombiner::getSingleton().log( 
                    "Baking: using " + (*it)->getName() + " as the base skeleton"   );

                MeshCombiner::getSingleton().log( 
                    "Baking: adding bones"   );
                Skeleton::BoneIterator bit = (*it)->getBoneIterator();
                while( bit.hasMoreElements() )
                {
                    Bone* bone = bit.getNext();
                    Bone* newbone = sp->createBone( bone->getName(), bone->getHandle() );
                    newbone->setScale( bone->getScale() );
                    newbone->setOrientation( bone->getOrientation() );
                    newbone->setPosition( bone->getPosition() );
                }
                MeshCombiner::getSingleton().log( 
                    "Baking: building bone hierarchy"   );
                // bone hierarchy
                bit = (*it)->getBoneIterator();
                while( bit.hasMoreElements() )
                {
                    Bone* bone = bit.getNext();
                    Node* pnode = bone->getParent();
                    if( pnode != NULL )
                    {
                        Bone* pbone = static_cast<Bone*>( pnode );
                        sp->getBone( pbone->getHandle() )->addChild( sp->getBone( bone->getHandle() ) );
                    }
                }
            }   

            MeshCombiner::getSingleton().log( 
                "Baking: adding animations for " + (*it)->getName() );

            // insert all animations
            for (unsigned short a=0; a < (*it)->getNumAnimations(); ++a )
            {
                Animation* anim = (*it)->getAnimation( a );
                Animation* newanim = sp->createAnimation( anim->getName(), anim->getLength() );

                if( anim->getNumNodeTracks() > 0 )
                    MeshCombiner::getSingleton().log( 
                        "Baking: adding node tracks" );
                for( unsigned short na=0; na < anim->getNumNodeTracks(); ++na )
                {
                    if( anim->hasNodeTrack( na ) )
                    {
                        NodeAnimationTrack* nat = anim->getNodeTrack( na );
                        NodeAnimationTrack* newnat = newanim->createNodeTrack( na );
                        // all key frames
                        for( unsigned short nf=0; nf < nat->getNumKeyFrames(); ++nf )
                        {
                            TransformKeyFrame* tkf = nat->getNodeKeyFrame( nf );
                            TransformKeyFrame* newtkf = newnat->createNodeKeyFrame( tkf->getTime() );
                            newtkf->setRotation( tkf->getRotation() );
                            newtkf->setTranslate( tkf->getTranslate() );
                            newtkf->setScale( tkf->getScale() );
                        }

                        newnat->setAssociatedNode( sp->getBone( nat->getHandle() ) );
                    }
                }

                if( anim->getNumNumericTracks() > 0 )
                    MeshCombiner::getSingleton().log( 
                        "Baking: adding numeric tracks" );
                for( unsigned short na=0; na < anim->getNumNumericTracks(); ++na )
                {
                    if( anim->hasNumericTrack( na ) )
                    {
                        NumericAnimationTrack* nat = anim->getNumericTrack( na );
                        NumericAnimationTrack* newnat = newanim->createNumericTrack( na );

                        // all key frames
                        for( unsigned short nf=0; nf < nat->getNumKeyFrames(); ++nf )
                        {
                            NumericKeyFrame* nkf = nat->getNumericKeyFrame( nf );
                            NumericKeyFrame* newnkf = newnat->createNumericKeyFrame( nkf->getTime() );
                            newnkf->setValue( nkf->getValue() );
                        }
                    }
                }

                if( anim->getNumVertexTracks() > 0 )
                    MeshCombiner::getSingleton().log( 
                        "Baking: adding vertex tracks" );
                for( unsigned short va=0; va < anim->getNumVertexTracks(); ++va )
                {
                    if( anim->hasVertexTrack( va ) )
                    {
                        VertexAnimationTrack* vat = anim->getVertexTrack( va );
                        VertexAnimationTrack* newvat = newanim->createVertexTrack( va, vat->getAnimationType() );

                        // all key frames
                        for( unsigned short nf=0; nf < vat->getNumKeyFrames(); ++nf )
                        {
                            // all morphs
                            VertexMorphKeyFrame* vmkf = vat->getVertexMorphKeyFrame( nf );
                            if( vmkf != NULL )
                            {
                                VertexMorphKeyFrame* newvmkf = newvat->createVertexMorphKeyFrame( vmkf->getTime() );
                                // @todo vertex buffer copying correct??
                                HardwareVertexBufferSharedPtr buf = vmkf->getVertexBuffer();
                                HardwareVertexBufferSharedPtr newbuf = HardwareBufferManager::getSingleton().createVertexBuffer(
                                    buf->getVertexSize(), buf->getNumVertices(), buf->getUsage(), buf->hasShadowBuffer() );
                                newbuf->copyData( *buf.getPointer(), 0, 0, buf->getSizeInBytes() );
                            }

                            // all poses
                            VertexPoseKeyFrame* vpkf = vat->getVertexPoseKeyFrame( nf );
                            if( vpkf != NULL )
                            {
                                VertexPoseKeyFrame* newvpkf = newvat->createVertexPoseKeyFrame( vpkf->getTime() );
                                
                                VertexPoseKeyFrame::PoseRefIterator pit = vpkf->getPoseReferenceIterator();
                                while( pit.hasMoreElements() )
                                {
                                    VertexPoseKeyFrame::PoseRef pr = pit.getNext();
                                    newvpkf->addPoseReference( pr.poseIndex, pr.influence );
                                }
                            }

                        }
                    }
                }
            }
        }           

        return sp;
	}
Ejemplo n.º 15
0
//-----------------------------------------------------------------------------
NodeAnimationTrack *Animation::CreateNodeTrack(unsigned short handle, Node *node)
{
	NodeAnimationTrack *ret = CreateNodeTrack(handle, node->GetName());
	ret->SetAssociatedNode(node);
	return ret;
}
Ejemplo n.º 16
0
void OgreSample18App::createScene()
{
	mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE);
	mCurrentShadowTechnique = SHADOWTYPE_STENCIL_ADDITIVE;

	// Set ambient light off
	mSceneMgr->setAmbientLight(ColourValue(0.0, 0.0, 0.0));

	// Fixed light, dim
	mSunLight = mSceneMgr->createLight("SunLight");
	mSunLight->setType(Light::LT_SPOTLIGHT);
	mSunLight->setPosition(1500,1750,1300);
	mSunLight->setSpotlightRange(Degree(30), Degree(50));
	Ogre::Vector3 dir;
	dir = -mSunLight->getPosition();
	dir.normalise();
	mSunLight->setDirection(dir);
	mSunLight->setDiffuseColour(0.35, 0.35, 0.38);
	mSunLight->setSpecularColour(0.9, 0.9, 1);

	// Point light, movable, reddish
	mLight = mSceneMgr->createLight("Light2");
	mLight->setDiffuseColour(mMinLightColour);
	mLight->setSpecularColour(1, 1, 1);
	mLight->setAttenuation(8000,1,0.0005,0);

	// Create light node
	mLightNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(
		"MovingLightNode");
	mLightNode->attachObject(mLight);
	// create billboard set
	BillboardSet* bbs = mSceneMgr->createBillboardSet("lightbbs", 1);
	bbs->setMaterialName("Examples/Flare");
	Billboard* bb = bbs->createBillboard(0,0,0,mMinLightColour);
	// attach
	mLightNode->attachObject(bbs);

	ControllerFunctionRealPtr func = ControllerFunctionRealPtr(new WaveformControllerFunction(Ogre::WFT_SINE,0.75f,0.5f));
	ControllerManager& contMgr = ControllerManager::getSingleton();
	ControllerValueRealPtr val = ControllerValueRealPtr(new LightWibbler(mLight,bb,mMinLightColour,mMaxLightColour,mMinFlareSize,mMaxFlareSize));
	mController = contMgr.createController(contMgr.getFrameTimeSource(),val,func);
	mLightNode->setPosition(Vector3(300,1750,-700));
	Animation* anim = mSceneMgr->createAnimation("LightTrack", 20);
	// Spline it for nice curves
	anim->setInterpolationMode(Animation::IM_SPLINE);
	// Create a track to animate the camera's node
	NodeAnimationTrack* track = anim->createNodeTrack(0, mLightNode);
	// Setup keyframes
	TransformKeyFrame* key = track->createNodeKeyFrame(0); // A startposition
	key->setTranslate(Vector3(300,750,-700));
	key = track->createNodeKeyFrame(2);//B
	key->setTranslate(Vector3(150,800,-250));
	key = track->createNodeKeyFrame(4);//C
	key->setTranslate(Vector3(-150,850,-100));
	key = track->createNodeKeyFrame(6);//D
	key->setTranslate(Vector3(-400,700,-200));
	key = track->createNodeKeyFrame(8);//E
	key->setTranslate(Vector3(-200,700,-400));
	key = track->createNodeKeyFrame(10);//F
	key->setTranslate(Vector3(-100,850,-200));
	key = track->createNodeKeyFrame(12);//G
	key->setTranslate(Vector3(-100,575,180));
	key = track->createNodeKeyFrame(14);//H
	key->setTranslate(Vector3(0,750,300));
	key = track->createNodeKeyFrame(16);//I
	key->setTranslate(Vector3(100,850,100));
	key = track->createNodeKeyFrame(18);//J
	key->setTranslate(Vector3(250,800,0));
	key = track->createNodeKeyFrame(20);//K == A
	key->setTranslate(Vector3(300,750,-700));
	// Create a new animation state to track this
	mAnimState = mSceneMgr->createAnimationState("LightTrack");
	mAnimState->setEnabled(true);

	mLightNode->setAutoTracking(true,mSceneMgr->getRootSceneNode());

	MeshPtr pAthene = MeshManager::getSingleton().load("athene.mesh", 
		ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
	unsigned short src, dest;
	if (!pAthene->suggestTangentVectorBuildParams(VES_TANGENT, src, dest))
	{
		pAthene->buildTangentVectors(VES_TANGENT, src, dest);
	}

	SceneNode* node;
	node = mSceneMgr->getRootSceneNode()->createChildSceneNode();
	mAthene = mSceneMgr->createEntity( "athene", "athene.mesh" );
	mAthene->setMaterialName(BASIC_ATHENE_MATERIAL);
	node->attachObject( mAthene );
	node->yaw(Degree(90));

	Entity* pEnt;
	// Columns
	for (int x = -2; x <= 2; ++x)
	{
		for (int z = -2; z <= 2; ++z)
		{
			if (x != 0 || z != 0)
			{
				StringUtil::StrStreamType str;
				str << "col" << x << "_" << z;
				node = mSceneMgr->getRootSceneNode()->createChildSceneNode();
				pEnt = mSceneMgr->createEntity( str.str(), "column.mesh" );
				pEnt->setMaterialName(BASIC_ROCKWALL_MATERIAL);
				pColumns.push_back(pEnt);
				node->attachObject( pEnt );
				node->translate(x*300,0, z*300);
			}
		}
	}

	// Skybox
	mSceneMgr->setSkyBox(true, "Examples/StormySkyBox");

	// Floor plane (use POSM plane def)
	mPlane = new MovablePlane("*mPlane");
	mPlane->normal = Vector3::UNIT_Y;
	mPlane->d = 107;
	MeshManager::getSingleton().createPlane("Myplane",
		ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, *mPlane,
		1500,1500,50,50,true,1,5,5,Vector3::UNIT_Z);
	pPlaneEnt = mSceneMgr->createEntity( "plane", "Myplane" );
	pPlaneEnt->setMaterialName(BASIC_ROCKWALL_MATERIAL);
	pPlaneEnt->setCastShadows(false);
	mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(pPlaneEnt);

	if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_HWRENDER_TO_TEXTURE))
	{
		mSceneMgr->setShadowTextureSettings(1024,2);
	}
	else
	{
		mSceneMgr->setShadowTextureSettings(512,2);
	}

	mSceneMgr->setShadowColour(ColourValue(0.5f,0.5f,0.5f));
	//handles;

	resetMaterials();
	materialChanged(0);
	configureLights(ShadowTechnique::SHADOWTYPE_STENCIL_MODULATIVE);
}
Ejemplo n.º 17
0
void Sample_VolumeTex::setupContent()
{
    // Create dynamic texture
    ptex = TextureManager::getSingleton().createManual(
                "DynaTex","General", TEX_TYPE_3D, 64, 64, 64, 0, PF_A8R8G8B8);

    // Set ambient light
    mSceneMgr->setAmbientLight(ColourValue(0.6, 0.6, 0.6));
    mSceneMgr->setSkyBox(true, "Examples/MorningSkyBox", 50 );

    //mRoot->getRenderSystem()->clearFrameBuffer(FBT_COLOUR, ColourValue(255,255,255,0));

    // Create a light
    Light* l = mSceneMgr->createLight("MainLight");
    l->setDiffuseColour(0.75, 0.75, 0.80);
    l->setSpecularColour(0.9, 0.9, 1);
    l->setPosition(-100,80,50);
    mSceneMgr->getRootSceneNode()->attachObject(l);

    // Create volume renderable
    snode = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0,0,0));

    vrend = new VolumeRenderable(32, 750.0f, "DynaTex");
    snode->attachObject( vrend );

    trend = new ThingRenderable(90.0f, 32, 7.5f);
    trend->setMaterial("Examples/VTDarkStuff");
    snode->attachObject(trend);

    // Ogre head node
    fnode = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(0,0,0));
    // Load ogre head
    Entity* head = mSceneMgr->createEntity("head", "ogrehead.mesh");
    fnode->attachObject(head);

    // Animation for ogre head
    // Create a track for the light
    Animation* anim = mSceneMgr->createAnimation("OgreTrack", 10);
    // Spline it for nice curves
    anim->setInterpolationMode(Animation::IM_SPLINE);
    // Create a track to animate the camera's node
    NodeAnimationTrack* track = anim->createNodeTrack(0, fnode);
    // Setup keyframes
    TransformKeyFrame* key = track->createNodeKeyFrame(0); // A startposition
    key->setTranslate(Vector3(0.0f, -15.0f, 0.0f));
    key = track->createNodeKeyFrame(5);//B
    key->setTranslate(Vector3(0.0f, 15.0f, 0.0f));
    key = track->createNodeKeyFrame(10);//C
    key->setTranslate(Vector3(0.0f, -15.0f, 0.0f));
    // Create a new animation state to track this
    mOgreAnimState = mSceneMgr->createAnimationState("OgreTrack");
    mOgreAnimState->setEnabled(true);

    //mFountainNode->attachObject(pSys2);

    //Setup defaults
    global_real = 0.4f;
    global_imag = 0.6f;
    global_theta = 0.0f;

    // show GUI
    createControls();

    setDragLook(true);

    generate();
}
Ejemplo n.º 18
0
// Just override the mandatory create scene method
    void createScene(void)
    {
		sceneMgr = mSceneMgr ;
        // Set ambient light
        mSceneMgr->setAmbientLight(ColourValue(0.75, 0.75, 0.75));

        // Create a light
        Light* l = mSceneMgr->createLight("MainLight");
        // Accept default settings: point light, white diffuse, just set position
        // NB I could attach the light to a SceneNode if I wanted it to move automatically with
        //  other objects, but I don't
        l->setPosition(200,300,100);

		// Create water mesh and entity
		waterMesh = new WaterMesh(MESH_NAME, PLANE_SIZE, COMPLEXITY);
		waterEntity = mSceneMgr->createEntity(ENTITY_NAME,
			MESH_NAME);
		//~ waterEntity->setMaterialName(MATERIAL_NAME);
		SceneNode *waterNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
		waterNode->attachObject(waterEntity);

        // Add a head, give it it's own node
        headNode = waterNode->createChildSceneNode();
        Entity *ent = mSceneMgr->createEntity("head", "ogrehead.mesh");
        headNode->attachObject(ent);

		// Make sure the camera track this node
        //~ mCamera->setAutoTracking(true, headNode);

		// Create the camera node, set its position & attach camera
        SceneNode* camNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
		camNode->translate(0, 500, PLANE_SIZE);
		camNode->yaw(Degree(-45));
        camNode->attachObject(mCamera);

		// Create light node
        SceneNode* lightNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
		lightNode->attachObject(l);

        // set up spline animation of light node
        Animation* anim = mSceneMgr->createAnimation("WaterLight", 20);
		NodeAnimationTrack *track ;
        TransformKeyFrame *key ;
		// create a random spline for light
		track = anim->createNodeTrack(0, lightNode);
		key = track->createNodeKeyFrame(0);
		for(int ff=1;ff<=19;ff++) {
			key = track->createNodeKeyFrame(ff);
			Vector3 lpos (
				rand()%(int)PLANE_SIZE , //- PLANE_SIZE/2,
				rand()%300+100,
				rand()%(int)PLANE_SIZE //- PLANE_SIZE/2
				);
			key->setTranslate(lpos);
		}
		key = track->createNodeKeyFrame(20);

        // Create a new animation state to track this
        mAnimState = mSceneMgr->createAnimationState("WaterLight");
        mAnimState->setEnabled(true);

        // Put in a bit of fog for the hell of it
        //mSceneMgr->setFog(FOG_EXP, ColourValue::White, 0.0002);

		// show overlay
		waterOverlay = OverlayManager::getSingleton().getByName("Example/WaterOverlay");
		waterOverlay->show();

        // Let there be rain
        particleSystem = mSceneMgr->createParticleSystem("rain",
            "Examples/Water/Rain");
		particleEmitter = particleSystem->getEmitter(0);
        SceneNode* rNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
        rNode->translate(PLANE_SIZE/2.0f, 3000, PLANE_SIZE/2.0f);
        rNode->attachObject(particleSystem);
        // Fast-forward the rain so it looks more natural
        particleSystem->fastForward(20);
		// It can't be set in .particle file, and we need it ;)
		static_cast<BillboardParticleRenderer*>(particleSystem->getRenderer())->setBillboardOrigin(BBO_BOTTOM_CENTER);

		prepareCircleMaterial();
	}
Ejemplo n.º 19
0
void OgreSample14App::createLights()
{
	mSceneMgr->setAmbientLight(ColourValue(0.1f, 0.1f, 0.1f));

	NameValuePairList params;
	params["numberOfChains"] = "2";
	params["maxElements"] = "80";
	RibbonTrail * trail = (RibbonTrail*)mSceneMgr->createMovableObject("RibbonTrail",&params);
	mSceneMgr->getRootSceneNode()->attachObject(trail);
	trail->setMaterialName("Examples/LightRibbonTrail");
	trail->setTrailLength(400);

	SceneNode* node;
	Animation* anim;
	NodeAnimationTrack* track;
	Light* light;
	BillboardSet* bbs;

	// create a light node
	node = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(50, 30, 0));

	// create a 14 second animation with spline interpolation
	anim = mSceneMgr->createAnimation("Path1", 14);
	anim->setInterpolationMode(Animation::IM_SPLINE);

	track = anim->createNodeTrack(1, node);  // create a node track for our animation

	// enter keyframes for our track to define a path for the light to follow
	track->createNodeKeyFrame(0)->setTranslate(Vector3(50, 30, 0));
	track->createNodeKeyFrame(2)->setTranslate(Vector3(100, -30, 0));
	track->createNodeKeyFrame(4)->setTranslate(Vector3(120, -80, 150));
	track->createNodeKeyFrame(6)->setTranslate(Vector3(30, -80, 50));
	track->createNodeKeyFrame(8)->setTranslate(Vector3(-50, 30, -50));
	track->createNodeKeyFrame(10)->setTranslate(Vector3(-150, -20, -100));
	track->createNodeKeyFrame(12)->setTranslate(Vector3(-50, -30, 0));
	track->createNodeKeyFrame(14)->setTranslate(Vector3(50, 30, 0));

	// create an animation state from the animation and enable it
	mYellowLightAnimState = mSceneMgr->createAnimationState("Path1");
	mYellowLightAnimState->setEnabled(true);

	// set initial settings for the ribbon trail and add the light node
	trail->setInitialColour(0, 1.0f, 0.8f, 0);
	trail->setColourChange(0, 0.5f, 0.5f, 0.5f, 0.5f);
	trail->setInitialWidth(0, 5);
	trail->addNode(node);

	// attach a light with the same colour to the light node
	light = mSceneMgr->createLight();
	light->setDiffuseColour(trail->getInitialColour(0));
	node->attachObject(light);

	// attach a flare with the same colour to the light node
	bbs = mSceneMgr->createBillboardSet(1);
	bbs->createBillboard(Vector3::ZERO, trail->getInitialColour(0));
	bbs->setMaterialName("Examples/Flare");
	node->attachObject(bbs);

	// create a second light node
	node = mSceneMgr->getRootSceneNode()->createChildSceneNode(Vector3(-50, 100, 0));

	// create a 10 second animation with spline interpolation
	anim = mSceneMgr->createAnimation("Path2", 10);
	anim->setInterpolationMode(Animation::IM_SPLINE);

	track = anim->createNodeTrack(1, node);  // create a node track for our animation

	// enter keyframes for our track to define a path for the light to follow
	track->createNodeKeyFrame(0)->setTranslate(Vector3(-50, 100, 0));
	track->createNodeKeyFrame(2)->setTranslate(Vector3(-100, 150, -30));
	track->createNodeKeyFrame(4)->setTranslate(Vector3(-200, 0, 40));
	track->createNodeKeyFrame(6)->setTranslate(Vector3(0, -150, 70));
	track->createNodeKeyFrame(8)->setTranslate(Vector3(50, 0, 30));
	track->createNodeKeyFrame(10)->setTranslate(Vector3(-50, 100, 0));

	// create an animation state from the animation and enable it
	mGreenLightAnimState = mSceneMgr->createAnimationState("Path2");
	mGreenLightAnimState->setEnabled(true);

	trail->setInitialColour(1,0.0f,1.0f,0.4f);
	trail->setColourChange(1,0.5f,0.5f,0.5f,0.5f);
	trail->addNode(node);

	// attach a light with the same colour to the light node
	light = mSceneMgr->createLight();
	light->setDiffuseColour(trail->getInitialColour(1));
	node->attachObject(light);

	// attach a flare with the same colour to the light node
	bbs = mSceneMgr->createBillboardSet(1);
	bbs->createBillboard(Vector3::ZERO, trail->getInitialColour(1));
	bbs->setMaterialName("Examples/Flare");
	node->attachObject(bbs);
}