From 9961f77445cad6f62d9389dff7d57a4e1b1a60ea Mon Sep 17 00:00:00 2001 From: "Kae..pl" Date: Mon, 29 Apr 2013 11:31:48 +0000 Subject: [PATCH] Code refactoring: - removed unused methods - added javadocs - minor name fixes - one constructor type for all helpers git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10585 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../blender/AbstractBlenderHelper.java | 12 +- .../scene/plugins/blender/BlenderContext.java | 63 +--------- .../scene/plugins/blender/BlenderLoader.java | 24 ++-- .../blender/animations/ArmatureHelper.java | 31 +---- .../blender/animations/BoneContext.java | 8 +- .../scene/plugins/blender/animations/Ipo.java | 9 -- .../plugins/blender/animations/IpoHelper.java | 13 +- .../plugins/blender/cameras/CameraHelper.java | 8 +- .../blender/constraints/ConstraintHelper.java | 36 ++---- .../blender/constraints/SimulationNode.java | 15 +-- .../definitions/ConstraintDefinition.java | 39 +++++- .../plugins/blender/curves/CurvesHelper.java | 8 +- .../plugins/blender/file/DnaBlockData.java | 2 +- .../plugins/blender/file/DynamicArray.java | 20 ---- .../scene/plugins/blender/file/Field.java | 2 +- .../plugins/blender/file/FileBlockHeader.java | 8 -- .../scene/plugins/blender/file/Structure.java | 15 +-- .../plugins/blender/lights/LightHelper.java | 8 +- .../blender/materials/MaterialContext.java | 19 +-- .../blender/materials/MaterialHelper.java | 113 ++---------------- .../plugins/blender/meshes/MeshBuilder.java | 5 + .../plugins/blender/meshes/MeshContext.java | 25 ---- .../plugins/blender/meshes/MeshHelper.java | 8 +- .../blender/modifiers/ArmatureModifier.java | 52 +++----- .../blender/modifiers/ArrayModifier.java | 5 - .../blender/modifiers/MirrorModifier.java | 5 - .../plugins/blender/modifiers/Modifier.java | 7 -- .../blender/modifiers/ModifierHelper.java | 11 +- .../modifiers/ObjectAnimationModifier.java | 5 - .../blender/modifiers/ParticlesModifier.java | 5 - .../plugins/blender/objects/ObjectHelper.java | 23 ++-- .../plugins/blender/objects/Properties.java | 16 --- .../blender/particles/ParticlesHelper.java | 8 +- .../blender/textures/TextureHelper.java | 11 +- .../textures/blending/TextureBlenderAWT.java | 1 + .../textures/generating/NoiseGenerator.java | 34 ++---- .../generating/TextureGeneratorFactory.java | 6 +- 37 files changed, 184 insertions(+), 496 deletions(-) diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/AbstractBlenderHelper.java b/engine/src/blender/com/jme3/scene/plugins/blender/AbstractBlenderHelper.java index 9e52e7ba3..dfe71bca1 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/AbstractBlenderHelper.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/AbstractBlenderHelper.java @@ -49,7 +49,8 @@ import com.jme3.scene.plugins.blender.objects.Properties; * @author Marcin Roguski */ public abstract class AbstractBlenderHelper { - + /** The blender context. */ + protected BlenderContext blenderContext; /** The version of the blend file. */ protected final int blenderVersion; /** This variable indicates if the Y asxis is the UP axis or not. */ @@ -62,12 +63,13 @@ public abstract class AbstractBlenderHelper { * versions. * @param blenderVersion * the version read from the blend file - * @param fixUpAxis - * a variable that indicates if the Y asxis is the UP axis or not + * @param blenderContext + * the blender context */ - public AbstractBlenderHelper(String blenderVersion, boolean fixUpAxis) { + public AbstractBlenderHelper(String blenderVersion, BlenderContext blenderContext) { this.blenderVersion = Integer.parseInt(blenderVersion); - this.fixUpAxis = fixUpAxis; + this.blenderContext = blenderContext; + this.fixUpAxis = blenderContext.getBlenderKey().isFixUpAxis(); if (fixUpAxis) { upAxisRotationQuaternion = new Quaternion().fromAngles(-FastMath.HALF_PI, 0, 0); } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/BlenderContext.java b/engine/src/blender/com/jme3/scene/plugins/blender/BlenderContext.java index b858c9727..22d5312aa 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/BlenderContext.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/BlenderContext.java @@ -54,7 +54,6 @@ import com.jme3.scene.plugins.blender.file.DnaBlockData; import com.jme3.scene.plugins.blender.file.FileBlockHeader; import com.jme3.scene.plugins.blender.file.Structure; import com.jme3.scene.plugins.blender.meshes.MeshContext; -import com.jme3.scene.plugins.blender.modifiers.Modifier; import com.jme3.scene.plugins.ogre.AnimData; /** @@ -101,8 +100,6 @@ public class BlenderContext { private Map loadedFeaturesByName = new HashMap(); /** A stack that hold the parent structure of currently loaded feature. */ private Stack parentStack = new Stack(); - /** A list of modifiers for the specified object. */ - protected Map> modifiers = new HashMap>(); /** A list of constraints for the specified object. */ protected Map> constraints = new HashMap>(); /** Anim data loaded for features. */ @@ -272,14 +269,6 @@ public class BlenderContext { return fileBlockHeadersByCode.get(code); } - /** - * This method clears the saved block headers stored in the features map. - */ - public void clearFileBlocks() { - fileBlockHeadersByOma.clear(); - fileBlockHeadersByCode.clear(); - } - /** * This method adds a helper instance to the helpers' map. * @@ -342,13 +331,6 @@ public class BlenderContext { return null; } - /** - * This method clears the saved features stored in the features map. - */ - public void clearLoadedFeatures() { - loadedFeatures.clear(); - } - /** * This method adds the structure to the parent stack. * @@ -386,48 +368,6 @@ public class BlenderContext { } } - /** - * This method adds a new modifier to the list. - * - * @param ownerOMA - * the owner's old memory address - * @param modifier - * the object's modifier - */ - public void addModifier(Long ownerOMA, Modifier modifier) { - List objectModifiers = this.modifiers.get(ownerOMA); - if (objectModifiers == null) { - objectModifiers = new ArrayList(); - this.modifiers.put(ownerOMA, objectModifiers); - } - objectModifiers.add(modifier); - } - - /** - * This method returns modifiers for the object specified by its old memory - * address and the modifier type. If no modifiers are found - empty list is - * returned. If the type is null - all modifiers for the object are - * returned. - * - * @param objectOMA - * object's old memory address - * @param type - * the type of the modifier - * @return the list of object's modifiers - */ - public List getModifiers(Long objectOMA, String type) { - List result = new ArrayList(); - List readModifiers = modifiers.get(objectOMA); - if (readModifiers != null && readModifiers.size() > 0) { - for (Modifier modifier : readModifiers) { - if (type == null || type.isEmpty() || modifier.getType().equals(type)) { - result.add(modifier); - } - } - } - return result; - } - /** * This method adds a new modifier to the list. * @@ -632,13 +572,14 @@ public class BlenderContext { loadedFeatures.clear(); loadedFeaturesByName.clear(); parentStack.clear(); - modifiers.clear(); constraints.clear(); animData.clear(); skeletons.clear(); meshContexts.clear(); boneContexts.clear(); helpers.clear(); + fileBlockHeadersByOma.clear(); + fileBlockHeadersByCode.clear(); } /** diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/BlenderLoader.java b/engine/src/blender/com/jme3/scene/plugins/blender/BlenderLoader.java index c7f5d19be..310fb51de 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/BlenderLoader.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/BlenderLoader.java @@ -195,18 +195,18 @@ public class BlenderLoader extends AbstractBlenderLoader { blenderContext.setBlenderKey(blenderKey); // creating helpers - blenderContext.putHelper(ArmatureHelper.class, new ArmatureHelper(inputStream.getVersionNumber(), blenderKey.isFixUpAxis())); - blenderContext.putHelper(TextureHelper.class, new TextureHelper(inputStream.getVersionNumber(), blenderKey.isFixUpAxis())); - blenderContext.putHelper(MeshHelper.class, new MeshHelper(inputStream.getVersionNumber(), blenderKey.isFixUpAxis())); - blenderContext.putHelper(ObjectHelper.class, new ObjectHelper(inputStream.getVersionNumber(), blenderKey.isFixUpAxis())); - blenderContext.putHelper(CurvesHelper.class, new CurvesHelper(inputStream.getVersionNumber(), blenderKey.isFixUpAxis())); - blenderContext.putHelper(LightHelper.class, new LightHelper(inputStream.getVersionNumber(), blenderKey.isFixUpAxis())); - blenderContext.putHelper(CameraHelper.class, new CameraHelper(inputStream.getVersionNumber(), blenderKey.isFixUpAxis())); - blenderContext.putHelper(ModifierHelper.class, new ModifierHelper(inputStream.getVersionNumber(), blenderKey.isFixUpAxis())); - blenderContext.putHelper(MaterialHelper.class, new MaterialHelper(inputStream.getVersionNumber(), blenderKey.isFixUpAxis())); - blenderContext.putHelper(ConstraintHelper.class, new ConstraintHelper(inputStream.getVersionNumber(), blenderContext, blenderKey.isFixUpAxis())); - blenderContext.putHelper(IpoHelper.class, new IpoHelper(inputStream.getVersionNumber(), blenderKey.isFixUpAxis())); - blenderContext.putHelper(ParticlesHelper.class, new ParticlesHelper(inputStream.getVersionNumber(), blenderKey.isFixUpAxis())); + blenderContext.putHelper(ArmatureHelper.class, new ArmatureHelper(inputStream.getVersionNumber(), blenderContext)); + blenderContext.putHelper(TextureHelper.class, new TextureHelper(inputStream.getVersionNumber(), blenderContext)); + blenderContext.putHelper(MeshHelper.class, new MeshHelper(inputStream.getVersionNumber(), blenderContext)); + blenderContext.putHelper(ObjectHelper.class, new ObjectHelper(inputStream.getVersionNumber(), blenderContext)); + blenderContext.putHelper(CurvesHelper.class, new CurvesHelper(inputStream.getVersionNumber(), blenderContext)); + blenderContext.putHelper(LightHelper.class, new LightHelper(inputStream.getVersionNumber(), blenderContext)); + blenderContext.putHelper(CameraHelper.class, new CameraHelper(inputStream.getVersionNumber(), blenderContext)); + blenderContext.putHelper(ModifierHelper.class, new ModifierHelper(inputStream.getVersionNumber(), blenderContext)); + blenderContext.putHelper(MaterialHelper.class, new MaterialHelper(inputStream.getVersionNumber(), blenderContext)); + blenderContext.putHelper(ConstraintHelper.class, new ConstraintHelper(inputStream.getVersionNumber(), blenderContext)); + blenderContext.putHelper(IpoHelper.class, new IpoHelper(inputStream.getVersionNumber(), blenderContext)); + blenderContext.putHelper(ParticlesHelper.class, new ParticlesHelper(inputStream.getVersionNumber(), blenderContext)); // reading the blocks (dna block is automatically saved in the blender context when found) FileBlockHeader sceneFileBlock = null; diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/animations/ArmatureHelper.java b/engine/src/blender/com/jme3/scene/plugins/blender/animations/ArmatureHelper.java index ad019d768..97c51b19f 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/animations/ArmatureHelper.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/animations/ArmatureHelper.java @@ -58,10 +58,7 @@ import com.jme3.scene.plugins.blender.file.Structure; public class ArmatureHelper extends AbstractBlenderHelper { private static final Logger LOGGER = Logger.getLogger(ArmatureHelper.class.getName()); - public static final String ARMETURE_NODE_MARKER = "armeture-node"; - - /** A map of bones and their old memory addresses. */ - private Map bonesOMAs = new HashMap(); + public static final String ARMATURE_NODE_MARKER = "armature-node"; /** * This constructor parses the given blender version and stores the result. @@ -69,11 +66,11 @@ public class ArmatureHelper extends AbstractBlenderHelper { * * @param blenderVersion * the version read from the blend file - * @param fixUpAxis - * a variable that indicates if the Y asxis is the UP axis or not + * @param blenderContext + * the blender context */ - public ArmatureHelper(String blenderVersion, boolean fixUpAxis) { - super(blenderVersion, fixUpAxis); + public ArmatureHelper(String blenderVersion, BlenderContext blenderContext) { + super(blenderVersion, blenderContext); } /** @@ -93,23 +90,7 @@ public class ArmatureHelper extends AbstractBlenderHelper { */ public void buildBones(Long armatureObjectOMA, Structure boneStructure, Bone parent, List result, Matrix4f objectToArmatureTransformation, BlenderContext blenderContext) throws BlenderFileException { BoneContext bc = new BoneContext(armatureObjectOMA, boneStructure, blenderContext); - bc.buildBone(result, bonesOMAs, objectToArmatureTransformation, blenderContext); - } - - /** - * This method returns the old memory address of a bone. If the bone does - * not exist in the blend file - zero is returned. - * - * @param bone - * the bone whose old memory address we seek - * @return the old memory address of the given bone - */ - public Long getBoneOMA(Bone bone) { - Long result = bonesOMAs.get(bone); - if (result == null) { - result = Long.valueOf(0); - } - return result; + bc.buildBone(result, objectToArmatureTransformation, blenderContext); } /** diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/animations/BoneContext.java b/engine/src/blender/com/jme3/scene/plugins/blender/animations/BoneContext.java index e98890cf1..aa443becc 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/animations/BoneContext.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/animations/BoneContext.java @@ -2,7 +2,6 @@ package com.jme3.scene.plugins.blender.animations; import java.util.ArrayList; import java.util.List; -import java.util.Map; import com.jme3.animation.Bone; import com.jme3.animation.Skeleton; @@ -105,19 +104,16 @@ public class BoneContext { * * @param bones * a list of bones where the newly created bone will be added - * @param boneOMAs - * the map between bone and its old memory address * @param objectToArmatureMatrix * object to armature transformation matrix * @param blenderContext * the blender context * @return newly created bone */ - public Bone buildBone(List bones, Map boneOMAs, Matrix4f objectToArmatureMatrix, BlenderContext blenderContext) { + public Bone buildBone(List bones, Matrix4f objectToArmatureMatrix, BlenderContext blenderContext) { Long boneOMA = boneStructure.getOldMemoryAddress(); bone = new Bone(boneName); bones.add(bone); - boneOMAs.put(bone, boneOMA); blenderContext.addLoadedFeatures(boneOMA, boneName, boneStructure, bone); Vector3f poseLocation = restMatrix.toTranslationVector(); @@ -132,7 +128,7 @@ public class BoneContext { bone.setBindTransforms(poseLocation, rotation, scale); for (BoneContext child : children) { - bone.addChild(child.buildBone(bones, boneOMAs, objectToArmatureMatrix, blenderContext)); + bone.addChild(child.buildBone(bones, objectToArmatureMatrix, blenderContext)); } return bone; diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/animations/Ipo.java b/engine/src/blender/com/jme3/scene/plugins/blender/animations/Ipo.java index a4c3b243d..4f6445794 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/animations/Ipo.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/animations/Ipo.java @@ -88,15 +88,6 @@ public class Ipo { return bezierCurves[curveIndex].evaluate(frame, BezierCurve.Y_VALUE); } - /** - * This method returns the curves amount. - * - * @return the curves amount - */ - public int getCurvesAmount() { - return bezierCurves.length; - } - /** * This method returns the frame where last bezier triple center point of * the specified bezier curve is located. diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/animations/IpoHelper.java b/engine/src/blender/com/jme3/scene/plugins/blender/animations/IpoHelper.java index 6e0d9961e..aed367e49 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/animations/IpoHelper.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/animations/IpoHelper.java @@ -29,11 +29,11 @@ public class IpoHelper extends AbstractBlenderHelper { * * @param blenderVersion * the version read from the blend file - * @param fixUpAxis - * a variable that indicates if the Y asxis is the UP axis or not + * @param blenderContext + * the blender context */ - public IpoHelper(String blenderVersion, boolean fixUpAxis) { - super(blenderVersion, fixUpAxis); + public IpoHelper(String blenderVersion, BlenderContext blenderContext) { + super(blenderVersion, blenderContext); } /** @@ -189,11 +189,6 @@ public class IpoHelper extends AbstractBlenderHelper { return constValue; } - @Override - public int getCurvesAmount() { - return 0; - } - @Override public BoneTrack calculateTrack(int boneIndex, Quaternion localQuaternionRotation, int startFrame, int stopFrame, int fps, boolean boneTrack) { throw new IllegalStateException("Constatnt ipo object cannot be used for calculating bone tracks!"); diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/cameras/CameraHelper.java b/engine/src/blender/com/jme3/scene/plugins/blender/cameras/CameraHelper.java index 044df1676..b219517ea 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/cameras/CameraHelper.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/cameras/CameraHelper.java @@ -26,11 +26,11 @@ public class CameraHelper extends AbstractBlenderHelper { * different blender versions. * @param blenderVersion * the version read from the blend file - * @param fixUpAxis - * a variable that indicates if the Y asxis is the UP axis or not + * @param blenderContext + * the blender context */ - public CameraHelper(String blenderVersion, boolean fixUpAxis) { - super(blenderVersion, fixUpAxis); + public CameraHelper(String blenderVersion, BlenderContext blenderContext) { + super(blenderVersion, blenderContext); } /** diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintHelper.java b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintHelper.java index ac1a26170..e2f3931e9 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintHelper.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/ConstraintHelper.java @@ -1,7 +1,6 @@ package com.jme3.scene.plugins.blender.constraints; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -40,26 +39,16 @@ public class ConstraintHelper extends AbstractBlenderHelper { private static final Quaternion POS_PARLOC_SPACE_QUATERNION = new Quaternion(new float[] { FastMath.HALF_PI, 0, 0 }); private static final Quaternion NEG_PARLOC_SPACE_QUATERNION = new Quaternion(new float[] { -FastMath.HALF_PI, 0, 0 }); - private BlenderContext blenderContext; - /** - * Helper constructor. It's main task is to generate the affection - * functions. These functions are common to all ConstraintHelper instances. - * Unfortunately this constructor might grow large. If it becomes too large - * - I shall consider refactoring. The constructor parses the given blender - * version and stores the result. Some functionalities may differ in - * different blender versions. + * Helper constructor. * * @param blenderVersion * the version read from the blend file * @param blenderContext * the blender context - * @param fixUpAxis - * a variable that indicates if the Y asxis is the UP axis or not */ - public ConstraintHelper(String blenderVersion, BlenderContext blenderContext, boolean fixUpAxis) { - super(blenderVersion, fixUpAxis); - this.blenderContext = blenderContext; + public ConstraintHelper(String blenderVersion, BlenderContext blenderContext) { + super(blenderVersion, blenderContext); } /** @@ -231,16 +220,14 @@ public class ConstraintHelper extends AbstractBlenderHelper { */ public Transform getTransform(Long oma, String subtargetName, Space space) { Spatial feature = (Spatial) blenderContext.getLoadedFeature(oma, LoadedFeatureDataType.LOADED_FEATURE); - boolean isArmature = feature.getUserData(ArmatureHelper.ARMETURE_NODE_MARKER) != null; + boolean isArmature = feature.getUserData(ArmatureHelper.ARMATURE_NODE_MARKER) != null; if (isArmature) { BoneContext targetBoneContext = blenderContext.getBoneByName(subtargetName); Bone bone = targetBoneContext.getBone(); switch (space) { case CONSTRAINT_SPACE_WORLD: - Transform t = new Transform(bone.getModelSpacePosition(), bone.getModelSpaceRotation(), bone.getModelSpaceScale()); - System.out.println("A: " + Arrays.toString(t.getRotation().toAngles(null))); - return t; + return new Transform(bone.getModelSpacePosition(), bone.getModelSpaceRotation(), bone.getModelSpaceScale()); case CONSTRAINT_SPACE_LOCAL: Transform localTransform = new Transform(bone.getLocalPosition(), bone.getLocalRotation()); localTransform.setScale(bone.getLocalScale()); @@ -264,8 +251,9 @@ public class ConstraintHelper extends AbstractBlenderHelper { if (bone.getParent() != null) { Bone parent = bone.getParent(); parentLocalMatrix = this.toMatrix(parent.getLocalPosition(), parent.getLocalRotation(), parent.getLocalScale()); - } else {// we need to clone it because otherwise we could - // spoil the IDENTITY matrix + } else { + // we need to clone it because otherwise we could spoil + // the IDENTITY matrix parentLocalMatrix = parentLocalMatrix.clone(); } Matrix4f boneLocalMatrix = this.toMatrix(bone.getLocalPosition(), bone.getLocalRotation(), bone.getLocalScale()); @@ -309,7 +297,7 @@ public class ConstraintHelper extends AbstractBlenderHelper { */ public void applyTransform(Long oma, String subtargetName, Space space, Transform transform) { Spatial feature = (Spatial) blenderContext.getLoadedFeature(oma, LoadedFeatureDataType.LOADED_FEATURE); - boolean isArmature = feature.getUserData(ArmatureHelper.ARMETURE_NODE_MARKER) != null; + boolean isArmature = feature.getUserData(ArmatureHelper.ARMATURE_NODE_MARKER) != null; if (isArmature) { Skeleton skeleton = blenderContext.getSkeleton(oma); BoneContext targetBoneContext = blenderContext.getBoneByName(subtargetName); @@ -324,7 +312,6 @@ public class ConstraintHelper extends AbstractBlenderHelper { bone.setBindTransforms(transform.getTranslation(), transform.getRotation(), transform.getScale()); break; case CONSTRAINT_SPACE_WORLD: - System.out.println("B: " + Arrays.toString(transform.getRotation().toAngles(null))); Matrix4f boneMatrix = this.toMatrix(transform); Bone parent = bone.getParent(); if (parent != null) { @@ -352,8 +339,9 @@ public class ConstraintHelper extends AbstractBlenderHelper { if (bone.getParent() != null) { parentLocalMatrix = this.toMatrix(bone.getParent().getLocalPosition(), bone.getParent().getLocalRotation(), bone.getParent().getLocalScale()); parentLocalMatrix.invertLocal(); - } else {// we need to clone it because otherwise we could - // spoil the IDENTITY matrix + } else { + // we need to clone it because otherwise we could + // spoil the IDENTITY matrix parentLocalMatrix = parentLocalMatrix.clone(); } Matrix4f m = this.toMatrix(transform.getTranslation(), transform.getRotation(), transform.getScale()); diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/SimulationNode.java b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/SimulationNode.java index 70f1c1d8c..170e88b30 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/SimulationNode.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/SimulationNode.java @@ -43,8 +43,6 @@ public class SimulationNode { private String name; /** A list of children for the node (either bones or child spatials). */ private List children = new ArrayList(); - /** A virtual track for each of the nodes. */ - private Map virtualTrack = new HashMap(); /** A list of constraints that the current node has. */ private List constraints; /** A list of node's animations. */ @@ -91,7 +89,7 @@ public class SimulationNode { */ private SimulationNode(Long featureOMA, BlenderContext blenderContext, boolean rootNode) { Node spatial = (Node) blenderContext.getLoadedFeature(featureOMA, LoadedFeatureDataType.LOADED_FEATURE); - if (spatial.getUserData(ArmatureHelper.ARMETURE_NODE_MARKER) != null) { + if (spatial.getUserData(ArmatureHelper.ARMATURE_NODE_MARKER) != null) { this.skeleton = blenderContext.getSkeleton(featureOMA); Node nodeWithAnimationControl = blenderContext.getControlledNode(skeleton); @@ -206,7 +204,6 @@ public class SimulationNode { float maxTime = animationTimeBoundaries[1]; VirtualTrack vTrack = new VirtualTrack(maxFrame, maxTime); - virtualTrack.put(animation.getName(), vTrack); for (Track track : animation.getTracks()) { for (int frame = 0; frame < maxFrame; ++frame) { spatial.setLocalTranslation(((SpatialTrack) track).getTranslations()[frame]); @@ -260,11 +257,11 @@ public class SimulationNode { Map tracks = new HashMap(); Map previousTransforms = new HashMap(); for (int frame = 0; frame < maxFrame; ++frame) { - this.reset();// this MUST be done here, otherwise - // setting next frame of animation will - // lead to possible errors - // first set proper time for all bones in all the tracks - // ... + // this MUST be done here, otherwise setting next frame of animation will + // lead to possible errors + this.reset(); + + // first set proper time for all bones in all the tracks ... for (Track track : animation.getTracks()) { float time = ((BoneTrack) track).getTimes()[frame]; Integer boneIndex = ((BoneTrack) track).getTargetBoneIndex(); diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinition.java b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinition.java index 4ff0b15b5..fa1b651cd 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinition.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinition.java @@ -5,12 +5,32 @@ import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.BlenderContext.LoadedFeatureDataType; import com.jme3.scene.plugins.blender.file.Structure; +/** + * A base class for all constraint definitions. + * + * @author Marcin Roguski (Kaelthas) + */ public abstract class ConstraintDefinition { + /** Constraints flag. Used to load user's options applied to the constraint. */ protected int flag; + /** The constraint's owner. Loaded during runtime. */ private Object owner; + /** The blender context. */ private BlenderContext blenderContext; + /** The constraint's owner OMA. */ private Long ownerOMA; + /** + * Loads a constraint definition based on the constraint definition + * structure. + * + * @param constraintData + * the constraint definition structure + * @param ownerOMA + * the constraint's owner OMA + * @param blenderContext + * the blender context + */ public ConstraintDefinition(Structure constraintData, Long ownerOMA, BlenderContext blenderContext) { if (constraintData != null) {// Null constraint has no data Number flag = (Number) constraintData.getFieldValue("flag"); @@ -29,7 +49,7 @@ public abstract class ConstraintDefinition { * * @return the owner of the constraint or null if none is set */ - public Object getOwner() { + protected Object getOwner() { if (ownerOMA != null && owner == null) { owner = blenderContext.getLoadedFeature(ownerOMA, LoadedFeatureDataType.LOADED_FEATURE); if (owner == null) { @@ -39,11 +59,28 @@ public abstract class ConstraintDefinition { return owner; } + /** + * @return true if the definition is implemented and false + * otherwise + */ public boolean isImplemented() { return true; } + /** + * @return the type name of the constraint + */ public abstract String getConstraintTypeName(); + /** + * Bakes the constraint for the current feature (bone or spatial) position. + * + * @param ownerTransform + * the input transform (here the result is stored) + * @param targetTransform + * the target transform used by some of the constraints + * @param influence + * the influence of the constraint (from range <0; 1>) + */ public abstract void bake(Transform ownerTransform, Transform targetTransform, float influence); } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/curves/CurvesHelper.java b/engine/src/blender/com/jme3/scene/plugins/blender/curves/CurvesHelper.java index 2171e12ec..97bcab1f9 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/curves/CurvesHelper.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/curves/CurvesHelper.java @@ -89,11 +89,11 @@ public class CurvesHelper extends AbstractBlenderHelper { * different blender versions. * @param blenderVersion * the version read from the blend file - * @param fixUpAxis - * a variable that indicates if the Y asxis is the UP axis or not + * @param blenderContext + * the blender context */ - public CurvesHelper(String blenderVersion, boolean fixUpAxis) { - super(blenderVersion, fixUpAxis); + public CurvesHelper(String blenderVersion, BlenderContext blenderContext) { + super(blenderVersion, blenderContext); } /** diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/file/DnaBlockData.java b/engine/src/blender/com/jme3/scene/plugins/blender/file/DnaBlockData.java index 23efda54b..ae75a2414 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/file/DnaBlockData.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/file/DnaBlockData.java @@ -38,7 +38,7 @@ import java.util.Map; /** * The data block containing the description of the file. - * @author Marcin Roguski + * @author Marcin Roguski (Kaelthas) */ public class DnaBlockData { diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/file/DynamicArray.java b/engine/src/blender/com/jme3/scene/plugins/blender/file/DynamicArray.java index 1cda607d3..01b79c146 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/file/DynamicArray.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/file/DynamicArray.java @@ -50,26 +50,6 @@ public class DynamicArray implements Cloneable { */ private int[] tableSizes; - /** - * Constructor. Builds an empty array of the specified sizes. - * @param tableSizes - * the sizes of the table - * @throws BlenderFileException - * an exception is thrown if one of the sizes is not a positive number - */ - @SuppressWarnings("unchecked") - public DynamicArray(int[] tableSizes) throws BlenderFileException { - this.tableSizes = tableSizes; - int totalSize = 1; - for (int size : tableSizes) { - if (size <= 0) { - throw new BlenderFileException("The size of the table must be positive!"); - } - totalSize *= size; - } - this.array = (T[]) new Object[totalSize]; - } - /** * Constructor. Builds an empty array of the specified sizes. * @param tableSizes diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/file/Field.java b/engine/src/blender/com/jme3/scene/plugins/blender/file/Field.java index 8b085c689..2600c3d66 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/file/Field.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/file/Field.java @@ -281,7 +281,7 @@ class Field implements Cloneable { * This method builds the full name of the field (with function, pointer and table indications). * @return the full name of the field */ - public String getFullName() { + /*package*/ String getFullName() { StringBuilder result = new StringBuilder(); if (function) { result.append('('); diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/file/FileBlockHeader.java b/engine/src/blender/com/jme3/scene/plugins/blender/file/FileBlockHeader.java index 079da5001..de4da7afa 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/file/FileBlockHeader.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/file/FileBlockHeader.java @@ -129,14 +129,6 @@ public class FileBlockHeader { return size; } - /** - * This method returns the memory address. - * @return the memory address - */ - public long getOldMemoryAddress() { - return oldMemoryAddress; - } - /** * This method returns the sdna index. * @return the sdna index diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/file/Structure.java b/engine/src/blender/com/jme3/scene/plugins/blender/file/Structure.java index bc4f11600..91e433f3d 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/file/Structure.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/file/Structure.java @@ -206,16 +206,6 @@ public class Structure implements Cloneable { return fields.length; } - /** - * This method returns the field name of the given index. - * @param fieldIndex - * the index of the field - * @return the field name of the given index - */ - public String getFieldName(int fieldIndex) { - return fields[fieldIndex].name; - } - /** * This method returns the full field name of the given index. * @param fieldIndex @@ -278,10 +268,9 @@ public class Structure implements Cloneable { /** * This enum enumerates all known data types that can be found in the blend file. - * @author Marcin Roguski + * @author Marcin Roguski (Kaelthas) */ - /* package */ - static enum DataType { + /* package */ static enum DataType { CHARACTER, SHORT, INTEGER, LONG, FLOAT, DOUBLE, VOID, STRUCTURE, POINTER; /** The map containing the known primary types. */ diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/lights/LightHelper.java b/engine/src/blender/com/jme3/scene/plugins/blender/lights/LightHelper.java index 9d2df52ef..6ea24d5cd 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/lights/LightHelper.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/lights/LightHelper.java @@ -60,11 +60,11 @@ public class LightHelper extends AbstractBlenderHelper { * different blender versions. * @param blenderVersion * the version read from the blend file - * @param fixUpAxis - * a variable that indicates if the Y asxis is the UP axis or not + * @param blenderContext + * the blender context */ - public LightHelper(String blenderVersion, boolean fixUpAxis) { - super(blenderVersion, fixUpAxis); + public LightHelper(String blenderVersion, BlenderContext blenderContext) { + super(blenderVersion, blenderContext); } public LightNode toLight(Structure structure, BlenderContext blenderContext) throws BlenderFileException { diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/materials/MaterialContext.java b/engine/src/blender/com/jme3/scene/plugins/blender/materials/MaterialContext.java index 5e0ee83a0..c9a3f16d9 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/materials/MaterialContext.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/materials/MaterialContext.java @@ -164,6 +164,18 @@ public final class MaterialContext { this.transparent = transparent; } + /** + * Applies material to a given geometry. + * + * @param geometry + * the geometry + * @param geometriesOMA + * the geometries OMA + * @param userDefinedUVCoordinates + * UV coords defined by user + * @param blenderContext + * the blender context + */ public void applyMaterial(Geometry geometry, Long geometriesOMA, List userDefinedUVCoordinates, BlenderContext blenderContext) { Material material = null; if (shadeless) { @@ -326,13 +338,6 @@ public final class MaterialContext { this.faceCullMode = faceCullMode; } - /** - * @return the face cull mode - */ - public FaceCullMode getFaceCullMode() { - return faceCullMode; - } - /** * This method returns the diffuse color. * diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/materials/MaterialHelper.java b/engine/src/blender/com/jme3/scene/plugins/blender/materials/MaterialHelper.java index 9a99f998a..f02916684 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/materials/MaterialHelper.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/materials/MaterialHelper.java @@ -31,9 +31,15 @@ */ package com.jme3.scene.plugins.blender.materials; +import java.nio.ByteBuffer; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + import com.jme3.asset.BlenderKey.FeaturesToLoad; import com.jme3.material.MatParam; -import com.jme3.material.MatParamTexture; import com.jme3.material.Material; import com.jme3.math.ColorRGBA; import com.jme3.math.FastMath; @@ -48,13 +54,6 @@ import com.jme3.texture.Image; import com.jme3.texture.Image.Format; import com.jme3.texture.Texture; import com.jme3.util.BufferUtils; -import java.nio.ByteBuffer; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.logging.Level; -import java.util.logging.Logger; public class MaterialHelper extends AbstractBlenderHelper { private static final Logger LOGGER = Logger.getLogger(MaterialHelper.class.getName()); @@ -93,11 +92,11 @@ public class MaterialHelper extends AbstractBlenderHelper { * * @param blenderVersion * the version read from the blend file - * @param fixUpAxis - * a variable that indicates if the Y asxis is the UP axis or not + * @param blenderContext + * the blender context */ - public MaterialHelper(String blenderVersion, boolean fixUpAxis) { - super(blenderVersion, false); + public MaterialHelper(String blenderVersion, BlenderContext blenderContext) { + super(blenderVersion, blenderContext); // setting alpha masks alphaMasks.put(ALPHA_MASK_NONE, new IAlphaMask() { public void setImageSize(int width, int height) { @@ -174,49 +173,6 @@ public class MaterialHelper extends AbstractBlenderHelper { return result; } - /** - * This method returns a material similar to the one given but without textures. If the material has no textures it is not cloned but - * returned itself. - * - * @param material - * a material to be cloned without textures - * @param imageType - * type of image defined by blender; the constants are defined in TextureHelper - * @return material without textures of a specified type - */ - public Material getNonTexturedMaterial(Material material, int imageType) { - String[] textureParamNames = new String[] { TEXTURE_TYPE_DIFFUSE, TEXTURE_TYPE_NORMAL, TEXTURE_TYPE_GLOW, TEXTURE_TYPE_SPECULAR, TEXTURE_TYPE_ALPHA }; - Map textures = new HashMap(textureParamNames.length); - for (String textureParamName : textureParamNames) { - MatParamTexture matParamTexture = material.getTextureParam(textureParamName); - if (matParamTexture != null) { - textures.put(textureParamName, matParamTexture.getTextureValue()); - } - } - if (textures.isEmpty()) { - return material; - } else { - // clear all textures first so that wo de not waste resources cloning them - for (Entry textureParamName : textures.entrySet()) { - String name = textureParamName.getValue().getName(); - try { - int type = Integer.parseInt(name); - if (type == imageType) { - material.clearParam(textureParamName.getKey()); - } - } catch (NumberFormatException e) { - LOGGER.log(Level.WARNING, "The name of the texture does not contain the texture type value! {0} will not be removed!", name); - } - } - Material result = material.clone(); - // put the textures back in place - for (Entry textureEntry : textures.entrySet()) { - material.setTexture(textureEntry.getKey(), textureEntry.getValue()); - } - return result; - } - } - /** * This method converts the given material into particles-usable material. * The texture and glow color are being copied. @@ -269,53 +225,6 @@ public class MaterialHelper extends AbstractBlenderHelper { return result; } - /** - * This method indicates if the material has any kind of texture. - * - * @param material - * the material - * @return true if the texture exists in the material and false otherwise - */ - public boolean hasTexture(Material material) { - if (material != null) { - if (material.getTextureParam(TEXTURE_TYPE_ALPHA) != null) { - return true; - } - if (material.getTextureParam(TEXTURE_TYPE_COLOR) != null) { - return true; - } - if (material.getTextureParam(TEXTURE_TYPE_DIFFUSE) != null) { - return true; - } - if (material.getTextureParam(TEXTURE_TYPE_GLOW) != null) { - return true; - } - if (material.getTextureParam(TEXTURE_TYPE_NORMAL) != null) { - return true; - } - if (material.getTextureParam(TEXTURE_TYPE_SPECULAR) != null) { - return true; - } - } - return false; - } - - /** - * This method indicates if the material has a texture of a specified type. - * - * @param material - * the material - * @param textureType - * the type of the texture - * @return true if the texture exists in the material and false otherwise - */ - public boolean hasTexture(Material material, String textureType) { - if (material != null) { - return material.getTextureParam(textureType) != null; - } - return false; - } - /** * This method returns the table of materials connected to the specified structure. The given structure can be of any type (ie. mesh or * curve) but needs to have 'mat' field/ diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshBuilder.java b/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshBuilder.java index cac38ff66..6280deaae 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshBuilder.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshBuilder.java @@ -12,6 +12,11 @@ import com.jme3.math.Vector2f; import com.jme3.math.Vector3f; import com.jme3.util.BufferUtils; +/** + * A builder class for meshes. + * + * @author Marcin Roguski (Kaelthas) + */ /*package*/class MeshBuilder { private static final Logger LOGGER = Logger.getLogger(MeshBuilder.class.getName()); diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshContext.java b/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshContext.java index 8e373be34..c3045195c 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshContext.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshContext.java @@ -18,8 +18,6 @@ public class MeshContext { private Map geometries = new HashMap(); /** The vertex reference map. */ private Map>> vertexReferenceMap; - /** The UV-coordinates for each of the geometries. */ - private Map uvCoordinates = new HashMap(); /** Bind buffer for vertices is stored here and applied when required. */ private Map bindPoseBuffer = new HashMap(); /** Bind buffer for normals is stored here and applied when required. */ @@ -81,29 +79,6 @@ public class MeshContext { this.vertexReferenceMap = vertexReferenceMap; } - /** - * This method adds the mesh's UV-coordinates. - * - * @param geometry - * the mesh that has the UV-coordinates - * @param vertexBuffer - * the mesh's UV-coordinates - */ - public void addUVCoordinates(Geometry geometry, VertexBuffer vertexBuffer) { - uvCoordinates.put(geometry, vertexBuffer); - } - - /** - * This method returns the mesh's UV-coordinates. - * - * @param geometry - * the mesh - * @return the mesh's UV-coordinates - */ - public VertexBuffer getUVCoordinates(Geometry geometry) { - return uvCoordinates.get(geometry); - } - /** * This method sets the bind buffer for vertices. * diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshHelper.java b/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshHelper.java index 75a2c9ac8..30ec799d8 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshHelper.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshHelper.java @@ -71,11 +71,11 @@ public class MeshHelper extends AbstractBlenderHelper { * * @param blenderVersion * the version read from the blend file - * @param fixUpAxis - * a variable that indicates if the Y asxis is the UP axis or not + * @param blenderContext + * the blender context */ - public MeshHelper(String blenderVersion, boolean fixUpAxis) { - super(blenderVersion, fixUpAxis); + public MeshHelper(String blenderVersion, BlenderContext blenderContext) { + super(blenderVersion, blenderContext); } /** diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java index 8237a91bc..8b1e029fe 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java @@ -28,6 +28,7 @@ import com.jme3.scene.VertexBuffer.Usage; import com.jme3.scene.plugins.blender.BlenderContext; import com.jme3.scene.plugins.blender.BlenderContext.LoadedFeatureDataType; import com.jme3.scene.plugins.blender.animations.ArmatureHelper; +import com.jme3.scene.plugins.blender.animations.BoneContext; import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; import com.jme3.scene.plugins.blender.file.FileBlockHeader; import com.jme3.scene.plugins.blender.file.Pointer; @@ -72,9 +73,7 @@ import com.jme3.util.BufferUtils; */ public ArmatureModifier(Structure objectStructure, Structure modifierStructure, BlenderContext blenderContext) throws BlenderFileException { Structure meshStructure = ((Pointer) objectStructure.getFieldValue("data")).fetchData(blenderContext.getInputStream()).get(0); - Pointer pDvert = (Pointer) meshStructure.getFieldValue("dvert");// dvert - // = - // DeformVERTices + Pointer pDvert = (Pointer) meshStructure.getFieldValue("dvert");// dvert = DeformVERTices // if pDvert==null then there are not vertex groups and no need to load // skeleton (untill bone envelopes are supported) @@ -162,9 +161,12 @@ import com.jme3.util.BufferUtils; // store the animation data for each bone for (Bone bone : bones) { - Long boneOma = armatureHelper.getBoneOMA(bone); - if (boneOma != null) { - blenderContext.setAnimData(boneOma, animData); + if(bone.getName().length() > 0) { + BoneContext boneContext = blenderContext.getBoneContext(bone); + Long boneOma = boneContext.getBoneOma(); + if (boneOma != null) { + blenderContext.setAnimData(boneOma, animData); + } } } } else { @@ -300,39 +302,18 @@ import com.jme3.util.BufferUtils; if (pDvert.isNotNull()) {// assigning weights and bone indices boolean warnAboutTooManyVertexWeights = false; - List dverts = pDvert.fetchData(blenderContext.getInputStream());// dverts.size() - // == - // verticesAmount - // (one - // dvert - // per - // vertex - // in - // blender) + // dverts.size() = verticesAmount (one dvert per vertex in blender) + List dverts = pDvert.fetchData(blenderContext.getInputStream()); int vertexIndex = 0; // use tree map to sort weights from the lowest to the highest ones TreeMap weightToIndexMap = new TreeMap(); for (Structure dvert : dverts) { - List vertexIndices = vertexReferenceMap.get(Integer.valueOf(vertexIndex));// we - // fetch - // the - // referenced - // vertices - // here + //we fetch the referenced vertices here + List vertexIndices = vertexReferenceMap.get(Integer.valueOf(vertexIndex)); if (vertexIndices != null) { - int totweight = ((Number) dvert.getFieldValue("totweight")).intValue();// total - // amount - // of - // weights - // assignet - // to - // the - // vertex - // (max. - // 4 - // in - // JME) + // total amount of wights assigned to the vertex (max. 4 in JME) + int totweight = ((Number) dvert.getFieldValue("totweight")).intValue(); Pointer pDW = (Pointer) dvert.getFieldValue("dw"); if (totweight > 0 && groupToBoneIndexMap != null) { weightToIndexMap.clear(); @@ -448,9 +429,4 @@ import com.jme3.util.BufferUtils; } weightsFloatData.rewind(); } - - @Override - public String getType() { - return Modifier.ARMATURE_MODIFIER_DATA; - } } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArrayModifier.java b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArrayModifier.java index 78e5c6def..51e32a0b5 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArrayModifier.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArrayModifier.java @@ -239,9 +239,4 @@ import java.util.logging.Logger; } return node; } - - @Override - public String getType() { - return ARRAY_MODIFIER_DATA; - } } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/MirrorModifier.java b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/MirrorModifier.java index fbce73f25..ba807271f 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/MirrorModifier.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/MirrorModifier.java @@ -192,9 +192,4 @@ import com.jme3.scene.plugins.blender.objects.ObjectHelper; } return node; } - - @Override - public String getType() { - return Modifier.MIRROR_MODIFIER_DATA; - } } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/Modifier.java b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/Modifier.java index 862c0256b..513d56b26 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/Modifier.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/Modifier.java @@ -41,13 +41,6 @@ public abstract class Modifier { */ public abstract Node apply(Node node, BlenderContext blenderContext); - /** - * This method returns blender's type of modifier. - * - * @return blender's type of modifier - */ - public abstract String getType(); - /** * Determines if the modifier can be applied multiple times over one mesh. * At this moment only armature and object animation modifiers cannot be diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ModifierHelper.java b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ModifierHelper.java index 815ce6a25..a7e7c589f 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ModifierHelper.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ModifierHelper.java @@ -61,11 +61,11 @@ public class ModifierHelper extends AbstractBlenderHelper { * * @param blenderVersion * the version read from the blend file - * @param fixUpAxis - * a variable that indicates if the Y asxis is the UP axis or not + * @param blenderContext + * the blender context */ - public ModifierHelper(String blenderVersion, boolean fixUpAxis) { - super(blenderVersion, fixUpAxis); + public ModifierHelper(String blenderVersion, BlenderContext blenderContext) { + super(blenderVersion, blenderContext); } /** @@ -103,7 +103,6 @@ public class ModifierHelper extends AbstractBlenderHelper { if (modifier != null) { if (modifier.isModifying()) { result.add(modifier); - blenderContext.addModifier(objectStructure.getOldMemoryAddress(), modifier); alreadyReadModifiers.add(modifierType); } else { LOGGER.log(Level.WARNING, "The modifier {0} will cause no changes in the model. It will be ignored!", modifierStructure.getName()); @@ -155,7 +154,6 @@ public class ModifierHelper extends AbstractBlenderHelper { Ipo ipo = ipoHelper.fromIpoStructure(ipoStructure, blenderContext); if (ipo != null) { result = new ObjectAnimationModifier(ipo, objectStructure.getName(), objectStructure.getOldMemoryAddress(), blenderContext); - blenderContext.addModifier(objectStructure.getOldMemoryAddress(), result); } } return result; @@ -186,7 +184,6 @@ public class ModifierHelper extends AbstractBlenderHelper { Ipo ipo = ipoHelper.fromAction(actionStructure, blenderContext); if (ipo != null) {// ipo can be null if it has no curves applied, ommit such modifier then result = new ObjectAnimationModifier(ipo, actionStructure.getName(), objectStructure.getOldMemoryAddress(), blenderContext); - blenderContext.addModifier(objectStructure.getOldMemoryAddress(), result); } } } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ObjectAnimationModifier.java b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ObjectAnimationModifier.java index 0e0030d19..4dee2246e 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ObjectAnimationModifier.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ObjectAnimationModifier.java @@ -86,9 +86,4 @@ import com.jme3.scene.plugins.ogre.AnimData; } return node; } - - @Override - public String getType() { - return Modifier.OBJECT_ANIMATION_MODIFIER_DATA; - } } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ParticlesModifier.java b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ParticlesModifier.java index 5ce04a70d..5239c378e 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ParticlesModifier.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ParticlesModifier.java @@ -92,9 +92,4 @@ import java.util.logging.Logger; node.attachChild(emitter); return node; } - - @Override - public String getType() { - return Modifier.PARTICLE_MODIFIER_DATA; - } } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/objects/ObjectHelper.java b/engine/src/blender/com/jme3/scene/plugins/blender/objects/ObjectHelper.java index 58af0e94f..5b13ddce2 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/objects/ObjectHelper.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/objects/ObjectHelper.java @@ -90,11 +90,11 @@ public class ObjectHelper extends AbstractBlenderHelper { * * @param blenderVersion * the version read from the blend file - * @param fixUpAxis - * a variable that indicates if the Y asxis is the UP axis or not + * @param blenderContext + * the blender context */ - public ObjectHelper(String blenderVersion, boolean fixUpAxis) { - super(blenderVersion, fixUpAxis); + public ObjectHelper(String blenderVersion, BlenderContext blenderContext) { + super(blenderVersion, blenderContext); } /** @@ -214,7 +214,7 @@ public class ObjectHelper extends AbstractBlenderHelper { // parent-children relationships between nodes Node armature = new Node(name); armature.setLocalTransform(t); - armature.setUserData(ArmatureHelper.ARMETURE_NODE_MARKER, Boolean.TRUE); + armature.setUserData(ArmatureHelper.ARMATURE_NODE_MARKER, Boolean.TRUE); if (parent instanceof Node) { ((Node) parent).attachChild(armature); @@ -229,9 +229,9 @@ public class ObjectHelper extends AbstractBlenderHelper { } if (result != null) { - result.updateModelBound();// I prefer do compute bounding box here - // than read it from the file - + // I prefer do compute bounding box here than read it from the file + result.updateModelBound(); + blenderContext.addLoadedFeatures(objectStructure.getOldMemoryAddress(), name, objectStructure, result); // TODO: this data is only to help during loading, shall I remove it // after all the loading is done ??? @@ -341,11 +341,8 @@ public class ObjectHelper extends AbstractBlenderHelper { public Matrix4f getMatrix(Structure structure, String matrixName, boolean applyFixUpAxis) { Matrix4f result = new Matrix4f(); DynamicArray obmat = (DynamicArray) structure.getFieldValue(matrixName); - int rowAndColumnSize = Math.abs((int) Math.sqrt(obmat.getTotalSize()));// the - // matrix - // must - // be - // square + //the matrix must be square + int rowAndColumnSize = Math.abs((int) Math.sqrt(obmat.getTotalSize())); for (int i = 0; i < rowAndColumnSize; ++i) { for (int j = 0; j < rowAndColumnSize; ++j) { result.set(i, j, obmat.get(j, i).floatValue()); diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/objects/Properties.java b/engine/src/blender/com/jme3/scene/plugins/blender/objects/Properties.java index d003f28ad..9732ddc5a 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/objects/Properties.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/objects/Properties.java @@ -163,22 +163,6 @@ public class Properties implements Cloneable { return name; } - /** - * This method returns the description of the property. - * @return the description of the property - */ - public String getDescription() { - return description; - } - - /** - * This method returns the type of the property. - * @return the type of the property - */ - public int getType() { - return type; - } - /** * This method returns the value of the property. * The type of the value depends on the type of the property. diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/particles/ParticlesHelper.java b/engine/src/blender/com/jme3/scene/plugins/blender/particles/ParticlesHelper.java index 784197e49..29f4dc974 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/particles/ParticlesHelper.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/particles/ParticlesHelper.java @@ -86,11 +86,11 @@ public class ParticlesHelper extends AbstractBlenderHelper { * different blender versions. * @param blenderVersion * the version read from the blend file - * @param fixUpAxis - * a variable that indicates if the Y asxis is the UP axis or not + * @param blenderContext + * the blender context */ - public ParticlesHelper(String blenderVersion, boolean fixUpAxis) { - super(blenderVersion, fixUpAxis); + public ParticlesHelper(String blenderVersion, BlenderContext blenderContext) { + super(blenderVersion, blenderContext); } @SuppressWarnings("unchecked") diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureHelper.java b/engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureHelper.java index 0b907c95d..815c50498 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureHelper.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureHelper.java @@ -99,7 +99,7 @@ public class TextureHelper extends AbstractBlenderHelper { public static final int TEX_VOXELDATA = 15; // v. // 25+ - private TextureGeneratorFactory textureGeneratorFactory; + private TextureGeneratorFactory textureGeneratorFactory = new TextureGeneratorFactory(); /** * This constructor parses the given blender version and stores the result. @@ -107,12 +107,11 @@ public class TextureHelper extends AbstractBlenderHelper { * * @param blenderVersion * the version read from the blend file - * @param fixUpAxis - * a variable that indicates if the Y asxis is the UP axis or not + * @param blenderContext + * the blender context */ - public TextureHelper(String blenderVersion, boolean fixUpAxis) { - super(blenderVersion, false); - textureGeneratorFactory = new TextureGeneratorFactory(blenderVersion); + public TextureHelper(String blenderVersion, BlenderContext blenderContext) { + super(blenderVersion, blenderContext); } /** diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/textures/blending/TextureBlenderAWT.java b/engine/src/blender/com/jme3/scene/plugins/blender/textures/blending/TextureBlenderAWT.java index 78789a968..b1ea2bb4b 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/textures/blending/TextureBlenderAWT.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/textures/blending/TextureBlenderAWT.java @@ -51,6 +51,7 @@ public class TextureBlenderAWT extends AbstractTextureBlender { super(flag, negateTexture, blendType, materialColor, color, blendFactor); } + @Override public Image blend(Image image, Image baseImage, BlenderContext blenderContext) { this.prepareImagesForBlending(image, baseImage); diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/textures/generating/NoiseGenerator.java b/engine/src/blender/com/jme3/scene/plugins/blender/textures/generating/NoiseGenerator.java index 91df1bf11..1ba0b0b17 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/textures/generating/NoiseGenerator.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/textures/generating/NoiseGenerator.java @@ -31,11 +31,6 @@ */ package com.jme3.scene.plugins.blender.textures.generating; -import com.jme3.math.FastMath; -import com.jme3.scene.plugins.blender.AbstractBlenderHelper; -import com.jme3.scene.plugins.blender.BlenderContext; -import com.jme3.scene.plugins.blender.file.Structure; -import com.jme3.scene.plugins.blender.textures.generating.TextureGeneratorMusgrave.MusgraveData; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; @@ -44,14 +39,16 @@ import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; +import com.jme3.math.FastMath; +import com.jme3.scene.plugins.blender.textures.generating.TextureGeneratorMusgrave.MusgraveData; + /** * This generator is responsible for creating various noises used to create * generated textures loaded from blender. - * It derives from AbstractBlenderHelper but is not stored in blender context. * It is only used by TextureHelper. * @author Marcin Roguski (Kaelthas) */ -/* package */class NoiseGenerator extends AbstractBlenderHelper { +/* package */class NoiseGenerator { private static final Logger LOGGER = Logger.getLogger(NoiseGenerator.class.getName()); // tex->stype @@ -79,21 +76,11 @@ import java.util.logging.Logger; protected static float[][] g; /** - * Constructor. Stores the blender version number and loads the constants needed for computations. - * @param blenderVersion - * the number of blender version + * Constructor. Loads the constants needed for computations. They are exactly like the ones the blender uses. Each + * deriving class should override this method and load its own constraints. */ - public NoiseGenerator(String blenderVersion) { - super(blenderVersion, false); - this.loadConstants(); - } - - /** - * This method loads the constants needed for computations. They are exactly like the ones the blender uses. Each - * deriving class should override this method and load its own constraints. Be carefult with overriding though, if - * an exception will be thrown the class will not be instantiated. - */ - protected void loadConstants() { + public NoiseGenerator() { + LOGGER.fine("Loading noise constants."); InputStream is = NoiseGenerator.class.getResourceAsStream("noiseconstants.dat"); try { ObjectInputStream ois = new ObjectInputStream(is); @@ -791,11 +778,6 @@ import java.util.logging.Logger; } } - @Override - public boolean shouldBeLoaded(Structure structure, BlenderContext blenderContext) { - return true; - } - /** * This interface is used for distance calculation classes. Distance metrics for voronoi. e parameter only used in * Minkovsky. diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/textures/generating/TextureGeneratorFactory.java b/engine/src/blender/com/jme3/scene/plugins/blender/textures/generating/TextureGeneratorFactory.java index 3b6536597..a0e29f1b3 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/textures/generating/TextureGeneratorFactory.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/textures/generating/TextureGeneratorFactory.java @@ -4,11 +4,7 @@ import com.jme3.scene.plugins.blender.textures.TextureHelper; public class TextureGeneratorFactory { - private NoiseGenerator noiseGenerator; - - public TextureGeneratorFactory(String blenderVersion) { - noiseGenerator = new NoiseGenerator(blenderVersion); - } + private NoiseGenerator noiseGenerator = new NoiseGenerator(); public TextureGenerator createTextureGenerator(int generatedTexture) { switch (generatedTexture) {