- update external change scanner to allow import of animations

experimental
Normen Hansen 10 years ago
parent a2fc435167
commit b61656ffaa
  1. 14
      sdk/jme3-core/src/com/jme3/gde/core/assets/ExternalChangeScanner.java
  2. 21
      sdk/jme3-core/src/com/jme3/gde/core/util/SpatialUtil.java

@ -130,14 +130,14 @@ public class ExternalChangeScanner implements AssetDataPropertyChangeListener, F
Spatial original = loadOriginalSpatial(); Spatial original = loadOriginalSpatial();
Spatial spat = (Spatial) assetDataObject.loadAsset(); Spatial spat = (Spatial) assetDataObject.loadAsset();
SpatialUtil.updateMeshDataFromOriginal(spat, original); SpatialUtil.updateMeshDataFromOriginal(spat, original);
NotifyDescriptor.Confirmation mesg = new NotifyDescriptor.Confirmation("Model appears to have animations, try to import as well?\nCurrently this will unlink attachment Nodes and clear\nadded effects tracks.",
"Animations Available",
NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.QUESTION_MESSAGE);
DialogDisplayer.getDefault().notify(mesg);
if (mesg.getValue() == NotifyDescriptor.Confirmation.YES_OPTION) {
SpatialUtil.updateAnimControlDataFromOriginal(spat, original);
}
closeOriginalSpatial(); closeOriginalSpatial();
// NotifyDescriptor.Confirmation mesg = new NotifyDescriptor.Confirmation("Model appears to have animations, try to import as well?\nCurrently this will unlink attachment Nodes and clear\nadded effects tracks.",
// "Animations Available",
// NotifyDescriptor.YES_NO_OPTION, NotifyDescriptor.QUESTION_MESSAGE);
// DialogDisplayer.getDefault().notify(mesg);
// if (mesg.getValue() == NotifyDescriptor.Confirmation.YES_OPTION) {
// SpatialUtil.updateAnimControlDataFromOriginal(spat, original);
// }
assetDataObject.saveAsset(); assetDataObject.saveAsset();
} catch (Exception e) { } catch (Exception e) {
logger.log(Level.SEVERE, "Exception when trying to update external data.", e); logger.log(Level.SEVERE, "Exception when trying to update external data.", e);

@ -256,6 +256,7 @@ public class SpatialUtil {
public static void updateAnimControlDataFromOriginal(final Spatial root, final Spatial original) { public static void updateAnimControlDataFromOriginal(final Spatial root, final Spatial original) {
//loop through original to also find new AnimControls, we expect all nodes etc. to exist //loop through original to also find new AnimControls, we expect all nodes etc. to exist
//TODO: can (blender) AnimControls end up in other nodes that are not a parent of the geometry they modify? //TODO: can (blender) AnimControls end up in other nodes that are not a parent of the geometry they modify?
removeAnimData(root);
original.depthFirstTraversal(new SceneGraphVisitor() { original.depthFirstTraversal(new SceneGraphVisitor() {
@Override @Override
public void visit(Spatial spat) { public void visit(Spatial spat) {
@ -273,11 +274,11 @@ public class SpatialUtil {
if (myAnimControl != null) { if (myAnimControl != null) {
mySpatial.removeControl(myAnimControl); mySpatial.removeControl(myAnimControl);
} }
AnimControl newControl = (AnimControl)animControl.cloneForSpatial(mySpatial); AnimControl newControl = (AnimControl) animControl.cloneForSpatial(mySpatial);
if (mySpatial.getControl(SkeletonControl.class) == null) { if (mySpatial.getControl(SkeletonControl.class) == null) {
logger.log(Level.INFO, "Adding control for {0}", mySpatial.getName()); logger.log(Level.INFO, "Adding control for {0}", mySpatial.getName());
mySpatial.addControl(newControl); mySpatial.addControl(newControl);
}else{ } else {
logger.log(Level.INFO, "Control for {0} was added automatically", mySpatial.getName()); logger.log(Level.INFO, "Control for {0} was added automatically", mySpatial.getName());
} }
if (mySpatial.getControl(SkeletonControl.class) == null) { if (mySpatial.getControl(SkeletonControl.class) == null) {
@ -295,6 +296,22 @@ public class SpatialUtil {
//TODO: remove old AnimControls? //TODO: remove old AnimControls?
} }
public static void removeAnimData(Spatial root) {
root.depthFirstTraversal(new SceneGraphVisitor() {
@Override
public void visit(Spatial spat) {
AnimControl animControl = spat.getControl(AnimControl.class);
if (animControl != null) {
spat.removeControl(animControl);
SkeletonControl skeletonControl = spat.getControl(SkeletonControl.class);
if (skeletonControl != null) {
spat.removeControl(skeletonControl);
}
}
}
});
}
public static void clearRemovedOriginals(final Spatial root, final Spatial original) { public static void clearRemovedOriginals(final Spatial root, final Spatial original) {
//TODO: Clear old stuff at all? //TODO: Clear old stuff at all?
return; return;

Loading…
Cancel
Save