Exemple #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Face" /> class.
        /// </summary>
        /// <param name="header">Rsm Header</param>
        /// <param name="reader">The reader.</param>
        public Face(RsmHeader header, IBinaryReader reader)
        {
            int len = -1;

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

            VertexIds        = reader.ArrayUInt16(3);
            TextureVertexIds = reader.ArrayUInt16(3);
            TextureId        = reader.UInt16();
            Padding          = reader.UInt16();
            TwoSide          = reader.Int32();
            SmoothGroup[0]   = SmoothGroup[1] = SmoothGroup[2] = reader.Int32();

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

            if (len > 28)
            {
                SmoothGroup[2] = reader.Int32();
            }
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Face" /> class.
        /// </summary>
        /// <param name="header">Rsm Header</param>
        /// <param name="reader">The reader.</param>
        /// <param name="smoothGroup">The smooth group.</param>
        public Face(RsmHeader header, IBinaryReader reader, int smoothGroup)
        {
            VertexIds        = reader.ArrayUInt16(3);
            TextureVertexIds = reader.ArrayUInt16(3);
            TextureId        = reader.UInt16();
            Padding          = reader.UInt16();
            TwoSide          = reader.Int32();

            for (int i = 0; i < 3; i++)
            {
                SmoothGroup[i] = smoothGroup;
            }
        }
Exemple #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>
        /// <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();
        }