Esempio n. 1
0
        public Actor(ContentRegister content, Vector3 position, float animationSpeed, int animationIndex)
        {
            Matrix.CreateRotationZ(1 - (float)animationIndex, out this.worldMatrix);
            this.worldMatrix.Translation = position;

            model = new ModelInstance();
            this.animationController = model.GetAnimationController();

            content.Add(this);

            this.animation = this.animationController.PlayLoopingAnimation(animationIndex);
            this.animation.PlaybackSpeed = animationSpeed;
        }
Esempio n. 2
0
        public Actor(ContentRegister content)
        {
            //A ModelInstance can be created without any content...
            //However it cannot be used until the content is set

            model = new ModelInstance();

            content.Add(this);

            //play an animation
            model.GetAnimationController().PlayLoopingAnimation(3);

            //This method creates a Cube for each bone in the mesh
            BuildBoundingBoxGeometry();
        }
		public Actor(ContentRegister content)
		{
			//A ModelInstance can be created without any content...
			//However it cannot be used until the content is set

			model = new ModelInstance();

			content.Add(this);

			//play an animation
			model.GetAnimationController().PlayLoopingAnimation(3);

			//This method creates a Cube for each bone in the mesh
			BuildBoundingBoxGeometry();
		}
		//NEW CODE
		public Actor(ContentRegister content, MaterialLightCollection lights)
		{
			//A ModelInstance can be created without any content...
			//However it cannot be used until the content is set

			model = new ModelInstance();
			model.LightCollection = lights;	//this class is reused by later tutorials, which require lights

			//get and create the animation controller for this model.
			animationController = model.GetAnimationController();

			//NOTE: Animations cannot be played until the model data has been loaded...

			content.Add(this);

			//At this point in this tutorial, the model is now loaded.

			//get the index of the walk animation
			//this model has 4 animations, Wave, Jog, Walk and Loiter
			//The animations are stored in model.ModelData.Animations
			int animationIndex = animationController.AnimationIndex("Walk");

			//begin playing the animation, looping
			animation = animationController.PlayLoopingAnimation(animationIndex);

			//as many animations as you want can be played at any one time
			//to blend between animations, adjust their weighting with:
			//animation.Weighting = ...;
			//Combined weightings usually should add up to 1.0
			//A weighting of 0 means the animation has no effect, 1 has normal effect.
			//Values outside the 0-1 range usually produces undesirable results.

			//Note:
			//Animations in xen are lossy compressed.
			//For the model used here, the animation data is reduced from nearly 2mb
			//down to around 200kb. (The model geometry is less than 300kb)
			//The amount of compression change can be configured in the content's properties
			//The 'Animation Compression Tolerance' value is a percentage
			//The default is .5%. This means the animation will always be within .5%
			//of the source. Setting this value to 0 will save a lossless animation.
		}
Esempio n. 5
0
        //NEW CODE
        public Actor(ContentRegister content)
        {
            //A ModelInstance can be created without any content...
            //However it cannot be used until the content is set

            model = new ModelInstance();

            //create the animation controller.
            animationController = model.GetAnimationController();

            //NOTE: Animations cannot be played until the model data has been loaded...

            content.Add(this);

            //At this point in this tutorial, the model is now loaded.

            //get the index of the walk animation
            //this model has 4 animations, Wave, Jog, Walk and Loiter
            //The animations are stored in model.ModelData.Animations
            int animationIndex = animationController.AnimationIndex("Walk");

            //begin playing the animation, looping
            animation = animationController.PlayLoopingAnimation(animationIndex);

            //as many animations as you want can be played at any one time
            //to blend between animations, adjust their weighting with:
            //animation.Weighting = ...;
            //Combined weightings usually should add up to 1.
            //A weighting of 0 means the animation has no effect, 1 has normal effect.
            //Values outside the 0-1 range usually produces undesirable results.

            //Note:
            //Animations in xen are lossy compressed.
            //For the model used here, the animation data is reduced from nearly 2mb
            //down to around 200kb. (The model geometry is less than 300kb)
            //The amount of compression change can be configured in the content's properties
            //The 'Animation Compression Tolerance' value is a percentage
            //The default is .5%. This means the animation will always be within .5%
            //of the source. Setting this value to 0 will save a lossless animation.
        }
Esempio n. 6
0
        //NEW CODE
        private void DrawBoundingBoxes(DrawState state)
        {
            //First, get the animated bone transforms of the model.
            //These transforms are in 'bone-space', not in world space.
            ReadOnlyArrayCollection <Transform> boneAnimationTransforms = model.GetAnimationController().GetTransformedBones(state);


            //Get a simple shader from Xen.Ex that fills a solid colour
            Xen.Ex.Shaders.FillSolidColour shader = state.GetShader <Xen.Ex.Shaders.FillSolidColour>();

            shader.FillColour = Color.White.ToVector4();

            shader.Bind(state);



            //push the render state...
            state.PushRenderState();

            //disable back face culling
            state.RenderState.DepthColourCull.CullMode = CullMode.None;
            //set to wireframe
            state.RenderState.DepthColourCull.FillMode = FillMode.WireFrame;

            //loop through all the geometry data in the model..
            //(note, the sample model has only 1 geometry instance)


            Xen.Ex.Graphics.Content.SkeletonData modelSkeleton = model.ModelData.Skeleton;
            Matrix matrix;
            int    boxIndex = 0;

            foreach (Xen.Ex.Graphics.Content.MeshData meshData in model.ModelData.Meshes)
            {
                foreach (Xen.Ex.Graphics.Content.GeometryData geometry in meshData.Geometry)
                {
                    //now loop through all bones used by this geometry

                    for (int geometryBone = 0; geometryBone < geometry.BoneIndices.Length; geometryBone++)
                    {
                        //index of the bone (a piece of geometry may not use all the bones in the model)
                        int boneIndex = geometry.BoneIndices[geometryBone];

                        //get the base transform of the bone (the transform when not animated)
                        Transform boneTransform = modelSkeleton.BoneWorldTransforms[boneIndex];

                        //multiply the transform with the animation bone-local transform

                        //it would be better to use Transform.Multiply() here to save data copying on the xbox
                        boneTransform *= boneAnimationTransforms[boneIndex];

                        //Get the transform as a matrix
                        boneTransform.GetMatrix(out matrix);

                        //push the matrix
                        state.PushWorldMatrix(ref matrix);

                        //draw the box
                        if (boundingBoxes[boxIndex].CullTest(state))
                        {
                            boundingBoxes[boxIndex].Draw(state);
                        }

                        boxIndex++;

                        //pop the world matrix
                        state.PopWorldMatrix();
                    }
                }
            }

            //pop the render state
            state.PopRenderState();
        }
		public Actor(ContentRegister content, Vector3 position, float animationSpeed, int animationIndex)
		{
			Matrix.CreateRotationZ(1-(float)animationIndex, out this.worldMatrix);
			this.worldMatrix.Translation = position;

			model = new ModelInstance();
			this.animationController = model.GetAnimationController();

			content.Add(this);

			this.animation = this.animationController.PlayLoopingAnimation(animationIndex);
			this.animation.PlaybackSpeed = animationSpeed;
		}