Esempio n. 1
0
        public void Write(Rsm model, BinaryWriter writer)
        {
            if (model.Version >= 2.2)
            {
                int len = 24;

                if (SmoothGroup[1] != SmoothGroup[0])
                {
                    len += 4;

                    if (SmoothGroup[2] != SmoothGroup[0])
                    {
                        len += 4;
                    }
                }
                else if (SmoothGroup[2] != SmoothGroup[0])
                {
                    len += 8;
                }

                writer.Write(len);
            }

            for (int i = 0; i < 3; i++)
            {
                writer.Write(VertexIds[i]);
            }

            for (int i = 0; i < 3; i++)
            {
                writer.Write(TextureVertexIds[i]);
            }

            writer.Write(TextureId);
            writer.Write(Padding);
            writer.Write(TwoSide);

            if (model.Version >= 1.2)
            {
                writer.Write(SmoothGroup[0]);

                if (SmoothGroup[1] != SmoothGroup[0])
                {
                    writer.Write(SmoothGroup[1]);

                    if (SmoothGroup[2] != SmoothGroup[0])
                    {
                        writer.Write(SmoothGroup[2]);
                    }
                }
                else if (SmoothGroup[2] != SmoothGroup[0])
                {
                    writer.Write(SmoothGroup[1]);
                    writer.Write(SmoothGroup[2]);
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Mesh"/> class.
 /// </summary>
 /// <param name="rsm">The RSM.</param>
 /// <param name="file">The file.</param>
 public Mesh(Rsm rsm, string file)
     : this(rsm, new ByteReader(file, 6), 1.4)
 {
     LoadedPath = file;
 }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Mesh"/> class.
 /// </summary>
 /// <param name="rsm">The RSM.</param>
 /// <param name="reader">The reader.</param>
 public Mesh(Rsm rsm, IBinaryReader reader)
     : this(rsm, reader, rsm.Version)
 {
 }
Esempio n. 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Mesh"/> class.
        /// </summary>
        /// <param name="rsm">The RSM.</param>
        /// <param name="reader">The reader.</param>
        /// <param name="version">The version.</param>
        public Mesh(Rsm rsm, IBinaryReader reader, double version)
        {
            int count;

            Model = rsm;

            if (version >= 2.2)
            {
                Name       = reader.String(reader.Int32(), '\0');
                ParentName = reader.String(reader.Int32(), '\0');
            }
            else
            {
                Name       = reader.String(40, '\0');
                ParentName = reader.String(40, '\0');
            }

            if (version >= 2.3)
            {
                count = reader.Int32();

                for (int i = 0; i < count; i++)
                {
                    Textures.Add(reader.String(reader.Int32(), '\0'));
                }

                _textureIndexes.Capacity = count;

                for (int i = 0; i < count; i++)
                {
                    _textureIndexes.Add(i);
                }
            }
            else
            {
                _textureIndexes.Capacity = count = reader.Int32();

                for (int i = 0; i < count; i++)
                {
                    _textureIndexes.Add(reader.Int32());
                }
            }

            for (int i = 0; i < 9; i++)
            {
                _transformationMatrix[i] = reader.Float();
            }

            Position_ = new Vertex(reader);

            if (version >= 2.2)
            {
                Position = new Vertex(0, 0, 0);
                RotAngle = 0;
                RotAxis  = new Vertex(0, 0, 0);
                Scale    = new Vertex(1, 1, 1);
            }
            else
            {
                Position = new Vertex(reader);
                RotAngle = reader.Float();
                RotAxis  = new Vertex(reader);
                Scale    = new Vertex(reader);
            }

            _vertices.Capacity = count = reader.Int32();

            for (int i = 0; i < count; i++)
            {
                _vertices.Add(new Vertex(reader));
            }

            _tvertices.Capacity = count = reader.Int32();

            for (int i = 0; i < count; i++)
            {
                _tvertices.Add(new TextureVertex {
                    Color = version >= 1.2 ? reader.UInt32() : 0xFFFFFFFF,
                    U     = reader.Float(),
                    V     = reader.Float()
                });
            }

            _faces.Capacity = count = reader.Int32();

            for (int i = 0; i < count; i++)
            {
                Face face = new Face();
                int  len  = -1;

                if (version >= 2.2)
                {
                    len = reader.Int32();
                }

                face.VertexIds        = reader.ArrayUInt16(3);
                face.TextureVertexIds = reader.ArrayUInt16(3);
                face.TextureId        = reader.UInt16();
                face.Padding          = reader.UInt16();
                face.TwoSide          = reader.Int32();

                if (version >= 1.2)
                {
                    face.SmoothGroup[0] = face.SmoothGroup[1] = face.SmoothGroup[2] = reader.Int32();

                    if (len > 24)
                    {
                        face.SmoothGroup[1] = reader.Int32();
                    }

                    if (len > 28)
                    {
                        face.SmoothGroup[2] = reader.Int32();
                    }
                }

                _faces.Add(face);
            }

            if (version >= 1.6)
            {
                _scaleKeyFrames.Capacity = count = reader.Int32();

                for (int i = 0; i < count; i++)
                {
                    _scaleKeyFrames.Add(new ScaleKeyFrame {
                        Frame = reader.Int32(),
                        Sx    = reader.Float(),
                        Sy    = reader.Float(),
                        Sz    = reader.Float(),
                        Data  = reader.Float()
                    });
                }
            }

            _rotFrames.Capacity = count = reader.Int32();

            for (int i = 0; i < count; i++)
            {
                _rotFrames.Add(new RotKeyFrame {
                    Frame      = reader.Int32(),
                    Quaternion = new TkQuaternion(reader.Float(), reader.Float(), reader.Float(), reader.Float())
                });
            }

            if (version >= 2.2)
            {
                _posKeyFrames.Capacity = count = reader.Int32();

                for (int i = 0; i < count; i++)
                {
                    _posKeyFrames.Add(new PosKeyFrame {
                        Frame = reader.Int32(),
                        X     = reader.Float(),
                        Y     = reader.Float(),
                        Z     = reader.Float(),
                        Data  = reader.Int32()
                    });
                }
            }

            if (version >= 2.3)
            {
                count = reader.Int32();

                for (int i = 0; i < count; i++)
                {
                    int textureId = reader.Int32();
                    int amountTextureAnimations = reader.Int32();

                    for (int j = 0; j < amountTextureAnimations; j++)
                    {
                        int type         = reader.Int32();
                        int amountFrames = reader.Int32();

                        for (int k = 0; k < amountFrames; k++)
                        {
                            _textureKeyFrameGroup.AddTextureKeyFrame(textureId, type, new TextureKeyFrame {
                                Frame  = reader.Int32(),
                                Offset = reader.Float()
                            });
                        }
                    }
                }
            }

            _uniqueTextures();
        }