示例#1
0
        public DeviceBuffer GetIndexBuffer(
            int width,
            int height,
            out ushort[] indices)
        {
            var size = new TerrainPatchSize
            {
                Width  = width,
                Height = height
            };

            if (!_cachedIndexBuffers.TryGetValue(size, out var result))
            {
                _cachedIndexBuffers[size] = result = new CacheEntry
                {
                    Buffer  = AddDisposable(CreateIndexBuffer(size, out indices)),
                    Indices = indices
                };
            }
            else
            {
                indices = result.Indices;
            }
            return(result.Buffer);
        }
示例#2
0
        private DeviceBuffer CreateIndexBuffer(
            TerrainPatchSize size,
            out ushort[] indices)
        {
            // TODO: Could use triangle strip

            var numIndices = CalculateNumIndices(size.Width, size.Height);

            indices = new ushort[numIndices];

            for (int y = 0, indexIndex = 0; y < size.Height - 1; y++)
            {
                var yThis = y * size.Width;
                var yNext = (y + 1) * size.Width;

                for (var x = 0; x < size.Width - 1; x++)
                {
                    // Triangle 1
                    indices[indexIndex++] = (ushort)(yThis + x);
                    indices[indexIndex++] = (ushort)(yThis + x + 1);
                    indices[indexIndex++] = (ushort)(yNext + x);

                    // Triangle 2
                    indices[indexIndex++] = (ushort)(yNext + x);
                    indices[indexIndex++] = (ushort)(yThis + x + 1);
                    indices[indexIndex++] = (ushort)(yNext + x + 1);
                }
            }

            return(_graphicsDevice.CreateStaticBuffer(indices, BufferUsage.IndexBuffer));
        }
示例#3
0
 public TerrainSceneNode AddTerrainSceneNodeFromRawData(float[,] data, int width, SceneNode parent, int id, Vector3D position, Vector3D rotation, Vector3D scale, Color vertexColor, int maxLOD, TerrainPatchSize patchSize, int smoothFactor)
 {
     IntPtr par = IntPtr.Zero;
     if (parent != null)
         par = parent.Raw;
     return (TerrainSceneNode)
         NativeElement.GetObject(SceneManager_AddTerrainSceneNodeFromRawData(_raw, data, data.Length, width, par, id, position.ToUnmanaged(), rotation.ToUnmanaged(), scale.ToUnmanaged(), vertexColor.ToUnmanaged(), maxLOD, patchSize, smoothFactor),
                                 typeof(TerrainSceneNode));
 }
示例#4
0
 /// <summary>
 /// Adds a heightmap-based terrain on the scene
 /// </summary>
 /// <returns>The terrain node</returns>
 /// <param name="heightMap">Relative or non-relative path to the heightmap.</param>
 /// <param name="parent">Parent from the terrain</param>
 /// <param name="id">ID (-1 for automatic assign.)</param>
 /// <param name="position">Position of the node</param>
 /// <param name="rotation">Rotation of the node</param>
 /// <param name="scale">Scale of the node</param>
 /// <param name="vertexColor">Default color of all the vertices used if no texture is assigned to the node.</param>
 /// <param name="maxLOD">Maximal LOD, set 5 or change it ONLY IF YOU KNOW WHAT YOU ARE DOING</param>
 /// <param name="patchSize">PatchSize, should be 17 and you mustn't change it unless you know what you're doing</param>
 public TerrainSceneNode AddTerrainSceneNode(string heightMap, SceneNode parent, int id, Vector3D position, Vector3D rotation, Vector3D scale, Color vertexColor, int maxLOD, TerrainPatchSize patchSize, int smoothFactor)
 {
     IntPtr par = IntPtr.Zero;
     if(parent != null)
         par = parent.Raw;
     return (TerrainSceneNode)
         NativeElement.GetObject(SceneManager_AddTerrainSceneNode(_raw, heightMap, par, id, position.ToUnmanaged(), rotation.ToUnmanaged(), scale.ToUnmanaged(), vertexColor.ToUnmanaged(), maxLOD, patchSize, smoothFactor),
                                 typeof(TerrainSceneNode));
 }
示例#5
0
 static extern IntPtr SceneManager_AddTerrainSceneNodeFromRawData(IntPtr scenemanager, [MarshalAs(UnmanagedType.LPArray,SizeParamIndex=2)] float[,] data, int size, int width, IntPtr parent, int id, float[] position, float[] rotation, float[] scale, int[] vertexColor, int maxLOD, TerrainPatchSize patchSize, int smoothFactor);
示例#6
0
 static extern IntPtr SceneManager_AddTerrainSceneNode(IntPtr scenemanager, string TreeXML, IntPtr parent, int id, float[] position, float[] rotation, float[] scale, int[] vertexColor, int maxLOD, TerrainPatchSize patchSize, int smoothFactor);
示例#7
0
 static extern IntPtr SceneManager_AddTerrainSceneNode(IntPtr scenemanager, string heightMap, IntPtr parent, int id, float[] position, float[] rotation, float[] scale, int[] vertexColor,int maxLOD, TerrainPatchSize patchSize);