public static void Export(string dirPath, xxParser xxParser, xxFrame meshFrame, xaParser xaParser, xaMorphClip clip) { DirectoryInfo dir = new DirectoryInfo(dirPath); ExporterMorph exporter = new ExporterMorph(dir, xxParser, xaParser, clip); exporter.Export(dir, meshFrame); }
private ExporterMorph(DirectoryInfo dir, xxParser xxParser, xaParser xaParser, xaMorphClip clip) { this.xxParser = xxParser; this.xaParser = xaParser; this.clip = clip; }
public static void ExportMorphMqo([DefaultVar] string dirPath, xxParser xxparser, xxFrame meshFrame, xaParser xaparser, xaMorphClip clip) { Mqo.ExporterMorph.Export(dirPath, xxparser, meshFrame, xaparser, clip); }
public static void ExportMorphFbx([DefaultVar] xxParser xxparser, string path, xxFrame meshFrame, xaParser xaparser, xaMorphClip morphClip, string exportFormat, bool oneBlendShape) { Fbx.Exporter.ExportMorph(path, xxparser, meshFrame, morphClip, xaparser, exportFormat, oneBlendShape); }
protected xaMorphSection ParseMorphSection() { if (reader.ReadByte() == 0) { return(null); } xaMorphSection section = new xaMorphSection(); int numIndexSets = reader.ReadInt32(); section.IndexSetList = new List <xaMorphIndexSet>(numIndexSets); for (int i = 0; i < numIndexSets; i++) { xaMorphIndexSet indexSet = new xaMorphIndexSet(); section.IndexSetList.Add(indexSet); indexSet.Unknown1 = reader.ReadBytes(1); int numVertices = reader.ReadInt32(); indexSet.MeshIndices = reader.ReadUInt16Array(numVertices); indexSet.MorphIndices = reader.ReadUInt16Array(numVertices); indexSet.Name = reader.ReadName(); } int numKeyframes = reader.ReadInt32(); section.KeyframeList = new List <xaMorphKeyframe>(numKeyframes); for (int i = 0; i < numKeyframes; i++) { xaMorphKeyframe keyframe = new xaMorphKeyframe(); section.KeyframeList.Add(keyframe); int numVertices = reader.ReadInt32(); keyframe.PositionList = new List <Vector3>(numVertices); keyframe.NormalList = new List <Vector3>(numVertices); for (int j = 0; j < numVertices; j++) { keyframe.PositionList.Add(reader.ReadVector3()); } for (int j = 0; j < numVertices; j++) { keyframe.NormalList.Add(reader.ReadVector3()); } keyframe.Name = reader.ReadName(); } int numClips = reader.ReadInt32(); section.ClipList = new List <xaMorphClip>(numClips); for (int i = 0; i < numClips; i++) { xaMorphClip clip = new xaMorphClip(); section.ClipList.Add(clip); clip.MeshName = reader.ReadName(); clip.Name = reader.ReadName(); int numKeyframeRefs = reader.ReadInt32(); clip.KeyframeRefList = new List <xaMorphKeyframeRef>(numKeyframeRefs); for (int j = 0; j < numKeyframeRefs; j++) { xaMorphKeyframeRef keyframeRef = new xaMorphKeyframeRef(); clip.KeyframeRefList.Add(keyframeRef); keyframeRef.Unknown1 = reader.ReadBytes(1); keyframeRef.Index = reader.ReadInt32(); keyframeRef.Unknown2 = reader.ReadBytes(1); keyframeRef.Name = reader.ReadName(); } clip.Unknown1 = reader.ReadBytes(4); } return(section); }
public static void ReplaceMorph(string destMorphName, xaParser parser, WorkspaceMorph wsMorphList, string newMorphName, bool replaceMorphMask, bool replaceNormals, float minSquaredDistance, bool minKeyframes) { if (parser.MorphSection == null) { Report.ReportLog("The .xa file doesn't have a morph section. Skipping these morphs"); return; } xaMorphSection morphSection = parser.MorphSection; xaMorphIndexSet indices = FindMorphIndexSet(destMorphName, morphSection); if (indices == null) { Report.ReportLog("Couldn't find morph clip " + destMorphName + ". Skipping these morphs"); return; } if (replaceMorphMask && wsMorphList.MorphedVertexIndices != null) { int index = morphSection.IndexSetList.IndexOf(indices); xaMorphIndexSet newIndices = new xaMorphIndexSet(); newIndices.Name = indices.Name; int numMorphedVertices = wsMorphList.MorphedVertexIndices.Count; newIndices.MeshIndices = new ushort[numMorphedVertices]; wsMorphList.MorphedVertexIndices.CopyTo(newIndices.MeshIndices); newIndices.MorphIndices = new ushort[numMorphedVertices]; if (minKeyframes) { for (ushort i = 0; i < numMorphedVertices; i++) { newIndices.MorphIndices[i] = i; } } else { wsMorphList.MorphedVertexIndices.CopyTo(newIndices.MorphIndices); } newIndices.Unknown1 = indices.Unknown1; morphSection.IndexSetList.RemoveAt(index); morphSection.IndexSetList.Insert(index, newIndices); indices = newIndices; } Report.ReportLog("Replacing morphs ..."); try { ushort[] meshIndices = indices.MeshIndices; ushort[] morphIndices = indices.MorphIndices; foreach (ImportedMorphKeyframe wsMorph in wsMorphList.KeyframeList) { if (!wsMorphList.isMorphKeyframeEnabled(wsMorph)) { continue; } List <ImportedVertex> vertList = wsMorph.VertexList; xaMorphKeyframe keyframe = FindMorphKeyFrame(wsMorph.Name, morphSection); if (keyframe == null) { Report.ReportLog("Adding new Keyframe " + wsMorph.Name); keyframe = new xaMorphKeyframe(); keyframe.Name = wsMorph.Name; int numVertices = minKeyframes ? meshIndices.Length : wsMorph.VertexList.Count; keyframe.PositionList = new List <Vector3>(new Vector3[numVertices]); keyframe.NormalList = new List <Vector3>(new Vector3[numVertices]); for (int i = 0; i < meshIndices.Length; i++) { keyframe.PositionList[morphIndices[i]] = vertList[meshIndices[i]].Position; keyframe.NormalList[morphIndices[i]] = vertList[meshIndices[i]].Normal; } morphSection.KeyframeList.Add(keyframe); } else { if (!minKeyframes && keyframe.PositionList.Count != vertList.Count || minKeyframes && keyframe.PositionList.Count != meshIndices.Length) { Report.ReportLog("Adapting Keyframe " + wsMorph.Name + " to new length."); int length = minKeyframes ? meshIndices.Length : vertList.Count; Vector3[] newPositions = new Vector3[length]; Vector3[] newNormals = new Vector3[length]; if (!minKeyframes) { for (int i = 0; i < vertList.Count; i++) { newPositions[i] = vertList[i].Position; newNormals[i] = vertList[i].Normal; } } for (int i = 0; i < meshIndices.Length; i++) { newPositions[morphIndices[i]] = vertList[meshIndices[i]].Position; newNormals[morphIndices[i]] = vertList[meshIndices[i]].Normal; } keyframe.PositionList.Clear(); keyframe.NormalList.Clear(); keyframe.PositionList.AddRange(newPositions); keyframe.NormalList.AddRange(newNormals); } else { Report.ReportLog("Replacing Keyframe " + wsMorph.Name); for (int i = 0; i < meshIndices.Length; i++) { Vector3 orgPos = new Vector3(keyframe.PositionList[morphIndices[i]].X, keyframe.PositionList[morphIndices[i]].Y, keyframe.PositionList[morphIndices[i]].Z), newPos = new Vector3(vertList[meshIndices[i]].Position.X, vertList[meshIndices[i]].Position.Y, vertList[meshIndices[i]].Position.Z); if ((orgPos - newPos).LengthSquared() >= minSquaredDistance) { keyframe.PositionList[morphIndices[i]] = vertList[meshIndices[i]].Position; if (replaceNormals) { keyframe.NormalList[morphIndices[i]] = vertList[meshIndices[i]].Normal; } } } } } string morphNewName = wsMorphList.getMorphKeyframeNewName(wsMorph); if (morphNewName != String.Empty) { for (int i = 0; i < morphSection.ClipList.Count; i++) { xaMorphClip clip = morphSection.ClipList[i]; for (int j = 0; j < clip.KeyframeRefList.Count; j++) { xaMorphKeyframeRef keyframeRef = clip.KeyframeRefList[j]; if (keyframeRef.Name == wsMorph.Name) { keyframeRef.Name = morphNewName; } } } keyframe.Name = morphNewName; } } if (newMorphName != String.Empty) { for (int i = 0; i < morphSection.ClipList.Count; i++) { xaMorphClip clip = morphSection.ClipList[i]; if (clip.Name == destMorphName) { clip.Name = newMorphName; break; } } indices.Name = newMorphName; } } catch (Exception ex) { Report.ReportLog("Error replacing morphs: " + ex.Message); } }
public static void ReplaceMorph(string destMorphName, xaParser parser, WorkspaceMorph wsMorphList, string newMorphName, bool replaceNormals, float minSquaredDistance) { if (parser.MorphSection == null) { Report.ReportLog("The .xa file doesn't have a morph section. Skipping these morphs"); return; } xaMorphSection morphSection = parser.MorphSection; xaMorphIndexSet indices = FindMorphIndexSet(destMorphName, morphSection); if (indices == null) { Report.ReportLog("Couldn't find morph clip " + destMorphName + ". Skipping these morphs"); return; } Report.ReportLog("Replacing morphs ..."); try { ushort[] meshIndices = indices.MeshIndices; ushort[] morphIndices = indices.MorphIndices; foreach (ImportedMorphKeyframe wsMorph in wsMorphList.KeyframeList) { if (!wsMorphList.isMorphKeyframeEnabled(wsMorph)) { continue; } List <ImportedVertex> vertList = wsMorph.VertexList; xaMorphKeyframe keyframe = FindMorphKeyFrame(wsMorph.Name, morphSection); if (keyframe == null) { keyframe = new xaMorphKeyframe(); keyframe.Name = wsMorph.Name; keyframe.PositionList = new List <Vector3>(new Vector3[wsMorph.VertexList.Count]); keyframe.NormalList = new List <Vector3>(new Vector3[wsMorph.VertexList.Count]); for (int i = 0; i < meshIndices.Length; i++) { keyframe.PositionList[morphIndices[i]] = vertList[meshIndices[i]].Position; keyframe.NormalList[morphIndices[i]] = vertList[meshIndices[i]].Normal; } morphSection.KeyframeList.Add(keyframe); } else { for (int i = 0; i < meshIndices.Length; i++) { Vector3 orgPos = new Vector3(keyframe.PositionList[morphIndices[i]].X, keyframe.PositionList[morphIndices[i]].Y, keyframe.PositionList[morphIndices[i]].Z), newPos = new Vector3(vertList[meshIndices[i]].Position.X, vertList[meshIndices[i]].Position.Y, vertList[meshIndices[i]].Position.Z); if ((orgPos - newPos).LengthSquared() >= minSquaredDistance) { keyframe.PositionList[morphIndices[i]] = vertList[meshIndices[i]].Position; if (replaceNormals) { keyframe.NormalList[morphIndices[i]] = vertList[meshIndices[i]].Normal; } } } } string morphNewName = wsMorphList.getMorphKeyframeNewName(wsMorph); if (morphNewName != String.Empty) { for (int i = 0; i < morphSection.ClipList.Count; i++) { xaMorphClip clip = morphSection.ClipList[i]; for (int j = 0; j < clip.KeyframeRefList.Count; j++) { xaMorphKeyframeRef keyframeRef = clip.KeyframeRefList[j]; if (keyframeRef.Name == wsMorph.Name) { keyframeRef.Name = morphNewName; } } } keyframe.Name = morphNewName; } } if (newMorphName != String.Empty) { for (int i = 0; i < morphSection.ClipList.Count; i++) { xaMorphClip clip = morphSection.ClipList[i]; if (clip.Name == destMorphName) { clip.Name = newMorphName; break; } } indices.Name = newMorphName; } } catch (Exception ex) { Report.ReportLog("Error replacing morphs: " + ex.Message); } }