Refactoring: renaming 'DataRepository' to 'BlenderContext'.

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8244 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
Kae..pl 13 years ago
parent 7a44519bac
commit ba57377795
  1. 18
      engine/src/blender/com/jme3/scene/plugins/blender/AbstractBlenderHelper.java
  2. 4
      engine/src/blender/com/jme3/scene/plugins/blender/BlenderContext.java
  3. 60
      engine/src/blender/com/jme3/scene/plugins/blender/BlenderLoader.java
  4. 2
      engine/src/blender/com/jme3/scene/plugins/blender/BlenderModelLoader.java
  5. 48
      engine/src/blender/com/jme3/scene/plugins/blender/JmeConverter.java
  6. 68
      engine/src/blender/com/jme3/scene/plugins/blender/animations/ArmatureHelper.java
  7. 16
      engine/src/blender/com/jme3/scene/plugins/blender/animations/IpoHelper.java
  8. 6
      engine/src/blender/com/jme3/scene/plugins/blender/cameras/CameraHelper.java
  9. 30
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/Constraint.java
  10. 10
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintAction.java
  11. 10
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintChildOf.java
  12. 10
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintClampTo.java
  13. 10
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintDistLimit.java
  14. 48
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintFactory.java
  15. 10
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintFollowPath.java
  16. 40
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintHelper.java
  17. 18
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintInverseKinematics.java
  18. 10
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintLocLike.java
  19. 10
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintLocLimit.java
  20. 10
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintLockTrack.java
  21. 10
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintMinMax.java
  22. 10
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintNull.java
  23. 10
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintPython.java
  24. 10
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintRigidBodyJoint.java
  25. 10
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintRotLike.java
  26. 10
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintRotLimit.java
  27. 12
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintShrinkWrap.java
  28. 10
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintSizeLike.java
  29. 10
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintSizeLimit.java
  30. 10
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintStretchTo.java
  31. 10
      engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintTransform.java
  32. 78
      engine/src/blender/com/jme3/scene/plugins/blender/curves/CurvesHelper.java
  33. 10
      engine/src/blender/com/jme3/scene/plugins/blender/file/DnaBlockData.java
  34. 26
      engine/src/blender/com/jme3/scene/plugins/blender/file/Field.java
  35. 24
      engine/src/blender/com/jme3/scene/plugins/blender/file/FileBlockHeader.java
  36. 18
      engine/src/blender/com/jme3/scene/plugins/blender/file/Pointer.java
  37. 42
      engine/src/blender/com/jme3/scene/plugins/blender/file/Structure.java
  38. 12
      engine/src/blender/com/jme3/scene/plugins/blender/lights/LightHelper.java
  39. 8
      engine/src/blender/com/jme3/scene/plugins/blender/materials/MaterialContext.java
  40. 60
      engine/src/blender/com/jme3/scene/plugins/blender/materials/MaterialHelper.java
  41. 60
      engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshHelper.java
  42. 66
      engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java
  43. 36
      engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArrayModifier.java
  44. 16
      engine/src/blender/com/jme3/scene/plugins/blender/modifiers/MirrorModifier.java
  45. 8
      engine/src/blender/com/jme3/scene/plugins/blender/modifiers/Modifier.java
  46. 26
      engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ModifierHelper.java
  47. 30
      engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ObjectAnimationModifier.java
  48. 20
      engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ParticlesModifier.java
  49. 74
      engine/src/blender/com/jme3/scene/plugins/blender/objects/ObjectHelper.java
  50. 24
      engine/src/blender/com/jme3/scene/plugins/blender/objects/Properties.java
  51. 10
      engine/src/blender/com/jme3/scene/plugins/blender/particles/ParticlesHelper.java
  52. 6
      engine/src/blender/com/jme3/scene/plugins/blender/textures/NoiseGenerator.java
  53. 20
      engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGenerator.java
  54. 6
      engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorBlend.java
  55. 6
      engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorClouds.java
  56. 6
      engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorDistnoise.java
  57. 6
      engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorMagic.java
  58. 6
      engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorMarble.java
  59. 6
      engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorMusgrave.java
  60. 6
      engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorNoise.java
  61. 6
      engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorStucci.java
  62. 6
      engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorVoronoi.java
  63. 6
      engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureGeneratorWood.java
  64. 82
      engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureHelper.java

