public static void ReplaceMorph(string destMorphName, odfParser parser, WorkspaceMorph wsMorphList, string newMorphName, bool replaceNormals, float minSquaredDistance) { odfMorphSection morphSection = parser.MorphSection; if (morphSection == null) { Report.ReportLog("The .odf file doesn't have a morph section. Skipping these morphs"); return; } odfMorphObject morphObj = odf.FindMorphObject(destMorphName, morphSection); if (morphObj == null) { Report.ReportLog("Couldn't find morph object " + destMorphName + ". Skipping these morphs"); return; } Report.ReportLog("Replacing morphs ..."); try { ushort[] meshIndices = morphObj.MeshIndices; foreach (ImportedMorphKeyframe wsMorph in wsMorphList.KeyframeList) { if (!wsMorphList.isMorphKeyframeEnabled(wsMorph)) continue; odfMorphProfile profile = odf.FindMorphProfile(wsMorph.Name, morphObj); if (profile == null) { Report.ReportLog("Warning: Couldn't find morph profile " + wsMorph.Name + ". Skipping this morph"); continue; } List<ImportedVertex> vertList = wsMorph.VertexList; for (int i = 0; i < meshIndices.Length; i++) { Vector3 orgPos = new Vector3(profile.VertexList[i].Position.X, profile.VertexList[i].Position.Y, profile.VertexList[i].Position.Z), newPos = new Vector3(vertList[meshIndices[i]].Position.X, vertList[meshIndices[i]].Position.Y, vertList[meshIndices[i]].Position.Z); if ((orgPos - newPos).LengthSquared() >= minSquaredDistance) profile.VertexList[i].Position = vertList[meshIndices[i]].Position; if (replaceNormals) { profile.VertexList[i].Normal = vertList[meshIndices[i]].Normal; } } string morphNewName = wsMorphList.getMorphKeyframeNewName(wsMorph); if (morphNewName != String.Empty) { profile.Name = new ObjectName(morphNewName, null); } } if (newMorphName != String.Empty) { morphObj.Name = new ObjectName(newMorphName, null); } } catch (Exception ex) { Utility.ReportException(ex); } }
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); } }
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); } }
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); } }