CopyAbsoluteBoneTransformsTo() public method

Copies bone transforms relative to all parent bones of the each bone from this model to a given array.
public CopyAbsoluteBoneTransformsTo ( Matrix destinationBoneTransforms ) : void
destinationBoneTransforms Matrix The array receiving the transformed bones.
return void
Esempio n. 1
0
        public void DrawBall(float aspectRatio, Vector3 cameraPosition, Model ball, float xrotation,float yrotation)
        {
            // assign random number to roid1modelPosition.x or y

            // Copy any parent transforms.
            Matrix[] transforms = new Matrix[ball.Bones.Count];
            ball.CopyAbsoluteBoneTransformsTo(transforms);

            // Draw the model. A model can have multiple meshes, so loop.
            foreach (ModelMesh mesh in ball.Meshes)
            {
                // This is where the mesh orientation is set, as well as our camera and projection.
                foreach (BasicEffect effect in mesh.Effects)
                {

                    effect.EnableDefaultLighting();
                    effect.World = transforms[mesh.ParentBone.Index] //* Matrix.CreateRotationZ(Roid1modelRotation)
                        * Matrix.CreateRotationX(xrotation) * Matrix.CreateRotationY(yrotation)
                        * Matrix.CreateTranslation(new Vector3(3750, -2750, 0));

                    effect.View = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
                    effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f),
                        aspectRatio, 1.0f, 10000.0f);
                }
                // Draw the mesh, using the effects set above.
                mesh.Draw();
            }
        }
Esempio n. 2
0
        public void Draw(float aspectRatio, Vector3 cameraPosition,Model mesh)
        {
            transforms = new Matrix[mesh.Bones.Count];
            mesh.CopyAbsoluteBoneTransformsTo(transforms);

            foreach (var singleMesh in mesh.Meshes)
            {
                // This is where the mesh orientation is set, as well as our camera and projection.
                foreach (BasicEffect effect in singleMesh.Effects)
                {
                    effect.EnableDefaultLighting();

                    effect.World = transforms[singleMesh.ParentBone.Index] * Matrix.CreateRotationY(ObjectArrangement.Rotation.Y)
                        * Matrix.CreateTranslation(ObjectArrangement.Position) * Matrix.CreateScale(ObjectArrangement.Scale);

                    effect.View = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);

                    effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f),
                        aspectRatio, 1.0f, 10000.0f);

                }

                singleMesh.Draw();
            }
        }
Esempio n. 3
0
        public override void LoadContent(ContentManager Content)
        {
            Board.setModel(Content.Load<Model>("Models\\board"));
            Piece.setModel(Content.Load<Model>("Models\\piece"));

            selector = Content.Load<Model>("Models\\selector");
            selectorTrans = new Matrix[selector.Bones.Count];
            selector.CopyAbsoluteBoneTransformsTo(selectorTrans);
            ((BasicEffect)selector.Meshes[0].Effects[0]).Alpha = 0.6f;
            ((BasicEffect)selector.Meshes[0].Effects[0]).DiffuseColor = Vector3.UnitX;

            Player.LoadContent(Content);

            background = Content.Load<Texture2D>("Images\\background");

            Viewport v = Program.game.GraphicsDevice.Viewport;
            destRect = new Rectangle(0, 0, v.Width, v.Height);
            int x, y, w, h;
            if (background.Width / background.Height > destRect.Width / destRect.Height)
            {
                h = background.Height;
                w = background.Height * destRect.Width / destRect.Height;
                y = 0;
                x = (background.Width - w) / 2;
            }
            else
            {
                h = background.Width * destRect.Height / destRect.Width;
                w = background.Width;
                y = (background.Height - h) / 2;
                x = 0;
            }
            srcRect = new Rectangle(x, y, w, h);
        }
        public BillboardsSystem(ContentManager content, BillboardMode mode, Model model,
            Matrix[] instancedModelBones, Matrix[] instanceTransforms,
            Vector3 position, Vector3 rotation, Vector3 scale,
            Vector3 LightDirection, Vector3 LightColor, Vector3 AmbientLight,
            GraphicsDevice graphicsDevice)
        {
            this.model = model;
            modelTransforms = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(modelTransforms);

            buildBoundingSphere();

            this.position = position;
            this.rotation = rotation;
            this.scale = scale;
            this.graphicsDevice = graphicsDevice;

            this.instancedModelBones = instancedModelBones;
            this.instanceTransforms = instanceTransforms;

               // this.LightDirection = LightDirection;
               // this.LightColor = LightColor;
               // this.AmbientColor = AmbientLight;

            this.mode = mode;
            effect = content.Load<Effect>("Effects//AlphaBlending");
            _effect = content.Load<Effect>("shaders//LPPMainEffect");
            //SetModelEffect(effect, false);
        }
Esempio n. 5
0
        public ShipFbx(String modelName)
        {
            model = BeatShift.contentManager.Load<Model>("Models/Ships/" + modelName);

            SkinningData skd = GetSkinningDataFromTag();
            if (isAnimated) {
                clipPlayer = new ClipPlayer(skd, 24);
            }
            else
            {
                bones = new Matrix[model.Bones.Count];
                model.CopyAbsoluteBoneTransformsTo(bones);
            }

            #if !DEBUG
            Utils.fixNullLightDirections(model);
            #endif

            GC.Collect();

            //Override the default texture
            //Texture2D grayTexture;
            //grayTexture = content.Load<Texture2D>("tex5");
            //shipRenderer.Texture = grayTexture;
            //shipRenderer.TextureEnabled = true;
        }
Esempio n. 6
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(MXF.GameTime gameTime)
        {
            ICameraManagerService cameraManagerService = (ICameraManagerService)this.Services.GetService(typeof(ICameraManagerService));

            graphics.GraphicsDevice.Clear(MXF.Color.CornflowerBlue);

            // Copy any parent transforms.
            MXF.Matrix[] transforms = new MXF.Matrix[castle.Bones.Count];
            castle.CopyAbsoluteBoneTransformsTo(transforms);

            //// Draw the model. A model can have multiple meshes, so loop.
            foreach (XFG.ModelMesh mesh in castle.Meshes)
            {
                // This is where the mesh orientation is set, as well as our camera and projection.
                foreach (XFG.BasicEffect effect in mesh.Effects)
                {
                    effect.World      = MXF.Matrix.CreateRotationY(this.modelRotation) * MXF.Matrix.CreateTranslation(this.modelPosition);
                    effect.View       = cameraManagerService.Camera.View;
                    effect.Projection = cameraManagerService.Camera.Projection;
                    effect.EnableDefaultLighting();
                }
                // Draw the mesh, using the effects set above.
                mesh.Draw();
            }

            base.Draw(gameTime);
        }
