Wrapping cameras into CameraNode.

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9699 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
Kae..pl 13 years ago
parent be5428736d
commit fa426feb08
  1. 10
      engine/src/blender/com/jme3/asset/BlenderKey.java
  2. 11
      engine/src/blender/com/jme3/scene/plugins/blender/AbstractBlenderLoader.java
  3. 24
      engine/src/blender/com/jme3/scene/plugins/blender/BlenderLoader.java
  4. 23
      engine/src/blender/com/jme3/scene/plugins/blender/cameras/CameraHelper.java
  5. 8
      engine/src/blender/com/jme3/scene/plugins/blender/objects/ObjectHelper.java

@ -49,7 +49,7 @@ import com.jme3.export.OutputCapsule;
import com.jme3.light.AmbientLight; import com.jme3.light.AmbientLight;
import com.jme3.material.Material; import com.jme3.material.Material;
import com.jme3.material.RenderState.FaceCullMode; 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.LightNode;
import com.jme3.scene.Node; import com.jme3.scene.Node;
import com.jme3.scene.SceneGraphVisitor; import com.jme3.scene.SceneGraphVisitor;
@ -513,7 +513,7 @@ public class BlenderKey extends ModelKey {
/** Animations of all objects. */ /** Animations of all objects. */
private List<AnimData> animations; private List<AnimData> animations;
/** All cameras from the file. */ /** All cameras from the file. */
private List<Camera> cameras; private List<CameraNode>cameras;
/** All lights from the file. */ /** All lights from the file. */
private List<LightNode> lights; private List<LightNode> lights;
@ -541,7 +541,7 @@ public class BlenderKey extends ModelKey {
} }
} }
if ((featuresToLoad & FeaturesToLoad.CAMERAS) != 0) { if ((featuresToLoad & FeaturesToLoad.CAMERAS) != 0) {
cameras = new ArrayList<Camera>(); cameras = new ArrayList<CameraNode>();
} }
if ((featuresToLoad & FeaturesToLoad.LIGHTS) != 0) { if ((featuresToLoad & FeaturesToLoad.LIGHTS) != 0) {
lights = new ArrayList<LightNode>(); lights = new ArrayList<LightNode>();
@ -606,7 +606,7 @@ public class BlenderKey extends ModelKey {
* @param camera * @param camera
* camera to be added to the result set * camera to be added to the result set
*/ */
public void addCamera(Camera camera) { public void addCamera(CameraNode camera) {
if (cameras != null) { if (cameras != null) {
cameras.add(camera); cameras.add(camera);
} }
@ -667,7 +667,7 @@ public class BlenderKey extends ModelKey {
* This method returns all loaded cameras. * This method returns all loaded cameras.
* @return all loaded cameras * @return all loaded cameras
*/ */
public List<Camera> getCameras() { public List<CameraNode> getCameras() {
return cameras; return cameras;
} }

@ -31,13 +31,17 @@
*/ */
package com.jme3.scene.plugins.blender; 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.AssetLoader;
import com.jme3.asset.BlenderKey.FeaturesToLoad; import com.jme3.asset.BlenderKey.FeaturesToLoad;
import com.jme3.asset.BlenderKey.WorldData; import com.jme3.asset.BlenderKey.WorldData;
import com.jme3.light.AmbientLight; import com.jme3.light.AmbientLight;
import com.jme3.light.Light; import com.jme3.light.Light;
import com.jme3.math.ColorRGBA; import com.jme3.math.ColorRGBA;
import com.jme3.renderer.Camera; import com.jme3.scene.CameraNode;
import com.jme3.scene.Geometry; import com.jme3.scene.Geometry;
import com.jme3.scene.LightNode; import com.jme3.scene.LightNode;
import com.jme3.scene.Node; 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.lights.LightHelper;
import com.jme3.scene.plugins.blender.meshes.MeshHelper; import com.jme3.scene.plugins.blender.meshes.MeshHelper;
import com.jme3.scene.plugins.blender.objects.ObjectHelper; 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. * This class converts blender file blocks into jMonkeyEngine data structures.
@ -99,7 +100,7 @@ import java.util.logging.Logger;
* structure of a camera * structure of a camera
* @return camera's node * @return camera's node
*/ */
public Camera toCamera(Structure structure) throws BlenderFileException { public CameraNode toCamera(Structure structure) throws BlenderFileException {
CameraHelper cameraHelper = blenderContext.getHelper(CameraHelper.class); CameraHelper cameraHelper = blenderContext.getHelper(CameraHelper.class);
if (cameraHelper.shouldBeLoaded(structure, blenderContext)) { if (cameraHelper.shouldBeLoaded(structure, blenderContext)) {
return cameraHelper.toCamera(structure); return cameraHelper.toCamera(structure);

@ -43,7 +43,7 @@ import com.jme3.asset.BlenderKey.FeaturesToLoad;
import com.jme3.asset.BlenderKey.LoadingResults; import com.jme3.asset.BlenderKey.LoadingResults;
import com.jme3.asset.BlenderKey.WorldData; import com.jme3.asset.BlenderKey.WorldData;
import com.jme3.asset.ModelKey; import com.jme3.asset.ModelKey;
import com.jme3.renderer.Camera; import com.jme3.scene.CameraNode;
import com.jme3.scene.LightNode; import com.jme3.scene.LightNode;
import com.jme3.scene.Node; import com.jme3.scene.Node;
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
@ -86,20 +86,14 @@ public class BlenderLoader extends AbstractBlenderLoader {
switch (block.getCode()) { switch (block.getCode()) {
case FileBlockHeader.BLOCK_OB00:// Object case FileBlockHeader.BLOCK_OB00:// Object
Object object = this.toObject(block.getStructure(blenderContext)); Object object = this.toObject(block.getStructure(blenderContext));
if(object instanceof LightNode) { if(object instanceof LightNode && (blenderKey.getFeaturesToLoad() & FeaturesToLoad.LIGHTS) != 0) {
if ((blenderKey.getFeaturesToLoad() & FeaturesToLoad.LIGHTS) != 0) { loadingResults.addLight((LightNode) object);
loadingResults.addLight((LightNode) object); } else if (object instanceof CameraNode && (blenderKey.getFeaturesToLoad() & FeaturesToLoad.CAMERAS) != 0) {
} loadingResults.addCamera((CameraNode) object);
} else if (object instanceof Node) { } else if (object instanceof Node && (blenderKey.getFeaturesToLoad() & FeaturesToLoad.OBJECTS) != 0) {
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() });
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)) {
if (this.isRootObject(loadingResults, (Node)object)) { loadingResults.addObject((Node) object);
loadingResults.addObject((Node) object);
}
}
} else if (object instanceof Camera) {
if ((blenderKey.getFeaturesToLoad() & FeaturesToLoad.CAMERAS) != 0) {
loadingResults.addCamera((Camera) object);
} }
} }
break; break;

@ -2,6 +2,7 @@ package com.jme3.scene.plugins.blender.cameras;
import com.jme3.asset.BlenderKey.FeaturesToLoad; import com.jme3.asset.BlenderKey.FeaturesToLoad;
import com.jme3.renderer.Camera; import com.jme3.renderer.Camera;
import com.jme3.scene.CameraNode;
import com.jme3.scene.plugins.blender.AbstractBlenderHelper; import com.jme3.scene.plugins.blender.AbstractBlenderHelper;
import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; 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 * an exception is thrown when there are problems with the
* blender file * blender file
*/ */
public Camera toCamera(Structure structure) throws BlenderFileException { public CameraNode toCamera(Structure structure) throws BlenderFileException {
if (blenderVersion >= 250) { if (blenderVersion >= 250) {
return this.toCamera250(structure); return this.toCamera250(structure);
} else { } else {
@ -59,15 +60,15 @@ public class CameraHelper extends AbstractBlenderHelper {
* an exception is thrown when there are problems with the * an exception is thrown when there are problems with the
* blender file * blender file
*/ */
public Camera toCamera250(Structure structure) throws BlenderFileException { private CameraNode toCamera250(Structure structure) throws BlenderFileException {
Camera result = new Camera(DEFAULT_CAM_WIDTH, DEFAULT_CAM_HEIGHT); Camera camera = new Camera(DEFAULT_CAM_WIDTH, DEFAULT_CAM_HEIGHT);
int type = ((Number) structure.getFieldValue("type")).intValue(); int type = ((Number) structure.getFieldValue("type")).intValue();
if (type != 0 && type != 1) { if (type != 0 && type != 1) {
LOGGER.log(Level.WARNING, "Unknown camera type: {0}. Perspective camera is being used!", type); LOGGER.log(Level.WARNING, "Unknown camera type: {0}. Perspective camera is being used!", type);
type = 0; type = 0;
} }
//type==0 - perspective; type==1 - orthographic; perspective is used as default //type==0 - perspective; type==1 - orthographic; perspective is used as default
result.setParallelProjection(type == 1); camera.setParallelProjection(type == 1);
float aspect = 0; float aspect = 0;
float clipsta = ((Number) structure.getFieldValue("clipsta")).floatValue(); float clipsta = ((Number) structure.getFieldValue("clipsta")).floatValue();
float clipend = ((Number) structure.getFieldValue("clipend")).floatValue(); float clipend = ((Number) structure.getFieldValue("clipend")).floatValue();
@ -76,8 +77,8 @@ public class CameraHelper extends AbstractBlenderHelper {
} else { } else {
aspect = ((Number) structure.getFieldValue("ortho_scale")).floatValue(); aspect = ((Number) structure.getFieldValue("ortho_scale")).floatValue();
} }
result.setFrustumPerspective(45, aspect, clipsta, clipend); camera.setFrustumPerspective(45, aspect, clipsta, clipend);
return result; return new CameraNode(null, camera);
} }
/** /**
@ -90,15 +91,15 @@ public class CameraHelper extends AbstractBlenderHelper {
* an exception is thrown when there are problems with the * an exception is thrown when there are problems with the
* blender file * blender file
*/ */
public Camera toCamera249(Structure structure) throws BlenderFileException { private CameraNode toCamera249(Structure structure) throws BlenderFileException {
Camera result = new Camera(DEFAULT_CAM_WIDTH, DEFAULT_CAM_HEIGHT); Camera camera = new Camera(DEFAULT_CAM_WIDTH, DEFAULT_CAM_HEIGHT);
int type = ((Number) structure.getFieldValue("type")).intValue(); int type = ((Number) structure.getFieldValue("type")).intValue();
if (type != 0 && type != 1) { if (type != 0 && type != 1) {
LOGGER.log(Level.WARNING, "Unknown camera type: {0}. Perspective camera is being used!", type); LOGGER.log(Level.WARNING, "Unknown camera type: {0}. Perspective camera is being used!", type);
type = 0; type = 0;
} }
//type==0 - perspective; type==1 - orthographic; perspective is used as default //type==0 - perspective; type==1 - orthographic; perspective is used as default
result.setParallelProjection(type == 1); camera.setParallelProjection(type == 1);
float aspect = 0; float aspect = 0;
float clipsta = ((Number) structure.getFieldValue("clipsta")).floatValue(); float clipsta = ((Number) structure.getFieldValue("clipsta")).floatValue();
float clipend = ((Number) structure.getFieldValue("clipend")).floatValue(); float clipend = ((Number) structure.getFieldValue("clipend")).floatValue();
@ -107,8 +108,8 @@ public class CameraHelper extends AbstractBlenderHelper {
} else { } else {
aspect = ((Number) structure.getFieldValue("ortho_scale")).floatValue(); aspect = ((Number) structure.getFieldValue("ortho_scale")).floatValue();
} }
result.setFrustumPerspective(aspect, result.getWidth() / result.getHeight(), clipsta, clipend); camera.setFrustumPerspective(aspect, camera.getWidth() / camera.getHeight(), clipsta, clipend);
return result; return new CameraNode(null, camera);
} }
@Override @Override

@ -41,7 +41,7 @@ import com.jme3.math.Matrix4f;
import com.jme3.math.Quaternion; import com.jme3.math.Quaternion;
import com.jme3.math.Transform; import com.jme3.math.Transform;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.renderer.Camera; import com.jme3.scene.CameraNode;
import com.jme3.scene.Geometry; import com.jme3.scene.Geometry;
import com.jme3.scene.LightNode; import com.jme3.scene.LightNode;
import com.jme3.scene.Node; import com.jme3.scene.Node;
@ -207,9 +207,9 @@ public class ObjectHelper extends AbstractBlenderHelper {
if(pCamera.isNotNull()) { if(pCamera.isNotNull()) {
CameraHelper cameraHelper = blenderContext.getHelper(CameraHelper.class); CameraHelper cameraHelper = blenderContext.getHelper(CameraHelper.class);
List<Structure> camerasArray = pCamera.fetchData(blenderContext.getInputStream()); List<Structure> camerasArray = pCamera.fetchData(blenderContext.getInputStream());
Camera camera = cameraHelper.toCamera(camerasArray.get(0)); CameraNode camera = cameraHelper.toCamera(camerasArray.get(0));
camera.setLocation(t.getTranslation()); camera.setName(name);
camera.setRotation(t.getRotation()); camera.setLocalTransform(t);
result = camera; result = camera;
} }
break; break;

Loading…
Cancel
Save