Beispiel #1
0
 public void UpdateVertexData()
 {
     this.vertexData.Clear();
     for (int index = 0; index < this.vertices.Count; index++)
     {
         BSVertexData vd = new BSVertexData();
         vd.vertex = new Vector3(this.vertices[index][0], this.vertices[index][1], this.vertices[index][2]);
         if (this.uvCoords.Count != 0)
         {
             vd.uvcoords = new UVCoord(this.uvCoords[index][0], this.uvCoords[index][1]);
         }
         if (this.normals.Count != 0)
         {
             vd.normal = new Vector3(this.normals[index][0], this.normals[index][1], this.normals[index][2]);
         }
         if (this.tangents.Count != 0)
         {
             vd.tangent    = new Vector3(this.tangents[index][0], this.tangents[index][1], this.tangents[index][2]);
             vd.bitangentY = this.bitangents[index][1];
             vd.bitangentX = this.bitangents[index][0];
             vd.bitangentZ = this.bitangents[index][2];
         }
         if (this.vertexColors.Count != 0)
         {
             vd.vertexColors = new Color4(this.vertexColors[index][0], this.vertexColors[index][1], this.vertexColors[index][2], this.vertexColors[index][3]);
         }
         this.vertexData.Add(vd);
         this.numVertices  = (ushort)this.vertices.Count;
         this.numTriangles = (uint)this.triangles.Count;
     }
 }
Beispiel #2
0
        public override void Read(NiHeader header, BinaryReader reader)
        {
            base.Read(header, reader);
            this.center          = Utils.ReadVector3(reader);
            this.radius          = reader.ReadSingle();
            this.skinInstance    = reader.ReadInt32();
            this.bsProperties[0] = reader.ReadInt32();
            this.bsProperties[1] = reader.ReadInt32();
            this.vertexSize      = reader.ReadByte();
            this.floatSize       = reader.ReadByte();
            this.vertexFlag3     = reader.ReadByte();
            this.vertexFlag4     = reader.ReadByte();
            this.vertexFlag5     = reader.ReadByte();
            this.vertexFlags     = reader.ReadUInt16();
            // 16 = vertex
            // 32 = uv
            // 128 = normals
            // 256 = tangents
            // 512 = vertex colors
            // 1024 = skinned
            // 4096 = male eyes
            // 16384 = full precision

            this.vertexFlag8 = reader.ReadByte();
            if (header.GetUserVersion2() == 100)
            {
                this.numTriangles = reader.ReadUInt16();
            }
            else
            {
                this.numTriangles = reader.ReadUInt32();
            }
            this.numVertices = reader.ReadUInt16();
            this.dataSize    = reader.ReadUInt32();

            if (this.dataSize > 0)
            {
                for (int index = 0; index < numVertices; index++)
                {
                    BSVertexData vd = new BSVertexData();
                    if ((this.vertexFlags & 16) == 16)
                    {
                        if (header.GetUserVersion2() == 100 || (this.vertexFlags & 16384) == 16384)
                        {
                            vd.vertex     = Utils.ReadVector3(reader);
                            vd.bitangentX = reader.ReadSingle();
                        }
                        else
                        {
                            vd.vertex     = new Vector3(Utils.ShortToFloat(reader.ReadInt16()), Utils.ShortToFloat(reader.ReadInt16()), Utils.ShortToFloat(reader.ReadInt16()));
                            vd.bitangentX = Utils.ShortToFloat(reader.ReadInt16());
                        }
                    }
                    if ((this.vertexFlags & 32) == 32)
                    {
                        vd.uvcoords = new UVCoord(Utils.ShortToFloat(reader.ReadInt16()), Utils.ShortToFloat(reader.ReadInt16()));
                    }
                    if ((this.vertexFlags & 128) == 128)
                    {
                        vd.normal     = new Vector3(Utils.ByteToFloat(reader.ReadByte()), Utils.ByteToFloat(reader.ReadByte()), Utils.ByteToFloat(reader.ReadByte()));
                        vd.bitangentY = Utils.ByteToFloat(reader.ReadByte());
                    }
                    if ((this.vertexFlags & 256) == 256)
                    {
                        vd.tangent    = new Vector3(Utils.ByteToFloat(reader.ReadByte()), Utils.ByteToFloat(reader.ReadByte()), Utils.ByteToFloat(reader.ReadByte()));
                        vd.bitangentZ = Utils.ByteToFloat(reader.ReadByte());
                    }
                    if ((this.vertexFlags & 512) == 512)
                    {
                        vd.vertexColors = new Color4((float)reader.ReadByte() / 255, (float)reader.ReadByte() / 255, (float)reader.ReadByte() / 255, (float)reader.ReadByte() / 255);
                    }
                    if ((this.vertexFlags & 1024) == 1024)
                    {
                        vd.boneWeights[0] = Utils.ShortToFloat(reader.ReadInt16());
                        vd.boneWeights[1] = Utils.ShortToFloat(reader.ReadInt16());
                        vd.boneWeights[2] = Utils.ShortToFloat(reader.ReadInt16());
                        vd.boneWeights[3] = Utils.ShortToFloat(reader.ReadInt16());
                        vd.boneIndices[0] = reader.ReadByte();
                        vd.boneIndices[1] = reader.ReadByte();
                        vd.boneIndices[2] = reader.ReadByte();
                        vd.boneIndices[3] = reader.ReadByte();
                    }
                    if ((this.vertexFlags & 4096) == 4096)
                    {
                        reader.ReadInt32();
                    }

                    this.vertexData.Add(vd);
                    this.vertices.Add(vd.vertex);
                    this.normals.Add(vd.normal);
                    this.tangents.Add(vd.tangent);
                    this.bitangents.Add(new Vector3(vd.bitangentX, vd.bitangentY, vd.bitangentZ));
                    this.vertexColors.Add(vd.vertexColors);
                    this.uvCoords.Add(vd.uvcoords);
                }
                for (int index = 0; index < numTriangles; index++)
                {
                    this.triangles.Add(Utils.ReadTriangle(reader));
                }

                if (header.GetUserVersion2() == 100)
                {
                    particleDataSize = reader.ReadUInt32();
                }

                /*for (int index = 0; index < numVertices; index++)
                 * {
                 *  Console.WriteLine("Vertex ["+ index + "] = " + vertices[index]);
                 * }*/
                /*for (int index = 0; index < normals.Count; index++)
                 * {
                 *  Console.WriteLine("Normal ["+ index + "] = " + normals[index]);
                 * }
                 * for (int index = 0; index < bitangents.Count; index++)
                 * {
                 *  Console.WriteLine("Bitang [" + index + "] = " + bitangents[index]);
                 * }
                 * for (int index = 0; index < vertexColors.Count; index++)
                 * {
                 *  Console.WriteLine("vertexColors [" + index + "] = " + vertexColors[index]);
                 * }
                 * for (int index = 0; index < numTriangles; index++)
                 * {
                 *  Console.WriteLine("Triangle [" + index + "] = " + triangles[index]);
                 * }*/
            }
        }