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
3.0
Kae..pl 13 years ago
parent daa86cfec7
commit 6c9395c4e9
  1. 253
      engine/src/blender/com/jme3/scene/plugins/blender/BlenderLoader.java
  2. 69
      engine/src/blender/com/jme3/scene/plugins/blender/BlenderModelLoader.java
  3. 216
      engine/src/blender/com/jme3/scene/plugins/blender/JmeConverter.java
  4. 2
      engine/src/test/jme3test/blender/ManualBlenderTester.java

@ -47,6 +47,7 @@ import com.jme3.asset.ModelKey;
import com.jme3.light.Light; import com.jme3.light.Light;
import com.jme3.renderer.Camera; import com.jme3.renderer.Camera;
import com.jme3.scene.Node; 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.ArmatureHelper;
import com.jme3.scene.plugins.blender.animations.IpoHelper; import com.jme3.scene.plugins.blender.animations.IpoHelper;
import com.jme3.scene.plugins.blender.cameras.CameraHelper; 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 { 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 /** Converter for blender structures. */
public LoadingResults load(AssetInfo assetInfo) throws IOException { protected JmeConverter converter;
try { /** The data repository. */
//registering loaders protected DataRepository dataRepository;
ModelKey modelKey = (ModelKey) assetInfo.getKey(); /** The blender key to use. */
BlenderKey blenderKey; protected BlenderKey blenderKey;
if (modelKey instanceof BlenderKey) { /** The blocks read from the file. */
blenderKey = (BlenderKey) modelKey; protected List<FileBlockHeader> blocks;
} else { /** Blender input stream. */
blenderKey = new BlenderKey(modelKey.getName()); protected BlenderInputStream inputStream;
blenderKey.setAssetRootPath(modelKey.getFolder());
}
//opening stream @Override
BlenderInputStream inputStream = new BlenderInputStream(assetInfo.openStream(), assetInfo.getManager()); public Spatial load(AssetInfo assetInfo) throws IOException {
try {
this.setup(assetInfo);
//reading blocks LoadingResults loadingResults = blenderKey.prepareLoadingResults();
List<FileBlockHeader> blocks = new ArrayList<FileBlockHeader>(); WorldData worldData = null;// a set of data used in different scene aspects
FileBlockHeader fileBlock; for (FileBlockHeader block : blocks) {
DataRepository dataRepository = new DataRepository(); switch (block.getCode()) {
dataRepository.setAssetManager(assetInfo.getManager()); case FileBlockHeader.BLOCK_OB00:// Object
dataRepository.setInputStream(inputStream); Object object = converter.toObject(block.getStructure(dataRepository));
dataRepository.setBlenderKey(blenderKey); 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())); * This method sets up the loader.
dataRepository.putHelper(TextureHelper.class, new TextureHelper(inputStream.getVersionNumber())); * @param assetInfo
dataRepository.putHelper(MeshHelper.class, new MeshHelper(inputStream.getVersionNumber())); * the asset info
dataRepository.putHelper(ObjectHelper.class, new ObjectHelper(inputStream.getVersionNumber())); * @throws BlenderFileException
dataRepository.putHelper(CurvesHelper.class, new CurvesHelper(inputStream.getVersionNumber())); * an exception is throw when something wrong happens with blender file
dataRepository.putHelper(LightHelper.class, new LightHelper(inputStream.getVersionNumber())); */
dataRepository.putHelper(CameraHelper.class, new CameraHelper(inputStream.getVersionNumber())); protected void setup(AssetInfo assetInfo) throws BlenderFileException {
dataRepository.putHelper(ModifierHelper.class, new ModifierHelper(inputStream.getVersionNumber())); // registering loaders
dataRepository.putHelper(MaterialHelper.class, new MaterialHelper(inputStream.getVersionNumber())); ModelKey modelKey = (ModelKey) assetInfo.getKey();
dataRepository.putHelper(ConstraintHelper.class, new ConstraintHelper(inputStream.getVersionNumber(), dataRepository)); if (modelKey instanceof BlenderKey) {
dataRepository.putHelper(IpoHelper.class, new IpoHelper(inputStream.getVersionNumber())); blenderKey = (BlenderKey) modelKey;
dataRepository.putHelper(ParticlesHelper.class, new ParticlesHelper(inputStream.getVersionNumber())); } else {
blenderKey = new BlenderKey(modelKey.getName());
blenderKey.setAssetRootPath(modelKey.getFolder());
}
//setting additional data to helpers // opening stream
if (blenderKey.isFixUpAxis()) { inputStream = new BlenderInputStream(assetInfo.openStream(), assetInfo.getManager());
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 // reading blocks
do { blocks = new ArrayList<FileBlockHeader>();
fileBlock = new FileBlockHeader(inputStream, dataRepository); FileBlockHeader fileBlock;
if (!fileBlock.isDnaBlock()) { dataRepository = new DataRepository();
blocks.add(fileBlock); dataRepository.setAssetManager(assetInfo.getManager());
} dataRepository.setInputStream(inputStream);
} while (!fileBlock.isLastBlock()); dataRepository.setBlenderKey(blenderKey);
JmeConverter converter = new JmeConverter(dataRepository); // creating helpers
LoadingResults loadingResults = blenderKey.prepareLoadingResults(); dataRepository.putHelper(ArmatureHelper.class, new ArmatureHelper(inputStream.getVersionNumber()));
WorldData worldData = null;//a set of data used in different scene aspects dataRepository.putHelper(TextureHelper.class, new TextureHelper(inputStream.getVersionNumber()));
for (FileBlockHeader block : blocks) { dataRepository.putHelper(MeshHelper.class, new MeshHelper(inputStream.getVersionNumber()));
switch (block.getCode()) { dataRepository.putHelper(ObjectHelper.class, new ObjectHelper(inputStream.getVersionNumber()));
case FileBlockHeader.BLOCK_OB00://Object dataRepository.putHelper(CurvesHelper.class, new CurvesHelper(inputStream.getVersionNumber()));
Object object = converter.toObject(block.getStructure(dataRepository)); dataRepository.putHelper(LightHelper.class, new LightHelper(inputStream.getVersionNumber()));
if (object instanceof Node) { dataRepository.putHelper(CameraHelper.class, new CameraHelper(inputStream.getVersionNumber()));
if ((blenderKey.getFeaturesToLoad() & FeaturesToLoad.OBJECTS) != 0) { dataRepository.putHelper(ModifierHelper.class, new ModifierHelper(inputStream.getVersionNumber()));
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()}); dataRepository.putHelper(MaterialHelper.class, new MaterialHelper(inputStream.getVersionNumber()));
if (((Node) object).getParent() == null) { dataRepository.putHelper(ConstraintHelper.class, new ConstraintHelper(inputStream.getVersionNumber(), dataRepository));
loadingResults.addObject((Node) object); dataRepository.putHelper(IpoHelper.class, new IpoHelper(inputStream.getVersionNumber()));
} dataRepository.putHelper(ParticlesHelper.class, new ParticlesHelper(inputStream.getVersionNumber()));
}
} else if (object instanceof Camera) { // setting additional data to helpers
if ((blenderKey.getFeaturesToLoad() & FeaturesToLoad.CAMERAS) != 0) { if (blenderKey.isFixUpAxis()) {
loadingResults.addCamera((Camera) object); ObjectHelper objectHelper = dataRepository.getHelper(ObjectHelper.class);
} objectHelper.setyIsUpAxis(true);
} else if (object instanceof Light) { CurvesHelper curvesHelper = dataRepository.getHelper(CurvesHelper.class);
if ((blenderKey.getFeaturesToLoad() & FeaturesToLoad.LIGHTS) != 0) { curvesHelper.setyIsUpAxis(true);
loadingResults.addLight((Light) object); }
} MaterialHelper materialHelper = dataRepository.getHelper(MaterialHelper.class);
} materialHelper.setFaceCullMode(blenderKey.getFaceCullMode());
break;
case FileBlockHeader.BLOCK_MA00://Material // reading the blocks (dna block is automatically saved in the data repository when found)//TODO: zmienić to
if (blenderKey.isLoadUnlinkedAssets() && (blenderKey.getFeaturesToLoad() & FeaturesToLoad.MATERIALS) != 0) { FileBlockHeader sceneFileBlock = null;
loadingResults.addMaterial(converter.toMaterial(block.getStructure(dataRepository))); do {
} fileBlock = new FileBlockHeader(inputStream, dataRepository);
break; if (!fileBlock.isDnaBlock()) {
case FileBlockHeader.BLOCK_SC00://Scene blocks.add(fileBlock);
if ((blenderKey.getFeaturesToLoad() & FeaturesToLoad.SCENES) != 0) { // save the scene's file block
loadingResults.addScene(converter.toScene(block.getStructure(dataRepository))); if (fileBlock.getCode() == FileBlockHeader.BLOCK_SC00 && blenderKey.getLayersToLoad() < 0) {
} sceneFileBlock = fileBlock;
break; }
case FileBlockHeader.BLOCK_WO00://World }
if (blenderKey.isLoadUnlinkedAssets() && worldData == null) {//onlu one world data is used } while (!fileBlock.isLastBlock());
Structure worldStructure = block.getStructure(dataRepository); // VERIFY LAYERS TO BE LOADED BEFORE LOADING FEATURES
String worldName = worldStructure.getName(); if (sceneFileBlock != null) {
if (blenderKey.getUsedWorld() == null || blenderKey.getUsedWorld().equals(worldName)) { int lay = ((Number) sceneFileBlock.getStructure(dataRepository).getFieldValue("lay")).intValue();
worldData = converter.toWorldData(worldStructure); dataRepository.getBlenderKey().setLayersToLoad(lay);// load only current layer
if ((blenderKey.getFeaturesToLoad() & FeaturesToLoad.LIGHTS) != 0) { }
loadingResults.addLight(worldData.getAmbientLight());
} converter = new JmeConverter(dataRepository);
} }
}
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;
}
} }

@ -32,95 +32,30 @@
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.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import com.jme3.asset.AssetInfo; 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.BlenderKey.LoadingResults;
import com.jme3.asset.ModelKey;
import com.jme3.scene.Node; import com.jme3.scene.Node;
import com.jme3.scene.Spatial; 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.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.BlenderInputStream;
import com.jme3.scene.plugins.blender.file.FileBlockHeader; 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. * This is the main loading class. Have in notice that asset manager needs to have loaders for resources like textures.
* @author Marcin Roguski * @author Marcin Roguski
*/ */
public class BlenderModelLoader implements AssetLoader { public class BlenderModelLoader extends BlenderLoader {
private static final Logger LOGGER = Logger.getLogger(BlenderModelLoader.class.getName()); private static final Logger LOGGER = Logger.getLogger(BlenderModelLoader.class.getName());
@Override @Override
public Spatial load(AssetInfo assetInfo) throws IOException { public Spatial load(AssetInfo assetInfo) throws IOException {
try { try {
//registering loaders this.setup(assetInfo);
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<FileBlockHeader> blocks = new ArrayList<FileBlockHeader>();
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);
LoadingResults loadingResults = blenderKey.prepareLoadingResults(); LoadingResults loadingResults = blenderKey.prepareLoadingResults();
for (FileBlockHeader block : blocks) { for (FileBlockHeader block : blocks) {
if (block.getCode() == FileBlockHeader.BLOCK_OB00) { if (block.getCode() == FileBlockHeader.BLOCK_OB00) {

@ -54,109 +54,137 @@ import com.jme3.scene.plugins.blender.objects.ObjectHelper;
* This class converts blender file blocks into jMonkeyEngine data structures. * This class converts blender file blocks into jMonkeyEngine data structures.
* @author Marcin Roguski * @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. * Constructor. Creates the loader and checks if the given data is correct.
* @param dataRepository * @param dataRepository
* the data repository; it should have the following field set: - asset manager - blender key - dna block * 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. * data - blender input stream Otherwise IllegalArgumentException will be thrown.
* @param featuresToLoad * @param featuresToLoad
* bitwise flag describing what features are to be loaded * bitwise flag describing what features are to be loaded
* @see FeaturesToLoad FeaturesToLoad * @see FeaturesToLoad FeaturesToLoad
*/ */
public JmeConverter(DataRepository dataRepository) { public JmeConverter(DataRepository dataRepository) {
//validating the given data first // validating the given data first
if (dataRepository.getAssetManager() == null) { if (dataRepository.getAssetManager() == null) {
throw new IllegalArgumentException("Cannot find asset manager!"); throw new IllegalArgumentException("Cannot find asset manager!");
} }
if (dataRepository.getBlenderKey() == null) { if (dataRepository.getBlenderKey() == null) {
throw new IllegalArgumentException("Cannot find blender key!"); throw new IllegalArgumentException("Cannot find blender key!");
} }
if (dataRepository.getDnaBlockData() == null) { if (dataRepository.getDnaBlockData() == null) {
throw new IllegalArgumentException("Cannot find dna block!"); throw new IllegalArgumentException("Cannot find dna block!");
} }
if (dataRepository.getInputStream() == null) { if (dataRepository.getInputStream() == null) {
throw new IllegalArgumentException("Cannot find blender file stream!"); throw new IllegalArgumentException("Cannot find blender file stream!");
} }
this.dataRepository = dataRepository; this.dataRepository = dataRepository;
} }
public Node toScene(Structure structure) {//TODO: poprawny import sceny /**
if ((dataRepository.getBlenderKey().getFeaturesToLoad() & FeaturesToLoad.SCENES) == 0) { * This method converts the given structure to a scene node.
return null; * @param structure
} * structure of a scene
Structure id = (Structure) structure.getFieldValue("id"); * @return scene's node
String sceneName = id.getFieldValue("name").toString(); */
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) { * This method converts the given structure to a camera.
int lay = ((Number) structure.getFieldValue("lay")).intValue(); * @param structure
dataRepository.getBlenderKey().setLayersToLoad(lay);//load only current layer * structure of a camera
} * @return camera's node
return new Node(sceneName); */
} 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); * This method converts the given structure to a light.
if (cameraHelper.shouldBeLoaded(structure, dataRepository)) { * @param structure
return cameraHelper.toCamera(structure); * structure of a light
} * @return light's node
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;
}
public Light toLight(Structure structure) throws BlenderFileException { /**
LightHelper lightHelper = dataRepository.getHelper(LightHelper.class); * This method converts the given structure to a node.
if (lightHelper.shouldBeLoaded(structure, dataRepository)) { * @param structure
return lightHelper.toLight(structure, dataRepository); * structure of an object
} * @return object's node
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;
}
public Object toObject(Structure structure) throws BlenderFileException { /**
ObjectHelper objectHelper = dataRepository.getHelper(ObjectHelper.class); * This method converts the given structure to a list of geometries.
if(objectHelper.shouldBeLoaded(structure, dataRepository)) { * @param structure
return objectHelper.toObject(structure, dataRepository); * structure of a mesh
} * @return list of geometries
return null; */
} public List<Geometry> 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<Geometry> toMesh(Structure structure) throws BlenderFileException { /**
MeshHelper meshHelper = dataRepository.getHelper(MeshHelper.class); * This method converts the given structure to a material.
if(meshHelper.shouldBeLoaded(structure, dataRepository)) { * @param structure
return meshHelper.toMesh(structure, dataRepository); * structure of a material
} * @return material's node
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;
}
public Material toMaterial(Structure structure) throws BlenderFileException { /**
MaterialHelper materialHelper = dataRepository.getHelper(MaterialHelper.class); * This method returns the data read from the WORLD file block. The block contains data that can be stored as
if (materialHelper.shouldBeLoaded(structure, dataRepository)) { * separate jme features and therefore cannot be returned as a single jME scene feature.
return materialHelper.toMaterial(structure, dataRepository); * @param structure
} * the structure with WORLD block data
return null; * @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
* This method returns the data read from the WORLD file block. The block contains data that can be stored as AmbientLight ambientLight = new AmbientLight();
* separate jme features and therefore cannot be returned as a single jME scene feature. float ambr = ((Number) structure.getFieldValue("ambr")).floatValue();
* @param structure float ambg = ((Number) structure.getFieldValue("ambg")).floatValue();
* the structure with WORLD block data float ambb = ((Number) structure.getFieldValue("ambb")).floatValue();
* @return data read from the WORLD block that can be added to the scene ambientLight.setColor(new ColorRGBA(ambr, ambg, ambb, 0.0f));
*/ result.setAmbientLight(ambientLight);
public WorldData toWorldData(Structure structure) {
WorldData result = new WorldData();
//reading ambient light return result;
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;
}
} }

@ -187,7 +187,7 @@ public class ManualBlenderTester extends SimpleApplication {
Node blenderModel = null; Node blenderModel = null;
BlenderLoader blenderLoader = new BlenderLoader(); BlenderLoader blenderLoader = new BlenderLoader();
try { try {
LoadingResults loadingResults = blenderLoader.load(assetInfo); LoadingResults loadingResults = (LoadingResults) blenderLoader.load(assetInfo);
for (Node object : loadingResults.getObjects()) { for (Node object : loadingResults.getObjects()) {
this.rootNode.attachChild(object); this.rootNode.attachChild(object);
blenderModel = object; blenderModel = object;

Loading…
Cancel
Save