public TerrainTileHeader CalculateHeaderInfo(ref Vector3[] ecefPoints) { BoundingSphere.FromPoints(ecefPoints); var hdr = new TerrainTileHeader(); hdr.CenterX = BoundingSphere.Center.X; hdr.CenterY = BoundingSphere.Center.Y; hdr.CenterZ = BoundingSphere.Center.Z; hdr.BoundingSphereRadius = BoundingSphere.Radius; return(hdr); }
public EdgeIndices16 MeshEdgeIndices16; // todo seperate out private void MakeHeader(TerrainTileHeader headerRec) { MeshHeader = new TerrainTileHeader() { CenterX = headerRec.CenterX, CenterY = headerRec.CenterY, CenterZ = headerRec.CenterZ, MinimumHeight = headerRec.MinimumHeight, MaximumHeight = headerRec.MaximumHeight, BoundingSphereCenterX = headerRec.BoundingSphereCenterX, BoundingSphereCenterY = headerRec.BoundingSphereCenterY, BoundingSphereCenterZ = headerRec.BoundingSphereCenterZ, BoundingSphereRadius = headerRec.BoundingSphereRadius, HorizonOcclusionPointX = headerRec.HorizonOcclusionPointX, HorizonOcclusionPointY = headerRec.HorizonOcclusionPointY, HorizonOcclusionPointZ = headerRec.HorizonOcclusionPointZ }; }
public TerrainTileHeader(TerrainTileHeader terrainTileHeader) { CenterX = terrainTileHeader.CenterX; CenterY = terrainTileHeader.CenterY; CenterZ = terrainTileHeader.CenterZ; MinimumHeight = terrainTileHeader.MinimumHeight; MaximumHeight = terrainTileHeader.MaximumHeight; BoundingSphereCenterX = terrainTileHeader.BoundingSphereCenterX; BoundingSphereCenterY = terrainTileHeader.BoundingSphereCenterY; BoundingSphereCenterZ = terrainTileHeader.BoundingSphereCenterZ; BoundingSphereRadius = terrainTileHeader.BoundingSphereRadius; HorizonOcclusionPointX = terrainTileHeader.HorizonOcclusionPointX; HorizonOcclusionPointY = terrainTileHeader.HorizonOcclusionPointY; HorizonOcclusionPointZ = terrainTileHeader.HorizonOcclusionPointZ; }
/// <summary> /// From the vertices passed in make quantized mesh tile /// </summary> /// <param name="vertices"></param> /// <param name="vertexNormals"></param> /// <param name="headerRec"></param> /// <param name="trianglesCount"></param> /// <param name="gridSize"></param> /// <param name="hasLighting"></param> /// <returns>Quantized Mesh Tile</returns> public byte[] MakeTile(VertexData vertices, ref byte[] vertexNormals, TerrainTileHeader headerRec, int trianglesCount, int gridSize, bool hasLighting) { // Assemble tile data _TriangleCount = trianglesCount; _GridSize = gridSize; MakeHeader(headerRec); EncodeVertices(ref vertices); MakeTriangleIndices(); MakeEdgeIndicesData(); // We are now ready to assemble the tile into a byte array var ms = new MemoryStream(); using (BinaryWriter writer = new BinaryWriter(ms)) { // write header writer.Write(MeshHeader.CenterX); writer.Write(MeshHeader.CenterY); writer.Write(MeshHeader.CenterZ); writer.Write(MeshHeader.MinimumHeight); writer.Write(MeshHeader.MaximumHeight); writer.Write(MeshHeader.BoundingSphereCenterX); writer.Write(MeshHeader.BoundingSphereCenterY); writer.Write(MeshHeader.BoundingSphereCenterZ); writer.Write(MeshHeader.BoundingSphereRadius); writer.Write(MeshHeader.HorizonOcclusionPointX); writer.Write(MeshHeader.HorizonOcclusionPointY); writer.Write(MeshHeader.HorizonOcclusionPointZ); // write vertex data in order. count, long array, lat array, height array writer.Write(MeshVertexData.vertexCount); for (int i = 0; i < MeshVertexData.vertexCount; i++) { writer.Write(MeshVertexData.u[i]); // longitude } for (int i = 0; i < MeshVertexData.vertexCount; i++) { writer.Write(MeshVertexData.v[i]); // latitude } for (int i = 0; i < MeshVertexData.vertexCount; i++) { writer.Write(MeshVertexData.height[i]); //heights } // write triangle indices writer.Write(MeshIndexData16.triangleCount); for (int i = 0; i < MeshIndexData16.triangleCount * 3; i++) // three indices to a triangle { writer.Write(MeshIndexData16.indices[i]); } // write west indices writer.Write(MeshEdgeIndices16.westVertexCount); for (int i = 0; i < MeshEdgeIndices16.westVertexCount; i++) { writer.Write(MeshEdgeIndices16.westIndices[i]); } // write south indices writer.Write(MeshEdgeIndices16.southVertexCount); for (int i = 0; i < MeshEdgeIndices16.southVertexCount; i++) { writer.Write(MeshEdgeIndices16.southIndices[i]); } // write east indices writer.Write(MeshEdgeIndices16.eastVertexCount); for (int i = 0; i < MeshEdgeIndices16.eastVertexCount; i++) { writer.Write(MeshEdgeIndices16.eastIndices[i]); } // write north indices writer.Write(MeshEdgeIndices16.northVertexCount); for (int i = 0; i < MeshEdgeIndices16.northVertexCount; i++) { writer.Write(MeshEdgeIndices16.northIndices[i]); } if (hasLighting) { // write normal map writer.Write((byte)1); writer.Write(vertexNormals.Length); for (int i = 0; i < vertexNormals.Length; i++) { writer.Write((byte)vertexNormals[i]); } } /* if we ever show animated water flow on tile. Watermask * writer.Write((byte)2); * writer.Write((int)1); * // writer.Write((byte)255); // water * writer.Write((byte)0); // land */ return(ms.ToArray()); } }