From 6c9395c4e988555d4d89d3f4c9b8b23e534bc867 Mon Sep 17 00:00:00 2001 From: "Kae..pl" Date: Sat, 20 Aug 2011 11:05:59 +0000 Subject: [PATCH] Creating common setup for both types of loaders. Fixing a bug with loading objects from all layers when using BlenderModelLoader. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8043 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../scene/plugins/blender/BlenderLoader.java | 253 ++++++++++-------- .../plugins/blender/BlenderModelLoader.java | 71 +---- .../scene/plugins/blender/JmeConverter.java | 216 ++++++++------- .../jme3test/blender/ManualBlenderTester.java | 2 +- 4 files changed, 269 insertions(+), 273 deletions(-) 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 bc5db85fa..e64ca23fb 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/BlenderLoader.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/BlenderLoader.java @@ -47,6 +47,7 @@ import com.jme3.asset.ModelKey; import com.jme3.light.Light; import com.jme3.renderer.Camera; import com.jme3.scene.Node; +import com.jme3.scene.Spatial; import com.jme3.scene.plugins.blender.animations.ArmatureHelper; import com.jme3.scene.plugins.blender.animations.IpoHelper; import com.jme3.scene.plugins.blender.cameras.CameraHelper; @@ -70,121 +71,153 @@ import com.jme3.scene.plugins.blender.textures.TextureHelper; */ public class BlenderLoader implements AssetLoader { - private static final Logger LOGGER = Logger.getLogger(BlenderLoader.class.getName()); + private static final Logger LOGGER = Logger.getLogger(BlenderLoader.class.getName()); - @Override - public LoadingResults load(AssetInfo assetInfo) throws IOException { - try { - //registering loaders - ModelKey modelKey = (ModelKey) assetInfo.getKey(); - BlenderKey blenderKey; - if (modelKey instanceof BlenderKey) { - blenderKey = (BlenderKey) modelKey; - } else { - blenderKey = new BlenderKey(modelKey.getName()); - blenderKey.setAssetRootPath(modelKey.getFolder()); - } + /** Converter for blender structures. */ + protected JmeConverter converter; + /** The data repository. */ + protected DataRepository dataRepository; + /** The blender key to use. */ + protected BlenderKey blenderKey; + /** The blocks read from the file. */ + protected List blocks; + /** Blender input stream. */ + protected BlenderInputStream inputStream; - //opening stream - BlenderInputStream inputStream = new BlenderInputStream(assetInfo.openStream(), assetInfo.getManager()); + @Override + public Spatial load(AssetInfo assetInfo) throws IOException { + try { + this.setup(assetInfo); - //reading blocks - List blocks = new ArrayList(); - FileBlockHeader fileBlock; - DataRepository dataRepository = new DataRepository(); - dataRepository.setAssetManager(assetInfo.getManager()); - dataRepository.setInputStream(inputStream); - dataRepository.setBlenderKey(blenderKey); + LoadingResults loadingResults = blenderKey.prepareLoadingResults(); + WorldData worldData = null;// a set of data used in different scene aspects + for (FileBlockHeader block : blocks) { + switch (block.getCode()) { + case FileBlockHeader.BLOCK_OB00:// Object + Object object = converter.toObject(block.getStructure(dataRepository)); + 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 (((Node) object).getParent() == null) { + loadingResults.addObject((Node) object); + } + } + } else if (object instanceof Camera) { + if ((blenderKey.getFeaturesToLoad() & FeaturesToLoad.CAMERAS) != 0) { + loadingResults.addCamera((Camera) object); + } + } else if (object instanceof Light) { + if ((blenderKey.getFeaturesToLoad() & FeaturesToLoad.LIGHTS) != 0) { + loadingResults.addLight((Light) object); + } + } + break; + case FileBlockHeader.BLOCK_MA00:// Material + if (blenderKey.isLoadUnlinkedAssets() && (blenderKey.getFeaturesToLoad() & FeaturesToLoad.MATERIALS) != 0) { + loadingResults.addMaterial(converter.toMaterial(block.getStructure(dataRepository))); + } + break; + case FileBlockHeader.BLOCK_SC00:// Scene + if ((blenderKey.getFeaturesToLoad() & FeaturesToLoad.SCENES) != 0) { + loadingResults.addScene(converter.toScene(block.getStructure(dataRepository))); + } + break; + case FileBlockHeader.BLOCK_WO00:// World + if (blenderKey.isLoadUnlinkedAssets() && worldData == null) {// onlu one world data is used + Structure worldStructure = block.getStructure(dataRepository); + String worldName = worldStructure.getName(); + if (blenderKey.getUsedWorld() == null || blenderKey.getUsedWorld().equals(worldName)) { + worldData = converter.toWorldData(worldStructure); + if ((blenderKey.getFeaturesToLoad() & FeaturesToLoad.LIGHTS) != 0) { + loadingResults.addLight(worldData.getAmbientLight()); + } + } + } + break; + } + } + try { + inputStream.close(); + } catch (IOException e) { + LOGGER.log(Level.SEVERE, e.getMessage(), e); + } + return loadingResults; + } catch (BlenderFileException e) { + LOGGER.log(Level.SEVERE, e.getMessage(), e); + } + return null; + } - //creating helpers - dataRepository.putHelper(ArmatureHelper.class, new ArmatureHelper(inputStream.getVersionNumber())); - dataRepository.putHelper(TextureHelper.class, new TextureHelper(inputStream.getVersionNumber())); - dataRepository.putHelper(MeshHelper.class, new MeshHelper(inputStream.getVersionNumber())); - dataRepository.putHelper(ObjectHelper.class, new ObjectHelper(inputStream.getVersionNumber())); - dataRepository.putHelper(CurvesHelper.class, new CurvesHelper(inputStream.getVersionNumber())); - dataRepository.putHelper(LightHelper.class, new LightHelper(inputStream.getVersionNumber())); - dataRepository.putHelper(CameraHelper.class, new CameraHelper(inputStream.getVersionNumber())); - dataRepository.putHelper(ModifierHelper.class, new ModifierHelper(inputStream.getVersionNumber())); - dataRepository.putHelper(MaterialHelper.class, new MaterialHelper(inputStream.getVersionNumber())); - dataRepository.putHelper(ConstraintHelper.class, new ConstraintHelper(inputStream.getVersionNumber(), dataRepository)); - dataRepository.putHelper(IpoHelper.class, new IpoHelper(inputStream.getVersionNumber())); - dataRepository.putHelper(ParticlesHelper.class, new ParticlesHelper(inputStream.getVersionNumber())); + /** + * This method sets up the loader. + * @param assetInfo + * the asset info + * @throws BlenderFileException + * an exception is throw when something wrong happens with blender file + */ + protected void setup(AssetInfo assetInfo) throws BlenderFileException { + // registering loaders + ModelKey modelKey = (ModelKey) assetInfo.getKey(); + if (modelKey instanceof BlenderKey) { + blenderKey = (BlenderKey) modelKey; + } else { + blenderKey = new BlenderKey(modelKey.getName()); + blenderKey.setAssetRootPath(modelKey.getFolder()); + } - //setting additional data to helpers - if (blenderKey.isFixUpAxis()) { - ObjectHelper objectHelper = dataRepository.getHelper(ObjectHelper.class); - objectHelper.setyIsUpAxis(true); - CurvesHelper curvesHelper = dataRepository.getHelper(CurvesHelper.class); - curvesHelper.setyIsUpAxis(true); - } - MaterialHelper materialHelper = dataRepository.getHelper(MaterialHelper.class); - materialHelper.setFaceCullMode(blenderKey.getFaceCullMode()); + // opening stream + inputStream = new BlenderInputStream(assetInfo.openStream(), assetInfo.getManager()); - //reading the blocks (dna block is automatically saved in the data repository when found)//TODO: zmienić to - do { - fileBlock = new FileBlockHeader(inputStream, dataRepository); - if (!fileBlock.isDnaBlock()) { - blocks.add(fileBlock); - } - } while (!fileBlock.isLastBlock()); + // reading blocks + blocks = new ArrayList(); + FileBlockHeader fileBlock; + dataRepository = new DataRepository(); + dataRepository.setAssetManager(assetInfo.getManager()); + dataRepository.setInputStream(inputStream); + dataRepository.setBlenderKey(blenderKey); - JmeConverter converter = new JmeConverter(dataRepository); - LoadingResults loadingResults = blenderKey.prepareLoadingResults(); - WorldData worldData = null;//a set of data used in different scene aspects - for (FileBlockHeader block : blocks) { - switch (block.getCode()) { - case FileBlockHeader.BLOCK_OB00://Object - Object object = converter.toObject(block.getStructure(dataRepository)); - 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 (((Node) object).getParent() == null) { - loadingResults.addObject((Node) object); - } - } - } else if (object instanceof Camera) { - if ((blenderKey.getFeaturesToLoad() & FeaturesToLoad.CAMERAS) != 0) { - loadingResults.addCamera((Camera) object); - } - } else if (object instanceof Light) { - if ((blenderKey.getFeaturesToLoad() & FeaturesToLoad.LIGHTS) != 0) { - loadingResults.addLight((Light) object); - } - } - break; - case FileBlockHeader.BLOCK_MA00://Material - if (blenderKey.isLoadUnlinkedAssets() && (blenderKey.getFeaturesToLoad() & FeaturesToLoad.MATERIALS) != 0) { - loadingResults.addMaterial(converter.toMaterial(block.getStructure(dataRepository))); - } - break; - case FileBlockHeader.BLOCK_SC00://Scene - if ((blenderKey.getFeaturesToLoad() & FeaturesToLoad.SCENES) != 0) { - loadingResults.addScene(converter.toScene(block.getStructure(dataRepository))); - } - break; - case FileBlockHeader.BLOCK_WO00://World - if (blenderKey.isLoadUnlinkedAssets() && worldData == null) {//onlu one world data is used - Structure worldStructure = block.getStructure(dataRepository); - String worldName = worldStructure.getName(); - if (blenderKey.getUsedWorld() == null || blenderKey.getUsedWorld().equals(worldName)) { - worldData = converter.toWorldData(worldStructure); - if ((blenderKey.getFeaturesToLoad() & FeaturesToLoad.LIGHTS) != 0) { - loadingResults.addLight(worldData.getAmbientLight()); - } - } - } - break; - } - } - try { - inputStream.close(); - } catch (IOException e) { - LOGGER.log(Level.SEVERE, e.getMessage(), e); - } - return loadingResults; - } catch (BlenderFileException e) { - LOGGER.log(Level.SEVERE, e.getMessage(), e); - } - return null; - } + // creating helpers + dataRepository.putHelper(ArmatureHelper.class, new ArmatureHelper(inputStream.getVersionNumber())); + dataRepository.putHelper(TextureHelper.class, new TextureHelper(inputStream.getVersionNumber())); + dataRepository.putHelper(MeshHelper.class, new MeshHelper(inputStream.getVersionNumber())); + dataRepository.putHelper(ObjectHelper.class, new ObjectHelper(inputStream.getVersionNumber())); + dataRepository.putHelper(CurvesHelper.class, new CurvesHelper(inputStream.getVersionNumber())); + dataRepository.putHelper(LightHelper.class, new LightHelper(inputStream.getVersionNumber())); + dataRepository.putHelper(CameraHelper.class, new CameraHelper(inputStream.getVersionNumber())); + dataRepository.putHelper(ModifierHelper.class, new ModifierHelper(inputStream.getVersionNumber())); + dataRepository.putHelper(MaterialHelper.class, new MaterialHelper(inputStream.getVersionNumber())); + dataRepository.putHelper(ConstraintHelper.class, new ConstraintHelper(inputStream.getVersionNumber(), dataRepository)); + dataRepository.putHelper(IpoHelper.class, new IpoHelper(inputStream.getVersionNumber())); + dataRepository.putHelper(ParticlesHelper.class, new ParticlesHelper(inputStream.getVersionNumber())); + + // setting additional data to helpers + if (blenderKey.isFixUpAxis()) { + ObjectHelper objectHelper = dataRepository.getHelper(ObjectHelper.class); + objectHelper.setyIsUpAxis(true); + CurvesHelper curvesHelper = dataRepository.getHelper(CurvesHelper.class); + curvesHelper.setyIsUpAxis(true); + } + MaterialHelper materialHelper = dataRepository.getHelper(MaterialHelper.class); + materialHelper.setFaceCullMode(blenderKey.getFaceCullMode()); + + // reading the blocks (dna block is automatically saved in the data repository when found)//TODO: zmienić to + FileBlockHeader sceneFileBlock = null; + do { + fileBlock = new FileBlockHeader(inputStream, dataRepository); + if (!fileBlock.isDnaBlock()) { + blocks.add(fileBlock); + // save the scene's file block + if (fileBlock.getCode() == FileBlockHeader.BLOCK_SC00 && blenderKey.getLayersToLoad() < 0) { + sceneFileBlock = fileBlock; + } + } + } while (!fileBlock.isLastBlock()); + // VERIFY LAYERS TO BE LOADED BEFORE LOADING FEATURES + if (sceneFileBlock != null) { + int lay = ((Number) sceneFileBlock.getStructure(dataRepository).getFieldValue("lay")).intValue(); + dataRepository.getBlenderKey().setLayersToLoad(lay);// load only current layer + } + + converter = new JmeConverter(dataRepository); + } } 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 6eec532da..2f1c0512c 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/BlenderModelLoader.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/BlenderModelLoader.java @@ -32,95 +32,30 @@ package com.jme3.scene.plugins.blender; import java.io.IOException; -import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import com.jme3.asset.AssetInfo; -import com.jme3.asset.AssetLoader; -import com.jme3.asset.BlenderKey; import com.jme3.asset.BlenderKey.LoadingResults; -import com.jme3.asset.ModelKey; import com.jme3.scene.Node; import com.jme3.scene.Spatial; -import com.jme3.scene.plugins.blender.animations.ArmatureHelper; -import com.jme3.scene.plugins.blender.animations.IpoHelper; -import com.jme3.scene.plugins.blender.cameras.CameraHelper; -import com.jme3.scene.plugins.blender.constraints.ConstraintHelper; -import com.jme3.scene.plugins.blender.curves.CurvesHelper; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; -import com.jme3.scene.plugins.blender.file.BlenderInputStream; import com.jme3.scene.plugins.blender.file.FileBlockHeader; -import com.jme3.scene.plugins.blender.lights.LightHelper; -import com.jme3.scene.plugins.blender.materials.MaterialHelper; -import com.jme3.scene.plugins.blender.meshes.MeshHelper; -import com.jme3.scene.plugins.blender.modifiers.ModifierHelper; -import com.jme3.scene.plugins.blender.objects.ObjectHelper; -import com.jme3.scene.plugins.blender.particles.ParticlesHelper; -import com.jme3.scene.plugins.blender.textures.TextureHelper; /** * This is the main loading class. Have in notice that asset manager needs to have loaders for resources like textures. * @author Marcin Roguski */ -public class BlenderModelLoader implements AssetLoader { +public class BlenderModelLoader extends BlenderLoader { private static final Logger LOGGER = Logger.getLogger(BlenderModelLoader.class.getName()); @Override public Spatial load(AssetInfo assetInfo) throws IOException { try { - //registering loaders - ModelKey modelKey = (ModelKey) assetInfo.getKey(); - BlenderKey blenderKey; - if (modelKey instanceof BlenderKey) { - blenderKey = (BlenderKey) modelKey; - } else { - blenderKey = new BlenderKey(modelKey.getName()); - blenderKey.setAssetRootPath(modelKey.getFolder()); - } - - //opening stream - BlenderInputStream inputStream = new BlenderInputStream(assetInfo.openStream(), assetInfo.getManager()); - List blocks = new ArrayList(); - FileBlockHeader fileBlock; - DataRepository dataRepository = new DataRepository(); - dataRepository.setAssetManager(assetInfo.getManager()); - dataRepository.setInputStream(inputStream); - dataRepository.setBlenderKey(blenderKey); - dataRepository.putHelper(ArmatureHelper.class, new ArmatureHelper(inputStream.getVersionNumber())); - dataRepository.putHelper(TextureHelper.class, new TextureHelper(inputStream.getVersionNumber())); - dataRepository.putHelper(MeshHelper.class, new MeshHelper(inputStream.getVersionNumber())); - dataRepository.putHelper(ObjectHelper.class, new ObjectHelper(inputStream.getVersionNumber())); - dataRepository.putHelper(CurvesHelper.class, new CurvesHelper(inputStream.getVersionNumber())); - dataRepository.putHelper(LightHelper.class, new LightHelper(inputStream.getVersionNumber())); - dataRepository.putHelper(CameraHelper.class, new CameraHelper(inputStream.getVersionNumber())); - dataRepository.putHelper(ModifierHelper.class, new ModifierHelper(inputStream.getVersionNumber())); - dataRepository.putHelper(MaterialHelper.class, new MaterialHelper(inputStream.getVersionNumber())); - dataRepository.putHelper(ConstraintHelper.class, new ConstraintHelper(inputStream.getVersionNumber(), dataRepository)); - dataRepository.putHelper(IpoHelper.class, new IpoHelper(inputStream.getVersionNumber())); - dataRepository.putHelper(ParticlesHelper.class, new ParticlesHelper(inputStream.getVersionNumber())); - - //setting additional data to helpers - if (blenderKey.isFixUpAxis()) { - ObjectHelper objectHelper = dataRepository.getHelper(ObjectHelper.class); - objectHelper.setyIsUpAxis(true); - CurvesHelper curvesHelper = dataRepository.getHelper(CurvesHelper.class); - curvesHelper.setyIsUpAxis(true); - } - MaterialHelper materialHelper = dataRepository.getHelper(MaterialHelper.class); - materialHelper.setFaceCullMode(blenderKey.getFaceCullMode()); - - //reading the blocks (dna block is automatically saved in the data repository when found)//TODO: zmienić to - do { - fileBlock = new FileBlockHeader(inputStream, dataRepository); - if (!fileBlock.isDnaBlock()) { - blocks.add(fileBlock); - } - } while (!fileBlock.isLastBlock()); - - JmeConverter converter = new JmeConverter(dataRepository); + this.setup(assetInfo); + LoadingResults loadingResults = blenderKey.prepareLoadingResults(); for (FileBlockHeader block : blocks) { if (block.getCode() == FileBlockHeader.BLOCK_OB00) { diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/JmeConverter.java b/engine/src/blender/com/jme3/scene/plugins/blender/JmeConverter.java index 5d037b499..65813c7ce 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/JmeConverter.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/JmeConverter.java @@ -54,109 +54,137 @@ import com.jme3.scene.plugins.blender.objects.ObjectHelper; * This class converts blender file blocks into jMonkeyEngine data structures. * @author Marcin Roguski */ -/*package*/ class JmeConverter { +/* package */class JmeConverter { - private final DataRepository dataRepository; + private final DataRepository dataRepository; - /** - * Constructor. Creates the loader and checks if the given data is correct. - * @param dataRepository - * the data repository; it should have the following field set: - asset manager - blender key - dna block - * data - blender input stream Otherwise IllegalArgumentException will be thrown. - * @param featuresToLoad - * bitwise flag describing what features are to be loaded - * @see FeaturesToLoad FeaturesToLoad - */ - public JmeConverter(DataRepository dataRepository) { - //validating the given data first - if (dataRepository.getAssetManager() == null) { - throw new IllegalArgumentException("Cannot find asset manager!"); - } - if (dataRepository.getBlenderKey() == null) { - throw new IllegalArgumentException("Cannot find blender key!"); - } - if (dataRepository.getDnaBlockData() == null) { - throw new IllegalArgumentException("Cannot find dna block!"); - } - if (dataRepository.getInputStream() == null) { - throw new IllegalArgumentException("Cannot find blender file stream!"); - } - this.dataRepository = dataRepository; - } + /** + * Constructor. Creates the loader and checks if the given data is correct. + * @param dataRepository + * the data repository; it should have the following field set: - asset manager - blender key - dna block + * data - blender input stream Otherwise IllegalArgumentException will be thrown. + * @param featuresToLoad + * bitwise flag describing what features are to be loaded + * @see FeaturesToLoad FeaturesToLoad + */ + public JmeConverter(DataRepository dataRepository) { + // validating the given data first + if (dataRepository.getAssetManager() == null) { + throw new IllegalArgumentException("Cannot find asset manager!"); + } + if (dataRepository.getBlenderKey() == null) { + throw new IllegalArgumentException("Cannot find blender key!"); + } + if (dataRepository.getDnaBlockData() == null) { + throw new IllegalArgumentException("Cannot find dna block!"); + } + if (dataRepository.getInputStream() == null) { + throw new IllegalArgumentException("Cannot find blender file stream!"); + } + this.dataRepository = dataRepository; + } - public Node toScene(Structure structure) {//TODO: poprawny import sceny - if ((dataRepository.getBlenderKey().getFeaturesToLoad() & FeaturesToLoad.SCENES) == 0) { - return null; - } - Structure id = (Structure) structure.getFieldValue("id"); - String sceneName = id.getFieldValue("name").toString(); + /** + * This method converts the given structure to a scene node. + * @param structure + * structure of a scene + * @return scene's node + */ + public Node toScene(Structure structure) {// TODO: import the scene + if ((dataRepository.getBlenderKey().getFeaturesToLoad() & FeaturesToLoad.SCENES) == 0) { + return null; + } + return new Node(structure.getName()); + } - //veryfying layers to be loaded - if (dataRepository.getBlenderKey().getLayersToLoad() < 0) { - int lay = ((Number) structure.getFieldValue("lay")).intValue(); - dataRepository.getBlenderKey().setLayersToLoad(lay);//load only current layer - } - return new Node(sceneName); - } + /** + * This method converts the given structure to a camera. + * @param structure + * structure of a camera + * @return camera's node + */ + public Camera toCamera(Structure structure) throws BlenderFileException { + CameraHelper cameraHelper = dataRepository.getHelper(CameraHelper.class); + if (cameraHelper.shouldBeLoaded(structure, dataRepository)) { + return cameraHelper.toCamera(structure); + } + return null; + } - public Camera toCamera(Structure structure) throws BlenderFileException { - CameraHelper cameraHelper = dataRepository.getHelper(CameraHelper.class); - if (cameraHelper.shouldBeLoaded(structure, dataRepository)) { - return cameraHelper.toCamera(structure); - } - return null; - } + /** + * This method converts the given structure to a light. + * @param structure + * structure of a light + * @return light's node + */ + public Light toLight(Structure structure) throws BlenderFileException { + LightHelper lightHelper = dataRepository.getHelper(LightHelper.class); + if (lightHelper.shouldBeLoaded(structure, dataRepository)) { + return lightHelper.toLight(structure, dataRepository); + } + return null; + } - public Light toLight(Structure structure) throws BlenderFileException { - LightHelper lightHelper = dataRepository.getHelper(LightHelper.class); - if (lightHelper.shouldBeLoaded(structure, dataRepository)) { - return lightHelper.toLight(structure, dataRepository); - } - return null; - } + /** + * This method converts the given structure to a node. + * @param structure + * structure of an object + * @return object's node + */ + public Object toObject(Structure structure) throws BlenderFileException { + ObjectHelper objectHelper = dataRepository.getHelper(ObjectHelper.class); + if (objectHelper.shouldBeLoaded(structure, dataRepository)) { + return objectHelper.toObject(structure, dataRepository); + } + return null; + } - public Object toObject(Structure structure) throws BlenderFileException { - ObjectHelper objectHelper = dataRepository.getHelper(ObjectHelper.class); - if(objectHelper.shouldBeLoaded(structure, dataRepository)) { - return objectHelper.toObject(structure, dataRepository); - } - return null; - } + /** + * This method converts the given structure to a list of geometries. + * @param structure + * structure of a mesh + * @return list of geometries + */ + public List toMesh(Structure structure) throws BlenderFileException { + MeshHelper meshHelper = dataRepository.getHelper(MeshHelper.class); + if (meshHelper.shouldBeLoaded(structure, dataRepository)) { + return meshHelper.toMesh(structure, dataRepository); + } + return null; + } - public List toMesh(Structure structure) throws BlenderFileException { - MeshHelper meshHelper = dataRepository.getHelper(MeshHelper.class); - if(meshHelper.shouldBeLoaded(structure, dataRepository)) { - return meshHelper.toMesh(structure, dataRepository); - } - return null; - } + /** + * This method converts the given structure to a material. + * @param structure + * structure of a material + * @return material's node + */ + public Material toMaterial(Structure structure) throws BlenderFileException { + MaterialHelper materialHelper = dataRepository.getHelper(MaterialHelper.class); + if (materialHelper.shouldBeLoaded(structure, dataRepository)) { + return materialHelper.toMaterial(structure, dataRepository); + } + return null; + } - public Material toMaterial(Structure structure) throws BlenderFileException { - MaterialHelper materialHelper = dataRepository.getHelper(MaterialHelper.class); - if (materialHelper.shouldBeLoaded(structure, dataRepository)) { - return materialHelper.toMaterial(structure, dataRepository); - } - return null; - } + /** + * This method returns the data read from the WORLD file block. The block contains data that can be stored as + * separate jme features and therefore cannot be returned as a single jME scene feature. + * @param structure + * the structure with WORLD block data + * @return data read from the WORLD block that can be added to the scene + */ + public WorldData toWorldData(Structure structure) { + WorldData result = new WorldData(); - /** - * This method returns the data read from the WORLD file block. The block contains data that can be stored as - * separate jme features and therefore cannot be returned as a single jME scene feature. - * @param structure - * the structure with WORLD block data - * @return data read from the WORLD block that can be added to the scene - */ - public WorldData toWorldData(Structure structure) { - WorldData result = new WorldData(); + // reading ambient light + AmbientLight ambientLight = new AmbientLight(); + float ambr = ((Number) structure.getFieldValue("ambr")).floatValue(); + float ambg = ((Number) structure.getFieldValue("ambg")).floatValue(); + float ambb = ((Number) structure.getFieldValue("ambb")).floatValue(); + ambientLight.setColor(new ColorRGBA(ambr, ambg, ambb, 0.0f)); + result.setAmbientLight(ambientLight); - //reading ambient light - AmbientLight ambientLight = new AmbientLight(); - float ambr = ((Number) structure.getFieldValue("ambr")).floatValue(); - float ambg = ((Number) structure.getFieldValue("ambg")).floatValue(); - float ambb = ((Number) structure.getFieldValue("ambb")).floatValue(); - ambientLight.setColor(new ColorRGBA(ambr, ambg, ambb, 0.0f)); - result.setAmbientLight(ambientLight); - - return result; - } + return result; + } } diff --git a/engine/src/test/jme3test/blender/ManualBlenderTester.java b/engine/src/test/jme3test/blender/ManualBlenderTester.java index 81f9103b2..a6a7c84bf 100644 --- a/engine/src/test/jme3test/blender/ManualBlenderTester.java +++ b/engine/src/test/jme3test/blender/ManualBlenderTester.java @@ -187,7 +187,7 @@ public class ManualBlenderTester extends SimpleApplication { Node blenderModel = null; BlenderLoader blenderLoader = new BlenderLoader(); try { - LoadingResults loadingResults = blenderLoader.load(assetInfo); + LoadingResults loadingResults = (LoadingResults) blenderLoader.load(assetInfo); for (Node object : loadingResults.getObjects()) { this.rootNode.attachChild(object); blenderModel = object;