private unsafe TreeModelLibrary(RenderSystem rs) { renderSys = rs; FileLocation fl = FileSystem.Instance.Locate("trees.xml", GameFileLocs.Config); Configuration conf = ConfigurationManager.Instance.CreateInstance(fl); foreach (KeyValuePair<string, ConfigurationSection> s in conf) { ConfigurationSection sect = s.Value; TreeModelData mdl; int type = sect.GetInt("Type", 0); string fileName = sect.GetString("Level0", string.Empty); FileLocation fl2 = FileSystem.Instance.Locate(fileName, GameFileLocs.Model); ModelMemoryData mdlData = new ModelMemoryData(rs, fl2); loadedModels.Add(mdlData); MeshData[] dataArr = mdlData.Entities; if (dataArr.Length == 1) { MeshData data = dataArr[0]; Material[][] mtrls = data.Materials; int partCount = mtrls.Length; FastList<int>[] indices = new FastList<int>[partCount]; for (int i = 0; i < partCount; i++) indices[i] = new FastList<int>(); mdl.Materials = new Material[partCount]; mdl.Indices = new int[partCount][]; mdl.PartVtxCount = new int[partCount]; MeshFace[] faces = data.Faces; for (int i = 0; i < faces.Length; i++) { int matId = faces[i].MaterialIndex; indices[matId].Add(faces[i].IndexA); indices[matId].Add(faces[i].IndexB); indices[matId].Add(faces[i].IndexC); } for (int i = 0; i < partCount; i++) { Material mtrl = mtrls[i][0]; mdl.Materials[i] = mtrl; indices[i].Trim(); mdl.Indices[i] = indices[i].Elements; int partVtxCount = 0; bool[] passed = new bool[data.VertexCount]; for (int j = 0; j < mdl.Indices[i].Length; j++) { passed[indices[i][j]] = true; } for (int j = 0; j < data.VertexCount; j++) if (passed[j]) partVtxCount++; mdl.PartVtxCount[i] = partVtxCount; } mdl.VertexCount = data.VertexCount; mdl.VertexData = new byte[data.VertexCount * data.VertexSize]; fixed (byte* dst = &mdl.VertexData[0]) { Memory.Copy(data.Data.ToPointer(), dst, mdl.VertexData.Length); } if (typedList[type] == null) { typedList[type] = new FastList<TreeModelData>(); } typedList[type].Add(mdl); } BuildTrunk(rs); } for (int i = 0; i < typedList.Length; i++) { typedList[i].Trim(); } }
private unsafe TreeModelLibrary(RenderSystem rs) { renderSys = rs; FileLocation fl = FileSystem.Instance.Locate("trees.xml", GameFileLocs.Config); Configuration conf = ConfigurationManager.Instance.CreateInstance(fl); foreach (KeyValuePair <string, ConfigurationSection> s in conf) { ConfigurationSection sect = s.Value; TreeModelData mdl; int type = sect.GetInt("Type", 0); string fileName = sect.GetString("Level0", string.Empty); FileLocation fl2 = FileSystem.Instance.Locate(fileName, GameFileLocs.Model); ModelMemoryData mdlData = new ModelMemoryData(rs, fl2); loadedModels.Add(mdlData); MeshData[] dataArr = mdlData.Entities; if (dataArr.Length == 1) { MeshData data = dataArr[0]; Material[][] mtrls = data.Materials; int partCount = mtrls.Length; FastList <int>[] indices = new FastList <int> [partCount]; for (int i = 0; i < partCount; i++) { indices[i] = new FastList <int>(); } mdl.Materials = new Material[partCount]; mdl.Indices = new int[partCount][]; mdl.PartVtxCount = new int[partCount]; MeshFace[] faces = data.Faces; for (int i = 0; i < faces.Length; i++) { int matId = faces[i].MaterialIndex; indices[matId].Add(faces[i].IndexA); indices[matId].Add(faces[i].IndexB); indices[matId].Add(faces[i].IndexC); } for (int i = 0; i < partCount; i++) { Material mtrl = mtrls[i][0]; mdl.Materials[i] = mtrl; indices[i].Trim(); mdl.Indices[i] = indices[i].Elements; int partVtxCount = 0; bool[] passed = new bool[data.VertexCount]; for (int j = 0; j < mdl.Indices[i].Length; j++) { passed[indices[i][j]] = true; } for (int j = 0; j < data.VertexCount; j++) { if (passed[j]) { partVtxCount++; } } mdl.PartVtxCount[i] = partVtxCount; } mdl.VertexCount = data.VertexCount; mdl.VertexData = new byte[data.VertexCount * data.VertexSize]; fixed(byte *dst = &mdl.VertexData[0]) { Memory.Copy(data.Data.ToPointer(), dst, mdl.VertexData.Length); } if (typedList[type] == null) { typedList[type] = new FastList <TreeModelData>(); } typedList[type].Add(mdl); } BuildTrunk(rs); } for (int i = 0; i < typedList.Length; i++) { typedList[i].Trim(); } }
unsafe void BuildTrunk(RenderSystem rs) { FileLocation fl = FileSystem.Instance.Locate("shuzhuang.mesh", GameFileLocs.Model); ModelMemoryData mdlData2 = new ModelMemoryData(rs, fl); loadedModels.Add(mdlData2); MeshData[] dataArr2 = mdlData2.Entities; if (dataArr2.Length == 1) { TreeModelData mdl; MeshData data = dataArr2[0]; Material[][] mtrls = data.Materials; int partCount = mtrls.Length; FastList<int>[] indices = new FastList<int>[partCount]; for (int i = 0; i < partCount; i++) indices[i] = new FastList<int>(); mdl.Materials = new Material[partCount]; mdl.Indices = new int[partCount][]; mdl.PartVtxCount = new int[partCount]; MeshFace[] faces = data.Faces; for (int i = 0; i < faces.Length; i++) { int matId = faces[i].MaterialIndex; indices[matId].Add(faces[i].IndexA); indices[matId].Add(faces[i].IndexB); indices[matId].Add(faces[i].IndexC); } for (int i = 0; i < partCount; i++) { Material mtrl = mtrls[i][0]; mdl.Materials[i] = mtrl; indices[i].Trim(); mdl.Indices[i] = indices[i].Elements; int partVtxCount = 0; bool[] passed = new bool[data.VertexCount]; for (int j = 0; j < mdl.Indices[i].Length; j++) { passed[indices[i][j]] = true; } for (int j = 0; j < data.VertexCount; j++) if (passed[j]) partVtxCount++; mdl.PartVtxCount[i] = partVtxCount; } mdl.VertexCount = data.VertexCount; mdl.VertexData = new byte[data.VertexCount * data.VertexSize]; fixed (byte* dst = &mdl.VertexData[0]) { Memory.Copy(data.Data.ToPointer(), dst, mdl.VertexData.Length); } trunk = mdl; } }
unsafe void BuildTrunk(RenderSystem rs) { FileLocation fl = FileSystem.Instance.Locate("shuzhuang.mesh", GameFileLocs.Model); ModelMemoryData mdlData2 = new ModelMemoryData(rs, fl); loadedModels.Add(mdlData2); MeshData[] dataArr2 = mdlData2.Entities; if (dataArr2.Length == 1) { TreeModelData mdl; MeshData data = dataArr2[0]; Material[][] mtrls = data.Materials; int partCount = mtrls.Length; FastList <int>[] indices = new FastList <int> [partCount]; for (int i = 0; i < partCount; i++) { indices[i] = new FastList <int>(); } mdl.Materials = new Material[partCount]; mdl.Indices = new int[partCount][]; mdl.PartVtxCount = new int[partCount]; MeshFace[] faces = data.Faces; for (int i = 0; i < faces.Length; i++) { int matId = faces[i].MaterialIndex; indices[matId].Add(faces[i].IndexA); indices[matId].Add(faces[i].IndexB); indices[matId].Add(faces[i].IndexC); } for (int i = 0; i < partCount; i++) { Material mtrl = mtrls[i][0]; mdl.Materials[i] = mtrl; indices[i].Trim(); mdl.Indices[i] = indices[i].Elements; int partVtxCount = 0; bool[] passed = new bool[data.VertexCount]; for (int j = 0; j < mdl.Indices[i].Length; j++) { passed[indices[i][j]] = true; } for (int j = 0; j < data.VertexCount; j++) { if (passed[j]) { partVtxCount++; } } mdl.PartVtxCount[i] = partVtxCount; } mdl.VertexCount = data.VertexCount; mdl.VertexData = new byte[data.VertexCount * data.VertexSize]; fixed(byte *dst = &mdl.VertexData[0]) { Memory.Copy(data.Data.ToPointer(), dst, mdl.VertexData.Length); } trunk = mdl; } }