Blending data for a mesh/model.
示例#1
0
        /// <summary>
        /// Reads a mesh from a stream.
        /// </summary>
        /// <param name="stream">A Stream instance holding a mesh.</param> <param name="bmf">If this stream contains a .bmf file (rather than TSO .mesh).</param>
        public void Read(BCFReadProxy io, bool bmf)
        {
            if (bmf)
            {
                SkinName    = io.ReadPascalString();
                TextureName = io.ReadPascalString();
            }
            else
            {
                var version = io.ReadInt32();
            }
            var boneCount = io.ReadInt32();
            var boneNames = new string[boneCount];

            for (var i = 0; i < boneCount; i++)
            {
                boneNames[i] = io.ReadPascalString();
            }

            var faceCount = io.ReadInt32();

            NumPrimitives = faceCount;

            IndexBuffer = new int[faceCount * 3];
            int offset = 0;

            for (var i = 0; i < faceCount; i++)
            {
                IndexBuffer[offset++] = io.ReadInt32();
                IndexBuffer[offset++] = io.ReadInt32();
                IndexBuffer[offset++] = io.ReadInt32();
            }

            /** Bone bindings **/
            var bindingCount = io.ReadInt32();

            BoneBindings = new BoneBinding[bindingCount];
            for (var i = 0; i < bindingCount; i++)
            {
                BoneBindings[i] = new BoneBinding
                {
                    BoneIndex        = io.ReadInt32(),
                    FirstRealVertex  = io.ReadInt32(),
                    RealVertexCount  = io.ReadInt32(),
                    FirstBlendVertex = io.ReadInt32(),
                    BlendVertexCount = io.ReadInt32()
                };

                BoneBindings[i].BoneName = boneNames[Math.Min(boneNames.Length - 1, BoneBindings[i].BoneIndex)];
            }


            var realVertexCount = io.ReadInt32();

            VertexBuffer = new VitaboyVertex[realVertexCount];

            for (var i = 0; i < realVertexCount; i++)
            {
                VertexBuffer[i].TextureCoordinate.X = io.ReadFloat();
                VertexBuffer[i].TextureCoordinate.Y = io.ReadFloat();
            }

            /** Blend data **/
            var blendVertexCount = io.ReadInt32();

            BlendData = new BlendData[blendVertexCount];
            for (var i = 0; i < blendVertexCount; i++)
            {
                if (io is IoBuffer)
                {
                    BlendData[i] = new BlendData
                    {
                        Weight      = (float)io.ReadInt32() / 0x8000,
                        OtherVertex = io.ReadInt32()
                    };
                }
                else
                {
                    BlendData[i] = new BlendData
                    {
                        OtherVertex = io.ReadInt32(),
                        Weight      = (float)io.ReadInt32() / 0x8000
                    };
                }
            }

            var realVertexCount2 = io.ReadInt32();

            for (int i = 0; i < realVertexCount; i++)
            {
                VertexBuffer[i].Position = new Microsoft.Xna.Framework.Vector3(
                    -io.ReadFloat(),
                    io.ReadFloat(),
                    io.ReadFloat()
                    );

                VertexBuffer[i].Normal = new Microsoft.Xna.Framework.Vector3(
                    -io.ReadFloat(),
                    io.ReadFloat(),
                    io.ReadFloat()
                    );
                if (VertexBuffer[i].Normal == Vector3.Zero)
                {
                    VertexBuffer[i].Normal = new Vector3(0, 1, 0);
                }
            }

            BlendVerts   = new Vector3[blendVertexCount];
            BlendNormals = new Vector3[blendVertexCount];

            for (int i = 0; i < blendVertexCount; i++)
            {
                BlendVerts[i] = new Vector3(
                    -io.ReadFloat(),
                    io.ReadFloat(),
                    io.ReadFloat()
                    );

                BlendNormals[i] = new Vector3(
                    -io.ReadFloat(),
                    io.ReadFloat(),
                    io.ReadFloat()
                    ); //todo: use it for lighting.
            }

            BlendVertBoneIndices = new int[blendVertexCount];
        }
