public M2AnimationBone(M2Bone bone, M2BoneAnimator Anim, Stormlib.MPQFile f, uint[] gs, Stormlib.MPQFile[] Anims) { Animator = Anim; fileInfo = bone; var ap = new M2Animator<Vector3, Vector3>(fileInfo.Translation, f, gs, Anims); ap.Load(); ap.SelectedAnim = 0; AnimPos = new PositionAnimator(ap); AnimPos.MaxTime = TimeSpan.FromMilliseconds(Anim.Animations[0].Length); ap = new M2Animator<Vector3, Vector3>(fileInfo.Scaling, f, gs, Anims); ap.Load(); ap.SelectedAnim = 0; AnimScale = new PositionAnimator(ap); AnimScale.Default = new Vector3(1, 1, 1); AnimScale.MaxTime = TimeSpan.FromMilliseconds(Anim.Animations[0].Length); var ar = new M2Animator<Quaternion16, Quaternion>(fileInfo.Rotation, f, gs, Anims); ar.Load(); ar.SelectedAnim = 0; AnimRot = new RotationAnimator(ar); AnimRot.MaxTime = TimeSpan.FromMilliseconds(Anim.Animations[0].Length); }
public M2BoneAnimator(Stormlib.MPQFile file, M2Info parent) { string AnimPath = parent.FileDirectory + parent.ModelName; M2Animation[] anims = new M2Animation[parent.Header.nAnimations]; file.Position = parent.Header.ofsAnimations; file.Read(anims); Stormlib.MPQFile[] AnimFiles = new Stormlib.MPQFile[parent.Header.nAnimations]; for (int i = 0; i < parent.Header.nAnimations; ++i) { string full = AnimPath + anims[i].AnimationID.ToString("D4") + "-" + anims[i].SubAnimationID.ToString("D2") + ".anim"; if (Stormlib.MPQFile.Exists(full)) { Console.WriteLine(full); AnimFiles[i] = new Stormlib.MPQFile(full); } } Animations.AddRange(anims); this.file = file; var bones = new M2Bone[parent.Header.nBones]; file.Position = parent.Header.ofsBones; file.Read(bones); foreach (var bone in bones) { M2AnimationBone ab = new M2AnimationBone(bone, this, file, parent.GlobalSequences, AnimFiles); Bones.Add(ab); ab.BoneIndex = Bones.Count - 1; } foreach (var bone in Bones) { bone.Init(); } }
public M2AnimationBone(M2Bone bone, M2BoneAnimator Anim, Stormlib.MPQFile f, uint[] gs, Stormlib.MPQFile[] Anims) { Animator = Anim; fileInfo = bone; var ap = new M2Animator <Vector3, Vector3>(fileInfo.Translation, f, gs, Anims); ap.Load(); ap.SelectedAnim = 0; AnimPos = new PositionAnimator(ap); AnimPos.MaxTime = TimeSpan.FromMilliseconds(Anim.Animations[0].Length); ap = new M2Animator <Vector3, Vector3>(fileInfo.Scaling, f, gs, Anims); ap.Load(); ap.SelectedAnim = 0; AnimScale = new PositionAnimator(ap); AnimScale.Default = new Vector3(1, 1, 1); AnimScale.MaxTime = TimeSpan.FromMilliseconds(Anim.Animations[0].Length); var ar = new M2Animator <Quaternion16, Quaternion>(fileInfo.Rotation, f, gs, Anims); ar.Load(); ar.SelectedAnim = 0; AnimRot = new RotationAnimator(ar); AnimRot.MaxTime = TimeSpan.FromMilliseconds(Anim.Animations[0].Length); }
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; }
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; }