Esempio n. 7
0
 public MovableModel(Model model, Matrix4 transform)
     : base(transform)
 {
     m_model = model;
     m_transforms = new Matrix[m_model.Bones.Count];
     m_model.CopyAbsoluteBoneTransformsTo (m_transforms);
 }
Esempio n. 8
0
        public void drawMesh(Model myModel, Vector3 modelPosition, float modelRotation, Camera camera)
        {
            float aspectRatio = (float)Tools.Quick.graphics.GraphicsDevice.Viewport.Width /
               (float)Tools.Quick.graphics.GraphicsDevice.Viewport.Height;
            // Copy any parent transforms.
            Matrix[] transforms = new Matrix[myModel.Bones.Count];
            myModel.CopyAbsoluteBoneTransformsTo(transforms);
            Tools.Quick.device.RasterizerState = RasterizerState.CullNone;  // vertex order doesn't matter
            Tools.Quick.device.BlendState = BlendState.Opaque;    // use alpha blending
            Tools.Quick.device.DepthStencilState = DepthStencilState.Default;  // don't bother with the depth/stencil buffer

            // Draw the model. A model can have multiple meshes, so loop.
            foreach (ModelMesh mesh in myModel.Meshes)
            {
                // This is where the mesh orientation is set, as well as our camera and projection.
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(modelRotation) * Matrix.CreateTranslation(modelPosition); //modelPosition
                    effect.View = camera.getview();
                    effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f),

                        aspectRatio, 1.0f, 1000000.0f);

                }
                // Draw the mesh, using the effects set above.
                mesh.Draw();
            }
        }
Esempio n. 9
0
        public void DrawTheMatrix(Model DModel, Matrix ChangeMatrix, Vector3 Pos)
        {
            Matrix[] transforms = new Matrix[DModel.Bones.Count];
            DModel.CopyAbsoluteBoneTransformsTo(transforms);

            //Draw model with all its meshes
            foreach (ModelMesh mesh in DModel.Meshes)//Every mesh in MyModel
            {

                //Mesh Orientation and camera and projection
                foreach (BasicEffect effect in mesh.Effects)
                {

                    effect.EnableDefaultLighting();

                    //Sets up the posibillity to use transformatiion on the G.myModelObject
                    effect.World
                        = transforms[mesh.ParentBone.Index]
                        * ChangeMatrix;

                    effect.View = Matrix.CreateLookAt(G.CamPos, G.ship.Position, Vector3.Up);
                    //                                                                                            Near  Far   Wherever you are
                    effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(G.Fov), G.aspectRatio, 1.0f, 100000);

                }
                mesh.Draw();
            }
        }
Esempio n. 10
0
        protected override void Draw(GameTime gameTime)
        {
            graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

            // Copy any parent transforms.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            myModel = Content.Load<Model>("Models\\test");
            aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio;

            Matrix[] transforms = new Matrix[myModel.Bones.Count];
            myModel.CopyAbsoluteBoneTransformsTo(transforms);

            // Draw the model. A model can have multiple meshes, so loop.
            foreach (ModelMesh mesh in myModel.Meshes)
            {
                // This is where the mesh orientation is set, as well
                // as our camera and projection.
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.World = transforms[mesh.ParentBone.Index] *
                        Matrix.CreateRotationY(modelRotation)
                        * Matrix.CreateTranslation(modelPosition);
                    effect.View = Matrix.CreateLookAt(cameraPosition,
                        Vector3.Zero, Vector3.Up);
                    effect.Projection = Matrix.CreatePerspectiveFieldOfView(
                        MathHelper.ToRadians(45.0f), aspectRatio,
                        1.0f, 10000.0f);
                }
                // Draw the mesh, using the effects set above.
                mesh.Draw();
            }
            base.Draw(gameTime);
        }
Esempio n. 11
0
        public override void Build()
        {
            model = Demo.Content.Load<Model>("staticmesh");
            boneTransforms = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(boneTransforms);

            List<TriangleVertexIndices> indices = new List<TriangleVertexIndices>();
            List<Vector3> vertices = new List<Vector3>();

            ExtractData(vertices, indices, model);

            List<JVector> jvertices = new List<JVector>(vertices.Count);
            foreach(Vector3 vertex in vertices) jvertices.Add(Conversion.ToJitterVector(vertex));

            Octree octree = new Octree(jvertices, indices);

            TriangleMeshShape tms = new TriangleMeshShape(octree);
            RigidBody body = new RigidBody(tms);
            body.IsStatic = true;
            //body.EnableDebugDraw = true;
            body.Tag = BodyTag.DontDrawMe;

            Demo.World.AddBody(body);

            AddCar(new JVector(-20, 20, 0));
        }
Esempio n. 12
0
        public Star(GameplayScreen game, Model model, Matrix view, Matrix projection, Random random)
            : base(game.ScreenManager.Game)
        {
            this.random = random;
            this.x = random.Next(-340, 200) / 100f;
            this.speed = random.Next(2, 8) / 1000f;

            float scale = random.Next(100, 1000)/100000f;

            if(speed > 0.0004)
                this.y = random.Next(5, 10);
            else
                this.y = random.Next(2, 5);

            xRotation = (float) random.Next(-360, 360);
            yRotation = (float)random.Next(-360, 360);
            zRotation = (float)random.Next(-360, 360);

            color = new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble());

            this.DrawOrder = 900;
            this.view = view;
            this.projection = projection;
            this.model = model;
            this.game = game;
            this.world = Matrix.Identity * Matrix.CreateScale(scale) * Matrix.CreateTranslation(x, y, 13f);
            transforms = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(transforms);
        }
Esempio n. 13
0
        /// <summary>
        /// Copies the positions of the model to the target array.
        /// </summary>
        public static int CopyPositionsTo(this Microsoft.Xna.Framework.Graphics.Model model, Vector3[] positions, int startIndex)
        {
            Matrix[] bones = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(bones);

            int count = 0;

            foreach (var mesh in model.Meshes)
            {
                foreach (var part in mesh.MeshParts)
                {
                    int partCount = CopyPositionsTo(model, mesh, part, positions, startIndex);
                    if (positions != null)
                    {
                        for (int i = startIndex; i < startIndex + partCount; ++i)
                        {
                            Vector3.Transform(ref positions[i], ref bones[mesh.ParentBone.Index], out positions[i]);
                        }
                    }
                    startIndex += partCount;
                    count      += partCount;
                }
            }
            return(count);
        }