示例#2
0
        /// <summary>
        /// Reads a mesh from a stream.
        /// </summary>
        /// <param name="stream">A Stream instance holding a mesh.</param> <param name="bmf">If this stream contains a .bmf file (rather than TSO .mesh).</param>
        public void Read(Stream stream, bool bmf)
        {
            using (var io = IoBuffer.FromStream(stream, bmf?ByteOrder.LITTLE_ENDIAN:ByteOrder.BIG_ENDIAN))
            {
                if (bmf)
                {
                    SkinName    = io.ReadPascalString();
                    TextureName = io.ReadPascalString();
                }
                else
                {
                    var version = io.ReadInt32();
                }
                var boneCount = io.ReadInt32();
                var boneNames = new string[boneCount];
                for (var i = 0; i < boneCount; i++)
                {
                    boneNames[i] = io.ReadPascalString();
                }

                var faceCount = io.ReadInt32();
                NumPrimitives = faceCount;

                IndexBuffer = new short[faceCount * 3];
                int offset = 0;
                for (var i = 0; i < faceCount; i++)
                {
                    IndexBuffer[offset++] = (short)io.ReadInt32();
                    IndexBuffer[offset++] = (short)io.ReadInt32();
                    IndexBuffer[offset++] = (short)io.ReadInt32();
                }

                /** Bone bindings **/
                var bindingCount = io.ReadInt32();
                BoneBindings = new BoneBinding[bindingCount];
                for (var i = 0; i < bindingCount; i++)
                {
                    BoneBindings[i] = new BoneBinding
                    {
                        BoneIndex        = io.ReadInt32(),
                        FirstRealVertex  = io.ReadInt32(),
                        RealVertexCount  = io.ReadInt32(),
                        FirstBlendVertex = io.ReadInt32(),
                        BlendVertexCount = io.ReadInt32()
                    };

                    BoneBindings[i].BoneName = boneNames[Math.Min(boneNames.Length - 1, BoneBindings[i].BoneIndex)];
                }


                var realVertexCount = io.ReadInt32();
                VertexBuffer = new VitaboyVertex[realVertexCount];

                for (var i = 0; i < realVertexCount; i++)
                {
                    VertexBuffer[i].TextureCoordinate.X = io.ReadFloat();
                    VertexBuffer[i].TextureCoordinate.Y = io.ReadFloat();
                }

                /** Blend data **/
                var blendVertexCount = io.ReadInt32();
                BlendData = new BlendData[blendVertexCount];
                for (var i = 0; i < blendVertexCount; i++)
                {
                    BlendData[i] = new BlendData
                    {
                        Weight      = (float)io.ReadInt32() / 0x8000,
                        OtherVertex = io.ReadInt32()
                    };
                }

                var realVertexCount2 = io.ReadInt32();

                for (int i = 0; i < realVertexCount; i++)
                {
                    VertexBuffer[i].Position = new Microsoft.Xna.Framework.Vector3(
                        -io.ReadFloat(),
                        io.ReadFloat(),
                        io.ReadFloat()
                        );

                    VertexBuffer[i].Normal = new Microsoft.Xna.Framework.Vector3(
                        -io.ReadFloat(),
                        io.ReadFloat(),
                        io.ReadFloat()
                        );
                }

                BlendVerts = new Vector3[blendVertexCount];

                for (int i = 0; i < blendVertexCount; i++)
                {
                    BlendVerts[i] = new Vector3(
                        -io.ReadFloat(),
                        io.ReadFloat(),
                        io.ReadFloat()
                        );

                    var normal = new Vector3(
                        -io.ReadFloat(),
                        io.ReadFloat(),
                        io.ReadFloat()
                        ); //todo: read this in somewhere and use it for lighting.
                }

                BlendVertBoneIndices = new int[blendVertexCount];
            }
        }
示例#3
0
文件: Mesh.cs 项目: RHY3756547/FreeSO
        /// <summary>
        /// Reads a mesh from a stream.
        /// </summary>
        /// <param name="stream">A Stream instance holding a mesh.</param>
        public unsafe void Read(Stream stream)
        {
            using (var io = IoBuffer.FromStream(stream))
            {
                var version = io.ReadInt32();
                var boneCount = io.ReadInt32();
                var boneNames = new string[boneCount];
                for (var i = 0; i < boneCount; i++){
                    boneNames[i] = io.ReadPascalString();
                }

                var faceCount = io.ReadInt32();
                NumPrimitives = faceCount;

                IndexBuffer = new short[faceCount * 3];
                int offset = 0;
                for (var i = 0; i < faceCount; i++){
                    IndexBuffer[offset++] = (short)io.ReadInt32();
                    IndexBuffer[offset++] = (short)io.ReadInt32();
                    IndexBuffer[offset++] = (short)io.ReadInt32();
                }

                /** Bone bindings **/
                var bindingCount = io.ReadInt32();
                BoneBindings = new BoneBinding[bindingCount];
                for (var i = 0; i < bindingCount; i++)
                {
                    BoneBindings[i] = new BoneBinding
                    {
                        BoneIndex = io.ReadInt32(),
                        FirstRealVertex = io.ReadInt32(),
                        RealVertexCount = io.ReadInt32(),
                        FirstBlendVertex = io.ReadInt32(),
                        BlendVertexCount = io.ReadInt32()
                    };

                    BoneBindings[i].BoneName = boneNames[BoneBindings[i].BoneIndex];
                }

                var realVertexCount = io.ReadInt32();
                VertexBuffer = new VitaboyVertex[realVertexCount];

                for (var i = 0; i < realVertexCount; i++){
                    VertexBuffer[i].TextureCoordinate.X = io.ReadFloat();
                    VertexBuffer[i].TextureCoordinate.Y = io.ReadFloat();
                }

                /** Blend data **/
                var blendVertexCount = io.ReadInt32();
                BlendData = new BlendData[blendVertexCount];
                for (var i = 0; i < blendVertexCount; i++)
                {
                    BlendData[i] = new BlendData
                    {
                        Weight = (float)io.ReadInt32() / 0x8000,
                        OtherVertex = io.ReadInt32()
                    };
                }

                var realVertexCount2 = io.ReadInt32();

                for (int i = 0; i < realVertexCount; i++)
                {
                    VertexBuffer[i].Position = new Microsoft.Xna.Framework.Vector3(
                        -io.ReadFloat(),
                        io.ReadFloat(),
                        io.ReadFloat()
                    );

                    VertexBuffer[i].Normal = new Microsoft.Xna.Framework.Vector3(
                        -io.ReadFloat(),
                        io.ReadFloat(),
                        io.ReadFloat()
                    );
                }

                BlendVerts = new Vector3[blendVertexCount];

                for (int i = 0; i < blendVertexCount; i++)
                {
                    BlendVerts[i] = new Vector3(
                        -io.ReadFloat(),
                        io.ReadFloat(),
                        io.ReadFloat()
                    );

                    var normal = new Vector3(
                        -io.ReadFloat(),
                        io.ReadFloat(),
                        io.ReadFloat()
                    ); //todo: read this in somewhere and use it for lighting.
                }

                BlendVertBoneIndices = new int[blendVertexCount];
            }
        }