Exemple #1
0
        private void LoadSkins()
        {
            string skinFile = FileDirectory + ModelName + "00.skin";
            Stormlib.MPQFile skin = new Stormlib.MPQFile(skinFile);
            skin.Dispose();
            SKINView mView = skin.Read<SKINView>();
            ushort[] indexLookup = new ushort[mView.nIndices];
            skin.Position = mView.ofsIndices;
            skin.Read(indexLookup);
            ushort[] triangles = new ushort[mView.nTriangles];
            skin.Position = mView.ofsTriangles;
            skin.Read(triangles);

            SKINSubMesh[] SubMeshes = new SKINSubMesh[mView.nSubMeshes];
            skin.Position = mView.ofsSubMeshes;
            skin.Read(SubMeshes);

            SKINTexUnit[] TexUnits = new SKINTexUnit[mView.nTexUnits];
            skin.Position = mView.ofsTexUnits;
            skin.Read(TexUnits);

            ushort[] texLookUp = new ushort[Header.nTexLookups];
            mFile.Position = Header.ofsTexLookups;
            mFile.Read(texLookUp);

            ushort[] texUnitLookUp = new ushort[Header.nTexUnits];
            mFile.Position = Header.ofsTexUnits;
            mFile.Read(texUnitLookUp);

            M2RenderFlags[] renderFlags = new M2RenderFlags[Header.nRenderFlags];
            mFile.Position = Header.ofsRenderFlags;
            mFile.Read(renderFlags);

            ushort[] indices = new ushort[mView.nTriangles];
            for (int i = 0; i < mView.nTriangles; ++i)
                indices[i] = indexLookup[triangles[i]];

            var bones = new M2Bone[Header.nBones];
            mFile.Position = Header.ofsBones;
            mFile.Read(bones);

            M2BoneAnimator mba = new M2BoneAnimator(mFile, this);
            BoneLookupTable = new ushort[Header.nBoneLookupTables];
            mFile.Position = Header.ofsBoneLookupTables;
            mFile.Read(BoneLookupTable);

            GlobalSequences = new uint[Header.nGlobalSequences];
            mFile.Position = Header.ofsGlobalSequences;
            mFile.Read(GlobalSequences);

            for (int i = 0; i < mView.nTexUnits; ++i)
            {
                M2RenderPass pass = new M2RenderPass();
                SKINSubMesh mesh = SubMeshes[TexUnits[i].SubMesh1];
                pass.Vertices = new MdxVertex[mesh.nTriangles];
                pass.Texture = Textures[(int)texLookUp[TexUnits[i].Texture]];
                pass.BlendMode = renderFlags[TexUnits[i].RenderFlags];
                pass.BoneMatrices = new SlimDX.Matrix[mesh.nBones];
                pass.BoneBaseIndex = mesh.startBone;
                pass.ParentModel = this;
                pass.Index = TexUnits[i].TexUnitNumber;

                for (uint q = 0; q < mesh.nBones; ++q)
                {
                    pass.BoneMatrices[q] = mba.GetBone((short)(BoneLookupTable[mesh.startBone + q])).Matrix;
                }

                for (ushort t = mesh.startTriangle, k = 0; k < mesh.nTriangles; ++t, ++k)
                {
                    ushort index = indices[t];
                    pass.Vertices[k] = Vertices[index];
                    pass.Vertices[k].bi1 = (byte)(Vertices[i].bi1);
                    pass.Vertices[k].bi2 = (byte)(Vertices[i].bi2);
                    pass.Vertices[k].bi3 = (byte)(Vertices[i].bi3);
                    pass.Vertices[k].bi4 = (byte)(Vertices[i].bi4);
                }

                pass.SetVertexIndices();
                Passes.Add(pass);
            }

            Passes.Sort((g1, g2) =>
            {
                if (g1.BlendMode.blend == 2 && g2.BlendMode.blend != 2)
                    return 1;
                if (g2.BlendMode.blend == 2 && g1.BlendMode.blend != 2)
                    return -1;

                if (g1.BlendMode.blend < g2.BlendMode.blend)
                    return -1;
                if (g2.BlendMode.blend < g1.BlendMode.blend)
                    return 1;

                if (g1.Index == g2.Index)
                    return 0;
                if (g1.Index < g2.Index)
                    return -1;
                if (g1.Index > g2.Index)
                    return 1;
                return 0;
            }
            );

            BoneAnimator = mba;
        }
