Browse Source

issue fixing

rickard 3 years ago
parent
commit
f87d553aa4

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

@@ -9,6 +9,10 @@ import java.util.logging.Logger;
  * the name and path to be looked for from the given needle Spatial.
  */
 public class TaggedSpatialFinder {
+    
+    public TaggedSpatialFinder(){
+        
+    }
 
     private static final Logger LOGGER =
             Logger.getLogger(TaggedSpatialFinder.class.getName());

+ 33 - 25
jme3-core/src/com/jme3/gde/core/util/datatransfer/AnimationDataFromOriginal.java

@@ -4,6 +4,7 @@ import com.jme3.anim.AnimClip;
 import com.jme3.anim.AnimComposer;
 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;
 
@@ -30,28 +31,34 @@ public final class AnimationDataFromOriginal implements SpatialDataTransferInter
         //loop through original to also find new AnimControls, we expect all 
         // nodes etc. to exist
         removeAnimData(root);
-        original.depthFirstTraversal(spatial -> {
-            final AnimComposer animComposer =
-                    spatial.getControl(AnimComposer.class);
-            if (animComposer != null) {
-                final Spatial mySpatial = finder.find(root, spatial);
-                if (mySpatial != null) {
-                    //TODO: move attachments: have to scan through all
-                    // nodes and find the ones
-                    //where UserData "AttachedBone" == Bone and move it
-                    // to new Bone
-                    final AnimComposer myAnimControl =
-                            getAndRemoveControl(mySpatial);
-
-                    updateAndAddControl(mySpatial, myAnimControl, animComposer);
-
-                    LOGGER.log(ApplicationLogHandler.LogLevel.FINE,
-                            "Updated animation for {0}",
-                            mySpatial.getName());
-                } else {
-                    LOGGER.log(Level.WARNING, "Could not find sibling for"
-                            + " {0} in root {1} when trying to apply "
-                            + "AnimControl data", new Object[]{spatial, root});
+        original.depthFirstTraversal(new SceneGraphVisitor() {
+
+            @Override
+            public void visit(final Spatial spatial) {
+                final AnimComposer animComposer =
+                        spatial.getControl(AnimComposer.class);
+                if (animComposer != null) {
+                    final Spatial mySpatial = finder.find(root, spatial);
+                    if (mySpatial != null) {
+                        //TODO: move attachments: have to scan through all
+                        // nodes and find the ones
+                        //where UserData "AttachedBone" == Bone and move it
+                        // to new Bone
+                        final AnimComposer myAnimControl =
+                                getAndRemoveControl(mySpatial);
+
+                        updateAndAddControl(mySpatial, myAnimControl,
+                                animComposer);
+
+                        LOGGER.log(ApplicationLogHandler.LogLevel.FINE,
+                                "Updated animation for {0}",
+                                mySpatial.getName());
+                    } else {
+                        LOGGER.log(Level.WARNING, "Could not find sibling for"
+                                + " {0} in root {1} when trying to apply "
+                                + "AnimControl data", new Object[]{spatial,
+                                root});
+                    }
                 }
             }
         });
@@ -66,8 +73,9 @@ public final class AnimationDataFromOriginal implements SpatialDataTransferInter
         return myAnimControl;
     }
 
-    private void updateAndAddControl(final Spatial spatial, final AnimComposer newControl
-            , final AnimComposer originalControl) {
+    private void updateAndAddControl(final Spatial spatial,
+                                     final AnimComposer newControl, 
+                                     final AnimComposer originalControl) {
         newControl.cloneFields(new Cloner(),
                 originalControl.jmeClone());
         copyAnimClips(newControl, originalControl);
@@ -84,7 +92,7 @@ public final class AnimationDataFromOriginal implements SpatialDataTransferInter
     private void copyAnimClips(final AnimComposer control,
                                final AnimComposer original) {
         final Collection<AnimClip> clips = original.getAnimClips();
-        for (AnimClip c : clips) {
+        for (final AnimClip c : clips) {
             control.addAnimClip(c);
         }
     }

+ 2 - 0
jme3-core/src/com/jme3/gde/core/util/datatransfer/MaterialDataFromOriginal.java

@@ -3,8 +3,10 @@ package com.jme3.gde.core.util.datatransfer;
 import com.jme3.gde.core.scene.ApplicationLogHandler;
 import com.jme3.gde.core.util.TaggedSpatialFinder;
 import com.jme3.scene.Geometry;
+import com.jme3.scene.SceneGraphVisitor;
 import com.jme3.scene.SceneGraphVisitorAdapter;
 import com.jme3.scene.Spatial;
+
 import java.util.logging.Logger;
 
 /**

+ 32 - 17
jme3-core/src/com/jme3/gde/core/util/datatransfer/MeshDataFromOriginal.java

@@ -7,16 +7,20 @@ import com.jme3.scene.Geometry;
 import com.jme3.scene.Node;
 import com.jme3.scene.SceneGraphVisitorAdapter;
 import com.jme3.scene.Spatial;
-import java.util.logging.Level;
 
+import java.util.logging.Level;
 import java.util.logging.Logger;
 
-public class MeshDataFromOriginal implements SpatialDataTransferInterface{
+/**
+ * Copies mesh data from an updated external file to the spatial
+ */
+public class MeshDataFromOriginal implements SpatialDataTransferInterface {
 
     private static final Logger LOGGER =
             Logger.getLogger(MeshDataFromOriginal.class.getName());
 
     private final TaggedSpatialFinder finder;
+
     public MeshDataFromOriginal(final TaggedSpatialFinder finder) {
         this.finder = finder;
     }
@@ -27,55 +31,66 @@ public class MeshDataFromOriginal implements SpatialDataTransferInterface{
         original.depthFirstTraversal(new SceneGraphVisitorAdapter() {
             @Override
             public void visit(Geometry geom) {
-                //will always return same class type as 2nd param, so casting is safe
-                Geometry spat = (Geometry) finder.find(root, geom);
+                //will always return same class type as 2nd param, so casting
+                // is safe
+                final Geometry spat = (Geometry) finder.find(root, geom);
                 if (spat != null) {
                     spat.setMesh(geom.getMesh());
-                    LOGGER.log(LogLevel.USERINFO, "Updated mesh for Geometry {0}", geom.getName());
+                    LOGGER.log(LogLevel.USERINFO, "Updated mesh for Geometry "
+                            + "{0}", geom.getName());
                 } else {
                     addLeafWithNonExistingParents(root, geom);
                 }
             }
         });
     }
-    
+
     /**
      * Adds a leaf to a spatial, including all nonexisting parents.
      *
      * @param root
-     * @param original
+     * @param leaf
      */
     private void addLeafWithNonExistingParents(Spatial root, 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()});
+            LOGGER.log(Level.WARNING, "Cannot add new Leaf {0} to {1}, is not"
+                    + " a Node!", new Object[]{leaf.getName(), root.getName()});
             return;
         }
         for (Spatial s = leaf; s.getParent() != null; s = s.getParent()) {
-            Spatial parent = s.getParent();
-            Spatial other = finder.find(root, parent);
+            final Spatial parent = s.getParent();
+            final Spatial other = finder.find(root, parent);
             if (other == null) {
                 continue;
             }
             if (other instanceof Node) {
-                LOGGER.log(Level.INFO, "Attaching {0} to {1} in root {2} to add leaf {3}", new Object[]{s, other, root, leaf});
+                LOGGER.log(Level.INFO, "Attaching {0} to {1} in root {2} to "
+                        + "add leaf {3}", new Object[]{s, other, root, leaf});
                 //set original path data to leaf and new parents
                 for (Spatial spt = leaf; spt != parent; spt = spt.getParent()) {
-                    if(spt == null){
-                        return; // this is to avoid a crash when changing names of meshes externally
+                    // this is to avoid a crash when changing
+                    // names of meshes externally
+                    if (spt == null) {
+                        return;
                     }
                     spt.setUserData(SpatialUtil.ORIGINAL_NAME, spt.getName());
-                    spt.setUserData(SpatialUtil.ORIGINAL_PATH, SpatialUtil.getSpatialPath(spt));
+                    spt.setUserData(SpatialUtil.ORIGINAL_PATH,
+                            SpatialUtil.getSpatialPath(spt));
                     spt = spt.getParent();
                 }
                 //attach to new node in own root
                 Node otherNode = (Node) other;
                 otherNode.attachChild(s);
-                LOGGER.log(LogLevel.USERINFO, "Attached Node {0} with leaf {0}", new Object[]{other.getName(), leaf.getName()});
+                LOGGER.log(LogLevel.USERINFO, "Attached Node {0} with leaf "
+                        + "{0}", new Object[]{other.getName(), leaf.getName()});
                 return;
             } else {
-                LOGGER.log(Level.WARNING, "Cannot attach leaf {0} to found spatial {1} in root {2}, not a node.", new Object[]{leaf, other, root});
+                LOGGER.log(Level.WARNING, "Cannot attach leaf {0} to found "
+                                + "spatial {1} in root {2}, not a node.",
+                        new Object[]{leaf, other, root});
             }
         }
-        LOGGER.log(Level.WARNING, "Could not attach new Leaf {0}, no root node found.", leaf.getName());
+        LOGGER.log(Level.WARNING, "Could not attach new Leaf {0}, no root "
+                + "node found.", leaf.getName());
     }
 }

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

@@ -2,7 +2,18 @@ package com.jme3.gde.core.util.datatransfer;
 
 import com.jme3.scene.Spatial;
 
+/**
+ * Generic interface for data transfer from files updated externally
+ *
+ * @author rickard
+ */
 public interface SpatialDataTransferInterface {
 
-    void update(final Spatial root, final Spatial original);
+    /**
+     * Performs the data transfer
+     *
+     * @param root     the node containing the spatial to update
+     * @param original spatial to update data from
+     */
+    abstract void update(Spatial root, Spatial original);
 }

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

@@ -4,7 +4,9 @@ import com.jme3.gde.core.scene.ApplicationLogHandler;
 import com.jme3.gde.core.util.TaggedSpatialFinder;
 import com.jme3.scene.Geometry;
 import com.jme3.scene.Node;
+import com.jme3.scene.SceneGraphVisitorAdapter;
 import com.jme3.scene.Spatial;
+
 import java.util.logging.Logger;
 
 /**
@@ -24,7 +26,7 @@ public final class TransformDataFromOriginal implements SpatialDataTransferInter
 
     @Override
     public void update(final Spatial root, final Spatial original) {
-        original.depthFirstTraversal(new com.jme3.scene.SceneGraphVisitorAdapter() {
+        original.depthFirstTraversal(new SceneGraphVisitorAdapter() {
 
             @Override
             public void visit(final Geometry geom) {
@@ -48,4 +50,5 @@ public final class TransformDataFromOriginal implements SpatialDataTransferInter
             }
         });
     }
+    
 }