public void ReplaceAnimation(WorkspaceAnimation animation, int resampleCount, string method, int insertPos) { var replaceMethod = (ReplaceAnimationMethod)Enum.Parse(typeof(ReplaceAnimationMethod), method); ReplaceAnimation(animation, Parser, resampleCount, replaceMethod, insertPos); Changed = true; }
public static List<KeyValuePair<string, ImportedAnimationKeyframe[]>> CopyAnimation(WorkspaceAnimation wsAnimation, int resampleCount, bool linear) { List<KeyValuePair<string, ImportedAnimationKeyframe[]>> newTrackList = new List<KeyValuePair<string, ImportedAnimationKeyframe[]>>(wsAnimation.TrackList.Count); List<Tuple<ImportedAnimationTrack, ImportedAnimationKeyframe[]>> interpolateTracks = new List<Tuple<ImportedAnimationTrack, ImportedAnimationKeyframe[]>>(); foreach (var wsTrack in wsAnimation.TrackList) { if (!wsAnimation.isTrackEnabled(wsTrack)) continue; ImportedAnimationKeyframe[] newKeyframes; if (resampleCount < 0 || wsTrack.Keyframes.Length == resampleCount) { newKeyframes = new ImportedAnimationKeyframe[wsTrack.Keyframes.Length]; for (int i = 0; i < wsTrack.Keyframes.Length; i++) { ImportedAnimationKeyframe keyframe = wsTrack.Keyframes[i]; if (keyframe == null) continue; newKeyframes[i] = new ImportedAnimationKeyframe(); newKeyframes[i].Rotation = keyframe.Rotation; newKeyframes[i].Translation = keyframe.Translation; newKeyframes[i].Scaling = keyframe.Scaling; } } else { newKeyframes = new ImportedAnimationKeyframe[resampleCount]; if (wsTrack.Keyframes.Length < 1) { ImportedAnimationKeyframe keyframe = new ImportedAnimationKeyframe(); keyframe.Rotation = Quaternion.Identity; keyframe.Scaling = new Vector3(1, 1, 1); keyframe.Translation = new Vector3(0, 0, 0); for (int i = 0; i < newKeyframes.Length; i++) { newKeyframes[i] = keyframe; } } else { interpolateTracks.Add(new Tuple<ImportedAnimationTrack, ImportedAnimationKeyframe[]>(wsTrack, newKeyframes)); } } newTrackList.Add(new KeyValuePair<string, ImportedAnimationKeyframe[]>(wsTrack.Name, newKeyframes)); } if (resampleCount >= 0) { Fbx.InterpolateKeyframes(interpolateTracks, resampleCount, linear); } return newTrackList; }
public ImportedEditor(IImported imported) { Imported = imported; if (Imported.MaterialList != null && Imported.MaterialList.Count > 0) { Materials = new List <WorkspaceMaterial>(Imported.MaterialList.Count); foreach (ImportedMaterial mat in Imported.MaterialList) { WorkspaceMaterial wsMat = new WorkspaceMaterial(mat); Materials.Add(wsMat); } } if ((Imported.FrameList != null) && (Imported.FrameList.Count > 0)) { Frames = new List <ImportedFrame>(); foreach (var frame in Imported.FrameList) { InitFrames(frame); } } if (Imported.MeshList != null && Imported.MeshList.Count > 0) { Meshes = new List <WorkspaceMesh>(Imported.MeshList.Count); foreach (ImportedMesh mesh in Imported.MeshList) { WorkspaceMesh wsMesh = new WorkspaceMesh(mesh); Meshes.Add(wsMesh); } } if (Imported.MorphList != null && Imported.MorphList.Count > 0) { Morphs = new List <WorkspaceMorph>(Imported.MorphList.Count); foreach (ImportedMorph morph in Imported.MorphList) { WorkspaceMorph wsMorph = new WorkspaceMorph(morph); Morphs.Add(wsMorph); } } if (Imported.AnimationList != null && Imported.AnimationList.Count > 0) { Animations = new List <WorkspaceAnimation>(Imported.AnimationList.Count); foreach (ImportedAnimation animation in Imported.AnimationList) { WorkspaceAnimation wsAnimation = new WorkspaceAnimation(animation); Animations.Add(wsAnimation); } } }
public void setTrackEnabled(int animationId, int id, bool enabled) { WorkspaceAnimation wsAnim = this.Animations[animationId]; ImportedAnimationTrack track = null; if (wsAnim.importedAnimation is ImportedKeyframedAnimation) { track = ((ImportedKeyframedAnimation)wsAnim.importedAnimation).TrackList[id]; } else if (wsAnim.importedAnimation is ImportedSampledAnimation) { track = ((ImportedSampledAnimation)wsAnim.importedAnimation).TrackList[id]; } this.Animations[animationId].setTrackEnabled(track, enabled); }
public ImportedEditor(IImported imported) { Imported = imported; if ((Imported.FrameList != null) && (Imported.FrameList.Count > 0)) { Frames = new List<ImportedFrame>(); foreach (var frame in Imported.FrameList) { InitFrames(frame); } } if (Imported.MeshList != null && Imported.MeshList.Count > 0) { Meshes = new List<WorkspaceMesh>(Imported.MeshList.Count); foreach (ImportedMesh mesh in Imported.MeshList) { WorkspaceMesh wsMesh = new WorkspaceMesh(mesh); Meshes.Add(wsMesh); } } if (Imported.MorphList != null && Imported.MorphList.Count > 0) { Morphs = new List<WorkspaceMorph>(Imported.MorphList.Count); foreach (ImportedMorph morph in Imported.MorphList) { WorkspaceMorph wsMorph = new WorkspaceMorph(morph); Morphs.Add(wsMorph); } } if (Imported.AnimationList != null && Imported.AnimationList.Count > 0) { Animations = new List<WorkspaceAnimation>(Imported.AnimationList.Count); foreach (ImportedAnimation animation in Imported.AnimationList) { WorkspaceAnimation wsAnimation = new WorkspaceAnimation(animation); Animations.Add(wsAnimation); } } }
public static void ReplaceAnimation(WorkspaceAnimation wsAnimation, xaParser parser, int resampleCount, ReplaceAnimationMethod replaceMethod, int insertPos) { if (parser.AnimationSection == null) { Report.ReportLog("The .xa file doesn't have an animation section. Skipping this animation"); return; } if (!(wsAnimation.importedAnimation is ImportedKeyframedAnimation)) { Report.ReportLog("The animation has incompatible keyframes."); return; } Report.ReportLog("Replacing animation ..."); List<ImportedAnimationKeyframedTrack> trackList = ((ImportedKeyframedAnimation)wsAnimation.importedAnimation).TrackList; List<KeyValuePair<string, xaAnimationKeyframe[]>> newTrackList = new List<KeyValuePair<string, xaAnimationKeyframe[]>>(trackList.Count); List<Tuple<ImportedAnimationTrack, xaAnimationKeyframe[]>> interpolateTracks = new List<Tuple<ImportedAnimationTrack,xaAnimationKeyframe[]>>(); foreach (var wsTrack in trackList) { if (!wsAnimation.isTrackEnabled(wsTrack)) continue; ImportedAnimationKeyframe[] keyframes = ((ImportedAnimationKeyframedTrack)wsTrack).Keyframes; xaAnimationKeyframe[] newKeyframes = null; int wsTrackKeyframesLength = 0; for (int i = 0; i < keyframes.Length; i++) { if (keyframes[i] != null) wsTrackKeyframesLength++; } if (resampleCount < 0 || wsTrackKeyframesLength == resampleCount) { newKeyframes = new xaAnimationKeyframe[wsTrackKeyframesLength]; int keyframeIdx = 0; for (int i = 0; i < keyframes.Length; i++) { ImportedAnimationKeyframe keyframe = keyframes[i]; if (keyframe == null) continue; newKeyframes[keyframeIdx] = new xaAnimationKeyframe(); newKeyframes[keyframeIdx].Index = i; newKeyframes[keyframeIdx].Rotation = keyframe.Rotation; xa.CreateUnknowns(newKeyframes[keyframeIdx]); newKeyframes[keyframeIdx].Translation = keyframe.Translation; newKeyframes[keyframeIdx].Scaling = keyframe.Scaling; keyframeIdx++; } } else { newKeyframes = new xaAnimationKeyframe[resampleCount]; if (wsTrackKeyframesLength < 1) { xaAnimationKeyframe keyframe = new xaAnimationKeyframe(); keyframe.Rotation = Quaternion.Identity; keyframe.Scaling = new Vector3(1, 1, 1); keyframe.Translation = new Vector3(0, 0, 0); xa.CreateUnknowns(keyframe); for (int i = 0; i < newKeyframes.Length; i++) { keyframe.Index = i; newKeyframes[i] = keyframe; } } else { interpolateTracks.Add(new Tuple<ImportedAnimationTrack, xaAnimationKeyframe[]>(wsTrack, newKeyframes)); } } newTrackList.Add(new KeyValuePair<string, xaAnimationKeyframe[]>(wsTrack.Name, newKeyframes)); } if (interpolateTracks.Count > 0) { Fbx.InterpolateKeyframes(interpolateTracks, resampleCount); } List<xaAnimationTrack> animationNodeList = parser.AnimationSection.TrackList; Dictionary<string, xaAnimationTrack> animationNodeDic = null; if (replaceMethod != ReplaceAnimationMethod.Replace) { animationNodeDic = new Dictionary<string, xaAnimationTrack>(); foreach (xaAnimationTrack animationNode in animationNodeList) { animationNodeDic.Add(animationNode.Name, animationNode); } } if (replaceMethod == ReplaceAnimationMethod.Replace) { animationNodeList.Clear(); foreach (var newTrack in newTrackList) { xaAnimationTrack animationNode = new xaAnimationTrack(); animationNodeList.Add(animationNode); animationNode.KeyframeList = new List<xaAnimationKeyframe>(newTrack.Value); animationNode.Name = newTrack.Key; xa.CreateUnknowns(animationNode); } } else if (replaceMethod == ReplaceAnimationMethod.ReplacePresent) { foreach (var newTrack in newTrackList) { xaAnimationTrack animationNode = xa.animationGetOriginalKeyframes(animationNodeDic, newTrack.Key, animationNodeList); animationNode.KeyframeList = new List<xaAnimationKeyframe>(newTrack.Value); } } else if (replaceMethod == ReplaceAnimationMethod.Merge) { foreach (var newTrack in newTrackList) { xaAnimationTrack animationNode; xaAnimationKeyframe[] origKeyframes = xa.animationGetOriginalKeyframes(animationNodeDic, newTrack.Key, animationNodeList, out animationNode); xaAnimationKeyframe[] destKeyframes; int newEnd = insertPos + newTrack.Value.Length; if (origKeyframes.Length < insertPos) { destKeyframes = new xaAnimationKeyframe[newEnd]; xa.animationCopyKeyframeTransformArray(origKeyframes, 0, destKeyframes, 0, origKeyframes.Length); xa.animationNormalizeTrack(origKeyframes, destKeyframes, insertPos); } else { if (origKeyframes.Length < newEnd) { destKeyframes = new xaAnimationKeyframe[newEnd]; } else { destKeyframes = new xaAnimationKeyframe[origKeyframes.Length]; xa.animationCopyKeyframeTransformArray(origKeyframes, newEnd, destKeyframes, newEnd, origKeyframes.Length - newEnd); } xa.animationCopyKeyframeTransformArray(origKeyframes, 0, destKeyframes, 0, insertPos); } xa.animationCopyKeyframeTransformArray(newTrack.Value, 0, destKeyframes, insertPos, newTrack.Value.Length); animationNode.KeyframeList = new List<xaAnimationKeyframe>(destKeyframes); } } else if (replaceMethod == ReplaceAnimationMethod.Insert) { foreach (var newTrack in newTrackList) { xaAnimationTrack animationNode; xaAnimationKeyframe[] origKeyframes = xa.animationGetOriginalKeyframes(animationNodeDic, newTrack.Key, animationNodeList, out animationNode); ; xaAnimationKeyframe[] destKeyframes; int newEnd = insertPos + newTrack.Value.Length; if (origKeyframes.Length < insertPos) { destKeyframes = new xaAnimationKeyframe[newEnd]; xa.animationCopyKeyframeTransformArray(origKeyframes, 0, destKeyframes, 0, origKeyframes.Length); xa.animationNormalizeTrack(origKeyframes, destKeyframes, insertPos); } else { destKeyframes = new xaAnimationKeyframe[origKeyframes.Length + newTrack.Value.Length]; xa.animationCopyKeyframeTransformArray(origKeyframes, 0, destKeyframes, 0, insertPos); xa.animationCopyKeyframeTransformArray(origKeyframes, insertPos, destKeyframes, newEnd, origKeyframes.Length - insertPos); } xa.animationCopyKeyframeTransformArray(newTrack.Value, 0, destKeyframes, insertPos, newTrack.Value.Length); animationNode.KeyframeList = new List<xaAnimationKeyframe>(destKeyframes); } } else if (replaceMethod == ReplaceAnimationMethod.Append) { int maxKeyframes = 0; foreach (xaAnimationTrack animationNode in animationNodeList) { int numKeyframes = animationNode.KeyframeList[animationNode.KeyframeList.Count - 1].Index; if (numKeyframes > maxKeyframes) { maxKeyframes = numKeyframes; } } foreach (var newTrack in newTrackList) { xaAnimationTrack animationNode; xaAnimationKeyframe[] origKeyframes = xa.animationGetOriginalKeyframes(animationNodeDic, newTrack.Key, animationNodeList, out animationNode); xaAnimationKeyframe[] destKeyframes = new xaAnimationKeyframe[maxKeyframes + insertPos + newTrack.Value[newTrack.Value.Length - 1].Index + 1]; xa.animationCopyKeyframeTransformArray(origKeyframes, destKeyframes, 0); if (origKeyframes.Length > 0 && origKeyframes.Length == origKeyframes[origKeyframes.Length - 1].Index + 1) { xa.animationNormalizeTrack(origKeyframes, destKeyframes, origKeyframes.Length + insertPos); } xa.animationCopyKeyframeTransformArray(newTrack.Value, destKeyframes, maxKeyframes + insertPos); animationNode.KeyframeList = new List<xaAnimationKeyframe>(origKeyframes.Length + insertPos + newTrack.Value.Length); for (int i = 0; i < destKeyframes.Length; i++) { if (destKeyframes[i] == null) continue; animationNode.KeyframeList.Add(destKeyframes[i]); } } } else { Report.ReportLog("Error: Unexpected animation replace method " + replaceMethod + ". Skipping this animation"); return; } }
public static void UpdateAnimationNode(TreeNode node, WorkspaceAnimation animation) { int id = (int)((DragSource)node.Tag).Id; if (animation.importedAnimation is ImportedKeyframedAnimation) { node.Text = "Animation" + id; List <ImportedAnimationKeyframedTrack> trackList = ((ImportedKeyframedAnimation)animation.importedAnimation).TrackList; for (int i = 0; i < trackList.Count; i++) { ImportedAnimationKeyframedTrack track = trackList[i]; TreeNode trackNode = node.Nodes[i]; trackNode.Tag = track; int numKeyframes = 0; foreach (ImportedAnimationKeyframe keyframe in track.Keyframes) { if (keyframe != null) { numKeyframes++; } } trackNode.Text = "Track: " + track.Name + ", Keyframes: " + numKeyframes; } } else if (animation.importedAnimation is ImportedSampledAnimation) { node.Text = "Animation(Reduced Keys)" + id; List <ImportedAnimationSampledTrack> trackList = ((ImportedSampledAnimation)animation.importedAnimation).TrackList; for (int i = 0; i < trackList.Count; i++) { ImportedAnimationSampledTrack track = trackList[i]; TreeNode trackNode = node.Nodes[i]; trackNode.Tag = track; int numScalings = 0; for (int k = 0; k < track.Scalings.Length; k++) { if (track.Scalings[k] != null) { numScalings++; } } int numRotations = 0; for (int k = 0; k < track.Rotations.Length; k++) { if (track.Rotations[k] != null) { numRotations++; } } int numTranslations = 0; for (int k = 0; k < track.Translations.Length; k++) { if (track.Translations[k] != null) { numTranslations++; } } trackNode.Text = "Track: " + track.Name + ", Length: " + track.Scalings.Length + ", Scalings: " + numScalings + ", Rotations: " + numRotations + ", Translations: " + numTranslations; } } }
private void AddList <T>(List <T> list, string rootName, string editorVar) { if ((list != null) && (list.Count > 0)) { TreeNode root = new TreeNode(rootName); root.Checked = true; this.treeView.AddChild(root); for (int i = 0; i < list.Count; i++) { dynamic item = list[i]; TreeNode node = new TreeNode(item is WorkspaceAnimation ? ((WorkspaceAnimation)item).importedAnimation is ImportedKeyframedAnimation ? "Animation" + i : "Animation(Reduced Keys)" + i : item.Name); node.Checked = true; node.Tag = new DragSource(editorVar, typeof(T), i); this.treeView.AddChild(root, node); if (item is WorkspaceMesh) { WorkspaceMesh mesh = item; for (int j = 0; j < mesh.SubmeshList.Count; j++) { ImportedSubmesh submesh = mesh.SubmeshList[j]; TreeNode submeshNode = new TreeNode(); submeshNode.Checked = mesh.isSubmeshEnabled(submesh); submeshNode.Tag = submesh; submeshNode.ContextMenuStrip = this.contextMenuStripSubmesh; this.treeView.AddChild(node, submeshNode); UpdateSubmeshNode(submeshNode); } } else if (item is WorkspaceMorph) { WorkspaceMorph morph = item; string extraInfo = morph.MorphedVertexIndices != null ? " (morphed vertices: " + morph.MorphedVertexIndices.Count : String.Empty; extraInfo += (extraInfo.Length == 0 ? " (" : ", ") + "keyframes: " + morph.KeyframeList.Count + ")"; node.Text += extraInfo; for (int j = 0; j < morph.KeyframeList.Count; j++) { ImportedMorphKeyframe keyframe = morph.KeyframeList[j]; TreeNode keyframeNode = new TreeNode(); keyframeNode.Checked = morph.isMorphKeyframeEnabled(keyframe); keyframeNode.Tag = keyframe; keyframeNode.ContextMenuStrip = this.contextMenuStripMorphKeyframe; this.treeView.AddChild(node, keyframeNode); UpdateMorphKeyframeNode(keyframeNode); } } else if (item is WorkspaceAnimation) { WorkspaceAnimation animation = item; if (animation.importedAnimation is ImportedKeyframedAnimation) { List <ImportedAnimationKeyframedTrack> trackList = ((ImportedKeyframedAnimation)animation.importedAnimation).TrackList; for (int j = 0; j < trackList.Count; j++) { ImportedAnimationKeyframedTrack track = trackList[j]; TreeNode trackNode = new TreeNode(); trackNode.Checked = animation.isTrackEnabled(track); trackNode.Tag = track; int numKeyframes = 0; foreach (ImportedAnimationKeyframe keyframe in track.Keyframes) { if (keyframe != null) { numKeyframes++; } } trackNode.Text = "Track: " + track.Name + ", Keyframes: " + numKeyframes; this.treeView.AddChild(node, trackNode); } } else if (animation.importedAnimation is ImportedSampledAnimation) { List <ImportedAnimationSampledTrack> trackList = ((ImportedSampledAnimation)animation.importedAnimation).TrackList; for (int j = 0; j < trackList.Count; j++) { ImportedAnimationSampledTrack track = trackList[j]; TreeNode trackNode = new TreeNode(); trackNode.Checked = animation.isTrackEnabled(track); trackNode.Tag = track; int numScalings = 0; for (int k = 0; k < track.Scalings.Length; k++) { if (track.Scalings[k] != null) { numScalings++; } } int numRotations = 0; for (int k = 0; k < track.Rotations.Length; k++) { if (track.Rotations[k] != null) { numRotations++; } } int numTranslations = 0; for (int k = 0; k < track.Translations.Length; k++) { if (track.Translations[k] != null) { numTranslations++; } } trackNode.Text = "Track: " + track.Name + ", Length: " + track.Scalings.Length + ", Scalings: " + numScalings + ", Rotations: " + numRotations + ", Translations: " + numTranslations; this.treeView.AddChild(node, trackNode); } } } } } }
public static List <KeyValuePair <string, ImportedAnimationKeyframe[]> > CopyAnimation(WorkspaceAnimation wsAnimation, int resampleCount, bool linear) { List <KeyValuePair <string, ImportedAnimationKeyframe[]> > newTrackList = new List <KeyValuePair <string, ImportedAnimationKeyframe[]> >(wsAnimation.TrackList.Count); List <Tuple <ImportedAnimationTrack, ImportedAnimationKeyframe[]> > interpolateTracks = new List <Tuple <ImportedAnimationTrack, ImportedAnimationKeyframe[]> >(); foreach (var wsTrack in wsAnimation.TrackList) { if (!wsAnimation.isTrackEnabled(wsTrack)) { continue; } ImportedAnimationKeyframe[] newKeyframes; if (resampleCount < 0 || wsTrack.Keyframes.Length == resampleCount) { newKeyframes = new ImportedAnimationKeyframe[wsTrack.Keyframes.Length]; for (int i = 0; i < wsTrack.Keyframes.Length; i++) { ImportedAnimationKeyframe keyframe = wsTrack.Keyframes[i]; if (keyframe == null) { continue; } newKeyframes[i] = new ImportedAnimationKeyframe(); newKeyframes[i].Rotation = keyframe.Rotation; newKeyframes[i].Translation = keyframe.Translation; newKeyframes[i].Scaling = keyframe.Scaling; } } else { newKeyframes = new ImportedAnimationKeyframe[resampleCount]; if (wsTrack.Keyframes.Length < 1) { ImportedAnimationKeyframe keyframe = new ImportedAnimationKeyframe(); keyframe.Rotation = Quaternion.Identity; keyframe.Scaling = new Vector3(1, 1, 1); keyframe.Translation = new Vector3(0, 0, 0); for (int i = 0; i < newKeyframes.Length; i++) { newKeyframes[i] = keyframe; } } else { interpolateTracks.Add(new Tuple <ImportedAnimationTrack, ImportedAnimationKeyframe[]>(wsTrack, newKeyframes)); } } newTrackList.Add(new KeyValuePair <string, ImportedAnimationKeyframe[]>(wsTrack.Name, newKeyframes)); } if (resampleCount >= 0) { Fbx.InterpolateKeyframes(interpolateTracks, resampleCount, linear); } return(newTrackList); }
public static void ReplaceAnimation(WorkspaceAnimation wsAnimation, xaParser parser, int resampleCount, ReplaceAnimationMethod replaceMethod, int insertPos) { if (parser.AnimationSection == null) { Report.ReportLog("The .xa file doesn't have an animation section. Skipping this animation"); return; } if (!(wsAnimation.importedAnimation is ImportedKeyframedAnimation)) { Report.ReportLog("The animation has incompatible keyframes."); return; } Report.ReportLog("Replacing animation ..."); List <ImportedAnimationKeyframedTrack> trackList = ((ImportedKeyframedAnimation)wsAnimation.importedAnimation).TrackList; List <KeyValuePair <string, xaAnimationKeyframe[]> > newTrackList = new List <KeyValuePair <string, xaAnimationKeyframe[]> >(trackList.Count); List <Tuple <ImportedAnimationTrack, xaAnimationKeyframe[]> > interpolateTracks = new List <Tuple <ImportedAnimationTrack, xaAnimationKeyframe[]> >(); foreach (var wsTrack in trackList) { if (!wsAnimation.isTrackEnabled(wsTrack)) { continue; } ImportedAnimationKeyframe[] keyframes = ((ImportedAnimationKeyframedTrack)wsTrack).Keyframes; xaAnimationKeyframe[] newKeyframes = null; int wsTrackKeyframesLength = 0; for (int i = 0; i < keyframes.Length; i++) { if (keyframes[i] != null) { wsTrackKeyframesLength++; } } if (resampleCount < 0 || wsTrackKeyframesLength == resampleCount) { newKeyframes = new xaAnimationKeyframe[wsTrackKeyframesLength]; int keyframeIdx = 0; for (int i = 0; i < keyframes.Length; i++) { ImportedAnimationKeyframe keyframe = keyframes[i]; if (keyframe == null) { continue; } newKeyframes[keyframeIdx] = new xaAnimationKeyframe(); newKeyframes[keyframeIdx].Index = i; newKeyframes[keyframeIdx].Rotation = keyframe.Rotation; xa.CreateUnknowns(newKeyframes[keyframeIdx]); newKeyframes[keyframeIdx].Translation = keyframe.Translation; newKeyframes[keyframeIdx].Scaling = keyframe.Scaling; keyframeIdx++; } } else { newKeyframes = new xaAnimationKeyframe[resampleCount]; if (wsTrackKeyframesLength < 1) { xaAnimationKeyframe keyframe = new xaAnimationKeyframe(); keyframe.Rotation = Quaternion.Identity; keyframe.Scaling = new Vector3(1, 1, 1); keyframe.Translation = new Vector3(0, 0, 0); xa.CreateUnknowns(keyframe); for (int i = 0; i < newKeyframes.Length; i++) { keyframe.Index = i; newKeyframes[i] = keyframe; } } else { interpolateTracks.Add(new Tuple <ImportedAnimationTrack, xaAnimationKeyframe[]>(wsTrack, newKeyframes)); } } newTrackList.Add(new KeyValuePair <string, xaAnimationKeyframe[]>(wsTrack.Name, newKeyframes)); } if (interpolateTracks.Count > 0) { Fbx.InterpolateKeyframes(interpolateTracks, resampleCount); } List <xaAnimationTrack> animationNodeList = parser.AnimationSection.TrackList; Dictionary <string, xaAnimationTrack> animationNodeDic = null; if (replaceMethod != ReplaceAnimationMethod.Replace) { animationNodeDic = new Dictionary <string, xaAnimationTrack>(); foreach (xaAnimationTrack animationNode in animationNodeList) { animationNodeDic.Add(animationNode.Name, animationNode); } } if (replaceMethod == ReplaceAnimationMethod.Replace) { animationNodeList.Clear(); foreach (var newTrack in newTrackList) { xaAnimationTrack animationNode = new xaAnimationTrack(); animationNodeList.Add(animationNode); animationNode.KeyframeList = new List <xaAnimationKeyframe>(newTrack.Value); animationNode.Name = newTrack.Key; xa.CreateUnknowns(animationNode); } } else if (replaceMethod == ReplaceAnimationMethod.ReplacePresent) { foreach (var newTrack in newTrackList) { xaAnimationTrack animationNode = xa.animationGetOriginalKeyframes(animationNodeDic, newTrack.Key, animationNodeList); animationNode.KeyframeList = new List <xaAnimationKeyframe>(newTrack.Value); } } else if (replaceMethod == ReplaceAnimationMethod.Merge) { foreach (var newTrack in newTrackList) { xaAnimationTrack animationNode; xaAnimationKeyframe[] origKeyframes = xa.animationGetOriginalKeyframes(animationNodeDic, newTrack.Key, animationNodeList, out animationNode); xaAnimationKeyframe[] destKeyframes; int newEnd = insertPos + newTrack.Value.Length; if (origKeyframes.Length < insertPos) { destKeyframes = new xaAnimationKeyframe[newEnd]; xa.animationCopyKeyframeTransformArray(origKeyframes, 0, destKeyframes, 0, origKeyframes.Length); xa.animationNormalizeTrack(origKeyframes, destKeyframes, insertPos); } else { if (origKeyframes.Length < newEnd) { destKeyframes = new xaAnimationKeyframe[newEnd]; } else { destKeyframes = new xaAnimationKeyframe[origKeyframes.Length]; xa.animationCopyKeyframeTransformArray(origKeyframes, newEnd, destKeyframes, newEnd, origKeyframes.Length - newEnd); } xa.animationCopyKeyframeTransformArray(origKeyframes, 0, destKeyframes, 0, insertPos); } xa.animationCopyKeyframeTransformArray(newTrack.Value, 0, destKeyframes, insertPos, newTrack.Value.Length); animationNode.KeyframeList = new List <xaAnimationKeyframe>(destKeyframes); } } else if (replaceMethod == ReplaceAnimationMethod.Insert) { foreach (var newTrack in newTrackList) { xaAnimationTrack animationNode; xaAnimationKeyframe[] origKeyframes = xa.animationGetOriginalKeyframes(animationNodeDic, newTrack.Key, animationNodeList, out animationNode);; xaAnimationKeyframe[] destKeyframes; int newEnd = insertPos + newTrack.Value.Length; if (origKeyframes.Length < insertPos) { destKeyframes = new xaAnimationKeyframe[newEnd]; xa.animationCopyKeyframeTransformArray(origKeyframes, 0, destKeyframes, 0, origKeyframes.Length); xa.animationNormalizeTrack(origKeyframes, destKeyframes, insertPos); } else { destKeyframes = new xaAnimationKeyframe[origKeyframes.Length + newTrack.Value.Length]; xa.animationCopyKeyframeTransformArray(origKeyframes, 0, destKeyframes, 0, insertPos); xa.animationCopyKeyframeTransformArray(origKeyframes, insertPos, destKeyframes, newEnd, origKeyframes.Length - insertPos); } xa.animationCopyKeyframeTransformArray(newTrack.Value, 0, destKeyframes, insertPos, newTrack.Value.Length); animationNode.KeyframeList = new List <xaAnimationKeyframe>(destKeyframes); } } else if (replaceMethod == ReplaceAnimationMethod.Append) { int maxKeyframes = 0; foreach (xaAnimationTrack animationNode in animationNodeList) { int numKeyframes = animationNode.KeyframeList[animationNode.KeyframeList.Count - 1].Index; if (numKeyframes > maxKeyframes) { maxKeyframes = numKeyframes; } } foreach (var newTrack in newTrackList) { xaAnimationTrack animationNode; xaAnimationKeyframe[] origKeyframes = xa.animationGetOriginalKeyframes(animationNodeDic, newTrack.Key, animationNodeList, out animationNode); xaAnimationKeyframe[] destKeyframes = new xaAnimationKeyframe[maxKeyframes + insertPos + newTrack.Value[newTrack.Value.Length - 1].Index + 1]; xa.animationCopyKeyframeTransformArray(origKeyframes, destKeyframes, 0); if (origKeyframes.Length > 0 && origKeyframes.Length == origKeyframes[origKeyframes.Length - 1].Index + 1) { xa.animationNormalizeTrack(origKeyframes, destKeyframes, origKeyframes.Length + insertPos); } xa.animationCopyKeyframeTransformArray(newTrack.Value, destKeyframes, maxKeyframes + insertPos); animationNode.KeyframeList = new List <xaAnimationKeyframe>(origKeyframes.Length + insertPos + newTrack.Value.Length); for (int i = 0; i < destKeyframes.Length; i++) { if (destKeyframes[i] == null) { continue; } animationNode.KeyframeList.Add(destKeyframes[i]); } } } else { Report.ReportLog("Error: Unexpected animation replace method " + replaceMethod + ". Skipping this animation"); return; } }
private void AddList <T>(List <T> list, string rootName, string editorVar) { if ((list != null) && (list.Count > 0)) { TreeNode root = new TreeNode(rootName); root.Checked = true; this.treeView.AddChild(root); for (int i = 0; i < list.Count; i++) { dynamic item = list[i]; TreeNode node = new TreeNode(item is WorkspaceAnimation ? "Animation" + i : item.Name); node.Checked = true; node.Tag = new DragSource(editorVar, typeof(T), i); this.treeView.AddChild(root, node); if (item is WorkspaceMesh) { WorkspaceMesh mesh = item; for (int j = 0; j < mesh.SubmeshList.Count; j++) { ImportedSubmesh submesh = mesh.SubmeshList[j]; TreeNode submeshNode = new TreeNode(); submeshNode.Checked = mesh.isSubmeshEnabled(submesh); submeshNode.Tag = submesh; submeshNode.ContextMenuStrip = this.contextMenuStripSubmesh; this.treeView.AddChild(node, submeshNode); UpdateSubmeshNode(submeshNode); } } else if (item is WorkspaceMorph) { WorkspaceMorph morph = item; for (int j = 0; j < morph.KeyframeList.Count; j++) { ImportedMorphKeyframe keyframe = morph.KeyframeList[j]; TreeNode keyframeNode = new TreeNode(); keyframeNode.Checked = morph.isMorphKeyframeEnabled(keyframe); keyframeNode.Tag = keyframe; keyframeNode.ContextMenuStrip = this.contextMenuStripMorphKeyframe; this.treeView.AddChild(node, keyframeNode); UpdateMorphKeyframeNode(keyframeNode); } } else if (item is WorkspaceAnimation) { WorkspaceAnimation animation = item; for (int j = 0; j < animation.TrackList.Count; j++) { ImportedAnimationTrack track = animation.TrackList[j]; TreeNode trackNode = new TreeNode(); trackNode.Checked = animation.isTrackEnabled(track); trackNode.Tag = track; int numKeyframes = 0; foreach (ImportedAnimationKeyframe keyframe in track.Keyframes) { if (keyframe != null) { numKeyframes++; } } trackNode.Text = "Track: " + track.Name + ", Keyframes: " + numKeyframes; this.treeView.AddChild(node, trackNode); } } } } }
public static List <KeyValuePair <string, ImportedAnimationSampledTrack> > CopySampledAnimation(WorkspaceAnimation wsAnimation, int resampleCount, bool linear, bool EulerFilter, float filterPrecision, bool forceInterpolation = false) { List <ImportedAnimationSampledTrack> trackList = ((ImportedSampledAnimation)wsAnimation.importedAnimation).TrackList; List <KeyValuePair <string, ImportedAnimationSampledTrack> > newTrackList = new List <KeyValuePair <string, ImportedAnimationSampledTrack> >(trackList.Count); List <Tuple <ImportedAnimationTrack, ImportedAnimationSampledTrack> > interpolateTracks = new List <Tuple <ImportedAnimationTrack, ImportedAnimationSampledTrack> >(); foreach (var wsTrack in trackList) { if (!wsAnimation.isTrackEnabled(wsTrack)) { continue; } ImportedAnimationSampledTrack track = new ImportedAnimationSampledTrack(); bool interpolateTrack = forceInterpolation; Vector3?[] newScalings = null; Quaternion?[] newRotations = null; Vector3?[] newTranslations = null; if (!interpolateTrack) { Vector3?[] scalings = wsTrack.Scalings; if (scalings != null) { if (resampleCount < 0 || scalings.Length == resampleCount) { newScalings = new Vector3?[scalings.Length]; for (int i = 0; i < scalings.Length; i++) { Vector3?scale = scalings[i]; if (scale == null) { continue; } newScalings[i] = scale.Value; } } else { if (scalings.Length < 1) { newScalings = new Vector3?[resampleCount]; for (int i = 0; i < newScalings.Length; i++) { newScalings[i] = new Vector3(1, 1, 1); } } else { interpolateTrack = true; } } } Quaternion?[] rotations = wsTrack.Rotations; if (rotations != null) { if (resampleCount < 0 || rotations.Length == resampleCount) { newRotations = new Quaternion?[rotations.Length]; for (int i = 0; i < rotations.Length; i++) { Quaternion?rotate = rotations[i]; if (rotate == null) { continue; } newRotations[i] = rotate.Value; } } else { if (rotations.Length < 1) { newRotations = new Quaternion?[resampleCount]; for (int i = 0; i < newRotations.Length; i++) { newRotations[i] = Quaternion.Identity; } } else { interpolateTrack = true; } } } Vector3?[] translations = wsTrack.Translations; if (translations != null) { if (resampleCount < 0 || translations.Length == resampleCount) { newTranslations = new Vector3?[translations.Length]; for (int i = 0; i < translations.Length; i++) { Vector3?translate = translations[i]; if (translate == null) { continue; } newTranslations[i] = translate.Value; } } else { if (translations.Length < 1) { newTranslations = new Vector3?[resampleCount]; for (int i = 0; i < newTranslations.Length; i++) { newTranslations[i] = new Vector3(0, 0, 0); } } else { interpolateTrack = true; } } } } if (interpolateTrack) { interpolateTracks.Add(new Tuple <ImportedAnimationTrack, ImportedAnimationSampledTrack>(wsTrack, track)); } track.Scalings = newScalings; track.Rotations = newRotations; track.Translations = newTranslations; newTrackList.Add(new KeyValuePair <string, ImportedAnimationSampledTrack>(wsTrack.Name, track)); } if (interpolateTracks.Count > 0) { Fbx.InterpolateSampledTracks(interpolateTracks, resampleCount, linear, EulerFilter, filterPrecision); } return(newTrackList); }