Пример #1
0
        public static ITexture SingleColorTexture(System.Drawing.Color color)
        {
            var r = new Texel.A8R8G8B8[1, 1];

            r[0, 0] = new Graphics.Software.Texel.A8R8G8B8(color);
            return(new Texture <Texel.A8R8G8B8>(r));
        }
Пример #2
0
        public void InitSplatMapValues()
        {
            var t1 = new global::Graphics.Software.Texture <global::Graphics.Software.Texel.A8R8G8B8>(SplatMap1.Resource9, 0);
            var t2 = new global::Graphics.Software.Texture <global::Graphics.Software.Texel.A8R8G8B8>(SplatMap2.Resource9, 0);

            // (r3448) These should be [Height, Width], but the rest of the code doesn't support non-square values anyway so I'm leaving them as they are
            SplatMap1Values = new Graphics.Software.Texel.A8R8G8B8[t1.Size.Width, t1.Size.Height];
            splatMap2Values = new Graphics.Software.Texel.A8R8G8B8[t2.Size.Width, t2.Size.Height];

            for (int i = 0; i < t1.Size.Width; i++)
            {
                for (int j = 0; j < t2.Size.Height; j++)
                {
                    SplatMap1Values[i, j] = t1.Data[i, j];
                    SplatMap2Values[i, j] = t2.Data[i, j];
                }
            }
        }
Пример #3
0
        public override void Init()
        {
            Content.ContentPath = "Data";

            scene        = new Scene();
            scene.View   = this;
            scene.Camera = new LookatCartesianCamera()
            {
                Position    = new Vector3(10, 10, 10),
                Lookat      = Vector3.Zero,
                ZFar        = 100,
                AspectRatio = AspectRatio
            };
            //heightmap = TextureUtil.ToHeightmap(Content.Peek<Texture>(new TextureFromFile("testheightmap.png")), 100);
            texture = new Graphics.Software.Texture <Graphics.Software.Texel.A8R8G8B8>(
                new Graphics.Software.Texel.A8R8G8B8[250, 250]);

            var r = new Random();

            for (int y = 0; y < texture.Size.Height; y++)
            {
                for (int x = 0; x < texture.Size.Width; x++)
                {
                    texture[y, x] =
                        new Graphics.Software.Texel.A8R8G8B8
                    {
                        //R = 1f,//(float)r.NextDouble(),
                        //G = (float)r.NextDouble(),
                        //B = (float)r.NextDouble(),
                        A = 1f,
                    }
                }
            }
            ;



            scene.Add(ground = new TestGround
            {
                Size = new SizeF(100, 100),
                //Texture = new SingleColorTexture(Color.Orange),
                NPieces = new Size(20, 20),
            });
            ground.ConstructPieces();

            dxTexture = texture.ToTexture9(Device9);
            UpdateTexture();

            groundTextureEditor = new Graphics.Editors.GroundTextureEditor
            {
                Camera          = scene.Camera,
                Viewport        = Viewport,
                SoftwareTexture = new ITexture[] { texture },
                Texture9        = new[] { dxTexture },
                Position        = ground.Translation,
                Size            = ground.Size,
                GroundIntersect = new WorldViewProbe(this, scene.Camera)
                {
                    WorldProbe = new GroundProbe()
                },
                Pencil = new Graphics.Editors.GroundTexturePencil
                {
                    Color  = new Vector4(1, 0, 0, 0),
                    Radius = 30,
                    Type   = Graphics.Editors.GroundTexturePencilType.Add
                }
            };
            groundTextureEditor.TextureValuesChanged += new Graphics.Editors.TextureValuesChangedEventHandler((o, e) =>
            {
                UpdateTexture();
                foreach (var v in ground.Children)
                {
                    v.Invalidate();
                }
            });
            InputHandler = new WalkaroundCameraInputHandler
            {
                Camera       = (LookatCartesianCamera)scene.Camera,
                InputHandler = groundTextureEditor
            };

            renderer = new Graphics.Renderer.Renderer(Device9)
            {
                Scene        = scene,
                StateManager = new Device9StateManager(Device9)
            };
            renderer.Initialize(this);

            sceneRendererConnector = new SortedTestSceneRendererConnector
            {
                Scene    = scene,
                Renderer = renderer
            };
            sceneRendererConnector.Initialize();
        }
