Example #1
0
        public void Draw()
        {
            Matrix WorldMatrix = Matrix.CreateTranslation((-m_TerrainWidth) / 2.0f, 0, (m_TerrainHeight) / 2.0f);

            m_Effect.CurrentTechnique = m_Effect.Techniques["Textured"];
            m_Effect.Parameters["Blend"].SetValue(m_VertexColor);
            m_Effect.Parameters["TerrainType"].SetValue(m_TerrainType);
            m_Effect.Parameters["Grass"].SetValue(m_Grass);
            m_Effect.Parameters["Rock"].SetValue(m_Rock);
            m_Effect.Parameters["Sand"].SetValue(m_Sand);
            m_Effect.Parameters["Snow"].SetValue(m_Snow);
            m_Effect.Parameters["Water"].SetValue(m_Water);
            m_Effect.Parameters["xView"].SetValue(m_CController.View);
            m_Effect.Parameters["xProjection"].SetValue(m_CController.Projection);
            m_Effect.Parameters["xWorld"].SetValue(WorldMatrix);

            RasterizerState RS = new RasterizerState();

            RS.CullMode = CullMode.None;
            //RS.FillMode = FillMode.WireFrame;
            m_Device.RasterizerState = RS;

            m_Device.Clear(Color.CornflowerBlue);

            foreach (EffectPass Pass in m_Effect.CurrentTechnique.Passes)
            {
                Pass.Apply();

                m_Device.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, m_Vertices, 0, m_Vertices.Length,
                                                   m_Indices, 0, m_Indices.Length / 3, CityVertex.VertexElements);
                //DrawQuadtree(m_QuadTreeRoot);
            }
        }
Example #2
0
 public void Apply()
 {
     foreach (EffectPass Pass in Raw.CurrentTechnique.Passes)
     {
         Pass.Apply();
     }
 }
Example #3
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(GameTime gameTime)
        {
            BaseEffect.Projection = ProjectionMatrix;
            BaseEffect.View       = ViewMatrix;
            BaseEffect.World      = WorldMatrix;
            GraphicsDevice.Clear(Color.HotPink);
            GraphicsDevice.SetVertexBuffer(VertexBuff);

            //turn off culling so we see both sides of our triangles
            RasterizerState RasterState = new RasterizerState();

            RasterState.CullMode           = CullMode.None;
            GraphicsDevice.RasterizerState = RasterState;
            foreach (EffectPass Pass in BaseEffect.CurrentTechnique.Passes)
            {
                Pass.Apply();
                GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, 3);
            }



            // TODO: Add your drawing code here

            base.Draw(gameTime);
        }
Example #4
0
        protected override void Draw(GameTime time)
        {
            var dt = (float)time.ElapsedGameTime.TotalSeconds;

            UpdateShader();
            UpdateUniforms(dt);
            SetUniforms(Shader);
            GraphicsDevice.Clear(Color.SteelBlue);
            GraphicsDevice.SamplerStates[0] = new SamplerState()
            {
                AddressU = TextureAddressMode.Wrap,
                AddressV = TextureAddressMode.Wrap,
                AddressW = TextureAddressMode.Wrap,
                Filter   = TextureFilter.Point
            };
            GraphicsDevice.RasterizerState = RasterizerState.CullNone;
            GraphicsDevice.SetVertexBuffer(VertexBuffer);
            GraphicsDevice.Indices = IndexBuffer;
            if (Shader != null)
            {
                foreach (var Technique in Shader.Techniques)
                {
                    foreach (var Pass in Technique.Passes)
                    {
                        Pass.Apply();
                        GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 2);
                    }
                }
            }
        }
Example #5
0
 public void Execute(Action <ISubset> drawAction, ISubset ipmxSubset)
 {
     if (string.IsNullOrWhiteSpace(ScriptRuntime.ScriptCode))
     {
         Pass.Apply(context.DeviceManager.Context);
         drawAction(ipmxSubset);
     }
     else//スクリプトが存在する場合は処理をスクリプトランタイムに任せる
     {
         ScriptRuntime.Execute(drawAction, ipmxSubset);
     }
 }
Example #6
0
        public override void Draw()
        {
            Material.Projection = Level.Active3DCamera.ProjectionMatrix;
            Material.View       = Level.Active3DCamera.ViewMatrix;
            Material.World      = LinkedObject.WorldMatrix;

            Game.graphics.GraphicsDevice.SetVertexBuffer(Buffer);

            DrawSettings = new RasterizerState();
            Game.graphics.GraphicsDevice.RasterizerState = DrawSettings;

            foreach (EffectPass Pass in Material.CurrentTechnique.Passes)
            {
                Pass.Apply();
                Game.graphics.GraphicsDevice.DrawPrimitives(Microsoft.Xna.Framework.Graphics.PrimitiveType.TriangleList, 0, Verts.Count);
            }
        }
        protected override void DrawSelf(SpriteBatch spriteBatch)
        {
            if (Texture == null)
            {
                return;
            }

            PreDraw?.Invoke();

            CalculatedStyle dimensions = base.GetDimensions();
            Rectangle?      nullable   = null;

            spriteBatch.End();
            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, PointSample ? SamplerState.PointClamp : SamplerState.AnisotropicClamp, DepthStencilState.None, _overflowRaster, null, Main.UIScaleMatrix);

            if (Pass != null)
            {
                Pass.Apply();
            }
            spriteBatch.Draw(this.Texture, dimensions.ToRectangle(), nullable, Color.White, 0f, Vector2.Zero, SpriteEffects.None, 0f);

            spriteBatch.End();
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.AnisotropicClamp, DepthStencilState.None, _overflowRaster, null, Main.UIScaleMatrix);
        }
