示例#1
0
        private SimpleMesh <PositionNormalTexture> GenerateHeightMapMesh(float[,] heightData, DXDevice dxDevice)
        {
            PositionNormalTexture[] vertexBuffer;
            int[] indexBuffer;

            int xCount = heightData.GetUpperBound(0) + 1;
            int yCount = heightData.GetUpperBound(1) + 2;

            CreateHeightVertexAndIndexBuffer(heightData,
                                             centerPosition: new Vector3(0, 0, 0),
                                             size: new Vector3(1000, MaxHeightMapHeight, 1000.0f * (float)yCount / (float)xCount),
                                             vertexBuffer: out vertexBuffer,
                                             indexBuffer: out indexBuffer);

            var heightMapMesh = new SimpleMesh <PositionNormalTexture>(vertexBuffer,
                                                                       indexBuffer,
                                                                       inputLayoutType: InputLayoutType.Position | InputLayoutType.Normal | InputLayoutType.TextureCoordinate,
                                                                       name: "HeightSimpleMesh");

            // If DXDevice is already initialized, then we can also initialize (create DirectX resources) for the SimpleMesh.
            // This will create the DirectX resources and send them to the GPU
            if (dxDevice != null)
            {
                heightMapMesh.InitializeResources(dxDevice);
            }

            return(heightMapMesh);
        }