public GFSubMesh(H3DSubMesh SubMesh, H3DMesh Parent, List <PICAVertex> Vertices, string Name) : this() { this.Name = Name; BoneIndicesCount = (byte)SubMesh.BoneIndicesCount; BoneIndices = new byte[SubMesh.BoneIndicesCount]; for (int i = 0; i < SubMesh.BoneIndicesCount; i++) { BoneIndices[i] = (byte)SubMesh.BoneIndices[i]; } Indices = SubMesh.Indices; PrimitiveMode = SubMesh.PrimitiveMode; VertexStride = Parent.VertexStride; Attributes = Parent.Attributes; foreach (PICAFixedAttribute Old in Parent.FixedAttributes) { PICAFixedAttribute New = new PICAFixedAttribute() { Name = Old.Name, Value = Old.Value }; FixedAttributes.Add(New); } List <PICAVertex> NewVertices = new List <PICAVertex>(); Dictionary <ushort, ushort> OldNewIndexMap = new Dictionary <ushort, ushort>(); ushort[] NewIndices = new ushort[Indices.Length]; for (int i = 0; i < NewIndices.Length; i++) { if (OldNewIndexMap.ContainsKey(Indices[i])) { NewIndices[i] = OldNewIndexMap[Indices[i]]; } else { PICAVertex Vertex = Vertices[Indices[i]]; ushort NewIndex = (ushort)NewVertices.Count; NewVertices.Add(Vertex); NewIndices[i] = NewIndex; OldNewIndexMap.Add(Indices[i], NewIndex); } } Indices = NewIndices; IsIdx8Bits = /*NewIndices.Length <= 0x100*/ false; RawBuffer = VerticesConverter.GetBuffer(NewVertices, Attributes); }
public GFSubMesh(H3DSubMesh SubMesh, H3DMesh Parent, List <PICAVertex> Vertices, string Name) { this.Name = Name; BoneIndicesCount = (byte)SubMesh.BoneIndicesCount; BoneIndices = new byte[SubMesh.BoneIndicesCount]; for (int i = 0; i < SubMesh.BoneIndicesCount; i++) { BoneIndices[i] = (byte)SubMesh.BoneIndices[i]; } Indices = SubMesh.Indices; IsIdx8Bits = true; foreach (ushort Index in Indices) { if (Index > 0xFF) { IsIdx8Bits = false; break; } } PrimitiveMode = SubMesh.PrimitiveMode; VertexStride = Parent.VertexStride; Attributes = Parent.Attributes; FixedAttributes = Parent.FixedAttributes; List <PICAVertex> NewVertices = new List <PICAVertex>(); ushort[] NewIndices = new ushort[Indices.Length]; for (int i = 0; i < NewIndices.Length; i++) { PICAVertex Vertex = Vertices[Indices[i]]; int NewIndex = NewVertices.IndexOf(Vertex); if (NewIndex == -1) { NewIndex = NewVertices.Count; NewVertices.Add(Vertex); } NewIndices[i] = (ushort)NewIndex; } Indices = NewIndices; RawBuffer = VerticesConverter.GetBuffer(NewVertices, Attributes); }