Bugfix: BlenderModelLoader attached root objects to the scene node before applying the constraints; this sometimes caused NPE to occur while applying the constraints

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10839 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
experimental
Kae..pl 11 years ago
parent d61ac1afe5
commit c0f0f0ca9e
  1. 20
      engine/src/blender/com/jme3/scene/plugins/blender/BlenderModelLoader.java

@ -32,6 +32,8 @@
package com.jme3.scene.plugins.blender; package com.jme3.scene.plugins.blender;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -61,19 +63,17 @@ public class BlenderModelLoader extends BlenderLoader {
this.setup(assetInfo); this.setup(assetInfo);
BlenderKey blenderKey = blenderContext.getBlenderKey(); BlenderKey blenderKey = blenderContext.getBlenderKey();
Node modelRoot = new Node(blenderKey.getName()); List<Node> rootObjects = new ArrayList<Node>();
for (FileBlockHeader block : blocks) { for (FileBlockHeader block : blocks) {
if (block.getCode() == FileBlockHeader.BLOCK_OB00) { if (block.getCode() == FileBlockHeader.BLOCK_OB00) {
ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class); ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class);
Object object = objectHelper.toObject(block.getStructure(blenderContext), blenderContext); Object object = objectHelper.toObject(block.getStructure(blenderContext), blenderContext);
if (object instanceof LightNode && (blenderKey.getFeaturesToLoad() & FeaturesToLoad.LIGHTS) != 0) { if (object instanceof LightNode && (blenderKey.getFeaturesToLoad() & FeaturesToLoad.LIGHTS) != 0) {
modelRoot.addLight(((LightNode) object).getLight()); rootObjects.add((LightNode)object);
modelRoot.attachChild((LightNode) object);
} else if (object instanceof Node && (blenderKey.getFeaturesToLoad() & FeaturesToLoad.OBJECTS) != 0) { } else if (object instanceof Node && (blenderKey.getFeaturesToLoad() & FeaturesToLoad.OBJECTS) != 0) {
LOGGER.log(Level.FINE, "{0}: {1}--> {2}", new Object[] { ((Node) object).getName(), ((Node) object).getLocalTranslation().toString(), ((Node) object).getParent() == null ? "null" : ((Node) object).getParent().getName() }); LOGGER.log(Level.FINE, "{0}: {1}--> {2}", new Object[] { ((Node) object).getName(), ((Node) object).getLocalTranslation().toString(), ((Node) object).getParent() == null ? "null" : ((Node) object).getParent().getName() });
if (((Node) object).getParent() == null) { if (((Node) object).getParent() == null) {
modelRoot.attachChild((Node) object); rootObjects.add((Node)object);
} }
} }
} }
@ -83,6 +83,16 @@ public class BlenderModelLoader extends BlenderLoader {
ConstraintHelper constraintHelper = blenderContext.getHelper(ConstraintHelper.class); ConstraintHelper constraintHelper = blenderContext.getHelper(ConstraintHelper.class);
constraintHelper.bakeConstraints(blenderContext); constraintHelper.bakeConstraints(blenderContext);
//attach the nodes to the root node at the very end so that the root objects have no parents during constraint applying
LOGGER.fine("Creating the root node of the model and applying loaded nodes of the scene to it.");
Node modelRoot = new Node(blenderKey.getName());
for(Node node : rootObjects) {
if(node instanceof LightNode) {
modelRoot.addLight(((LightNode) node).getLight());
}
modelRoot.attachChild(node);
}
blenderContext.dispose(); blenderContext.dispose();
return modelRoot; return modelRoot;
} catch (BlenderFileException e) { } catch (BlenderFileException e) {

Loading…
Cancel
Save