Exemple #1
0
 public static ImportedAnimationKeyframe[] animationGetOriginalKeyframes(Dictionary <string, ImportedAnimationKeyframedTrack> animationNodeDic, string trackName, ImportedKeyframedAnimation anim, out ImportedAnimationKeyframedTrack animationNode)
 {
     ImportedAnimationKeyframe[] origKeyframes;
     if (animationNodeDic.TryGetValue(trackName, out animationNode))
     {
         origKeyframes = animationNode.Keyframes;
     }
     else
     {
         animationNode = new ImportedAnimationKeyframedTrack();
         anim.TrackList.Add(animationNode);
         animationNode.Name = trackName;
         origKeyframes      = new ImportedAnimationKeyframe[0];
     }
     return(origKeyframes);
 }
Exemple #2
0
 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 ImportedAnimationKeyframedTrack)
     {
         TreeNode trackNode = e.Node;
         ImportedAnimationKeyframedTrack track = (ImportedAnimationKeyframedTrack)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);
     }
     else if (e.Node.Tag is ImportedAnimationSampledTrack)
     {
         TreeNode trackNode = e.Node;
         ImportedAnimationSampledTrack track = (ImportedAnimationSampledTrack)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);
     }
 }
Exemple #3
0
        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;
                }
            }
        }
Exemple #4
0
        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);
                            }
                        }
                    }
                }
            }
        }
Exemple #5
0
        public static void ReplaceAnimation(ReplaceAnimationMethod replaceMethod, int insertPos, List <KeyValuePair <string, ImportedAnimationKeyframe[]> > newTrackList, ImportedKeyframedAnimation iAnim, Dictionary <string, ImportedAnimationKeyframedTrack> animationNodeDic, bool negateQuaternionFlips)
        {
            if (replaceMethod == ReplaceAnimationMethod.Replace)
            {
                foreach (var newTrack in newTrackList)
                {
                    ImportedAnimationKeyframedTrack iTrack = new ImportedAnimationKeyframedTrack();
                    iAnim.TrackList.Add(iTrack);
                    iTrack.Name = newTrack.Key;
                    if (insertPos == 0)
                    {
                        iTrack.Keyframes = newTrack.Value;
                    }
                    else
                    {
                        iTrack.Keyframes = new ImportedAnimationKeyframe[insertPos + newTrack.Value.Length];
                        newTrack.Value.CopyTo(iTrack.Keyframes, insertPos);
                    }
                }
            }
            else if (replaceMethod == ReplaceAnimationMethod.ReplacePresent)
            {
                if (insertPos > 0)
                {
                    foreach (var oldTrack in iAnim.TrackList)
                    {
                        ImportedAnimationKeyframe[] keyframes = new ImportedAnimationKeyframe[insertPos + oldTrack.Keyframes.Length];
                        oldTrack.Keyframes.CopyTo(keyframes, insertPos);
                        oldTrack.Keyframes = keyframes;
                    }
                }
                foreach (var newTrack in newTrackList)
                {
                    ImportedAnimationKeyframedTrack animationNode;
                    FbxUtility.animationGetOriginalKeyframes(animationNodeDic, newTrack.Key, iAnim, out animationNode);
                    if (insertPos == 0)
                    {
                        animationNode.Keyframes = newTrack.Value;
                    }
                    else
                    {
                        animationNode.Keyframes = new ImportedAnimationKeyframe[insertPos + newTrack.Value.Length];
                        newTrack.Value.CopyTo(animationNode.Keyframes, insertPos);
                    }
                }
            }
            else if (replaceMethod == ReplaceAnimationMethod.Merge)
            {
                foreach (var newTrack in newTrackList)
                {
                    ImportedAnimationKeyframedTrack 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)
                {
                    ImportedAnimationKeyframedTrack 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)
                {
                    ImportedAnimationKeyframedTrack 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)
                {
                    ImportedAnimationKeyframe[] keyframes = ((ImportedAnimationKeyframedTrack)newTrack).Keyframes;
                    Quaternion lastQ = Quaternion.Identity;
                    for (int i = 0, lastUsed_keyIndex = -1; i < keyframes.Length; i++)
                    {
                        ImportedAnimationKeyframe iKeyframe = 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;
                    }
                }
            }
        }