protected virtual bool ReadTriangleList(BinaryReader xReader, ref DefianceTriangleList xTriangleList) { xTriangleList.m_uPolygonCount = (UInt32)xReader.ReadUInt16() / 3; xTriangleList.m_usGroupID = xReader.ReadUInt16(); // Used by MON_SetAccessories and INSTANCE_UnhideAllDrawGroups xTriangleList.m_uPolygonStart = (UInt32)(xReader.BaseStream.Position) + 0x10; UInt16 xWord0 = xReader.ReadUInt16(); UInt16 xWord1 = xReader.ReadUInt16(); UInt32 xDWord0 = xReader.ReadUInt32(); UInt32 xDWord1 = xReader.ReadUInt32(); xTriangleList.m_xMaterial = new Material(); xTriangleList.m_xMaterial.visible = ((xWord1 & 0xFF00) == 0); xTriangleList.m_xMaterial.textureID = (UInt16)(xWord0 & 0x0FFF); xTriangleList.m_xMaterial.colour = 0xFFFFFFFF; if (xTriangleList.m_xMaterial.textureID > 0) { xTriangleList.m_xMaterial.textureUsed = true; } else { xTriangleList.m_xMaterial.textureUsed = false; //xMaterial.colour = 0x00000000; } xTriangleList.m_uNext = xReader.ReadUInt32(); if (xTriangleList.m_uPolygonCount == 0) { xTriangleList.m_uNext = 0; } return(xTriangleList.m_xMaterial.visible); }
protected override void ReadPolygons(BinaryReader xReader, CDC.Objects.ExportOptions options) { if (_materialStart == 0) { return; } List <DefianceTriangleList> xTriangleListList = new List <DefianceTriangleList>(); UInt32 uMaterialPosition = _materialStart; _groupCount = 0; while (uMaterialPosition != 0) { xReader.BaseStream.Position = uMaterialPosition; DefianceTriangleList xTriangleList = new DefianceTriangleList(); if (ReadTriangleList(xReader, ref xTriangleList) /* && xTriangleList.m_usGroupID == 0*/) { xTriangleListList.Add(xTriangleList); _polygonCount += xTriangleList.m_uPolygonCount; if ((UInt32)xTriangleList.m_usGroupID > _groupCount) { _groupCount = xTriangleList.m_usGroupID; } } _materialsList.Add(xTriangleList.m_xMaterial); uMaterialPosition = xTriangleList.m_uNext; } _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 (DefianceTriangleList xTriangleList in xTriangleListList) { if (t == (UInt32)xTriangleList.m_usGroupID) { _trees[t].mesh.polygonCount += xTriangleList.m_uPolygonCount; } } _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 (DefianceTriangleList xTriangleList in xTriangleListList) { if (t != (UInt32)xTriangleList.m_usGroupID) { continue; } xReader.BaseStream.Position = xTriangleList.m_uPolygonStart; for (int pl = 0; pl < xTriangleList.m_uPolygonCount; pl++) { _trees[t].mesh.polygons[tp].v1 = _geometry.Vertices[xReader.ReadUInt16()]; _trees[t].mesh.polygons[tp].v2 = _geometry.Vertices[xReader.ReadUInt16()]; _trees[t].mesh.polygons[tp].v3 = _geometry.Vertices[xReader.ReadUInt16()]; _trees[t].mesh.polygons[tp].material = xTriangleList.m_xMaterial; 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 (DefianceTriangleList xTriangleList in xTriangleListList) { xReader.BaseStream.Position = xTriangleList.m_uPolygonStart; for (int pl = 0; pl < xTriangleList.m_uPolygonCount; pl++) { _polygons[p].v1 = _geometry.Vertices[xReader.ReadUInt16()]; _polygons[p].v2 = _geometry.Vertices[xReader.ReadUInt16()]; _polygons[p].v3 = _geometry.Vertices[xReader.ReadUInt16()]; _polygons[p].material = xTriangleList.m_xMaterial; p++; } } }