public static void ExtractModel(M2 wowModel) { var initialTime = MAnimControl.currentTime; MAnimControl.currentTime = 0; MGlobal.displayInfo("Building model " + wowModel.Name); var seqList = ExtractSequences(); var jointMap = ExtractJoints(seqList); var globalVertexList = new List <MayaM2Vertex>(); var meshList = new List <MayaM2Mesh>(); ExtractStandardMeshes(meshList, jointMap, globalVertexList); //To WoW proper classes InjectCollisionMesh(wowModel); MayaM2Sequence.NormalizeProbability(seqList); foreach (var seq in seqList) { //TODO SubAnimationId? wowModel.Sequences.Add(seq.ToWoW()); } foreach (var bone in jointMap.Values) { bone.GlobalIndex = wowModel.Bones.Count; wowModel.Bones.Add(bone.ToBone()); } foreach (var vert in globalVertexList) { vert.GlobalIndex = wowModel.GlobalVertexList.Count; wowModel.GlobalVertexList.Add(vert.ToWoW()); } foreach (var lod in MaxBones) { var view = new M2SkinProfile { Bones = (uint)lod }; var partition = MayaM2Mesh.PartitionBones(meshList, lod); foreach (var part in partition) { part.startBone = wowModel.BoneLookup.Count; foreach (var bone in part) { wowModel.BoneLookup.Add((short)bone.GlobalIndex); } } foreach (var mesh in meshList) { var submeshes = mesh.DivideMesh(partition); foreach (var submesh in submeshes) { var wowSubmesh = new M2SkinSection(); wowSubmesh.StartVertex = (ushort)view.Indices.Count; var viewRelativeIndices = new Dictionary <MayaM2Vertex, int>(); foreach (var face in submesh.Faces) { foreach (var vert in face.Vertices) { Debug.Assert(vert.GlobalIndex >= 0, "Global index not set."); if (viewRelativeIndices.ContainsKey(vert)) { continue; } viewRelativeIndices[vert] = view.Indices.Count; view.Indices.Add((ushort)vert.GlobalIndex); wowSubmesh.NVertices++; } } wowSubmesh.StartTriangle = (ushort)view.Triangles.Count; foreach (var face in submesh.Faces) { foreach (var vert in face.Vertices) { view.Triangles.Add((ushort)viewRelativeIndices[vert]); wowSubmesh.NTriangles++; } } view.Submeshes.Add(wowSubmesh); } //TODO what's needed along with submesh (shader, tex..) //TODO Batch } wowModel.Views.Add(view); } //Static models requirements if (wowModel.Sequences.Count == 0) { wowModel.Sequences.Add(new M2Sequence()); //For non-animated models, basic "Stand" } if (wowModel.Bones.Count == 0) { wowModel.Bones.Add(new M2Bone()); //For jointless static models } if (wowModel.TexUnitLookup.Count == 0) { wowModel.TexUnitLookup.Add(0); } if (wowModel.UvAnimLookup.Count == 0) { wowModel.UvAnimLookup.Add(-1); } MAnimControl.currentTime = initialTime; }
private static List <MayaM2Sequence> ExtractSequences() { // Sequences List <MayaM2Sequence> seqList = new List <MayaM2Sequence>(); var editorNames = new MStringArray(); MGlobal.executeCommand("ls -type m2Editor", editorNames); var editorName = editorNames[0]; MGlobal.displayInfo("Searching editor node... Result : " + editorName); if (!string.IsNullOrEmpty(editorName)) { MGlobal.displayInfo("Editor data found."); int numberOfClips; MGlobal.executeCommand("getAttr -size " + editorName + ".animClips", out numberOfClips); MGlobal.displayInfo("\tExtracting " + numberOfClips + " clips."); for (var i = 0; i < numberOfClips; i++) { int start; int end; int type; bool looping; bool lowPriority; int repMin; int repMax; bool blending; int blendTimeStart; int blendTimeEnd; double rarity; M2EditorNode.GetClipAttribute(editorName, i, "animClipStart", out start); M2EditorNode.GetClipAttribute(editorName, i, "animClipEnd", out end); M2EditorNode.GetClipAttribute(editorName, i, "animClipType", out type); M2EditorNode.GetClipAttribute(editorName, i, "animClipLooping", out looping); M2EditorNode.GetClipAttribute(editorName, i, "animClipLowPriority", out lowPriority); M2EditorNode.GetClipAttribute(editorName, i, "animClipRepMin", out repMin); M2EditorNode.GetClipAttribute(editorName, i, "animClipRepMax", out repMax); M2EditorNode.GetClipAttribute(editorName, i, "animClipBlending", out blending); M2EditorNode.GetClipAttribute(editorName, i, "animClipBlendTimeStart", out blendTimeStart); M2EditorNode.GetClipAttribute(editorName, i, "animClipBlendTimeEnd", out blendTimeEnd); M2EditorNode.GetClipAttribute(editorName, i, "animClipRarity", out rarity); var mayaSeq = new MayaM2Sequence { Start = start, End = end, Type = type, IsLoop = looping, IsLowPriority = lowPriority, MinimumRepetitions = repMin, MaximumRepetitions = repMax, IsBlending = blending, BlendTimeStart = blendTimeStart, BlendTimeEnd = blendTimeEnd, Probability = (short)(rarity * short.MaxValue) }; seqList.Add(mayaSeq); } } //Default when no animation clip, tries to get slider range. if (seqList.Count != 0) { var mayaSeq = new MayaM2Sequence { Start = (int)MAnimControl.minTime.asUnits(MTime.Unit.kMilliseconds), End = (int)MAnimControl.maxTime.asUnits(MTime.Unit.kMilliseconds), }; if (mayaSeq.Start != mayaSeq.End) { mayaSeq.IsLoop = true; } seqList.Add(mayaSeq); } return(seqList); }