Esempio n. 14
0
        }         // NumOfMeshParts
        #endregion

        #region Constructor
        /// <summary>
        /// Create model
        /// </summary>
        /// <param name="setModelName">Set model name</param>
        public Model(string setModelName)
        {
            name = setModelName;

            Load();

            BaseGame.RegisterGraphicContentObject(this);

            // Get matrix transformations of the model
            // Has to be done only once because we don't use animations in this game.
            Matrix[] transforms = new Matrix[xnaModel.Bones.Count];
            xnaModel.CopyAbsoluteBoneTransformsTo(transforms);

            // Calculate scaling for this object, used for distance comparisons.
            if (xnaModel.Meshes.Count > 0)
            {
                downScaling =                // scaling =
                              xnaModel.Meshes[0].BoundingSphere.Radius *
                              transforms[0].Right.Length();
            }
            if (downScaling > 0)
            {
                downScaling = 1.0f / downScaling;
            }
            objectMatrix =
                // Use transformation of our first mesh (we support only one)
                transforms[xnaModel.Meshes[0].ParentBone.Index] *
                Matrix.CreateRotationX(MathHelper.Pi / 2.0f) *
                Matrix.CreateScale(downScaling);
        }         // Model(setModelName)
Esempio n. 15
0
 public Weapon(Game1 game,Player player, Model model, Unit unit)
     : base(game, unit, new CModel(game, model))
 {
     this.player = player;
     Matrix[] transforms = new Matrix[model.Bones.Count];
     model.CopyAbsoluteBoneTransformsTo(transforms);
 }
        public void ExtractData(List<JVector> vertices, List<JOctree.TriangleVertexIndices> indices, Model model)
        {
            Matrix[] bones_ = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(bones_);
            foreach (ModelMesh mm in model.Meshes)
            {
                Matrix xform = bones_[mm.ParentBone.Index];
                foreach (ModelMeshPart mmp in mm.MeshParts)
                {
                    int offset = vertices.Count;
                    Vector3[] a = new Vector3[mmp.NumVertices];
                    mm.VertexBuffer.GetData<Vector3>(mmp.StreamOffset + mmp.BaseVertex * mmp.VertexStride,
                        a, 0, mmp.NumVertices, mmp.VertexStride);
                    for (int i = 0; i != a.Length; ++i)
                        Vector3.Transform(ref a[i], ref xform, out a[i]);

                    for (int i = 0; i < a.Length; i++) vertices.Add(new JVector(a[i].X, a[i].Y, a[i].Z));

                    if (mm.IndexBuffer.IndexElementSize != IndexElementSize.SixteenBits)
                        throw new Exception(
                            String.Format("Model uses 32-bit indices, which are not supported."));
                    short[] s = new short[mmp.PrimitiveCount * 3];
                    mm.IndexBuffer.GetData<short>(mmp.StartIndex * 2, s, 0, mmp.PrimitiveCount * 3);
                    JOctree.TriangleVertexIndices[] tvi = new JOctree.TriangleVertexIndices[mmp.PrimitiveCount];
                    for (int i = 0; i != tvi.Length; ++i)
                    {
                        tvi[i].I0 = s[i * 3 + 2] + offset;
                        tvi[i].I1 = s[i * 3 + 1] + offset;
                        tvi[i].I2 = s[i * 3 + 0] + offset;
                    }
                    indices.AddRange(tvi);
                }
            }
        }
Esempio n. 17
0
 public c0000da(Model p0, c0000b5 p1, c0000db p2)
 {
     this.f00008e = p1;
     this.f000018 = p2;
     this.f00007a = new Dictionary<string, c0000dc>();
     foreach (string str in this.f00008e.Keys)
     {
         this.f00007a.Add(str, new c0000dc(this.f00008e[str]));
     }
     this.f0000e1 = new Matrix[p0.Bones.Count];
     p0.CopyAbsoluteBoneTransformsTo(this.f0000e1);
     Dictionary<string, object> tag = (Dictionary<string, object>) p0.Tag;
     if (tag == null)
     {
         throw new Exception("Model Processor must subclass AnimatedModelProcessor.");
     }
     this.f00013c = (c00008f[]) tag["SkinInfo"];
     if (this.f00013c == null)
     {
         throw new Exception("Model processor must pass skinning info through the tag.");
     }
     this.f00013d = new Matrix[p0.Meshes.Count][];
     for (int i = 0; i < this.f00013c.Length; i++)
     {
         if (c0000dd.m0001a9(p0.Meshes[i]))
         {
             this.f00013d[i] = new Matrix[this.f00013c[i].Count];
         }
         else
         {
             this.f00013d[i] = null;
         }
     }
 }
        //Ctor used for items like key which wont nescessarily be visible in the world
        public EnvironmentObject(string modelPath, ContentManager content)
        {
            model = content.Load<Model>(modelPath);

            transformation = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(transformation);
        }
Esempio n. 19
0
 public void Load(ContentManager content)
 {
     this.model = content.Load<Model>(path);
     // Copy any parent transforms.
     transforms = new Matrix[model.Bones.Count];
     model.CopyAbsoluteBoneTransformsTo(transforms);
 }
Esempio n. 20
0
        private void DrawModel(Model m)
        {
            Matrix[] transforms = new Matrix[m.Bones.Count];
            float aspectRatio = Context.Graphics.Device.Viewport.AspectRatio;
            m.CopyAbsoluteBoneTransformsTo(transforms);
            Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f);
            Matrix view = Matrix.CreateLookAt(new Vector3(0.0f, 2.0f, 10f), Vector3.Zero, Vector3.Up);

            var state = new RasterizerState();
            state.CullMode = CullMode.None;
            Context.Graphics.Device.RasterizerState = state;

            foreach (ModelMesh mesh in m.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.DiffuseColor = new Vector3(1, 1, 1);

                    effect.View = view;
                    effect.Projection = projection;
                    effect.World = Matrix.Identity * transforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(Position) * Matrix.CreateRotationY(MathHelper.ToRadians(angle));
                }

                mesh.Draw();
            }
        }
Esempio n. 21
0
 public Level(Game game, string levelModelFilename)
     : base(game)
 {
     model = game.Content.Load<Model>(levelModelFilename);
     boneTransforms = new Matrix[model.Bones.Count];
     model.CopyAbsoluteBoneTransformsTo(boneTransforms);
 }
