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
This commit is contained in:
		
							parent
							
								
									3602d86c20
								
							
						
					
					
						commit
						9961f77445
					
				| @ -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); | ||||
|         } | ||||
|  | ||||
| @ -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<String, Object[]>               loadedFeaturesByName   = new HashMap<String, Object[]>(); | ||||
|     /** A stack that hold the parent structure of currently loaded feature. */ | ||||
|     private Stack<Structure>                    parentStack            = new Stack<Structure>(); | ||||
|     /** A list of modifiers for the specified object. */ | ||||
|     protected Map<Long, List<Modifier>>         modifiers              = new HashMap<Long, List<Modifier>>(); | ||||
|     /** A list of constraints for the specified object. */ | ||||
|     protected Map<Long, List<Constraint>>       constraints            = new HashMap<Long, List<Constraint>>(); | ||||
|     /** 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<Modifier> objectModifiers = this.modifiers.get(ownerOMA); | ||||
|         if (objectModifiers == null) { | ||||
|             objectModifiers = new ArrayList<Modifier>(); | ||||
|             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<Modifier> getModifiers(Long objectOMA, String type) { | ||||
|         List<Modifier> result = new ArrayList<Modifier>(); | ||||
|         List<Modifier> 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(); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
| @ -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; | ||||
|  | ||||
| @ -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<Bone, Long>     bonesOMAs            = new HashMap<Bone, Long>(); | ||||
|     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<Bone> 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); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
| @ -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<Bone> bones, Map<Bone, Long> boneOMAs, Matrix4f objectToArmatureMatrix, BlenderContext blenderContext) { | ||||
|     public Bone buildBone(List<Bone> 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; | ||||
|  | ||||
| @ -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. | ||||
|  | ||||
| @ -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!"); | ||||
|  | ||||
| @ -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); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
| @ -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()); | ||||
|  | ||||
| @ -43,8 +43,6 @@ public class SimulationNode { | ||||
|     private String                    name; | ||||
|     /** A list of children for the node (either bones or child spatials). */ | ||||
|     private List<SimulationNode>      children     = new ArrayList<SimulationNode>(); | ||||
|     /** A virtual track for each of the nodes. */ | ||||
|     private Map<String, VirtualTrack> virtualTrack = new HashMap<String, VirtualTrack>(); | ||||
|     /** A list of constraints that the current node has. */ | ||||
|     private List<Constraint>          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<Integer, VirtualTrack> tracks = new HashMap<Integer, VirtualTrack>(); | ||||
|                     Map<Integer, Transform> previousTransforms = new HashMap<Integer, Transform>(); | ||||
|                     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(); | ||||
|  | ||||
| @ -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 <b>true</b> if the definition is implemented and <b>false</b> | ||||
|      *         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); | ||||
| } | ||||
|  | ||||
| @ -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); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
| @ -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 { | ||||
| 
 | ||||
|  | ||||
| @ -50,26 +50,6 @@ public class DynamicArray<T> 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 | ||||
|  | ||||
| @ -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('('); | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
| @ -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. */ | ||||
|  | ||||
| @ -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 { | ||||
|  | ||||
| @ -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<Vector2f> 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. | ||||
|      *  | ||||
|  | ||||
| @ -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<String, Texture> textures = new HashMap<String, Texture>(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<String, Texture> 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<String, Texture> 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 <b>true</b> if the texture exists in the material and <B>false</b> 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 <b>true</b> if the texture exists in the material and <B>false</b> 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/ | ||||
|  | ||||
| @ -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()); | ||||
| 
 | ||||
|  | ||||
| @ -18,8 +18,6 @@ public class MeshContext { | ||||
|     private Map<Integer, Geometry>                    geometries       = new HashMap<Integer, Geometry>(); | ||||
|     /** The vertex reference map. */ | ||||
|     private Map<Integer, Map<Integer, List<Integer>>> vertexReferenceMap; | ||||
|     /** The UV-coordinates for each of the geometries. */ | ||||
|     private Map<Geometry, VertexBuffer>               uvCoordinates    = new HashMap<Geometry, VertexBuffer>(); | ||||
|     /** Bind buffer for vertices is stored here and applied when required. */ | ||||
|     private Map<Integer, VertexBuffer>                bindPoseBuffer   = new HashMap<Integer, VertexBuffer>(); | ||||
|     /** 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. | ||||
|      *  | ||||
|  | ||||
| @ -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); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
| @ -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<Structure> dverts = pDvert.fetchData(blenderContext.getInputStream());// dverts.size() | ||||
|                                                                                        // == | ||||
|                                                                                        // verticesAmount | ||||
|                                                                                        // (one | ||||
|                                                                                        // dvert | ||||
|                                                                                        // per | ||||
|                                                                                        // vertex | ||||
|                                                                                        // in | ||||
|                                                                                        // blender) | ||||
|             // dverts.size() = verticesAmount (one dvert per vertex in blender) | ||||
|             List<Structure> dverts = pDvert.fetchData(blenderContext.getInputStream()); | ||||
|             int vertexIndex = 0; | ||||
|             // use tree map to sort weights from the lowest to the highest ones | ||||
|             TreeMap<Float, Integer> weightToIndexMap = new TreeMap<Float, Integer>(); | ||||
| 
 | ||||
|             for (Structure dvert : dverts) { | ||||
|                 List<Integer> vertexIndices = vertexReferenceMap.get(Integer.valueOf(vertexIndex));// we | ||||
|                                                                                                    // fetch | ||||
|                                                                                                    // the | ||||
|                                                                                                    // referenced | ||||
|                                                                                                    // vertices | ||||
|                                                                                                    // here | ||||
|                 //we fetch the referenced vertices here | ||||
|                 List<Integer> 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; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -239,9 +239,4 @@ import java.util.logging.Logger; | ||||
|         } | ||||
|         return node; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public String getType() { | ||||
|         return ARRAY_MODIFIER_DATA; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -192,9 +192,4 @@ import com.jme3.scene.plugins.blender.objects.ObjectHelper; | ||||
|         } | ||||
|         return node; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public String getType() { | ||||
|         return Modifier.MIRROR_MODIFIER_DATA; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
| @ -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); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
| @ -86,9 +86,4 @@ import com.jme3.scene.plugins.ogre.AnimData; | ||||
|         } | ||||
|         return node; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public String getType() { | ||||
|         return Modifier.OBJECT_ANIMATION_MODIFIER_DATA; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -92,9 +92,4 @@ import java.util.logging.Logger; | ||||
|         node.attachChild(emitter); | ||||
|         return node; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public String getType() { | ||||
|         return Modifier.PARTICLE_MODIFIER_DATA; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -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<Number> obmat = (DynamicArray<Number>) 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()); | ||||
|  | ||||
| @ -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. | ||||
|  | ||||
| @ -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") | ||||
|  | ||||
| @ -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); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | ||||
| @ -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); | ||||
| 
 | ||||
|  | ||||
| @ -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. | ||||
|  | ||||
| @ -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) { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user