Browse Source

restored missing files. fixed compile errors(?)

rickard 3 years ago
parent
commit
719845433c

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

@@ -50,6 +50,12 @@ import java.util.logging.Logger;
 import org.netbeans.api.progress.ProgressHandle;
 import org.netbeans.api.progress.ProgressHandle;
 import org.openide.DialogDisplayer;
 import org.openide.DialogDisplayer;
 import org.openide.NotifyDescriptor;
 import org.openide.NotifyDescriptor;
+import org.openide.filesystems.FileAttributeEvent;
+import org.openide.filesystems.FileChangeAdapter;
+import org.openide.filesystems.FileChangeListener;
+import org.openide.filesystems.FileEvent;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileRenameEvent;
 import org.openide.loaders.DataObject;
 import org.openide.loaders.DataObject;
 import org.openide.loaders.DataObjectNotFoundException;
 import org.openide.loaders.DataObjectNotFoundException;
 import org.openide.util.Exceptions;
 import org.openide.util.Exceptions;
@@ -68,7 +74,7 @@ public class ExternalChangeScanner implements AssetDataPropertyChangeListener,
     private static final AtomicBoolean userNotified = new AtomicBoolean(false);
     private static final AtomicBoolean userNotified = new AtomicBoolean(false);
     private final AssetDataObject assetDataObject;
     private final AssetDataObject assetDataObject;
     private final AssetData assetData;
     private final AssetData assetData;
-    private final FileObject originalObject;
+    private FileObject originalObject;
 
 
     public ExternalChangeScanner(AssetDataObject assetDataObject) {
     public ExternalChangeScanner(AssetDataObject assetDataObject) {
         this.assetDataObject = assetDataObject;
         this.assetDataObject = assetDataObject;

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

@@ -88,12 +88,12 @@ public class SpatialUtil {
         if (spat != null) {
         if (spat != null) {
             spat.depthFirstTraversal(geom -> {
             spat.depthFirstTraversal(geom -> {
 
 
-                final String geomName = geom.getName();
+                String geomName = geom.getName();
                 if (geomName == null) {
                 if (geomName == null) {
                     LOGGER.log(Level.WARNING, "Null Spatial name!");
                     LOGGER.log(Level.WARNING, "Null Spatial name!");
                     geomName = "null";
                     geomName = "null";
                 }
                 }
-                geom.setUserData((SpatialUtil.ORIGINAL_NAME, geomName);
+                geom.setUserData(SpatialUtil.ORIGINAL_NAME, geomName);
                 LOGGER.log(Level.FINE, "Set ORIGINAL_NAME for {0}",
                 LOGGER.log(Level.FINE, "Set ORIGINAL_NAME for {0}",
                         geomName);
                         geomName);
                 final Spatial curSpat = geom;
                 final Spatial curSpat = geom;
@@ -103,7 +103,7 @@ public class SpatialUtil {
                             + "for Spatial {0}: {1}", new Object[]{geom, id});
                             + "for Spatial {0}: {1}", new Object[]{geom, id});
                 }
                 }
                 geomMap.add(id);
                 geomMap.add(id);
-                geom.setUserData((SpatialUtil.ORIGINAL_PATH, id);
+                geom.setUserData(SpatialUtil.ORIGINAL_PATH, id);
                 LOGGER.log(Level.FINE, "Set ORIGINAL_PATH for {0}", id);
                 LOGGER.log(Level.FINE, "Set ORIGINAL_PATH for {0}", id);
             });
             });
         } else {
         } else {

+ 81 - 0
jme3-core/src/com/jme3/gde/core/util/datatransfer/MeshDataFromOriginal.java

@@ -0,0 +1,81 @@
+package com.jme3.gde.core.util.datatransfer;
+
+import com.jme3.gde.core.scene.ApplicationLogHandler.LogLevel;
+import com.jme3.gde.core.util.SpatialUtil;
+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.Level;
+
+import java.util.logging.Logger;
+
+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;
+    }
+
+    @Override
+    public void update(final Spatial root, final Spatial original) {
+        //loop through original to also find new geometry
+        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);
+                if (spat != null) {
+                    spat.setMesh(geom.getMesh());
+                    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
+     */
+    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()});
+            return;
+        }
+        for (Spatial s = leaf; s.getParent() != null; s = s.getParent()) {
+            Spatial parent = s.getParent();
+            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});
+                //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
+                    }
+                    spt.setUserData(SpatialUtil.ORIGINAL_NAME, spt.getName());
+                    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()});
+                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, "Could not attach new Leaf {0}, no root node found.", leaf.getName());
+    }
+}

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

@@ -0,0 +1,8 @@
+package com.jme3.gde.core.util.datatransfer;
+
+import com.jme3.scene.Spatial;
+
+public interface SpatialDataTransferInterface {
+
+    void update(final Spatial root, final Spatial original);
+}