private void treeView_AfterCheck(object sender, TreeViewEventArgs e) { if (e.Node.Tag is ImportedSubmesh) { TreeNode submeshNode = e.Node; ImportedSubmesh submesh = (ImportedSubmesh)submeshNode.Tag; TreeNode meshNode = submeshNode.Parent; DragSource dragSrc = (DragSource)meshNode.Tag; var srcEditor = (ImportedEditor)Gui.Scripting.Variables[dragSrc.Variable]; srcEditor.Meshes[(int)dragSrc.Id].setSubmeshEnabled(submesh, submeshNode.Checked); } else if (e.Node.Tag is ImportedMorphKeyframe) { TreeNode keyframeNode = e.Node; ImportedMorphKeyframe keyframe = (ImportedMorphKeyframe)keyframeNode.Tag; TreeNode morphNode = keyframeNode.Parent; DragSource dragSrc = (DragSource)morphNode.Tag; var srcEditor = (ImportedEditor)Gui.Scripting.Variables[dragSrc.Variable]; srcEditor.Morphs[(int)dragSrc.Id].setMorphKeyframeEnabled(keyframe, keyframeNode.Checked); } else if (e.Node.Tag is ImportedAnimationTrack) { TreeNode trackNode = e.Node; ImportedAnimationTrack track = (ImportedAnimationTrack)trackNode.Tag; TreeNode animationNode = trackNode.Parent; DragSource dragSrc = (DragSource)animationNode.Tag; var srcEditor = (ImportedEditor)Gui.Scripting.Variables[dragSrc.Variable]; srcEditor.Animations[(int)dragSrc.Id].setTrackEnabled(track, trackNode.Checked); } }
public WorkspaceAnimation(ImportedAnimation importedAnimation) : base() { this.importedAnimation = importedAnimation; if (importedAnimation is ImportedKeyframedAnimation) { List <ImportedAnimationKeyframedTrack> importedTrackList = ((ImportedKeyframedAnimation)importedAnimation).TrackList; this.TrackOptions = new Dictionary <ImportedAnimationTrack, AdditionalTrackOptions>(importedTrackList.Count); for (int i = 0; i < importedTrackList.Count; i++) { ImportedAnimationTrack track = importedTrackList[i]; AdditionalTrackOptions options = new AdditionalTrackOptions(); this.TrackOptions.Add(track, options); } } else if (importedAnimation is ImportedSampledAnimation) { List <ImportedAnimationSampledTrack> importedTrackList = ((ImportedSampledAnimation)importedAnimation).TrackList; this.TrackOptions = new Dictionary <ImportedAnimationTrack, AdditionalTrackOptions>(importedTrackList.Count); for (int i = 0; i < importedTrackList.Count; i++) { ImportedAnimationTrack track = importedTrackList[i]; AdditionalTrackOptions options = new AdditionalTrackOptions(); this.TrackOptions.Add(track, options); } } }
public bool isTrackEnabled(ImportedAnimationTrack track) { AdditionalTrackOptions options; if (this.TrackOptions.TryGetValue(track, out options)) { return(options.Enabled); } throw new Exception("Track " + track.Name + " not found"); }
public void setTrackEnabled(ImportedAnimationTrack track, bool enabled) { AdditionalTrackOptions options; if (this.TrackOptions.TryGetValue(track, out options)) { options.Enabled = enabled; return; } throw new Exception("Track " + track.Name + " not found"); }
public void SetAnimation(ImportedAnimation importedAnimation) { if (importedAnimation is ImportedKeyframedAnimation) { List <ImportedAnimationKeyframedTrack> importedTrackList = ((ImportedKeyframedAnimation)importedAnimation).TrackList; for (int i = 0; i < importedTrackList.Count; i++) { ImportedAnimationTrack track = importedTrackList[i]; foreach (KeyValuePair <ImportedAnimationTrack, AdditionalTrackOptions> pair in this.TrackOptions) { if (pair.Key.Name == track.Name) { this.TrackOptions.Remove(pair.Key); this.TrackOptions.Add(track, pair.Value); track = null; break; } } if (track != null) { AdditionalTrackOptions options = new AdditionalTrackOptions(); this.TrackOptions.Add(track, options); } } } else if (importedAnimation is ImportedSampledAnimation) { List <ImportedAnimationSampledTrack> importedTrackList = ((ImportedSampledAnimation)importedAnimation).TrackList; for (int i = 0; i < importedTrackList.Count; i++) { ImportedAnimationTrack track = importedTrackList[i]; foreach (KeyValuePair <ImportedAnimationTrack, AdditionalTrackOptions> pair in this.TrackOptions) { if (pair.Key.Name == track.Name) { this.TrackOptions.Remove(pair.Key); this.TrackOptions.Add(track, pair.Value); track = null; break; } } if (track != null) { AdditionalTrackOptions options = new AdditionalTrackOptions(); this.TrackOptions.Add(track, options); } } } this.importedAnimation = importedAnimation; }
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 static ImportedAnimationKeyframe[] animationGetOriginalKeyframes(Dictionary <string, ImportedAnimationTrack> animationNodeDic, string trackName, ImportedAnimation anim, out ImportedAnimationTrack animationNode) { ImportedAnimationKeyframe[] origKeyframes; if (animationNodeDic.TryGetValue(trackName, out animationNode)) { origKeyframes = animationNode.Keyframes; } else { animationNode = new ImportedAnimationTrack(); anim.TrackList.Add(animationNode); animationNode.Name = trackName; origKeyframes = new ImportedAnimationKeyframe[0]; } return(origKeyframes); }
public static void ReplaceAnimation(ReplaceAnimationMethod replaceMethod, int insertPos, List <KeyValuePair <string, ImportedAnimationKeyframe[]> > newTrackList, ImportedAnimation iAnim, Dictionary <string, ImportedAnimationTrack> animationNodeDic, bool negateQuaternionFlips) { if (replaceMethod == ReplaceAnimationMethod.Replace) { foreach (var newTrack in newTrackList) { ImportedAnimationTrack iTrack = new ImportedAnimationTrack(); iAnim.TrackList.Add(iTrack); iTrack.Name = newTrack.Key; iTrack.Keyframes = newTrack.Value; } } else if (replaceMethod == ReplaceAnimationMethod.Merge) { foreach (var newTrack in newTrackList) { ImportedAnimationTrack animationNode; ImportedAnimationKeyframe[] origKeyframes = FbxUtility.animationGetOriginalKeyframes(animationNodeDic, newTrack.Key, iAnim, out animationNode); ImportedAnimationKeyframe[] destKeyframes; int newEnd = insertPos + newTrack.Value.Length; if (origKeyframes.Length < insertPos) { destKeyframes = new ImportedAnimationKeyframe[newEnd]; FbxUtility.animationCopyKeyframeTransformArray(origKeyframes, 0, destKeyframes, 0, origKeyframes.Length); FbxUtility.animationNormalizeTrack(origKeyframes, destKeyframes, insertPos); } else { if (origKeyframes.Length < newEnd) { destKeyframes = new ImportedAnimationKeyframe[newEnd]; } else { destKeyframes = new ImportedAnimationKeyframe[origKeyframes.Length]; FbxUtility.animationCopyKeyframeTransformArray(origKeyframes, newEnd, destKeyframes, newEnd, origKeyframes.Length - newEnd); } FbxUtility.animationCopyKeyframeTransformArray(origKeyframes, 0, destKeyframes, 0, insertPos); } FbxUtility.animationCopyKeyframeTransformArray(newTrack.Value, 0, destKeyframes, insertPos, newTrack.Value.Length); animationNode.Keyframes = destKeyframes; } } else if (replaceMethod == ReplaceAnimationMethod.Insert) { foreach (var newTrack in newTrackList) { ImportedAnimationTrack animationNode; ImportedAnimationKeyframe[] origKeyframes = FbxUtility.animationGetOriginalKeyframes(animationNodeDic, newTrack.Key, iAnim, out animationNode); ImportedAnimationKeyframe[] destKeyframes; int newEnd = insertPos + newTrack.Value.Length; if (origKeyframes.Length < insertPos) { destKeyframes = new ImportedAnimationKeyframe[newEnd]; FbxUtility.animationCopyKeyframeTransformArray(origKeyframes, 0, destKeyframes, 0, origKeyframes.Length); FbxUtility.animationNormalizeTrack(origKeyframes, destKeyframes, insertPos); } else { destKeyframes = new ImportedAnimationKeyframe[origKeyframes.Length + newTrack.Value.Length]; FbxUtility.animationCopyKeyframeTransformArray(origKeyframes, 0, destKeyframes, 0, insertPos); FbxUtility.animationCopyKeyframeTransformArray(origKeyframes, insertPos, destKeyframes, newEnd, origKeyframes.Length - insertPos); } FbxUtility.animationCopyKeyframeTransformArray(newTrack.Value, 0, destKeyframes, insertPos, newTrack.Value.Length); animationNode.Keyframes = destKeyframes; } } else if (replaceMethod == ReplaceAnimationMethod.Append) { foreach (var newTrack in newTrackList) { ImportedAnimationTrack animationNode; ImportedAnimationKeyframe[] origKeyframes = FbxUtility.animationGetOriginalKeyframes(animationNodeDic, newTrack.Key, iAnim, out animationNode); ImportedAnimationKeyframe[] destKeyframes = new ImportedAnimationKeyframe[origKeyframes.Length + newTrack.Value.Length]; FbxUtility.animationCopyKeyframeTransformArray(origKeyframes, 0, destKeyframes, 0, origKeyframes.Length); FbxUtility.animationCopyKeyframeTransformArray(newTrack.Value, 0, destKeyframes, origKeyframes.Length, newTrack.Value.Length); animationNode.Keyframes = destKeyframes; } } else { Report.ReportLog("Error: Unexpected animation replace method " + replaceMethod + ". Skipping this animation"); } if (negateQuaternionFlips) { foreach (var newTrack in iAnim.TrackList) { Quaternion lastQ = Quaternion.Identity; for (int i = 0, lastUsed_keyIndex = -1; i < newTrack.Keyframes.Length; i++) { ImportedAnimationKeyframe iKeyframe = newTrack.Keyframes[i]; if (iKeyframe == null) { continue; } Quaternion q = iKeyframe.Rotation; if (lastUsed_keyIndex >= 0) { bool diffX = Math.Sign(lastQ.X) != Math.Sign(q.X); bool diffY = Math.Sign(lastQ.Y) != Math.Sign(q.Y); bool diffZ = Math.Sign(lastQ.Z) != Math.Sign(q.Z); bool diffW = Math.Sign(lastQ.W) != Math.Sign(q.W); if (diffX && diffY && diffZ && diffW) { q.X = -q.X; q.Y = -q.Y; q.Z = -q.Z; q.W = -q.W; iKeyframe.Rotation = q; } } lastQ = q; lastUsed_keyIndex = i; } } } }
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 void setTrackEnabled(int animationId, int id, bool enabled) { ImportedAnimationTrack track = this.Animations[animationId].TrackList[id]; this.Animations[animationId].setTrackEnabled(track, enabled); }