protected virtual bool ReadTriangleList(BinaryReader reader, ref TRLTriangleList triangleList) { triangleList.polygonCount = (UInt32)reader.ReadUInt16() / 3; triangleList.groupID = reader.ReadUInt16(); // Used by MON_SetAccessories and INSTANCE_UnhideAllDrawGroups triangleList.polygonStart = (UInt32)(reader.BaseStream.Position) + 0x10; UInt16 xWord0 = reader.ReadUInt16(); UInt16 xWord1 = reader.ReadUInt16(); UInt32 xDWord0 = reader.ReadUInt32(); UInt32 xDWord1 = reader.ReadUInt32(); triangleList.material = new Material(); triangleList.material.visible = true; // ((xWord1 & 0xFF00) == 0); triangleList.material.textureID = (UInt16)(xWord0 & 0x1FFF); triangleList.material.colour = 0xFFFFFFFF; if (triangleList.material.textureID > 0) { triangleList.material.textureUsed = true; } else { triangleList.material.textureUsed = false; //xMaterial.colour = 0x00000000; } triangleList.next = reader.ReadUInt32(); if (triangleList.polygonCount == 0) { triangleList.next = 0; } return(triangleList.material.visible); }
protected override void ReadPolygons(BinaryReader reader, CDC.Objects.ExportOptions options) { if (_materialStart == 0) { return; } List <TRLTriangleList> triangleListList = new List <TRLTriangleList>(); UInt32 materialPosition = _materialStart; _groupCount = 0; while (materialPosition != 0) { reader.BaseStream.Position = materialPosition; TRLTriangleList triangleList = new TRLTriangleList(); bool isVisible = (ReadTriangleList(reader, ref triangleList) /*&& triangleList.m_usGroupID == 0*/); if (isVisible) { triangleListList.Add(triangleList); _polygonCount += triangleList.polygonCount; if ((UInt32)triangleList.groupID > _groupCount) { _groupCount = triangleList.groupID; } } _materialsList.Add(triangleList.material); materialPosition = triangleList.next; } _materialCount = (UInt32)_materialsList.Count; _groupCount++; _trees = new Tree[_groupCount]; for (UInt32 t = 0; t < _groupCount; t++) { _trees[t] = new Tree(); _trees[t].mesh = new Mesh(); foreach (TRLTriangleList triangleList in triangleListList) { if (t == (UInt32)triangleList.groupID) { _trees[t].mesh.polygonCount += triangleList.polygonCount; } } _trees[t].mesh.indexCount = _trees[t].mesh.polygonCount * 3; _trees[t].mesh.polygons = new Polygon[_trees[t].mesh.polygonCount]; _trees[t].mesh.vertices = new Vertex[_trees[t].mesh.indexCount]; } for (UInt32 t = 0; t < _groupCount; t++) { UInt32 tp = 0; foreach (TRLTriangleList triangleList in triangleListList) { if (t != (UInt32)triangleList.groupID) { continue; } reader.BaseStream.Position = triangleList.polygonStart; for (int pl = 0; pl < triangleList.polygonCount; pl++) { _trees[t].mesh.polygons[tp].v1 = _geometry.Vertices[reader.ReadUInt16()]; _trees[t].mesh.polygons[tp].v2 = _geometry.Vertices[reader.ReadUInt16()]; _trees[t].mesh.polygons[tp].v3 = _geometry.Vertices[reader.ReadUInt16()]; _trees[t].mesh.polygons[tp].material = triangleList.material; tp++; } } for (UInt16 poly = 0; poly < _trees[t].mesh.polygonCount; poly++) { _trees[t].mesh.vertices[(3 * poly) + 0] = _trees[t].mesh.polygons[poly].v1; _trees[t].mesh.vertices[(3 * poly) + 1] = _trees[t].mesh.polygons[poly].v2; _trees[t].mesh.vertices[(3 * poly) + 2] = _trees[t].mesh.polygons[poly].v3; } } _polygons = new Polygon[_polygonCount]; UInt32 p = 0; foreach (TRLTriangleList triangleList in triangleListList) { reader.BaseStream.Position = triangleList.polygonStart; for (int pl = 0; pl < triangleList.polygonCount; pl++) { _polygons[p].v1 = _geometry.Vertices[reader.ReadUInt16()]; _polygons[p].v2 = _geometry.Vertices[reader.ReadUInt16()]; _polygons[p].v3 = _geometry.Vertices[reader.ReadUInt16()]; _polygons[p].material = triangleList.material; p++; } } }