Example #8
0
        /// <summary>
        /// Renders the different meshes making up this avatar.
        /// </summary>
        /// <param name="ViewMatrix">A view matrix.</param>
        /// <param name="WorldMatrix">A world matrix.</param>
        /// <param name="ProjectionMatrix">A projection matrix.</param>
        public void Render(Matrix ViewMatrix, Matrix WorldMatrix, Matrix ProjectionMatrix)
        {
            //This sets DepthBufferEnable and DepthBufferWriteEnable.
            m_Devc.DepthStencilState = DepthStencilState.Default;
            m_Devc.BlendState        = BlendState.AlphaBlend;
            m_Devc.RasterizerState   = RasterizerState.CullNone;

            if (m_GPURender == false)
            {
                // Configure effects
                m_HeadEffect.World      = WorldMatrix;
                m_HeadEffect.View       = ViewMatrix;
                m_HeadEffect.Projection = ProjectionMatrix;
                m_HeadEffect.EnableDefaultLighting();

                if (HeadTexture != null)
                {
                    m_HeadEffect.Texture        = HeadTexture;
                    m_HeadEffect.TextureEnabled = true;
                }

                m_AccessoryEffect.World      = WorldMatrix;
                m_AccessoryEffect.View       = ViewMatrix;
                m_AccessoryEffect.Projection = ProjectionMatrix;
                m_AccessoryEffect.EnableDefaultLighting();

                if (AccessoryTexture != null)
                {
                    m_AccessoryEffect.Texture        = AccessoryTexture;
                    m_AccessoryEffect.TextureEnabled = true;
                }

                m_LeftHandEffect.World      = WorldMatrix;
                m_LeftHandEffect.View       = ViewMatrix;
                m_LeftHandEffect.Projection = ProjectionMatrix;
                m_LeftHandEffect.EnableDefaultLighting();

                if (LeftHandTexture != null)
                {
                    m_LeftHandEffect.Texture        = LeftHandTexture;
                    m_LeftHandEffect.TextureEnabled = true;
                }

                m_RightHandEffect.World      = WorldMatrix;
                m_RightHandEffect.View       = ViewMatrix;
                m_RightHandEffect.Projection = ProjectionMatrix;
                m_RightHandEffect.EnableDefaultLighting();

                if (RightHandTexture != null)
                {
                    m_RightHandEffect.Texture        = RightHandTexture;
                    m_RightHandEffect.TextureEnabled = true;
                }

                m_BodyEffect.World      = WorldMatrix;
                m_BodyEffect.View       = ViewMatrix;
                m_BodyEffect.Projection = ProjectionMatrix;
                m_BodyEffect.EnableDefaultLighting();

                if (BodyTexture != null)
                {
                    m_BodyEffect.Texture        = BodyTexture;
                    m_BodyEffect.TextureEnabled = true;
                }
            }
            else
            {
                m_VitaboyShader.Parameters["View"].SetValue(ViewMatrix);
                m_VitaboyShader.Parameters["Projection"].SetValue(ProjectionMatrix);
            }

            if (HeadMesh != null)
            {
                if (m_GPURender == false)
                {
                    foreach (EffectPass Pass in m_HeadEffect.CurrentTechnique.Passes)
                    {
                        Pass.Apply();

                        foreach (Vector3 Fce in HeadMesh.Faces)
                        {
                            // Draw
                            VertexPositionNormalTexture[] Vertex = new VertexPositionNormalTexture[3];
                            Vertex[0].Position = HeadMesh.TransformedVertices[(int)Fce.X].Position;
                            Vertex[1].Position = HeadMesh.TransformedVertices[(int)Fce.Y].Position;
                            Vertex[2].Position = HeadMesh.TransformedVertices[(int)Fce.Z].Position;

                            Vertex[0].TextureCoordinate = HeadMesh.TransformedVertices[(int)Fce.X].TextureCoordinate;
                            Vertex[1].TextureCoordinate = HeadMesh.TransformedVertices[(int)Fce.Y].TextureCoordinate;
                            Vertex[2].TextureCoordinate = HeadMesh.TransformedVertices[(int)Fce.Z].TextureCoordinate;

                            Vertex[0].Normal = HeadMesh.TransformedVertices[(int)Fce.X].Normal;
                            Vertex[1].Normal = HeadMesh.TransformedVertices[(int)Fce.Y].Normal;
                            Vertex[2].Normal = HeadMesh.TransformedVertices[(int)Fce.Z].Normal;

                            m_Devc.DrawUserPrimitives(PrimitiveType.TriangleList, Vertex, 0, 1);
                        }

                        TransformVertices(HeadMesh, null, MeshType.Head);
                    }
                }
                else
                {
                    m_VitaboyShader.Parameters["VitaboyTexture"].SetValue(HeadTexture);
                    m_VitaboyShader.Parameters["World"].SetValue(WorldMatrix);
                    m_VitaboyShader.Parameters["ChildBones"].SetValue(GetAllBones(HeadMesh, Skel));

                    //foreach (EffectPass Pass in m_VitaboyShader.Techniques["TransformHeadTechnique"].Passes)
                    foreach (EffectPass Pass in m_VitaboyShader.Techniques["TransformVerticesTechnique"].Passes)
                    {
                        Pass.Apply();

                        foreach (Vector3 Fce in HeadMesh.Faces)
                        {
                            VitaboyVertex[] Vertex = new VitaboyVertex[3];
                            Vertex[0].Position = HeadMesh.RealVertices[(int)Fce.X].Position;
                            Vertex[1].Position = HeadMesh.RealVertices[(int)Fce.Y].Position;
                            Vertex[2].Position = HeadMesh.RealVertices[(int)Fce.Z].Position;

                            Vertex[0].TextureCoordinate = HeadMesh.RealVertices[(int)Fce.X].TextureCoordinate;
                            Vertex[1].TextureCoordinate = HeadMesh.RealVertices[(int)Fce.Y].TextureCoordinate;
                            Vertex[2].TextureCoordinate = HeadMesh.RealVertices[(int)Fce.Z].TextureCoordinate;

                            Vertex[0].Normal = HeadMesh.RealVertices[(int)Fce.X].Normal;
                            Vertex[1].Normal = HeadMesh.RealVertices[(int)Fce.Y].Normal;
                            Vertex[2].Normal = HeadMesh.RealVertices[(int)Fce.Z].Normal;

                            //All the meshes except the body mesh only references one bone.
                            Vertex[0].BoneBinding = 0;
                            Vertex[1].BoneBinding = 0;
                            Vertex[2].BoneBinding = 0;

                            m_Devc.DrawUserPrimitives(PrimitiveType.TriangleList, Vertex, 0, 1);
                        }
                    }
                }
            }

            if (AccessoryMesh != null)
            {
                if (m_GPURender == false)
                {
                    foreach (EffectPass Pass in m_AccessoryEffect.CurrentTechnique.Passes)
                    {
                        Pass.Apply();

                        foreach (Vector3 Fce in AccessoryMesh.Faces)
                        {
                            // Draw
                            VertexPositionNormalTexture[] Vertex = new VertexPositionNormalTexture[3];
                            Vertex[0].Position = AccessoryMesh.TransformedVertices[(int)Fce.X].Position;
                            Vertex[1].Position = AccessoryMesh.TransformedVertices[(int)Fce.Y].Position;
                            Vertex[2].Position = AccessoryMesh.TransformedVertices[(int)Fce.Z].Position;

                            Vertex[0].TextureCoordinate = AccessoryMesh.TransformedVertices[(int)Fce.X].TextureCoordinate;
                            Vertex[1].TextureCoordinate = AccessoryMesh.TransformedVertices[(int)Fce.Y].TextureCoordinate;
                            Vertex[2].TextureCoordinate = AccessoryMesh.TransformedVertices[(int)Fce.Z].TextureCoordinate;

                            Vertex[0].Normal = AccessoryMesh.TransformedVertices[(int)Fce.X].Normal;
                            Vertex[1].Normal = AccessoryMesh.TransformedVertices[(int)Fce.Y].Normal;
                            Vertex[2].Normal = AccessoryMesh.TransformedVertices[(int)Fce.Z].Normal;

                            m_Devc.DrawUserPrimitives(PrimitiveType.TriangleList, Vertex, 0, 1);
                        }

                        TransformVertices(AccessoryMesh, null, MeshType.Head);
                    }
                }
                else
                {
                    m_VitaboyShader.Parameters["VitaboyTexture"].SetValue(AccessoryTexture);
                    m_VitaboyShader.Parameters["World"].SetValue(WorldMatrix);
                    m_VitaboyShader.Parameters["ChildBones"].SetValue(GetAllBones(HeadMesh, Skel));

                    foreach (EffectPass Pass in m_VitaboyShader.Techniques["TransformVerticesTechnique"].Passes)
                    {
                        Pass.Apply();

                        foreach (Vector3 Fce in AccessoryMesh.Faces)
                        {
                            VitaboyVertex[] Vertex = new VitaboyVertex[3];
                            Vertex[0].Position = AccessoryMesh.RealVertices[(int)Fce.X].Position;
                            Vertex[1].Position = AccessoryMesh.RealVertices[(int)Fce.Y].Position;
                            Vertex[2].Position = AccessoryMesh.RealVertices[(int)Fce.Z].Position;

                            Vertex[0].TextureCoordinate = AccessoryMesh.RealVertices[(int)Fce.X].TextureCoordinate;
                            Vertex[1].TextureCoordinate = AccessoryMesh.RealVertices[(int)Fce.Y].TextureCoordinate;
                            Vertex[2].TextureCoordinate = AccessoryMesh.RealVertices[(int)Fce.Z].TextureCoordinate;

                            Vertex[0].Normal = AccessoryMesh.RealVertices[(int)Fce.X].Normal;
                            Vertex[1].Normal = AccessoryMesh.RealVertices[(int)Fce.Y].Normal;
                            Vertex[2].Normal = AccessoryMesh.RealVertices[(int)Fce.Z].Normal;

                            Vertex[0].BoneBinding = 0;
                            Vertex[1].BoneBinding = 0;
                            Vertex[2].BoneBinding = 0;

                            m_Devc.DrawUserPrimitives(PrimitiveType.TriangleList, Vertex, 0, 1);
                        }
                    }
                }
            }

            if (BodyMesh != null)
            {
                if (m_GPURender == false)
                {
                    foreach (EffectPass Pass in m_BodyEffect.CurrentTechnique.Passes)
                    {
                        Pass.Apply();

                        foreach (Vector3 Fce in BodyMesh.Faces)
                        {
                            // Draw
                            VertexPositionNormalTexture[] Vertex = new VertexPositionNormalTexture[3];
                            Vertex[0].Position = BodyMesh.TransformedVertices[(int)Fce.X].Position;
                            Vertex[1].Position = BodyMesh.TransformedVertices[(int)Fce.Y].Position;
                            Vertex[2].Position = BodyMesh.TransformedVertices[(int)Fce.Z].Position;

                            Vertex[0].TextureCoordinate = BodyMesh.TransformedVertices[(int)Fce.X].TextureCoordinate;
                            Vertex[1].TextureCoordinate = BodyMesh.TransformedVertices[(int)Fce.Y].TextureCoordinate;
                            Vertex[2].TextureCoordinate = BodyMesh.TransformedVertices[(int)Fce.Z].TextureCoordinate;

                            Vertex[0].Normal = BodyMesh.TransformedVertices[(int)Fce.X].Normal;
                            Vertex[1].Normal = BodyMesh.TransformedVertices[(int)Fce.Y].Normal;
                            Vertex[2].Normal = BodyMesh.TransformedVertices[(int)Fce.Z].Normal;

                            m_Devc.DrawUserPrimitives(PrimitiveType.TriangleList, Vertex, 0, 1);
                        }

                        TransformVertices(BodyMesh, Skel.Bones[Skel.FindBone("PELVIS")], MeshType.Body);
                    }
                }
                else
                {
                    CopyBodyVertices(Skel.Bones[Skel.FindBone("PELVIS")]);

                    m_VitaboyShader.Parameters["VitaboyTexture"].SetValue(BodyTexture);
                    m_VitaboyShader.Parameters["World"].SetValue(WorldMatrix);
                    m_VitaboyShader.Parameters["ChildBones"].SetValue(GetAllBones(BodyMesh, Skel));

                    foreach (EffectPass Pass in m_VitaboyShader.Techniques["TransformVerticesTechnique"].Passes)
                    {
                        foreach (Vector3 Fce in BodyMesh.Faces)
                        {
                            Pass.Apply();

                            // Draw
                            VitaboyVertex[] Vertex = new VitaboyVertex[3];

                            Vertex[0].Position = BodyMesh.TransformedVertices[(int)Fce.X].Position;
                            Vertex[1].Position = BodyMesh.TransformedVertices[(int)Fce.Y].Position;
                            Vertex[2].Position = BodyMesh.TransformedVertices[(int)Fce.Z].Position;

                            Vertex[0].TextureCoordinate = BodyMesh.TransformedVertices[(int)Fce.X].TextureCoordinate;
                            Vertex[1].TextureCoordinate = BodyMesh.TransformedVertices[(int)Fce.Y].TextureCoordinate;
                            Vertex[2].TextureCoordinate = BodyMesh.TransformedVertices[(int)Fce.Z].TextureCoordinate;

                            Vertex[0].Normal = BodyMesh.TransformedVertices[(int)Fce.X].Normal;
                            Vertex[1].Normal = BodyMesh.TransformedVertices[(int)Fce.Y].Normal;
                            Vertex[2].Normal = BodyMesh.TransformedVertices[(int)Fce.Z].Normal;

                            Vertex[0].BoneBinding = BodyMesh.TransformedVertices[(int)Fce.X].BoneBinding;
                            Vertex[1].BoneBinding = BodyMesh.TransformedVertices[(int)Fce.Y].BoneBinding;
                            Vertex[2].BoneBinding = BodyMesh.TransformedVertices[(int)Fce.Z].BoneBinding;

                            m_Devc.DrawUserPrimitives(PrimitiveType.TriangleList, Vertex, 0, 1);
                        }
                    }
                }
            }

            if (LeftHandMesh != null)
            {
                if (m_GPURender == false)
                {
                    foreach (EffectPass Pass in m_LeftHandEffect.CurrentTechnique.Passes)
                    {
                        Pass.Apply();

                        foreach (Vector3 Fce in LeftHandMesh.Faces)
                        {
                            // Draw
                            VertexPositionNormalTexture[] Vertex = new VertexPositionNormalTexture[3];
                            Vertex[0].Position = LeftHandMesh.TransformedVertices[(int)Fce.X].Position;
                            Vertex[1].Position = LeftHandMesh.TransformedVertices[(int)Fce.Y].Position;
                            Vertex[2].Position = LeftHandMesh.TransformedVertices[(int)Fce.Z].Position;

                            m_Devc.DrawUserPrimitives(PrimitiveType.TriangleList, Vertex, 0, 1);
                        }

                        TransformVertices(LeftHandMesh, null, MeshType.LHand);
                    }
                }
                else
                {
                    m_VitaboyShader.Parameters["VitaboyTexture"].SetValue(LeftHandTexture);
                    m_VitaboyShader.Parameters["World"].SetValue(WorldMatrix);
                    m_VitaboyShader.Parameters["ChildBones"].SetValue(GetAllBones(LeftHandMesh, Skel));

                    foreach (EffectPass Pass in m_VitaboyShader.Techniques["TransformVerticesTechnique"].Passes)
                    {
                        Pass.Apply();

                        foreach (Vector3 Fce in LeftHandMesh.Faces)
                        {
                            VitaboyVertex[] Vertex = new VitaboyVertex[3];
                            Vertex[0].Position = LeftHandMesh.RealVertices[(int)Fce.X].Position;
                            Vertex[1].Position = LeftHandMesh.RealVertices[(int)Fce.Y].Position;
                            Vertex[2].Position = LeftHandMesh.RealVertices[(int)Fce.Z].Position;

                            Vertex[0].TextureCoordinate = LeftHandMesh.RealVertices[(int)Fce.X].TextureCoordinate;
                            Vertex[1].TextureCoordinate = LeftHandMesh.RealVertices[(int)Fce.Y].TextureCoordinate;
                            Vertex[2].TextureCoordinate = LeftHandMesh.RealVertices[(int)Fce.Z].TextureCoordinate;

                            Vertex[0].Normal = LeftHandMesh.RealVertices[(int)Fce.X].Normal;
                            Vertex[1].Normal = LeftHandMesh.RealVertices[(int)Fce.Y].Normal;
                            Vertex[2].Normal = LeftHandMesh.RealVertices[(int)Fce.Z].Normal;

                            //All the meshes except the body mesh only references one bone.
                            Vertex[0].BoneBinding = 0;
                            Vertex[1].BoneBinding = 0;
                            Vertex[2].BoneBinding = 0;

                            m_Devc.DrawUserPrimitives(PrimitiveType.TriangleList, Vertex, 0, 1);
                        }
                    }
                }
            }

            if (RightHandMesh != null)
            {
                if (m_GPURender == false)
                {
                    foreach (EffectPass Pass in m_RightHandEffect.CurrentTechnique.Passes)
                    {
                        Pass.Apply();

                        foreach (Vector3 Fce in RightHandMesh.Faces)
                        {
                            // Draw
                            VertexPositionNormalTexture[] Vertex = new VertexPositionNormalTexture[3];
                            Vertex[0].Position = RightHandMesh.TransformedVertices[(int)Fce.X].Position;
                            Vertex[1].Position = RightHandMesh.TransformedVertices[(int)Fce.Y].Position;
                            Vertex[2].Position = RightHandMesh.TransformedVertices[(int)Fce.Z].Position;

                            m_Devc.DrawUserPrimitives(PrimitiveType.TriangleList, Vertex, 0, 1);
                        }

                        TransformVertices(RightHandMesh, null, MeshType.RHand);
                    }
                }
                else
                {
                    m_VitaboyShader.Parameters["VitaboyTexture"].SetValue(RightHandTexture);
                    m_VitaboyShader.Parameters["World"].SetValue(WorldMatrix);
                    m_VitaboyShader.Parameters["ChildBones"].SetValue(GetAllBones(RightHandMesh, Skel));

                    foreach (EffectPass Pass in m_VitaboyShader.Techniques["TransformVerticesTechnique"].Passes)
                    {
                        Pass.Apply();

                        foreach (Vector3 Fce in RightHandMesh.Faces)
                        {
                            VitaboyVertex[] Vertex = new VitaboyVertex[3];
                            Vertex[0].Position = RightHandMesh.RealVertices[(int)Fce.X].Position;
                            Vertex[1].Position = RightHandMesh.RealVertices[(int)Fce.Y].Position;
                            Vertex[2].Position = RightHandMesh.RealVertices[(int)Fce.Z].Position;

                            Vertex[0].TextureCoordinate = RightHandMesh.RealVertices[(int)Fce.X].TextureCoordinate;
                            Vertex[1].TextureCoordinate = RightHandMesh.RealVertices[(int)Fce.Y].TextureCoordinate;
                            Vertex[2].TextureCoordinate = RightHandMesh.RealVertices[(int)Fce.Z].TextureCoordinate;

                            Vertex[0].Normal = RightHandMesh.RealVertices[(int)Fce.X].Normal;
                            Vertex[1].Normal = RightHandMesh.RealVertices[(int)Fce.Y].Normal;
                            Vertex[2].Normal = RightHandMesh.RealVertices[(int)Fce.Z].Normal;

                            //All the meshes except the body mesh only references one bone.
                            Vertex[0].BoneBinding = 0;
                            Vertex[1].BoneBinding = 0;
                            Vertex[2].BoneBinding = 0;

                            m_Devc.DrawUserPrimitives(PrimitiveType.TriangleList, Vertex, 0, 1);
                        }
                    }
                }
            }
        }
