From 120a3d1e4f34a776d2d3c4d509f8a68b77fe492e Mon Sep 17 00:00:00 2001 From: "sha..rd" Date: Wed, 7 Sep 2011 02:39:02 +0000 Subject: [PATCH] Blender Loader * Correct calculation of spot light's inner and outer cone angles * Loaded lights are now attached to the model's root node instead of being foolishly discarded git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8209 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../jme3/app/android/AndroidApplication.java | 2 +- .../plugins/blender/BlenderModelLoader.java | 23 ++++++++----------- .../plugins/blender/lights/LightHelper.java | 10 +++----- .../core/com/jme3/texture/FrameBuffer.java | 1 + 4 files changed, 15 insertions(+), 21 deletions(-) diff --git a/engine/src/android/com/jme3/app/android/AndroidApplication.java b/engine/src/android/com/jme3/app/android/AndroidApplication.java index 296a540ab..f39aa82c8 100644 --- a/engine/src/android/com/jme3/app/android/AndroidApplication.java +++ b/engine/src/android/com/jme3/app/android/AndroidApplication.java @@ -222,7 +222,7 @@ public abstract class AndroidApplication extends Application implements DialogIn // render states stateManager.render(renderManager); - renderManager.render(tpf, true); + renderManager.render(tpf, context.isRenderable()); render(renderManager); stateManager.postRender(); } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/BlenderModelLoader.java b/engine/src/blender/com/jme3/scene/plugins/blender/BlenderModelLoader.java index 2f1c0512c..e6b4115f3 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/BlenderModelLoader.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/BlenderModelLoader.java @@ -38,6 +38,7 @@ import java.util.logging.Logger; import com.jme3.asset.AssetInfo; import com.jme3.asset.BlenderKey.LoadingResults; +import com.jme3.light.Light; import com.jme3.scene.Node; import com.jme3.scene.Spatial; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; @@ -54,35 +55,31 @@ public class BlenderModelLoader extends BlenderLoader { @Override public Spatial load(AssetInfo assetInfo) throws IOException { try { - this.setup(assetInfo); + setup(assetInfo); + + Node modelRoot = new Node(blenderKey.getName()); - LoadingResults loadingResults = blenderKey.prepareLoadingResults(); for (FileBlockHeader block : blocks) { if (block.getCode() == FileBlockHeader.BLOCK_OB00) { Object object = converter.toObject(block.getStructure(dataRepository)); if (object instanceof Node) { LOGGER.log(Level.INFO, "{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) { - loadingResults.addObject((Node) object); + modelRoot.attachChild( (Node) object ); } + }else if (object instanceof Light){ + modelRoot.addLight( (Light) object ); } } } + try { inputStream.close(); } catch(IOException e) { LOGGER.warning(e.getLocalizedMessage()); } - List objects = loadingResults.getObjects(); - if (objects.size() > 0) { - Node modelNode = new Node(blenderKey.getName()); - for(Node object : objects) { - modelNode.attachChild(object); - } - return modelNode; - } else if (objects.size() == 1) { - return objects.get(0); - } + + return modelRoot; } catch (BlenderFileException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/lights/LightHelper.java b/engine/src/blender/com/jme3/scene/plugins/blender/lights/LightHelper.java index 0ce6f0a49..7066de727 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/lights/LightHelper.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/lights/LightHelper.java @@ -90,13 +90,9 @@ public class LightHelper extends AbstractBlenderHelper { //inner angle float spotblend = ((Number) structure.getFieldValue("spotblend")).floatValue(); - if(spotblend > 1.0f) {//floating point errors fix - spotblend = 1.0f; - } - if(spotblend < 0.0f) {//floating point errors fix - spotblend = 0.0f; - } - float innerAngle = 2.0f * (float)Math.atan((1.0f-spotblend)*Math.tan(spotblend/2.0f)); + spotblend = FastMath.clamp(spotblend, 0, 1); + //float innerAngle = 2.0f * (float)Math.atan((1.0f-spotblend)*Math.tan(spotblend/2.0f)); + float innerAngle = outerAngle * (1 - spotblend); ((SpotLight)result).setSpotInnerAngle(innerAngle); break; case 3://Hemi diff --git a/engine/src/core/com/jme3/texture/FrameBuffer.java b/engine/src/core/com/jme3/texture/FrameBuffer.java index f642badd5..021167942 100644 --- a/engine/src/core/com/jme3/texture/FrameBuffer.java +++ b/engine/src/core/com/jme3/texture/FrameBuffer.java @@ -437,6 +437,7 @@ public class FrameBuffer extends GLObject { @Override public void resetObject() { this.id = -1; + for (int i = 0; i < colorBufs.size(); i++) { colorBufs.get(i).resetObject(); }