Exemplo n.º 1
0
        public override void ProduceOutput(ZContent content)
        {
            Shape shape = new Shape();

            if (Grid2DOnly)
            {
                //Create a simple 2d-grid
                shape.MakeNet(XCount, YCount);
                shape.Scale(new Vector3(2, 2, 1));
            }
            else
            {
                Shape temp = new Shape();
                temp.MakeNet(XCount, YCount);

                shape.CreateData(temp.Vertices.Length * 6,
                    (temp.Indices.Length * 6) / 3, true, false);

                int vertexOffset = 0;
                int indexOffset = 0;

                // MakeNet makes a network from -0.5 to 0.5
                // Increase to -1 .. 1, and move forward towards the camera

                //Default matrix
                Matrix4 mx = Matrix4.Scale(2, 2, 1) * Matrix4.CreateTranslation(0, 0, 1);

                //Sides
                for (int i = 0; i < 4; i++)
                {
                    Matrix4 m = mx * Matrix4.CreateRotationY(i * MathHelper.PiOver2);
                    shape.CopyMeshWithTransform(temp, m, vertexOffset, indexOffset);
                    vertexOffset += temp.Vertices.Length;
                    indexOffset += temp.Indices.Length;
                }

                //Top and bottom
                for (int i = 0; i < 2; i++)
                {
                    Matrix4 m = mx * Matrix4.CreateRotationX((-1.0f + i * 2) * MathHelper.PiOver2);
                    shape.CopyMeshWithTransform(temp, m, vertexOffset, indexOffset);
                    vertexOffset += temp.Vertices.Length;
                    indexOffset += temp.Indices.Length;
                }
            }

            shape.Scale(Scale);
            shape.ComputeNormals();

            Mesh mesh = content as Mesh;
            mesh.CreateVBO(shape);
        }
Exemplo n.º 2
0
        public override void ProduceOutput(ZContent content)
        {
            if (Heightmap == null) return;
            Heightmap.OnRefresh -= Refresh; //Avoid double subscription
            Heightmap.OnRefresh += Refresh;

            Shape shape = new Shape();

            Heightmap.Prepare();
            int w = Heightmap.Width;
            int h = Heightmap.Height;
            float[,] hm = Heightmap.data;            

            //Create a simple 2d-grid, and scale it up to [-1, 1]
            shape.MakeNet(w - 2, h - 2);
            shape.Scale(new Vector3(2, 2, 1));
            shape.ApplyHeightMap(hm, w, h);

            shape.Scale(Scale);
            shape.ComputeNormals();

            Mesh mesh = content as Mesh;
            mesh.CreateVBO(shape);
            
        }