Example #9
0
        /// <summary>
        /// Renders the different meshes making up this avatar.
        /// </summary>
        /// <param name="ViewMatrix">A view matrix.</param>
        /// <param name="WorldMatrix">A world matrix.</param>
        /// <param name="ProjectionMatrix">A projection matrix.</param>
        public void Render(Matrix ViewMatrix, Matrix WorldMatrix, Matrix ProjectionMatrix)
        {
            //This sets DepthBufferEnable and DepthBufferWriteEnable.
            m_Devc.DepthStencilState = DepthStencilState.Default;
            m_Devc.BlendState        = BlendState.AlphaBlend;
            m_Devc.RasterizerState   = RasterizerState.CullNone;

            if (m_GPURender == false)
            {
                // Configure effects
                m_HeadEffect.World      = WorldMatrix;
                m_HeadEffect.View       = ViewMatrix;
                m_HeadEffect.Projection = ProjectionMatrix;
                m_HeadEffect.EnableDefaultLighting();
            }
            else
            {
                m_VitaboyShader.Parameters["View"].SetValue(ViewMatrix);
                m_VitaboyShader.Parameters["Projection"].SetValue(ProjectionMatrix);
            }

            if (HeadTexture != null)
            {
                if (m_GPURender == false)
                {
                    m_HeadEffect.Texture        = HeadTexture;
                    m_HeadEffect.TextureEnabled = true;
                }
                else
                {
                    m_VitaboyShader.Parameters["HeadTexture"].SetValue(HeadTexture);
                }
            }

            if (m_GPURender == false)
            {
                m_AccessoryEffect.World      = WorldMatrix;
                m_AccessoryEffect.View       = ViewMatrix;
                m_AccessoryEffect.Projection = ProjectionMatrix;
                m_AccessoryEffect.EnableDefaultLighting();
            }

            if (AccessoryTexture != null)
            {
                if (m_GPURender == false)
                {
                    m_AccessoryEffect.Texture        = AccessoryTexture;
                    m_AccessoryEffect.TextureEnabled = true;
                }
                else
                {
                    m_VitaboyShader.Parameters["AccessoryTexture"].SetValue(AccessoryTexture);
                }
            }

            m_BodyEffect.World      = WorldMatrix;
            m_BodyEffect.View       = ViewMatrix;
            m_BodyEffect.Projection = ProjectionMatrix;
            m_BodyEffect.EnableDefaultLighting();

            if (m_BodyEffect != null)
            {
                m_BodyEffect.Texture        = BodyTexture;
                m_BodyEffect.TextureEnabled = true;
            }

            // Configure effects
            m_LeftHandEffect.World      = WorldMatrix;
            m_LeftHandEffect.View       = ViewMatrix;
            m_LeftHandEffect.Projection = ProjectionMatrix;
            m_LeftHandEffect.EnableDefaultLighting();

            if (LeftHandTexture != null)
            {
                if (m_GPURender == false)
                {
                    m_LeftHandEffect.Texture        = LeftHandTexture;
                    m_LeftHandEffect.TextureEnabled = true;
                }
                else
                {
                    m_VitaboyShader.Parameters["LeftHandTexture"].SetValue(LeftHandTexture);
                }
            }

            if (RightHandTexture != null)
            {
                if (m_GPURender)
                {
                    m_VitaboyShader.Parameters["RightHandTexture"].SetValue(RightHandTexture);
                }
            }

            if (HeadMesh != null)
            {
                if (m_GPURender == false)
                {
                    foreach (EffectPass Pass in m_HeadEffect.CurrentTechnique.Passes)
                    {
                        Pass.Apply();

                        foreach (Vector3 Fce in HeadMesh.Faces)
                        {
                            // Draw
                            VertexPositionNormalTexture[] Vertex = new VertexPositionNormalTexture[3];
                            Vertex[0] = HeadMesh.TransformedVertices[(int)Fce.X];
                            Vertex[1] = HeadMesh.TransformedVertices[(int)Fce.Y];
                            Vertex[2] = HeadMesh.TransformedVertices[(int)Fce.Z];

                            Vertex[0].TextureCoordinate = HeadMesh.TransformedVertices[(int)Fce.X].TextureCoordinate;
                            Vertex[1].TextureCoordinate = HeadMesh.TransformedVertices[(int)Fce.Y].TextureCoordinate;
                            Vertex[2].TextureCoordinate = HeadMesh.TransformedVertices[(int)Fce.Z].TextureCoordinate;

                            Vertex[0].Normal = HeadMesh.TransformedVertices[(int)Fce.X].Normal;
                            Vertex[1].Normal = HeadMesh.TransformedVertices[(int)Fce.Y].Normal;
                            Vertex[2].Normal = HeadMesh.TransformedVertices[(int)Fce.Z].Normal;

                            m_Devc.DrawUserPrimitives(PrimitiveType.TriangleList, Vertex, 0, 1);
                        }

                        TransformVertices(HeadMesh, null, MeshType.Head);
                    }
                }
                else
                {
                    m_VitaboyShader.Parameters["World"].SetValue(WorldMatrix * Skel.Bones[Skel.FindBone("HEAD")].AbsoluteMatrix);

                    foreach (EffectPass Pass in m_VitaboyShader.Techniques["TransformHeadTechnique"].Passes)
                    {
                        Pass.Apply();

                        foreach (Vector3 Fce in HeadMesh.Faces)
                        {
                            VertexPositionNormalTexture[] Vertex = new VertexPositionNormalTexture[3];
                            Vertex[0] = HeadMesh.RealVertices[(int)Fce.X];
                            Vertex[1] = HeadMesh.RealVertices[(int)Fce.Y];
                            Vertex[2] = HeadMesh.RealVertices[(int)Fce.Z];

                            Vertex[0].TextureCoordinate = HeadMesh.RealVertices[(int)Fce.X].TextureCoordinate;
                            Vertex[1].TextureCoordinate = HeadMesh.RealVertices[(int)Fce.Y].TextureCoordinate;
                            Vertex[2].TextureCoordinate = HeadMesh.RealVertices[(int)Fce.Z].TextureCoordinate;

                            Vertex[0].Normal = HeadMesh.RealVertices[(int)Fce.X].Normal;
                            Vertex[1].Normal = HeadMesh.RealVertices[(int)Fce.Y].Normal;
                            Vertex[2].Normal = HeadMesh.RealVertices[(int)Fce.Z].Normal;

                            m_Devc.DrawUserPrimitives(PrimitiveType.TriangleList, Vertex, 0, 1);
                        }
                    }
                }
            }

            if (AccessoryMesh != null)
            {
                if (m_GPURender == false)
                {
                    foreach (EffectPass Pass in m_AccessoryEffect.CurrentTechnique.Passes)
                    {
                        Pass.Apply();

                        foreach (Vector3 Fce in AccessoryMesh.Faces)
                        {
                            // Draw
                            VertexPositionNormalTexture[] Vertex = new VertexPositionNormalTexture[3];
                            Vertex[0] = AccessoryMesh.TransformedVertices[(int)Fce.X];
                            Vertex[1] = AccessoryMesh.TransformedVertices[(int)Fce.Y];
                            Vertex[2] = AccessoryMesh.TransformedVertices[(int)Fce.Z];

                            Vertex[0].TextureCoordinate = AccessoryMesh.TransformedVertices[(int)Fce.X].TextureCoordinate;
                            Vertex[1].TextureCoordinate = AccessoryMesh.TransformedVertices[(int)Fce.Y].TextureCoordinate;
                            Vertex[2].TextureCoordinate = AccessoryMesh.TransformedVertices[(int)Fce.Z].TextureCoordinate;

                            Vertex[0].Normal = AccessoryMesh.TransformedVertices[(int)Fce.X].Normal;
                            Vertex[1].Normal = AccessoryMesh.TransformedVertices[(int)Fce.Y].Normal;
                            Vertex[2].Normal = AccessoryMesh.TransformedVertices[(int)Fce.Z].Normal;

                            m_Devc.DrawUserPrimitives(PrimitiveType.TriangleList, Vertex, 0, 1);
                        }

                        TransformVertices(AccessoryMesh, null, MeshType.Head);
                    }
                }
                else
                {
                    m_VitaboyShader.Parameters["World"].SetValue(WorldMatrix * Skel.Bones[Skel.FindBone("HEAD")].AbsoluteMatrix);

                    foreach (EffectPass Pass in m_VitaboyShader.Techniques["TransformAccessoryTechnique"].Passes)
                    {
                        Pass.Apply();

                        foreach (Vector3 Fce in AccessoryMesh.Faces)
                        {
                            VertexPositionNormalTexture[] Vertex = new VertexPositionNormalTexture[3];
                            Vertex[0] = AccessoryMesh.RealVertices[(int)Fce.X];
                            Vertex[1] = AccessoryMesh.RealVertices[(int)Fce.Y];
                            Vertex[2] = AccessoryMesh.RealVertices[(int)Fce.Z];

                            Vertex[0].TextureCoordinate = AccessoryMesh.RealVertices[(int)Fce.X].TextureCoordinate;
                            Vertex[1].TextureCoordinate = AccessoryMesh.RealVertices[(int)Fce.Y].TextureCoordinate;
                            Vertex[2].TextureCoordinate = AccessoryMesh.RealVertices[(int)Fce.Z].TextureCoordinate;

                            Vertex[0].Normal = AccessoryMesh.RealVertices[(int)Fce.X].Normal;
                            Vertex[1].Normal = AccessoryMesh.RealVertices[(int)Fce.Y].Normal;
                            Vertex[2].Normal = AccessoryMesh.RealVertices[(int)Fce.Z].Normal;

                            m_Devc.DrawUserPrimitives(PrimitiveType.TriangleList, Vertex, 0, 1);
                        }
                    }
                }
            }

            if (BodyMesh != null)
            {
                foreach (EffectPass Pass in m_BodyEffect.CurrentTechnique.Passes)
                {
                    Pass.Apply();

                    foreach (Vector3 Fce in BodyMesh.Faces)
                    {
                        // Draw
                        VertexPositionNormalTexture[] Vertex = new VertexPositionNormalTexture[3];
                        Vertex[0] = BodyMesh.TransformedVertices[(int)Fce.X];
                        Vertex[1] = BodyMesh.TransformedVertices[(int)Fce.Y];
                        Vertex[2] = BodyMesh.TransformedVertices[(int)Fce.Z];

                        Vertex[0].TextureCoordinate = BodyMesh.TransformedVertices[(int)Fce.X].TextureCoordinate;
                        Vertex[1].TextureCoordinate = BodyMesh.TransformedVertices[(int)Fce.Y].TextureCoordinate;
                        Vertex[2].TextureCoordinate = BodyMesh.TransformedVertices[(int)Fce.Z].TextureCoordinate;

                        Vertex[0].Normal = BodyMesh.TransformedVertices[(int)Fce.X].Normal;
                        Vertex[1].Normal = BodyMesh.TransformedVertices[(int)Fce.Y].Normal;
                        Vertex[2].Normal = BodyMesh.TransformedVertices[(int)Fce.Z].Normal;

                        m_Devc.DrawUserPrimitives(PrimitiveType.TriangleList, Vertex, 0, 1);
                    }

                    TransformVertices(BodyMesh, Skel.Bones[Skel.FindBone("PELVIS")], MeshType.Body);
                }
            }

            if (LeftHandMesh != null)
            {
                if (m_GPURender == false)
                {
                    foreach (EffectPass Pass in m_LeftHandEffect.CurrentTechnique.Passes)
                    {
                        Pass.Apply();

                        foreach (Vector3 Fce in LeftHandMesh.Faces)
                        {
                            // Draw
                            VertexPositionNormalTexture[] Vertex = new VertexPositionNormalTexture[3];
                            Vertex[0] = LeftHandMesh.TransformedVertices[(int)Fce.X];
                            Vertex[1] = LeftHandMesh.TransformedVertices[(int)Fce.Y];
                            Vertex[2] = LeftHandMesh.TransformedVertices[(int)Fce.Z];

                            m_Devc.DrawUserPrimitives(PrimitiveType.TriangleList, Vertex, 0, 1);
                        }

                        TransformVertices(LeftHandMesh, null, MeshType.LHand);
                    }
                }
                else
                {
                    m_VitaboyShader.Parameters["World"].SetValue(WorldMatrix * Skel.Bones[Skel.FindBone("L_HAND")].AbsoluteMatrix);

                    foreach (EffectPass Pass in m_VitaboyShader.Techniques["TransformLeftHandTechnique"].Passes)
                    {
                        Pass.Apply();

                        foreach (Vector3 Fce in LeftHandMesh.Faces)
                        {
                            VertexPositionNormalTexture[] Vertex = new VertexPositionNormalTexture[3];
                            Vertex[0] = LeftHandMesh.RealVertices[(int)Fce.X];
                            Vertex[1] = LeftHandMesh.RealVertices[(int)Fce.Y];
                            Vertex[2] = LeftHandMesh.RealVertices[(int)Fce.Z];

                            Vertex[0].TextureCoordinate = LeftHandMesh.RealVertices[(int)Fce.X].TextureCoordinate;
                            Vertex[1].TextureCoordinate = LeftHandMesh.RealVertices[(int)Fce.Y].TextureCoordinate;
                            Vertex[2].TextureCoordinate = LeftHandMesh.RealVertices[(int)Fce.Z].TextureCoordinate;

                            Vertex[0].Normal = LeftHandMesh.RealVertices[(int)Fce.X].Normal;
                            Vertex[1].Normal = LeftHandMesh.RealVertices[(int)Fce.Y].Normal;
                            Vertex[2].Normal = LeftHandMesh.RealVertices[(int)Fce.Z].Normal;

                            m_Devc.DrawUserPrimitives(PrimitiveType.TriangleList, Vertex, 0, 1);
                        }
                    }
                }
            }

            if (RightHandMesh != null)
            {
                if (m_GPURender == false)
                {
                    foreach (EffectPass Pass in m_LeftHandEffect.CurrentTechnique.Passes)
                    {
                        Pass.Apply();

                        foreach (Vector3 Fce in RightHandMesh.Faces)
                        {
                            // Draw
                            VertexPositionNormalTexture[] Vertex = new VertexPositionNormalTexture[3];
                            Vertex[0] = RightHandMesh.TransformedVertices[(int)Fce.X];
                            Vertex[1] = RightHandMesh.TransformedVertices[(int)Fce.Y];
                            Vertex[2] = RightHandMesh.TransformedVertices[(int)Fce.Z];

                            m_Devc.DrawUserPrimitives(PrimitiveType.TriangleList, Vertex, 0, 1);
                        }

                        TransformVertices(RightHandMesh, null, MeshType.RHand);
                    }
                }
                else
                {
                    m_VitaboyShader.Parameters["World"].SetValue(WorldMatrix * Skel.Bones[Skel.FindBone("R_HAND")].AbsoluteMatrix);

                    foreach (EffectPass Pass in m_VitaboyShader.Techniques["TransformRightHandTechnique"].Passes)
                    {
                        Pass.Apply();

                        foreach (Vector3 Fce in RightHandMesh.Faces)
                        {
                            VertexPositionNormalTexture[] Vertex = new VertexPositionNormalTexture[3];
                            Vertex[0] = RightHandMesh.RealVertices[(int)Fce.X];
                            Vertex[1] = RightHandMesh.RealVertices[(int)Fce.Y];
                            Vertex[2] = RightHandMesh.RealVertices[(int)Fce.Z];

                            Vertex[0].TextureCoordinate = RightHandMesh.RealVertices[(int)Fce.X].TextureCoordinate;
                            Vertex[1].TextureCoordinate = RightHandMesh.RealVertices[(int)Fce.Y].TextureCoordinate;
                            Vertex[2].TextureCoordinate = RightHandMesh.RealVertices[(int)Fce.Z].TextureCoordinate;

                            Vertex[0].Normal = RightHandMesh.RealVertices[(int)Fce.X].Normal;
                            Vertex[1].Normal = RightHandMesh.RealVertices[(int)Fce.Y].Normal;
                            Vertex[2].Normal = RightHandMesh.RealVertices[(int)Fce.Z].Normal;

                            m_Devc.DrawUserPrimitives(PrimitiveType.TriangleList, Vertex, 0, 1);
                        }
                    }
                }
            }
        }