Пример #4
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)
                };
            }
        }
Пример #5
0
        public override void Init()
        {
            Content.ContentPath = "Data";

            scene = new Scene();
            scene.View = this;
            scene.Camera = new LookatCartesianCamera()
            {
                Position = new Vector3(10, 10, 10),
                Lookat = Vector3.Zero,
                ZFar = 100,
                AspectRatio = AspectRatio
            };
            //heightmap = TextureUtil.ToHeightmap(Content.Peek<Texture>(new TextureFromFile("testheightmap.png")), 100);
            texture = new Graphics.Software.Texture<Graphics.Software.Texel.A8R8G8B8>(
                new Graphics.Software.Texel.A8R8G8B8[250, 250]);

            var r = new Random();
            for(int y=0; y < texture.Size.Height; y++)
                for(int x=0; x < texture.Size.Width; x++)
                    texture[y, x] =
                        new Graphics.Software.Texel.A8R8G8B8
                            {
                                //R = 1f,//(float)r.NextDouble(),
                                //G = (float)r.NextDouble(),
                                //B = (float)r.NextDouble(),
                                A = 1f,
                            };

            scene.Add(ground = new TestGround
            {
                Size = new SizeF(100, 100),
                //Texture = new SingleColorTexture(Color.Orange),
                NPieces = new Size(20, 20),
            });
            ground.ConstructPieces();

            dxTexture = texture.ToTexture9(Device9);
            UpdateTexture();

            groundTextureEditor = new Graphics.Editors.GroundTextureEditor
            {
                Camera = scene.Camera,
                Viewport = Viewport,
                SoftwareTexture = new ITexture[] { texture },
                Texture9 = new[] {dxTexture},
                Position = ground.Translation,
                Size = ground.Size,
                GroundIntersect = new WorldViewProbe(this, scene.Camera)
                {
                    WorldProbe = new GroundProbe()
                },
                Pencil = new Graphics.Editors.GroundTexturePencil
                {
                    Color = new Vector4(1, 0, 0, 0),
                    Radius = 30,
                    Type = Graphics.Editors.GroundTexturePencilType.Add
                }
            };
            groundTextureEditor.TextureValuesChanged += new Graphics.Editors.TextureValuesChangedEventHandler((o, e) =>
            {
                UpdateTexture();
                foreach (var v in ground.Children)
                    v.Invalidate();
            });
            InputHandler = new WalkaroundCameraInputHandler
            {
                Camera = (LookatCartesianCamera)scene.Camera,
                InputHandler = groundTextureEditor
            };

            renderer = new Graphics.Renderer.Renderer(Device9) { Scene = scene,
                StateManager = new Device9StateManager(Device9) };
            renderer.Initialize(this);

            sceneRendererConnector = new SortedTestSceneRendererConnector
            {
                Scene =  scene,
                Renderer = renderer
            };
            sceneRendererConnector.Initialize();
        }
Пример #6
0
        public void InitSplatMapValues()
        {
            var t1 = new global::Graphics.Software.Texture<global::Graphics.Software.Texel.A8R8G8B8>(SplatMap1.Resource9, 0);
            var t2 = new global::Graphics.Software.Texture<global::Graphics.Software.Texel.A8R8G8B8>(SplatMap2.Resource9, 0);

            // (r3448) These should be [Height, Width], but the rest of the code doesn't support non-square values anyway so I'm leaving them as they are
            SplatMap1Values = new Graphics.Software.Texel.A8R8G8B8[t1.Size.Width, t1.Size.Height];
            splatMap2Values = new Graphics.Software.Texel.A8R8G8B8[t2.Size.Width, t2.Size.Height];

            for (int i = 0; i < t1.Size.Width; i++)
            {
                for (int j = 0; j < t2.Size.Height; j++)
                {
                    SplatMap1Values[i, j] = t1.Data[i, j];
                    SplatMap2Values[i, j] = t2.Data[i, j];
                }
            }
        }