Exemple #2
0
        private void LoadSkins()
        {
            string skinFile = FileDirectory + ModelName + "00.skin";

            Stormlib.MPQFile skin = new Stormlib.MPQFile(skinFile);
            skin.Dispose();
            SKINView mView = skin.Read <SKINView>();

            ushort[] indexLookup = new ushort[mView.nIndices];
            skin.Position = mView.ofsIndices;
            skin.Read(indexLookup);
            ushort[] triangles = new ushort[mView.nTriangles];
            skin.Position = mView.ofsTriangles;
            skin.Read(triangles);

            SKINSubMesh[] SubMeshes = new SKINSubMesh[mView.nSubMeshes];
            skin.Position = mView.ofsSubMeshes;
            skin.Read(SubMeshes);

            SKINTexUnit[] TexUnits = new SKINTexUnit[mView.nTexUnits];
            skin.Position = mView.ofsTexUnits;
            skin.Read(TexUnits);

            ushort[] texLookUp = new ushort[Header.nTexLookups];
            mFile.Position = Header.ofsTexLookups;
            mFile.Read(texLookUp);

            ushort[] texUnitLookUp = new ushort[Header.nTexUnits];
            mFile.Position = Header.ofsTexUnits;
            mFile.Read(texUnitLookUp);

            M2RenderFlags[] renderFlags = new M2RenderFlags[Header.nRenderFlags];
            mFile.Position = Header.ofsRenderFlags;
            mFile.Read(renderFlags);

            ushort[] indices = new ushort[mView.nTriangles];
            for (int i = 0; i < mView.nTriangles; ++i)
            {
                indices[i] = indexLookup[triangles[i]];
            }

            var bones = new M2Bone[Header.nBones];

            mFile.Position = Header.ofsBones;
            mFile.Read(bones);

            M2BoneAnimator mba = new M2BoneAnimator(mFile, this);

            BoneLookupTable = new ushort[Header.nBoneLookupTables];
            mFile.Position  = Header.ofsBoneLookupTables;
            mFile.Read(BoneLookupTable);

            GlobalSequences = new uint[Header.nGlobalSequences];
            mFile.Position  = Header.ofsGlobalSequences;
            mFile.Read(GlobalSequences);

            for (int i = 0; i < mView.nTexUnits; ++i)
            {
                M2RenderPass pass = new M2RenderPass();
                SKINSubMesh  mesh = SubMeshes[TexUnits[i].SubMesh1];
                pass.Vertices      = new MdxVertex[mesh.nTriangles];
                pass.Texture       = Textures[(int)texLookUp[TexUnits[i].Texture]];
                pass.BlendMode     = renderFlags[TexUnits[i].RenderFlags];
                pass.BoneMatrices  = new SlimDX.Matrix[mesh.nBones];
                pass.BoneBaseIndex = mesh.startBone;
                pass.ParentModel   = this;
                pass.Index         = TexUnits[i].TexUnitNumber;

                for (uint q = 0; q < mesh.nBones; ++q)
                {
                    pass.BoneMatrices[q] = mba.GetBone((short)(BoneLookupTable[mesh.startBone + q])).Matrix;
                }

                for (ushort t = mesh.startTriangle, k = 0; k < mesh.nTriangles; ++t, ++k)
                {
                    ushort index = indices[t];
                    pass.Vertices[k]     = Vertices[index];
                    pass.Vertices[k].bi1 = (byte)(Vertices[i].bi1);
                    pass.Vertices[k].bi2 = (byte)(Vertices[i].bi2);
                    pass.Vertices[k].bi3 = (byte)(Vertices[i].bi3);
                    pass.Vertices[k].bi4 = (byte)(Vertices[i].bi4);
                }

                pass.SetVertexIndices();
                Passes.Add(pass);
            }

            Passes.Sort((g1, g2) =>
            {
                if (g1.BlendMode.blend == 2 && g2.BlendMode.blend != 2)
                {
                    return(1);
                }
                if (g2.BlendMode.blend == 2 && g1.BlendMode.blend != 2)
                {
                    return(-1);
                }

                if (g1.BlendMode.blend < g2.BlendMode.blend)
                {
                    return(-1);
                }
                if (g2.BlendMode.blend < g1.BlendMode.blend)
                {
                    return(1);
                }

                if (g1.Index == g2.Index)
                {
                    return(0);
                }
                if (g1.Index < g2.Index)
                {
                    return(-1);
                }
                if (g1.Index > g2.Index)
                {
                    return(1);
                }
                return(0);
            }
                        );

            BoneAnimator = mba;
        }