@ -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 < String > geomMap = new ArrayList < String > ( ) ;
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" ) ;
}
}
}