public MapGeometryVertexElementGroup(MapGeometryVertex vertex) { this.Usage = MapGeometryVertexElementGroupUsage.Static; if (vertex.Position != null) { this.VertexElements.Add(new MapGeometryVertexElement(MapGeometryVertexElementName.Position, MapGeometryVertexElementFormat.XYZ_Float32)); } if (vertex.Normal != null) { this.VertexElements.Add(new MapGeometryVertexElement(MapGeometryVertexElementName.Normal, MapGeometryVertexElementFormat.XYZ_Float32)); } if (vertex.DiffuseUV != null) { this.VertexElements.Add(new MapGeometryVertexElement(MapGeometryVertexElementName.DiffuseUV, MapGeometryVertexElementFormat.XY_Float32)); } if (vertex.LightmapUV != null) { this.VertexElements.Add(new MapGeometryVertexElement(MapGeometryVertexElementName.LightmapUV, MapGeometryVertexElementFormat.XY_Float32)); } if (vertex.SecondaryColor != null) { this.VertexElements.Add(new MapGeometryVertexElement(MapGeometryVertexElementName.SecondaryColor, MapGeometryVertexElementFormat.BGRA_Packed8888)); } }
public static MapGeometryVertex Combine(MapGeometryVertex a, MapGeometryVertex b) { return(new MapGeometryVertex() { Position = (a.Position == null && b.Position != null) ? b.Position : a.Position, Normal = (a.Normal == null && b.Normal != null) ? b.Normal : a.Normal, DiffuseUV = (a.DiffuseUV == null && b.DiffuseUV != null) ? b.DiffuseUV : a.DiffuseUV, LightmapUV = (a.LightmapUV == null && b.LightmapUV != null) ? b.LightmapUV : a.LightmapUV, SecondaryColor = (a.SecondaryColor == null && b.SecondaryColor != null) ? b.SecondaryColor : a.SecondaryColor }); }
private static VERTEX CreateVertex(MapGeometryVertex vertex) { VERTEX gltfVertex = new VERTEX(); Vector3 position = vertex.Position.Value; Vector3 normal = vertex.Normal.HasValue ? vertex.Normal.Value : Vector3.Zero; Color color1 = vertex.SecondaryColor.HasValue ? vertex.SecondaryColor.Value : new Color(0, 0, 0, 1); Vector2 uv1 = vertex.DiffuseUV.HasValue ? vertex.DiffuseUV.Value : Vector2.Zero; Vector2 uv2 = vertex.LightmapUV.HasValue ? vertex.LightmapUV.Value : Vector2.Zero; return(gltfVertex .WithGeometry(position, normal) .WithMaterial(color1, uv1, uv2)); }
public MapGeometryModel(BinaryReader br, List <MapGeometryVertexElementGroup> vertexElementGroups, List <long> vertexBufferOffsets, List <ushort[]> indexBuffers, bool useSeparatePointLights, uint version) { this.Name = Encoding.ASCII.GetString(br.ReadBytes(br.ReadInt32())); uint vertexCount = br.ReadUInt32(); uint vertexBufferCount = br.ReadUInt32(); int vertexElementGroup = br.ReadInt32(); for (int i = 0; i < vertexCount; i++) { this.Vertices.Add(new MapGeometryVertex()); } for (int i = 0, currentVertexElementGroup = vertexElementGroup; i < vertexBufferCount; i++, currentVertexElementGroup++) { int vertexBufferID = br.ReadInt32(); long returnPosition = br.BaseStream.Position; br.BaseStream.Seek(vertexBufferOffsets[vertexBufferID], SeekOrigin.Begin); for (int j = 0; j < vertexCount; j++) { this.Vertices[j] = MapGeometryVertex.Combine(this.Vertices[j], new MapGeometryVertex(br, vertexElementGroups[currentVertexElementGroup].VertexElements)); } br.BaseStream.Seek(returnPosition, SeekOrigin.Begin); } uint indexCount = br.ReadUInt32(); int indexBuffer = br.ReadInt32(); this.Indices.AddRange(indexBuffers[indexBuffer]); uint submeshCount = br.ReadUInt32(); for (int i = 0; i < submeshCount; i++) { this.Submeshes.Add(new MapGeometrySubmesh(br, this)); } if (version != 5) { this.FlipNormals = br.ReadBoolean(); } this.BoundingBox = new R3DBox(br); this.Transformation = new R3DMatrix44(br); this.Flags = (MapGeometryModelFlags)br.ReadByte(); if (version >= 7) { this.Layer = (MapGeometryLayer)br.ReadByte(); if (version >= 11) { this.UnknownByte = br.ReadByte(); } } if (useSeparatePointLights && (version < 7)) { this.SeparatePointLight = new Vector3(br); } if (version < 9) { for (int i = 0; i < 9; i++) { this.UnknownFloats.Add(new Vector3(br)); } this.Lightmap = Encoding.ASCII.GetString(br.ReadBytes(br.ReadInt32())); this.Color = br.ReadColor(ColorFormat.RgbaF32); } else if (version >= 9) { this.Lightmap = Encoding.ASCII.GetString(br.ReadBytes(br.ReadInt32())); this.Color = br.ReadColor(ColorFormat.RgbaF32); this.BakedPaintTexture = Encoding.ASCII.GetString(br.ReadBytes(br.ReadInt32())); this.BakedPaintColor = br.ReadColor(ColorFormat.RgbaF32); } }