Esempio n. 22
0
        private void drawModel(Model m)
        {
            Matrix[] transforms = new Matrix[m.Bones.Count];
            float aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio;
            m.CopyAbsoluteBoneTransformsTo(transforms);
            Matrix projection =
                Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f),
                    aspectRatio, 1.0f, 10000.0f);
                Matrix view = Matrix.CreateLookAt(new Vector3(0.0f, 50.0f, Zoom),
                Vector3.Zero, Vector3.Up);

            foreach (ModelMesh mesh in m.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();

                    effect.View = view;
                    effect.Projection = projection;
                    effect.World = gameWorldRotation *
                        transforms[mesh.ParentBone.Index] *
                        Matrix.CreateTranslation(Position);
                }
                mesh.Draw();
            }
        }
Esempio n. 23
0
 public AnimatableModel(ContentManager content)
 {
     model = content.Load<Model>("SpaceShip");
     boneTransforms = new Matrix[model.Bones.Count];
     model.CopyAbsoluteBoneTransformsTo(boneTransforms);
     World = new AnimatableMatrix();
 }
Esempio n. 24
0
        //0 = block
        //1 = table
        //2 = floor
        public SolidThing(Game game, Model model, bool isColorRandom, int thingType)
            : base((RigidBodyModel)model.Tag)
        {
            this.game = game;
            this._thingType = thingType;
            if (thingType == 1 || thingType == 2)
            {
                this.Freeze();
            }
            _model = model;
            _meshTransforms = new Matrix[_model.Bones.Count];
            _model.CopyAbsoluteBoneTransformsTo(_meshTransforms);

            foreach (var mesh in _model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    //By disabling this we get even lighting
                    effect.EnableDefaultLighting();
                    effect.AmbientLightColor = Vector3.One * 0.6f; 
                    effect.SpecularColor = Vector3.One;
                    effect.PreferPerPixelLighting = true;
                }
            }
            if (_isColorRandom = isColorRandom)
            {
                _diffuseColor = new Vector3((float)_colorRand.NextDouble(),
                    (float)_colorRand.NextDouble(), (float)_colorRand.NextDouble());
                _diffuseColor *= 0.75f; //By Increasing this we get a increase in vibrance of the blocks
            }
        }
Esempio n. 25
0
        public override void Draw(SpriteBatch spriteBatch, GraphicsDevice device)
        {
            if (m_basic_effect == null)
            {
                m_basic_effect               = new BasicEffect(device);
                m_basic_effect.FogEnabled    = true;
                m_basic_effect.FogColor      = new Vector3(0.6f, 0.6f, 0.6f);
                m_basic_effect.FogStart      = 0.0f;
                m_basic_effect.FogEnd        = 2000.0f;
                m_basic_effect.SpecularPower = 10000000.0f;
            }

            device.BlendState        = BlendState.Opaque;
            device.DepthStencilState = DepthStencilState.Default;
            device.SamplerStates[0]  = SamplerState.LinearWrap;

            RasterizerState rs = new RasterizerState();

            rs.CullMode            = CullMode.CullClockwiseFace;
            device.RasterizerState = rs;

            Matrix[] transforms = new Matrix[m_model.Bones.Count];
            m_model.CopyAbsoluteBoneTransformsTo(transforms);

            Matrix World = Matrix.Identity *
                           Matrix.CreateScale(m_scale) *
                           Matrix.CreateFromYawPitchRoll(m_rotation.Y, m_rotation.X, m_rotation.Z) *
                           Matrix.CreateTranslation(m_position);

            foreach (ModelMesh mesh in m_model.Meshes)
            {
                for (int i = 0; i < mesh.Effects.Count; i++)
                {
                    BasicEffect effect = (BasicEffect)mesh.Effects[i];
                    effect.EnableDefaultLighting();
                    effect.AmbientLightColor      = m_basic_effect.AmbientLightColor;
                    effect.DiffuseColor           = m_basic_effect.DiffuseColor;
                    effect.EmissiveColor          = m_basic_effect.EmissiveColor;
                    effect.FogColor               = m_basic_effect.FogColor;
                    effect.FogEnabled             = m_basic_effect.FogEnabled;
                    effect.FogEnd                 = m_basic_effect.FogEnd;
                    effect.FogStart               = m_basic_effect.FogStart;
                    effect.PreferPerPixelLighting = m_basic_effect.PreferPerPixelLighting;
                    effect.SpecularColor          = m_basic_effect.SpecularColor;
                    effect.SpecularPower          = m_basic_effect.SpecularPower;

                    effect.Projection = m_projection_xform;
                    effect.View       = m_view_xform;
                    effect.World      = transforms[mesh.ParentBone.Index] * World;
                }
                mesh.Draw();
            }

            if (m_boundingbox_enabled)
            {
                m_boundingbox = CalculateBoundingBox(transforms, World);
                DebugHelp.Draw_BoundingBox.Draw(m_boundingbox, Matrix.Identity * m_view_xform * m_projection_xform);
            }
        }