@ -109,21 +109,21 @@ public abstract class AbstractBlenderHelper {
* This method loads the properties if they are available and defined for the structure. * This method loads the properties if they are available and defined for the structure.
* @param structure * @param structure
* the structure we read the properties from * the structure we read the properties from
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @return loaded properties or null if they are not available * @return loaded properties or null if they are not available
* @throws BlenderFileException * @throws BlenderFileException
* an exception is thrown when the blend file is somehow corrupted * an exception is thrown when the blend file is somehow corrupted
*/ */
protected Properties loadProperties(Structure structure, DataRepository dataRepository) throws BlenderFileException { protected Properties loadProperties(Structure structure, BlenderContext blenderContext) throws BlenderFileException {
Properties properties = null; Properties properties = null;
Structure id = (Structure) structure.getFieldValue("ID"); Structure id = (Structure) structure.getFieldValue("ID");
if (id != null) { if (id != null) {
Pointer pProperties = (Pointer) id.getFieldValue("properties"); Pointer pProperties = (Pointer) id.getFieldValue("properties");
if (pProperties.isNotNull()) { if (pProperties.isNotNull()) {
Structure propertiesStructure = pProperties.fetchData(dataRepository.getInputStream()).get(0); Structure propertiesStructure = pProperties.fetchData(blenderContext.getInputStream()).get(0);
properties = new Properties(); properties = new Properties();
properties.load(propertiesStructure, dataRepository); properties.load(propertiesStructure, blenderContext);
} }
} }
return properties; return properties;
@ -131,12 +131,12 @@ public abstract class AbstractBlenderHelper {
/** /**
* This method analyzes the given structure and the data contained within * This method analyzes the given structure and the data contained within
* data repository and decides if the feature should be loaded. * blender context and decides if the feature should be loaded.
* @param structure * @param structure
* structure to be analyzed * structure to be analyzed
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @return <b>true</b> if the feature should be loaded and false otherwise * @return <b>true</b> if the feature should be loaded and false otherwise
*/ */
public abstract boolean shouldBeLoaded(Structure structure, DataRepository dataRepository); public abstract boolean shouldBeLoaded(Structure structure, BlenderContext blenderContext);
} }

@ -55,9 +55,9 @@ import com.jme3.scene.plugins.blender.modifiers.Modifier;
/** /**
* The class that stores temporary data and manages it during loading the belnd file. This class is intended to be used * The class that stores temporary data and manages it during loading the belnd file. This class is intended to be used
* in a single loading thread. It holds the state of loading operations. * in a single loading thread. It holds the state of loading operations.
* @author Marcin Roguski * @author Marcin Roguski (Kaelthas)
*/ */
public class DataRepository { public class BlenderContext {
/** The blender key. */ /** The blender key. */
private BlenderKey blenderKey; private BlenderKey blenderKey;

@ -75,8 +75,8 @@ public class BlenderLoader implements AssetLoader {
/** Converter for blender structures. */ /** Converter for blender structures. */
protected JmeConverter converter; protected JmeConverter converter;
/** The data repository. */ /** The blender context. */
protected DataRepository dataRepository; protected BlenderContext blenderContext;
/** The blender key to use. */ /** The blender key to use. */
protected BlenderKey blenderKey; protected BlenderKey blenderKey;
/** The blocks read from the file. */ /** The blocks read from the file. */
@ -94,7 +94,7 @@ public class BlenderLoader implements AssetLoader {
for (FileBlockHeader block : blocks) { for (FileBlockHeader block : blocks) {
switch (block.getCode()) { switch (block.getCode()) {
case FileBlockHeader.BLOCK_OB00:// Object case FileBlockHeader.BLOCK_OB00:// Object
Object object = converter.toObject(block.getStructure(dataRepository)); Object object = converter.toObject(block.getStructure(blenderContext));
if (object instanceof Node) { if (object instanceof Node) {
if ((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() });
@ -114,17 +114,17 @@ public class BlenderLoader implements AssetLoader {
break; break;
case FileBlockHeader.BLOCK_MA00:// Material case FileBlockHeader.BLOCK_MA00:// Material
if (blenderKey.isLoadUnlinkedAssets() && (blenderKey.getFeaturesToLoad() & FeaturesToLoad.MATERIALS) != 0) { if (blenderKey.isLoadUnlinkedAssets() && (blenderKey.getFeaturesToLoad() & FeaturesToLoad.MATERIALS) != 0) {
loadingResults.addMaterial(converter.toMaterial(block.getStructure(dataRepository))); loadingResults.addMaterial(converter.toMaterial(block.getStructure(blenderContext)));
} }
break; break;
case FileBlockHeader.BLOCK_SC00:// Scene case FileBlockHeader.BLOCK_SC00:// Scene
if ((blenderKey.getFeaturesToLoad() & FeaturesToLoad.SCENES) != 0) { if ((blenderKey.getFeaturesToLoad() & FeaturesToLoad.SCENES) != 0) {
loadingResults.addScene(converter.toScene(block.getStructure(dataRepository))); loadingResults.addScene(converter.toScene(block.getStructure(blenderContext)));
} }
break; break;
case FileBlockHeader.BLOCK_WO00:// World case FileBlockHeader.BLOCK_WO00:// World
if (blenderKey.isLoadUnlinkedAssets() && worldData == null) {// onlu one world data is used if (blenderKey.isLoadUnlinkedAssets() && worldData == null) {// onlu one world data is used
Structure worldStructure = block.getStructure(dataRepository); Structure worldStructure = block.getStructure(blenderContext);
String worldName = worldStructure.getName(); String worldName = worldStructure.getName();
if (blenderKey.getUsedWorld() == null || blenderKey.getUsedWorld().equals(worldName)) { if (blenderKey.getUsedWorld() == null || blenderKey.getUsedWorld().equals(worldName)) {
worldData = converter.toWorldData(worldStructure); worldData = converter.toWorldData(worldStructure);
@ -171,39 +171,39 @@ public class BlenderLoader implements AssetLoader {
// reading blocks // reading blocks
blocks = new ArrayList<FileBlockHeader>(); blocks = new ArrayList<FileBlockHeader>();
FileBlockHeader fileBlock; FileBlockHeader fileBlock;
dataRepository = new DataRepository(); blenderContext = new BlenderContext();
dataRepository.setAssetManager(assetInfo.getManager()); blenderContext.setAssetManager(assetInfo.getManager());
dataRepository.setInputStream(inputStream); blenderContext.setInputStream(inputStream);
dataRepository.setBlenderKey(blenderKey); blenderContext.setBlenderKey(blenderKey);
// creating helpers // creating helpers
dataRepository.putHelper(ArmatureHelper.class, new ArmatureHelper(inputStream.getVersionNumber())); blenderContext.putHelper(ArmatureHelper.class, new ArmatureHelper(inputStream.getVersionNumber()));
dataRepository.putHelper(TextureHelper.class, new TextureHelper(inputStream.getVersionNumber())); blenderContext.putHelper(TextureHelper.class, new TextureHelper(inputStream.getVersionNumber()));
dataRepository.putHelper(MeshHelper.class, new MeshHelper(inputStream.getVersionNumber())); blenderContext.putHelper(MeshHelper.class, new MeshHelper(inputStream.getVersionNumber()));
dataRepository.putHelper(ObjectHelper.class, new ObjectHelper(inputStream.getVersionNumber())); blenderContext.putHelper(ObjectHelper.class, new ObjectHelper(inputStream.getVersionNumber()));
dataRepository.putHelper(CurvesHelper.class, new CurvesHelper(inputStream.getVersionNumber())); blenderContext.putHelper(CurvesHelper.class, new CurvesHelper(inputStream.getVersionNumber()));
dataRepository.putHelper(LightHelper.class, new LightHelper(inputStream.getVersionNumber())); blenderContext.putHelper(LightHelper.class, new LightHelper(inputStream.getVersionNumber()));
dataRepository.putHelper(CameraHelper.class, new CameraHelper(inputStream.getVersionNumber())); blenderContext.putHelper(CameraHelper.class, new CameraHelper(inputStream.getVersionNumber()));
dataRepository.putHelper(ModifierHelper.class, new ModifierHelper(inputStream.getVersionNumber())); blenderContext.putHelper(ModifierHelper.class, new ModifierHelper(inputStream.getVersionNumber()));
dataRepository.putHelper(MaterialHelper.class, new MaterialHelper(inputStream.getVersionNumber())); blenderContext.putHelper(MaterialHelper.class, new MaterialHelper(inputStream.getVersionNumber()));
dataRepository.putHelper(ConstraintHelper.class, new ConstraintHelper(inputStream.getVersionNumber(), dataRepository)); blenderContext.putHelper(ConstraintHelper.class, new ConstraintHelper(inputStream.getVersionNumber(), blenderContext));
dataRepository.putHelper(IpoHelper.class, new IpoHelper(inputStream.getVersionNumber())); blenderContext.putHelper(IpoHelper.class, new IpoHelper(inputStream.getVersionNumber()));
dataRepository.putHelper(ParticlesHelper.class, new ParticlesHelper(inputStream.getVersionNumber())); blenderContext.putHelper(ParticlesHelper.class, new ParticlesHelper(inputStream.getVersionNumber()));
// setting additional data to helpers // setting additional data to helpers
if (blenderKey.isFixUpAxis()) { if (blenderKey.isFixUpAxis()) {
ObjectHelper objectHelper = dataRepository.getHelper(ObjectHelper.class); ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class);
objectHelper.setyIsUpAxis(true); objectHelper.setyIsUpAxis(true);
CurvesHelper curvesHelper = dataRepository.getHelper(CurvesHelper.class); CurvesHelper curvesHelper = blenderContext.getHelper(CurvesHelper.class);
curvesHelper.setyIsUpAxis(true); curvesHelper.setyIsUpAxis(true);
} }
MaterialHelper materialHelper = dataRepository.getHelper(MaterialHelper.class); MaterialHelper materialHelper = blenderContext.getHelper(MaterialHelper.class);
materialHelper.setFaceCullMode(blenderKey.getFaceCullMode()); materialHelper.setFaceCullMode(blenderKey.getFaceCullMode());
// reading the blocks (dna block is automatically saved in the data repository when found)//TODO: zmienić to // reading the blocks (dna block is automatically saved in the blender context when found)//TODO: zmienić to
FileBlockHeader sceneFileBlock = null; FileBlockHeader sceneFileBlock = null;
do { do {
fileBlock = new FileBlockHeader(inputStream, dataRepository); fileBlock = new FileBlockHeader(inputStream, blenderContext);
if (!fileBlock.isDnaBlock()) { if (!fileBlock.isDnaBlock()) {
blocks.add(fileBlock); blocks.add(fileBlock);
// save the scene's file block // save the scene's file block
@ -214,10 +214,10 @@ public class BlenderLoader implements AssetLoader {
} while (!fileBlock.isLastBlock()); } while (!fileBlock.isLastBlock());
// VERIFY LAYERS TO BE LOADED BEFORE LOADING FEATURES // VERIFY LAYERS TO BE LOADED BEFORE LOADING FEATURES
if (sceneFileBlock != null) { if (sceneFileBlock != null) {
int lay = ((Number) sceneFileBlock.getStructure(dataRepository).getFieldValue("lay")).intValue(); int lay = ((Number) sceneFileBlock.getStructure(blenderContext).getFieldValue("lay")).intValue();
dataRepository.getBlenderKey().setLayersToLoad(lay);// load only current layer blenderContext.getBlenderKey().setLayersToLoad(lay);// load only current layer
} }
converter = new JmeConverter(dataRepository); converter = new JmeConverter(blenderContext);
} }
} }

@ -61,7 +61,7 @@ public class BlenderModelLoader extends BlenderLoader {
for (FileBlockHeader block : blocks) { for (FileBlockHeader block : blocks) {
if (block.getCode() == FileBlockHeader.BLOCK_OB00) { if (block.getCode() == FileBlockHeader.BLOCK_OB00) {
Object object = converter.toObject(block.getStructure(dataRepository)); Object object = converter.toObject(block.getStructure(blenderContext));
if (object instanceof Node) { 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()}); 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) { if (((Node) object).getParent() == null) {

@ -56,32 +56,32 @@ import com.jme3.scene.plugins.blender.objects.ObjectHelper;
*/ */
/* package */class JmeConverter { /* package */class JmeConverter {
private final DataRepository dataRepository; private final BlenderContext blenderContext;
/** /**
* 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 blenderContext
* the data repository; it should have the following field set: - asset manager - blender key - dna block * the blender context; 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(BlenderContext blenderContext) {
// validating the given data first // validating the given data first
if (dataRepository.getAssetManager() == null) { if (blenderContext.getAssetManager() == null) {
throw new IllegalArgumentException("Cannot find asset manager!"); throw new IllegalArgumentException("Cannot find asset manager!");
} }
if (dataRepository.getBlenderKey() == null) { if (blenderContext.getBlenderKey() == null) {
throw new IllegalArgumentException("Cannot find blender key!"); throw new IllegalArgumentException("Cannot find blender key!");
} }
if (dataRepository.getDnaBlockData() == null) { if (blenderContext.getDnaBlockData() == null) {
throw new IllegalArgumentException("Cannot find dna block!"); throw new IllegalArgumentException("Cannot find dna block!");
} }
if (dataRepository.getInputStream() == null) { if (blenderContext.getInputStream() == null) {
throw new IllegalArgumentException("Cannot find blender file stream!"); throw new IllegalArgumentException("Cannot find blender file stream!");
} }
this.dataRepository = dataRepository; this.blenderContext = blenderContext;
} }
/** /**
@ -91,7 +91,7 @@ import com.jme3.scene.plugins.blender.objects.ObjectHelper;
* @return scene's node * @return scene's node
*/ */
public Node toScene(Structure structure) {// TODO: import the scene public Node toScene(Structure structure) {// TODO: import the scene
if ((dataRepository.getBlenderKey().getFeaturesToLoad() & FeaturesToLoad.SCENES) == 0) { if ((blenderContext.getBlenderKey().getFeaturesToLoad() & FeaturesToLoad.SCENES) == 0) {
return null; return null;
} }
return new Node(structure.getName()); return new Node(structure.getName());
@ -104,8 +104,8 @@ import com.jme3.scene.plugins.blender.objects.ObjectHelper;
* @return camera's node * @return camera's node
*/ */
public Camera toCamera(Structure structure) throws BlenderFileException { public Camera toCamera(Structure structure) throws BlenderFileException {
CameraHelper cameraHelper = dataRepository.getHelper(CameraHelper.class); CameraHelper cameraHelper = blenderContext.getHelper(CameraHelper.class);
if (cameraHelper.shouldBeLoaded(structure, dataRepository)) { if (cameraHelper.shouldBeLoaded(structure, blenderContext)) {
return cameraHelper.toCamera(structure); return cameraHelper.toCamera(structure);
} }
return null; return null;
@ -118,9 +118,9 @@ import com.jme3.scene.plugins.blender.objects.ObjectHelper;
* @return light's node * @return light's node
*/ */
public Light toLight(Structure structure) throws BlenderFileException { public Light toLight(Structure structure) throws BlenderFileException {
LightHelper lightHelper = dataRepository.getHelper(LightHelper.class); LightHelper lightHelper = blenderContext.getHelper(LightHelper.class);
if (lightHelper.shouldBeLoaded(structure, dataRepository)) { if (lightHelper.shouldBeLoaded(structure, blenderContext)) {
return lightHelper.toLight(structure, dataRepository); return lightHelper.toLight(structure, blenderContext);
} }
return null; return null;
} }
@ -132,9 +132,9 @@ import com.jme3.scene.plugins.blender.objects.ObjectHelper;
* @return object's node * @return object's node
*/ */
public Object toObject(Structure structure) throws BlenderFileException { public Object toObject(Structure structure) throws BlenderFileException {
ObjectHelper objectHelper = dataRepository.getHelper(ObjectHelper.class); ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class);
if (objectHelper.shouldBeLoaded(structure, dataRepository)) { if (objectHelper.shouldBeLoaded(structure, blenderContext)) {
return objectHelper.toObject(structure, dataRepository); return objectHelper.toObject(structure, blenderContext);
} }
return null; return null;
} }
@ -146,9 +146,9 @@ import com.jme3.scene.plugins.blender.objects.ObjectHelper;
* @return list of geometries * @return list of geometries
*/ */
public List<Geometry> toMesh(Structure structure) throws BlenderFileException { public List<Geometry> toMesh(Structure structure) throws BlenderFileException {
MeshHelper meshHelper = dataRepository.getHelper(MeshHelper.class); MeshHelper meshHelper = blenderContext.getHelper(MeshHelper.class);
if (meshHelper.shouldBeLoaded(structure, dataRepository)) { if (meshHelper.shouldBeLoaded(structure, blenderContext)) {
return meshHelper.toMesh(structure, dataRepository); return meshHelper.toMesh(structure, blenderContext);
} }
return null; return null;
} }
@ -160,9 +160,9 @@ import com.jme3.scene.plugins.blender.objects.ObjectHelper;
* @return material's node * @return material's node
*/ */
public Material toMaterial(Structure structure) throws BlenderFileException { public Material toMaterial(Structure structure) throws BlenderFileException {
MaterialHelper materialHelper = dataRepository.getHelper(MaterialHelper.class); MaterialHelper materialHelper = blenderContext.getHelper(MaterialHelper.class);
if (materialHelper.shouldBeLoaded(structure, dataRepository)) { if (materialHelper.shouldBeLoaded(structure, blenderContext)) {
return materialHelper.toMaterial(structure, dataRepository); return materialHelper.toMaterial(structure, blenderContext);
} }
return null; return null;
} }

@ -43,7 +43,7 @@ import com.jme3.animation.BoneTrack;
import com.jme3.math.Matrix4f; import com.jme3.math.Matrix4f;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.scene.plugins.blender.AbstractBlenderHelper; import com.jme3.scene.plugins.blender.AbstractBlenderHelper;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.curves.BezierCurve; import com.jme3.scene.plugins.blender.curves.BezierCurve;
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.BlenderInputStream;
@ -104,11 +104,11 @@ public class ArmatureHelper extends AbstractBlenderHelper {
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blender file is somehow corrupted * this exception is thrown when the blender file is somehow corrupted
*/ */
public Map<Integer, Integer> getGroupToBoneIndexMap(Structure defBaseStructure, DataRepository dataRepository) throws BlenderFileException { public Map<Integer, Integer> getGroupToBoneIndexMap(Structure defBaseStructure, BlenderContext blenderContext) throws BlenderFileException {
Map<Integer, Integer> result = null; Map<Integer, Integer> result = null;
if (bonesMap != null && bonesMap.size() != 0) { if (bonesMap != null && bonesMap.size() != 0) {
result = new HashMap<Integer, Integer>(); result = new HashMap<Integer, Integer>();
List<Structure> deformGroups = defBaseStructure.evaluateListBase(dataRepository);//bDeformGroup List<Structure> deformGroups = defBaseStructure.evaluateListBase(blenderContext);//bDeformGroup
int groupIndex = 0; int groupIndex = 0;
for (Structure deformGroup : deformGroups) { for (Structure deformGroup : deformGroups) {
String deformGroupName = deformGroup.getFieldValue("name").toString(); String deformGroupName = deformGroup.getFieldValue("name").toString();
@ -146,14 +146,14 @@ public class ArmatureHelper extends AbstractBlenderHelper {
* a structure containing the bone data * a structure containing the bone data
* @param parent * @param parent
* the bone parent; if null then we read the root bone * the bone parent; if null then we read the root bone
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @return the bone transformation data; contains bone chierarchy and the bone's matrices * @return the bone transformation data; contains bone chierarchy and the bone's matrices
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blender file is somehow corrupted * this exception is thrown when the blender file is somehow corrupted
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public BoneTransformationData readBoneAndItsChildren(Structure boneStructure, BoneTransformationData parent, DataRepository dataRepository) throws BlenderFileException { public BoneTransformationData readBoneAndItsChildren(Structure boneStructure, BoneTransformationData parent, BlenderContext blenderContext) throws BlenderFileException {
String name = boneStructure.getFieldValue("name").toString(); String name = boneStructure.getFieldValue("name").toString();
Bone bone = new Bone(name); Bone bone = new Bone(name);
int bonesAmount = bonesOMAs.size(); int bonesAmount = bonesOMAs.size();
@ -165,12 +165,12 @@ public class ArmatureHelper extends AbstractBlenderHelper {
DynamicArray<Float> sizeArray = (DynamicArray<Float>) boneStructure.getFieldValue("size"); DynamicArray<Float> sizeArray = (DynamicArray<Float>) boneStructure.getFieldValue("size");
Vector3f size = new Vector3f(sizeArray.get(0), sizeArray.get(1), sizeArray.get(2)); Vector3f size = new Vector3f(sizeArray.get(0), sizeArray.get(1), sizeArray.get(2));
BoneTransformationData boneTransformationData = new BoneTransformationData(boneArmatureMatrix, size, bone, parent); BoneTransformationData boneTransformationData = new BoneTransformationData(boneArmatureMatrix, size, bone, parent);
dataRepository.addLoadedFeatures(boneStructure.getOldMemoryAddress(), name, boneStructure, bone); blenderContext.addLoadedFeatures(boneStructure.getOldMemoryAddress(), name, boneStructure, bone);
Structure childbase = (Structure) boneStructure.getFieldValue("childbase"); Structure childbase = (Structure) boneStructure.getFieldValue("childbase");
List<Structure> children = childbase.evaluateListBase(dataRepository);//Bone List<Structure> children = childbase.evaluateListBase(blenderContext);//Bone
for (Structure boneChild : children) { for (Structure boneChild : children) {
this.readBoneAndItsChildren(boneChild, boneTransformationData, dataRepository); this.readBoneAndItsChildren(boneChild, boneTransformationData, blenderContext);
} }
return boneTransformationData; return boneTransformationData;
} }
@ -293,7 +293,7 @@ public class ArmatureHelper extends AbstractBlenderHelper {
} }
@Override @Override
public boolean shouldBeLoaded(Structure structure, DataRepository dataRepository) { public boolean shouldBeLoaded(Structure structure, BlenderContext blenderContext) {
return true; return true;
} }
@ -302,8 +302,8 @@ public class ArmatureHelper extends AbstractBlenderHelper {
* *
* @param actionStructure * @param actionStructure
* the structure containing the tracks * the structure containing the tracks
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @param objectName * @param objectName
* the name of the object that will use these tracks * the name of the object that will use these tracks
* @param animationName * @param animationName
@ -313,11 +313,11 @@ public class ArmatureHelper extends AbstractBlenderHelper {
* an exception is thrown when there are problems with the blend * an exception is thrown when there are problems with the blend
* file * file
*/ */
public BoneTrack[] getTracks(Structure actionStructure, DataRepository dataRepository, String objectName, String animationName) throws BlenderFileException { public BoneTrack[] getTracks(Structure actionStructure, BlenderContext blenderContext, String objectName, String animationName) throws BlenderFileException {
if (blenderVersion < 250) { if (blenderVersion < 250) {
return this.getTracks249(actionStructure, dataRepository, objectName, animationName); return this.getTracks249(actionStructure, blenderContext, objectName, animationName);
} else { } else {
return this.getTracks250(actionStructure, dataRepository, objectName, animationName); return this.getTracks250(actionStructure, blenderContext, objectName, animationName);
} }
} }
@ -326,8 +326,8 @@ public class ArmatureHelper extends AbstractBlenderHelper {
* *
* @param actionStructure * @param actionStructure
* the structure containing the tracks * the structure containing the tracks
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @param objectName * @param objectName
* the name of the object that will use these tracks * the name of the object that will use these tracks
* @param animationName * @param animationName
@ -337,12 +337,12 @@ public class ArmatureHelper extends AbstractBlenderHelper {
* an exception is thrown when there are problems with the blend * an exception is thrown when there are problems with the blend
* file * file
*/ */
private BoneTrack[] getTracks250(Structure actionStructure, DataRepository dataRepository, String objectName, String animationName) throws BlenderFileException { private BoneTrack[] getTracks250(Structure actionStructure, BlenderContext blenderContext, String objectName, String animationName) throws BlenderFileException {
LOGGER.log(Level.INFO, "Getting tracks!"); LOGGER.log(Level.INFO, "Getting tracks!");
int fps = dataRepository.getBlenderKey().getFps(); int fps = blenderContext.getBlenderKey().getFps();
int[] animationFrames = dataRepository.getBlenderKey().getAnimationFrames(objectName, animationName); int[] animationFrames = blenderContext.getBlenderKey().getAnimationFrames(objectName, animationName);
Structure groups = (Structure) actionStructure.getFieldValue("groups"); Structure groups = (Structure) actionStructure.getFieldValue("groups");
List<Structure> actionGroups = groups.evaluateListBase(dataRepository);//bActionGroup List<Structure> actionGroups = groups.evaluateListBase(blenderContext);//bActionGroup
if (actionGroups != null && actionGroups.size() > 0 && (bonesMap == null || bonesMap.size() == 0)) { if (actionGroups != null && actionGroups.size() > 0 && (bonesMap == null || bonesMap.size() == 0)) {
throw new IllegalStateException("No bones found! Cannot proceed to calculating tracks!"); throw new IllegalStateException("No bones found! Cannot proceed to calculating tracks!");
} }
@ -352,15 +352,15 @@ public class ArmatureHelper extends AbstractBlenderHelper {
String name = actionGroup.getFieldValue("name").toString(); String name = actionGroup.getFieldValue("name").toString();
Integer boneIndex = bonesMap.get(name); Integer boneIndex = bonesMap.get(name);
if (boneIndex != null) { if (boneIndex != null) {
List<Structure> channels = ((Structure) actionGroup.getFieldValue("channels")).evaluateListBase(dataRepository); List<Structure> channels = ((Structure) actionGroup.getFieldValue("channels")).evaluateListBase(blenderContext);
BezierCurve[] bezierCurves = new BezierCurve[channels.size()]; BezierCurve[] bezierCurves = new BezierCurve[channels.size()];
int channelCounter = 0; int channelCounter = 0;
for (Structure c : channels) { for (Structure c : channels) {
//reading rna path first //reading rna path first
BlenderInputStream bis = dataRepository.getInputStream(); BlenderInputStream bis = blenderContext.getInputStream();
int currentPosition = bis.getPosition(); int currentPosition = bis.getPosition();
Pointer pRnaPath = (Pointer) c.getFieldValue("rna_path"); Pointer pRnaPath = (Pointer) c.getFieldValue("rna_path");
FileBlockHeader dataFileBlock = dataRepository.getFileBlock(pRnaPath.getOldMemoryAddress()); FileBlockHeader dataFileBlock = blenderContext.getFileBlock(pRnaPath.getOldMemoryAddress());
bis.setPosition(dataFileBlock.getBlockPosition()); bis.setPosition(dataFileBlock.getBlockPosition());
String rnaPath = bis.readString(); String rnaPath = bis.readString();
bis.setPosition(currentPosition); bis.setPosition(currentPosition);
@ -368,7 +368,7 @@ public class ArmatureHelper extends AbstractBlenderHelper {
int type = this.getCurveType(rnaPath, arrayIndex); int type = this.getCurveType(rnaPath, arrayIndex);
Pointer pBezTriple = (Pointer) c.getFieldValue("bezt"); Pointer pBezTriple = (Pointer) c.getFieldValue("bezt");
List<Structure> bezTriples = pBezTriple.fetchData(dataRepository.getInputStream()); List<Structure> bezTriples = pBezTriple.fetchData(blenderContext.getInputStream());
bezierCurves[channelCounter++] = new BezierCurve(type, bezTriples, 2); bezierCurves[channelCounter++] = new BezierCurve(type, bezTriples, 2);
} }
@ -384,8 +384,8 @@ public class ArmatureHelper extends AbstractBlenderHelper {
* *
* @param actionStructure * @param actionStructure
* the structure containing the tracks * the structure containing the tracks
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @param objectName * @param objectName
* the name of the object that will use these tracks * the name of the object that will use these tracks
* @param animationName * @param animationName
@ -395,13 +395,13 @@ public class ArmatureHelper extends AbstractBlenderHelper {
* an exception is thrown when there are problems with the blend * an exception is thrown when there are problems with the blend
* file * file
*/ */
private BoneTrack[] getTracks249(Structure actionStructure, DataRepository dataRepository, String objectName, String animationName) throws BlenderFileException { private BoneTrack[] getTracks249(Structure actionStructure, BlenderContext blenderContext, String objectName, String animationName) throws BlenderFileException {
LOGGER.log(Level.INFO, "Getting tracks!"); LOGGER.log(Level.INFO, "Getting tracks!");
IpoHelper ipoHelper = dataRepository.getHelper(IpoHelper.class); IpoHelper ipoHelper = blenderContext.getHelper(IpoHelper.class);
int fps = dataRepository.getBlenderKey().getFps(); int fps = blenderContext.getBlenderKey().getFps();
int[] animationFrames = dataRepository.getBlenderKey().getAnimationFrames(objectName, animationName); int[] animationFrames = blenderContext.getBlenderKey().getAnimationFrames(objectName, animationName);
Structure chanbase = (Structure) actionStructure.getFieldValue("chanbase"); Structure chanbase = (Structure) actionStructure.getFieldValue("chanbase");
List<Structure> actionChannels = chanbase.evaluateListBase(dataRepository);//bActionChannel List<Structure> actionChannels = chanbase.evaluateListBase(blenderContext);//bActionChannel
if (actionChannels != null && actionChannels.size() > 0 && (bonesMap == null || bonesMap.size() == 0)) { if (actionChannels != null && actionChannels.size() > 0 && (bonesMap == null || bonesMap.size() == 0)) {
throw new IllegalStateException("No bones found! Cannot proceed to calculating tracks!"); throw new IllegalStateException("No bones found! Cannot proceed to calculating tracks!");
} }
@ -412,8 +412,8 @@ public class ArmatureHelper extends AbstractBlenderHelper {
if (boneIndex != null) { if (boneIndex != null) {
Pointer p = (Pointer) bActionChannel.getFieldValue("ipo"); Pointer p = (Pointer) bActionChannel.getFieldValue("ipo");
if (!p.isNull()) { if (!p.isNull()) {
Structure ipoStructure = p.fetchData(dataRepository.getInputStream()).get(0); Structure ipoStructure = p.fetchData(blenderContext.getInputStream()).get(0);
Ipo ipo = ipoHelper.createIpo(ipoStructure, dataRepository); Ipo ipo = ipoHelper.createIpo(ipoStructure, blenderContext);
tracks.add(ipo.calculateTrack(boneIndex.intValue(), animationFrames[0], animationFrames[1], fps)); tracks.add(ipo.calculateTrack(boneIndex.intValue(), animationFrames[0], animationFrames[1], fps));
} }
} }

@ -4,7 +4,7 @@ import java.util.List;
import com.jme3.animation.BoneTrack; import com.jme3.animation.BoneTrack;
import com.jme3.scene.plugins.blender.AbstractBlenderHelper; import com.jme3.scene.plugins.blender.AbstractBlenderHelper;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.curves.BezierCurve; import com.jme3.scene.plugins.blender.curves.BezierCurve;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.Pointer; import com.jme3.scene.plugins.blender.file.Pointer;
@ -31,30 +31,30 @@ public class IpoHelper extends AbstractBlenderHelper {
* This method creates an ipo object used for interpolation calculations. * This method creates an ipo object used for interpolation calculations.
* @param ipoStructure * @param ipoStructure
* the structure with ipo definition * the structure with ipo definition
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @return the ipo object * @return the ipo object
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blender file is somehow corrupted * this exception is thrown when the blender file is somehow corrupted
*/ */
public Ipo createIpo(Structure ipoStructure, DataRepository dataRepository) throws BlenderFileException { public Ipo createIpo(Structure ipoStructure, BlenderContext blenderContext) throws BlenderFileException {
Structure curvebase = (Structure) ipoStructure.getFieldValue("curve"); Structure curvebase = (Structure) ipoStructure.getFieldValue("curve");
//preparing bezier curves //preparing bezier curves
Ipo result = null; Ipo result = null;
List<Structure> curves = curvebase.evaluateListBase(dataRepository);//IpoCurve List<Structure> curves = curvebase.evaluateListBase(blenderContext);//IpoCurve
if (curves.size() > 0) { if (curves.size() > 0) {
BezierCurve[] bezierCurves = new BezierCurve[curves.size()]; BezierCurve[] bezierCurves = new BezierCurve[curves.size()];
int frame = 0; int frame = 0;
for (Structure curve : curves) { for (Structure curve : curves) {
Pointer pBezTriple = (Pointer) curve.getFieldValue("bezt"); Pointer pBezTriple = (Pointer) curve.getFieldValue("bezt");
List<Structure> bezTriples = pBezTriple.fetchData(dataRepository.getInputStream()); List<Structure> bezTriples = pBezTriple.fetchData(blenderContext.getInputStream());
int type = ((Number) curve.getFieldValue("adrcode")).intValue(); int type = ((Number) curve.getFieldValue("adrcode")).intValue();
bezierCurves[frame++] = new BezierCurve(type, bezTriples, 2); bezierCurves[frame++] = new BezierCurve(type, bezTriples, 2);
} }
curves.clear(); curves.clear();
result = new Ipo(bezierCurves); result = new Ipo(bezierCurves);
dataRepository.addLoadedFeatures(ipoStructure.getOldMemoryAddress(), ipoStructure.getName(), ipoStructure, result); blenderContext.addLoadedFeatures(ipoStructure.getOldMemoryAddress(), ipoStructure.getName(), ipoStructure, result);
} }
return result; return result;
} }
@ -71,7 +71,7 @@ public class IpoHelper extends AbstractBlenderHelper {
} }
@Override @Override
public boolean shouldBeLoaded(Structure structure, DataRepository dataRepository) { public boolean shouldBeLoaded(Structure structure, BlenderContext blenderContext) {
return true; return true;
} }

@ -6,7 +6,7 @@ import java.util.logging.Logger;
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.plugins.blender.AbstractBlenderHelper; import com.jme3.scene.plugins.blender.AbstractBlenderHelper;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
@ -112,7 +112,7 @@ public class CameraHelper extends AbstractBlenderHelper {
} }
@Override @Override
public boolean shouldBeLoaded(Structure structure, DataRepository dataRepository) { public boolean shouldBeLoaded(Structure structure, BlenderContext blenderContext) {
return (dataRepository.getBlenderKey().getFeaturesToLoad() & FeaturesToLoad.CAMERAS) != 0; return (blenderContext.getBlenderKey().getFeaturesToLoad() & FeaturesToLoad.CAMERAS) != 0;
} }
} }

@ -7,8 +7,8 @@ import com.jme3.animation.Skeleton;
import com.jme3.math.Quaternion; import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.scene.Node; import com.jme3.scene.Node;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.DataRepository.LoadedFeatureDataType; import com.jme3.scene.plugins.blender.BlenderContext.LoadedFeatureDataType;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.Pointer; import com.jme3.scene.plugins.blender.file.Pointer;
@ -32,7 +32,7 @@ public abstract class Constraint {
protected final Structure data; protected final Structure data;
/** The ipo object defining influence. */ /** The ipo object defining influence. */
protected final Ipo ipo; protected final Ipo ipo;
protected DataRepository dataRepository; protected BlenderContext blenderContext;
/** /**
* This constructor creates the constraint instance. * This constructor creates the constraint instance.
* *
@ -42,14 +42,14 @@ public abstract class Constraint {
* the old memory address of the constraint owner * the old memory address of the constraint owner
* @param influenceIpo * @param influenceIpo
* the ipo curve of the influence factor * the ipo curve of the influence factor
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blender file is somehow * this exception is thrown when the blender file is somehow
* corrupted * corrupted
*/ */
public Constraint(Structure constraintStructure, Long boneOMA, public Constraint(Structure constraintStructure, Long boneOMA,
Ipo influenceIpo, DataRepository dataRepository) throws BlenderFileException { Ipo influenceIpo, BlenderContext blenderContext) throws BlenderFileException {
this.name = constraintStructure.getFieldValue("name").toString(); this.name = constraintStructure.getFieldValue("name").toString();
ConstraintType constraintType = ConstraintType.valueOf(((Number)constraintStructure.getFieldValue("type")).intValue()); ConstraintType constraintType = ConstraintType.valueOf(((Number)constraintStructure.getFieldValue("type")).intValue());
if(constraintType != this.getType()) { if(constraintType != this.getType()) {
@ -57,7 +57,7 @@ public abstract class Constraint {
} }
Pointer pData = (Pointer) constraintStructure.getFieldValue("data"); Pointer pData = (Pointer) constraintStructure.getFieldValue("data");
if (pData.isNotNull()) { if (pData.isNotNull()) {
data = pData.fetchData(dataRepository.getInputStream()).get(0); data = pData.fetchData(blenderContext.getInputStream()).get(0);
} else { } else {
throw new BlenderFileException("The constraint has no data specified!"); throw new BlenderFileException("The constraint has no data specified!");
} }
@ -102,7 +102,7 @@ public abstract class Constraint {
* @return the bone track for the bone that is being affected by the constraint * @return the bone track for the bone that is being affected by the constraint
*/ */
protected BoneTrack getBoneTrack(Skeleton skeleton, BoneAnimation boneAnimation) { protected BoneTrack getBoneTrack(Skeleton skeleton, BoneAnimation boneAnimation) {
Bone bone = (Bone) dataRepository.getLoadedFeature(boneOMA, LoadedFeatureDataType.LOADED_FEATURE); Bone bone = (Bone) blenderContext.getLoadedFeature(boneOMA, LoadedFeatureDataType.LOADED_FEATURE);
int boneIndex = bone==null ? 0 : skeleton.getBoneIndex(bone);//bone==null may mean the object animation int boneIndex = bone==null ? 0 : skeleton.getBoneIndex(bone);//bone==null may mean the object animation
if (boneIndex != -1) { if (boneIndex != -1) {
//searching for track for this bone //searching for track for this bone
@ -124,17 +124,17 @@ public abstract class Constraint {
protected Object getTarget(LoadedFeatureDataType loadedFeatureDataType) throws BlenderFileException { protected Object getTarget(LoadedFeatureDataType loadedFeatureDataType) throws BlenderFileException {
//load the feature through objectHelper, this way we are certain the object loads and has //load the feature through objectHelper, this way we are certain the object loads and has
//his own constraints applied to traces //his own constraints applied to traces
ObjectHelper objectHelper = dataRepository.getHelper(ObjectHelper.class); ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class);
//always load the target first //always load the target first
Long targetOMA = ((Pointer) data.getFieldValue("tar")).getOldMemoryAddress(); Long targetOMA = ((Pointer) data.getFieldValue("tar")).getOldMemoryAddress();
Structure objectStructure = dataRepository.getFileBlock(targetOMA).getStructure(dataRepository); Structure objectStructure = blenderContext.getFileBlock(targetOMA).getStructure(blenderContext);
Object result = objectHelper.toObject(objectStructure, dataRepository); Object result = objectHelper.toObject(objectStructure, blenderContext);
//subtarget should be loaded alogn with target //subtarget should be loaded alogn with target
Object subtarget = data.getFieldValue("subtarget"); Object subtarget = data.getFieldValue("subtarget");
String subtargetName = subtarget==null ? null : subtarget.toString(); String subtargetName = subtarget==null ? null : subtarget.toString();
if (subtargetName!=null && subtargetName.length() > 0) { if (subtargetName!=null && subtargetName.length() > 0) {
result = dataRepository.getLoadedFeature(subtargetName, loadedFeatureDataType); result = blenderContext.getLoadedFeature(subtargetName, loadedFeatureDataType);
} }
return result; return result;
} }
@ -145,7 +145,7 @@ public abstract class Constraint {
*/ */
protected Vector3f getTargetLocation() { protected Vector3f getTargetLocation() {
Long targetOMA = ((Pointer) data.getFieldValue("tar")).getOldMemoryAddress(); Long targetOMA = ((Pointer) data.getFieldValue("tar")).getOldMemoryAddress();
Node targetObject = (Node) dataRepository.getLoadedFeature(targetOMA, LoadedFeatureDataType.LOADED_FEATURE); Node targetObject = (Node) blenderContext.getLoadedFeature(targetOMA, LoadedFeatureDataType.LOADED_FEATURE);
switch (targetSpace) { switch (targetSpace) {
case CONSTRAINT_SPACE_LOCAL: case CONSTRAINT_SPACE_LOCAL:
return targetObject.getLocalTranslation(); return targetObject.getLocalTranslation();
@ -172,7 +172,7 @@ public abstract class Constraint {
*/ */
protected Quaternion getTargetRotation() { protected Quaternion getTargetRotation() {
Long targetOMA = ((Pointer) data.getFieldValue("tar")).getOldMemoryAddress(); Long targetOMA = ((Pointer) data.getFieldValue("tar")).getOldMemoryAddress();
Node targetObject = (Node) dataRepository.getLoadedFeature(targetOMA, LoadedFeatureDataType.LOADED_FEATURE); Node targetObject = (Node) blenderContext.getLoadedFeature(targetOMA, LoadedFeatureDataType.LOADED_FEATURE);
switch (targetSpace) { switch (targetSpace) {
case CONSTRAINT_SPACE_LOCAL: case CONSTRAINT_SPACE_LOCAL:
return targetObject.getLocalRotation(); return targetObject.getLocalRotation();
@ -189,7 +189,7 @@ public abstract class Constraint {
*/ */
protected Vector3f getTargetScale() { protected Vector3f getTargetScale() {
Long targetOMA = ((Pointer) data.getFieldValue("tar")).getOldMemoryAddress(); Long targetOMA = ((Pointer) data.getFieldValue("tar")).getOldMemoryAddress();
Node targetObject = (Node) dataRepository.getLoadedFeature(targetOMA, LoadedFeatureDataType.LOADED_FEATURE); Node targetObject = (Node) blenderContext.getLoadedFeature(targetOMA, LoadedFeatureDataType.LOADED_FEATURE);
switch (targetSpace) { switch (targetSpace) {
case CONSTRAINT_SPACE_LOCAL: case CONSTRAINT_SPACE_LOCAL:
return targetObject.getLocalScale(); return targetObject.getLocalScale();

@ -5,7 +5,7 @@ import java.util.logging.Logger;
import com.jme3.animation.BoneAnimation; import com.jme3.animation.BoneAnimation;
import com.jme3.animation.Skeleton; import com.jme3.animation.Skeleton;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
@ -26,15 +26,15 @@ import com.jme3.scene.plugins.blender.file.Structure;
* the old memory address of the constraint owner * the old memory address of the constraint owner
* @param influenceIpo * @param influenceIpo
* the ipo curve of the influence factor * the ipo curve of the influence factor
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blender file is somehow * this exception is thrown when the blender file is somehow
* corrupted * corrupted
*/ */
public ConstraintAction(Structure constraintStructure, Long boneOMA, public ConstraintAction(Structure constraintStructure, Long boneOMA,
Ipo influenceIpo, DataRepository dataRepository) throws BlenderFileException { Ipo influenceIpo, BlenderContext blenderContext) throws BlenderFileException {
super(constraintStructure, boneOMA, influenceIpo, dataRepository); super(constraintStructure, boneOMA, influenceIpo, blenderContext);
} }
@Override @Override

@ -5,7 +5,7 @@ import java.util.logging.Logger;
import com.jme3.animation.BoneAnimation; import com.jme3.animation.BoneAnimation;
import com.jme3.animation.Skeleton; import com.jme3.animation.Skeleton;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
@ -26,15 +26,15 @@ import com.jme3.scene.plugins.blender.file.Structure;
* the old memory address of the constraint owner * the old memory address of the constraint owner
* @param influenceIpo * @param influenceIpo
* the ipo curve of the influence factor * the ipo curve of the influence factor
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blender file is somehow * this exception is thrown when the blender file is somehow
* corrupted * corrupted
*/ */
public ConstraintChildOf(Structure constraintStructure, Long boneOMA, public ConstraintChildOf(Structure constraintStructure, Long boneOMA,
Ipo influenceIpo, DataRepository dataRepository) throws BlenderFileException { Ipo influenceIpo, BlenderContext blenderContext) throws BlenderFileException {
super(constraintStructure, boneOMA, influenceIpo, dataRepository); super(constraintStructure, boneOMA, influenceIpo, blenderContext);
} }
@Override @Override

@ -5,7 +5,7 @@ import java.util.logging.Logger;
import com.jme3.animation.BoneAnimation; import com.jme3.animation.BoneAnimation;
import com.jme3.animation.Skeleton; import com.jme3.animation.Skeleton;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
@ -26,16 +26,16 @@ import com.jme3.scene.plugins.blender.file.Structure;
* the old memory address of the constraint owner * the old memory address of the constraint owner
* @param influenceIpo * @param influenceIpo
* the ipo curve of the influence factor * the ipo curve of the influence factor
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blender file is somehow * this exception is thrown when the blender file is somehow
* corrupted * corrupted
*/ */
public ConstraintClampTo(Structure constraintStructure, Long boneOMA, public ConstraintClampTo(Structure constraintStructure, Long boneOMA,
Ipo influenceIpo, DataRepository dataRepository) Ipo influenceIpo, BlenderContext blenderContext)
throws BlenderFileException { throws BlenderFileException {
super(constraintStructure, boneOMA, influenceIpo, dataRepository); super(constraintStructure, boneOMA, influenceIpo, blenderContext);
} }
@Override @Override

@ -4,7 +4,7 @@ import com.jme3.animation.BoneAnimation;
import com.jme3.animation.BoneTrack; import com.jme3.animation.BoneTrack;
import com.jme3.animation.Skeleton; import com.jme3.animation.Skeleton;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
@ -27,15 +27,15 @@ import com.jme3.scene.plugins.blender.file.Structure;
* the old memory address of the constraint owner * the old memory address of the constraint owner
* @param influenceIpo * @param influenceIpo
* the ipo curve of the influence factor * the ipo curve of the influence factor
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blender file is somehow * this exception is thrown when the blender file is somehow
* corrupted * corrupted
*/ */
public ConstraintDistLimit(Structure constraintStructure, Long boneOMA, public ConstraintDistLimit(Structure constraintStructure, Long boneOMA,
Ipo influenceIpo, DataRepository dataRepository) throws BlenderFileException { Ipo influenceIpo, BlenderContext blenderContext) throws BlenderFileException {
super(constraintStructure, boneOMA, influenceIpo, dataRepository); super(constraintStructure, boneOMA, influenceIpo, blenderContext);
} }
@Override @Override

@ -1,6 +1,6 @@
package com.jme3.scene.plugins.blender.constraints; package com.jme3.scene.plugins.blender.constraints;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
@ -21,56 +21,56 @@ import com.jme3.scene.plugins.blender.file.Structure;
* the old memory address of the constraint owner * the old memory address of the constraint owner
* @param influenceIpo * @param influenceIpo
* the ipo curve of the influence factor * the ipo curve of the influence factor
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blender file is somehow * this exception is thrown when the blender file is somehow
* corrupted * corrupted
*/ */
public static Constraint createConstraint(Structure constraintStructure, Long boneOMA, Ipo influenceIpo, DataRepository dataRepository) throws BlenderFileException { public static Constraint createConstraint(Structure constraintStructure, Long boneOMA, Ipo influenceIpo, BlenderContext blenderContext) throws BlenderFileException {
int type = ((Number)constraintStructure.getFieldValue("type")).intValue(); int type = ((Number)constraintStructure.getFieldValue("type")).intValue();
ConstraintType constraintType = ConstraintType.valueOf(type); ConstraintType constraintType = ConstraintType.valueOf(type);
switch(constraintType) { switch(constraintType) {
case CONSTRAINT_TYPE_ACTION: case CONSTRAINT_TYPE_ACTION:
return new ConstraintAction(constraintStructure, boneOMA, influenceIpo, dataRepository); return new ConstraintAction(constraintStructure, boneOMA, influenceIpo, blenderContext);
case CONSTRAINT_TYPE_CHILDOF: case CONSTRAINT_TYPE_CHILDOF:
return new ConstraintChildOf(constraintStructure, boneOMA, influenceIpo, dataRepository); return new ConstraintChildOf(constraintStructure, boneOMA, influenceIpo, blenderContext);
case CONSTRAINT_TYPE_CLAMPTO: case CONSTRAINT_TYPE_CLAMPTO:
return new ConstraintClampTo(constraintStructure, boneOMA, influenceIpo, dataRepository); return new ConstraintClampTo(constraintStructure, boneOMA, influenceIpo, blenderContext);
case CONSTRAINT_TYPE_DISTLIMIT: case CONSTRAINT_TYPE_DISTLIMIT:
return new ConstraintDistLimit(constraintStructure, boneOMA, influenceIpo, dataRepository); return new ConstraintDistLimit(constraintStructure, boneOMA, influenceIpo, blenderContext);
case CONSTRAINT_TYPE_FOLLOWPATH: case CONSTRAINT_TYPE_FOLLOWPATH:
return new ConstraintFollowPath(constraintStructure, boneOMA, influenceIpo, dataRepository); return new ConstraintFollowPath(constraintStructure, boneOMA, influenceIpo, blenderContext);
case CONSTRAINT_TYPE_KINEMATIC: case CONSTRAINT_TYPE_KINEMATIC:
return new ConstraintInverseKinematics(constraintStructure, boneOMA, influenceIpo, dataRepository); return new ConstraintInverseKinematics(constraintStructure, boneOMA, influenceIpo, blenderContext);
case CONSTRAINT_TYPE_LOCKTRACK: case CONSTRAINT_TYPE_LOCKTRACK:
return new ConstraintLockTrack(constraintStructure, boneOMA, influenceIpo, dataRepository); return new ConstraintLockTrack(constraintStructure, boneOMA, influenceIpo, blenderContext);
case CONSTRAINT_TYPE_LOCLIKE: case CONSTRAINT_TYPE_LOCLIKE:
return new ConstraintLocLike(constraintStructure, boneOMA, influenceIpo, dataRepository); return new ConstraintLocLike(constraintStructure, boneOMA, influenceIpo, blenderContext);
case CONSTRAINT_TYPE_LOCLIMIT: case CONSTRAINT_TYPE_LOCLIMIT:
return new ConstraintLocLimit(constraintStructure, boneOMA, influenceIpo, dataRepository); return new ConstraintLocLimit(constraintStructure, boneOMA, influenceIpo, blenderContext);
case CONSTRAINT_TYPE_MINMAX: case CONSTRAINT_TYPE_MINMAX:
return new ConstraintMinMax(constraintStructure, boneOMA, influenceIpo, dataRepository); return new ConstraintMinMax(constraintStructure, boneOMA, influenceIpo, blenderContext);
case CONSTRAINT_TYPE_NULL: case CONSTRAINT_TYPE_NULL:
return new ConstraintNull(constraintStructure, boneOMA, influenceIpo, dataRepository); return new ConstraintNull(constraintStructure, boneOMA, influenceIpo, blenderContext);
case CONSTRAINT_TYPE_PYTHON: case CONSTRAINT_TYPE_PYTHON:
return new ConstraintPython(constraintStructure, boneOMA, influenceIpo, dataRepository); return new ConstraintPython(constraintStructure, boneOMA, influenceIpo, blenderContext);
case CONSTRAINT_TYPE_RIGIDBODYJOINT: case CONSTRAINT_TYPE_RIGIDBODYJOINT:
return new ConstraintRigidBodyJoint(constraintStructure, boneOMA, influenceIpo, dataRepository); return new ConstraintRigidBodyJoint(constraintStructure, boneOMA, influenceIpo, blenderContext);
case CONSTRAINT_TYPE_ROTLIKE: case CONSTRAINT_TYPE_ROTLIKE:
return new ConstraintRotLike(constraintStructure, boneOMA, influenceIpo, dataRepository); return new ConstraintRotLike(constraintStructure, boneOMA, influenceIpo, blenderContext);
case CONSTRAINT_TYPE_ROTLIMIT: case CONSTRAINT_TYPE_ROTLIMIT:
return new ConstraintRotLimit(constraintStructure, boneOMA, influenceIpo, dataRepository); return new ConstraintRotLimit(constraintStructure, boneOMA, influenceIpo, blenderContext);
case CONSTRAINT_TYPE_SHRINKWRAP: case CONSTRAINT_TYPE_SHRINKWRAP:
return new ConstraintShrinkWrap(constraintStructure, boneOMA, influenceIpo, dataRepository); return new ConstraintShrinkWrap(constraintStructure, boneOMA, influenceIpo, blenderContext);
case CONSTRAINT_TYPE_SIZELIKE: case CONSTRAINT_TYPE_SIZELIKE:
return new ConstraintSizeLike(constraintStructure, boneOMA, influenceIpo, dataRepository); return new ConstraintSizeLike(constraintStructure, boneOMA, influenceIpo, blenderContext);
case CONSTRAINT_TYPE_SIZELIMIT: case CONSTRAINT_TYPE_SIZELIMIT:
return new ConstraintSizeLimit(constraintStructure, boneOMA, influenceIpo, dataRepository); return new ConstraintSizeLimit(constraintStructure, boneOMA, influenceIpo, blenderContext);
case CONSTRAINT_TYPE_STRETCHTO: case CONSTRAINT_TYPE_STRETCHTO:
return new ConstraintStretchTo(constraintStructure, boneOMA, influenceIpo, dataRepository); return new ConstraintStretchTo(constraintStructure, boneOMA, influenceIpo, blenderContext);
case CONSTRAINT_TYPE_TRANSFORM: case CONSTRAINT_TYPE_TRANSFORM:
return new ConstraintTransform(constraintStructure, boneOMA, influenceIpo, dataRepository); return new ConstraintTransform(constraintStructure, boneOMA, influenceIpo, blenderContext);
default: default:
throw new IllegalStateException("Unknown constraint type: " + constraintType); throw new IllegalStateException("Unknown constraint type: " + constraintType);
} }

@ -5,7 +5,7 @@ import java.util.logging.Logger;
import com.jme3.animation.BoneAnimation; import com.jme3.animation.BoneAnimation;
import com.jme3.animation.Skeleton; import com.jme3.animation.Skeleton;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
@ -26,15 +26,15 @@ import com.jme3.scene.plugins.blender.file.Structure;
* the old memory address of the constraint owner * the old memory address of the constraint owner
* @param influenceIpo * @param influenceIpo
* the ipo curve of the influence factor * the ipo curve of the influence factor
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blender file is somehow * this exception is thrown when the blender file is somehow
* corrupted * corrupted
*/ */
public ConstraintFollowPath(Structure constraintStructure, Long boneOMA, public ConstraintFollowPath(Structure constraintStructure, Long boneOMA,
Ipo influenceIpo, DataRepository dataRepository) throws BlenderFileException { Ipo influenceIpo, BlenderContext blenderContext) throws BlenderFileException {
super(constraintStructure, boneOMA, influenceIpo, dataRepository); super(constraintStructure, boneOMA, influenceIpo, blenderContext);
} }
@Override @Override

@ -7,7 +7,7 @@ import java.util.Map;
import java.util.logging.Logger; import java.util.logging.Logger;
import com.jme3.scene.plugins.blender.AbstractBlenderHelper; import com.jme3.scene.plugins.blender.AbstractBlenderHelper;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.animations.IpoHelper; import com.jme3.scene.plugins.blender.animations.IpoHelper;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
@ -29,7 +29,7 @@ public class ConstraintHelper extends AbstractBlenderHelper {
* @param blenderVersion * @param blenderVersion
* the version read from the blend file * the version read from the blend file
*/ */
public ConstraintHelper(String blenderVersion, DataRepository dataRepository) { public ConstraintHelper(String blenderVersion, BlenderContext blenderContext) {
super(blenderVersion); super(blenderVersion);
} }
@ -39,34 +39,34 @@ public class ConstraintHelper extends AbstractBlenderHelper {
* the owner's old memory address * the owner's old memory address
* @param objectStructure * @param objectStructure
* the structure we read constraint's for * the structure we read constraint's for
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @throws BlenderFileException * @throws BlenderFileException
*/ */
public Map<Long, List<Constraint>> loadConstraints(Structure objectStructure, DataRepository dataRepository) throws BlenderFileException { public Map<Long, List<Constraint>> loadConstraints(Structure objectStructure, BlenderContext blenderContext) throws BlenderFileException {
if (blenderVersion >= 250) {//TODO if (blenderVersion >= 250) {//TODO
LOGGER.warning("Loading of constraints not yet implemented for version 2.5x !"); LOGGER.warning("Loading of constraints not yet implemented for version 2.5x !");
return new HashMap<Long, List<Constraint>>(0); return new HashMap<Long, List<Constraint>>(0);
} }
// reading influence ipos for the constraints // reading influence ipos for the constraints
IpoHelper ipoHelper = dataRepository.getHelper(IpoHelper.class); IpoHelper ipoHelper = blenderContext.getHelper(IpoHelper.class);
Map<String, Map<String, Ipo>> constraintsIpos = new HashMap<String, Map<String, Ipo>>(); Map<String, Map<String, Ipo>> constraintsIpos = new HashMap<String, Map<String, Ipo>>();
Pointer pActions = (Pointer) objectStructure.getFieldValue("action"); Pointer pActions = (Pointer) objectStructure.getFieldValue("action");
if (pActions.isNotNull()) { if (pActions.isNotNull()) {
List<Structure> actions = pActions.fetchData(dataRepository.getInputStream()); List<Structure> actions = pActions.fetchData(blenderContext.getInputStream());
for (Structure action : actions) { for (Structure action : actions) {
Structure chanbase = (Structure) action.getFieldValue("chanbase"); Structure chanbase = (Structure) action.getFieldValue("chanbase");
List<Structure> actionChannels = chanbase.evaluateListBase(dataRepository); List<Structure> actionChannels = chanbase.evaluateListBase(blenderContext);
for (Structure actionChannel : actionChannels) { for (Structure actionChannel : actionChannels) {
Map<String, Ipo> ipos = new HashMap<String, Ipo>(); Map<String, Ipo> ipos = new HashMap<String, Ipo>();
Structure constChannels = (Structure) actionChannel.getFieldValue("constraintChannels"); Structure constChannels = (Structure) actionChannel.getFieldValue("constraintChannels");
List<Structure> constraintChannels = constChannels.evaluateListBase(dataRepository); List<Structure> constraintChannels = constChannels.evaluateListBase(blenderContext);
for (Structure constraintChannel : constraintChannels) { for (Structure constraintChannel : constraintChannels) {
Pointer pIpo = (Pointer) constraintChannel.getFieldValue("ipo"); Pointer pIpo = (Pointer) constraintChannel.getFieldValue("ipo");
if (pIpo.isNotNull()) { if (pIpo.isNotNull()) {
String constraintName = constraintChannel.getFieldValue("name").toString(); String constraintName = constraintChannel.getFieldValue("name").toString();
Ipo ipo = ipoHelper.createIpo(pIpo.fetchData(dataRepository.getInputStream()).get(0), dataRepository); Ipo ipo = ipoHelper.createIpo(pIpo.fetchData(blenderContext.getInputStream()).get(0), blenderContext);
ipos.put(constraintName, ipo); ipos.put(constraintName, ipo);
} }
} }
@ -81,14 +81,14 @@ public class ConstraintHelper extends AbstractBlenderHelper {
//loading constraints connected with the object's bones //loading constraints connected with the object's bones
Pointer pPose = (Pointer) objectStructure.getFieldValue("pose");//TODO: what if the object has two armatures ???? Pointer pPose = (Pointer) objectStructure.getFieldValue("pose");//TODO: what if the object has two armatures ????
if (pPose.isNotNull()) { if (pPose.isNotNull()) {
List<Structure> poseChannels = ((Structure) pPose.fetchData(dataRepository.getInputStream()).get(0).getFieldValue("chanbase")).evaluateListBase(dataRepository); List<Structure> poseChannels = ((Structure) pPose.fetchData(blenderContext.getInputStream()).get(0).getFieldValue("chanbase")).evaluateListBase(blenderContext);
for (Structure poseChannel : poseChannels) { for (Structure poseChannel : poseChannels) {
List<Constraint> constraintsList = new ArrayList<Constraint>(); List<Constraint> constraintsList = new ArrayList<Constraint>();
Long boneOMA = Long.valueOf(((Pointer) poseChannel.getFieldValue("bone")).getOldMemoryAddress()); Long boneOMA = Long.valueOf(((Pointer) poseChannel.getFieldValue("bone")).getOldMemoryAddress());
//the name is read directly from structure because bone might not yet be loaded //the name is read directly from structure because bone might not yet be loaded
String name = dataRepository.getFileBlock(boneOMA).getStructure(dataRepository).getFieldValue("name").toString(); String name = blenderContext.getFileBlock(boneOMA).getStructure(blenderContext).getFieldValue("name").toString();
List<Structure> constraints = ((Structure) poseChannel.getFieldValue("constraints")).evaluateListBase(dataRepository); List<Structure> constraints = ((Structure) poseChannel.getFieldValue("constraints")).evaluateListBase(blenderContext);
for (Structure constraint : constraints) { for (Structure constraint : constraints) {
String constraintName = constraint.getFieldValue("name").toString(); String constraintName = constraint.getFieldValue("name").toString();
Map<String, Ipo> ipoMap = constraintsIpos.get(name); Map<String, Ipo> ipoMap = constraintsIpos.get(name);
@ -97,22 +97,22 @@ public class ConstraintHelper extends AbstractBlenderHelper {
float enforce = ((Number) constraint.getFieldValue("enforce")).floatValue(); float enforce = ((Number) constraint.getFieldValue("enforce")).floatValue();
ipo = ipoHelper.createIpo(enforce); ipo = ipoHelper.createIpo(enforce);
} }
constraintsList.add(ConstraintFactory.createConstraint(constraint, boneOMA, ipo, dataRepository)); constraintsList.add(ConstraintFactory.createConstraint(constraint, boneOMA, ipo, blenderContext));
} }
result.put(boneOMA, constraintsList); result.put(boneOMA, constraintsList);
dataRepository.addConstraints(boneOMA, constraintsList); blenderContext.addConstraints(boneOMA, constraintsList);
} }
} }
// TODO: reading constraints for objects (implement when object's animation will be available) // TODO: reading constraints for objects (implement when object's animation will be available)
List<Structure> constraintChannels = ((Structure)objectStructure.getFieldValue("constraintChannels")).evaluateListBase(dataRepository); List<Structure> constraintChannels = ((Structure)objectStructure.getFieldValue("constraintChannels")).evaluateListBase(blenderContext);
for(Structure constraintChannel : constraintChannels) { for(Structure constraintChannel : constraintChannels) {
System.out.println(constraintChannel); System.out.println(constraintChannel);
} }
//loading constraints connected with the object itself (TODO: test this) //loading constraints connected with the object itself (TODO: test this)
if(!result.containsKey(objectStructure.getOldMemoryAddress())) { if(!result.containsKey(objectStructure.getOldMemoryAddress())) {
List<Structure> constraints = ((Structure)objectStructure.getFieldValue("constraints")).evaluateListBase(dataRepository); List<Structure> constraints = ((Structure)objectStructure.getFieldValue("constraints")).evaluateListBase(blenderContext);
List<Constraint> constraintsList = new ArrayList<Constraint>(constraints.size()); List<Constraint> constraintsList = new ArrayList<Constraint>(constraints.size());
for(Structure constraint : constraints) { for(Structure constraint : constraints) {
@ -125,16 +125,16 @@ public class ConstraintHelper extends AbstractBlenderHelper {
float enforce = ((Number) constraint.getFieldValue("enforce")).floatValue(); float enforce = ((Number) constraint.getFieldValue("enforce")).floatValue();
ipo = ipoHelper.createIpo(enforce); ipo = ipoHelper.createIpo(enforce);
} }
constraintsList.add(ConstraintFactory.createConstraint(constraint, null, ipo, dataRepository)); constraintsList.add(ConstraintFactory.createConstraint(constraint, null, ipo, blenderContext));
} }
result.put(objectStructure.getOldMemoryAddress(), constraintsList); result.put(objectStructure.getOldMemoryAddress(), constraintsList);
dataRepository.addConstraints(objectStructure.getOldMemoryAddress(), constraintsList); blenderContext.addConstraints(objectStructure.getOldMemoryAddress(), constraintsList);
} }
return result; return result;
} }
@Override @Override
public boolean shouldBeLoaded(Structure structure, DataRepository dataRepository) { public boolean shouldBeLoaded(Structure structure, BlenderContext blenderContext) {
return true; return true;
} }
} }

@ -12,8 +12,8 @@ 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.scene.Node; import com.jme3.scene.Node;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.DataRepository.LoadedFeatureDataType; import com.jme3.scene.plugins.blender.BlenderContext.LoadedFeatureDataType;
import com.jme3.scene.plugins.blender.animations.CalculationBone; import com.jme3.scene.plugins.blender.animations.CalculationBone;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
@ -37,22 +37,22 @@ import com.jme3.scene.plugins.blender.objects.ObjectHelper;
* the old memory address of the constraint owner * the old memory address of the constraint owner
* @param influenceIpo * @param influenceIpo
* the ipo curve of the influence factor * the ipo curve of the influence factor
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blender file is somehow * this exception is thrown when the blender file is somehow
* corrupted * corrupted
*/ */
public ConstraintInverseKinematics(Structure constraintStructure, public ConstraintInverseKinematics(Structure constraintStructure,
Long boneOMA, Ipo influenceIpo, DataRepository dataRepository) throws BlenderFileException { Long boneOMA, Ipo influenceIpo, BlenderContext blenderContext) throws BlenderFileException {
super(constraintStructure, boneOMA, influenceIpo, dataRepository); super(constraintStructure, boneOMA, influenceIpo, blenderContext);
} }
@Override @Override
public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) { public void affectAnimation(Skeleton skeleton, BoneAnimation boneAnimation) {
try { try {
// IK solver is only attached to bones // IK solver is only attached to bones
Bone ownerBone = (Bone) dataRepository.getLoadedFeature(boneOMA, LoadedFeatureDataType.LOADED_FEATURE); Bone ownerBone = (Bone) blenderContext.getLoadedFeature(boneOMA, LoadedFeatureDataType.LOADED_FEATURE);
// get the target point // get the target point
Object targetObject = this.getTarget(LoadedFeatureDataType.LOADED_FEATURE); Object targetObject = this.getTarget(LoadedFeatureDataType.LOADED_FEATURE);
@ -63,8 +63,8 @@ import com.jme3.scene.plugins.blender.objects.ObjectHelper;
pt = ((Node) targetObject).getWorldTranslation(); pt = ((Node) targetObject).getWorldTranslation();
} else if (targetObject instanceof Skeleton) { } else if (targetObject instanceof Skeleton) {
Structure armatureNodeStructure = (Structure) this.getTarget(LoadedFeatureDataType.LOADED_STRUCTURE); Structure armatureNodeStructure = (Structure) this.getTarget(LoadedFeatureDataType.LOADED_STRUCTURE);
ObjectHelper objectHelper = dataRepository.getHelper(ObjectHelper.class); ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class);
Transform transform = objectHelper.getTransformation(armatureNodeStructure, dataRepository); Transform transform = objectHelper.getTransformation(armatureNodeStructure, blenderContext);
pt = transform.getTranslation(); pt = transform.getTranslation();
} else { } else {
throw new IllegalStateException( throw new IllegalStateException(

@ -4,7 +4,7 @@ import com.jme3.animation.BoneAnimation;
import com.jme3.animation.BoneTrack; import com.jme3.animation.BoneTrack;
import com.jme3.animation.Skeleton; import com.jme3.animation.Skeleton;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
@ -33,15 +33,15 @@ import com.jme3.scene.plugins.blender.file.Structure;
* the old memory address of the constraint owner * the old memory address of the constraint owner
* @param influenceIpo * @param influenceIpo
* the ipo curve of the influence factor * the ipo curve of the influence factor
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blender file is somehow * this exception is thrown when the blender file is somehow
* corrupted * corrupted
*/ */
public ConstraintLocLike(Structure constraintStructure, Long boneOMA, public ConstraintLocLike(Structure constraintStructure, Long boneOMA,
Ipo influenceIpo, DataRepository dataRepository) throws BlenderFileException { Ipo influenceIpo, BlenderContext blenderContext) throws BlenderFileException {
super(constraintStructure, boneOMA, influenceIpo, dataRepository); super(constraintStructure, boneOMA, influenceIpo, blenderContext);
} }
@Override @Override

@ -4,7 +4,7 @@ import com.jme3.animation.BoneAnimation;
import com.jme3.animation.BoneTrack; import com.jme3.animation.BoneTrack;
import com.jme3.animation.Skeleton; import com.jme3.animation.Skeleton;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
@ -30,15 +30,15 @@ import com.jme3.scene.plugins.blender.file.Structure;
* the old memory address of the constraint owner * the old memory address of the constraint owner
* @param influenceIpo * @param influenceIpo
* the ipo curve of the influence factor * the ipo curve of the influence factor
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blender file is somehow * this exception is thrown when the blender file is somehow
* corrupted * corrupted
*/ */
public ConstraintLocLimit(Structure constraintStructure, Long boneOMA, public ConstraintLocLimit(Structure constraintStructure, Long boneOMA,
Ipo influenceIpo, DataRepository dataRepository) throws BlenderFileException { Ipo influenceIpo, BlenderContext blenderContext) throws BlenderFileException {
super(constraintStructure, boneOMA, influenceIpo, dataRepository); super(constraintStructure, boneOMA, influenceIpo, blenderContext);
} }
@Override @Override

@ -5,7 +5,7 @@ import java.util.logging.Logger;
import com.jme3.animation.BoneAnimation; import com.jme3.animation.BoneAnimation;
import com.jme3.animation.Skeleton; import com.jme3.animation.Skeleton;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
@ -26,16 +26,16 @@ import com.jme3.scene.plugins.blender.file.Structure;
* the old memory address of the constraint owner * the old memory address of the constraint owner
* @param influenceIpo * @param influenceIpo
* the ipo curve of the influence factor * the ipo curve of the influence factor
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blender file is somehow * this exception is thrown when the blender file is somehow
* corrupted * corrupted
*/ */
public ConstraintLockTrack(Structure constraintStructure, Long boneOMA, public ConstraintLockTrack(Structure constraintStructure, Long boneOMA,
Ipo influenceIpo, DataRepository dataRepository) Ipo influenceIpo, BlenderContext blenderContext)
throws BlenderFileException { throws BlenderFileException {
super(constraintStructure, boneOMA, influenceIpo, dataRepository); super(constraintStructure, boneOMA, influenceIpo, blenderContext);
} }
@Override @Override

@ -5,7 +5,7 @@ import java.util.logging.Logger;
import com.jme3.animation.BoneAnimation; import com.jme3.animation.BoneAnimation;
import com.jme3.animation.Skeleton; import com.jme3.animation.Skeleton;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
@ -26,15 +26,15 @@ import com.jme3.scene.plugins.blender.file.Structure;
* the old memory address of the constraint owner * the old memory address of the constraint owner
* @param influenceIpo * @param influenceIpo
* the ipo curve of the influence factor * the ipo curve of the influence factor
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blender file is somehow * this exception is thrown when the blender file is somehow
* corrupted * corrupted
*/ */
public ConstraintMinMax(Structure constraintStructure, Long boneOMA, public ConstraintMinMax(Structure constraintStructure, Long boneOMA,
Ipo influenceIpo, DataRepository dataRepository) throws BlenderFileException { Ipo influenceIpo, BlenderContext blenderContext) throws BlenderFileException {
super(constraintStructure, boneOMA, influenceIpo, dataRepository); super(constraintStructure, boneOMA, influenceIpo, blenderContext);
} }
@Override @Override

@ -2,7 +2,7 @@ package com.jme3.scene.plugins.blender.constraints;
import com.jme3.animation.BoneAnimation; import com.jme3.animation.BoneAnimation;
import com.jme3.animation.Skeleton; import com.jme3.animation.Skeleton;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
@ -22,16 +22,16 @@ import com.jme3.scene.plugins.blender.file.Structure;
* the old memory address of the constraint owner * the old memory address of the constraint owner
* @param influenceIpo * @param influenceIpo
* the ipo curve of the influence factor * the ipo curve of the influence factor
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blender file is somehow * this exception is thrown when the blender file is somehow
* corrupted * corrupted
*/ */
public ConstraintNull(Structure constraintStructure, Long boneOMA, public ConstraintNull(Structure constraintStructure, Long boneOMA,
Ipo influenceIpo, DataRepository dataRepository) Ipo influenceIpo, BlenderContext blenderContext)
throws BlenderFileException { throws BlenderFileException {
super(constraintStructure, boneOMA, influenceIpo, dataRepository); super(constraintStructure, boneOMA, influenceIpo, blenderContext);
} }
@Override @Override

@ -5,7 +5,7 @@ import java.util.logging.Logger;
import com.jme3.animation.BoneAnimation; import com.jme3.animation.BoneAnimation;
import com.jme3.animation.Skeleton; import com.jme3.animation.Skeleton;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
@ -26,15 +26,15 @@ import com.jme3.scene.plugins.blender.file.Structure;
* the old memory address of the constraint owner * the old memory address of the constraint owner
* @param influenceIpo * @param influenceIpo
* the ipo curve of the influence factor * the ipo curve of the influence factor
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blender file is somehow * this exception is thrown when the blender file is somehow
* corrupted * corrupted
*/ */
public ConstraintPython(Structure constraintStructure, Long boneOMA, public ConstraintPython(Structure constraintStructure, Long boneOMA,
Ipo influenceIpo, DataRepository dataRepository) throws BlenderFileException { Ipo influenceIpo, BlenderContext blenderContext) throws BlenderFileException {
super(constraintStructure, boneOMA, influenceIpo, dataRepository); super(constraintStructure, boneOMA, influenceIpo, blenderContext);
} }
@Override @Override

@ -5,7 +5,7 @@ import java.util.logging.Logger;
import com.jme3.animation.BoneAnimation; import com.jme3.animation.BoneAnimation;
import com.jme3.animation.Skeleton; import com.jme3.animation.Skeleton;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
@ -26,15 +26,15 @@ import com.jme3.scene.plugins.blender.file.Structure;
* the old memory address of the constraint owner * the old memory address of the constraint owner
* @param influenceIpo * @param influenceIpo
* the ipo curve of the influence factor * the ipo curve of the influence factor
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blender file is somehow * this exception is thrown when the blender file is somehow
* corrupted * corrupted
*/ */
public ConstraintRigidBodyJoint(Structure constraintStructure, public ConstraintRigidBodyJoint(Structure constraintStructure,
Long boneOMA, Ipo influenceIpo, DataRepository dataRepository) throws BlenderFileException { Long boneOMA, Ipo influenceIpo, BlenderContext blenderContext) throws BlenderFileException {
super(constraintStructure, boneOMA, influenceIpo, dataRepository); super(constraintStructure, boneOMA, influenceIpo, blenderContext);
} }
@Override @Override

@ -4,7 +4,7 @@ import com.jme3.animation.BoneAnimation;
import com.jme3.animation.BoneTrack; import com.jme3.animation.BoneTrack;
import com.jme3.animation.Skeleton; import com.jme3.animation.Skeleton;
import com.jme3.math.Quaternion; import com.jme3.math.Quaternion;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
@ -31,15 +31,15 @@ import com.jme3.scene.plugins.blender.file.Structure;
* the old memory address of the constraint owner * the old memory address of the constraint owner
* @param influenceIpo * @param influenceIpo
* the ipo curve of the influence factor * the ipo curve of the influence factor
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blender file is somehow * this exception is thrown when the blender file is somehow
* corrupted * corrupted
*/ */
public ConstraintRotLike(Structure constraintStructure, Long boneOMA, public ConstraintRotLike(Structure constraintStructure, Long boneOMA,
Ipo influenceIpo, DataRepository dataRepository) throws BlenderFileException { Ipo influenceIpo, BlenderContext blenderContext) throws BlenderFileException {
super(constraintStructure, boneOMA, influenceIpo, dataRepository); super(constraintStructure, boneOMA, influenceIpo, blenderContext);
} }
@Override @Override

@ -5,7 +5,7 @@ import com.jme3.animation.BoneTrack;
import com.jme3.animation.Skeleton; import com.jme3.animation.Skeleton;
import com.jme3.math.FastMath; import com.jme3.math.FastMath;
import com.jme3.math.Quaternion; import com.jme3.math.Quaternion;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
@ -28,15 +28,15 @@ import com.jme3.scene.plugins.blender.file.Structure;
* the old memory address of the constraint owner * the old memory address of the constraint owner
* @param influenceIpo * @param influenceIpo
* the ipo curve of the influence factor * the ipo curve of the influence factor
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blender file is somehow * this exception is thrown when the blender file is somehow
* corrupted * corrupted
*/ */
public ConstraintRotLimit(Structure constraintStructure, Long boneOMA, public ConstraintRotLimit(Structure constraintStructure, Long boneOMA,
Ipo influenceIpo, DataRepository dataRepository) throws BlenderFileException { Ipo influenceIpo, BlenderContext blenderContext) throws BlenderFileException {
super(constraintStructure, boneOMA, influenceIpo, dataRepository); super(constraintStructure, boneOMA, influenceIpo, blenderContext);
} }
@Override @Override

@ -15,8 +15,8 @@ import com.jme3.scene.Mesh;
import com.jme3.scene.Node; import com.jme3.scene.Node;
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
import com.jme3.scene.VertexBuffer.Type; import com.jme3.scene.VertexBuffer.Type;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.DataRepository.LoadedFeatureDataType; import com.jme3.scene.plugins.blender.BlenderContext.LoadedFeatureDataType;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
@ -37,15 +37,15 @@ import com.jme3.scene.plugins.blender.file.Structure;
* the old memory address of the constraint owner * the old memory address of the constraint owner
* @param influenceIpo * @param influenceIpo
* the ipo curve of the influence factor * the ipo curve of the influence factor
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blender file is somehow * this exception is thrown when the blender file is somehow
* corrupted * corrupted
*/ */
public ConstraintShrinkWrap(Structure constraintStructure, Long boneOMA, public ConstraintShrinkWrap(Structure constraintStructure, Long boneOMA,
Ipo influenceIpo, DataRepository dataRepository) throws BlenderFileException { Ipo influenceIpo, BlenderContext blenderContext) throws BlenderFileException {
super(constraintStructure, boneOMA, influenceIpo, dataRepository); super(constraintStructure, boneOMA, influenceIpo, blenderContext);
} }
@Override @Override

@ -4,7 +4,7 @@ import com.jme3.animation.BoneAnimation;
import com.jme3.animation.BoneTrack; import com.jme3.animation.BoneTrack;
import com.jme3.animation.Skeleton; import com.jme3.animation.Skeleton;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
@ -28,15 +28,15 @@ import com.jme3.scene.plugins.blender.file.Structure;
* the old memory address of the constraint owner * the old memory address of the constraint owner
* @param influenceIpo * @param influenceIpo
* the ipo curve of the influence factor * the ipo curve of the influence factor
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blender file is somehow * this exception is thrown when the blender file is somehow
* corrupted * corrupted
*/ */
public ConstraintSizeLike(Structure constraintStructure, Long boneOMA, public ConstraintSizeLike(Structure constraintStructure, Long boneOMA,
Ipo influenceIpo, DataRepository dataRepository) throws BlenderFileException { Ipo influenceIpo, BlenderContext blenderContext) throws BlenderFileException {
super(constraintStructure, boneOMA, influenceIpo, dataRepository); super(constraintStructure, boneOMA, influenceIpo, blenderContext);
} }
@Override @Override

@ -4,7 +4,7 @@ import com.jme3.animation.BoneAnimation;
import com.jme3.animation.BoneTrack; import com.jme3.animation.BoneTrack;
import com.jme3.animation.Skeleton; import com.jme3.animation.Skeleton;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
@ -30,15 +30,15 @@ import com.jme3.scene.plugins.blender.file.Structure;
* the old memory address of the constraint owner * the old memory address of the constraint owner
* @param influenceIpo * @param influenceIpo
* the ipo curve of the influence factor * the ipo curve of the influence factor
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blender file is somehow * this exception is thrown when the blender file is somehow
* corrupted * corrupted
*/ */
public ConstraintSizeLimit(Structure constraintStructure, Long boneOMA, public ConstraintSizeLimit(Structure constraintStructure, Long boneOMA,
Ipo influenceIpo, DataRepository dataRepository) throws BlenderFileException { Ipo influenceIpo, BlenderContext blenderContext) throws BlenderFileException {
super(constraintStructure, boneOMA, influenceIpo, dataRepository); super(constraintStructure, boneOMA, influenceIpo, blenderContext);
} }
@Override @Override

@ -5,7 +5,7 @@ import java.util.logging.Logger;
import com.jme3.animation.BoneAnimation; import com.jme3.animation.BoneAnimation;
import com.jme3.animation.Skeleton; import com.jme3.animation.Skeleton;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
@ -26,16 +26,16 @@ import com.jme3.scene.plugins.blender.file.Structure;
* the old memory address of the constraint owner * the old memory address of the constraint owner
* @param influenceIpo * @param influenceIpo
* the ipo curve of the influence factor * the ipo curve of the influence factor
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blender file is somehow * this exception is thrown when the blender file is somehow
* corrupted * corrupted
*/ */
public ConstraintStretchTo(Structure constraintStructure, Long boneOMA, public ConstraintStretchTo(Structure constraintStructure, Long boneOMA,
Ipo influenceIpo, DataRepository dataRepository) Ipo influenceIpo, BlenderContext blenderContext)
throws BlenderFileException { throws BlenderFileException {
super(constraintStructure, boneOMA, influenceIpo, dataRepository); super(constraintStructure, boneOMA, influenceIpo, blenderContext);
} }
@Override @Override

@ -5,7 +5,7 @@ import java.util.logging.Logger;
import com.jme3.animation.BoneAnimation; import com.jme3.animation.BoneAnimation;
import com.jme3.animation.Skeleton; import com.jme3.animation.Skeleton;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
@ -26,15 +26,15 @@ import com.jme3.scene.plugins.blender.file.Structure;
* the old memory address of the constraint owner * the old memory address of the constraint owner
* @param influenceIpo * @param influenceIpo
* the ipo curve of the influence factor * the ipo curve of the influence factor
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blender file is somehow * this exception is thrown when the blender file is somehow
* corrupted * corrupted
*/ */
public ConstraintTransform(Structure constraintStructure, Long boneOMA, public ConstraintTransform(Structure constraintStructure, Long boneOMA,
Ipo influenceIpo, DataRepository dataRepository) throws BlenderFileException { Ipo influenceIpo, BlenderContext blenderContext) throws BlenderFileException {
super(constraintStructure, boneOMA, influenceIpo, dataRepository); super(constraintStructure, boneOMA, influenceIpo, blenderContext);
} }
@Override @Override

@ -22,7 +22,7 @@ import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh; import com.jme3.scene.Mesh;
import com.jme3.scene.VertexBuffer.Type; import com.jme3.scene.VertexBuffer.Type;
import com.jme3.scene.plugins.blender.AbstractBlenderHelper; import com.jme3.scene.plugins.blender.AbstractBlenderHelper;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
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.BlenderInputStream;
import com.jme3.scene.plugins.blender.file.DynamicArray; import com.jme3.scene.plugins.blender.file.DynamicArray;
@ -74,12 +74,12 @@ public class CurvesHelper extends AbstractBlenderHelper {
* can have several separate curves. * can have several separate curves.
* @param curveStructure * @param curveStructure
* the curve structure * the curve structure
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @return a list of geometries repreenting a single curve object * @return a list of geometries repreenting a single curve object
* @throws BlenderFileException * @throws BlenderFileException
*/ */
public List<Geometry> toCurve(Structure curveStructure, DataRepository dataRepository) throws BlenderFileException { public List<Geometry> toCurve(Structure curveStructure, BlenderContext blenderContext) throws BlenderFileException {
String name = curveStructure.getName(); String name = curveStructure.getName();
int flag = ((Number) curveStructure.getFieldValue("flag")).intValue(); int flag = ((Number) curveStructure.getFieldValue("flag")).intValue();
boolean is3D = (flag & 0x01) != 0; boolean is3D = (flag & 0x01) != 0;
@ -93,7 +93,7 @@ public class CurvesHelper extends AbstractBlenderHelper {
} }
//reading nurbs (and sorting them by material) //reading nurbs (and sorting them by material)
List<Structure> nurbStructures = ((Structure) curveStructure.getFieldValue("nurb")).evaluateListBase(dataRepository); List<Structure> nurbStructures = ((Structure) curveStructure.getFieldValue("nurb")).evaluateListBase(blenderContext);
Map<Number, List<Structure>> nurbs = new HashMap<Number, List<Structure>>(); Map<Number, List<Structure>> nurbs = new HashMap<Number, List<Structure>>();
for (Structure nurb : nurbStructures) { for (Structure nurb : nurbStructures) {
Number matNumber = (Number) nurb.getFieldValue("mat_nr"); Number matNumber = (Number) nurb.getFieldValue("mat_nr");
@ -106,10 +106,10 @@ public class CurvesHelper extends AbstractBlenderHelper {
} }
//getting materials //getting materials
MaterialHelper materialHelper = dataRepository.getHelper(MaterialHelper.class); MaterialHelper materialHelper = blenderContext.getHelper(MaterialHelper.class);
Material[] materials = materialHelper.getMaterials(curveStructure, dataRepository); Material[] materials = materialHelper.getMaterials(curveStructure, blenderContext);
if (materials == null) { if (materials == null) {
materials = new Material[]{dataRepository.getDefaultMaterial().clone()}; materials = new Material[]{blenderContext.getDefaultMaterial().clone()};
} }
for (Material material : materials) { for (Material material : materials) {
material.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off); material.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);
@ -119,9 +119,9 @@ public class CurvesHelper extends AbstractBlenderHelper {
List<Geometry> bevelObject = null; List<Geometry> bevelObject = null;
Pointer pBevelObject = (Pointer) curveStructure.getFieldValue("bevobj"); Pointer pBevelObject = (Pointer) curveStructure.getFieldValue("bevobj");
if (pBevelObject.isNotNull()) { if (pBevelObject.isNotNull()) {
Pointer pBevelStructure = (Pointer) pBevelObject.fetchData(dataRepository.getInputStream()).get(0).getFieldValue("data"); Pointer pBevelStructure = (Pointer) pBevelObject.fetchData(blenderContext.getInputStream()).get(0).getFieldValue("data");
Structure bevelStructure = pBevelStructure.fetchData(dataRepository.getInputStream()).get(0); Structure bevelStructure = pBevelStructure.fetchData(blenderContext.getInputStream()).get(0);
bevelObject = this.toCurve(bevelStructure, dataRepository); bevelObject = this.toCurve(bevelStructure, blenderContext);
} else { } else {
int bevResol = ((Number) curveStructure.getFieldValue("bevresol")).intValue(); int bevResol = ((Number) curveStructure.getFieldValue("bevresol")).intValue();
float extrude = ((Number) curveStructure.getFieldValue("ext1")).floatValue(); float extrude = ((Number) curveStructure.getFieldValue("ext1")).floatValue();
@ -179,9 +179,9 @@ public class CurvesHelper extends AbstractBlenderHelper {
Curve taperObject = null; Curve taperObject = null;
Pointer pTaperObject = (Pointer) curveStructure.getFieldValue("taperobj"); Pointer pTaperObject = (Pointer) curveStructure.getFieldValue("taperobj");
if (bevelObject != null && pTaperObject.isNotNull()) { if (bevelObject != null && pTaperObject.isNotNull()) {
Pointer pTaperStructure = (Pointer) pTaperObject.fetchData(dataRepository.getInputStream()).get(0).getFieldValue("data"); Pointer pTaperStructure = (Pointer) pTaperObject.fetchData(blenderContext.getInputStream()).get(0).getFieldValue("data");
Structure taperStructure = pTaperStructure.fetchData(dataRepository.getInputStream()).get(0); Structure taperStructure = pTaperStructure.fetchData(blenderContext.getInputStream()).get(0);
taperObject = this.loadTaperObject(taperStructure, dataRepository); taperObject = this.loadTaperObject(taperStructure, blenderContext);
} }
Vector3f loc = this.getLoc(curveStructure); Vector3f loc = this.getLoc(curveStructure);
@ -192,9 +192,9 @@ public class CurvesHelper extends AbstractBlenderHelper {
int type = ((Number) nurb.getFieldValue("type")).intValue(); int type = ((Number) nurb.getFieldValue("type")).intValue();
List<Geometry> nurbGeoms = null; List<Geometry> nurbGeoms = null;
if ((type & 0x01) != 0) {//Bezier curve if ((type & 0x01) != 0) {//Bezier curve
nurbGeoms = this.loadBezierCurve(loc, nurb, bevelObject, taperObject, dataRepository); nurbGeoms = this.loadBezierCurve(loc, nurb, bevelObject, taperObject, blenderContext);
} else if ((type & 0x04) != 0) {//NURBS } else if ((type & 0x04) != 0) {//NURBS
nurbGeoms = this.loadNurb(loc, nurb, bevelObject, taperObject, dataRepository); nurbGeoms = this.loadNurb(loc, nurb, bevelObject, taperObject, blenderContext);
} }
if (nurbGeoms != null) {//setting the name and assigning materials if (nurbGeoms != null) {//setting the name and assigning materials
for (Geometry nurbGeom : nurbGeoms) { for (Geometry nurbGeom : nurbGeoms) {
@ -207,7 +207,7 @@ public class CurvesHelper extends AbstractBlenderHelper {
} }
//reading custom properties //reading custom properties
Properties properties = this.loadProperties(curveStructure, dataRepository); Properties properties = this.loadProperties(curveStructure, blenderContext);
if(properties != null && properties.getValue() != null) { if(properties != null && properties.getValue() != null) {
for(Geometry geom : result) { for(Geometry geom : result) {
geom.setUserData("properties", properties); geom.setUserData("properties", properties);
@ -227,14 +227,14 @@ public class CurvesHelper extends AbstractBlenderHelper {
* the bevel object * the bevel object
* @param taperObject * @param taperObject
* the taper object * the taper object
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @return a list of geometries representing the curves * @return a list of geometries representing the curves
* @throws BlenderFileException * @throws BlenderFileException
* an exception is thrown when there are problems with the blender file * an exception is thrown when there are problems with the blender file
*/ */
protected List<Geometry> loadBezierCurve(Vector3f loc, Structure nurb, List<Geometry> bevelObject, Curve taperObject, protected List<Geometry> loadBezierCurve(Vector3f loc, Structure nurb, List<Geometry> bevelObject, Curve taperObject,
DataRepository dataRepository) throws BlenderFileException { BlenderContext blenderContext) throws BlenderFileException {
Pointer pBezierTriple = (Pointer) nurb.getFieldValue("bezt"); Pointer pBezierTriple = (Pointer) nurb.getFieldValue("bezt");
List<Geometry> result = new ArrayList<Geometry>(); List<Geometry> result = new ArrayList<Geometry>();
if (pBezierTriple.isNotNull()) { if (pBezierTriple.isNotNull()) {
@ -243,7 +243,7 @@ public class CurvesHelper extends AbstractBlenderHelper {
boolean cyclic = (((Number) nurb.getFieldValue("flagu")).intValue() & 0x01) != 0; boolean cyclic = (((Number) nurb.getFieldValue("flagu")).intValue() & 0x01) != 0;
//creating the curve object //creating the curve object
BezierCurve bezierCurve = new BezierCurve(0, pBezierTriple.fetchData(dataRepository.getInputStream()), 3); BezierCurve bezierCurve = new BezierCurve(0, pBezierTriple.fetchData(blenderContext.getInputStream()), 3);
List<Vector3f> controlPoints = bezierCurve.getControlPoints(); List<Vector3f> controlPoints = bezierCurve.getControlPoints();
if (cyclic) { if (cyclic) {
//copy the first three points at the end //copy the first three points at the end
@ -263,7 +263,7 @@ public class CurvesHelper extends AbstractBlenderHelper {
result.add(curveGeometry); result.add(curveGeometry);
//TODO: use front and back flags; surface excluding algorithm for bezier circles should be added //TODO: use front and back flags; surface excluding algorithm for bezier circles should be added
} else {//creating curve with bevel and taper shape } else {//creating curve with bevel and taper shape
result = this.applyBevelAndTaper(curve, bevelObject, taperObject, smooth, dataRepository); result = this.applyBevelAndTaper(curve, bevelObject, taperObject, smooth, blenderContext);
} }
} }
return result; return result;
@ -279,22 +279,22 @@ public class CurvesHelper extends AbstractBlenderHelper {
* the bevel object to be applied * the bevel object to be applied
* @param taperObject * @param taperObject
* the taper object to be applied * the taper object to be applied
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @return a list of geometries that represents the loaded NURBS curve or surface * @return a list of geometries that represents the loaded NURBS curve or surface
* @throws BlenderFileException * @throws BlenderFileException
* an exception is throw when problems with blender loaded data occurs * an exception is throw when problems with blender loaded data occurs
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected List<Geometry> loadNurb(Vector3f loc, Structure nurb, List<Geometry> bevelObject, Curve taperObject, protected List<Geometry> loadNurb(Vector3f loc, Structure nurb, List<Geometry> bevelObject, Curve taperObject,
DataRepository dataRepository) throws BlenderFileException { BlenderContext blenderContext) throws BlenderFileException {
//loading the knots //loading the knots
List<Float>[] knots = new List[2]; List<Float>[] knots = new List[2];
Pointer[] pKnots = new Pointer[]{(Pointer) nurb.getFieldValue("knotsu"), (Pointer) nurb.getFieldValue("knotsv")}; Pointer[] pKnots = new Pointer[]{(Pointer) nurb.getFieldValue("knotsu"), (Pointer) nurb.getFieldValue("knotsv")};
for (int i = 0; i < knots.length; ++i) { for (int i = 0; i < knots.length; ++i) {
if (pKnots[i].isNotNull()) { if (pKnots[i].isNotNull()) {
FileBlockHeader fileBlockHeader = dataRepository.getFileBlock(pKnots[i].getOldMemoryAddress()); FileBlockHeader fileBlockHeader = blenderContext.getFileBlock(pKnots[i].getOldMemoryAddress());
BlenderInputStream blenderInputStream = dataRepository.getInputStream(); BlenderInputStream blenderInputStream = blenderContext.getInputStream();
blenderInputStream.setPosition(fileBlockHeader.getBlockPosition()); blenderInputStream.setPosition(fileBlockHeader.getBlockPosition());
int knotsAmount = fileBlockHeader.getCount() * fileBlockHeader.getSize() / 4; int knotsAmount = fileBlockHeader.getCount() * fileBlockHeader.getSize() / 4;
knots[i] = new ArrayList<Float>(knotsAmount); knots[i] = new ArrayList<Float>(knotsAmount);
@ -313,7 +313,7 @@ public class CurvesHelper extends AbstractBlenderHelper {
//loading control points and their weights //loading control points and their weights
int pntsU = ((Number) nurb.getFieldValue("pntsu")).intValue(); int pntsU = ((Number) nurb.getFieldValue("pntsu")).intValue();
int pntsV = ((Number) nurb.getFieldValue("pntsv")).intValue(); int pntsV = ((Number) nurb.getFieldValue("pntsv")).intValue();
List<Structure> bPoints = ((Pointer) nurb.getFieldValue("bp")).fetchData(dataRepository.getInputStream()); List<Structure> bPoints = ((Pointer) nurb.getFieldValue("bp")).fetchData(blenderContext.getInputStream());
List<List<Vector4f>> controlPoints = new ArrayList<List<Vector4f>>(pntsV); List<List<Vector4f>> controlPoints = new ArrayList<List<Vector4f>>(pntsV);
for (int i = 0; i < pntsV; ++i) { for (int i = 0; i < pntsV; ++i) {
List<Vector4f> uControlPoints = new ArrayList<Vector4f>(pntsU); List<Vector4f> uControlPoints = new ArrayList<Vector4f>(pntsU);
@ -344,7 +344,7 @@ public class CurvesHelper extends AbstractBlenderHelper {
Spline nurbSpline = new Spline(controlPoints.get(0), knots[0]); Spline nurbSpline = new Spline(controlPoints.get(0), knots[0]);
Curve nurbCurve = new Curve(nurbSpline, resolu); Curve nurbCurve = new Curve(nurbSpline, resolu);
if (bevelObject != null) { if (bevelObject != null) {
result = this.applyBevelAndTaper(nurbCurve, bevelObject, taperObject, true, dataRepository);//TODO: smooth result = this.applyBevelAndTaper(nurbCurve, bevelObject, taperObject, true, blenderContext);//TODO: smooth
} else { } else {
result = new ArrayList<Geometry>(1); result = new ArrayList<Geometry>(1);
Geometry nurbGeometry = new Geometry("", nurbCurve); Geometry nurbGeometry = new Geometry("", nurbCurve);
@ -400,14 +400,14 @@ public class CurvesHelper extends AbstractBlenderHelper {
* the taper object * the taper object
* @param smooth * @param smooth
* the smooth flag * the smooth flag
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @return a list of geometries representing the beveled and/or tapered curve * @return a list of geometries representing the beveled and/or tapered curve
*/ */
protected List<Geometry> applyBevelAndTaper(Curve curve, List<Geometry> bevelObject, Curve taperObject, protected List<Geometry> applyBevelAndTaper(Curve curve, List<Geometry> bevelObject, Curve taperObject,
boolean smooth, DataRepository dataRepository) { boolean smooth, BlenderContext blenderContext) {
float[] curvePoints = BufferUtils.getFloatArray(curve.getFloatBuffer(Type.Position)); float[] curvePoints = BufferUtils.getFloatArray(curve.getFloatBuffer(Type.Position));
MeshHelper meshHelper = dataRepository.getHelper(MeshHelper.class); MeshHelper meshHelper = blenderContext.getHelper(MeshHelper.class);
float curveLength = curve.getLength(); float curveLength = curve.getLength();
//TODO: use the smooth var //TODO: use the smooth var
@ -556,19 +556,19 @@ public class CurvesHelper extends AbstractBlenderHelper {
* This method loads the taper object. * This method loads the taper object.
* @param taperStructure * @param taperStructure
* the taper structure * the taper structure
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @return the taper object * @return the taper object
* @throws BlenderFileException * @throws BlenderFileException
*/ */
protected Curve loadTaperObject(Structure taperStructure, DataRepository dataRepository) throws BlenderFileException { protected Curve loadTaperObject(Structure taperStructure, BlenderContext blenderContext) throws BlenderFileException {
//reading nurbs //reading nurbs
List<Structure> nurbStructures = ((Structure) taperStructure.getFieldValue("nurb")).evaluateListBase(dataRepository); List<Structure> nurbStructures = ((Structure) taperStructure.getFieldValue("nurb")).evaluateListBase(blenderContext);
for (Structure nurb : nurbStructures) { for (Structure nurb : nurbStructures) {
Pointer pBezierTriple = (Pointer) nurb.getFieldValue("bezt"); Pointer pBezierTriple = (Pointer) nurb.getFieldValue("bezt");
if (pBezierTriple.isNotNull()) { if (pBezierTriple.isNotNull()) {
//creating the curve object //creating the curve object
BezierCurve bezierCurve = new BezierCurve(0, pBezierTriple.fetchData(dataRepository.getInputStream()), 3); BezierCurve bezierCurve = new BezierCurve(0, pBezierTriple.fetchData(blenderContext.getInputStream()), 3);
List<Vector3f> controlPoints = bezierCurve.getControlPoints(); List<Vector3f> controlPoints = bezierCurve.getControlPoints();
//removing the first and last handles //removing the first and last handles
controlPoints.remove(0); controlPoints.remove(0);
@ -602,7 +602,7 @@ public class CurvesHelper extends AbstractBlenderHelper {
} }
@Override @Override
public boolean shouldBeLoaded(Structure structure, DataRepository dataRepository) { public boolean shouldBeLoaded(Structure structure, BlenderContext blenderContext) {
return true; return true;
} }
} }

@ -34,7 +34,7 @@ package com.jme3.scene.plugins.blender.file;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
/** /**
@ -57,12 +57,12 @@ public class DnaBlockData {
* Constructor. Loads the block from the given stream during instance creation. * Constructor. Loads the block from the given stream during instance creation.
* @param inputStream * @param inputStream
* the stream we read the block from * the stream we read the block from
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @throws BlenderFileException * @throws BlenderFileException
* this exception is throw if the blend file is invalid or somehow corrupted * this exception is throw if the blend file is invalid or somehow corrupted
*/ */
public DnaBlockData(BlenderInputStream inputStream, DataRepository dataRepository) throws BlenderFileException { public DnaBlockData(BlenderInputStream inputStream, BlenderContext blenderContext) throws BlenderFileException {
int identifier; int identifier;
//reading 'SDNA' identifier //reading 'SDNA' identifier
@ -130,7 +130,7 @@ public class DnaBlockData {
structures = new Structure[amount]; structures = new Structure[amount];
structuresMap = new HashMap<String, Structure>(amount); structuresMap = new HashMap<String, Structure>(amount);
for (int i = 0; i < amount; ++i) { for (int i = 0; i < amount; ++i) {
structures[i] = new Structure(inputStream, names, types, dataRepository); structures[i] = new Structure(inputStream, names, types, blenderContext);
if (structuresMap.containsKey(structures[i].getType())) { if (structuresMap.containsKey(structures[i].getType())) {
throw new BlenderFileException("Blend file seems to be corrupted! The type " + structures[i].getType() + " is defined twice!"); throw new BlenderFileException("Blend file seems to be corrupted! The type " + structures[i].getType() + " is defined twice!");
} }

@ -3,7 +3,7 @@ package com.jme3.scene.plugins.blender.file;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.Structure.DataType; import com.jme3.scene.plugins.blender.file.Structure.DataType;
@ -17,8 +17,8 @@ class Field implements Cloneable {
private static final int NAME_LENGTH = 24; private static final int NAME_LENGTH = 24;
private static final int TYPE_LENGTH = 16; private static final int TYPE_LENGTH = 16;
/** The data repository. */ /** The blender context. */
public DataRepository dataRepository; public BlenderContext blenderContext;
/** The type of the field. */ /** The type of the field. */
public String type; public String type;
/** The name of the field. */ /** The name of the field. */
@ -40,14 +40,14 @@ class Field implements Cloneable {
* the name of the field * the name of the field
* @param type * @param type
* the type of the field * the type of the field
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown if the names contain errors * this exception is thrown if the names contain errors
*/ */
public Field(String name, String type, DataRepository dataRepository) throws BlenderFileException { public Field(String name, String type, BlenderContext blenderContext) throws BlenderFileException {
this.type = type; this.type = type;
this.dataRepository = dataRepository; this.blenderContext = blenderContext;
this.parseField(new StringBuilder(name)); this.parseField(new StringBuilder(name));
} }
@ -60,7 +60,7 @@ class Field implements Cloneable {
private Field(Field field) { private Field(Field field) {
type = field.type; type = field.type;
name = field.name; name = field.name;
dataRepository = field.dataRepository; blenderContext = field.blenderContext;
pointerLevel = field.pointerLevel; pointerLevel = field.pointerLevel;
if (field.tableSizes != null) { if (field.tableSizes != null) {
tableSizes = field.tableSizes.clone(); tableSizes = field.tableSizes.clone();
@ -90,17 +90,17 @@ class Field implements Cloneable {
dataToRead *= size; dataToRead *= size;
} }
} }
DataType dataType = pointerLevel == 0 ? DataType.getDataType(type, dataRepository) : DataType.POINTER; DataType dataType = pointerLevel == 0 ? DataType.getDataType(type, blenderContext) : DataType.POINTER;
switch (dataType) { switch (dataType) {
case POINTER: case POINTER:
if (dataToRead == 1) { if (dataToRead == 1) {
Pointer pointer = new Pointer(pointerLevel, function, dataRepository); Pointer pointer = new Pointer(pointerLevel, function, blenderContext);
pointer.fill(blenderInputStream); pointer.fill(blenderInputStream);
value = pointer; value = pointer;
} else { } else {
Pointer[] data = new Pointer[dataToRead]; Pointer[] data = new Pointer[dataToRead];
for (int i = 0; i < dataToRead; ++i) { for (int i = 0; i < dataToRead; ++i) {
Pointer pointer = new Pointer(pointerLevel, function, dataRepository); Pointer pointer = new Pointer(pointerLevel, function, blenderContext);
pointer.fill(blenderInputStream); pointer.fill(blenderInputStream);
data[i] = pointer; data[i] = pointer;
} }
@ -180,13 +180,13 @@ class Field implements Cloneable {
break; break;
case STRUCTURE: case STRUCTURE:
if (dataToRead == 1) { if (dataToRead == 1) {
Structure structure = dataRepository.getDnaBlockData().getStructure(type); Structure structure = blenderContext.getDnaBlockData().getStructure(type);
structure.fill(blenderInputStream); structure.fill(blenderInputStream);
value = structure; value = structure;
} else { } else {
Structure[] data = new Structure[dataToRead]; Structure[] data = new Structure[dataToRead];
for (int i = 0; i < dataToRead; ++i) { for (int i = 0; i < dataToRead; ++i) {
Structure structure = dataRepository.getDnaBlockData().getStructure(type); Structure structure = blenderContext.getDnaBlockData().getStructure(type);
structure.fill(blenderInputStream); structure.fill(blenderInputStream);
data[i] = structure; data[i] = structure;
} }

@ -31,7 +31,7 @@
*/ */
package com.jme3.scene.plugins.blender.file; package com.jme3.scene.plugins.blender.file;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
/** /**
@ -78,12 +78,12 @@ public class FileBlockHeader {
* Constructor. Loads the block header from the given stream during instance creation. * Constructor. Loads the block header from the given stream during instance creation.
* @param inputStream * @param inputStream
* the stream we read the block header from * the stream we read the block header from
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the pointer size is neither 4 nor 8 * this exception is thrown when the pointer size is neither 4 nor 8
*/ */
public FileBlockHeader(BlenderInputStream inputStream, DataRepository dataRepository) throws BlenderFileException { public FileBlockHeader(BlenderInputStream inputStream, BlenderContext blenderContext) throws BlenderFileException {
inputStream.alignPosition(4); inputStream.alignPosition(4);
code = inputStream.readByte() << 24 | inputStream.readByte() << 16 code = inputStream.readByte() << 24 | inputStream.readByte() << 16
| inputStream.readByte() << 8 | inputStream.readByte(); | inputStream.readByte() << 8 | inputStream.readByte();
@ -93,24 +93,24 @@ public class FileBlockHeader {
count = inputStream.readInt(); count = inputStream.readInt();
blockPosition = inputStream.getPosition(); blockPosition = inputStream.getPosition();
if (FileBlockHeader.BLOCK_DNA1 == code) { if (FileBlockHeader.BLOCK_DNA1 == code) {
dataRepository.setBlockData(new DnaBlockData(inputStream, dataRepository)); blenderContext.setBlockData(new DnaBlockData(inputStream, blenderContext));
} else { } else {
inputStream.setPosition(blockPosition + size); inputStream.setPosition(blockPosition + size);
dataRepository.addFileBlockHeader(Long.valueOf(oldMemoryAddress), this); blenderContext.addFileBlockHeader(Long.valueOf(oldMemoryAddress), this);
} }
} }
/** /**
* This method returns the structure described by the header filled with appropriate data. * This method returns the structure described by the header filled with appropriate data.
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @return structure filled with data * @return structure filled with data
* @throws BlenderFileException * @throws BlenderFileException
*/ */
public Structure getStructure(DataRepository dataRepository) throws BlenderFileException { public Structure getStructure(BlenderContext blenderContext) throws BlenderFileException {
dataRepository.getInputStream().setPosition(blockPosition); blenderContext.getInputStream().setPosition(blockPosition);
Structure structure = dataRepository.getDnaBlockData().getStructure(sdnaIndex); Structure structure = blenderContext.getDnaBlockData().getStructure(sdnaIndex);
structure.fill(dataRepository.getInputStream()); structure.fill(blenderContext.getInputStream());
return structure; return structure;
} }

@ -34,7 +34,7 @@ package com.jme3.scene.plugins.blender.file;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
/** /**
@ -43,8 +43,8 @@ import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
*/ */
public class Pointer { public class Pointer {
/** The data repository. */ /** The blender context. */
private DataRepository dataRepository; private BlenderContext blenderContext;
/** The level of the pointer. */ /** The level of the pointer. */
private int pointerLevel; private int pointerLevel;
/** The address in file it points to. */ /** The address in file it points to. */
@ -58,13 +58,13 @@ public class Pointer {
* the level of the pointer * the level of the pointer
* @param function * @param function
* this variable indicates if the field is a function pointer * this variable indicates if the field is a function pointer
* @param dataRepository * @param blenderContext
* the repository f data; used in fetching the value that the pointer points * the repository f data; used in fetching the value that the pointer points
*/ */
public Pointer(int pointerLevel, boolean function, DataRepository dataRepository) { public Pointer(int pointerLevel, boolean function, BlenderContext blenderContext) {
this.pointerLevel = pointerLevel; this.pointerLevel = pointerLevel;
this.function = function; this.function = function;
this.dataRepository = dataRepository; this.blenderContext = blenderContext;
} }
/** /**
@ -92,14 +92,14 @@ public class Pointer {
throw new NullPointerException("The pointer points to nothing!"); throw new NullPointerException("The pointer points to nothing!");
} }
List<Structure> structures = null; List<Structure> structures = null;
FileBlockHeader dataFileBlock = dataRepository.getFileBlock(oldMemoryAddress); FileBlockHeader dataFileBlock = blenderContext.getFileBlock(oldMemoryAddress);
if (pointerLevel > 1) { if (pointerLevel > 1) {
int pointersAmount = dataFileBlock.getSize() / inputStream.getPointerSize() * dataFileBlock.getCount(); int pointersAmount = dataFileBlock.getSize() / inputStream.getPointerSize() * dataFileBlock.getCount();
for (int i = 0; i < pointersAmount; ++i) { for (int i = 0; i < pointersAmount; ++i) {
inputStream.setPosition(dataFileBlock.getBlockPosition() + inputStream.getPointerSize() * i); inputStream.setPosition(dataFileBlock.getBlockPosition() + inputStream.getPointerSize() * i);
long oldMemoryAddress = inputStream.readPointer(); long oldMemoryAddress = inputStream.readPointer();
if (oldMemoryAddress != 0L) { if (oldMemoryAddress != 0L) {
Pointer p = new Pointer(pointerLevel - 1, this.function, dataRepository); Pointer p = new Pointer(pointerLevel - 1, this.function, blenderContext);
p.oldMemoryAddress = oldMemoryAddress; p.oldMemoryAddress = oldMemoryAddress;
if (structures == null) { if (structures == null) {
structures = p.fetchData(inputStream); structures = p.fetchData(inputStream);
@ -112,7 +112,7 @@ public class Pointer {
inputStream.setPosition(dataFileBlock.getBlockPosition()); inputStream.setPosition(dataFileBlock.getBlockPosition());
structures = new ArrayList<Structure>(dataFileBlock.getCount()); structures = new ArrayList<Structure>(dataFileBlock.getCount());
for (int i = 0; i < dataFileBlock.getCount(); ++i) { for (int i = 0; i < dataFileBlock.getCount(); ++i) {
Structure structure = dataRepository.getDnaBlockData().getStructure(dataFileBlock.getSdnaIndex()); Structure structure = blenderContext.getDnaBlockData().getStructure(dataFileBlock.getSdnaIndex());
structure.fill(inputStream); structure.fill(inputStream);
structures.add(structure); structures.add(structure);
} }

@ -36,7 +36,7 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
/** /**
@ -45,8 +45,8 @@ import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
*/ */
public class Structure implements Cloneable { public class Structure implements Cloneable {
/** The data repository. */ /** The blender context. */
private DataRepository dataRepository; private BlenderContext blenderContext;
/** The address of the block that fills the structure. */ /** The address of the block that fills the structure. */
private transient Long oldMemoryAddress; private transient Long oldMemoryAddress;
/** The type of the structure. */ /** The type of the structure. */
@ -60,18 +60,18 @@ public class Structure implements Cloneable {
* Constructor that copies the data of the structure. * Constructor that copies the data of the structure.
* @param structure * @param structure
* the structure to copy. * the structure to copy.
* @param dataRepository * @param blenderContext
* the data repository of the structure * the blender context of the structure
* @throws CloneNotSupportedException * @throws CloneNotSupportedException
* this exception should never be thrown * this exception should never be thrown
*/ */
private Structure(Structure structure, DataRepository dataRepository) throws CloneNotSupportedException { private Structure(Structure structure, BlenderContext blenderContext) throws CloneNotSupportedException {
type = structure.type; type = structure.type;
fields = new Field[structure.fields.length]; fields = new Field[structure.fields.length];
for (int i = 0; i < fields.length; ++i) { for (int i = 0; i < fields.length; ++i) {
fields[i] = (Field) structure.fields[i].clone(); fields[i] = (Field) structure.fields[i].clone();
} }
this.dataRepository = dataRepository; this.blenderContext = blenderContext;
this.oldMemoryAddress = structure.oldMemoryAddress; this.oldMemoryAddress = structure.oldMemoryAddress;
} }
@ -83,15 +83,15 @@ public class Structure implements Cloneable {
* the names from which the name of structure and its fields will be taken * the names from which the name of structure and its fields will be taken
* @param types * @param types
* the names of types for the structure * the names of types for the structure
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @throws BlenderFileException * @throws BlenderFileException
* this exception occurs if the amount of fields, defined in the file, is negative * this exception occurs if the amount of fields, defined in the file, is negative
*/ */
public Structure(BlenderInputStream inputStream, String[] names, String[] types, DataRepository dataRepository) throws BlenderFileException { public Structure(BlenderInputStream inputStream, String[] names, String[] types, BlenderContext blenderContext) throws BlenderFileException {
int nameIndex = inputStream.readShort(); int nameIndex = inputStream.readShort();
type = types[nameIndex]; type = types[nameIndex];
this.dataRepository = dataRepository; this.blenderContext = blenderContext;
int fieldsAmount = inputStream.readShort(); int fieldsAmount = inputStream.readShort();
if (fieldsAmount < 0) { if (fieldsAmount < 0) {
throw new BlenderFileException("The amount of fields of " + this.type + " structure cannot be negative!"); throw new BlenderFileException("The amount of fields of " + this.type + " structure cannot be negative!");
@ -101,7 +101,7 @@ public class Structure implements Cloneable {
for (int i = 0; i < fieldsAmount; ++i) { for (int i = 0; i < fieldsAmount; ++i) {
int typeIndex = inputStream.readShort(); int typeIndex = inputStream.readShort();
nameIndex = inputStream.readShort(); nameIndex = inputStream.readShort();
fields[i] = new Field(names[nameIndex], types[typeIndex], dataRepository); fields[i] = new Field(names[nameIndex], types[typeIndex], blenderContext);
} }
} }
this.oldMemoryAddress = Long.valueOf(-1L); this.oldMemoryAddress = Long.valueOf(-1L);
@ -165,15 +165,15 @@ public class Structure implements Cloneable {
/** /**
* This methos should be used on structures that are of a 'ListBase' type. It creates a List of structures that are * This methos should be used on structures that are of a 'ListBase' type. It creates a List of structures that are
* held by this structure within the blend file. * held by this structure within the blend file.
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @return a list of filled structures * @return a list of filled structures
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blend file structure is somehow invalid or corrupted * this exception is thrown when the blend file structure is somehow invalid or corrupted
* @throws IllegalArgumentException * @throws IllegalArgumentException
* this exception is thrown if the type of the structure is not 'ListBase' * this exception is thrown if the type of the structure is not 'ListBase'
*/ */
public List<Structure> evaluateListBase(DataRepository dataRepository) throws BlenderFileException { public List<Structure> evaluateListBase(BlenderContext blenderContext) throws BlenderFileException {
if (!"ListBase".equals(this.type)) { if (!"ListBase".equals(this.type)) {
throw new IllegalStateException("This structure is not of type: 'ListBase'"); throw new IllegalStateException("This structure is not of type: 'ListBase'");
} }
@ -184,7 +184,7 @@ public class Structure implements Cloneable {
List<Structure> result = new LinkedList<Structure>(); List<Structure> result = new LinkedList<Structure>();
while (currentAddress != lastAddress) { while (currentAddress != lastAddress) {
currentAddress = first.getOldMemoryAddress(); currentAddress = first.getOldMemoryAddress();
Structure structure = first.fetchData(dataRepository.getInputStream()).get(0); Structure structure = first.fetchData(blenderContext.getInputStream()).get(0);
result.add(structure); result.add(structure);
first = (Pointer) structure.getFlatFieldValue("next"); first = (Pointer) structure.getFlatFieldValue("next");
} }
@ -264,7 +264,7 @@ public class Structure implements Cloneable {
@Override @Override
public Object clone() throws CloneNotSupportedException { public Object clone() throws CloneNotSupportedException {
return new Structure(this, dataRepository); return new Structure(this, blenderContext);
} }
/** /**
@ -296,18 +296,18 @@ public class Structure implements Cloneable {
* is case sensitive! * is case sensitive!
* @param type * @param type
* the type name of the data * the type name of the data
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @return appropriate enum value to the given type name * @return appropriate enum value to the given type name
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown if the given type name does not exist in the blend file * this exception is thrown if the given type name does not exist in the blend file
*/ */
public static DataType getDataType(String type, DataRepository dataRepository) throws BlenderFileException { public static DataType getDataType(String type, BlenderContext blenderContext) throws BlenderFileException {
DataType result = PRIMARY_TYPES.get(type); DataType result = PRIMARY_TYPES.get(type);
if (result != null) { if (result != null) {
return result; return result;
} }
if (dataRepository.getDnaBlockData().hasStructure(type)) { if (blenderContext.getDnaBlockData().hasStructure(type)) {
return STRUCTURE; return STRUCTURE;
} }
throw new BlenderFileException("Unknown data type: " + type); throw new BlenderFileException("Unknown data type: " + type);

@ -42,8 +42,8 @@ import com.jme3.light.SpotLight;
import com.jme3.math.ColorRGBA; import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath; import com.jme3.math.FastMath;
import com.jme3.scene.plugins.blender.AbstractBlenderHelper; import com.jme3.scene.plugins.blender.AbstractBlenderHelper;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.DataRepository.LoadedFeatureDataType; import com.jme3.scene.plugins.blender.BlenderContext.LoadedFeatureDataType;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
@ -65,8 +65,8 @@ public class LightHelper extends AbstractBlenderHelper {
super(blenderVersion); super(blenderVersion);
} }
public Light toLight(Structure structure, DataRepository dataRepository) throws BlenderFileException { public Light toLight(Structure structure, BlenderContext blenderContext) throws BlenderFileException {
Light result = (Light) dataRepository.getLoadedFeature(structure.getOldMemoryAddress(), LoadedFeatureDataType.LOADED_FEATURE); Light result = (Light) blenderContext.getLoadedFeature(structure.getOldMemoryAddress(), LoadedFeatureDataType.LOADED_FEATURE);
if (result != null) { if (result != null) {
return result; return result;
} }
@ -114,7 +114,7 @@ public class LightHelper extends AbstractBlenderHelper {
} }
@Override @Override
public boolean shouldBeLoaded(Structure structure, DataRepository dataRepository) { public boolean shouldBeLoaded(Structure structure, BlenderContext blenderContext) {
return (dataRepository.getBlenderKey().getFeaturesToLoad() & FeaturesToLoad.LIGHTS) != 0; return (blenderContext.getBlenderKey().getFeaturesToLoad() & FeaturesToLoad.LIGHTS) != 0;
} }
} }

@ -5,7 +5,7 @@ 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.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.DynamicArray; import com.jme3.scene.plugins.blender.file.DynamicArray;
import com.jme3.scene.plugins.blender.file.Pointer; import com.jme3.scene.plugins.blender.file.Pointer;
@ -31,7 +31,7 @@ public final class MaterialContext {
/* package */int projectionType; /* package */int projectionType;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
/* package */MaterialContext(Structure structure, DataRepository dataRepository) throws BlenderFileException { /* package */MaterialContext(Structure structure, BlenderContext blenderContext) throws BlenderFileException {
name = structure.getName(); name = structure.getName();
int mode = ((Number) structure.getFieldValue("mode")).intValue(); int mode = ((Number) structure.getFieldValue("mode")).intValue();
@ -48,7 +48,7 @@ public final class MaterialContext {
for (int i = 0; i < mtexsArray.getTotalSize(); ++i) { for (int i = 0; i < mtexsArray.getTotalSize(); ++i) {
Pointer p = mtexsArray.get(i); Pointer p = mtexsArray.get(i);
if (p.isNotNull() && (separatedTextures & 1 << i) == 0) { if (p.isNotNull() && (separatedTextures & 1 << i) == 0) {
Structure mtex = p.fetchData(dataRepository.getInputStream()).get(0); Structure mtex = p.fetchData(blenderContext.getInputStream()).get(0);
// the first texture determines the texture coordinates type // the first texture determines the texture coordinates type
if (uvCoordinatesType == -1) { if (uvCoordinatesType == -1) {
@ -61,7 +61,7 @@ public final class MaterialContext {
Pointer pTex = (Pointer) mtex.getFieldValue("tex"); Pointer pTex = (Pointer) mtex.getFieldValue("tex");
if (pTex.isNotNull()) { if (pTex.isNotNull()) {
Structure tex = pTex.fetchData(dataRepository.getInputStream()).get(0); Structure tex = pTex.fetchData(blenderContext.getInputStream()).get(0);
int type = ((Number) tex.getFieldValue("type")).intValue(); int type = ((Number) tex.getFieldValue("type")).intValue();
Type textureType = this.getType(type); Type textureType = this.getType(type);
if (textureType != null) { if (textureType != null) {

@ -49,8 +49,8 @@ import com.jme3.material.RenderState.FaceCullMode;
import com.jme3.math.ColorRGBA; import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath; import com.jme3.math.FastMath;
import com.jme3.scene.plugins.blender.AbstractBlenderHelper; import com.jme3.scene.plugins.blender.AbstractBlenderHelper;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.DataRepository.LoadedFeatureDataType; import com.jme3.scene.plugins.blender.BlenderContext.LoadedFeatureDataType;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.Pointer; import com.jme3.scene.plugins.blender.file.Pointer;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
@ -182,23 +182,23 @@ public class MaterialHelper extends AbstractBlenderHelper {
* This method converts the material structure to jme Material. * This method converts the material structure to jme Material.
* @param structure * @param structure
* structure with material data * structure with material data
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @return jme material * @return jme material
* @throws BlenderFileException * @throws BlenderFileException
* an exception is throw when problems with blend file occur * an exception is throw when problems with blend file occur
*/ */
public Material toMaterial(Structure structure, DataRepository dataRepository) throws BlenderFileException { public Material toMaterial(Structure structure, BlenderContext blenderContext) throws BlenderFileException {
LOGGER.log(Level.INFO, "Loading material."); LOGGER.log(Level.INFO, "Loading material.");
if (structure == null) { if (structure == null) {
return dataRepository.getDefaultMaterial(); return blenderContext.getDefaultMaterial();
} }
Material result = (Material) dataRepository.getLoadedFeature(structure.getOldMemoryAddress(), LoadedFeatureDataType.LOADED_FEATURE); Material result = (Material) blenderContext.getLoadedFeature(structure.getOldMemoryAddress(), LoadedFeatureDataType.LOADED_FEATURE);
if (result != null) { if (result != null) {
return result; return result;
} }
MaterialContext materialContext = new MaterialContext(structure, dataRepository); MaterialContext materialContext = new MaterialContext(structure, blenderContext);
LOGGER.log(Level.INFO, "Material's name: {0}", materialContext.name); LOGGER.log(Level.INFO, "Material's name: {0}", materialContext.name);
if(materialContext.textures.size() > 0) { if(materialContext.textures.size() > 0) {
@ -212,8 +212,8 @@ public class MaterialHelper extends AbstractBlenderHelper {
// texture // texture
Map<String, Texture> texturesMap = new HashMap<String, Texture>(); Map<String, Texture> texturesMap = new HashMap<String, Texture>();
Type firstTextureType = null; Type firstTextureType = null;
if ((dataRepository.getBlenderKey().getFeaturesToLoad() & FeaturesToLoad.TEXTURES) != 0) { if ((blenderContext.getBlenderKey().getFeaturesToLoad() & FeaturesToLoad.TEXTURES) != 0) {
TextureHelper textureHelper = dataRepository.getHelper(TextureHelper.class); TextureHelper textureHelper = blenderContext.getHelper(TextureHelper.class);
for (int i=0;i<materialContext.texturesCount;++i) { for (int i=0;i<materialContext.texturesCount;++i) {
Structure mtex = materialContext.mTexs.get(i); Structure mtex = materialContext.mTexs.get(i);
@ -223,7 +223,7 @@ public class MaterialHelper extends AbstractBlenderHelper {
int mapto = ((Number) mtex.getFieldValue("mapto")).intValue(); int mapto = ((Number) mtex.getFieldValue("mapto")).intValue();
if (mapto != 0) { if (mapto != 0) {
Structure tex = materialContext.textures.get(i); Structure tex = materialContext.textures.get(i);
Texture texture = textureHelper.getTexture(tex, dataRepository); Texture texture = textureHelper.getTexture(tex, blenderContext);
if (texture != null) { if (texture != null) {
if(firstTextureType == null) { if(firstTextureType == null) {
firstTextureType = texture.getType(); firstTextureType = texture.getType();
@ -245,7 +245,7 @@ public class MaterialHelper extends AbstractBlenderHelper {
int blendType = ((Number) mtex.getFieldValue("blendtype")).intValue(); int blendType = ((Number) mtex.getFieldValue("blendtype")).intValue();
float[] color = new float[] { ((Number) mtex.getFieldValue("r")).floatValue(), ((Number) mtex.getFieldValue("g")).floatValue(), ((Number) mtex.getFieldValue("b")).floatValue() }; float[] color = new float[] { ((Number) mtex.getFieldValue("r")).floatValue(), ((Number) mtex.getFieldValue("g")).floatValue(), ((Number) mtex.getFieldValue("b")).floatValue() };
float colfac = ((Number) mtex.getFieldValue("colfac")).floatValue(); float colfac = ((Number) mtex.getFieldValue("colfac")).floatValue();
texture = textureHelper.blendTexture(diffuseColorArray, texture, color, colfac, blendType, negateTexture, dataRepository); texture = textureHelper.blendTexture(diffuseColorArray, texture, color, colfac, blendType, negateTexture, blenderContext);
texture.setWrap(WrapMode.Repeat); texture.setWrap(WrapMode.Repeat);
//TODO: textures merging //TODO: textures merging
if (materialContext.shadeless) { if (materialContext.shadeless) {
@ -291,12 +291,12 @@ public class MaterialHelper extends AbstractBlenderHelper {
//creating the material //creating the material
if(firstTextureType==Type.ThreeDimensional) { if(firstTextureType==Type.ThreeDimensional) {
result = new Material(dataRepository.getAssetManager(), "jme3test/texture/tex3D.j3md"); result = new Material(blenderContext.getAssetManager(), "jme3test/texture/tex3D.j3md");
} else { } else {
if (materialContext.shadeless) { if (materialContext.shadeless) {
result = new Material(dataRepository.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); result = new Material(blenderContext.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
} else { } else {
result = new Material(dataRepository.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md"); result = new Material(blenderContext.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
} }
if (materialContext.vertexColor) { if (materialContext.vertexColor) {
@ -337,8 +337,8 @@ public class MaterialHelper extends AbstractBlenderHelper {
result.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); result.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
} }
dataRepository.setMaterialContext(result, materialContext); blenderContext.setMaterialContext(result, materialContext);
dataRepository.addLoadedFeatures(structure.getOldMemoryAddress(), structure.getName(), structure, result); blenderContext.addLoadedFeatures(structure.getOldMemoryAddress(), structure.getName(), structure, result);
return result; return result;
} }
@ -391,12 +391,12 @@ public class MaterialHelper extends AbstractBlenderHelper {
* The method assumes it receives the Lighting type of material. * The method assumes it receives the Lighting type of material.
* @param material * @param material
* the source material * the source material
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @return material converted into particles-usable material * @return material converted into particles-usable material
*/ */
public Material getParticlesMaterial(Material material, Integer alphaMaskIndex, DataRepository dataRepository) { public Material getParticlesMaterial(Material material, Integer alphaMaskIndex, BlenderContext blenderContext) {
Material result = new Material(dataRepository.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md"); Material result = new Material(blenderContext.getAssetManager(), "Common/MatDefs/Misc/Particle.j3md");
// copying texture // copying texture
MatParam diffuseMap = material.getParam("DiffuseMap"); MatParam diffuseMap = material.getParam("DiffuseMap");
@ -612,25 +612,25 @@ public class MaterialHelper extends AbstractBlenderHelper {
* *
* @param structureWithMaterials * @param structureWithMaterials
* the structure containing the mesh data * the structure containing the mesh data
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @return a list of vertices colors, each color belongs to a single vertex * @return a list of vertices colors, each color belongs to a single vertex
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blend file structure is somehow invalid or corrupted * this exception is thrown when the blend file structure is somehow invalid or corrupted
*/ */
public Material[] getMaterials(Structure structureWithMaterials, DataRepository dataRepository) throws BlenderFileException { public Material[] getMaterials(Structure structureWithMaterials, BlenderContext blenderContext) throws BlenderFileException {
Pointer ppMaterials = (Pointer) structureWithMaterials.getFieldValue("mat"); Pointer ppMaterials = (Pointer) structureWithMaterials.getFieldValue("mat");
Material[] materials = null; Material[] materials = null;
if (ppMaterials.isNotNull()) { if (ppMaterials.isNotNull()) {
List<Structure> materialStructures = ppMaterials.fetchData(dataRepository.getInputStream()); List<Structure> materialStructures = ppMaterials.fetchData(blenderContext.getInputStream());
if (materialStructures != null && materialStructures.size() > 0) { if (materialStructures != null && materialStructures.size() > 0) {
MaterialHelper materialHelper = dataRepository.getHelper(MaterialHelper.class); MaterialHelper materialHelper = blenderContext.getHelper(MaterialHelper.class);
materials = new Material[materialStructures.size()]; materials = new Material[materialStructures.size()];
int i = 0; int i = 0;
for (Structure s : materialStructures) { for (Structure s : materialStructures) {
Material material = (Material) dataRepository.getLoadedFeature(s.getOldMemoryAddress(), LoadedFeatureDataType.LOADED_FEATURE); Material material = (Material) blenderContext.getLoadedFeature(s.getOldMemoryAddress(), LoadedFeatureDataType.LOADED_FEATURE);
if (material == null) { if (material == null) {
material = materialHelper.toMaterial(s, dataRepository); material = materialHelper.toMaterial(s, blenderContext);
} }
materials[i++] = material; materials[i++] = material;
} }
@ -751,7 +751,7 @@ public class MaterialHelper extends AbstractBlenderHelper {
} }
@Override @Override
public boolean shouldBeLoaded(Structure structure, DataRepository dataRepository) { public boolean shouldBeLoaded(Structure structure, BlenderContext blenderContext) {
return (dataRepository.getBlenderKey().getFeaturesToLoad() & FeaturesToLoad.MATERIALS) != 0; return (blenderContext.getBlenderKey().getFeaturesToLoad() & FeaturesToLoad.MATERIALS) != 0;
} }
} }

@ -52,8 +52,8 @@ import com.jme3.scene.VertexBuffer.Format;
import com.jme3.scene.VertexBuffer.Type; import com.jme3.scene.VertexBuffer.Type;
import com.jme3.scene.VertexBuffer.Usage; import com.jme3.scene.VertexBuffer.Usage;
import com.jme3.scene.plugins.blender.AbstractBlenderHelper; import com.jme3.scene.plugins.blender.AbstractBlenderHelper;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.DataRepository.LoadedFeatureDataType; import com.jme3.scene.plugins.blender.BlenderContext.LoadedFeatureDataType;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.DynamicArray; import com.jme3.scene.plugins.blender.file.DynamicArray;
import com.jme3.scene.plugins.blender.file.Pointer; import com.jme3.scene.plugins.blender.file.Pointer;
@ -92,8 +92,8 @@ public class MeshHelper extends AbstractBlenderHelper {
* @throws BlenderFileException * @throws BlenderFileException
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public List<Geometry> toMesh(Structure structure, DataRepository dataRepository) throws BlenderFileException { public List<Geometry> toMesh(Structure structure, BlenderContext blenderContext) throws BlenderFileException {
List<Geometry> geometries = (List<Geometry>) dataRepository.getLoadedFeature(structure.getOldMemoryAddress(), List<Geometry> geometries = (List<Geometry>) blenderContext.getLoadedFeature(structure.getOldMemoryAddress(),
LoadedFeatureDataType.LOADED_FEATURE); LoadedFeatureDataType.LOADED_FEATURE);
if (geometries != null) { if (geometries != null) {
List<Geometry> copiedGeometries = new ArrayList<Geometry>(geometries.size()); List<Geometry> copiedGeometries = new ArrayList<Geometry>(geometries.size());
@ -104,17 +104,17 @@ public class MeshHelper extends AbstractBlenderHelper {
} }
// helpers // helpers
TextureHelper textureHelper = dataRepository.getHelper(TextureHelper.class); TextureHelper textureHelper = blenderContext.getHelper(TextureHelper.class);
// reading mesh data // reading mesh data
String name = structure.getName(); String name = structure.getName();
// reading vertices // reading vertices
Vector3f[] vertices = this.getVertices(structure, dataRepository); Vector3f[] vertices = this.getVertices(structure, blenderContext);
int verticesAmount = vertices.length; int verticesAmount = vertices.length;
// vertices Colors // vertices Colors
List<float[]> verticesColors = this.getVerticesColors(structure, dataRepository); List<float[]> verticesColors = this.getVerticesColors(structure, blenderContext);
// reading faces // reading faces
// the following map sorts faces by material number (because in jme Mesh can have only one material) // the following map sorts faces by material number (because in jme Mesh can have only one material)
@ -122,7 +122,7 @@ public class MeshHelper extends AbstractBlenderHelper {
Pointer pMFace = (Pointer) structure.getFieldValue("mface"); Pointer pMFace = (Pointer) structure.getFieldValue("mface");
List<Structure> mFaces = null; List<Structure> mFaces = null;
if (pMFace.isNotNull()){ if (pMFace.isNotNull()){
mFaces = pMFace.fetchData(dataRepository.getInputStream()); mFaces = pMFace.fetchData(blenderContext.getInputStream());
if(mFaces==null || mFaces.size()==0) { if(mFaces==null || mFaces.size()==0) {
return new ArrayList<Geometry>(0); return new ArrayList<Geometry>(0);
} }
@ -133,7 +133,7 @@ public class MeshHelper extends AbstractBlenderHelper {
List<Structure> mtFaces = null; List<Structure> mtFaces = null;
if (pMTFace.isNotNull()) { if (pMTFace.isNotNull()) {
mtFaces = pMTFace.fetchData(dataRepository.getInputStream()); mtFaces = pMTFace.fetchData(blenderContext.getInputStream());
int facesAmount = ((Number) structure.getFieldValue("totface")).intValue(); int facesAmount = ((Number) structure.getFieldValue("totface")).intValue();
if (mtFaces.size() != facesAmount) { if (mtFaces.size() != facesAmount) {
throw new BlenderFileException("The amount of faces uv coordinates is not equal to faces amount!"); throw new BlenderFileException("The amount of faces uv coordinates is not equal to faces amount!");
@ -178,8 +178,8 @@ public class MeshHelper extends AbstractBlenderHelper {
// attaching image to texture (face can have UV's and image whlie its material may have no texture attached) // attaching image to texture (face can have UV's and image whlie its material may have no texture attached)
if (pImage != null && pImage.isNotNull() && !materialNumberToTexture.containsKey(materialNumber)) { if (pImage != null && pImage.isNotNull() && !materialNumberToTexture.containsKey(materialNumber)) {
Texture texture = textureHelper.getTextureFromImage(pImage.fetchData(dataRepository.getInputStream()).get(0), Texture texture = textureHelper.getTextureFromImage(pImage.fetchData(blenderContext.getInputStream()).get(0),
dataRepository); blenderContext);
if (texture != null) { if (texture != null) {
materialNumberToTexture.put(materialNumber, texture); materialNumberToTexture.put(materialNumber, texture);
} }
@ -243,14 +243,14 @@ public class MeshHelper extends AbstractBlenderHelper {
} }
} }
} }
dataRepository.setVertexData(structure.getOldMemoryAddress(), new VertexData(vertexList, vertexReferenceMap)); blenderContext.setVertexData(structure.getOldMemoryAddress(), new VertexData(vertexList, vertexReferenceMap));
Vector3f[] normals = normalList.toArray(new Vector3f[normalList.size()]); Vector3f[] normals = normalList.toArray(new Vector3f[normalList.size()]);
// reading vertices groups (from the parent) // reading vertices groups (from the parent)
Structure parent = dataRepository.peekParent(); Structure parent = blenderContext.peekParent();
Structure defbase = (Structure) parent.getFieldValue("defbase"); Structure defbase = (Structure) parent.getFieldValue("defbase");
List<Structure> defs = defbase.evaluateListBase(dataRepository); List<Structure> defs = defbase.evaluateListBase(blenderContext);
String[] verticesGroups = new String[defs.size()]; String[] verticesGroups = new String[defs.size()];
int defIndex = 0; int defIndex = 0;
for (Structure def : defs) { for (Structure def : defs) {
@ -258,11 +258,11 @@ public class MeshHelper extends AbstractBlenderHelper {
} }
// reading materials // reading materials
MaterialHelper materialHelper = dataRepository.getHelper(MaterialHelper.class); MaterialHelper materialHelper = blenderContext.getHelper(MaterialHelper.class);
Material[] materials = null; Material[] materials = null;
Material[] nonTexturedMaterials = null; Material[] nonTexturedMaterials = null;
if ((dataRepository.getBlenderKey().getFeaturesToLoad() & FeaturesToLoad.MATERIALS) != 0) { if ((blenderContext.getBlenderKey().getFeaturesToLoad() & FeaturesToLoad.MATERIALS) != 0) {
materials = materialHelper.getMaterials(structure, dataRepository); materials = materialHelper.getMaterials(structure, blenderContext);
nonTexturedMaterials = materials == null ? null : new Material[materials.length];// fill it when needed nonTexturedMaterials = materials == null ? null : new Material[materials.length];// fill it when needed
} }
@ -292,7 +292,7 @@ public class MeshHelper extends AbstractBlenderHelper {
} }
//reading custom properties //reading custom properties
Properties properties = this.loadProperties(structure, dataRepository); Properties properties = this.loadProperties(structure, blenderContext);
// generating meshes // generating meshes
FloatBuffer verticesColorsBuffer = this.createFloatBuffer(verticesColors); FloatBuffer verticesColorsBuffer = this.createFloatBuffer(verticesColors);
@ -355,7 +355,7 @@ public class MeshHelper extends AbstractBlenderHelper {
geometry.setQueueBucket(Bucket.Transparent); geometry.setQueueBucket(Bucket.Transparent);
} }
} else { } else {
geometry.setMaterial(dataRepository.getDefaultMaterial()); geometry.setMaterial(blenderContext.getDefaultMaterial());
} }
if(properties != null && properties.getValue() != null) { if(properties != null && properties.getValue() != null) {
geometry.setUserData("properties", properties); geometry.setUserData("properties", properties);
@ -381,7 +381,7 @@ public class MeshHelper extends AbstractBlenderHelper {
} }
for(Entry<Material, List<Geometry>> entry : materialMap.entrySet()) { for(Entry<Material, List<Geometry>> entry : materialMap.entrySet()) {
MaterialContext materialContext = dataRepository.getMaterialContext(entry.getKey()); MaterialContext materialContext = blenderContext.getMaterialContext(entry.getKey());
if(materialContext != null && materialContext.getTexturesCount()>0) { if(materialContext != null && materialContext.getTexturesCount()>0) {
UVCoordinatesGenerator.generateUVCoordinates(materialContext.getUvCoordinatesType(), UVCoordinatesGenerator.generateUVCoordinates(materialContext.getUvCoordinatesType(),
materialContext.getProjectionType(), materialContext.getTextureDimension(), materialContext.getProjectionType(), materialContext.getTextureDimension(),
@ -390,7 +390,7 @@ public class MeshHelper extends AbstractBlenderHelper {
} }
} }
dataRepository.addLoadedFeatures(structure.getOldMemoryAddress(), structure.getName(), structure, geometries); blenderContext.addLoadedFeatures(structure.getOldMemoryAddress(), structure.getName(), structure, geometries);
return geometries; return geometries;
} }
@ -443,19 +443,19 @@ public class MeshHelper extends AbstractBlenderHelper {
* *
* @param meshStructure * @param meshStructure
* the structure containing the mesh data * the structure containing the mesh data
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @return a list of vertices colors, each color belongs to a single vertex * @return a list of vertices colors, each color belongs to a single vertex
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blend file structure is somehow invalid or corrupted * this exception is thrown when the blend file structure is somehow invalid or corrupted
*/ */
public List<float[]> getVerticesColors(Structure meshStructure, DataRepository dataRepository) throws BlenderFileException { public List<float[]> getVerticesColors(Structure meshStructure, BlenderContext blenderContext) throws BlenderFileException {
Pointer pMCol = (Pointer) meshStructure.getFieldValue("mcol"); Pointer pMCol = (Pointer) meshStructure.getFieldValue("mcol");
List<float[]> verticesColors = null; List<float[]> verticesColors = null;
List<Structure> mCol = null; List<Structure> mCol = null;
if (pMCol.isNotNull()) { if (pMCol.isNotNull()) {
verticesColors = new LinkedList<float[]>(); verticesColors = new LinkedList<float[]>();
mCol = pMCol.fetchData(dataRepository.getInputStream()); mCol = pMCol.fetchData(blenderContext.getInputStream());
for (Structure color : mCol) { for (Structure color : mCol) {
float r = ((Number) color.getFieldValue("r")).byteValue() / 256.0f; float r = ((Number) color.getFieldValue("r")).byteValue() / 256.0f;
float g = ((Number) color.getFieldValue("g")).byteValue() / 256.0f; float g = ((Number) color.getFieldValue("g")).byteValue() / 256.0f;
@ -472,14 +472,14 @@ public class MeshHelper extends AbstractBlenderHelper {
* *
* @param meshStructure * @param meshStructure
* the structure containing the mesh data * the structure containing the mesh data
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @return a list of vertices colors, each color belongs to a single vertex * @return a list of vertices colors, each color belongs to a single vertex
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blend file structure is somehow invalid or corrupted * this exception is thrown when the blend file structure is somehow invalid or corrupted
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Vector3f[] getVertices(Structure meshStructure, DataRepository dataRepository) throws BlenderFileException { public Vector3f[] getVertices(Structure meshStructure, BlenderContext blenderContext) throws BlenderFileException {
int verticesAmount = ((Number) meshStructure.getFieldValue("totvert")).intValue(); int verticesAmount = ((Number) meshStructure.getFieldValue("totvert")).intValue();
Vector3f[] vertices = new Vector3f[verticesAmount]; Vector3f[] vertices = new Vector3f[verticesAmount];
if (verticesAmount == 0) { if (verticesAmount == 0) {
@ -487,7 +487,7 @@ public class MeshHelper extends AbstractBlenderHelper {
} }
Pointer pMVert = (Pointer) meshStructure.getFieldValue("mvert"); Pointer pMVert = (Pointer) meshStructure.getFieldValue("mvert");
List<Structure> mVerts = pMVert.fetchData(dataRepository.getInputStream()); List<Structure> mVerts = pMVert.fetchData(blenderContext.getInputStream());
for (int i = 0; i < verticesAmount; ++i) { for (int i = 0; i < verticesAmount; ++i) {
DynamicArray<Number> coordinates = (DynamicArray<Number>) mVerts.get(i).getFieldValue("co"); DynamicArray<Number> coordinates = (DynamicArray<Number>) mVerts.get(i).getFieldValue("co");
vertices[i] = new Vector3f(coordinates.get(0).floatValue(), coordinates.get(1).floatValue(), coordinates.get(2).floatValue()); vertices[i] = new Vector3f(coordinates.get(0).floatValue(), coordinates.get(1).floatValue(), coordinates.get(2).floatValue());
@ -496,7 +496,7 @@ public class MeshHelper extends AbstractBlenderHelper {
} }
@Override @Override
public boolean shouldBeLoaded(Structure structure, DataRepository dataRepository) { public boolean shouldBeLoaded(Structure structure, BlenderContext blenderContext) {
return true; return true;
} }

@ -23,8 +23,8 @@ import com.jme3.scene.VertexBuffer;
import com.jme3.scene.VertexBuffer.Format; import com.jme3.scene.VertexBuffer.Format;
import com.jme3.scene.VertexBuffer.Type; import com.jme3.scene.VertexBuffer.Type;
import com.jme3.scene.VertexBuffer.Usage; import com.jme3.scene.VertexBuffer.Usage;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.DataRepository.LoadedFeatureDataType; import com.jme3.scene.plugins.blender.BlenderContext.LoadedFeatureDataType;
import com.jme3.scene.plugins.blender.animations.ArmatureHelper; import com.jme3.scene.plugins.blender.animations.ArmatureHelper;
import com.jme3.scene.plugins.blender.animations.ArmatureHelper.BoneTransformationData; import com.jme3.scene.plugins.blender.animations.ArmatureHelper.BoneTransformationData;
import com.jme3.scene.plugins.blender.constraints.Constraint; import com.jme3.scene.plugins.blender.constraints.Constraint;
@ -73,28 +73,28 @@ import com.jme3.util.BufferUtils;
* the structure of the object * the structure of the object
* @param modifierStructure * @param modifierStructure
* the structure of the modifier * the structure of the modifier
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blender file is somehow * this exception is thrown when the blender file is somehow
* corrupted * corrupted
*/ */
public ArmatureModifier(Structure objectStructure, Structure modifierStructure, DataRepository dataRepository) throws BlenderFileException { public ArmatureModifier(Structure objectStructure, Structure modifierStructure, BlenderContext blenderContext) throws BlenderFileException {
Pointer pArmatureObject = (Pointer) modifierStructure.getFieldValue("object"); Pointer pArmatureObject = (Pointer) modifierStructure.getFieldValue("object");
if (pArmatureObject.isNotNull()) { if (pArmatureObject.isNotNull()) {
ObjectHelper objectHelper = dataRepository.getHelper(ObjectHelper.class); ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class);
ArmatureHelper armatureHelper = dataRepository.getHelper(ArmatureHelper.class); ArmatureHelper armatureHelper = blenderContext.getHelper(ArmatureHelper.class);
Structure armatureObject = pArmatureObject.fetchData(dataRepository.getInputStream()).get(0); Structure armatureObject = pArmatureObject.fetchData(blenderContext.getInputStream()).get(0);
this.armatureObjectOMA = armatureObject.getOldMemoryAddress(); this.armatureObjectOMA = armatureObject.getOldMemoryAddress();
//read skeleton //read skeleton
// changing bones matrices so that they fit the current object // changing bones matrices so that they fit the current object
Structure armatureStructure = ((Pointer)armatureObject.getFieldValue("data")).fetchData(dataRepository.getInputStream()).get(0); Structure armatureStructure = ((Pointer)armatureObject.getFieldValue("data")).fetchData(blenderContext.getInputStream()).get(0);
Structure bonebase = (Structure) armatureStructure.getFieldValue("bonebase"); Structure bonebase = (Structure) armatureStructure.getFieldValue("bonebase");
List<Structure> bonesStructures = bonebase.evaluateListBase(dataRepository); List<Structure> bonesStructures = bonebase.evaluateListBase(blenderContext);
for (Structure boneStructure : bonesStructures) { for (Structure boneStructure : bonesStructures) {
BoneTransformationData rootBoneTransformationData = armatureHelper.readBoneAndItsChildren(boneStructure, null, dataRepository); BoneTransformationData rootBoneTransformationData = armatureHelper.readBoneAndItsChildren(boneStructure, null, blenderContext);
armatureHelper.addBoneDataRoot(rootBoneTransformationData); armatureHelper.addBoneDataRoot(rootBoneTransformationData);
} }
Matrix4f armatureObjectMatrix = objectHelper.getTransformationMatrix(armatureObject); Matrix4f armatureObjectMatrix = objectHelper.getTransformationMatrix(armatureObject);
@ -103,26 +103,26 @@ import com.jme3.util.BufferUtils;
Bone[] bones = armatureHelper.buildBonesStructure(Long.valueOf(0L), additionalRootBoneTransformation); Bone[] bones = armatureHelper.buildBonesStructure(Long.valueOf(0L), additionalRootBoneTransformation);
//read mesh indexes //read mesh indexes
Structure meshStructure = ((Pointer)objectStructure.getFieldValue("data")).fetchData(dataRepository.getInputStream()).get(0); Structure meshStructure = ((Pointer)objectStructure.getFieldValue("data")).fetchData(blenderContext.getInputStream()).get(0);
this.meshOMA = meshStructure.getOldMemoryAddress(); this.meshOMA = meshStructure.getOldMemoryAddress();
this.readVerticesWeightsData(objectStructure, meshStructure, dataRepository); this.readVerticesWeightsData(objectStructure, meshStructure, blenderContext);
//read animations //read animations
String objectName = objectStructure.getName(); String objectName = objectStructure.getName();
Set<String> animationNames = dataRepository.getBlenderKey().getAnimationNames(objectName); Set<String> animationNames = blenderContext.getBlenderKey().getAnimationNames(objectName);
if (animationNames != null && animationNames.size() > 0) { if (animationNames != null && animationNames.size() > 0) {
ArrayList<Animation> animations = new ArrayList<Animation>(); ArrayList<Animation> animations = new ArrayList<Animation>();
List<FileBlockHeader> actionHeaders = dataRepository.getFileBlocks(Integer.valueOf(FileBlockHeader.BLOCK_AC00)); List<FileBlockHeader> actionHeaders = blenderContext.getFileBlocks(Integer.valueOf(FileBlockHeader.BLOCK_AC00));
for (FileBlockHeader header : actionHeaders) { for (FileBlockHeader header : actionHeaders) {
Structure actionStructure = header.getStructure(dataRepository); Structure actionStructure = header.getStructure(blenderContext);
String actionName = actionStructure.getName(); String actionName = actionStructure.getName();
if (animationNames.contains(actionName)) { if (animationNames.contains(actionName)) {
int[] animationFrames = dataRepository.getBlenderKey().getAnimationFrames(objectName, actionName); int[] animationFrames = blenderContext.getBlenderKey().getAnimationFrames(objectName, actionName);
int fps = dataRepository.getBlenderKey().getFps(); int fps = blenderContext.getBlenderKey().getFps();
float start = (float) animationFrames[0] / (float) fps; float start = (float) animationFrames[0] / (float) fps;
float stop = (float) animationFrames[1] / (float) fps; float stop = (float) animationFrames[1] / (float) fps;
BoneAnimation boneAnimation = new BoneAnimation(actionName, stop - start); BoneAnimation boneAnimation = new BoneAnimation(actionName, stop - start);
boneAnimation.setTracks(armatureHelper.getTracks(actionStructure, dataRepository, objectName, actionName)); boneAnimation.setTracks(armatureHelper.getTracks(actionStructure, blenderContext, objectName, actionName));
animations.add(boneAnimation); animations.add(boneAnimation);
} }
} }
@ -133,13 +133,13 @@ import com.jme3.util.BufferUtils;
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Node apply(Node node, DataRepository dataRepository) { public Node apply(Node node, BlenderContext blenderContext) {
if(animData == null) { if(animData == null) {
return node; return node;
} }
// setting weights for bones // setting weights for bones
List<Geometry> geomList = (List<Geometry>) dataRepository.getLoadedFeature(this.meshOMA, LoadedFeatureDataType.LOADED_FEATURE); List<Geometry> geomList = (List<Geometry>) blenderContext.getLoadedFeature(this.meshOMA, LoadedFeatureDataType.LOADED_FEATURE);
for(Geometry geom : geomList) { for(Geometry geom : geomList) {
Mesh mesh = geom.getMesh(); Mesh mesh = geom.getMesh();
if (this.verticesWeights != null) { if (this.verticesWeights != null) {
@ -151,7 +151,7 @@ import com.jme3.util.BufferUtils;
ArrayList<Animation> animList = animData.anims; ArrayList<Animation> animList = animData.anims;
if (animList != null && animList.size() > 0) { if (animList != null && animList.size() > 0) {
List<Constraint> constraints = dataRepository.getConstraints(this.armatureObjectOMA); List<Constraint> constraints = blenderContext.getConstraints(this.armatureObjectOMA);
HashMap<String, Animation> anims = new HashMap<String, Animation>(); HashMap<String, Animation> anims = new HashMap<String, Animation>();
for (int i = 0; i < animList.size(); ++i) { for (int i = 0; i < animList.size(); ++i) {
BoneAnimation boneAnimation = (BoneAnimation) animList.get(i).clone(); BoneAnimation boneAnimation = (BoneAnimation) animList.get(i).clone();
@ -194,21 +194,21 @@ import com.jme3.util.BufferUtils;
* This method reads mesh indexes * This method reads mesh indexes
* @param objectStructure structure of the object that has the armature modifier applied * @param objectStructure structure of the object that has the armature modifier applied
* @param meshStructure the structure of the object's mesh * @param meshStructure the structure of the object's mesh
* @param dataRepository the data repository * @param blenderContext the blender context
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blend file structure is somehow invalid or corrupted * this exception is thrown when the blend file structure is somehow invalid or corrupted
*/ */
private void readVerticesWeightsData(Structure objectStructure, Structure meshStructure, DataRepository dataRepository) throws BlenderFileException { private void readVerticesWeightsData(Structure objectStructure, Structure meshStructure, BlenderContext blenderContext) throws BlenderFileException {
ArmatureHelper armatureHelper = dataRepository.getHelper(ArmatureHelper.class); ArmatureHelper armatureHelper = blenderContext.getHelper(ArmatureHelper.class);
Structure defBase = (Structure) objectStructure.getFieldValue("defbase"); Structure defBase = (Structure) objectStructure.getFieldValue("defbase");
Map<Integer, Integer> groupToBoneIndexMap = armatureHelper.getGroupToBoneIndexMap(defBase, dataRepository); Map<Integer, Integer> groupToBoneIndexMap = armatureHelper.getGroupToBoneIndexMap(defBase, blenderContext);
int[] bonesGroups = new int[] { 0 }; int[] bonesGroups = new int[] { 0 };
VertexData vertexData = dataRepository.getVertexData(meshStructure.getOldMemoryAddress()); VertexData vertexData = blenderContext.getVertexData(meshStructure.getOldMemoryAddress());
VertexBuffer[] boneWeightsAndIndex = this.getBoneWeightAndIndexBuffer(meshStructure, vertexData.getVertexList().size(), bonesGroups, VertexBuffer[] boneWeightsAndIndex = this.getBoneWeightAndIndexBuffer(meshStructure, vertexData.getVertexList().size(), bonesGroups,
vertexData.getVertexReferenceMap(), groupToBoneIndexMap, dataRepository); vertexData.getVertexReferenceMap(), groupToBoneIndexMap, blenderContext);
this.verticesWeights = boneWeightsAndIndex[0]; this.verticesWeights = boneWeightsAndIndex[0];
this.verticesWeightsIndices = boneWeightsAndIndex[1]; this.verticesWeightsIndices = boneWeightsAndIndex[1];
this.boneGroups = bonesGroups[0]; this.boneGroups = bonesGroups[0];
@ -230,20 +230,20 @@ import com.jme3.util.BufferUtils;
* vertex may appear several times in the result model * vertex may appear several times in the result model
* @param groupToBoneIndexMap * @param groupToBoneIndexMap
* this object maps the group index (to which a vertices in blender belong) to bone index of the model * this object maps the group index (to which a vertices in blender belong) to bone index of the model
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @return arrays of vertices weights and their bone indices and (as an output parameter) the maximum amount of weights for a vertex * @return arrays of vertices weights and their bone indices and (as an output parameter) the maximum amount of weights for a vertex
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blend file structure is somehow invalid or corrupted * this exception is thrown when the blend file structure is somehow invalid or corrupted
*/ */
private VertexBuffer[] getBoneWeightAndIndexBuffer(Structure meshStructure, int vertexListSize, int[] bonesGroups, private VertexBuffer[] getBoneWeightAndIndexBuffer(Structure meshStructure, int vertexListSize, int[] bonesGroups,
Map<Integer, List<Integer>> vertexReferenceMap, Map<Integer, Integer> groupToBoneIndexMap, DataRepository dataRepository) Map<Integer, List<Integer>> vertexReferenceMap, Map<Integer, Integer> groupToBoneIndexMap, BlenderContext blenderContext)
throws BlenderFileException { throws BlenderFileException {
Pointer pDvert = (Pointer) meshStructure.getFieldValue("dvert");// dvert = DeformVERTices Pointer pDvert = (Pointer) meshStructure.getFieldValue("dvert");// dvert = DeformVERTices
FloatBuffer weightsFloatData = BufferUtils.createFloatBuffer(vertexListSize * MAXIMUM_WEIGHTS_PER_VERTEX); FloatBuffer weightsFloatData = BufferUtils.createFloatBuffer(vertexListSize * MAXIMUM_WEIGHTS_PER_VERTEX);
ByteBuffer indicesData = BufferUtils.createByteBuffer(vertexListSize * MAXIMUM_WEIGHTS_PER_VERTEX); ByteBuffer indicesData = BufferUtils.createByteBuffer(vertexListSize * MAXIMUM_WEIGHTS_PER_VERTEX);
if (pDvert.isNotNull()) {// assigning weights and bone indices if (pDvert.isNotNull()) {// assigning weights and bone indices
List<Structure> dverts = pDvert.fetchData(dataRepository.getInputStream());// dverts.size() == verticesAmount (one dvert per List<Structure> dverts = pDvert.fetchData(blenderContext.getInputStream());// dverts.size() == verticesAmount (one dvert per
// vertex in blender) // vertex in blender)
int vertexIndex = 0; int vertexIndex = 0;
for (Structure dvert : dverts) { for (Structure dvert : dverts) {
@ -253,7 +253,7 @@ import com.jme3.util.BufferUtils;
List<Integer> vertexIndices = vertexReferenceMap.get(Integer.valueOf(vertexIndex));// we fetch the referenced vertices here List<Integer> vertexIndices = vertexReferenceMap.get(Integer.valueOf(vertexIndex));// we fetch the referenced vertices here
if (totweight > 0 && pDW.isNotNull() && groupToBoneIndexMap!=null) {// pDW should never be null here, but I check it just in case :) if (totweight > 0 && pDW.isNotNull() && groupToBoneIndexMap!=null) {// pDW should never be null here, but I check it just in case :)
int weightIndex = 0; int weightIndex = 0;
List<Structure> dw = pDW.fetchData(dataRepository.getInputStream()); List<Structure> dw = pDW.fetchData(blenderContext.getInputStream());
for (Structure deformWeight : dw) { for (Structure deformWeight : dw) {
Integer boneIndex = groupToBoneIndexMap.get(((Number) deformWeight.getFieldValue("def_nr")).intValue()); Integer boneIndex = groupToBoneIndexMap.get(((Number) deformWeight.getFieldValue("def_nr")).intValue());
if (boneIndex != null) {// null here means that we came accross group that has no bone attached to if (boneIndex != null) {// null here means that we came accross group that has no bone attached to

@ -15,8 +15,8 @@ import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh; import com.jme3.scene.Mesh;
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.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.DataRepository.LoadedFeatureDataType; import com.jme3.scene.plugins.blender.BlenderContext.LoadedFeatureDataType;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.DynamicArray; import com.jme3.scene.plugins.blender.file.DynamicArray;
import com.jme3.scene.plugins.blender.file.FileBlockHeader; import com.jme3.scene.plugins.blender.file.FileBlockHeader;
@ -45,14 +45,14 @@ import com.jme3.scene.shape.Curve;
* the structure of the object * the structure of the object
* @param modifierStructure * @param modifierStructure
* the structure of the modifier * the structure of the modifier
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blender file is somehow * this exception is thrown when the blender file is somehow
* corrupted * corrupted
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public ArrayModifier(Structure modifier, DataRepository dataRepository) throws BlenderFileException { public ArrayModifier(Structure modifier, BlenderContext blenderContext) throws BlenderFileException {
Number fittype = (Number) modifier.getFieldValue("fit_type"); Number fittype = (Number) modifier.getFieldValue("fit_type");
modifierData.put("fittype", fittype); modifierData.put("fittype", fittype);
switch (fittype.intValue()) { switch (fittype.intValue()) {
@ -66,9 +66,9 @@ import com.jme3.scene.shape.Curve;
Pointer pCurveOb = (Pointer) modifier.getFieldValue("curve_ob"); Pointer pCurveOb = (Pointer) modifier.getFieldValue("curve_ob");
float length = 0; float length = 0;
if (pCurveOb.isNotNull()) { if (pCurveOb.isNotNull()) {
Structure curveStructure = pCurveOb.fetchData(dataRepository.getInputStream()).get(0); Structure curveStructure = pCurveOb.fetchData(blenderContext.getInputStream()).get(0);
ObjectHelper objectHelper = dataRepository.getHelper(ObjectHelper.class); ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class);
Node curveObject = (Node) objectHelper.toObject(curveStructure, dataRepository); Node curveObject = (Node) objectHelper.toObject(curveStructure, blenderContext);
Set<Number> referencesToCurveLengths = new HashSet<Number>(curveObject.getChildren().size()); Set<Number> referencesToCurveLengths = new HashSet<Number>(curveObject.getChildren().size());
for (Spatial spatial : curveObject.getChildren()) { for (Spatial spatial : curveObject.getChildren()) {
if (spatial instanceof Geometry) { if (spatial instanceof Geometry) {
@ -125,7 +125,7 @@ import com.jme3.scene.shape.Curve;
} }
@Override @Override
public Node apply(Node node, DataRepository dataRepository) { public Node apply(Node node, BlenderContext blenderContext) {
int fittype = ((Number) modifierData.get("fittype")).intValue(); int fittype = ((Number) modifierData.get("fittype")).intValue();
float[] offset = (float[]) modifierData.get("offset"); float[] offset = (float[]) modifierData.get("offset");
if (offset == null) {// the node will be repeated several times in the same place if (offset == null) {// the node will be repeated several times in the same place
@ -156,11 +156,11 @@ import com.jme3.scene.shape.Curve;
float[] objectOffset = new float[]{0.0f, 0.0f, 0.0f}; float[] objectOffset = new float[]{0.0f, 0.0f, 0.0f};
Pointer pOffsetObject = (Pointer) modifierData.get("offsetob"); Pointer pOffsetObject = (Pointer) modifierData.get("offsetob");
if (pOffsetObject != null) { if (pOffsetObject != null) {
FileBlockHeader offsetObjectBlock = dataRepository.getFileBlock(pOffsetObject.getOldMemoryAddress()); FileBlockHeader offsetObjectBlock = blenderContext.getFileBlock(pOffsetObject.getOldMemoryAddress());
ObjectHelper objectHelper = dataRepository.getHelper(ObjectHelper.class); ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class);
try {// we take the structure in case the object was not yet loaded try {// we take the structure in case the object was not yet loaded
Structure offsetStructure = offsetObjectBlock.getStructure(dataRepository); Structure offsetStructure = offsetObjectBlock.getStructure(blenderContext);
Vector3f translation = objectHelper.getTransformation(offsetStructure, dataRepository).getTranslation(); Vector3f translation = objectHelper.getTransformation(offsetStructure, blenderContext).getTranslation();
objectOffset[0] = translation.x; objectOffset[0] = translation.x;
objectOffset[1] = translation.y; objectOffset[1] = translation.y;
objectOffset[2] = translation.z; objectOffset[2] = translation.z;
@ -174,15 +174,15 @@ import com.jme3.scene.shape.Curve;
Pointer[] pCaps = new Pointer[]{(Pointer) modifierData.get("startcap"), (Pointer) modifierData.get("endcap")}; Pointer[] pCaps = new Pointer[]{(Pointer) modifierData.get("startcap"), (Pointer) modifierData.get("endcap")};
for (int i = 0; i < pCaps.length; ++i) { for (int i = 0; i < pCaps.length; ++i) {
if (pCaps[i] != null) { if (pCaps[i] != null) {
caps[i] = (Node) dataRepository.getLoadedFeature(pCaps[i].getOldMemoryAddress(), LoadedFeatureDataType.LOADED_FEATURE); caps[i] = (Node) blenderContext.getLoadedFeature(pCaps[i].getOldMemoryAddress(), LoadedFeatureDataType.LOADED_FEATURE);
if (caps[i] != null) { if (caps[i] != null) {
caps[i] = (Node) caps[i].clone(); caps[i] = (Node) caps[i].clone();
} else { } else {
FileBlockHeader capBlock = dataRepository.getFileBlock(pOffsetObject.getOldMemoryAddress()); FileBlockHeader capBlock = blenderContext.getFileBlock(pOffsetObject.getOldMemoryAddress());
try {// we take the structure in case the object was not yet loaded try {// we take the structure in case the object was not yet loaded
Structure capStructure = capBlock.getStructure(dataRepository); Structure capStructure = capBlock.getStructure(blenderContext);
ObjectHelper objectHelper = dataRepository.getHelper(ObjectHelper.class); ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class);
caps[i] = (Node) objectHelper.toObject(capStructure, dataRepository); caps[i] = (Node) objectHelper.toObject(capStructure, blenderContext);
if (caps[i] == null) { if (caps[i] == null) {
LOGGER.log(Level.WARNING, "Cap object ''{0}'' couldn''t be loaded!", capStructure.getName()); LOGGER.log(Level.WARNING, "Cap object ''{0}'' couldn''t be loaded!", capStructure.getName());
} }

@ -15,7 +15,7 @@ import com.jme3.scene.Mesh;
import com.jme3.scene.Node; import com.jme3.scene.Node;
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
import com.jme3.scene.VertexBuffer.Type; import com.jme3.scene.VertexBuffer.Type;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.Pointer; import com.jme3.scene.plugins.blender.file.Pointer;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
@ -42,13 +42,13 @@ import com.jme3.scene.plugins.blender.objects.ObjectHelper;
* the structure of the object * the structure of the object
* @param modifierStructure * @param modifierStructure
* the structure of the modifier * the structure of the modifier
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blender file is somehow * this exception is thrown when the blender file is somehow
* corrupted * corrupted
*/ */
public MirrorModifier(Structure modifier, DataRepository dataRepository) { public MirrorModifier(Structure modifier, BlenderContext blenderContext) {
modifierData.put("flag", modifier.getFieldValue("flag")); modifierData.put("flag", modifier.getFieldValue("flag"));
modifierData.put("tolerance", modifier.getFieldValue("tolerance")); modifierData.put("tolerance", modifier.getFieldValue("tolerance"));
Pointer pMirrorOb = (Pointer) modifier.getFieldValue("mirror_ob"); Pointer pMirrorOb = (Pointer) modifier.getFieldValue("mirror_ob");
@ -58,7 +58,7 @@ import com.jme3.scene.plugins.blender.objects.ObjectHelper;
} }
@Override @Override
public Node apply(Node node, DataRepository dataRepository) { public Node apply(Node node, BlenderContext blenderContext) {
int flag = ((Number) modifierData.get("flag")).intValue(); int flag = ((Number) modifierData.get("flag")).intValue();
float[] mirrorFactor = new float[]{ float[] mirrorFactor = new float[]{
(flag & 0x08) != 0 ? -1.0f : 1.0f, (flag & 0x08) != 0 ? -1.0f : 1.0f,
@ -70,9 +70,9 @@ import com.jme3.scene.plugins.blender.objects.ObjectHelper;
if (pObject != null) { if (pObject != null) {
Structure objectStructure; Structure objectStructure;
try { try {
objectStructure = pObject.fetchData(dataRepository.getInputStream()).get(0); objectStructure = pObject.fetchData(blenderContext.getInputStream()).get(0);
ObjectHelper objectHelper = dataRepository.getHelper(ObjectHelper.class); ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class);
Node object = (Node) objectHelper.toObject(objectStructure, dataRepository); Node object = (Node) objectHelper.toObject(objectStructure, blenderContext);
if (object != null) { if (object != null) {
Vector3f translation = object.getWorldTranslation(); Vector3f translation = object.getWorldTranslation();
center[0] = translation.x; center[0] = translation.x;

@ -1,7 +1,7 @@
package com.jme3.scene.plugins.blender.modifiers; package com.jme3.scene.plugins.blender.modifiers;
import com.jme3.scene.Node; import com.jme3.scene.Node;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
/** /**
* This class represents an object's modifier. The modifier object can be varied * This class represents an object's modifier. The modifier object can be varied
@ -24,11 +24,11 @@ public abstract class Modifier {
* *
* @param node * @param node
* the node that will have modifier applied * the node that will have modifier applied
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @return the node with applied modifier * @return the node with applied modifier
*/ */
public abstract Node apply(Node node, DataRepository dataRepository); public abstract Node apply(Node node, BlenderContext blenderContext);
/** /**
* This method returns blender's type of modifier. * This method returns blender's type of modifier.

@ -38,7 +38,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import com.jme3.scene.plugins.blender.AbstractBlenderHelper; import com.jme3.scene.plugins.blender.AbstractBlenderHelper;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.Pointer; import com.jme3.scene.plugins.blender.file.Pointer;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
@ -65,32 +65,32 @@ public class ModifierHelper extends AbstractBlenderHelper {
* This method reads the given object's modifiers. * This method reads the given object's modifiers.
* @param objectStructure * @param objectStructure
* the object structure * the object structure
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @param converter * @param converter
* the converter object (in some cases we need to read an object first before loading the modifier) * the converter object (in some cases we need to read an object first before loading the modifier)
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blender file is somehow corrupted * this exception is thrown when the blender file is somehow corrupted
*/ */
public Collection<Modifier> readModifiers(Structure objectStructure, DataRepository dataRepository) throws BlenderFileException { public Collection<Modifier> readModifiers(Structure objectStructure, BlenderContext blenderContext) throws BlenderFileException {
Collection<Modifier> result = new ArrayList<Modifier>(); Collection<Modifier> result = new ArrayList<Modifier>();
Structure modifiersListBase = (Structure) objectStructure.getFieldValue("modifiers"); Structure modifiersListBase = (Structure) objectStructure.getFieldValue("modifiers");
List<Structure> modifiers = modifiersListBase.evaluateListBase(dataRepository); List<Structure> modifiers = modifiersListBase.evaluateListBase(blenderContext);
for (Structure modifierStructure : modifiers) { for (Structure modifierStructure : modifiers) {
Modifier modifier = null; Modifier modifier = null;
if (Modifier.ARRAY_MODIFIER_DATA.equals(modifierStructure.getType())) { if (Modifier.ARRAY_MODIFIER_DATA.equals(modifierStructure.getType())) {
modifier = new ArrayModifier(modifierStructure, dataRepository); modifier = new ArrayModifier(modifierStructure, blenderContext);
} else if (Modifier.MIRROR_MODIFIER_DATA.equals(modifierStructure.getType())) { } else if (Modifier.MIRROR_MODIFIER_DATA.equals(modifierStructure.getType())) {
modifier = new MirrorModifier(modifierStructure, dataRepository); modifier = new MirrorModifier(modifierStructure, blenderContext);
} else if (Modifier.ARMATURE_MODIFIER_DATA.equals(modifierStructure.getType())) { } else if (Modifier.ARMATURE_MODIFIER_DATA.equals(modifierStructure.getType())) {
modifier = new ArmatureModifier(objectStructure, modifierStructure, dataRepository); modifier = new ArmatureModifier(objectStructure, modifierStructure, blenderContext);
} else if (Modifier.PARTICLE_MODIFIER_DATA.equals(modifierStructure.getType())) { } else if (Modifier.PARTICLE_MODIFIER_DATA.equals(modifierStructure.getType())) {
modifier = new ParticlesModifier(modifierStructure, dataRepository); modifier = new ParticlesModifier(modifierStructure, blenderContext);
} }
if(modifier != null) { if(modifier != null) {
result.add(modifier); result.add(modifier);
dataRepository.addModifier(objectStructure.getOldMemoryAddress(), modifier); blenderContext.addModifier(objectStructure.getOldMemoryAddress(), modifier);
} else { } else {
LOGGER.log(Level.WARNING, "Unsupported modifier type: {0}", modifierStructure.getType()); LOGGER.log(Level.WARNING, "Unsupported modifier type: {0}", modifierStructure.getType());
} }
@ -99,15 +99,15 @@ public class ModifierHelper extends AbstractBlenderHelper {
//at the end read object's animation modifier //at the end read object's animation modifier
Pointer pIpo = (Pointer) objectStructure.getFieldValue("ipo"); Pointer pIpo = (Pointer) objectStructure.getFieldValue("ipo");
if (pIpo.isNotNull()) { if (pIpo.isNotNull()) {
Modifier modifier = new ObjectAnimationModifier(objectStructure, dataRepository); Modifier modifier = new ObjectAnimationModifier(objectStructure, blenderContext);
result.add(modifier); result.add(modifier);
dataRepository.addModifier(objectStructure.getOldMemoryAddress(), modifier); blenderContext.addModifier(objectStructure.getOldMemoryAddress(), modifier);
} }
return result; return result;
} }
@Override @Override
public boolean shouldBeLoaded(Structure structure, DataRepository dataRepository) { public boolean shouldBeLoaded(Structure structure, BlenderContext blenderContext) {
return true; return true;
} }
} }

@ -11,7 +11,7 @@ import com.jme3.animation.BoneTrack;
import com.jme3.animation.Skeleton; import com.jme3.animation.Skeleton;
import com.jme3.math.Transform; import com.jme3.math.Transform;
import com.jme3.scene.Node; import com.jme3.scene.Node;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.animations.Ipo; import com.jme3.scene.plugins.blender.animations.Ipo;
import com.jme3.scene.plugins.blender.animations.IpoHelper; import com.jme3.scene.plugins.blender.animations.IpoHelper;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
@ -44,24 +44,24 @@ import com.jme3.scene.plugins.ogre.AnimData;
* *
* @param objectStructure * @param objectStructure
* the structure of the object * the structure of the object
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @return animation modifier is returned, it should be separately applied * @return animation modifier is returned, it should be separately applied
* when the object is loaded * when the object is loaded
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blender file is somehow * this exception is thrown when the blender file is somehow
* corrupted * corrupted
*/ */
public ObjectAnimationModifier(Structure objectStructure, DataRepository dataRepository) throws BlenderFileException { public ObjectAnimationModifier(Structure objectStructure, BlenderContext blenderContext) throws BlenderFileException {
Pointer pIpo = (Pointer) objectStructure.getFieldValue("ipo"); Pointer pIpo = (Pointer) objectStructure.getFieldValue("ipo");
if (pIpo.isNotNull()) { if (pIpo.isNotNull()) {
// check if there is an action name connected with this ipo // check if there is an action name connected with this ipo
String objectAnimationName = null; String objectAnimationName = null;
List<FileBlockHeader> actionBlocks = dataRepository List<FileBlockHeader> actionBlocks = blenderContext
.getFileBlocks(Integer.valueOf(FileBlockHeader.BLOCK_AC00)); .getFileBlocks(Integer.valueOf(FileBlockHeader.BLOCK_AC00));
for (FileBlockHeader actionBlock : actionBlocks) { for (FileBlockHeader actionBlock : actionBlocks) {
Structure action = actionBlock.getStructure(dataRepository); Structure action = actionBlock.getStructure(blenderContext);
List<Structure> actionChannels = ((Structure) action.getFieldValue("chanbase")).evaluateListBase(dataRepository); List<Structure> actionChannels = ((Structure) action.getFieldValue("chanbase")).evaluateListBase(blenderContext);
if (actionChannels.size() == 1) {// object's animtion action has only one channel if (actionChannels.size() == 1) {// object's animtion action has only one channel
Pointer pChannelIpo = (Pointer) actionChannels.get(0).getFieldValue("ipo"); Pointer pChannelIpo = (Pointer) actionChannels.get(0).getFieldValue("ipo");
if (pChannelIpo.equals(pIpo)) { if (pChannelIpo.equals(pIpo)) {
@ -76,14 +76,14 @@ import com.jme3.scene.plugins.ogre.AnimData;
objectAnimationName = objectName; objectAnimationName = objectName;
} }
IpoHelper ipoHelper = dataRepository.getHelper(IpoHelper.class); IpoHelper ipoHelper = blenderContext.getHelper(IpoHelper.class);
Structure ipoStructure = pIpo.fetchData(dataRepository.getInputStream()).get(0); Structure ipoStructure = pIpo.fetchData(blenderContext.getInputStream()).get(0);
Ipo ipo = ipoHelper.createIpo(ipoStructure, dataRepository); Ipo ipo = ipoHelper.createIpo(ipoStructure, blenderContext);
int[] animationFrames = dataRepository.getBlenderKey().getAnimationFrames(objectName, objectAnimationName); int[] animationFrames = blenderContext.getBlenderKey().getAnimationFrames(objectName, objectAnimationName);
if (animationFrames == null) {// if the name was created here there are no frames set for the animation if (animationFrames == null) {// if the name was created here there are no frames set for the animation
animationFrames = new int[] { 1, ipo.getLastFrame() }; animationFrames = new int[] { 1, ipo.getLastFrame() };
} }
int fps = dataRepository.getBlenderKey().getFps(); int fps = blenderContext.getBlenderKey().getFps();
float start = (float) animationFrames[0] / (float) fps; float start = (float) animationFrames[0] / (float) fps;
float stop = (float) animationFrames[1] / (float) fps; float stop = (float) animationFrames[1] / (float) fps;
@ -97,8 +97,8 @@ import com.jme3.scene.plugins.ogre.AnimData;
animations.add(boneAnimation); animations.add(boneAnimation);
// preparing the object's bone // preparing the object's bone
ObjectHelper objectHelper = dataRepository.getHelper(ObjectHelper.class); ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class);
Transform t = objectHelper.getTransformation(objectStructure, dataRepository); Transform t = objectHelper.getTransformation(objectStructure, blenderContext);
Bone bone = new Bone(null); Bone bone = new Bone(null);
bone.setBindTransforms(t.getTranslation(), t.getRotation(), t.getScale()); bone.setBindTransforms(t.getTranslation(), t.getRotation(), t.getScale());
@ -108,7 +108,7 @@ import com.jme3.scene.plugins.ogre.AnimData;
} }
@Override @Override
public Node apply(Node node, DataRepository dataRepository) { public Node apply(Node node, BlenderContext blenderContext) {
LOGGER.warning("Object animation modifier not yet implemented!"); LOGGER.warning("Object animation modifier not yet implemented!");
return null; return null;
} }

@ -11,7 +11,7 @@ import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh; import com.jme3.scene.Mesh;
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.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.Pointer; import com.jme3.scene.plugins.blender.file.Pointer;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
@ -32,25 +32,25 @@ import com.jme3.scene.plugins.blender.particles.ParticlesHelper;
* *
* @param modifier * @param modifier
* the structure of the modifier * the structure of the modifier
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @throws BlenderFileException * @throws BlenderFileException
* an exception is throw wneh there are problems with the * an exception is throw wneh there are problems with the
* blender file * blender file
*/ */
public ParticlesModifier(Structure modifier, DataRepository dataRepository) public ParticlesModifier(Structure modifier, BlenderContext blenderContext)
throws BlenderFileException { throws BlenderFileException {
Pointer pParticleSystem = (Pointer) modifier.getFieldValue("psys"); Pointer pParticleSystem = (Pointer) modifier.getFieldValue("psys");
if (pParticleSystem.isNotNull()) { if (pParticleSystem.isNotNull()) {
ParticlesHelper particlesHelper = dataRepository.getHelper(ParticlesHelper.class); ParticlesHelper particlesHelper = blenderContext.getHelper(ParticlesHelper.class);
Structure particleSystem = pParticleSystem.fetchData(dataRepository.getInputStream()).get(0); Structure particleSystem = pParticleSystem.fetchData(blenderContext.getInputStream()).get(0);
particleEmitter = particlesHelper.toParticleEmitter(particleSystem, dataRepository); particleEmitter = particlesHelper.toParticleEmitter(particleSystem, blenderContext);
} }
} }
@Override @Override
public Node apply(Node node, DataRepository dataRepository) { public Node apply(Node node, BlenderContext blenderContext) {
MaterialHelper materialHelper = dataRepository.getHelper(MaterialHelper.class); MaterialHelper materialHelper = blenderContext.getHelper(MaterialHelper.class);
ParticleEmitter emitter = particleEmitter.clone(); ParticleEmitter emitter = particleEmitter.clone();
// veryfying the alpha function for particles' texture // veryfying the alpha function for particles' texture
@ -71,7 +71,7 @@ import com.jme3.scene.plugins.blender.particles.ParticlesHelper;
if (mesh != null) { if (mesh != null) {
meshes.add(mesh); meshes.add(mesh);
Material material = materialHelper.getParticlesMaterial( Material material = materialHelper.getParticlesMaterial(
((Geometry) spatial).getMaterial(), alphaFunction, dataRepository); ((Geometry) spatial).getMaterial(), alphaFunction, blenderContext);
emitter.setMaterial(material);// TODO: divide into several pieces emitter.setMaterial(material);// TODO: divide into several pieces
} }
} }

@ -53,8 +53,8 @@ import com.jme3.scene.Node;
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
import com.jme3.scene.Spatial.CullHint; import com.jme3.scene.Spatial.CullHint;
import com.jme3.scene.plugins.blender.AbstractBlenderHelper; import com.jme3.scene.plugins.blender.AbstractBlenderHelper;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.DataRepository.LoadedFeatureDataType; import com.jme3.scene.plugins.blender.BlenderContext.LoadedFeatureDataType;
import com.jme3.scene.plugins.blender.cameras.CameraHelper; import com.jme3.scene.plugins.blender.cameras.CameraHelper;
import com.jme3.scene.plugins.blender.constraints.ConstraintHelper; import com.jme3.scene.plugins.blender.constraints.ConstraintHelper;
import com.jme3.scene.plugins.blender.curves.CurvesHelper; import com.jme3.scene.plugins.blender.curves.CurvesHelper;
@ -127,20 +127,20 @@ public class ObjectHelper extends AbstractBlenderHelper {
* This method reads the given structure and createn an object that represents the data. * This method reads the given structure and createn an object that represents the data.
* @param objectStructure * @param objectStructure
* the object's structure * the object's structure
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @return blener's object representation * @return blener's object representation
* @throws BlenderFileException * @throws BlenderFileException
* an exception is thrown when the given data is inapropriate * an exception is thrown when the given data is inapropriate
*/ */
public Object toObject(Structure objectStructure, DataRepository dataRepository) throws BlenderFileException { public Object toObject(Structure objectStructure, BlenderContext blenderContext) throws BlenderFileException {
Object loadedResult = dataRepository.getLoadedFeature(objectStructure.getOldMemoryAddress(), LoadedFeatureDataType.LOADED_FEATURE); Object loadedResult = blenderContext.getLoadedFeature(objectStructure.getOldMemoryAddress(), LoadedFeatureDataType.LOADED_FEATURE);
if(loadedResult != null) { if(loadedResult != null) {
return loadedResult; return loadedResult;
} }
dataRepository.pushParent(objectStructure); blenderContext.pushParent(objectStructure);
ObjectHelper objectHelper = dataRepository.getHelper(ObjectHelper.class); ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class);
//get object data //get object data
int type = ((Number)objectStructure.getFieldValue("type")).intValue(); int type = ((Number)objectStructure.getFieldValue("type")).intValue();
@ -148,21 +148,21 @@ public class ObjectHelper extends AbstractBlenderHelper {
LOGGER.log(Level.INFO, "Loading obejct: {0}", name); LOGGER.log(Level.INFO, "Loading obejct: {0}", name);
//loading constraints connected with this object //loading constraints connected with this object
ConstraintHelper constraintHelper = dataRepository.getHelper(ConstraintHelper.class); ConstraintHelper constraintHelper = blenderContext.getHelper(ConstraintHelper.class);
constraintHelper.loadConstraints(objectStructure, dataRepository); constraintHelper.loadConstraints(objectStructure, blenderContext);
int restrictflag = ((Number)objectStructure.getFieldValue("restrictflag")).intValue(); int restrictflag = ((Number)objectStructure.getFieldValue("restrictflag")).intValue();
boolean visible = (restrictflag & 0x01) != 0; boolean visible = (restrictflag & 0x01) != 0;
Object result = null; Object result = null;
Pointer pParent = (Pointer)objectStructure.getFieldValue("parent"); Pointer pParent = (Pointer)objectStructure.getFieldValue("parent");
Object parent = dataRepository.getLoadedFeature(pParent.getOldMemoryAddress(), LoadedFeatureDataType.LOADED_FEATURE); Object parent = blenderContext.getLoadedFeature(pParent.getOldMemoryAddress(), LoadedFeatureDataType.LOADED_FEATURE);
if(parent == null && pParent.isNotNull()) { if(parent == null && pParent.isNotNull()) {
Structure parentStructure = pParent.fetchData(dataRepository.getInputStream()).get(0);//TODO: what if there are more parents ?? Structure parentStructure = pParent.fetchData(blenderContext.getInputStream()).get(0);//TODO: what if there are more parents ??
parent = this.toObject(parentStructure, dataRepository); parent = this.toObject(parentStructure, blenderContext);
} }
Transform t = objectHelper.getTransformation(objectStructure, dataRepository); Transform t = objectHelper.getTransformation(objectStructure, blenderContext);
try { try {
switch(type) { switch(type) {
@ -178,10 +178,10 @@ public class ObjectHelper extends AbstractBlenderHelper {
node.setCullHint(visible ? CullHint.Always : CullHint.Inherit); node.setCullHint(visible ? CullHint.Always : CullHint.Inherit);
//reading mesh //reading mesh
MeshHelper meshHelper = dataRepository.getHelper(MeshHelper.class); MeshHelper meshHelper = blenderContext.getHelper(MeshHelper.class);
Pointer pMesh = (Pointer)objectStructure.getFieldValue("data"); Pointer pMesh = (Pointer)objectStructure.getFieldValue("data");
List<Structure> meshesArray = pMesh.fetchData(dataRepository.getInputStream()); List<Structure> meshesArray = pMesh.fetchData(blenderContext.getInputStream());
List<Geometry> geometries = meshHelper.toMesh(meshesArray.get(0), dataRepository); List<Geometry> geometries = meshHelper.toMesh(meshesArray.get(0), blenderContext);
if (geometries != null){ if (geometries != null){
for(Geometry geometry : geometries) { for(Geometry geometry : geometries) {
node.attachChild(geometry); node.attachChild(geometry);
@ -190,10 +190,10 @@ public class ObjectHelper extends AbstractBlenderHelper {
node.setLocalTransform(t); node.setLocalTransform(t);
//reading and applying all modifiers //reading and applying all modifiers
ModifierHelper modifierHelper = dataRepository.getHelper(ModifierHelper.class); ModifierHelper modifierHelper = blenderContext.getHelper(ModifierHelper.class);
Collection<Modifier> modifiers = modifierHelper.readModifiers(objectStructure, dataRepository); Collection<Modifier> modifiers = modifierHelper.readModifiers(objectStructure, blenderContext);
for(Modifier modifier : modifiers) { for(Modifier modifier : modifiers) {
modifier.apply(node, dataRepository); modifier.apply(node, blenderContext);
} }
//setting the parent //setting the parent
@ -208,9 +208,9 @@ public class ObjectHelper extends AbstractBlenderHelper {
LOGGER.log(Level.INFO, "Importing curve/nurb."); LOGGER.log(Level.INFO, "Importing curve/nurb.");
Pointer pCurve = (Pointer)objectStructure.getFieldValue("data"); Pointer pCurve = (Pointer)objectStructure.getFieldValue("data");
if(pCurve.isNotNull()) { if(pCurve.isNotNull()) {
CurvesHelper curvesHelper = dataRepository.getHelper(CurvesHelper.class); CurvesHelper curvesHelper = blenderContext.getHelper(CurvesHelper.class);
Structure curveData = pCurve.fetchData(dataRepository.getInputStream()).get(0); Structure curveData = pCurve.fetchData(blenderContext.getInputStream()).get(0);
List<Geometry> curves = curvesHelper.toCurve(curveData, dataRepository); List<Geometry> curves = curvesHelper.toCurve(curveData, blenderContext);
result = new Node(name); result = new Node(name);
for(Geometry curve : curves) { for(Geometry curve : curves) {
((Node)result).attachChild(curve); ((Node)result).attachChild(curve);
@ -222,9 +222,9 @@ public class ObjectHelper extends AbstractBlenderHelper {
LOGGER.log(Level.INFO, "Importing lamp."); LOGGER.log(Level.INFO, "Importing lamp.");
Pointer pLamp = (Pointer)objectStructure.getFieldValue("data"); Pointer pLamp = (Pointer)objectStructure.getFieldValue("data");
if(pLamp.isNotNull()) { if(pLamp.isNotNull()) {
LightHelper lightHelper = dataRepository.getHelper(LightHelper.class); LightHelper lightHelper = blenderContext.getHelper(LightHelper.class);
List<Structure> lampsArray = pLamp.fetchData(dataRepository.getInputStream()); List<Structure> lampsArray = pLamp.fetchData(blenderContext.getInputStream());
Light light = lightHelper.toLight(lampsArray.get(0), dataRepository); Light light = lightHelper.toLight(lampsArray.get(0), blenderContext);
if(light!=null) { if(light!=null) {
light.setName(name); light.setName(name);
} }
@ -251,8 +251,8 @@ public class ObjectHelper extends AbstractBlenderHelper {
case OBJECT_TYPE_CAMERA: case OBJECT_TYPE_CAMERA:
Pointer pCamera = (Pointer)objectStructure.getFieldValue("data"); Pointer pCamera = (Pointer)objectStructure.getFieldValue("data");
if(pCamera.isNotNull()) { if(pCamera.isNotNull()) {
CameraHelper cameraHelper = dataRepository.getHelper(CameraHelper.class); CameraHelper cameraHelper = blenderContext.getHelper(CameraHelper.class);
List<Structure> camerasArray = pCamera.fetchData(dataRepository.getInputStream()); List<Structure> camerasArray = pCamera.fetchData(blenderContext.getInputStream());
Camera camera = cameraHelper.toCamera(camerasArray.get(0)); Camera camera = cameraHelper.toCamera(camerasArray.get(0));
camera.setLocation(t.getTranslation()); camera.setLocation(t.getTranslation());
camera.setRotation(t.getRotation()); camera.setRotation(t.getRotation());
@ -266,17 +266,17 @@ public class ObjectHelper extends AbstractBlenderHelper {
LOGGER.log(Level.WARNING, "Unknown object type: {0}", type); LOGGER.log(Level.WARNING, "Unknown object type: {0}", type);
} }
} finally { } finally {
dataRepository.popParent(); blenderContext.popParent();
} }
if(result != null) { if(result != null) {
//reading custom properties //reading custom properties
Properties properties = this.loadProperties(objectStructure, dataRepository); Properties properties = this.loadProperties(objectStructure, blenderContext);
if(result instanceof Spatial && properties != null && properties.getValue() != null) { if(result instanceof Spatial && properties != null && properties.getValue() != null) {
((Spatial)result).setUserData("properties", properties); ((Spatial)result).setUserData("properties", properties);
} }
dataRepository.addLoadedFeatures(objectStructure.getOldMemoryAddress(), name, objectStructure, result); blenderContext.addLoadedFeatures(objectStructure.getOldMemoryAddress(), name, objectStructure, result);
} }
return result; return result;
} }
@ -288,7 +288,7 @@ public class ObjectHelper extends AbstractBlenderHelper {
* @return objects transformation relative to its parent * @return objects transformation relative to its parent
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Transform getTransformation(Structure objectStructure, DataRepository dataRepository) { public Transform getTransformation(Structure objectStructure, BlenderContext blenderContext) {
//these are transformations in global space //these are transformations in global space
DynamicArray<Number> loc = (DynamicArray<Number>)objectStructure.getFieldValue("loc"); DynamicArray<Number> loc = (DynamicArray<Number>)objectStructure.getFieldValue("loc");
DynamicArray<Number> size = (DynamicArray<Number>)objectStructure.getFieldValue("size"); DynamicArray<Number> size = (DynamicArray<Number>)objectStructure.getFieldValue("size");
@ -299,7 +299,7 @@ public class ObjectHelper extends AbstractBlenderHelper {
Structure parent = null; Structure parent = null;
if(pParent.isNotNull()) { if(pParent.isNotNull()) {
try { try {
parent = pParent.fetchData(dataRepository.getInputStream()).get(0); parent = pParent.fetchData(blenderContext.getInputStream()).get(0);
} catch (BlenderFileException e) { } catch (BlenderFileException e) {
LOGGER.log(Level.WARNING, "Cannot fetch parent for object! Reason: {0}", e.getLocalizedMessage()); LOGGER.log(Level.WARNING, "Cannot fetch parent for object! Reason: {0}", e.getLocalizedMessage());
} }
@ -324,7 +324,7 @@ public class ObjectHelper extends AbstractBlenderHelper {
size.get(2).floatValue() * scaleZ); size.get(2).floatValue() * scaleZ);
//the root object is transformed if the Y axis is UP //the root object is transformed if the Y axis is UP
if(fixUpAxis && (pParent.isNull() || (parent!=null && !this.shouldBeLoaded(parent, dataRepository)))) { if(fixUpAxis && (pParent.isNull() || (parent!=null && !this.shouldBeLoaded(parent, blenderContext)))) {
float y = translation.y; float y = translation.y;
translation.y = translation.z; translation.y = translation.z;
translation.z = -y; translation.z = -y;
@ -373,9 +373,9 @@ public class ObjectHelper extends AbstractBlenderHelper {
} }
@Override @Override
public boolean shouldBeLoaded(Structure structure, DataRepository dataRepository) { public boolean shouldBeLoaded(Structure structure, BlenderContext blenderContext) {
int lay = ((Number) structure.getFieldValue("lay")).intValue(); int lay = ((Number) structure.getFieldValue("lay")).intValue();
return ((lay & dataRepository.getBlenderKey().getLayersToLoad()) != 0 return ((lay & blenderContext.getBlenderKey().getLayersToLoad()) != 0
&& (dataRepository.getBlenderKey().getFeaturesToLoad() & FeaturesToLoad.OBJECTS) != 0); && (blenderContext.getBlenderKey().getFeaturesToLoad() & FeaturesToLoad.OBJECTS) != 0);
} }
} }

@ -11,7 +11,7 @@ import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter; import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule; import com.jme3.export.OutputCapsule;
import com.jme3.export.Savable; import com.jme3.export.Savable;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
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.BlenderInputStream;
import com.jme3.scene.plugins.blender.file.FileBlockHeader; import com.jme3.scene.plugins.blender.file.FileBlockHeader;
@ -57,12 +57,12 @@ public class Properties implements Cloneable, Savable {
* This method loads the property from the belnder file. * This method loads the property from the belnder file.
* @param idPropertyStructure * @param idPropertyStructure
* the ID structure constining the property * the ID structure constining the property
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @throws BlenderFileException * @throws BlenderFileException
* an exception is thrown when the belnder file is somehow invalid * an exception is thrown when the belnder file is somehow invalid
*/ */
public void load(Structure idPropertyStructure, DataRepository dataRepository) throws BlenderFileException { public void load(Structure idPropertyStructure, BlenderContext blenderContext) throws BlenderFileException {
name = idPropertyStructure.getFieldValue("name").toString(); name = idPropertyStructure.getFieldValue("name").toString();
if (name == null || name.length() == 0) { if (name == null || name.length() == 0) {
name = DEFAULT_NAME; name = DEFAULT_NAME;
@ -76,8 +76,8 @@ public class Properties implements Cloneable, Savable {
switch (type) { switch (type) {
case IDP_STRING: { case IDP_STRING: {
Pointer pointer = (Pointer) data.getFieldValue("pointer"); Pointer pointer = (Pointer) data.getFieldValue("pointer");
BlenderInputStream bis = dataRepository.getInputStream(); BlenderInputStream bis = blenderContext.getInputStream();
FileBlockHeader dataFileBlock = dataRepository.getFileBlock(pointer.getOldMemoryAddress()); FileBlockHeader dataFileBlock = blenderContext.getFileBlock(pointer.getOldMemoryAddress());
bis.setPosition(dataFileBlock.getBlockPosition()); bis.setPosition(dataFileBlock.getBlockPosition());
value = bis.readString(); value = bis.readString();
break; break;
@ -92,8 +92,8 @@ public class Properties implements Cloneable, Savable {
break; break;
case IDP_ARRAY: { case IDP_ARRAY: {
Pointer pointer = (Pointer) data.getFieldValue("pointer"); Pointer pointer = (Pointer) data.getFieldValue("pointer");
BlenderInputStream bis = dataRepository.getInputStream(); BlenderInputStream bis = blenderContext.getInputStream();
FileBlockHeader dataFileBlock = dataRepository.getFileBlock(pointer.getOldMemoryAddress()); FileBlockHeader dataFileBlock = blenderContext.getFileBlock(pointer.getOldMemoryAddress());
bis.setPosition(dataFileBlock.getBlockPosition()); bis.setPosition(dataFileBlock.getBlockPosition());
int elementAmount = dataFileBlock.getSize(); int elementAmount = dataFileBlock.getSize();
switch (subType) { switch (subType) {
@ -127,11 +127,11 @@ public class Properties implements Cloneable, Savable {
} }
case IDP_GROUP: case IDP_GROUP:
Structure group = (Structure) data.getFieldValue("group"); Structure group = (Structure) data.getFieldValue("group");
List<Structure> dataList = group.evaluateListBase(dataRepository); List<Structure> dataList = group.evaluateListBase(blenderContext);
List<Properties> subProperties = new ArrayList<Properties>(len); List<Properties> subProperties = new ArrayList<Properties>(len);
for (Structure d : dataList) { for (Structure d : dataList) {
Properties properties = new Properties(); Properties properties = new Properties();
properties.load(d, dataRepository); properties.load(d, blenderContext);
subProperties.add(properties); subProperties.add(properties);
} }
value = subProperties; value = subProperties;
@ -144,11 +144,11 @@ public class Properties implements Cloneable, Savable {
break; break;
case IDP_IDPARRAY: { case IDP_IDPARRAY: {
Pointer pointer = (Pointer) data.getFieldValue("pointer"); Pointer pointer = (Pointer) data.getFieldValue("pointer");
List<Structure> arrays = pointer.fetchData(dataRepository.getInputStream()); List<Structure> arrays = pointer.fetchData(blenderContext.getInputStream());
List<Object> result = new ArrayList<Object>(arrays.size()); List<Object> result = new ArrayList<Object>(arrays.size());
Properties temp = new Properties(); Properties temp = new Properties();
for (Structure array : arrays) { for (Structure array : arrays) {
temp.load(array, dataRepository); temp.load(array, blenderContext);
result.add(temp.value); result.add(temp.value);
} }
this.value = result; this.value = result;

@ -12,7 +12,7 @@ import com.jme3.effect.shapes.EmitterMeshFaceShape;
import com.jme3.effect.shapes.EmitterMeshVertexShape; import com.jme3.effect.shapes.EmitterMeshVertexShape;
import com.jme3.math.ColorRGBA; import com.jme3.math.ColorRGBA;
import com.jme3.scene.plugins.blender.AbstractBlenderHelper; import com.jme3.scene.plugins.blender.AbstractBlenderHelper;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.DynamicArray; import com.jme3.scene.plugins.blender.file.DynamicArray;
import com.jme3.scene.plugins.blender.file.Pointer; import com.jme3.scene.plugins.blender.file.Pointer;
@ -93,11 +93,11 @@ public class ParticlesHelper extends AbstractBlenderHelper {
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public ParticleEmitter toParticleEmitter(Structure particleSystem, DataRepository dataRepository) throws BlenderFileException { public ParticleEmitter toParticleEmitter(Structure particleSystem, BlenderContext blenderContext) throws BlenderFileException {
ParticleEmitter result = null; ParticleEmitter result = null;
Pointer pParticleSettings = (Pointer) particleSystem.getFieldValue("part"); Pointer pParticleSettings = (Pointer) particleSystem.getFieldValue("part");
if(pParticleSettings.isNotNull()) { if(pParticleSettings.isNotNull()) {
Structure particleSettings = pParticleSettings.fetchData(dataRepository.getInputStream()).get(0); Structure particleSettings = pParticleSettings.fetchData(blenderContext.getInputStream()).get(0);
int totPart = ((Number) particleSettings.getFieldValue("totpart")).intValue(); int totPart = ((Number) particleSettings.getFieldValue("totpart")).intValue();
@ -159,7 +159,7 @@ public class ParticlesHelper extends AbstractBlenderHelper {
result.setEndSize(size); result.setEndSize(size);
//reading lifetime //reading lifetime
int fps = dataRepository.getBlenderKey().getFps(); int fps = blenderContext.getBlenderKey().getFps();
float lifetime = ((Number)particleSettings.getFieldValue("lifetime")).floatValue() / fps; float lifetime = ((Number)particleSettings.getFieldValue("lifetime")).floatValue() / fps;
float randlife = ((Number)particleSettings.getFieldValue("randlife")).floatValue() / fps; float randlife = ((Number)particleSettings.getFieldValue("randlife")).floatValue() / fps;
result.setLowLife(lifetime * (1.0f - randlife)); result.setLowLife(lifetime * (1.0f - randlife));
@ -189,7 +189,7 @@ public class ParticlesHelper extends AbstractBlenderHelper {
} }
@Override @Override
public boolean shouldBeLoaded(Structure structure, DataRepository dataRepository) { public boolean shouldBeLoaded(Structure structure, BlenderContext blenderContext) {
return true; return true;
} }
} }

@ -41,14 +41,14 @@ import java.util.logging.Logger;
import com.jme3.math.FastMath; import com.jme3.math.FastMath;
import com.jme3.scene.plugins.blender.AbstractBlenderHelper; import com.jme3.scene.plugins.blender.AbstractBlenderHelper;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
import com.jme3.scene.plugins.blender.textures.TextureGeneratorMusgrave.MusgraveData; import com.jme3.scene.plugins.blender.textures.TextureGeneratorMusgrave.MusgraveData;
/** /**
* This generator is responsible for creating various noises used to create * This generator is responsible for creating various noises used to create
* generated textures loaded from blender. * generated textures loaded from blender.
* It derives from AbstractBlenderHelper but is not stored in data repository. * It derives from AbstractBlenderHelper but is not stored in blender context.
* It is only used by TextureHelper. * It is only used by TextureHelper.
* @author Marcin Roguski (Kaelthas) * @author Marcin Roguski (Kaelthas)
*/ */
@ -844,7 +844,7 @@ import com.jme3.scene.plugins.blender.textures.TextureGeneratorMusgrave.Musgrave
} }
@Override @Override
public boolean shouldBeLoaded(Structure structure, DataRepository dataRepository) { public boolean shouldBeLoaded(Structure structure, BlenderContext blenderContext) {
return true; return true;
} }

@ -37,7 +37,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import com.jme3.math.FastMath; import com.jme3.math.FastMath;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.DynamicArray; import com.jme3.scene.plugins.blender.file.DynamicArray;
import com.jme3.scene.plugins.blender.file.Pointer; import com.jme3.scene.plugins.blender.file.Pointer;
@ -67,29 +67,29 @@ import com.jme3.texture.Texture;
* the height of the result texture * the height of the result texture
* @param depth * @param depth
* the depth of the texture * the depth of the texture
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @return newly generated texture * @return newly generated texture
*/ */
protected abstract Texture generate(Structure tex, int width, int height, int depth, DataRepository dataRepository); protected abstract Texture generate(Structure tex, int width, int height, int depth, BlenderContext blenderContext);
/** /**
* This method reads the colorband data from the given texture structure. * This method reads the colorband data from the given texture structure.
* *
* @param tex * @param tex
* the texture structure * the texture structure
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @return read colorband or null if not present * @return read colorband or null if not present
*/ */
private ColorBand readColorband(Structure tex, DataRepository dataRepository) { private ColorBand readColorband(Structure tex, BlenderContext blenderContext) {
ColorBand result = null; ColorBand result = null;
int flag = ((Number) tex.getFieldValue("flag")).intValue(); int flag = ((Number) tex.getFieldValue("flag")).intValue();
if ((flag & NoiseGenerator.TEX_COLORBAND) != 0) { if ((flag & NoiseGenerator.TEX_COLORBAND) != 0) {
Pointer pColorband = (Pointer) tex.getFieldValue("coba"); Pointer pColorband = (Pointer) tex.getFieldValue("coba");
Structure colorbandStructure; Structure colorbandStructure;
try { try {
colorbandStructure = pColorband.fetchData(dataRepository.getInputStream()).get(0); colorbandStructure = pColorband.fetchData(blenderContext.getInputStream()).get(0);
result = new ColorBand(colorbandStructure); result = new ColorBand(colorbandStructure);
} catch (BlenderFileException e) { } catch (BlenderFileException e) {
LOGGER.log(Level.WARNING, "Cannot fetch the colorband structure. The reason: {0}", e.getLocalizedMessage()); LOGGER.log(Level.WARNING, "Cannot fetch the colorband structure. The reason: {0}", e.getLocalizedMessage());
@ -98,8 +98,8 @@ import com.jme3.texture.Texture;
return result; return result;
} }
protected float[][] computeColorband(Structure tex, DataRepository dataRepository) { protected float[][] computeColorband(Structure tex, BlenderContext blenderContext) {
ColorBand colorBand = this.readColorband(tex, dataRepository); ColorBand colorBand = this.readColorband(tex, blenderContext);
float[][] result = null; float[][] result = null;
if(colorBand!=null) { if(colorBand!=null) {
result = new float[1001][4];//1001 - amount of possible cursor positions; 4 = [r, g, b, a] result = new float[1001][4];//1001 - amount of possible cursor positions; 4 = [r, g, b, a]

@ -35,7 +35,7 @@ import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import com.jme3.math.FastMath; import com.jme3.math.FastMath;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
import com.jme3.texture.Image; import com.jme3.texture.Image;
import com.jme3.texture.Image.Format; import com.jme3.texture.Image.Format;
@ -115,13 +115,13 @@ public final class TextureGeneratorBlend extends TextureGenerator {
} }
@Override @Override
protected Texture generate(Structure tex, int width, int height, int depth, DataRepository dataRepository) { protected Texture generate(Structure tex, int width, int height, int depth, BlenderContext blenderContext) {
int flag = ((Number) tex.getFieldValue("flag")).intValue(); int flag = ((Number) tex.getFieldValue("flag")).intValue();
int stype = ((Number) tex.getFieldValue("stype")).intValue(); int stype = ((Number) tex.getFieldValue("stype")).intValue();
TextureResult texres = new TextureResult(); TextureResult texres = new TextureResult();
int halfW = width >> 1, halfH = height >> 1, halfD = depth >> 1, index = 0; int halfW = width >> 1, halfH = height >> 1, halfD = depth >> 1, index = 0;
float wDelta = 1.0f / halfW, hDelta = 1.0f / halfH, dDelta = 1.0f / halfD, x, y; float wDelta = 1.0f / halfW, hDelta = 1.0f / halfH, dDelta = 1.0f / halfD, x, y;
float[][] colorBand = this.computeColorband(tex, dataRepository); float[][] colorBand = this.computeColorband(tex, blenderContext);
BrightnessAndContrastData bacd = new BrightnessAndContrastData(tex); BrightnessAndContrastData bacd = new BrightnessAndContrastData(tex);
Format format = colorBand != null ? Format.RGB8 : Format.Luminance8; Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;
int bytesPerPixel = colorBand != null ? 3 : 1; int bytesPerPixel = colorBand != null ? 3 : 1;

@ -35,7 +35,7 @@ import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import com.jme3.math.FastMath; import com.jme3.math.FastMath;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
import com.jme3.texture.Image; import com.jme3.texture.Image;
import com.jme3.texture.Image.Format; import com.jme3.texture.Image.Format;
@ -66,7 +66,7 @@ public class TextureGeneratorClouds extends TextureGenerator {
} }
@Override @Override
protected Texture generate(Structure tex, int width, int height, int depth, DataRepository dataRepository) { protected Texture generate(Structure tex, int width, int height, int depth, BlenderContext blenderContext) {
float[] texvec = new float[] { 0, 0, 0 }; float[] texvec = new float[] { 0, 0, 0 };
TextureResult texres = new TextureResult(); TextureResult texres = new TextureResult();
@ -79,7 +79,7 @@ public class TextureGeneratorClouds extends TextureGenerator {
int sType = ((Number) tex.getFieldValue("stype")).intValue(); int sType = ((Number) tex.getFieldValue("stype")).intValue();
int halfW = width >> 1, halfH = height >> 1, halfD = depth >> 1, index = 0; int halfW = width >> 1, halfH = height >> 1, halfD = depth >> 1, index = 0;
float wDelta = 1.0f / halfW, hDelta = 1.0f / halfH, dDelta = 1.0f / halfD; float wDelta = 1.0f / halfW, hDelta = 1.0f / halfH, dDelta = 1.0f / halfD;
float[][] colorBand = this.computeColorband(tex, dataRepository); float[][] colorBand = this.computeColorband(tex, blenderContext);
Format format = sType == TEX_COLOR || colorBand != null ? Format.RGB8 : Format.Luminance8; Format format = sType == TEX_COLOR || colorBand != null ? Format.RGB8 : Format.Luminance8;
int bytesPerPixel = sType == TEX_COLOR || colorBand != null ? 3 : 1; int bytesPerPixel = sType == TEX_COLOR || colorBand != null ? 3 : 1;
BrightnessAndContrastData bacd = new BrightnessAndContrastData(tex); BrightnessAndContrastData bacd = new BrightnessAndContrastData(tex);

@ -34,7 +34,7 @@ package com.jme3.scene.plugins.blender.textures;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
import com.jme3.scene.plugins.blender.textures.NoiseGenerator.NoiseFunction; import com.jme3.scene.plugins.blender.textures.NoiseGenerator.NoiseFunction;
import com.jme3.texture.Image; import com.jme3.texture.Image;
@ -59,7 +59,7 @@ public class TextureGeneratorDistnoise extends TextureGenerator {
} }
@Override @Override
protected Texture generate(Structure tex, int width, int height, int depth, DataRepository dataRepository) { protected Texture generate(Structure tex, int width, int height, int depth, BlenderContext blenderContext) {
float noisesize = ((Number) tex.getFieldValue("noisesize")).floatValue(); float noisesize = ((Number) tex.getFieldValue("noisesize")).floatValue();
float distAmount = ((Number) tex.getFieldValue("dist_amount")).floatValue(); float distAmount = ((Number) tex.getFieldValue("dist_amount")).floatValue();
int noisebasis = ((Number) tex.getFieldValue("noisebasis")).intValue(); int noisebasis = ((Number) tex.getFieldValue("noisebasis")).intValue();
@ -69,7 +69,7 @@ public class TextureGeneratorDistnoise extends TextureGenerator {
float[] texvec = new float[] { 0, 0, 0 }; float[] texvec = new float[] { 0, 0, 0 };
int halfW = width >> 1, halfH = height >> 1, halfD = depth >> 1, index = 0; int halfW = width >> 1, halfH = height >> 1, halfD = depth >> 1, index = 0;
float wDelta = 1.0f / halfW, hDelta = 1.0f / halfH, dDelta = 1.0f / halfD; float wDelta = 1.0f / halfW, hDelta = 1.0f / halfH, dDelta = 1.0f / halfD;
float[][] colorBand = this.computeColorband(tex, dataRepository); float[][] colorBand = this.computeColorband(tex, blenderContext);
Format format = colorBand != null ? Format.RGB8 : Format.Luminance8; Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;
int bytesPerPixel = colorBand != null ? 3 : 1; int bytesPerPixel = colorBand != null ? 3 : 1;
BrightnessAndContrastData bacd = new BrightnessAndContrastData(tex); BrightnessAndContrastData bacd = new BrightnessAndContrastData(tex);

@ -34,7 +34,7 @@ package com.jme3.scene.plugins.blender.textures;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
import com.jme3.texture.Image; import com.jme3.texture.Image;
import com.jme3.texture.Image.Format; import com.jme3.texture.Image.Format;
@ -121,7 +121,7 @@ public class TextureGeneratorMagic extends TextureGenerator {
} }
@Override @Override
protected Texture generate(Structure tex, int width, int height, int depth, DataRepository dataRepository) { protected Texture generate(Structure tex, int width, int height, int depth, BlenderContext blenderContext) {
float xyz[] = new float[3], turb; float xyz[] = new float[3], turb;
int noisedepth = ((Number) tex.getFieldValue("noisedepth")).intValue(); int noisedepth = ((Number) tex.getFieldValue("noisedepth")).intValue();
float turbul = ((Number) tex.getFieldValue("turbul")).floatValue() / 5.0f; float turbul = ((Number) tex.getFieldValue("turbul")).floatValue() / 5.0f;
@ -129,7 +129,7 @@ public class TextureGeneratorMagic extends TextureGenerator {
TextureResult texres = new TextureResult(); TextureResult texres = new TextureResult();
int halfW = width >> 1, halfH = height >> 1, halfD = depth >> 1, index = 0; int halfW = width >> 1, halfH = height >> 1, halfD = depth >> 1, index = 0;
float wDelta = 1.0f / halfW, hDelta = 1.0f / halfH, dDelta = 1.0f / halfD; float wDelta = 1.0f / halfW, hDelta = 1.0f / halfH, dDelta = 1.0f / halfD;
float[][] colorBand = this.computeColorband(tex, dataRepository); float[][] colorBand = this.computeColorband(tex, blenderContext);
BrightnessAndContrastData bacd = new BrightnessAndContrastData(tex); BrightnessAndContrastData bacd = new BrightnessAndContrastData(tex);
byte[] data = new byte[width * height * depth * 3]; byte[] data = new byte[width * height * depth * 3];

@ -34,7 +34,7 @@ package com.jme3.scene.plugins.blender.textures;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
import com.jme3.texture.Image; import com.jme3.texture.Image;
import com.jme3.texture.Image.Format; import com.jme3.texture.Image.Format;
@ -62,12 +62,12 @@ public class TextureGeneratorMarble extends TextureGeneratorWood {
} }
@Override @Override
protected Texture generate(Structure tex, int width, int height, int depth, DataRepository dataRepository) { protected Texture generate(Structure tex, int width, int height, int depth, BlenderContext blenderContext) {
float[] texvec = new float[] { 0, 0, 0 }; float[] texvec = new float[] { 0, 0, 0 };
TextureResult texres = new TextureResult(); TextureResult texres = new TextureResult();
int halfW = width >> 1, halfH = height >> 1, halfD = depth >> 1, index = 0; int halfW = width >> 1, halfH = height >> 1, halfD = depth >> 1, index = 0;
float wDelta = 1.0f / halfW, hDelta = 1.0f / halfH, dDelta = 1.0f / halfD; float wDelta = 1.0f / halfW, hDelta = 1.0f / halfH, dDelta = 1.0f / halfD;
float[][] colorBand = this.computeColorband(tex, dataRepository); float[][] colorBand = this.computeColorband(tex, blenderContext);
Format format = colorBand != null ? Format.RGB8 : Format.Luminance8; Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;
int bytesPerPixel = colorBand != null ? 3 : 1; int bytesPerPixel = colorBand != null ? 3 : 1;
BrightnessAndContrastData bacd = new BrightnessAndContrastData(tex); BrightnessAndContrastData bacd = new BrightnessAndContrastData(tex);

@ -34,7 +34,7 @@ package com.jme3.scene.plugins.blender.textures;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
import com.jme3.scene.plugins.blender.textures.NoiseGenerator.MusgraveFunction; import com.jme3.scene.plugins.blender.textures.NoiseGenerator.MusgraveFunction;
import com.jme3.texture.Image; import com.jme3.texture.Image;
@ -59,14 +59,14 @@ public class TextureGeneratorMusgrave extends TextureGenerator {
} }
@Override @Override
protected Texture generate(Structure tex, int width, int height, int depth, DataRepository dataRepository) { protected Texture generate(Structure tex, int width, int height, int depth, BlenderContext blenderContext) {
int stype = ((Number) tex.getFieldValue("stype")).intValue(); int stype = ((Number) tex.getFieldValue("stype")).intValue();
float noisesize = ((Number) tex.getFieldValue("noisesize")).floatValue(); float noisesize = ((Number) tex.getFieldValue("noisesize")).floatValue();
TextureResult texres = new TextureResult(); TextureResult texres = new TextureResult();
float[] texvec = new float[] { 0, 0, 0 }; float[] texvec = new float[] { 0, 0, 0 };
int halfW = width >> 1, halfH = height >> 1, halfD = depth >> 1, index = 0; int halfW = width >> 1, halfH = height >> 1, halfD = depth >> 1, index = 0;
float wDelta = 1.0f / halfW, hDelta = 1.0f / halfH, dDelta = 1.0f / halfD; float wDelta = 1.0f / halfW, hDelta = 1.0f / halfH, dDelta = 1.0f / halfD;
float[][] colorBand = this.computeColorband(tex, dataRepository); float[][] colorBand = this.computeColorband(tex, blenderContext);
Format format = colorBand != null ? Format.RGB8 : Format.Luminance8; Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;
int bytesPerPixel = colorBand != null ? 3 : 1; int bytesPerPixel = colorBand != null ? 3 : 1;
MusgraveData musgraveData = new MusgraveData(tex); MusgraveData musgraveData = new MusgraveData(tex);

@ -35,7 +35,7 @@ import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import com.jme3.math.FastMath; import com.jme3.math.FastMath;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
import com.jme3.texture.Image; import com.jme3.texture.Image;
import com.jme3.texture.Image.Format; import com.jme3.texture.Image.Format;
@ -59,12 +59,12 @@ public class TextureGeneratorNoise extends TextureGenerator {
} }
@Override @Override
protected Texture generate(Structure tex, int width, int height, int depth, DataRepository dataRepository) { protected Texture generate(Structure tex, int width, int height, int depth, BlenderContext blenderContext) {
int val, random, loop; int val, random, loop;
int noisedepth = ((Number) tex.getFieldValue("noisedepth")).intValue(); int noisedepth = ((Number) tex.getFieldValue("noisedepth")).intValue();
TextureResult texres = new TextureResult(); TextureResult texres = new TextureResult();
int halfW = width >> 1, halfH = height >> 1, halfD = depth >> 1, index = 0; int halfW = width >> 1, halfH = height >> 1, halfD = depth >> 1, index = 0;
float[][] colorBand = this.computeColorband(tex, dataRepository); float[][] colorBand = this.computeColorband(tex, blenderContext);
Format format = colorBand != null ? Format.RGB8 : Format.Luminance8; Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;
int bytesPerPixel = colorBand != null ? 3 : 1; int bytesPerPixel = colorBand != null ? 3 : 1;
BrightnessAndContrastData bacd = new BrightnessAndContrastData(tex); BrightnessAndContrastData bacd = new BrightnessAndContrastData(tex);

@ -34,7 +34,7 @@ package com.jme3.scene.plugins.blender.textures;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
import com.jme3.texture.Image; import com.jme3.texture.Image;
import com.jme3.texture.Image.Format; import com.jme3.texture.Image.Format;
@ -59,7 +59,7 @@ public class TextureGeneratorStucci extends TextureGenerator {
} }
@Override @Override
protected Texture generate(Structure tex, int width, int height, int depth, DataRepository dataRepository) { protected Texture generate(Structure tex, int width, int height, int depth, BlenderContext blenderContext) {
float noisesize = ((Number) tex.getFieldValue("noisesize")).floatValue(); float noisesize = ((Number) tex.getFieldValue("noisesize")).floatValue();
int noisebasis = ((Number) tex.getFieldValue("noisebasis")).intValue(); int noisebasis = ((Number) tex.getFieldValue("noisebasis")).intValue();
int noisetype = ((Number) tex.getFieldValue("noisetype")).intValue(); int noisetype = ((Number) tex.getFieldValue("noisetype")).intValue();
@ -75,7 +75,7 @@ public class TextureGeneratorStucci extends TextureGenerator {
TextureResult texres = new TextureResult(); TextureResult texres = new TextureResult();
int halfW = width >> 1, halfH = height >> 1, halfD = depth >> 1, index = 0; int halfW = width >> 1, halfH = height >> 1, halfD = depth >> 1, index = 0;
float wDelta = 1.0f / halfW, hDelta = 1.0f / halfH, dDelta = 1.0f / halfD, noiseValue, ofs;; float wDelta = 1.0f / halfW, hDelta = 1.0f / halfH, dDelta = 1.0f / halfD, noiseValue, ofs;;
float[][] colorBand = this.computeColorband(tex, dataRepository); float[][] colorBand = this.computeColorband(tex, blenderContext);
Format format = colorBand != null ? Format.RGB8 : Format.Luminance8; Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;
int bytesPerPixel = colorBand != null ? 3 : 1; int bytesPerPixel = colorBand != null ? 3 : 1;

@ -35,7 +35,7 @@ import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import com.jme3.math.FastMath; import com.jme3.math.FastMath;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
import com.jme3.scene.plugins.blender.textures.NoiseGenerator.NoiseMath; import com.jme3.scene.plugins.blender.textures.NoiseGenerator.NoiseMath;
import com.jme3.texture.Image; import com.jme3.texture.Image;
@ -60,7 +60,7 @@ public class TextureGeneratorVoronoi extends TextureGenerator {
} }
@Override @Override
protected Texture generate(Structure tex, int width, int height, int depth, DataRepository dataRepository) { protected Texture generate(Structure tex, int width, int height, int depth, BlenderContext blenderContext) {
float voronoiWeight1 = ((Number) tex.getFieldValue("vn_w1")).floatValue(); float voronoiWeight1 = ((Number) tex.getFieldValue("vn_w1")).floatValue();
float voronoiWeight2 = ((Number) tex.getFieldValue("vn_w2")).floatValue(); float voronoiWeight2 = ((Number) tex.getFieldValue("vn_w2")).floatValue();
float voronoiWeight3 = ((Number) tex.getFieldValue("vn_w3")).floatValue(); float voronoiWeight3 = ((Number) tex.getFieldValue("vn_w3")).floatValue();
@ -76,7 +76,7 @@ public class TextureGeneratorVoronoi extends TextureGenerator {
int halfW = width >> 1, halfH = height >> 1, halfD = depth >> 1, index = 0; int halfW = width >> 1, halfH = height >> 1, halfD = depth >> 1, index = 0;
float wDelta = 1.0f / halfW, hDelta = 1.0f / halfH, dDelta = 1.0f / halfD; float wDelta = 1.0f / halfW, hDelta = 1.0f / halfH, dDelta = 1.0f / halfD;
float[][] colorBand = this.computeColorband(tex, dataRepository); float[][] colorBand = this.computeColorband(tex, blenderContext);
Format format = voronoiColorType != 0 || colorBand != null ? Format.RGB8 : Format.Luminance8; Format format = voronoiColorType != 0 || colorBand != null ? Format.RGB8 : Format.Luminance8;
int bytesPerPixel = voronoiColorType != 0 || colorBand != null ? 3 : 1; int bytesPerPixel = voronoiColorType != 0 || colorBand != null ? 3 : 1;
BrightnessAndContrastData bacd = new BrightnessAndContrastData(tex); BrightnessAndContrastData bacd = new BrightnessAndContrastData(tex);

@ -34,7 +34,7 @@ import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import com.jme3.math.FastMath; import com.jme3.math.FastMath;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.file.Structure;
import com.jme3.texture.Image; import com.jme3.texture.Image;
import com.jme3.texture.Image.Format; import com.jme3.texture.Image.Format;
@ -71,7 +71,7 @@ public class TextureGeneratorWood extends TextureGenerator {
} }
@Override @Override
protected Texture generate(Structure tex, int width, int height, int depth, DataRepository dataRepository) { protected Texture generate(Structure tex, int width, int height, int depth, BlenderContext blenderContext) {
float[] texvec = new float[] { 0, 0, 0 }; float[] texvec = new float[] { 0, 0, 0 };
TextureResult texres = new TextureResult(); TextureResult texres = new TextureResult();
int halfW = width >> 1; int halfW = width >> 1;
@ -79,7 +79,7 @@ public class TextureGeneratorWood extends TextureGenerator {
int halfD = depth >> 1; int halfD = depth >> 1;
float wDelta = 1.0f / halfW, hDelta = 1.0f / halfH, dDelta = 1.0f / halfD; float wDelta = 1.0f / halfW, hDelta = 1.0f / halfH, dDelta = 1.0f / halfD;
float[][] colorBand = this.computeColorband(tex, dataRepository); float[][] colorBand = this.computeColorband(tex, blenderContext);
Format format = colorBand != null ? Format.RGB8 : Format.Luminance8; Format format = colorBand != null ? Format.RGB8 : Format.Luminance8;
int bytesPerPixel = colorBand != null ? 3 : 1; int bytesPerPixel = colorBand != null ? 3 : 1;
WoodIntensityData woodIntensityData = new WoodIntensityData(tex); WoodIntensityData woodIntensityData = new WoodIntensityData(tex);

@ -53,8 +53,8 @@ import com.jme3.asset.TextureKey;
import com.jme3.math.FastMath; import com.jme3.math.FastMath;
import com.jme3.math.Vector3f; import com.jme3.math.Vector3f;
import com.jme3.scene.plugins.blender.AbstractBlenderHelper; import com.jme3.scene.plugins.blender.AbstractBlenderHelper;
import com.jme3.scene.plugins.blender.DataRepository; import com.jme3.scene.plugins.blender.BlenderContext;
import com.jme3.scene.plugins.blender.DataRepository.LoadedFeatureDataType; import com.jme3.scene.plugins.blender.BlenderContext.LoadedFeatureDataType;
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
import com.jme3.scene.plugins.blender.file.FileBlockHeader; import com.jme3.scene.plugins.blender.file.FileBlockHeader;
import com.jme3.scene.plugins.blender.file.Pointer; import com.jme3.scene.plugins.blender.file.Pointer;
@ -160,28 +160,28 @@ public class TextureHelper extends AbstractBlenderHelper {
* *
* @param tex * @param tex
* texture structure filled with data * texture structure filled with data
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @return the texture that can be used by JME engine * @return the texture that can be used by JME engine
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blend file structure is somehow invalid or corrupted * this exception is thrown when the blend file structure is somehow invalid or corrupted
*/ */
public Texture getTexture(Structure tex, DataRepository dataRepository) throws BlenderFileException { public Texture getTexture(Structure tex, BlenderContext blenderContext) throws BlenderFileException {
Texture result = (Texture) dataRepository.getLoadedFeature(tex.getOldMemoryAddress(), LoadedFeatureDataType.LOADED_FEATURE); Texture result = (Texture) blenderContext.getLoadedFeature(tex.getOldMemoryAddress(), LoadedFeatureDataType.LOADED_FEATURE);
if (result != null) { if (result != null) {
return result; return result;
} }
int type = ((Number) tex.getFieldValue("type")).intValue(); int type = ((Number) tex.getFieldValue("type")).intValue();
int width = dataRepository.getBlenderKey().getGeneratedTextureWidth(); int width = blenderContext.getBlenderKey().getGeneratedTextureWidth();
int height = dataRepository.getBlenderKey().getGeneratedTextureHeight(); int height = blenderContext.getBlenderKey().getGeneratedTextureHeight();
int depth = dataRepository.getBlenderKey().getGeneratedTextureDepth(); int depth = blenderContext.getBlenderKey().getGeneratedTextureDepth();
switch (type) { switch (type) {
case TEX_IMAGE:// (it is first because probably this will be most commonly used) case TEX_IMAGE:// (it is first because probably this will be most commonly used)
Pointer pImage = (Pointer) tex.getFieldValue("ima"); Pointer pImage = (Pointer) tex.getFieldValue("ima");
if (pImage.isNotNull()){ if (pImage.isNotNull()){
Structure image = pImage.fetchData(dataRepository.getInputStream()).get(0); Structure image = pImage.fetchData(blenderContext.getInputStream()).get(0);
result = this.getTextureFromImage(image, dataRepository); result = this.getTextureFromImage(image, blenderContext);
} }
break; break;
case TEX_CLOUDS: case TEX_CLOUDS:
@ -195,7 +195,7 @@ public class TextureHelper extends AbstractBlenderHelper {
case TEX_VORONOI: case TEX_VORONOI:
case TEX_DISTNOISE: case TEX_DISTNOISE:
TextureGenerator textureGenerator = textureGenerators.get(Integer.valueOf(type)); TextureGenerator textureGenerator = textureGenerators.get(Integer.valueOf(type));
result = textureGenerator.generate(tex, width, height, depth, dataRepository); result = textureGenerator.generate(tex, width, height, depth, blenderContext);
break; break;
case TEX_NONE:// No texture, do nothing case TEX_NONE:// No texture, do nothing
break; break;
@ -236,11 +236,11 @@ public class TextureHelper extends AbstractBlenderHelper {
* the factor that the color affects the texture (value form 0.0 to 1.0) * the factor that the color affects the texture (value form 0.0 to 1.0)
* @param blendType * @param blendType
* the blending type * the blending type
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @return new texture that was created after the blending * @return new texture that was created after the blending
*/ */
public Texture blendTexture(float[] materialColor, Texture texture, float[] color, float affectFactor, int blendType, boolean neg, DataRepository dataRepository) { public Texture blendTexture(float[] materialColor, Texture texture, float[] color, float affectFactor, int blendType, boolean neg, BlenderContext blenderContext) {
float[] materialColorClone = materialColor.clone();//this array may change, so we copy it float[] materialColorClone = materialColor.clone();//this array may change, so we copy it
Format format = texture.getImage().getFormat(); Format format = texture.getImage().getFormat();
ByteBuffer data = texture.getImage().getData(0); ByteBuffer data = texture.getImage().getData(0);
@ -257,7 +257,7 @@ public class TextureHelper extends AbstractBlenderHelper {
int dataIndex = 0; int dataIndex = 0;
while (data.hasRemaining()) { while (data.hasRemaining()) {
float tin = this.setupMaterialColor(data, format, neg, materialColorClone); float tin = this.setupMaterialColor(data, format, neg, materialColorClone);
this.blendPixel(resultPixel, materialColorClone, color, tin, affectFactor, blendType, dataRepository); this.blendPixel(resultPixel, materialColorClone, color, tin, affectFactor, blendType, blenderContext);
newData.put(dataIndex++, (byte) (resultPixel[0] * 255.0f)); newData.put(dataIndex++, (byte) (resultPixel[0] * 255.0f));
newData.put(dataIndex++, (byte) (resultPixel[1] * 255.0f)); newData.put(dataIndex++, (byte) (resultPixel[1] * 255.0f));
newData.put(dataIndex++, (byte) (resultPixel[2] * 255.0f)); newData.put(dataIndex++, (byte) (resultPixel[2] * 255.0f));
@ -396,10 +396,10 @@ public class TextureHelper extends AbstractBlenderHelper {
* texture affection factor (variable 'facg' in blender source code) * texture affection factor (variable 'facg' in blender source code)
* @param blendtype * @param blendtype
* the blend type * the blend type
* @param dataRepository * @param blenderContext
* the data repository * the blender context
*/ */
protected void blendPixel(float[] result, float[] materialColor, float[] color, float textureIntensity, float textureFactor, int blendtype, DataRepository dataRepository) { protected void blendPixel(float[] result, float[] materialColor, float[] color, float textureIntensity, float textureFactor, int blendtype, BlenderContext blenderContext) {
float oneMinusFactor, col; float oneMinusFactor, col;
textureIntensity *= textureFactor; textureIntensity *= textureFactor;
@ -492,7 +492,7 @@ public class TextureHelper extends AbstractBlenderHelper {
case MTEX_BLEND_VAL: case MTEX_BLEND_VAL:
case MTEX_BLEND_COLOR: case MTEX_BLEND_COLOR:
System.arraycopy(materialColor, 0, result, 0, 3); System.arraycopy(materialColor, 0, result, 0, 3);
this.rampBlend(blendtype, result, textureIntensity, color, dataRepository); this.rampBlend(blendtype, result, textureIntensity, color, blenderContext);
break; break;
default: default:
throw new IllegalStateException("Unknown blend type: " + blendtype); throw new IllegalStateException("Unknown blend type: " + blendtype);
@ -510,12 +510,12 @@ public class TextureHelper extends AbstractBlenderHelper {
* color affection factor * color affection factor
* @param col * @param col
* the texture color * the texture color
* @param dataRepository * @param blenderContext
* the data repository * the blender context
*/ */
protected void rampBlend(int type, float[] rgb, float fac, float[] col, DataRepository dataRepository) { protected void rampBlend(int type, float[] rgb, float fac, float[] col, BlenderContext blenderContext) {
float oneMinusFactor = 1.0f - fac; float oneMinusFactor = 1.0f - fac;
MaterialHelper materialHelper = dataRepository.getHelper(MaterialHelper.class); MaterialHelper materialHelper = blenderContext.getHelper(MaterialHelper.class);
if (rgb.length >= 3) { if (rgb.length >= 3) {
switch (type) { switch (type) {
@ -660,30 +660,30 @@ public class TextureHelper extends AbstractBlenderHelper {
* *
* @param image * @param image
* image structure filled with data * image structure filled with data
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @return the texture that can be used by JME engine * @return the texture that can be used by JME engine
* @throws BlenderFileException * @throws BlenderFileException
* this exception is thrown when the blend file structure is somehow invalid or corrupted * this exception is thrown when the blend file structure is somehow invalid or corrupted
*/ */
public Texture getTextureFromImage(Structure image, DataRepository dataRepository) throws BlenderFileException { public Texture getTextureFromImage(Structure image, BlenderContext blenderContext) throws BlenderFileException {
Texture result = (Texture) dataRepository.getLoadedFeature(image.getOldMemoryAddress(), LoadedFeatureDataType.LOADED_FEATURE); Texture result = (Texture) blenderContext.getLoadedFeature(image.getOldMemoryAddress(), LoadedFeatureDataType.LOADED_FEATURE);
if (result == null) { if (result == null) {
String texturePath = image.getFieldValue("name").toString(); String texturePath = image.getFieldValue("name").toString();
Pointer pPackedFile = (Pointer) image.getFieldValue("packedfile"); Pointer pPackedFile = (Pointer) image.getFieldValue("packedfile");
if (pPackedFile.isNull()) { if (pPackedFile.isNull()) {
LOGGER.info("Reading texture from file!"); LOGGER.info("Reading texture from file!");
result = this.loadTextureFromFile(texturePath, dataRepository); result = this.loadTextureFromFile(texturePath, blenderContext);
} else { } else {
LOGGER.info("Packed texture. Reading directly from the blend file!"); LOGGER.info("Packed texture. Reading directly from the blend file!");
Structure packedFile = pPackedFile.fetchData(dataRepository.getInputStream()).get(0); Structure packedFile = pPackedFile.fetchData(blenderContext.getInputStream()).get(0);
Pointer pData = (Pointer) packedFile.getFieldValue("data"); Pointer pData = (Pointer) packedFile.getFieldValue("data");
FileBlockHeader dataFileBlock = dataRepository.getFileBlock(pData.getOldMemoryAddress()); FileBlockHeader dataFileBlock = blenderContext.getFileBlock(pData.getOldMemoryAddress());
dataRepository.getInputStream().setPosition(dataFileBlock.getBlockPosition()); blenderContext.getInputStream().setPosition(dataFileBlock.getBlockPosition());
ImageLoader imageLoader = new ImageLoader(); ImageLoader imageLoader = new ImageLoader();
// Should the texture be flipped? It works for sinbad .. // Should the texture be flipped? It works for sinbad ..
Image im = imageLoader.loadImage(dataRepository.getInputStream(), dataFileBlock.getBlockPosition(), true); Image im = imageLoader.loadImage(blenderContext.getInputStream(), dataFileBlock.getBlockPosition(), true);
if (im != null) { if (im != null) {
result = new Texture2D(im); result = new Texture2D(im);
} }
@ -691,7 +691,7 @@ public class TextureHelper extends AbstractBlenderHelper {
if (result != null) { if (result != null) {
result.setName(texturePath); result.setName(texturePath);
result.setWrap(Texture.WrapMode.Repeat); result.setWrap(Texture.WrapMode.Repeat);
dataRepository.addLoadedFeatures(image.getOldMemoryAddress(), image.getName(), image, result); blenderContext.addLoadedFeatures(image.getOldMemoryAddress(), image.getName(), image, result);
} }
} }
return result; return result;
@ -702,12 +702,12 @@ public class TextureHelper extends AbstractBlenderHelper {
* *
* @param name * @param name
* the path to the image * the path to the image
* @param dataRepository * @param blenderContext
* the data repository * the blender context
* @return the loaded image or null if the image cannot be found * @return the loaded image or null if the image cannot be found
*/ */
protected Texture loadTextureFromFile(String name, DataRepository dataRepository) { protected Texture loadTextureFromFile(String name, BlenderContext blenderContext) {
AssetManager assetManager = dataRepository.getAssetManager(); AssetManager assetManager = blenderContext.getAssetManager();
name = name.replaceAll("\\\\", "\\/"); name = name.replaceAll("\\\\", "\\/");
Texture result = null; Texture result = null;
@ -715,7 +715,7 @@ public class TextureHelper extends AbstractBlenderHelper {
if (name.startsWith("//")) { if (name.startsWith("//")) {
String relativePath = name.substring(2); String relativePath = name.substring(2);
//augument the path with blender key path //augument the path with blender key path
BlenderKey blenderKey = dataRepository.getBlenderKey(); BlenderKey blenderKey = blenderContext.getBlenderKey();
int idx = blenderKey.getName().lastIndexOf('/'); int idx = blenderKey.getName().lastIndexOf('/');
String blenderAssetFolder = blenderKey.getName().substring(0, idx != -1 ? idx : 0); String blenderAssetFolder = blenderKey.getName().substring(0, idx != -1 ? idx : 0);
assetNames.add(blenderAssetFolder+'/'+relativePath); assetNames.add(blenderAssetFolder+'/'+relativePath);
@ -747,7 +747,7 @@ public class TextureHelper extends AbstractBlenderHelper {
} }
@Override @Override
public boolean shouldBeLoaded(Structure structure, DataRepository dataRepository) { public boolean shouldBeLoaded(Structure structure, BlenderContext blenderContext) {
return (dataRepository.getBlenderKey().getFeaturesToLoad() & FeaturesToLoad.TEXTURES) != 0; return (blenderContext.getBlenderKey().getFeaturesToLoad() & FeaturesToLoad.TEXTURES) != 0;
} }
} }
Loading…
Cancel
Save