From d0dc0d134524db3a9c6b3c79ad395bacbfad9d45 Mon Sep 17 00:00:00 2001 From: "nor..67" Date: Wed, 30 Jan 2013 12:43:53 +0000 Subject: [PATCH] SDK: - Only store ORIGINAL_PATH metadata in .j3odata when actually converting the model for the first time - Store ORIGINAL_PATH and ORIGINAL_NAME UserData on geometry when creating j3o files with the SDK git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10242 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../AbstractBlenderAssetDataObject.java | 1 + .../core/assets/SpatialAssetDataObject.java | 51 +++++++++++++++++++ .../ogretools/OgreBinaryMeshDataObject.java | 1 + 3 files changed, 53 insertions(+) diff --git a/sdk/jme3-blender/src/com/jme3/gde/blender/filetypes/AbstractBlenderAssetDataObject.java b/sdk/jme3-blender/src/com/jme3/gde/blender/filetypes/AbstractBlenderAssetDataObject.java index 5160e3964..a43cfde0d 100644 --- a/sdk/jme3-blender/src/com/jme3/gde/blender/filetypes/AbstractBlenderAssetDataObject.java +++ b/sdk/jme3-blender/src/com/jme3/gde/blender/filetypes/AbstractBlenderAssetDataObject.java @@ -72,6 +72,7 @@ public abstract class AbstractBlenderAssetDataObject extends SpatialAssetDataObj replaceFiles(); listListener.stop(); savable = spatial; + storeOriginalPathUserData(); return spatial; } catch (IOException ex) { Exceptions.printStackTrace(ex); diff --git a/sdk/jme3-core/src/com/jme3/gde/core/assets/SpatialAssetDataObject.java b/sdk/jme3-core/src/com/jme3/gde/core/assets/SpatialAssetDataObject.java index f3e156ef9..210b6fcc1 100644 --- a/sdk/jme3-core/src/com/jme3/gde/core/assets/SpatialAssetDataObject.java +++ b/sdk/jme3-core/src/com/jme3/gde/core/assets/SpatialAssetDataObject.java @@ -33,8 +33,11 @@ package com.jme3.gde.core.assets; import com.jme3.asset.AssetKey; import com.jme3.asset.ModelKey; +import com.jme3.scene.Geometry; +import com.jme3.scene.SceneGraphVisitorAdapter; import com.jme3.scene.Spatial; import java.io.IOException; +import java.util.ArrayList; import java.util.logging.Level; import java.util.logging.Logger; import org.openide.DialogDisplayer; @@ -94,6 +97,9 @@ public class SpatialAssetDataObject extends AssetDataObject { Spatial spatial = mgr.loadModel(getAssetKey()); listListener.stop(); savable = spatial; + if (!(this instanceof BinaryModelDataObject)) { + storeOriginalPathUserData(); + } lock.releaseLock(); return spatial; } catch (Exception ex) { @@ -136,4 +142,49 @@ public class SpatialAssetDataObject extends AssetDataObject { Exceptions.printStackTrace(ex); } } +/* + * SDK: +- Only store ORIGINAL_PATH AssetData property when actually converting +- Store ORIGINAL_PATH and ORIGINAL_NAME UserData on geometry when creating j3o files with the SDK +*/ + protected void storeOriginalPathUserData() { + final ArrayList geomMap = new ArrayList(); + Spatial spat = (Spatial) savable; + if (spat != null) { + spat.depthFirstTraversal(new SceneGraphVisitorAdapter() { + @Override + public void visit(Geometry geom) { + StringBuilder geometryIdentifier = new StringBuilder(); + Spatial curSpat = geom; + String geomName = curSpat.getName(); + if (geomName == null) { + logger.log(Level.WARNING, "Null geometry name!"); + geomName = "null"; + } + geom.setUserData("ORIGINAL_NAME", geomName); + logger.log(Level.INFO, "Set ORIGINAL_NAME for {0}", geomName); + while (curSpat != null) { + String name = curSpat.getName(); + if (name == null) { + logger.log(Level.WARNING, "Null spatial name!"); + name = "null"; + } + geometryIdentifier.insert(0, name); + geometryIdentifier.insert(0, '/'); + curSpat = curSpat.getParent(); + } + String id = geometryIdentifier.toString(); + if (geomMap.contains(id)) { + logger.log(Level.WARNING, "Cannot create unique name for Geometry {0}: {1}", new Object[]{geom, id}); + } + geomMap.add(id); + geom.setUserData("ORIGINAL_PATH", id); + logger.log(Level.INFO, "Set ORIGINAL_PATH for {0}", id); + super.visit(geom); + } + }); + } else { + logger.log(Level.SEVERE, "No geometry available when trying to scan initial geometry configuration"); + } + } } diff --git a/sdk/jme3-ogretools/src/com/jme3/gde/ogretools/OgreBinaryMeshDataObject.java b/sdk/jme3-ogretools/src/com/jme3/gde/ogretools/OgreBinaryMeshDataObject.java index 68ed373e6..f36cdfe45 100644 --- a/sdk/jme3-ogretools/src/com/jme3/gde/ogretools/OgreBinaryMeshDataObject.java +++ b/sdk/jme3-ogretools/src/com/jme3/gde/ogretools/OgreBinaryMeshDataObject.java @@ -64,6 +64,7 @@ public class OgreBinaryMeshDataObject extends SpatialAssetDataObject { replaceXmlFiles(mgr); listListener.stop(); savable = spatial; + storeOriginalPathUserData(); lock.releaseLock(); File deleteFile = new File(options.getDestFile()); deleteFile.delete();