Esempio n. 26
0
        // Teken een model op een zekere positie
        // Hier wordt het een klein beetje ingewikkeld om de 3D effecten uit te voeren.
        // Misschien hoef je deze functie helemaal niet aan te passen, maar het kan natuurlijk wel.
        public void drawModel(Model model, float x, float y, float z)
        {
            // Maak een vector met de gewenste coordinaten.
            Vector3 modelPosition = new Vector3(x, y, z);

            // Zoals bij de introductie uitgelegd, worden modeltransformaties gerepresenteerd met matrices.
            // Een model kan bestaan uit onderdelen 'bones', met elk hun eigen, relatieve transformatie.
            // Die vragen we eerst op uit het model
            // Maake eerst een array van matrices aan
            Matrix[] transforms = new Matrix[model.Bones.Count];
            // Vul deze array met de matrices van de transformaties van elk van de onderdelen van het model.
            model.CopyAbsoluteBoneTransformsTo(transforms);

            // 'view' is een 3D-naar-3D transformatie matrix die bepaalt hoe 3D voorwerpen georienteerd zijn tov een camera in de ruimte.
            // Maak een standaard view matrix op basis van een camera perspectief van een camera op locatie 'cameraPosition' die kijkt naar positie
            // 'aimPosition' en die horizontaal hangt wanneer de vector 'Vector3.Up' (0,1,) naar boven wijst.
            Matrix view = Matrix.CreateLookAt(cameraPosition, aimPosition, Vector3.Up);
            // 'projection' is een 3D-naar-2D transformatie matrix die bepaalt hoe de 3D voorwerpen in een assenstelsel relatief tov de camera afgebeeld worden
            // op een 2D vlak zoals het scherm.
            // Maak de projectie op basis van een camera met een field-of-view van 45 graden een lengte-breedte verhouding van 'aspectRatio' die alle voorwerpen ziet met een afstand
            // tussen 1 en 10000 eenheden.
            Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f);

            // Teken het model. Een model kan bestaan uit meerder 'Meshes', die één voor één getekend moeten worden. Vandaar de volgende lus.
            foreach (ModelMesh mesh in model.Meshes)
            {
                // bepaal de transformatie matrix. Deze begint met de transformatie uit het model zelf, uit de transforms array
                // Daaraan wordt nog een translatie toegevoegd (vermenigvuldiging van de matrices), naar de gewenste model locatie (modelPosition)
                // Rotatie transformaties zijn ook mogelijk, bijv. een rotatie om de Z-as met de functie: Matrix.CreateRotationZ()
                Matrix world = transforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(modelPosition);

                // Het afbeelden ('renderen') van het model gebeurt met één of meerdere 'effecten', gedefinieerd in de mesh.
                // Die moeten één voor één ingesteld worden met de gewenste parameters
                foreach (BasicEffect effect in mesh.Effects)
                {
                    // Hier worden de uiteindelijke rendering parameters bepaald.
                    // belichtingseffect
                    effect.EnableDefaultLighting();
                    // voeg licht uit een bepaalde richting toe
                    effect.DirectionalLight1.Enabled = true;
                    effect.DirectionalLight1.Direction = new Vector3(0.0f, 300.0f, 0.0f);
                    // zet de gewenste transformatie voor het object, 'world'
                    effect.World = world;
                    // zet de transformatie die het voorwerp in absolute 'wereld' coordinaten omzet in camera coordinaten
                    effect.View = view;
                    // zet de transformatie die de projectie naar een 2D afbeelding uitvoert.
                    effect.Projection = projection;

                    if (model == projectionModel)
                    {
                        GraphicsDevice.BlendState = BlendState.AlphaBlend;
                        effect.Alpha = 0.5f;
                    }

                }
                // Teken uiteindelijk mesh daadwerkelijk op het scherm met de effecten hierboven gedefinieerd.
                mesh.Draw();
            }
        }
Esempio n. 27
0
 public Table(Model table3d)
 {
     // now that we've loaded in the models that will sit on the table, go
     // through the same procedure for the table itself.
     table = table3d;
     tableAbsoluteBoneTransforms = new Matrix[table.Bones.Count];
     table.CopyAbsoluteBoneTransformsTo(tableAbsoluteBoneTransforms);
 }
Esempio n. 28
0
        public static void setModel(Model m)
        {
            model = m;
            ((BasicEffect)m.Meshes[0].Effects[0]).EnableDefaultLighting();

            aTrans = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(aTrans);
        }
        public void Setup(Model model)
        {
            originalModel = model;
            modelBones = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(modelBones);

            SetupInstancedVertexData();
        }
Esempio n. 30
0
 public Actor(Model m, Texture2D t, Matrix lo)
 {
     model = m;
     texture = t;
     BoneTransforms = new Matrix[model.Bones.Count];
     model.CopyAbsoluteBoneTransformsTo(BoneTransforms);
     localTransforms = lo;
 }
Esempio n. 31
0
 protected override void LoadContent()
 {
     spriteBatch = new SpriteBatch(GraphicsDevice);
     terrain = Content.Load<Model>(@"houses");
     terrain_boneTransforms = new Matrix[terrain.Bones.Count];
     terrain.CopyAbsoluteBoneTransformsTo(terrain_boneTransforms);
     terrain_transform = terrain.Root.Transform * Matrix.CreateScale(0.01f); // 0.05 Campus
 }
Esempio n. 32
0
        public static GameObject ToMeshRenderers(this Model model, Scene scene)
        {
            var boneTransforms = new Matrix[model.Bones.Count];

            model.CopyAbsoluteBoneTransformsTo(boneTransforms);

            var gameObject = new GameObject("Model");

            scene.Add(gameObject);

            foreach (ModelMesh mesh in model.Meshes)
            {
                var meshPartIndex = 0;

                var parent = new GameObject(mesh.Name);
                scene.Add(parent);
                parent.Transform.Parent = gameObject.Transform;

                var        matrix = boneTransforms[mesh.ParentBone.Index];
                Vector3    position;
                Quaternion rotation;
                Vector3    scale;

                matrix.Decompose(out scale, out rotation, out position);

                parent.Transform.LocalPosition = position;
                parent.Transform.LocalRotation = rotation.ToEuler();
                parent.Transform.LocalScale    = scale;

                foreach (var part in mesh.MeshParts)
                {
                    var effect   = (BasicEffect)part.Effect;
                    var material = new StandardMaterial(scene);
                    material.MainTexture   = effect.Texture;
                    material.DiffuseColor  = new Color(effect.DiffuseColor.X, effect.DiffuseColor.Y, effect.DiffuseColor.Z);
                    material.SpecularColor = new Color(effect.SpecularColor.X, effect.SpecularColor.Y, effect.SpecularColor.Z);
                    material.Shininess     = effect.SpecularPower;
                    material.EmissiveColor = new Color(effect.EmissiveColor.X, effect.EmissiveColor.Y, effect.EmissiveColor.Z);

                    var child = new GameObject($"{mesh.Name}_{meshPartIndex}");
                    scene.Add(child);
                    var renderer = child.AddComponent <MeshRenderer>();
                    renderer.material      = material;
                    renderer.CastShadow    = true;
                    renderer.ReceiveShadow = true;

                    var geometry = new Mesh();
                    geometry.VertexBuffer = part.VertexBuffer;
                    geometry.IndexBuffer  = part.IndexBuffer;

                    renderer.Geometry = geometry;

                    child.Transform.Parent = parent.Transform;
                }
            }

            return(gameObject);
        }
Esempio n. 33
0
 public ImportModel(Model model, GraphicsDevice gd, ContentManager cm)
 {
     GraphicDevice = gd;
     Content = cm;
     Model = model;
     modeltransforms = new Matrix[Model.Bones.Count];
     Model.CopyAbsoluteBoneTransformsTo(modeltransforms);
     generateTags();
 }
