public void Draw(Matrix world, Common.Bounding.GroundPiece bounding, Color color)
 {
     Draw(world, bounding.Bounding, color);
 }
Ejemplo n.º 2
0
        protected override void OnConstruct()
        {
            UVMin = new Vector2(
                Translation.X / Ground.Size.Width,
                Translation.Y / Ground.Size.Height);
            UVMax = new Vector2(
                (Translation.X + Size.X) / Ground.Size.Width,
                (Translation.Y + Size.Y) / Ground.Size.Height);
            base.OnConstruct();
            var ground = Ground;

            if (ground != null)
            {
                if (((MetaModel)MainGraphic).SplatTexutre == null)
                {
                    ((MetaModel)MainGraphic).SplatTexutre = new MetaResource <SlimDX.Direct3D9.Texture, SlimDX.Direct3D10.Texture2D>[]
                    {
                        ground.SplatMap1, ground.SplatMap2
                    }
                }
                ;
                if (!IsInGame)
                {
                    ((MetaModel)MainGraphic).MaterialTexture = new MetaResource <SlimDX.Direct3D9.Texture, SlimDX.Direct3D10.Texture2D>[]
                    {
                        new TextureFromFile("Models/GroundTextures/Rock1.png"),     //mud1
                        new TextureFromFile("Models/GroundTextures/Pebbles1.png"),  //mayatile1
                        new TextureFromFile("Models/GroundTextures/Sand1.png"),     //sand1
                        new TextureFromFile("Models/GroundTextures/Grass1.png"),    //grass1
                        new TextureFromFile("Models/GroundTextures/Moss1.png"),     //grass1
                        new TextureFromFile("Models/GroundTextures/Mayatile1.png"), //mayatile1
                        new TextureFromFile("Models/GroundTextures/Field1.png"),    //mud1
                        new TextureFromFile("Models/GroundTextures/Sand1.png")      //N/A
                    };
                }
                else if (((MetaModel)MainGraphic).MaterialTexture[0] == null && ((MetaModel)MainGraphic).MaterialTexture[1] == null)
                {
                    MetaResource <SlimDX.Direct3D9.Texture, SlimDX.Direct3D10.Texture2D>[] materialTexture = ((MetaModel)MainGraphic).MaterialTexture;

                    int numberOfValues1 = ground.SplatMap1Values.GetLength(0);
                    int numberOfValues2 = ground.SplatMap1Values.GetLength(1);
                    int numberOfValues3 = ground.SplatMap2Values.GetLength(0);
                    int numberOfValues4 = ground.SplatMap2Values.GetLength(1);

                    if (numberOfValues1 != numberOfValues2 || numberOfValues2 != numberOfValues3 || numberOfValues3 != numberOfValues4)
                    {
                        throw new NotImplementedException("width and hight must be equal");
                    }

                    for (int i = (int)(UVMin.X * numberOfValues1); i < UVMax.X * numberOfValues1 && UVMax.X <= 1; i++)
                    {
                        for (int j = (int)(UVMin.Y * numberOfValues1); j < UVMax.Y * numberOfValues1 && UVMax.Y <= 1; j++)
                        {
                            Graphics.Software.Texel.A8R8G8B8 g1 = ground.SplatMap1Values[j, i];
                            Graphics.Software.Texel.A8R8G8B8 g2 = ground.SplatMap2Values[j, i];

                            if (Program.Settings.RendererSettings.TerrainQuality == global::Graphics.Renderer.Settings.TerrainQualities.Low)
                            {
                                if (((MetaModel)MainGraphic).BaseTexture != null)
                                {
                                    ((MetaModel)MainGraphic).BaseTexture = null;
                                }
                                if (materialTexture[0] == null)
                                {
                                    materialTexture[0] = new TextureFromFile("Models/GroundTextures/Mud1.png");
                                }
                                if (g1.G > 0 && materialTexture[1] == null)
                                {
                                    materialTexture[1] = new TextureFromFile("Models/GroundTextures/Mayatile1.png");
                                }
                                if (g1.B > 0 && materialTexture[2] == null)
                                {
                                    materialTexture[2] = new TextureFromFile("Models/GroundTextures/Sand1.png");
                                }
                                if (g1.A > 0 && materialTexture[3] == null)
                                {
                                    materialTexture[3] = new TextureFromFile("Models/GroundTextures/Grass1.png");
                                }
                                ground.SplatMap1Values[j, i].A += g2.R;
                                ground.SplatMap1Values[j, i].G += g2.G;
                                ground.SplatMap1Values[j, i].R  = 1;
                            }
                            else
                            {
                                if (g1.R > 0 && materialTexture[0] == null)
                                {
                                    materialTexture[0] = new TextureFromFile("Models/GroundTextures/Rock1.png");
                                }
                                if (g1.G > 0 && materialTexture[1] == null)
                                {
                                    materialTexture[1] = new TextureFromFile("Models/GroundTextures/Pebbles1.png");
                                }
                                if (g1.B > 0 && materialTexture[2] == null)
                                {
                                    materialTexture[2] = new TextureFromFile("Models/GroundTextures/Sand1.png");
                                }
                                if (g1.A > 0 && materialTexture[3] == null)
                                {
                                    materialTexture[3] = new TextureFromFile("Models/GroundTextures/Grass1.png");
                                }

                                if (g2.R > 0 && materialTexture[4] == null)
                                {
                                    materialTexture[4] = new TextureFromFile("Models/GroundTextures/Moss1.png");
                                }
                                if (g2.G > 0 && materialTexture[5] == null)
                                {
                                    materialTexture[5] = new TextureFromFile("Models/GroundTextures/Mayatile1.png");
                                }
                                if (g2.B > 0 && materialTexture[6] == null)
                                {
                                    materialTexture[6] = new TextureFromFile("Models/GroundTextures/Field1.png");
                                }
                                if (g2.A > 0 && materialTexture[7] == null)
                                {
                                    materialTexture[7] = new TextureFromFile("Models/GroundTextures/Sand2.png");
                                }
                            }
                        }
                    }
                }
                PickingLocalBounding         = null;
                GroundIntersectLocalBounding = CreateBoundingMeshFromModel((MetaModel)MainGraphic);

                // This forces the ground physics mesh to be another one than the visual mesh
                // so that the physics doesn't need to intersect with the same mesh the renderer uses, in turn
                // meaning we don't need the device MultiThread mode.
                MetaModel m = (MetaModel)((MetaModel)MainGraphic).Clone();
                ((Graphics.Software.Meshes.MeshFromHeightmap2)((MeshConcretize)m.XMesh).MeshDescription).Height
                    += 0.0001f;
                //((MeshConcretize)m.XMesh).XMeshFlags = SlimDX.Direct3D9.MeshFlags.Software;
                PhysicsLocalBounding = new Common.Bounding.GroundPiece
                {
                    Bounding = CreatePhysicsMeshBounding(m)
                };
            }
        }
