Browse Source

Finally solved updating the SceneExplorer node.
Fixing a couple of codacy issues, but probably introducing more.

rickard 3 years ago
parent
commit
9a40ffe17d

+ 43 - 1
jme3-core/src/com/jme3/gde/core/assets/ExternalChangeScanner.java

@@ -34,6 +34,9 @@ package com.jme3.gde.core.assets;
 import com.jme3.export.Savable;
 import com.jme3.gde.core.scene.ApplicationLogHandler;
 import com.jme3.gde.core.scene.SceneApplication;
+import com.jme3.gde.core.sceneexplorer.SceneExplorerTopComponent;
+import com.jme3.gde.core.sceneexplorer.nodes.JmeNode;
+import com.jme3.gde.core.sceneexplorer.nodes.JmeSpatial;
 import com.jme3.gde.core.util.SpatialUtil;
 import com.jme3.gde.core.util.TaggedSpatialFinder;
 import com.jme3.gde.core.util.datatransfer.AnimationDataFromOriginal;
@@ -59,6 +62,7 @@ import org.openide.filesystems.FileObject;
 import org.openide.filesystems.FileRenameEvent;
 import org.openide.loaders.DataObject;
 import org.openide.loaders.DataObjectNotFoundException;
+import org.openide.nodes.Node;
 import org.openide.util.Exceptions;
 
 /**
@@ -159,6 +163,7 @@ public class ExternalChangeScanner implements AssetDataPropertyChangeListener,
             if(!onlyMeshData && SpatialUtil.hasAnimations(original)) {
                 new AnimationDataFromOriginal(finder).update(spat,
                             original);
+                
             }
             if(!onlyAnimData){
                 new MeshDataFromOriginal(finder).update(spat, original);
@@ -167,7 +172,13 @@ public class ExternalChangeScanner implements AssetDataPropertyChangeListener,
                 new TransformDataFromOriginal(finder).update(spat, original);
                 new MaterialDataFromOriginal(finder).update(spat, original);
             }
-
+            // Do a complicated recurse refresh since AbstractSceneExplorerNode:refresh() isn't working
+            SceneApplication.getApplication().enqueue((Runnable) () -> {
+                Node rootNode = SceneExplorerTopComponent.findInstance().getExplorerManager().getRootContext();
+                if (rootNode instanceof JmeNode) {
+                    refreshNamedSpatial((JmeNode) rootNode, spat.getName());
+                }
+            });
             closeOriginalSpatial();
             assetDataObject.saveAsset();
         } catch (IOException e) {
@@ -177,6 +188,37 @@ public class ExternalChangeScanner implements AssetDataPropertyChangeListener,
             handle.finish();
         }
     }
+    
+    /**
+     * Look for the spatial to update using the name of the asset
+     * @param spatial
+     * @param name 
+     */
+    private void refreshNamedSpatial(JmeSpatial spatial, String name){
+        if(spatial.getName().equals(name)){
+            recurseRefresh(spatial);
+        } else {
+            for(Node s: spatial.getChildren().getNodes()){
+                if(s instanceof JmeSpatial){
+                    refreshNamedSpatial((JmeSpatial) s, name);
+                }
+                
+            }
+        }
+    }
+    
+    /**
+     * Refreshes the spatial and all children
+     * @param spatial 
+     */
+    private void recurseRefresh(JmeSpatial spatial){
+        spatial.refresh(false);
+        for(Node s: spatial.getChildren().getNodes()){
+            if(s instanceof JmeSpatial){
+                recurseRefresh((JmeSpatial) s);
+            }
+        }
+    }
 
     private Spatial loadOriginalSpatial() {
         try {

+ 1 - 0
jme3-core/src/com/jme3/gde/core/util/SpatialUtil.java

@@ -50,6 +50,7 @@ public class SpatialUtil {
 
     public static final String ORIGINAL_NAME = "ORIGINAL_NAME";
     public static final String ORIGINAL_PATH = "ORIGINAL_PATH";
+    
     private static final Logger LOGGER =
             Logger.getLogger(SpatialUtil.class.getName());
 

+ 4 - 4
jme3-core/src/com/jme3/gde/core/util/TaggedSpatialFinder.java

@@ -10,12 +10,12 @@ import java.util.logging.Logger;
  */
 public class TaggedSpatialFinder {
     
-    public TaggedSpatialFinder(){
-        
-    }
-
     private static final Logger LOGGER =
             Logger.getLogger(TaggedSpatialFinder.class.getName());
+    
+    public TaggedSpatialFinder() {
+        
+    }
 
     /**
      * Finds a previously marked spatial in the supplied root Spatial, creates

+ 5 - 7
jme3-core/src/com/jme3/gde/core/util/datatransfer/AnimationDataFromOriginal.java

@@ -8,7 +8,6 @@ import com.jme3.gde.core.scene.ApplicationLogHandler;
 import com.jme3.gde.core.util.TaggedSpatialFinder;
 import com.jme3.scene.SceneGraphVisitor;
 import com.jme3.scene.Spatial;
-import com.jme3.util.clone.Cloner;
 
 import java.util.Collection;
 import java.util.logging.Level;
@@ -69,8 +68,7 @@ public final class AnimationDataFromOriginal implements SpatialDataTransferInter
                                      final AnimComposer originalAnimComposer,
                                      final SkinningControl originalSkinningControl) {
 
-        final AnimComposer newControl =spatial.getControl(AnimComposer.class);
-        newControl.cloneFields(new Cloner(), originalAnimComposer);
+        final AnimComposer newControl = new AnimComposer();
         copyAnimClips(newControl, originalAnimComposer);
         if (spatial.getControl(AnimComposer.class) == null) {
             LOGGER.log(Level.INFO, "Adding AnimComposer for {0}",
@@ -108,10 +106,10 @@ public final class AnimationDataFromOriginal implements SpatialDataTransferInter
 
     private void removeAnimData(final Spatial root) {
         root.depthFirstTraversal(spatial -> {
-//            final AnimComposer animControl = spatial.getControl(AnimComposer.class);
-//            if (animControl != null) {
-//                spatial.removeControl(animControl);
-//            }
+            final AnimComposer animControl = spatial.getControl(AnimComposer.class);
+            if (animControl != null) {
+                spatial.removeControl(animControl);
+            }
             final SkinningControl skinningControl =
                     spatial.getControl(SkinningControl.class);
             if (skinningControl != null) {

+ 3 - 2
jme3-core/src/com/jme3/gde/core/util/datatransfer/MeshDataFromOriginal.java

@@ -45,12 +45,13 @@ public class MeshDataFromOriginal implements SpatialDataTransferInterface {
     }
 
     /**
-     * Adds a leaf to a spatial, including all nonexisting parents.
+     * Adds a leaf to a spatial, including all non-existing parents.
      *
      * @param root
      * @param leaf
      */
-    private void addLeafWithNonExistingParents(Spatial root, Spatial leaf) {
+    private void addLeafWithNonExistingParents(final Spatial root, 
+            final Spatial leaf) {
         if (!(root instanceof Node)) {
             LOGGER.log(Level.WARNING, "Cannot add new Leaf {0} to {1}, is not"
                     + " a Node!", new Object[]{leaf.getName(), root.getName()});

+ 1 - 1
jme3-core/src/com/jme3/gde/core/util/datatransfer/SpatialDataTransferInterface.java

@@ -10,7 +10,7 @@ import com.jme3.scene.Spatial;
 public interface SpatialDataTransferInterface {
 
     /**
-     * Performs the data transfer
+     * Performs the data transfer.
      *
      * @param root     the node containing the spatial to update
      * @param original spatial to update data from

+ 7 - 6
jme3-core/src/com/jme3/gde/core/util/datatransfer/TransformDataFromOriginal.java

@@ -10,13 +10,14 @@ import com.jme3.scene.Spatial;
 import java.util.logging.Logger;
 
 /**
- * Copies Transform data (translation, rotation, scale) from an updated
- * spatial to the original.
+ * Copies Transform data (translation, rotation, scale) from an updated spatial
+ * to the original.
  */
-public final class TransformDataFromOriginal implements SpatialDataTransferInterface {
+public final class TransformDataFromOriginal implements 
+        SpatialDataTransferInterface {
 
-    private static final Logger LOGGER =
-            Logger.getLogger(AnimationDataFromOriginal.class.getName());
+    private static final Logger LOGGER
+            = Logger.getLogger(AnimationDataFromOriginal.class.getName());
 
     private final TaggedSpatialFinder finder;
 
@@ -50,5 +51,5 @@ public final class TransformDataFromOriginal implements SpatialDataTransferInter
             }
         });
     }
-    
+
 }