Browse Source

Animation: Added an AnimClipProperty to allow setting the currently active AnimClip by String. Also removed the TrackActions, as Tracks aren't part of the new animation system anymore, but Actions.

MeFisto94 5 năm trước cách đây
mục cha
commit
a9a2f061d3

+ 97 - 0
jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/actions/animation/AnimClipProperty.java

@@ -0,0 +1,97 @@
+/*
+ *  Copyright (c) 2009-2020 jMonkeyEngine
+ *  All rights reserved.
+ * 
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are
+ *  met:
+ * 
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 
+ *  * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ * 
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ *  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ *  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ *  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ *  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ *  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ *  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.jme3.gde.core.sceneexplorer.nodes.actions.animation;
+
+import com.jme3.anim.AnimClip;
+import com.jme3.anim.AnimComposer;
+import com.jme3.gde.core.scene.SceneApplication;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import org.openide.nodes.PropertySupport;
+import org.openide.util.Exceptions;
+
+/**
+ * The property implementation for {@link AnimClip}s, so those can be referred
+ * to by their name in property editors.
+ * 
+ * @author MeFisto94
+ */
+
+public class AnimClipProperty extends PropertySupport.ReadWrite<String> {
+    private final AnimComposer composer;
+    private String anim = "null";
+    /*private Map<String, Object> layers;
+    private Object layer;
+    private Field currentActionField;*/
+
+    public AnimClipProperty(AnimComposer composer) {
+        super("AnimationClip", String.class, "Animation Clip", "");
+        this.composer = composer;
+        
+        /*try {
+            Field layersField = AnimComposer.class.getDeclaredField("layers");
+            layers = (Map<String, Object>)layersField.get(composer);
+            layer = layers.get(AnimComposer.DEFAULT_LAYER);
+            // @TODO: currentActionField, in order to properly read the current anim
+        } catch (NoSuchFieldException | SecurityException | IllegalAccessException ex) {
+            Exceptions.printStackTrace(ex);
+        }*/
+    }
+    
+    @Override
+    public String getValue() throws IllegalAccessException, InvocationTargetException {
+        return anim;
+        //@TODO: Read the currently active anim instead of using the cached String, as other ways than this property might set the anim
+    }
+
+    @Override
+    public void setValue(String t) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+        if (composer != null) {
+            try {
+                SceneApplication.getApplication().enqueue(() -> {
+                    anim = t;
+                    
+                    if ("null".equals(t) || t.isBlank()) {
+                        composer.removeCurrentAction(AnimComposer.DEFAULT_LAYER);
+                    } else {
+                        composer.setCurrentAction(t);
+                    }
+                    return null;
+                }).get();
+            } catch (InterruptedException | ExecutionException ex) {
+                Exceptions.printStackTrace(ex);
+            }
+        }
+    }
+}

+ 2 - 90
jme3-core/src/com/jme3/gde/core/sceneexplorer/nodes/animation/JmeAnimComposer.java

@@ -33,13 +33,12 @@ package com.jme3.gde.core.sceneexplorer.nodes.animation;
 
 import com.jme3.anim.AnimComposer;
 import com.jme3.gde.core.icons.IconList;
-import com.jme3.gde.core.properties.AnimationProperty;
 import com.jme3.gde.core.scene.SceneApplication;
 import com.jme3.gde.core.sceneexplorer.nodes.JmeControl;
 import com.jme3.gde.core.sceneexplorer.nodes.JmeTrackChildren;
 import com.jme3.gde.core.sceneexplorer.nodes.SceneExplorerNode;
 import com.jme3.gde.core.sceneexplorer.nodes.actions.ControlsPopup;
-import com.jme3.gde.core.util.PropertyUtils;
+import com.jme3.gde.core.sceneexplorer.nodes.actions.animation.AnimClipProperty;
 import java.awt.Image;
 import java.util.concurrent.ExecutionException;
 import javax.swing.Action;
@@ -97,7 +96,7 @@ public class JmeAnimComposer extends JmeControl {
         set.setName(AnimComposer.class.getName());
 
         if (animComposer != null) {
-            //set.put(new AnimationProperty(animComposer));
+            set.put(new AnimClipProperty(animComposer));
             set.put(makeProperty(this, JmeAnimComposer.class, "GlobalSpeed", "Global Animation Speed"));
             sheet.put(set);
         } // else: Empty Sheet
@@ -134,7 +133,6 @@ public class JmeAnimComposer extends JmeControl {
     @Override
     public Action[] getActions(boolean context) {
         return new Action[]{
-            //new TrackVisibilityPopup(this),
             new ControlsPopup(this),
             SystemAction.get(DeleteAction.class)
         };
@@ -190,90 +188,4 @@ public class JmeAnimComposer extends JmeControl {
             ((JmeTrackChildren) anim.getChildren()).refreshChildren(true);
         }
     }
-
-    /*
-    class ToggleBoneTrackAction extends BooleanStateAction {
-
-        @Override
-        public String getName() {
-            return "Display bone tracks";
-        }
-
-        @Override
-        public void setBooleanState(boolean value) {
-            super.setBooleanState(value);
-            displayBoneTracks = value;
-            for (Object node : getChildren().getNodes()) {
-                JmeAnimation anim = (JmeAnimation) node;
-                ((JmeTrackChildren) anim.getChildren()).refreshChildren(true);
-            }
-        }
-
-        @Override
-        public boolean getBooleanState() {
-            return displayBoneTracks;
-        }
-
-        @Override
-        public HelpCtx getHelpCtx() {
-            return JmeAnimComposer.this.getHelpCtx();
-        }
-    };
-
-    class ToggleEffectTrackAction extends BooleanStateAction {
-
-        @Override
-        public String getName() {
-            return "Display effect tracks";
-        }
-
-        @Override
-        public void setBooleanState(boolean value) {
-            super.setBooleanState(value);
-            displayEffectTracks = value;
-            for (Object node : getChildren().getNodes()) {
-                JmeAnimation anim = (JmeAnimation) node;
-                ((JmeTrackChildren) anim.getChildren()).refreshChildren(true);
-            }
-        }
-
-        @Override
-        public boolean getBooleanState() {
-            return displayEffectTracks;
-        }
-
-        @Override
-        public HelpCtx getHelpCtx() {
-            return JmeAnimComposer.this.getHelpCtx();
-        }
-    };
-
-    class ToggleAudioTrackAction extends BooleanStateAction {
-
-        @Override
-        public String getName() {
-            return "Display audio tracks";
-        }
-
-        @Override
-        public void setBooleanState(boolean value) {
-            super.setBooleanState(value);
-            displayAudioTracks = value;
-            for (Object node : getChildren().getNodes()) {
-                JmeAnimation anim = (JmeAnimation) node;
-                ((JmeTrackChildren) anim.getChildren()).refreshChildren(true);
-            }
-        }
-
-        @Override
-        public boolean getBooleanState() {
-            return displayAudioTracks;
-        }
-
-        @Override
-        public HelpCtx getHelpCtx() {
-            return JmeAnimComposer.this.getHelpCtx();
-        }
-    };
-    */
 }