Ejemplo n.º 3
0
        protected override void OnConstruct()
        {
            UVMin = new Vector2(
                Translation.X / Ground.Size.Width,
                Translation.Y / Ground.Size.Height);
            UVMax = new Vector2(
                (Translation.X + Size.X) / Ground.Size.Width,
                (Translation.Y + Size.Y) / Ground.Size.Height);
            base.OnConstruct();
            var ground = Ground;
            if (ground != null)
            {
                if(((MetaModel)MainGraphic).SplatTexutre == null)
                    ((MetaModel)MainGraphic).SplatTexutre = new MetaResource<SlimDX.Direct3D9.Texture, SlimDX.Direct3D10.Texture2D>[]
                    {
                        ground.SplatMap1, ground.SplatMap2
                    };
                if (!IsInGame)
                {
                    ((MetaModel)MainGraphic).MaterialTexture = new MetaResource<SlimDX.Direct3D9.Texture,SlimDX.Direct3D10.Texture2D>[]
                    {
                        new TextureFromFile("Models/GroundTextures/Rock1.png"), //mud1
                        new TextureFromFile("Models/GroundTextures/Pebbles1.png"), //mayatile1
                        new TextureFromFile("Models/GroundTextures/Sand1.png"), //sand1
                        new TextureFromFile("Models/GroundTextures/Grass1.png"), //grass1
                        new TextureFromFile("Models/GroundTextures/Moss1.png"), //grass1
                        new TextureFromFile("Models/GroundTextures/Mayatile1.png"), //mayatile1
                        new TextureFromFile("Models/GroundTextures/Field1.png"), //mud1
                        new TextureFromFile("Models/GroundTextures/Sand1.png") //N/A
                    };
                }
                else if(((MetaModel)MainGraphic).MaterialTexture[0] == null && ((MetaModel)MainGraphic).MaterialTexture[1] == null)
                {
                    MetaResource<SlimDX.Direct3D9.Texture, SlimDX.Direct3D10.Texture2D>[] materialTexture = ((MetaModel)MainGraphic).MaterialTexture;

                    int numberOfValues1 = ground.SplatMap1Values.GetLength(0);
                    int numberOfValues2 = ground.SplatMap1Values.GetLength(1);
                    int numberOfValues3 = ground.SplatMap2Values.GetLength(0);
                    int numberOfValues4 = ground.SplatMap2Values.GetLength(1);

                    if (numberOfValues1 != numberOfValues2 || numberOfValues2 != numberOfValues3 || numberOfValues3 != numberOfValues4)
                        throw new NotImplementedException("width and hight must be equal");

                    for (int i = (int)(UVMin.X * numberOfValues1); i < UVMax.X * numberOfValues1 && UVMax.X <= 1; i++)
                    {
                        for (int j = (int)(UVMin.Y * numberOfValues1); j < UVMax.Y * numberOfValues1 && UVMax.Y <= 1; j++)
                        {
                            Graphics.Software.Texel.A8R8G8B8 g1 = ground.SplatMap1Values[j, i];
                            Graphics.Software.Texel.A8R8G8B8 g2 = ground.SplatMap2Values[j, i];

                            if (Program.Settings.RendererSettings.TerrainQuality == global::Graphics.Renderer.Settings.TerrainQualities.Low)
                            {
                                if (((MetaModel)MainGraphic).BaseTexture != null)
                                    ((MetaModel)MainGraphic).BaseTexture = null;
                                if (materialTexture[0] == null)
                                    materialTexture[0] = new TextureFromFile("Models/GroundTextures/Mud1.png");
                                if (g1.G > 0 && materialTexture[1] == null)
                                    materialTexture[1] = new TextureFromFile("Models/GroundTextures/Mayatile1.png");
                                if (g1.B > 0 && materialTexture[2] == null)
                                    materialTexture[2] = new TextureFromFile("Models/GroundTextures/Sand1.png");
                                if (g1.A > 0 && materialTexture[3] == null)
                                    materialTexture[3] = new TextureFromFile("Models/GroundTextures/Grass1.png");
                                ground.SplatMap1Values[j, i].A += g2.R;
                                ground.SplatMap1Values[j, i].G += g2.G;
                                ground.SplatMap1Values[j, i].R = 1;
                            }
                            else
                            {

                                if (g1.R > 0 && materialTexture[0] == null)
                                    materialTexture[0] = new TextureFromFile("Models/GroundTextures/Rock1.png");
                                if (g1.G > 0 && materialTexture[1] == null)
                                    materialTexture[1] = new TextureFromFile("Models/GroundTextures/Pebbles1.png");
                                if (g1.B > 0 && materialTexture[2] == null)
                                    materialTexture[2] = new TextureFromFile("Models/GroundTextures/Sand1.png");
                                if (g1.A > 0 && materialTexture[3] == null)
                                    materialTexture[3] = new TextureFromFile("Models/GroundTextures/Grass1.png");

                                if (g2.R > 0 && materialTexture[4] == null)
                                    materialTexture[4] = new TextureFromFile("Models/GroundTextures/Moss1.png");
                                if (g2.G > 0 && materialTexture[5] == null)
                                    materialTexture[5] = new TextureFromFile("Models/GroundTextures/Mayatile1.png");
                                if (g2.B > 0 && materialTexture[6] == null)
                                    materialTexture[6] = new TextureFromFile("Models/GroundTextures/Field1.png");
                                if (g2.A > 0 && materialTexture[7] == null)
                                    materialTexture[7] = new TextureFromFile("Models/GroundTextures/Sand2.png");
                            }
                        }
                    }
                }
                PickingLocalBounding = null;
                GroundIntersectLocalBounding = CreateBoundingMeshFromModel((MetaModel)MainGraphic);

                // This forces the ground physics mesh to be another one than the visual mesh
                // so that the physics doesn't need to intersect with the same mesh the renderer uses, in turn
                // meaning we don't need the device MultiThread mode.
                MetaModel m = (MetaModel)((MetaModel)MainGraphic).Clone();
                ((Graphics.Software.Meshes.MeshFromHeightmap2)((MeshConcretize)m.XMesh).MeshDescription).Height
                    += 0.0001f;
                //((MeshConcretize)m.XMesh).XMeshFlags = SlimDX.Direct3D9.MeshFlags.Software;
                PhysicsLocalBounding = new Common.Bounding.GroundPiece
                {
                    Bounding = CreatePhysicsMeshBounding(m)
                };
            }
        }