public CompressedVertex(DependencyReader reader) { Position = new RealVector3D(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle()); Normal = new HenDN3(reader.ReadUInt32()); Binormal = new HenDN3(reader.ReadUInt32()); Tangent = new HenDN3(reader.ReadUInt32()); TexCoords = new RealVector2D(reader.ReadInt16() / (float)short.MaxValue, reader.ReadInt16() / (float)short.MaxValue); NodeIndex1 = (short)(reader.ReadByte() / 3); NodeIndex2 = (short)(reader.ReadByte() / 3); var node0Weight = reader.ReadUInt16() / (float)short.MaxValue; NodeWeights = new RealVector2D(node0Weight, 1 - node0Weight); }
private IEnumerable <GeometryMesh> ReadPCMeshes(DependencyReader reader) { var tagIndex = cache.TagIndex as ITagIndexGen1; if (tagIndex == null) { throw new NotSupportedException(); } foreach (var section in Sections) { var indices = new List <int>(); var vertices = new List <UncompressedVertex>(); var submeshes = new List <IGeometrySubmesh>(); foreach (var submesh in section.Submeshes) { var gSubmesh = new GeometrySubmesh { MaterialIndex = submesh.ShaderIndex, IndexStart = indices.Count, IndexLength = submesh.IndexCount + 2 }; submeshes.Add(gSubmesh); reader.Seek(tagIndex.VertexDataOffset + tagIndex.IndexDataOffset + submesh.IndexOffset, SeekOrigin.Begin); indices.AddRange(reader.ReadEnumerable <ushort>(gSubmesh.IndexLength).Select(i => i + vertices.Count)); reader.Seek(tagIndex.VertexDataOffset + submesh.VertexOffset, SeekOrigin.Begin); var vertsTemp = reader.ReadEnumerable <UncompressedVertex>(submesh.VertexCount).ToList(); if (UScale != 1 || VScale != 1) { vertsTemp.ForEach((v) => { var vec = v.TexCoords; vec.X *= UScale; vec.Y *= VScale; v.TexCoords = vec; }); } if (Flags.HasFlag(ModelFlags.UseLocalNodes)) { var address = section.Submeshes.Pointer.Address; address += section.Submeshes.IndexOf(submesh) * 132; reader.Seek(address + 107, SeekOrigin.Begin); var nodeCount = reader.ReadByte(); var nodes = reader.ReadEnumerable <byte>(nodeCount).ToArray(); vertsTemp.ForEach((v) => { v.NodeIndex1 = nodes[v.NodeIndex1]; v.NodeIndex2 = nodes[v.NodeIndex2]; }); } vertices.AddRange(vertsTemp); } yield return(new GeometryMesh { IndexFormat = IndexFormat.TriangleStrip, VertexWeights = VertexWeights.Skinned, Indicies = indices.ToArray(), Vertices = vertices.ToArray(), Submeshes = submeshes }); } }