CopyBoneTransformsTo() public method

Copies bone transforms relative to Model.Root bone from this model to a given array.
public CopyBoneTransformsTo ( Matrix destinationBoneTransforms ) : void
destinationBoneTransforms Matrix The array receiving the transformed bones.
return void
        public void LoadContent(ContentManager content)
        {
            model = content.Load<Model>(asset);
            // allocate the array to the number of bones we have
            int boneCnt = model.Bones.Count;
            bindTransforms = new Matrix[boneCnt];
            bonesTransforms = new Matrix[boneCnt];
            absoTransforms = new Matrix[boneCnt];

            model.CopyBoneTransformsTo(bindTransforms);
            model.CopyBoneTransformsTo(bonesTransforms);
            model.CopyAbsoluteBoneTransformsTo(absoTransforms);

            PlayClip("Take 001");
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of <c>ModelSkeleton</c>.
        /// </summary>
        public ModelSkeleton(Microsoft.Xna.Framework.Graphics.Model model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            var skeleton = model.GetSkeletonData();

            if (skeleton != null)
            {
                SkeletonRoot            = skeleton.SkeletonRoot;
                InverseAbsoluteBindPose = new ReadOnlyCollection <Matrix>(skeleton.InverseAbsoluteBindPose);
            }

            boneTransforms = new Matrix[model.Bones.Count];
            model.CopyBoneTransformsTo(boneTransforms);
            BoneNames = new ReadOnlyCollection <string>(new BoneNameCollection()
            {
                Model = model
            });
            parentBones = new ReadOnlyCollection <int>(new ParentBoneCollection()
            {
                Model = model
            });
        }
Example #3
0
        //Matrix[] rot; 

        public CityEntity(City city)
        {
            _city = city;

            Point = city.Point;
            model = MainApplication.ManagerInstance.Content.Load<Model>("Content\\Models\\Civ5\\med_european");
            Scale = new Vector3(0.007f);

            int boneCount = model.Bones.Count;
            boneVisible = Enumerable.Repeat<bool>(true, boneCount).ToArray();

            this.boneTransforms = new Matrix[boneCount];
            model.CopyBoneTransformsTo(this.boneTransforms);

            this.absoluteBoneTransforms = new Matrix[boneCount];
        }
Example #4
0
        public DrawableModel(Model model, Matrix worldMatrix)
        {
            this.model = model;
            this.worldMatrix = worldMatrix;
            modelTransforms = new Matrix[model.Bones.Count];

            originalTransforms = new Matrix[model.Bones.Count];
            model.CopyBoneTransformsTo(originalTransforms);

            LoadModelBoundingSphere();

            position = new Vector3();

            if (debug)
                WriteModelStructure(model);
        }
Example #5
0
File: Car.cs Project: Biskus/rush
        // Constructor
        public Car(ContentManager content, string fileName)
        {
            // Utgangsposisjon, fart og styringsutslaget.
            Speed = 0.0f;
            SteerAngle = 0.0f;

            // Les .x-objektet fra 3DS Max
            model = content.Load<Model>(fileName);

            // Juster objektet i forhold til koordinatsystemet fra 3DS Max
            Matrix rotation = Matrix.CreateRotationZ(-MathHelper.PiOver2);
            model.Bones[0].Transform = rotation * model.Bones[0].Transform;

            // Initier tabell for utgangtransformasjoner
            initialTransforms = new Matrix[model.Bones.Count];
            model.CopyBoneTransformsTo(initialTransforms);

            // Initier tabell for nåværende transformasjoner
            currentTransforms = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(currentTransforms);
            //ModelLister.DumpModel(model);
            velocity = new Vector3(0, 0, 0);
        }
Example #6
0
        public static void Draw(DetectionResult markerResult, Model model, double x, double y, double z, float zRotation = 0.0f, bool customLocation = false)
        {
            if (markerResult != null)
            {
                float aspectRatio = (float)SharedGraphicsDeviceManager.Current.GraphicsDevice.Viewport.AspectRatio;

                SharedGraphicsDeviceManager.Current.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
                SharedGraphicsDeviceManager.Current.GraphicsDevice.BlendState = BlendState.Opaque;
                SharedGraphicsDeviceManager.Current.GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;

                Vector3 cameraPosition = new Vector3(0, 0, 150);

                Microsoft.Xna.Framework.Matrix[] transforms = new Microsoft.Xna.Framework.Matrix[model.Bones.Count];
                model.CopyBoneTransformsTo(transforms);
                // Draw the model. A model can have multiple meshes, so loop.
                foreach (ModelMesh mesh in model.Meshes)
                {
                    foreach (BasicEffect effect in mesh.Effects)
                    {
                        Vector3 modelPosition = new Vector3((int)(customLocation ?  x : ((x < 5 ? (4 - x) * -1 : x - 4) * SCALE)), (int)(customLocation ? y : ((y < 5 ? (4 - y) * -1 : y - 4) * SCALE)), (int)(customLocation ? z : (z * SCALE)));
                        effect.EnableDefaultLighting();
                        effect.World = Microsoft.Xna.Framework.Matrix.CreateScale(SCALE / 2) *
                            (transforms[mesh.ParentBone.Index]
                            * mesh.ParentBone.Transform
                            * Matrix.CreateRotationZ(zRotation)
                            * Microsoft.Xna.Framework.Matrix.CreateTranslation(modelPosition)
                            * markerResult.Transformation.ToXnaMatrix()
                        );

                        effect.View = Microsoft.Xna.Framework.Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
                        effect.Projection = Microsoft.Xna.Framework.Matrix.CreatePerspectiveFieldOfView(Microsoft.Xna.Framework.MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f);
                    }
                    // Draw the mesh, using the effects set above.
                    mesh.Draw();
                }
            }
        }
        public void LoadContent(ContentManager content)
        {
            model = content.Load<Model>(asset);
            // allocate the array to the number of bones we have
            int boneCnt = model.Bones.Count;
            bindTransforms = new Matrix[boneCnt];
            bonesTransforms = new Matrix[boneCnt];
            absoTransforms = new Matrix[boneCnt];

            model.CopyBoneTransformsTo(bindTransforms);
            model.CopyBoneTransformsTo(bonesTransforms);
            model.CopyAbsoluteBoneTransformsTo(absoTransforms);

            AnimationClips clips = model.Tag as AnimationClips;
            if (clips != null && clips.SkelToBone.Count > 0)
            {
                skelToBone = clips.SkelToBone;

                inverseBindTransforms = new Matrix[boneCnt];
                skinTransforms = new Matrix[NumSkinBones];

                model.CopyAbsoluteBoneTransformsTo(inverseBindTransforms);

                for (int b = 0; b < inverseBindTransforms.Length; b++)
                    inverseBindTransforms[b] = Matrix.Invert(inverseBindTransforms[b]);

                for (int i = 0; i < skinTransforms.Length; i++)
                    skinTransforms[i] = Matrix.Identity;
            }

            foreach (AssetClip clip in assetClips.Values)
            {
                Model clipmodel = content.Load<Model>(clip.Asset);
                AnimationClips modelclips = clipmodel.Tag as AnimationClips;
                clip.TheClip = modelclips.Clips["Take 001"];
            }
            //PlayClip("Take 001");
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="BoneSnapshotController"/> class.
 /// </summary>
 public BoneSnapshotController(Microsoft.Xna.Framework.Graphics.Model model)
 {
     transforms = new Matrix[model.Bones.Count];
     model.CopyBoneTransformsTo(transforms);
 }
Example #9
0
        /// <summary>
        /// This function is called to load content into this component
        /// of our game.
        /// </summary>
        /// <param name="content">The content manager to load from.</param>
        public void LoadContent(ContentManager content)
        {
            // Load the second model
            model = content.Load<Model>(asset);

            // Save off all of hte bone information
            int boneCnt = model.Bones.Count;
            bindTransforms = new Matrix[boneCnt];
            boneTransforms = new Matrix[boneCnt];

            model.CopyBoneTransformsTo(bindTransforms);
            model.CopyBoneTransformsTo(boneTransforms);

            // Find all of the doors and save the index for the bone
            for (int b = 0; b < boneCnt; b++)
            {
                if (model.Bones[b].Name.StartsWith("DoorInner") || model.Bones[b].Name.StartsWith("DoorOuter"))
                {
                    doors.Add(b);
                    doorState.Add(new DoorClass());
                }

            }

            effect = content.Load<Effect>("PhibesEffect1");
            effectT = content.Load<Effect>("PhibesEffect2");
        }
Example #10
0
        public UnitEntity(AbstractPlayerData player, Unit unit, string name)
        {
            Point = unit.Point;
            _unit = unit;
            _player = player;

            _model = MainApplication.ManagerInstance.Content.Load<Model>("Content\\Models\\" + name);
            _animations.Add("Idle", new ModelAnimation("Content\\Animations\\" + name + "\\Idle"));

            Status = ModelStatus.Standing;

            for (int i = 0; i < unit.Formation.Positions; ++i)
            {
                Vector3 startOffset = unit.Formation.GetPosition(i);

                _items.Add(new UnitItem(Position + startOffset, startOffset, Rotation));
            }

            _scaleMatrix = Matrix.CreateScale(Scale * 0.3f);

            int boneCount = _model.Bones.Count;

            this.boneTransforms = new Matrix[boneCount];
            _model.CopyBoneTransformsTo(this.boneTransforms);

            this.boneTransformsOriginal = new Matrix[boneCount];
            _model.CopyBoneTransformsTo(this.boneTransformsOriginal);

            this.absoluteBoneTransforms = new Matrix[boneCount];

            SetAnimation("Idle");
        }
Example #11
0
        protected override void LoadContent()
        {
            // Load Fonts
            startFont = Content.Load<SpriteFont>(@"fonts\Start");
            descriptionFont = Content.Load<SpriteFont>(@"fonts\Description");
            font = Content.Load<SpriteFont>(@"fonts\SpriteFont");

            String temp = "Score: " + score;

            mainscore = new Button(Content.Load<Texture2D>("widebutton"),//Texture
                new Vector2(Window.ClientBounds.Width-220, 20),//Position
                new Point(200, 50),//Framesize
                0, //Collision Offset
                font,
                Color.Black,
                temp);

            temp = "Happiness: " + happiness;

            happyscore = new Button(Content.Load<Texture2D>("widebutton"),//Texture
                new Vector2(Window.ClientBounds.Width - 220, 70),//Position
                new Point(200, 50),//Framesize
                0, //Collision Offset
                font,
                Color.Black,
                temp);

            mainscore.buttonhover = mainscore.buttonnorm = mainscore.buttonpressed = Content.Load<Texture2D>("widebutton");
            happyscore.buttonhover = happyscore.buttonnorm = happyscore.buttonpressed = Content.Load<Texture2D>("widebutton");

            enter = new Button(Content.Load<Texture2D>("buttonnorm"),//Texture
                new Vector2(Window.ClientBounds.Width / 2 - 50, 420),//Position
                new Point(100, 50),//Framesize
                0, //Collision Offset
                font,
                Color.Black,
                "Start!");

            enter.buttonhover = enter.buttonnorm = enter.buttonpressed = Content.Load<Texture2D>("buttonhover");

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            //Add RPS
            rps = new RPS(this);

            //Add Matching
            matching = new Matching(this);

            //Add Cards
            cards = new Cards(this);

            //Save game to file class
            gameFile = new GameInfo(this);
            //Load in game info
            gameFile.getFile();

            //Load Food textures
            //apple = Content.Load<Texture2D>(@"Food/apple-icon");
            //cherries = Content.Load<Texture2D>(@"Food/Cherry");
            //banana = Content.Load<Texture2D>(@"Food/Banana");

            //Loading Model
            m = Content.Load<Model>("hippo7");
            modelTransforms = new Matrix[m.Bones.Count];
            originalTransforms = new Matrix[m.Bones.Count];
            m.CopyBoneTransformsTo(originalTransforms);

            //Load Tree
            tree = Content.Load<Model>("tree4-fbx");
            treemodelTransforms = new Matrix[tree.Bones.Count];
            treeoriginalTransforms = new Matrix[m.Bones.Count];
            tree.CopyBoneTransformsTo(treeoriginalTransforms);

            //Load Grass
            grass = Content.Load<Model>("grass_low_poly");
            grassmodelTransforms = new Matrix[grass.Bones.Count];
            grassoriginalTransforms = new Matrix[grass.Bones.Count];
            grass.CopyBoneTransformsTo(grassoriginalTransforms);

            //Loading Terrain
            t = new Terrain(this);
            t.Initialize();

            //Load Hippo
            h = new Hippo(this);
            h.Initialize();

            //Loading Height Texture
            Texture2D heightMap = Content.Load<Texture2D>("Untitled");

            // Load Sounds
            audioBackground = Content.Load<SoundEffect>(@"sound\jungle");
            backgroundInstance = audioBackground.CreateInstance();
            backgroundInstance.Volume = 0.35f;

            audioBackground2 = Content.Load<SoundEffect>(@"sound\background1");
            backgroundInstance2 = audioBackground2.CreateInstance();
            backgroundInstance2.Volume = 0.35f;

            soundfxButton = Content.Load<SoundEffect>(@"sound\button");
            soundfxButton2 = Content.Load<SoundEffect>(@"sound\button2");

            //Intializing Camera
            c = new Camera(this);
            Components.Add(c);

            //Initalizing Sprite Manager
            spriteManager = new SpriteManager(this);

            // Initializing Text Utility Class
            text = new TextInterface(this);
            Components.Add(text);

            int hippobox = 25;
            for(int i = 0; i<200; i++){
                Point p = new Point(r.Next(80) - 40, r.Next(80) - 40);
                if((p.X < -hippobox || p.X > hippobox) || (p.Y < -hippobox || p.Y > hippobox+10))
                        grasspos.Add(p);
            }
        }
Example #12
0
        /// <summary>
        /// This function is called to load content into this component
        /// of our game.
        /// </summary>
        /// <param name="content">The content manager to load from.</param>
        public void LoadContent(ContentManager content)
        {
            // Load the second model
            model = content.Load<Model>(asset);

            // Save off all of hte bone information
            int boneCnt = model.Bones.Count;
            bindTransforms = new Matrix[boneCnt];
            boneTransforms = new Matrix[boneCnt];

            model.CopyBoneTransformsTo(bindTransforms);
            model.CopyBoneTransformsTo(boneTransforms);

            // Find all of the doors and save the index for the bone
            for (int b = 0; b < boneCnt; b++)
            {
                if (model.Bones[b].Name.StartsWith("DoorInner") || model.Bones[b].Name.StartsWith("DoorOuter"))
                {
                    //Create and initialize doors
                    Door thisDoor = new Door();
                    thisDoor.boneNum = b;
                    thisDoor.boneName = model.Bones[b].Name;
                    thisDoor.doorState = Door.DoorState.DoorClosed;
                    switch(thisDoor.boneName.Substring(9,thisDoor.boneName.Length-9))
                    {
                        case "1":
                            thisDoor.location=new Vector3(218,0,1023);
                            break;
                        case "2":
                            thisDoor.location=new Vector3(-11,0,-769);
                            break;
                        case "3":
                            thisDoor.location=new Vector3(587,0,-999);
                            break;
                        case "4":
                            thisDoor.location=new Vector3(787,0,-763);
                            break;
                        case "5":
                            thisDoor.location=new Vector3(1187,0,-1218);
                            break;
                    }
                    doors.Add(thisDoor);
                }
            }
        }
Example #13
0
 public object3d(Model modelToUse)
 {
     objectModel = modelToUse;
     originaltransforms = new Matrix[objectModel.Bones.Count];
     objectModel.CopyBoneTransformsTo(originaltransforms);
     transforms = new Matrix[objectModel.Bones.Count];           // probably not necessary but
     objectModel.CopyAbsoluteBoneTransformsTo(transforms);       // better safe than sorry
     pivotPoints = new Vector3[objectModel.Bones.Count];
 }
Example #14
0
        /// <summary>
        /// This function is called to load content into this component
        /// of our game.
        /// </summary>
        /// <param name="content">The content manager to load from.</param>
        public void LoadContent(ContentManager content)
        {
            // Load the second model
            model = content.Load<Model>(asset);

            // Save off all of hte bone information
            int boneCnt = model.Bones.Count;
            bindTransforms = new Matrix[boneCnt];
            boneTransforms = new Matrix[boneCnt];

            model.CopyBoneTransformsTo(bindTransforms);
            model.CopyBoneTransformsTo(boneTransforms);

            // Find all of the doors
            for (int b = 0; b < boneCnt; b++)
            {
                if (model.Bones[b].Name.StartsWith("DoorInner") || model.Bones[b].Name.StartsWith("DoorOuter"))
                {
                    // What is the door number?
                    int dnum = int.Parse(model.Bones[b].Name.Substring(9));

                    // Add to a dictionary that converts door numbers to bone indices
                    doors[dnum] = new Door();
                    doors[dnum].Bone = b;
                }

            }
        }
        /// <summary>
        /// This function is called to load content into this component
        /// of our game.
        /// </summary>
        /// <param name="content">The content manager to load from.</param>
        public void LoadContent(ContentManager content)
        {
            // Load the second model
            model = content.Load<Model>(asset);

            // Save off all of hte bone information
            int boneCnt = model.Bones.Count;
            bindTransforms = new Matrix[boneCnt];
            boneTransforms = new Matrix[boneCnt];

            model.CopyBoneTransformsTo(bindTransforms);
            model.CopyBoneTransformsTo(boneTransforms);

            // Find all of the doors and save the index for the bone
            for (int b = 0; b < boneCnt; b++)
            {
                if (model.Bones[b].Name.StartsWith("DoorInner") || model.Bones[b].Name.StartsWith("DoorOuter"))
                {
                    doors.Add(b);
                }

            }

            // As supplied, all of the doors are closed. This code opens each door by
            // translating it up 2 meters.
               // foreach (int d in doors)
               // {
                //boneTransforms[d] = Matrix.CreateTranslation(0, 0, 0) * bindTransforms[d];
               // }
        }
Example #16
0
        public Vector3 CalculerDimensionModele(Model Modèle)
        {
            // Create variables to hold min and max xyz values for the model. Initialise them to extremes
             Vector3 modelMax = new Vector3(float.MinValue, float.MinValue, float.MinValue);
             Vector3 modelMin = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);

             Matrix[] transformationModele = new Matrix[Modèle.Bones.Count];
             Modèle.CopyBoneTransformsTo(transformationModele);

             foreach (ModelMesh mesh in Modèle.Meshes)
             {
            //Create variables to hold min and max xyz values for the mesh. Initialise them to extremes
            Vector3 meshMax = new Vector3(float.MinValue, float.MinValue, float.MinValue);
            Vector3 meshMin = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);

            // There may be multiple parts in a mesh (different materials etc.) so loop through each
            foreach (ModelMeshPart part in mesh.MeshParts)
            {
               // The stride is how big, in bytes, one vertex is in the vertex buffer
               // We have to use this as we do not know the make up of the vertex
               int stride = part.VertexBuffer.VertexDeclaration.VertexStride;

               byte[] vertexData = new byte[stride * part.NumVertices];
               part.VertexBuffer.GetData(part.VertexOffset * stride, vertexData, 0, part.NumVertices, 1); // fixed 13/4/11

               // Find minimum and maximum xyz values for this mesh part
               // We know the position will always be the first 3 float values of the vertex data
               Vector3 vertPosition = new Vector3();
               for (int ndx = 0; ndx < vertexData.Length; ndx += stride)
               {
                  vertPosition.X = BitConverter.ToSingle(vertexData, ndx);
                  vertPosition.Y = BitConverter.ToSingle(vertexData, ndx + sizeof(float));
                  vertPosition.Z = BitConverter.ToSingle(vertexData, ndx + sizeof(float) * 2);

                  // update our running values from this vertex
                  meshMin = Vector3.Min(meshMin, vertPosition);
                  meshMax = Vector3.Max(meshMax, vertPosition);
               }
            }

            // transform by mesh bone transforms
            meshMin = Vector3.Transform(meshMin, transformationModele[mesh.ParentBone.Index]);
            meshMax = Vector3.Transform(meshMax, transformationModele[mesh.ParentBone.Index]);

            // Expand model extents by the ones from this mesh
            modelMin = Vector3.Min(modelMin, meshMin);
            modelMax = Vector3.Max(modelMax, meshMax);
             }

             // Create and return the model bounding box
             return ValeurAbsolueVecteur(modelMax) + ValeurAbsolueVecteur(modelMin);
        }