diff --git a/engine/src/blender/com/jme3/asset/BlenderKey.java b/engine/src/blender/com/jme3/asset/BlenderKey.java index 9c62f751c..cf0a4c736 100644 --- a/engine/src/blender/com/jme3/asset/BlenderKey.java +++ b/engine/src/blender/com/jme3/asset/BlenderKey.java @@ -49,7 +49,7 @@ import com.jme3.export.OutputCapsule; import com.jme3.light.AmbientLight; import com.jme3.material.Material; import com.jme3.material.RenderState.FaceCullMode; -import com.jme3.renderer.Camera; +import com.jme3.scene.CameraNode; import com.jme3.scene.LightNode; import com.jme3.scene.Node; import com.jme3.scene.SceneGraphVisitor; @@ -513,7 +513,7 @@ public class BlenderKey extends ModelKey { /** Animations of all objects. */ private List animations; /** All cameras from the file. */ - private List cameras; + private Listcameras; /** All lights from the file. */ private List lights; @@ -541,7 +541,7 @@ public class BlenderKey extends ModelKey { } } if ((featuresToLoad & FeaturesToLoad.CAMERAS) != 0) { - cameras = new ArrayList(); + cameras = new ArrayList(); } if ((featuresToLoad & FeaturesToLoad.LIGHTS) != 0) { lights = new ArrayList(); @@ -606,7 +606,7 @@ public class BlenderKey extends ModelKey { * @param camera * camera to be added to the result set */ - public void addCamera(Camera camera) { + public void addCamera(CameraNode camera) { if (cameras != null) { cameras.add(camera); } @@ -667,7 +667,7 @@ public class BlenderKey extends ModelKey { * This method returns all loaded cameras. * @return all loaded cameras */ - public List getCameras() { + public List getCameras() { return cameras; } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/AbstractBlenderLoader.java b/engine/src/blender/com/jme3/scene/plugins/blender/AbstractBlenderLoader.java index 9bbf006c2..73bc716ae 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/AbstractBlenderLoader.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/AbstractBlenderLoader.java @@ -31,13 +31,17 @@ */ package com.jme3.scene.plugins.blender; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + import com.jme3.asset.AssetLoader; import com.jme3.asset.BlenderKey.FeaturesToLoad; import com.jme3.asset.BlenderKey.WorldData; import com.jme3.light.AmbientLight; import com.jme3.light.Light; import com.jme3.math.ColorRGBA; -import com.jme3.renderer.Camera; +import com.jme3.scene.CameraNode; import com.jme3.scene.Geometry; import com.jme3.scene.LightNode; import com.jme3.scene.Node; @@ -49,9 +53,6 @@ import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.lights.LightHelper; import com.jme3.scene.plugins.blender.meshes.MeshHelper; import com.jme3.scene.plugins.blender.objects.ObjectHelper; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; /** * This class converts blender file blocks into jMonkeyEngine data structures. @@ -99,7 +100,7 @@ import java.util.logging.Logger; * structure of a camera * @return camera's node */ - public Camera toCamera(Structure structure) throws BlenderFileException { + public CameraNode toCamera(Structure structure) throws BlenderFileException { CameraHelper cameraHelper = blenderContext.getHelper(CameraHelper.class); if (cameraHelper.shouldBeLoaded(structure, blenderContext)) { return cameraHelper.toCamera(structure); diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/BlenderLoader.java b/engine/src/blender/com/jme3/scene/plugins/blender/BlenderLoader.java index 27b3ed313..46bb44b44 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/BlenderLoader.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/BlenderLoader.java @@ -43,7 +43,7 @@ import com.jme3.asset.BlenderKey.FeaturesToLoad; import com.jme3.asset.BlenderKey.LoadingResults; import com.jme3.asset.BlenderKey.WorldData; import com.jme3.asset.ModelKey; -import com.jme3.renderer.Camera; +import com.jme3.scene.CameraNode; import com.jme3.scene.LightNode; import com.jme3.scene.Node; import com.jme3.scene.Spatial; @@ -86,20 +86,14 @@ public class BlenderLoader extends AbstractBlenderLoader { switch (block.getCode()) { case FileBlockHeader.BLOCK_OB00:// Object Object object = this.toObject(block.getStructure(blenderContext)); - if(object instanceof LightNode) { - if ((blenderKey.getFeaturesToLoad() & FeaturesToLoad.LIGHTS) != 0) { - loadingResults.addLight((LightNode) object); - } - } else if (object instanceof Node) { - if ((blenderKey.getFeaturesToLoad() & FeaturesToLoad.OBJECTS) != 0) { - 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 (this.isRootObject(loadingResults, (Node)object)) { - loadingResults.addObject((Node) object); - } - } - } else if (object instanceof Camera) { - if ((blenderKey.getFeaturesToLoad() & FeaturesToLoad.CAMERAS) != 0) { - loadingResults.addCamera((Camera) object); + if(object instanceof LightNode && (blenderKey.getFeaturesToLoad() & FeaturesToLoad.LIGHTS) != 0) { + loadingResults.addLight((LightNode) object); + } else if (object instanceof CameraNode && (blenderKey.getFeaturesToLoad() & FeaturesToLoad.CAMERAS) != 0) { + loadingResults.addCamera((CameraNode) object); + } else if (object instanceof Node && (blenderKey.getFeaturesToLoad() & FeaturesToLoad.OBJECTS) != 0) { + 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 (this.isRootObject(loadingResults, (Node)object)) { + loadingResults.addObject((Node) object); } } break; diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/cameras/CameraHelper.java b/engine/src/blender/com/jme3/scene/plugins/blender/cameras/CameraHelper.java index e69eb3b5e..ae028ee32 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/cameras/CameraHelper.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/cameras/CameraHelper.java @@ -2,6 +2,7 @@ package com.jme3.scene.plugins.blender.cameras; import com.jme3.asset.BlenderKey.FeaturesToLoad; import com.jme3.renderer.Camera; +import com.jme3.scene.CameraNode; import com.jme3.scene.plugins.blender.AbstractBlenderHelper; import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; @@ -41,7 +42,7 @@ public class CameraHelper extends AbstractBlenderHelper { * an exception is thrown when there are problems with the * blender file */ - public Camera toCamera(Structure structure) throws BlenderFileException { + public CameraNode toCamera(Structure structure) throws BlenderFileException { if (blenderVersion >= 250) { return this.toCamera250(structure); } else { @@ -59,15 +60,15 @@ public class CameraHelper extends AbstractBlenderHelper { * an exception is thrown when there are problems with the * blender file */ - public Camera toCamera250(Structure structure) throws BlenderFileException { - Camera result = new Camera(DEFAULT_CAM_WIDTH, DEFAULT_CAM_HEIGHT); + private CameraNode toCamera250(Structure structure) throws BlenderFileException { + Camera camera = new Camera(DEFAULT_CAM_WIDTH, DEFAULT_CAM_HEIGHT); int type = ((Number) structure.getFieldValue("type")).intValue(); if (type != 0 && type != 1) { LOGGER.log(Level.WARNING, "Unknown camera type: {0}. Perspective camera is being used!", type); type = 0; } //type==0 - perspective; type==1 - orthographic; perspective is used as default - result.setParallelProjection(type == 1); + camera.setParallelProjection(type == 1); float aspect = 0; float clipsta = ((Number) structure.getFieldValue("clipsta")).floatValue(); float clipend = ((Number) structure.getFieldValue("clipend")).floatValue(); @@ -76,8 +77,8 @@ public class CameraHelper extends AbstractBlenderHelper { } else { aspect = ((Number) structure.getFieldValue("ortho_scale")).floatValue(); } - result.setFrustumPerspective(45, aspect, clipsta, clipend); - return result; + camera.setFrustumPerspective(45, aspect, clipsta, clipend); + return new CameraNode(null, camera); } /** @@ -90,15 +91,15 @@ public class CameraHelper extends AbstractBlenderHelper { * an exception is thrown when there are problems with the * blender file */ - public Camera toCamera249(Structure structure) throws BlenderFileException { - Camera result = new Camera(DEFAULT_CAM_WIDTH, DEFAULT_CAM_HEIGHT); + private CameraNode toCamera249(Structure structure) throws BlenderFileException { + Camera camera = new Camera(DEFAULT_CAM_WIDTH, DEFAULT_CAM_HEIGHT); int type = ((Number) structure.getFieldValue("type")).intValue(); if (type != 0 && type != 1) { LOGGER.log(Level.WARNING, "Unknown camera type: {0}. Perspective camera is being used!", type); type = 0; } //type==0 - perspective; type==1 - orthographic; perspective is used as default - result.setParallelProjection(type == 1); + camera.setParallelProjection(type == 1); float aspect = 0; float clipsta = ((Number) structure.getFieldValue("clipsta")).floatValue(); float clipend = ((Number) structure.getFieldValue("clipend")).floatValue(); @@ -107,8 +108,8 @@ public class CameraHelper extends AbstractBlenderHelper { } else { aspect = ((Number) structure.getFieldValue("ortho_scale")).floatValue(); } - result.setFrustumPerspective(aspect, result.getWidth() / result.getHeight(), clipsta, clipend); - return result; + camera.setFrustumPerspective(aspect, camera.getWidth() / camera.getHeight(), clipsta, clipend); + return new CameraNode(null, camera); } @Override diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/objects/ObjectHelper.java b/engine/src/blender/com/jme3/scene/plugins/blender/objects/ObjectHelper.java index 61bc046c5..db3c30ce2 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/objects/ObjectHelper.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/objects/ObjectHelper.java @@ -41,7 +41,7 @@ import com.jme3.math.Matrix4f; import com.jme3.math.Quaternion; import com.jme3.math.Transform; import com.jme3.math.Vector3f; -import com.jme3.renderer.Camera; +import com.jme3.scene.CameraNode; import com.jme3.scene.Geometry; import com.jme3.scene.LightNode; import com.jme3.scene.Node; @@ -207,9 +207,9 @@ public class ObjectHelper extends AbstractBlenderHelper { if(pCamera.isNotNull()) { CameraHelper cameraHelper = blenderContext.getHelper(CameraHelper.class); List camerasArray = pCamera.fetchData(blenderContext.getInputStream()); - Camera camera = cameraHelper.toCamera(camerasArray.get(0)); - camera.setLocation(t.getTranslation()); - camera.setRotation(t.getRotation()); + CameraNode camera = cameraHelper.toCamera(camerasArray.get(0)); + camera.setName(name); + camera.setLocalTransform(t); result = camera; } break;