Esempio n. 34
0
 public void LoadSkyBox()
 {
     ContentManager contentLoader = new ContentManager(game1Service);
     effect = new BasicEffect(this.graphics.GraphicsDevice, null);
     effect.TextureEnabled = true;
     skybox = contentLoader.Load<Model>(@"Content\Models\SkyBox\skybox2");
     boneTransforms_sky = new Matrix[skybox.Bones.Count];
     skybox.CopyAbsoluteBoneTransformsTo(boneTransforms_sky);
 }
Esempio n. 35
0
        public void LoadWorld()
        {
            ContentManager contentLoader = new ContentManager(game1Service);

            // Load model from run-time directory (debug/release)
            world = contentLoader.Load<Model>(@"Content\Models\World\houses");
            world_boneTransforms = new Matrix[world.Bones.Count];
            world.CopyAbsoluteBoneTransformsTo(world_boneTransforms);
            world_transform = world.Root.Transform * Matrix.CreateScale(0.01f); // 0.05 Campus
        }
Esempio n. 36
0
        /// <summary>
        /// Computes the bounding box for the specified xna model.
        /// </summary>
        private static bool ComputeBoundingBoxFromVertices(this Microsoft.Xna.Framework.Graphics.Model model, out BoundingBox boundingBox)
        {
            if (null == model || model.Meshes.Count <= 0)
            {
                boundingBox = new BoundingBox();
                return(false);
            }

            bool        first = true;
            BoundingBox temp  = new BoundingBox();

            Matrix[] bones = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(bones);

            foreach (var mesh in model.Meshes)
            {
                foreach (var part in mesh.MeshParts)
                {
                    if (part.VertexBuffer.BufferUsage == BufferUsage.WriteOnly)
                    {
                        boundingBox = new BoundingBox();
                        return(false);
                    }
                    if (!ComputeBoundingBoxFromVertices(model, mesh, part, bones[mesh.ParentBone.Index], out boundingBox))
                    {
                        boundingBox = new BoundingBox();
                        return(false);
                    }
                    if (first)
                    {
                        temp = boundingBox;
                    }
                    else
                    {
                        BoundingBox.CreateMerged(ref temp, ref boundingBox, out temp);
                    }

                    first = false;
                }
            }

            boundingBox = temp;
            return(true);
        }
Esempio n. 37
0
        public void CreateMeshInfo(XnaModel model)
        {
            _modelBoundingParts = new BoundingPartList();

            //Matrix[] modelBoneTransforms = new Matrix[model.Bones.Count];
            modelBoneTransforms = new Matrix[model.Bones.Count];

            model.CopyAbsoluteBoneTransformsTo(modelBoneTransforms);
            BoundingSphere[] pieces = new BoundingSphere[1];

            foreach (ModelMesh mesh in model.Meshes)
            {
                BoundingPart boundingPart =
                    new BoundingPart(mesh.BoundingSphere, pieces, modelBoneTransforms[mesh.ParentBone.Index],
                                     mesh.Name, Color.White);

                _modelBoundingParts.Add(boundingPart);
            }
        }
Esempio n. 38
0
        public IModel Load(String path, String modelAssetName)
        {
            path = (path.Equals("")) ? State.GetSettingVariable("ModelDirectory") : path;
            String   filePath = Path.Combine(path, modelAssetName);
            XNAModel xnaModel = State.Content.Load <XNAModel>(@"" + filePath);

            // Get matrix transformations of the model
            if (xnaModel != null)
            {
                Matrix[] transforms = new Matrix[xnaModel.Bones.Count];
                xnaModel.CopyAbsoluteBoneTransformsTo(transforms);

                IModel model = new Model(transforms, xnaModel.Meshes);
                return(model);
            }
            else
            {
                Log.Write("Model " + filePath + " does not exist ");
                return(null);
            }
        }
Esempio n. 39
0
        public static void AddCollision(this DynamicPrimitive dynamicPrimitive, Microsoft.Xna.Framework.Graphics.Model model, Matrix?world, Color color)
        {
            if (bones == null || bones.Length < model.Bones.Count)
            {
                bones = new Matrix[model.Bones.Count];
            }

            model.CopyAbsoluteBoneTransformsTo(bones);

            Matrix transform = world.HasValue ? world.Value : Matrix.Identity;

            ModelTag tag = model.Tag as ModelTag;

            // Add collision tree
            if (tag != null && tag.Collision != null)
            {
                transform = bones[model.Meshes[0].ParentBone.Index] * transform;
                Octree <bool> tree = tag.Collision.CollisionTree;

                tree.Traverse(node =>
                {
                    if (!node.hasChildren && node.value)
                    {
                        dynamicPrimitive.AddSolidBox(node.bounds, transform, color);
                    }
                    return(TraverseOptions.Continue);
                });
            }
            // Add collision sphere
            else
            {
                for (int i = 0; i < model.Meshes.Count; ++i)
                {
                    var mesh = model.Meshes[i];
                    dynamicPrimitive.AddSolidSphere(mesh.BoundingSphere, 18, bones[mesh.ParentBone.Index] * transform, color);
                }
            }
        }
Esempio n. 40
0
        private void Load(XnaModel model, string contentName)
        {
            _modelBoundingParts = new BoundingPartList();

            Matrix[] modelBoneTransforms = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(modelBoneTransforms);

            XmlDocument meshInfo = new XmlDocument();

            if (File.Exists(string.Format(@".\MeshInfo\{0}.xml", contentName)))
            {
                meshInfo.Load(string.Format(@".\MeshInfo\{0}.xml", contentName));
            }

            if ((!meshInfo.DocumentElement.HasAttributes) || (meshInfo.DocumentElement.Attributes["scaleModifier"] == null))
            {
                _scaleModifier = 1f;
            }
            else
            {
                _scaleModifier = float.Parse(meshInfo.DocumentElement.Attributes["scaleModifier"].Value);
            }

            int meshIndex = 0;

            foreach (ModelMesh mesh in model.Meshes)
            {
                string      xpath                 = string.Format("/MeshInfo/MeshPart[@id='{0}']", mesh.Name);
                XmlNode     meshInfoPart          = meshInfo.SelectSingleNode(xpath);
                XmlNodeList meshInfoBoundingParts = null;
                if (meshInfoPart != null)
                {
                    xpath = "BoundingParts/BoundingPart";
                    meshInfoBoundingParts = meshInfoPart.SelectNodes(xpath);
                }

                if ((meshInfoBoundingParts != null) && (meshInfoBoundingParts.Count > 0))
                {
                    BoundingSphere[] pieces = new BoundingSphere[meshInfoBoundingParts.Count];

                    int pieceIndex = 0;

                    Color boundingPartColour = new Color(byte.Parse(meshInfoPart.Attributes["color.bounds.r"].Value),
                                                         byte.Parse(meshInfoPart.Attributes["color.bounds.g"].Value),
                                                         byte.Parse(meshInfoPart.Attributes["color.bounds.b"].Value));

                    foreach (XmlNode subdivisionNode in meshInfoBoundingParts)
                    {
                        float   x0          = float.Parse(subdivisionNode.Attributes["x"].Value);
                        float   y0          = float.Parse(subdivisionNode.Attributes["y"].Value);
                        float   z0          = float.Parse(subdivisionNode.Attributes["z"].Value);
                        float   w0          = float.Parse(subdivisionNode.Attributes["w"].Value);
                        Vector4 subdivision = new Vector4(x0, y0, z0, w0);

                        //Determine the new BoundingSphere's Radius
                        float radius = subdivision.W * mesh.BoundingSphere.Radius;

                        //Determine the new BoundingSphere's Center by interpolating.
                        //The subdivision's X, Y, Z represent percentages in each axis.
                        //They will used across the full diameter of XNA's "default" BoundingSphere.
                        float x =
                            MathHelper.Lerp(mesh.BoundingSphere.Center.X - mesh.BoundingSphere.Radius,
                                            mesh.BoundingSphere.Center.X + mesh.BoundingSphere.Radius, subdivision.X);
                        float y =
                            MathHelper.Lerp(mesh.BoundingSphere.Center.Y - mesh.BoundingSphere.Radius,
                                            mesh.BoundingSphere.Center.Y + mesh.BoundingSphere.Radius, subdivision.Y);
                        float z =
                            MathHelper.Lerp(mesh.BoundingSphere.Center.Z - mesh.BoundingSphere.Radius,
                                            mesh.BoundingSphere.Center.Z + mesh.BoundingSphere.Radius, subdivision.Z);
                        Vector3 center = new Vector3(x, y, z);

                        pieces[pieceIndex] = new BoundingSphere(center, radius);

                        pieceIndex++;
                    }

                    BoundingPart boundingPart =
                        new BoundingPart(mesh.BoundingSphere, pieces, modelBoneTransforms[mesh.ParentBone.Index],
                                         mesh.Name, boundingPartColour);

                    _modelBoundingParts.Add(boundingPart);
                }
                meshIndex++;
            }
        }
Esempio n. 41
0
        public override void Draw(GameTime gameTime)
        {
            if (Content != null && Camera != null && Enabled && Visible)
            {
                // Copy any parent transforms.
                Matrix[] transforms = new Matrix[Content.Bones.Count];
                Content.CopyAbsoluteBoneTransformsTo(transforms);

                foreach (ModelMesh mesh in Content.Meshes)
                {
                    // Update our World Matrix for this Model
                    World = transforms[mesh.ParentBone.Index] *
                            Matrix.CreateRotationX(Rotation.X) *
                            Matrix.CreateRotationY(Rotation.Y) *
                            Matrix.CreateRotationZ(Rotation.Z) *
                            Matrix.CreateScale(Scale) *
                            Matrix.CreateTranslation(Position);

                    if (CustomEffect != null)
                    {
                        #region Custom HLSL Effect Rendering

                        /*********************************************************************************************************
                        *                                                                   -- Please do not f**k with this to much haha unless ya ask me (AR-50 LOCKED AND LOADED!) --
                        *********************************************************************************************************/

                        // Pass our meshes Index buffer to our graphics device
                        //GraphicsDevice.Indices = mesh.IndexBuffer;

                        // Loop thru the Custom Effect's passes
                        foreach (EffectPass pass in CustomEffect.CurrentTechnique.Passes)
                        {
                            // Begin our First pass
                            pass.Apply();

                            // Render this pass over the parts inside the mesh
                            foreach (ModelMeshPart part in mesh.MeshParts)
                            {
                                // Pass our mesh part's Vertex declaration to our graphics device
                                //GraphicsDevice.VertexDeclaration = part.VertexDeclaration;

                                // Manually pass our vertices to our graphics device
                                //GraphicsDevice.Vertices[0].SetSource(mesh.VertexBuffer, part.StreamOffset, part.VertexStride);

                                // TODO: Need to rework this .. the double casts will kill performance! *Refactor OUT*

                                // Check and see if the part has an attached texture
                                if (((BasicEffect)part.Effect).Texture != null)
                                {
                                    // If it does pass the texture our graphics device instead of manually in our shader
                                    GraphicsDevice.Textures[0] = ((BasicEffect)part.Effect).Texture;
                                }

                                // Finally Draw our Index Primitives (Triangles) for this part of our mesh
                                GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, part.NumVertices, 0, part.NumVertices,
                                                                     part.StartIndex, part.PrimitiveCount);
                            }
                        }

                        #endregion
                    }
                    else
                    {
                        #region Basic Effect Rendering Loop

                        // Setup culling / fill
                        RasterizerState rasterizerState1 = new RasterizerState();
                        rasterizerState1.CullMode      = CullMode;
                        rasterizerState1.FillMode      = FillMode;
                        GraphicsDevice.RasterizerState = rasterizerState1;

                        // Set our alpha blending states if enabled
                        if (EnableAlphaBlending)
                        {
                            GraphicsDevice.BlendState = BlendState.AlphaBlend;

                            //GraphicsDevice.RenderState.AlphaBlendEnable = true;
                            //GraphicsDevice.RenderState.AlphaTestEnable = true;

                            //GraphicsDevice.RenderState.AlphaFunction = CompareFunction.Greater;
                            //GraphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha;
                            //GraphicsDevice.RenderState.DestinationBlend = Blend.InverseSourceAlpha;
                            //GraphicsDevice.RenderState.BlendFunction = BlendFunction.Load;
                        }

                        foreach (BasicEffect effect in mesh.Effects)
                        {
                            effect.EnableDefaultLighting();

                            effect.AmbientLightColor = AmbientColor.ToVector3();
                            effect.DiffuseColor      = DiffuseColor.ToVector3();
                            effect.EmissiveColor     = EmissiveColor.ToVector3();
                            effect.SpecularColor     = SpecularColor.ToVector3();

                            effect.World      = World;
                            effect.View       = Camera.View;
                            effect.Projection = Camera.Projection;
                        }

                        mesh.Draw();

                        // Reset our alpha blending states
                        if (EnableAlphaBlending)
                        {
                            //GraphicsDevice.RenderState.AlphaBlendEnable = false;
                            //GraphicsDevice.RenderState.AlphaTestEnable = false;
                            //GraphicsDevice.RenderState.SourceBlend = Blend.Zero;
                            //GraphicsDevice.RenderState.DestinationBlend = Blend.Zero;
                        }

                        #endregion
                    }
                    base.Draw(gameTime);
                }
            }
        }
Esempio n. 42
0
        /// <summary>
        /// Create model
        /// </summary>
        /// <param name="setModelName">Set model name</param>
        public Model(string setModelName)
        {
            name = setModelName;

            xnaModel = BaseGame.Content.Load <XnaModel>(
                @"Content\Models\" + name);

            // Get matrix transformations of the model
            // Has to be done only once because we don't use animations in our game.
            if (xnaModel != null)
            {
                transforms = new Matrix[xnaModel.Bones.Count];
                xnaModel.CopyAbsoluteBoneTransformsTo(transforms);

                // Calculate scaling for this object, used for distance comparisons.
                if (xnaModel.Meshes.Count > 0)
                {
                    realScaling = scaling =
                        xnaModel.Meshes[0].BoundingSphere.Radius *
                        transforms[0].Right.Length();
                }

                // For palms, laterns, holders and column holders reduce scaling
                // to reduce the number of objects we have to render.
                if (name.ToLower() == "alphapalm" ||
                    name.ToLower() == "alphapalm2" ||
                    name.ToLower() == "alphapalm3" ||
                    name.ToLower() == "roadcolumnsegment")
                {
                    scaling *= 0.75f;
                }

                // Hotels and windmills should always be visible (they are big)
                if (name.ToLower() == "hotel01" ||
                    name.ToLower() == "hotel02" ||
                    name.ToLower() == "casino01" ||
                    name.ToLower() == "windmill")
                {
                    scaling *= 5.0f;
                }
                else
                // Don't use more than 3m for scaling and checking smaller objects
                if (scaling > 3)
                {
                    scaling = 3;
                }
            }

            hasAlpha = name.ToLower().StartsWith("alpha");
            // Is this a sign or banner? Then make sure ambient is pretty high!
            bool isSign = name.ToLower().StartsWith("sign") ||
                          name.ToLower().StartsWith("banner") ||
                          // Also include windmills, they are too dark
                          name.ToLower().StartsWith("windmill");

            //name.StartsWith("StartLight");

            isCar = (name.ToLower() == "car");

            // Go through all meshes in the model
            for (int meshNum = 0; meshNum < xnaModel.Meshes.Count; meshNum++)
            {
                ModelMesh mesh        = xnaModel.Meshes[meshNum];
                int       meshPartNum = 0;
                string    meshName    = mesh.Name;

                // Remember this mesh for animations done in Render!
                if (name.ToLower() == "windmill" &&
                    meshName.ToLower().StartsWith("windmill_wings"))
                {
                    animatedMesh = mesh;
                }

                // And for each effect this mesh uses (usually just 1, multimaterials
                // are nice in 3ds max, but not efficiently for rendering stuff).
                for (int effectNum = 0; effectNum < mesh.Effects.Count; effectNum++)
                {
                    Effect effect = mesh.Effects[effectNum];
                    // Store our 4 effect parameters
                    cachedEffectParameters.Add(effect.Parameters["diffuseTexture"]);
                    cachedEffectParameters.Add(effect.Parameters["ambientColor"]);
                    cachedEffectParameters.Add(effect.Parameters["diffuseColor"]);
                    cachedEffectParameters.Add(effect.Parameters["world"]);
                    cachedEffectParameters.Add(effect.Parameters["viewProj"]);
                    cachedEffectParameters.Add(effect.Parameters["viewInverse"]);
                    cachedEffectParameters.Add(effect.Parameters["lightDir"]);

                    // Store if this is a "ReflectionSpecular" technique
                    cachedIsReflectionSpecularTechnique.Add(
                        effect.CurrentTechnique.Name.Contains("ReflectionSpecular"));

                    // Increase ambient value to 0.5, 0.5, 0.5 for signs and banners!
                    if (isSign)
                    {
                        effect.Parameters["ambientColor"].SetValue(
                            new Color(128, 128, 128).ToVector4());
                    }

                    // Car only uses alpha on the glass
                    if (isCar && !mesh.Name.StartsWith("glass"))
                    {
                        effect.Parameters["UseAlpha"].SetValue(false);
                    }

                    // Get technique from meshName
                    int techniqueIndex = -1;
                    if (meshName.Length > meshPartNum)
                    {
                        string techniqueNumberString = meshName.Substring(
                            meshName.Length - (1 + meshPartNum), 1);
#if !XBOX360
                        // Faster and does not throw an exception!
                        int.TryParse(techniqueNumberString, out techniqueIndex);
#else
                        try
                        {
                            techniqueIndex = Convert.ToInt32(techniqueNumberString);
                        }
                        catch { }
#endif
                    }

                    // No technique found or invalid?
                    if (techniqueIndex < 0 ||
                        techniqueIndex >= effect.Techniques.Count)
                    {
                        // Try to use last technique
                        techniqueIndex = effect.Techniques.Count - 1;
                        // If this is NormalMapping, use DiffuseSpecular20 instead
                        // of the last technique (which is SpecularWithReflection20)
                        if (effect.Techniques[techniqueIndex].Name.Contains(
                                "SpecularWithReflection"))
                        {
                            techniqueIndex -= 2;
                        }
                        // Update: We have now 2 more techniques (ReflectionSpecular)
                        if (effect.Techniques[techniqueIndex].Name.Contains(
                                "ReflectionSpecular"))
                        {
                            techniqueIndex -= 4;
                        }
                    }

                    // Set current technique for rendering below
                    effect.CurrentTechnique = effect.Techniques[techniqueIndex];

                    // Next mesh part
                    meshPartNum++;
                }

                // Add all mesh parts!
                for (int partNum = 0; partNum < mesh.MeshParts.Count; partNum++)
                {
                    ModelMeshPart part = mesh.MeshParts[partNum];
                    // The model mesh part is not really used, we just extract the
                    // index and vertex buffers and all the render data.
                    // Material settings are build from the effect settings.
                    // Also add this to our own dictionary for rendering.
                    renderableMeshes.Add(part, BaseGame.MeshRenderManager.Add(
                                             part.VertexBuffer, part.IndexBuffer, part, part.Effect));
                }
            }

#if DEBUG
            // Check if there are no meshes to render
            if (xnaModel.Meshes.Count == 0)
            {
                throw new ArgumentException("Invalid model " + name +
                                            ". It does not contain any meshes");
            }
#endif
        }