Main repository of MikuMikuStudio
リビジョン | b0ce619c39c5192363c2f99ae6156bce60dcad80 (tree) |
---|---|
日時 | 2013-04-29 20:31:48 |
作者 | Kaelthas_Spellsinger@o2.pl <Kaelthas_Spellsinger@o2.p...> |
コミッター | Kaelthas_Spellsinger@o2.pl |
Code refactoring:
- removed unused methods
- added javadocs
- minor name fixes
- one constructor type for all helpers
git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@10585 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
@@ -49,7 +49,8 @@ import com.jme3.scene.plugins.blender.objects.Properties; | ||
49 | 49 | * @author Marcin Roguski |
50 | 50 | */ |
51 | 51 | public abstract class AbstractBlenderHelper { |
52 | - | |
52 | + /** The blender context. */ | |
53 | + protected BlenderContext blenderContext; | |
53 | 54 | /** The version of the blend file. */ |
54 | 55 | protected final int blenderVersion; |
55 | 56 | /** This variable indicates if the Y asxis is the UP axis or not. */ |
@@ -62,12 +63,13 @@ public abstract class AbstractBlenderHelper { | ||
62 | 63 | * versions. |
63 | 64 | * @param blenderVersion |
64 | 65 | * the version read from the blend file |
65 | - * @param fixUpAxis | |
66 | - * a variable that indicates if the Y asxis is the UP axis or not | |
66 | + * @param blenderContext | |
67 | + * the blender context | |
67 | 68 | */ |
68 | - public AbstractBlenderHelper(String blenderVersion, boolean fixUpAxis) { | |
69 | + public AbstractBlenderHelper(String blenderVersion, BlenderContext blenderContext) { | |
69 | 70 | this.blenderVersion = Integer.parseInt(blenderVersion); |
70 | - this.fixUpAxis = fixUpAxis; | |
71 | + this.blenderContext = blenderContext; | |
72 | + this.fixUpAxis = blenderContext.getBlenderKey().isFixUpAxis(); | |
71 | 73 | if (fixUpAxis) { |
72 | 74 | upAxisRotationQuaternion = new Quaternion().fromAngles(-FastMath.HALF_PI, 0, 0); |
73 | 75 | } |
@@ -54,7 +54,6 @@ import com.jme3.scene.plugins.blender.file.DnaBlockData; | ||
54 | 54 | import com.jme3.scene.plugins.blender.file.FileBlockHeader; |
55 | 55 | import com.jme3.scene.plugins.blender.file.Structure; |
56 | 56 | import com.jme3.scene.plugins.blender.meshes.MeshContext; |
57 | -import com.jme3.scene.plugins.blender.modifiers.Modifier; | |
58 | 57 | import com.jme3.scene.plugins.ogre.AnimData; |
59 | 58 | |
60 | 59 | /** |
@@ -101,8 +100,6 @@ public class BlenderContext { | ||
101 | 100 | private Map<String, Object[]> loadedFeaturesByName = new HashMap<String, Object[]>(); |
102 | 101 | /** A stack that hold the parent structure of currently loaded feature. */ |
103 | 102 | private Stack<Structure> parentStack = new Stack<Structure>(); |
104 | - /** A list of modifiers for the specified object. */ | |
105 | - protected Map<Long, List<Modifier>> modifiers = new HashMap<Long, List<Modifier>>(); | |
106 | 103 | /** A list of constraints for the specified object. */ |
107 | 104 | protected Map<Long, List<Constraint>> constraints = new HashMap<Long, List<Constraint>>(); |
108 | 105 | /** Anim data loaded for features. */ |
@@ -273,14 +270,6 @@ public class BlenderContext { | ||
273 | 270 | } |
274 | 271 | |
275 | 272 | /** |
276 | - * This method clears the saved block headers stored in the features map. | |
277 | - */ | |
278 | - public void clearFileBlocks() { | |
279 | - fileBlockHeadersByOma.clear(); | |
280 | - fileBlockHeadersByCode.clear(); | |
281 | - } | |
282 | - | |
283 | - /** | |
284 | 273 | * This method adds a helper instance to the helpers' map. |
285 | 274 | * |
286 | 275 | * @param <T> |
@@ -343,13 +332,6 @@ public class BlenderContext { | ||
343 | 332 | } |
344 | 333 | |
345 | 334 | /** |
346 | - * This method clears the saved features stored in the features map. | |
347 | - */ | |
348 | - public void clearLoadedFeatures() { | |
349 | - loadedFeatures.clear(); | |
350 | - } | |
351 | - | |
352 | - /** | |
353 | 335 | * This method adds the structure to the parent stack. |
354 | 336 | * |
355 | 337 | * @param parent |
@@ -391,48 +373,6 @@ public class BlenderContext { | ||
391 | 373 | * |
392 | 374 | * @param ownerOMA |
393 | 375 | * the owner's old memory address |
394 | - * @param modifier | |
395 | - * the object's modifier | |
396 | - */ | |
397 | - public void addModifier(Long ownerOMA, Modifier modifier) { | |
398 | - List<Modifier> objectModifiers = this.modifiers.get(ownerOMA); | |
399 | - if (objectModifiers == null) { | |
400 | - objectModifiers = new ArrayList<Modifier>(); | |
401 | - this.modifiers.put(ownerOMA, objectModifiers); | |
402 | - } | |
403 | - objectModifiers.add(modifier); | |
404 | - } | |
405 | - | |
406 | - /** | |
407 | - * This method returns modifiers for the object specified by its old memory | |
408 | - * address and the modifier type. If no modifiers are found - empty list is | |
409 | - * returned. If the type is null - all modifiers for the object are | |
410 | - * returned. | |
411 | - * | |
412 | - * @param objectOMA | |
413 | - * object's old memory address | |
414 | - * @param type | |
415 | - * the type of the modifier | |
416 | - * @return the list of object's modifiers | |
417 | - */ | |
418 | - public List<Modifier> getModifiers(Long objectOMA, String type) { | |
419 | - List<Modifier> result = new ArrayList<Modifier>(); | |
420 | - List<Modifier> readModifiers = modifiers.get(objectOMA); | |
421 | - if (readModifiers != null && readModifiers.size() > 0) { | |
422 | - for (Modifier modifier : readModifiers) { | |
423 | - if (type == null || type.isEmpty() || modifier.getType().equals(type)) { | |
424 | - result.add(modifier); | |
425 | - } | |
426 | - } | |
427 | - } | |
428 | - return result; | |
429 | - } | |
430 | - | |
431 | - /** | |
432 | - * This method adds a new modifier to the list. | |
433 | - * | |
434 | - * @param ownerOMA | |
435 | - * the owner's old memory address | |
436 | 376 | * @param constraints |
437 | 377 | * the object's constraints |
438 | 378 | */ |
@@ -632,13 +572,14 @@ public class BlenderContext { | ||
632 | 572 | loadedFeatures.clear(); |
633 | 573 | loadedFeaturesByName.clear(); |
634 | 574 | parentStack.clear(); |
635 | - modifiers.clear(); | |
636 | 575 | constraints.clear(); |
637 | 576 | animData.clear(); |
638 | 577 | skeletons.clear(); |
639 | 578 | meshContexts.clear(); |
640 | 579 | boneContexts.clear(); |
641 | 580 | helpers.clear(); |
581 | + fileBlockHeadersByOma.clear(); | |
582 | + fileBlockHeadersByCode.clear(); | |
642 | 583 | } |
643 | 584 | |
644 | 585 | /** |
@@ -195,18 +195,18 @@ public class BlenderLoader extends AbstractBlenderLoader { | ||
195 | 195 | blenderContext.setBlenderKey(blenderKey); |
196 | 196 | |
197 | 197 | // creating helpers |
198 | - blenderContext.putHelper(ArmatureHelper.class, new ArmatureHelper(inputStream.getVersionNumber(), blenderKey.isFixUpAxis())); | |
199 | - blenderContext.putHelper(TextureHelper.class, new TextureHelper(inputStream.getVersionNumber(), blenderKey.isFixUpAxis())); | |
200 | - blenderContext.putHelper(MeshHelper.class, new MeshHelper(inputStream.getVersionNumber(), blenderKey.isFixUpAxis())); | |
201 | - blenderContext.putHelper(ObjectHelper.class, new ObjectHelper(inputStream.getVersionNumber(), blenderKey.isFixUpAxis())); | |
202 | - blenderContext.putHelper(CurvesHelper.class, new CurvesHelper(inputStream.getVersionNumber(), blenderKey.isFixUpAxis())); | |
203 | - blenderContext.putHelper(LightHelper.class, new LightHelper(inputStream.getVersionNumber(), blenderKey.isFixUpAxis())); | |
204 | - blenderContext.putHelper(CameraHelper.class, new CameraHelper(inputStream.getVersionNumber(), blenderKey.isFixUpAxis())); | |
205 | - blenderContext.putHelper(ModifierHelper.class, new ModifierHelper(inputStream.getVersionNumber(), blenderKey.isFixUpAxis())); | |
206 | - blenderContext.putHelper(MaterialHelper.class, new MaterialHelper(inputStream.getVersionNumber(), blenderKey.isFixUpAxis())); | |
207 | - blenderContext.putHelper(ConstraintHelper.class, new ConstraintHelper(inputStream.getVersionNumber(), blenderContext, blenderKey.isFixUpAxis())); | |
208 | - blenderContext.putHelper(IpoHelper.class, new IpoHelper(inputStream.getVersionNumber(), blenderKey.isFixUpAxis())); | |
209 | - blenderContext.putHelper(ParticlesHelper.class, new ParticlesHelper(inputStream.getVersionNumber(), blenderKey.isFixUpAxis())); | |
198 | + blenderContext.putHelper(ArmatureHelper.class, new ArmatureHelper(inputStream.getVersionNumber(), blenderContext)); | |
199 | + blenderContext.putHelper(TextureHelper.class, new TextureHelper(inputStream.getVersionNumber(), blenderContext)); | |
200 | + blenderContext.putHelper(MeshHelper.class, new MeshHelper(inputStream.getVersionNumber(), blenderContext)); | |
201 | + blenderContext.putHelper(ObjectHelper.class, new ObjectHelper(inputStream.getVersionNumber(), blenderContext)); | |
202 | + blenderContext.putHelper(CurvesHelper.class, new CurvesHelper(inputStream.getVersionNumber(), blenderContext)); | |
203 | + blenderContext.putHelper(LightHelper.class, new LightHelper(inputStream.getVersionNumber(), blenderContext)); | |
204 | + blenderContext.putHelper(CameraHelper.class, new CameraHelper(inputStream.getVersionNumber(), blenderContext)); | |
205 | + blenderContext.putHelper(ModifierHelper.class, new ModifierHelper(inputStream.getVersionNumber(), blenderContext)); | |
206 | + blenderContext.putHelper(MaterialHelper.class, new MaterialHelper(inputStream.getVersionNumber(), blenderContext)); | |
207 | + blenderContext.putHelper(ConstraintHelper.class, new ConstraintHelper(inputStream.getVersionNumber(), blenderContext)); | |
208 | + blenderContext.putHelper(IpoHelper.class, new IpoHelper(inputStream.getVersionNumber(), blenderContext)); | |
209 | + blenderContext.putHelper(ParticlesHelper.class, new ParticlesHelper(inputStream.getVersionNumber(), blenderContext)); | |
210 | 210 | |
211 | 211 | // reading the blocks (dna block is automatically saved in the blender context when found) |
212 | 212 | FileBlockHeader sceneFileBlock = null; |
@@ -58,10 +58,7 @@ import com.jme3.scene.plugins.blender.file.Structure; | ||
58 | 58 | public class ArmatureHelper extends AbstractBlenderHelper { |
59 | 59 | private static final Logger LOGGER = Logger.getLogger(ArmatureHelper.class.getName()); |
60 | 60 | |
61 | - public static final String ARMETURE_NODE_MARKER = "armeture-node"; | |
62 | - | |
63 | - /** A map of bones and their old memory addresses. */ | |
64 | - private Map<Bone, Long> bonesOMAs = new HashMap<Bone, Long>(); | |
61 | + public static final String ARMATURE_NODE_MARKER = "armature-node"; | |
65 | 62 | |
66 | 63 | /** |
67 | 64 | * This constructor parses the given blender version and stores the result. |
@@ -69,11 +66,11 @@ public class ArmatureHelper extends AbstractBlenderHelper { | ||
69 | 66 | * |
70 | 67 | * @param blenderVersion |
71 | 68 | * the version read from the blend file |
72 | - * @param fixUpAxis | |
73 | - * a variable that indicates if the Y asxis is the UP axis or not | |
69 | + * @param blenderContext | |
70 | + * the blender context | |
74 | 71 | */ |
75 | - public ArmatureHelper(String blenderVersion, boolean fixUpAxis) { | |
76 | - super(blenderVersion, fixUpAxis); | |
72 | + public ArmatureHelper(String blenderVersion, BlenderContext blenderContext) { | |
73 | + super(blenderVersion, blenderContext); | |
77 | 74 | } |
78 | 75 | |
79 | 76 | /** |
@@ -93,23 +90,7 @@ public class ArmatureHelper extends AbstractBlenderHelper { | ||
93 | 90 | */ |
94 | 91 | public void buildBones(Long armatureObjectOMA, Structure boneStructure, Bone parent, List<Bone> result, Matrix4f objectToArmatureTransformation, BlenderContext blenderContext) throws BlenderFileException { |
95 | 92 | BoneContext bc = new BoneContext(armatureObjectOMA, boneStructure, blenderContext); |
96 | - bc.buildBone(result, bonesOMAs, objectToArmatureTransformation, blenderContext); | |
97 | - } | |
98 | - | |
99 | - /** | |
100 | - * This method returns the old memory address of a bone. If the bone does | |
101 | - * not exist in the blend file - zero is returned. | |
102 | - * | |
103 | - * @param bone | |
104 | - * the bone whose old memory address we seek | |
105 | - * @return the old memory address of the given bone | |
106 | - */ | |
107 | - public Long getBoneOMA(Bone bone) { | |
108 | - Long result = bonesOMAs.get(bone); | |
109 | - if (result == null) { | |
110 | - result = Long.valueOf(0); | |
111 | - } | |
112 | - return result; | |
93 | + bc.buildBone(result, objectToArmatureTransformation, blenderContext); | |
113 | 94 | } |
114 | 95 | |
115 | 96 | /** |
@@ -2,7 +2,6 @@ package com.jme3.scene.plugins.blender.animations; | ||
2 | 2 | |
3 | 3 | import java.util.ArrayList; |
4 | 4 | import java.util.List; |
5 | -import java.util.Map; | |
6 | 5 | |
7 | 6 | import com.jme3.animation.Bone; |
8 | 7 | import com.jme3.animation.Skeleton; |
@@ -105,19 +104,16 @@ public class BoneContext { | ||
105 | 104 | * |
106 | 105 | * @param bones |
107 | 106 | * a list of bones where the newly created bone will be added |
108 | - * @param boneOMAs | |
109 | - * the map between bone and its old memory address | |
110 | 107 | * @param objectToArmatureMatrix |
111 | 108 | * object to armature transformation matrix |
112 | 109 | * @param blenderContext |
113 | 110 | * the blender context |
114 | 111 | * @return newly created bone |
115 | 112 | */ |
116 | - public Bone buildBone(List<Bone> bones, Map<Bone, Long> boneOMAs, Matrix4f objectToArmatureMatrix, BlenderContext blenderContext) { | |
113 | + public Bone buildBone(List<Bone> bones, Matrix4f objectToArmatureMatrix, BlenderContext blenderContext) { | |
117 | 114 | Long boneOMA = boneStructure.getOldMemoryAddress(); |
118 | 115 | bone = new Bone(boneName); |
119 | 116 | bones.add(bone); |
120 | - boneOMAs.put(bone, boneOMA); | |
121 | 117 | blenderContext.addLoadedFeatures(boneOMA, boneName, boneStructure, bone); |
122 | 118 | |
123 | 119 | Vector3f poseLocation = restMatrix.toTranslationVector(); |
@@ -132,7 +128,7 @@ public class BoneContext { | ||
132 | 128 | |
133 | 129 | bone.setBindTransforms(poseLocation, rotation, scale); |
134 | 130 | for (BoneContext child : children) { |
135 | - bone.addChild(child.buildBone(bones, boneOMAs, objectToArmatureMatrix, blenderContext)); | |
131 | + bone.addChild(child.buildBone(bones, objectToArmatureMatrix, blenderContext)); | |
136 | 132 | } |
137 | 133 | |
138 | 134 | return bone; |
@@ -89,15 +89,6 @@ public class Ipo { | ||
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
92 | - * This method returns the curves amount. | |
93 | - * | |
94 | - * @return the curves amount | |
95 | - */ | |
96 | - public int getCurvesAmount() { | |
97 | - return bezierCurves.length; | |
98 | - } | |
99 | - | |
100 | - /** | |
101 | 92 | * This method returns the frame where last bezier triple center point of |
102 | 93 | * the specified bezier curve is located. |
103 | 94 | * |
@@ -29,11 +29,11 @@ public class IpoHelper extends AbstractBlenderHelper { | ||
29 | 29 | * |
30 | 30 | * @param blenderVersion |
31 | 31 | * the version read from the blend file |
32 | - * @param fixUpAxis | |
33 | - * a variable that indicates if the Y asxis is the UP axis or not | |
32 | + * @param blenderContext | |
33 | + * the blender context | |
34 | 34 | */ |
35 | - public IpoHelper(String blenderVersion, boolean fixUpAxis) { | |
36 | - super(blenderVersion, fixUpAxis); | |
35 | + public IpoHelper(String blenderVersion, BlenderContext blenderContext) { | |
36 | + super(blenderVersion, blenderContext); | |
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -190,11 +190,6 @@ public class IpoHelper extends AbstractBlenderHelper { | ||
190 | 190 | } |
191 | 191 | |
192 | 192 | @Override |
193 | - public int getCurvesAmount() { | |
194 | - return 0; | |
195 | - } | |
196 | - | |
197 | - @Override | |
198 | 193 | public BoneTrack calculateTrack(int boneIndex, Quaternion localQuaternionRotation, int startFrame, int stopFrame, int fps, boolean boneTrack) { |
199 | 194 | throw new IllegalStateException("Constatnt ipo object cannot be used for calculating bone tracks!"); |
200 | 195 | } |
@@ -26,11 +26,11 @@ public class CameraHelper extends AbstractBlenderHelper { | ||
26 | 26 | * different blender versions. |
27 | 27 | * @param blenderVersion |
28 | 28 | * the version read from the blend file |
29 | - * @param fixUpAxis | |
30 | - * a variable that indicates if the Y asxis is the UP axis or not | |
29 | + * @param blenderContext | |
30 | + * the blender context | |
31 | 31 | */ |
32 | - public CameraHelper(String blenderVersion, boolean fixUpAxis) { | |
33 | - super(blenderVersion, fixUpAxis); | |
32 | + public CameraHelper(String blenderVersion, BlenderContext blenderContext) { | |
33 | + super(blenderVersion, blenderContext); | |
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -1,7 +1,6 @@ | ||
1 | 1 | package com.jme3.scene.plugins.blender.constraints; |
2 | 2 | |
3 | 3 | import java.util.ArrayList; |
4 | -import java.util.Arrays; | |
5 | 4 | import java.util.HashMap; |
6 | 5 | import java.util.List; |
7 | 6 | import java.util.Map; |
@@ -40,26 +39,16 @@ public class ConstraintHelper extends AbstractBlenderHelper { | ||
40 | 39 | private static final Quaternion POS_PARLOC_SPACE_QUATERNION = new Quaternion(new float[] { FastMath.HALF_PI, 0, 0 }); |
41 | 40 | private static final Quaternion NEG_PARLOC_SPACE_QUATERNION = new Quaternion(new float[] { -FastMath.HALF_PI, 0, 0 }); |
42 | 41 | |
43 | - private BlenderContext blenderContext; | |
44 | - | |
45 | 42 | /** |
46 | - * Helper constructor. It's main task is to generate the affection | |
47 | - * functions. These functions are common to all ConstraintHelper instances. | |
48 | - * Unfortunately this constructor might grow large. If it becomes too large | |
49 | - * - I shall consider refactoring. The constructor parses the given blender | |
50 | - * version and stores the result. Some functionalities may differ in | |
51 | - * different blender versions. | |
43 | + * Helper constructor. | |
52 | 44 | * |
53 | 45 | * @param blenderVersion |
54 | 46 | * the version read from the blend file |
55 | 47 | * @param blenderContext |
56 | 48 | * the blender context |
57 | - * @param fixUpAxis | |
58 | - * a variable that indicates if the Y asxis is the UP axis or not | |
59 | 49 | */ |
60 | - public ConstraintHelper(String blenderVersion, BlenderContext blenderContext, boolean fixUpAxis) { | |
61 | - super(blenderVersion, fixUpAxis); | |
62 | - this.blenderContext = blenderContext; | |
50 | + public ConstraintHelper(String blenderVersion, BlenderContext blenderContext) { | |
51 | + super(blenderVersion, blenderContext); | |
63 | 52 | } |
64 | 53 | |
65 | 54 | /** |
@@ -231,16 +220,14 @@ public class ConstraintHelper extends AbstractBlenderHelper { | ||
231 | 220 | */ |
232 | 221 | public Transform getTransform(Long oma, String subtargetName, Space space) { |
233 | 222 | Spatial feature = (Spatial) blenderContext.getLoadedFeature(oma, LoadedFeatureDataType.LOADED_FEATURE); |
234 | - boolean isArmature = feature.getUserData(ArmatureHelper.ARMETURE_NODE_MARKER) != null; | |
223 | + boolean isArmature = feature.getUserData(ArmatureHelper.ARMATURE_NODE_MARKER) != null; | |
235 | 224 | if (isArmature) { |
236 | 225 | BoneContext targetBoneContext = blenderContext.getBoneByName(subtargetName); |
237 | 226 | Bone bone = targetBoneContext.getBone(); |
238 | 227 | |
239 | 228 | switch (space) { |
240 | 229 | case CONSTRAINT_SPACE_WORLD: |
241 | - Transform t = new Transform(bone.getModelSpacePosition(), bone.getModelSpaceRotation(), bone.getModelSpaceScale()); | |
242 | - System.out.println("A: " + Arrays.toString(t.getRotation().toAngles(null))); | |
243 | - return t; | |
230 | + return new Transform(bone.getModelSpacePosition(), bone.getModelSpaceRotation(), bone.getModelSpaceScale()); | |
244 | 231 | case CONSTRAINT_SPACE_LOCAL: |
245 | 232 | Transform localTransform = new Transform(bone.getLocalPosition(), bone.getLocalRotation()); |
246 | 233 | localTransform.setScale(bone.getLocalScale()); |
@@ -264,8 +251,9 @@ public class ConstraintHelper extends AbstractBlenderHelper { | ||
264 | 251 | if (bone.getParent() != null) { |
265 | 252 | Bone parent = bone.getParent(); |
266 | 253 | parentLocalMatrix = this.toMatrix(parent.getLocalPosition(), parent.getLocalRotation(), parent.getLocalScale()); |
267 | - } else {// we need to clone it because otherwise we could | |
268 | - // spoil the IDENTITY matrix | |
254 | + } else { | |
255 | + // we need to clone it because otherwise we could spoil | |
256 | + // the IDENTITY matrix | |
269 | 257 | parentLocalMatrix = parentLocalMatrix.clone(); |
270 | 258 | } |
271 | 259 | Matrix4f boneLocalMatrix = this.toMatrix(bone.getLocalPosition(), bone.getLocalRotation(), bone.getLocalScale()); |
@@ -309,7 +297,7 @@ public class ConstraintHelper extends AbstractBlenderHelper { | ||
309 | 297 | */ |
310 | 298 | public void applyTransform(Long oma, String subtargetName, Space space, Transform transform) { |
311 | 299 | Spatial feature = (Spatial) blenderContext.getLoadedFeature(oma, LoadedFeatureDataType.LOADED_FEATURE); |
312 | - boolean isArmature = feature.getUserData(ArmatureHelper.ARMETURE_NODE_MARKER) != null; | |
300 | + boolean isArmature = feature.getUserData(ArmatureHelper.ARMATURE_NODE_MARKER) != null; | |
313 | 301 | if (isArmature) { |
314 | 302 | Skeleton skeleton = blenderContext.getSkeleton(oma); |
315 | 303 | BoneContext targetBoneContext = blenderContext.getBoneByName(subtargetName); |
@@ -324,7 +312,6 @@ public class ConstraintHelper extends AbstractBlenderHelper { | ||
324 | 312 | bone.setBindTransforms(transform.getTranslation(), transform.getRotation(), transform.getScale()); |
325 | 313 | break; |
326 | 314 | case CONSTRAINT_SPACE_WORLD: |
327 | - System.out.println("B: " + Arrays.toString(transform.getRotation().toAngles(null))); | |
328 | 315 | Matrix4f boneMatrix = this.toMatrix(transform); |
329 | 316 | Bone parent = bone.getParent(); |
330 | 317 | if (parent != null) { |
@@ -352,8 +339,9 @@ public class ConstraintHelper extends AbstractBlenderHelper { | ||
352 | 339 | if (bone.getParent() != null) { |
353 | 340 | parentLocalMatrix = this.toMatrix(bone.getParent().getLocalPosition(), bone.getParent().getLocalRotation(), bone.getParent().getLocalScale()); |
354 | 341 | parentLocalMatrix.invertLocal(); |
355 | - } else {// we need to clone it because otherwise we could | |
356 | - // spoil the IDENTITY matrix | |
342 | + } else { | |
343 | + // we need to clone it because otherwise we could | |
344 | + // spoil the IDENTITY matrix | |
357 | 345 | parentLocalMatrix = parentLocalMatrix.clone(); |
358 | 346 | } |
359 | 347 | Matrix4f m = this.toMatrix(transform.getTranslation(), transform.getRotation(), transform.getScale()); |
@@ -43,8 +43,6 @@ public class SimulationNode { | ||
43 | 43 | private String name; |
44 | 44 | /** A list of children for the node (either bones or child spatials). */ |
45 | 45 | private List<SimulationNode> children = new ArrayList<SimulationNode>(); |
46 | - /** A virtual track for each of the nodes. */ | |
47 | - private Map<String, VirtualTrack> virtualTrack = new HashMap<String, VirtualTrack>(); | |
48 | 46 | /** A list of constraints that the current node has. */ |
49 | 47 | private List<Constraint> constraints; |
50 | 48 | /** A list of node's animations. */ |
@@ -91,7 +89,7 @@ public class SimulationNode { | ||
91 | 89 | */ |
92 | 90 | private SimulationNode(Long featureOMA, BlenderContext blenderContext, boolean rootNode) { |
93 | 91 | Node spatial = (Node) blenderContext.getLoadedFeature(featureOMA, LoadedFeatureDataType.LOADED_FEATURE); |
94 | - if (spatial.getUserData(ArmatureHelper.ARMETURE_NODE_MARKER) != null) { | |
92 | + if (spatial.getUserData(ArmatureHelper.ARMATURE_NODE_MARKER) != null) { | |
95 | 93 | this.skeleton = blenderContext.getSkeleton(featureOMA); |
96 | 94 | |
97 | 95 | Node nodeWithAnimationControl = blenderContext.getControlledNode(skeleton); |
@@ -206,7 +204,6 @@ public class SimulationNode { | ||
206 | 204 | float maxTime = animationTimeBoundaries[1]; |
207 | 205 | |
208 | 206 | VirtualTrack vTrack = new VirtualTrack(maxFrame, maxTime); |
209 | - virtualTrack.put(animation.getName(), vTrack); | |
210 | 207 | for (Track track : animation.getTracks()) { |
211 | 208 | for (int frame = 0; frame < maxFrame; ++frame) { |
212 | 209 | spatial.setLocalTranslation(((SpatialTrack) track).getTranslations()[frame]); |
@@ -260,11 +257,11 @@ public class SimulationNode { | ||
260 | 257 | Map<Integer, VirtualTrack> tracks = new HashMap<Integer, VirtualTrack>(); |
261 | 258 | Map<Integer, Transform> previousTransforms = new HashMap<Integer, Transform>(); |
262 | 259 | for (int frame = 0; frame < maxFrame; ++frame) { |
263 | - this.reset();// this MUST be done here, otherwise | |
264 | - // setting next frame of animation will | |
265 | - // lead to possible errors | |
266 | - // first set proper time for all bones in all the tracks | |
267 | - // ... | |
260 | + // this MUST be done here, otherwise setting next frame of animation will | |
261 | + // lead to possible errors | |
262 | + this.reset(); | |
263 | + | |
264 | + // first set proper time for all bones in all the tracks ... | |
268 | 265 | for (Track track : animation.getTracks()) { |
269 | 266 | float time = ((BoneTrack) track).getTimes()[frame]; |
270 | 267 | Integer boneIndex = ((BoneTrack) track).getTargetBoneIndex(); |
@@ -5,12 +5,32 @@ import com.jme3.scene.plugins.blender.BlenderContext; | ||
5 | 5 | import com.jme3.scene.plugins.blender.BlenderContext.LoadedFeatureDataType; |
6 | 6 | import com.jme3.scene.plugins.blender.file.Structure; |
7 | 7 | |
8 | +/** | |
9 | + * A base class for all constraint definitions. | |
10 | + * | |
11 | + * @author Marcin Roguski (Kaelthas) | |
12 | + */ | |
8 | 13 | public abstract class ConstraintDefinition { |
14 | + /** Constraints flag. Used to load user's options applied to the constraint. */ | |
9 | 15 | protected int flag; |
16 | + /** The constraint's owner. Loaded during runtime. */ | |
10 | 17 | private Object owner; |
18 | + /** The blender context. */ | |
11 | 19 | private BlenderContext blenderContext; |
20 | + /** The constraint's owner OMA. */ | |
12 | 21 | private Long ownerOMA; |
13 | 22 | |
23 | + /** | |
24 | + * Loads a constraint definition based on the constraint definition | |
25 | + * structure. | |
26 | + * | |
27 | + * @param constraintData | |
28 | + * the constraint definition structure | |
29 | + * @param ownerOMA | |
30 | + * the constraint's owner OMA | |
31 | + * @param blenderContext | |
32 | + * the blender context | |
33 | + */ | |
14 | 34 | public ConstraintDefinition(Structure constraintData, Long ownerOMA, BlenderContext blenderContext) { |
15 | 35 | if (constraintData != null) {// Null constraint has no data |
16 | 36 | Number flag = (Number) constraintData.getFieldValue("flag"); |
@@ -29,7 +49,7 @@ public abstract class ConstraintDefinition { | ||
29 | 49 | * |
30 | 50 | * @return the owner of the constraint or null if none is set |
31 | 51 | */ |
32 | - public Object getOwner() { | |
52 | + protected Object getOwner() { | |
33 | 53 | if (ownerOMA != null && owner == null) { |
34 | 54 | owner = blenderContext.getLoadedFeature(ownerOMA, LoadedFeatureDataType.LOADED_FEATURE); |
35 | 55 | if (owner == null) { |
@@ -39,11 +59,28 @@ public abstract class ConstraintDefinition { | ||
39 | 59 | return owner; |
40 | 60 | } |
41 | 61 | |
62 | + /** | |
63 | + * @return <b>true</b> if the definition is implemented and <b>false</b> | |
64 | + * otherwise | |
65 | + */ | |
42 | 66 | public boolean isImplemented() { |
43 | 67 | return true; |
44 | 68 | } |
45 | 69 | |
70 | + /** | |
71 | + * @return the type name of the constraint | |
72 | + */ | |
46 | 73 | public abstract String getConstraintTypeName(); |
47 | 74 | |
75 | + /** | |
76 | + * Bakes the constraint for the current feature (bone or spatial) position. | |
77 | + * | |
78 | + * @param ownerTransform | |
79 | + * the input transform (here the result is stored) | |
80 | + * @param targetTransform | |
81 | + * the target transform used by some of the constraints | |
82 | + * @param influence | |
83 | + * the influence of the constraint (from range <0; 1>) | |
84 | + */ | |
48 | 85 | public abstract void bake(Transform ownerTransform, Transform targetTransform, float influence); |
49 | 86 | } |
@@ -89,11 +89,11 @@ public class CurvesHelper extends AbstractBlenderHelper { | ||
89 | 89 | * different blender versions. |
90 | 90 | * @param blenderVersion |
91 | 91 | * the version read from the blend file |
92 | - * @param fixUpAxis | |
93 | - * a variable that indicates if the Y asxis is the UP axis or not | |
92 | + * @param blenderContext | |
93 | + * the blender context | |
94 | 94 | */ |
95 | - public CurvesHelper(String blenderVersion, boolean fixUpAxis) { | |
96 | - super(blenderVersion, fixUpAxis); | |
95 | + public CurvesHelper(String blenderVersion, BlenderContext blenderContext) { | |
96 | + super(blenderVersion, blenderContext); | |
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -38,7 +38,7 @@ import java.util.Map; | ||
38 | 38 | |
39 | 39 | /** |
40 | 40 | * The data block containing the description of the file. |
41 | - * @author Marcin Roguski | |
41 | + * @author Marcin Roguski (Kaelthas) | |
42 | 42 | */ |
43 | 43 | public class DnaBlockData { |
44 | 44 |
@@ -57,26 +57,6 @@ public class DynamicArray<T> implements Cloneable { | ||
57 | 57 | * @throws BlenderFileException |
58 | 58 | * an exception is thrown if one of the sizes is not a positive number |
59 | 59 | */ |
60 | - @SuppressWarnings("unchecked") | |
61 | - public DynamicArray(int[] tableSizes) throws BlenderFileException { | |
62 | - this.tableSizes = tableSizes; | |
63 | - int totalSize = 1; | |
64 | - for (int size : tableSizes) { | |
65 | - if (size <= 0) { | |
66 | - throw new BlenderFileException("The size of the table must be positive!"); | |
67 | - } | |
68 | - totalSize *= size; | |
69 | - } | |
70 | - this.array = (T[]) new Object[totalSize]; | |
71 | - } | |
72 | - | |
73 | - /** | |
74 | - * Constructor. Builds an empty array of the specified sizes. | |
75 | - * @param tableSizes | |
76 | - * the sizes of the table | |
77 | - * @throws BlenderFileException | |
78 | - * an exception is thrown if one of the sizes is not a positive number | |
79 | - */ | |
80 | 60 | public DynamicArray(int[] tableSizes, T[] data) throws BlenderFileException { |
81 | 61 | this.tableSizes = tableSizes; |
82 | 62 | int totalSize = 1; |
@@ -281,7 +281,7 @@ class Field implements Cloneable { | ||
281 | 281 | * This method builds the full name of the field (with function, pointer and table indications). |
282 | 282 | * @return the full name of the field |
283 | 283 | */ |
284 | - public String getFullName() { | |
284 | + /*package*/ String getFullName() { | |
285 | 285 | StringBuilder result = new StringBuilder(); |
286 | 286 | if (function) { |
287 | 287 | result.append('('); |
@@ -130,14 +130,6 @@ public class FileBlockHeader { | ||
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
133 | - * This method returns the memory address. | |
134 | - * @return the memory address | |
135 | - */ | |
136 | - public long getOldMemoryAddress() { | |
137 | - return oldMemoryAddress; | |
138 | - } | |
139 | - | |
140 | - /** | |
141 | 133 | * This method returns the sdna index. |
142 | 134 | * @return the sdna index |
143 | 135 | */ |
@@ -207,16 +207,6 @@ public class Structure implements Cloneable { | ||
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
210 | - * This method returns the field name of the given index. | |
211 | - * @param fieldIndex | |
212 | - * the index of the field | |
213 | - * @return the field name of the given index | |
214 | - */ | |
215 | - public String getFieldName(int fieldIndex) { | |
216 | - return fields[fieldIndex].name; | |
217 | - } | |
218 | - | |
219 | - /** | |
220 | 210 | * This method returns the full field name of the given index. |
221 | 211 | * @param fieldIndex |
222 | 212 | * the index of the field |
@@ -278,10 +268,9 @@ public class Structure implements Cloneable { | ||
278 | 268 | |
279 | 269 | /** |
280 | 270 | * This enum enumerates all known data types that can be found in the blend file. |
281 | - * @author Marcin Roguski | |
271 | + * @author Marcin Roguski (Kaelthas) | |
282 | 272 | */ |
283 | - /* package */ | |
284 | - static enum DataType { | |
273 | + /* package */ static enum DataType { | |
285 | 274 | |
286 | 275 | CHARACTER, SHORT, INTEGER, LONG, FLOAT, DOUBLE, VOID, STRUCTURE, POINTER; |
287 | 276 | /** The map containing the known primary types. */ |
@@ -60,11 +60,11 @@ public class LightHelper extends AbstractBlenderHelper { | ||
60 | 60 | * different blender versions. |
61 | 61 | * @param blenderVersion |
62 | 62 | * the version read from the blend file |
63 | - * @param fixUpAxis | |
64 | - * a variable that indicates if the Y asxis is the UP axis or not | |
63 | + * @param blenderContext | |
64 | + * the blender context | |
65 | 65 | */ |
66 | - public LightHelper(String blenderVersion, boolean fixUpAxis) { | |
67 | - super(blenderVersion, fixUpAxis); | |
66 | + public LightHelper(String blenderVersion, BlenderContext blenderContext) { | |
67 | + super(blenderVersion, blenderContext); | |
68 | 68 | } |
69 | 69 | |
70 | 70 | public LightNode toLight(Structure structure, BlenderContext blenderContext) throws BlenderFileException { |
@@ -164,6 +164,18 @@ public final class MaterialContext { | ||
164 | 164 | this.transparent = transparent; |
165 | 165 | } |
166 | 166 | |
167 | + /** | |
168 | + * Applies material to a given geometry. | |
169 | + * | |
170 | + * @param geometry | |
171 | + * the geometry | |
172 | + * @param geometriesOMA | |
173 | + * the geometries OMA | |
174 | + * @param userDefinedUVCoordinates | |
175 | + * UV coords defined by user | |
176 | + * @param blenderContext | |
177 | + * the blender context | |
178 | + */ | |
167 | 179 | public void applyMaterial(Geometry geometry, Long geometriesOMA, List<Vector2f> userDefinedUVCoordinates, BlenderContext blenderContext) { |
168 | 180 | Material material = null; |
169 | 181 | if (shadeless) { |
@@ -327,13 +339,6 @@ public final class MaterialContext { | ||
327 | 339 | } |
328 | 340 | |
329 | 341 | /** |
330 | - * @return the face cull mode | |
331 | - */ | |
332 | - public FaceCullMode getFaceCullMode() { | |
333 | - return faceCullMode; | |
334 | - } | |
335 | - | |
336 | - /** | |
337 | 342 | * This method returns the diffuse color. |
338 | 343 | * |
339 | 344 | * @param materialStructure |
@@ -31,9 +31,15 @@ | ||
31 | 31 | */ |
32 | 32 | package com.jme3.scene.plugins.blender.materials; |
33 | 33 | |
34 | +import java.nio.ByteBuffer; | |
35 | +import java.util.HashMap; | |
36 | +import java.util.List; | |
37 | +import java.util.Map; | |
38 | +import java.util.logging.Level; | |
39 | +import java.util.logging.Logger; | |
40 | + | |
34 | 41 | import com.jme3.asset.BlenderKey.FeaturesToLoad; |
35 | 42 | import com.jme3.material.MatParam; |
36 | -import com.jme3.material.MatParamTexture; | |
37 | 43 | import com.jme3.material.Material; |
38 | 44 | import com.jme3.math.ColorRGBA; |
39 | 45 | import com.jme3.math.FastMath; |
@@ -48,13 +54,6 @@ import com.jme3.texture.Image; | ||
48 | 54 | import com.jme3.texture.Image.Format; |
49 | 55 | import com.jme3.texture.Texture; |
50 | 56 | import com.jme3.util.BufferUtils; |
51 | -import java.nio.ByteBuffer; | |
52 | -import java.util.HashMap; | |
53 | -import java.util.List; | |
54 | -import java.util.Map; | |
55 | -import java.util.Map.Entry; | |
56 | -import java.util.logging.Level; | |
57 | -import java.util.logging.Logger; | |
58 | 57 | |
59 | 58 | public class MaterialHelper extends AbstractBlenderHelper { |
60 | 59 | private static final Logger LOGGER = Logger.getLogger(MaterialHelper.class.getName()); |
@@ -93,11 +92,11 @@ public class MaterialHelper extends AbstractBlenderHelper { | ||
93 | 92 | * |
94 | 93 | * @param blenderVersion |
95 | 94 | * the version read from the blend file |
96 | - * @param fixUpAxis | |
97 | - * a variable that indicates if the Y asxis is the UP axis or not | |
95 | + * @param blenderContext | |
96 | + * the blender context | |
98 | 97 | */ |
99 | - public MaterialHelper(String blenderVersion, boolean fixUpAxis) { | |
100 | - super(blenderVersion, false); | |
98 | + public MaterialHelper(String blenderVersion, BlenderContext blenderContext) { | |
99 | + super(blenderVersion, blenderContext); | |
101 | 100 | // setting alpha masks |
102 | 101 | alphaMasks.put(ALPHA_MASK_NONE, new IAlphaMask() { |
103 | 102 | public void setImageSize(int width, int height) { |
@@ -175,49 +174,6 @@ public class MaterialHelper extends AbstractBlenderHelper { | ||
175 | 174 | } |
176 | 175 | |
177 | 176 | /** |
178 | - * This method returns a material similar to the one given but without textures. If the material has no textures it is not cloned but | |
179 | - * returned itself. | |
180 | - * | |
181 | - * @param material | |
182 | - * a material to be cloned without textures | |
183 | - * @param imageType | |
184 | - * type of image defined by blender; the constants are defined in TextureHelper | |
185 | - * @return material without textures of a specified type | |
186 | - */ | |
187 | - public Material getNonTexturedMaterial(Material material, int imageType) { | |
188 | - String[] textureParamNames = new String[] { TEXTURE_TYPE_DIFFUSE, TEXTURE_TYPE_NORMAL, TEXTURE_TYPE_GLOW, TEXTURE_TYPE_SPECULAR, TEXTURE_TYPE_ALPHA }; | |
189 | - Map<String, Texture> textures = new HashMap<String, Texture>(textureParamNames.length); | |
190 | - for (String textureParamName : textureParamNames) { | |
191 | - MatParamTexture matParamTexture = material.getTextureParam(textureParamName); | |
192 | - if (matParamTexture != null) { | |
193 | - textures.put(textureParamName, matParamTexture.getTextureValue()); | |
194 | - } | |
195 | - } | |
196 | - if (textures.isEmpty()) { | |
197 | - return material; | |
198 | - } else { | |
199 | - // clear all textures first so that wo de not waste resources cloning them | |
200 | - for (Entry<String, Texture> textureParamName : textures.entrySet()) { | |
201 | - String name = textureParamName.getValue().getName(); | |
202 | - try { | |
203 | - int type = Integer.parseInt(name); | |
204 | - if (type == imageType) { | |
205 | - material.clearParam(textureParamName.getKey()); | |
206 | - } | |
207 | - } catch (NumberFormatException e) { | |
208 | - LOGGER.log(Level.WARNING, "The name of the texture does not contain the texture type value! {0} will not be removed!", name); | |
209 | - } | |
210 | - } | |
211 | - Material result = material.clone(); | |
212 | - // put the textures back in place | |
213 | - for (Entry<String, Texture> textureEntry : textures.entrySet()) { | |
214 | - material.setTexture(textureEntry.getKey(), textureEntry.getValue()); | |
215 | - } | |
216 | - return result; | |
217 | - } | |
218 | - } | |
219 | - | |
220 | - /** | |
221 | 177 | * This method converts the given material into particles-usable material. |
222 | 178 | * The texture and glow color are being copied. |
223 | 179 | * The method assumes it receives the Lighting type of material. |
@@ -270,53 +226,6 @@ public class MaterialHelper extends AbstractBlenderHelper { | ||
270 | 226 | } |
271 | 227 | |
272 | 228 | /** |
273 | - * This method indicates if the material has any kind of texture. | |
274 | - * | |
275 | - * @param material | |
276 | - * the material | |
277 | - * @return <b>true</b> if the texture exists in the material and <B>false</b> otherwise | |
278 | - */ | |
279 | - public boolean hasTexture(Material material) { | |
280 | - if (material != null) { | |
281 | - if (material.getTextureParam(TEXTURE_TYPE_ALPHA) != null) { | |
282 | - return true; | |
283 | - } | |
284 | - if (material.getTextureParam(TEXTURE_TYPE_COLOR) != null) { | |
285 | - return true; | |
286 | - } | |
287 | - if (material.getTextureParam(TEXTURE_TYPE_DIFFUSE) != null) { | |
288 | - return true; | |
289 | - } | |
290 | - if (material.getTextureParam(TEXTURE_TYPE_GLOW) != null) { | |
291 | - return true; | |
292 | - } | |
293 | - if (material.getTextureParam(TEXTURE_TYPE_NORMAL) != null) { | |
294 | - return true; | |
295 | - } | |
296 | - if (material.getTextureParam(TEXTURE_TYPE_SPECULAR) != null) { | |
297 | - return true; | |
298 | - } | |
299 | - } | |
300 | - return false; | |
301 | - } | |
302 | - | |
303 | - /** | |
304 | - * This method indicates if the material has a texture of a specified type. | |
305 | - * | |
306 | - * @param material | |
307 | - * the material | |
308 | - * @param textureType | |
309 | - * the type of the texture | |
310 | - * @return <b>true</b> if the texture exists in the material and <B>false</b> otherwise | |
311 | - */ | |
312 | - public boolean hasTexture(Material material, String textureType) { | |
313 | - if (material != null) { | |
314 | - return material.getTextureParam(textureType) != null; | |
315 | - } | |
316 | - return false; | |
317 | - } | |
318 | - | |
319 | - /** | |
320 | 229 | * This method returns the table of materials connected to the specified structure. The given structure can be of any type (ie. mesh or |
321 | 230 | * curve) but needs to have 'mat' field/ |
322 | 231 | * |
@@ -12,6 +12,11 @@ import com.jme3.math.Vector2f; | ||
12 | 12 | import com.jme3.math.Vector3f; |
13 | 13 | import com.jme3.util.BufferUtils; |
14 | 14 | |
15 | +/** | |
16 | + * A builder class for meshes. | |
17 | + * | |
18 | + * @author Marcin Roguski (Kaelthas) | |
19 | + */ | |
15 | 20 | /*package*/class MeshBuilder { |
16 | 21 | private static final Logger LOGGER = Logger.getLogger(MeshBuilder.class.getName()); |
17 | 22 |
@@ -18,8 +18,6 @@ public class MeshContext { | ||
18 | 18 | private Map<Integer, Geometry> geometries = new HashMap<Integer, Geometry>(); |
19 | 19 | /** The vertex reference map. */ |
20 | 20 | private Map<Integer, Map<Integer, List<Integer>>> vertexReferenceMap; |
21 | - /** The UV-coordinates for each of the geometries. */ | |
22 | - private Map<Geometry, VertexBuffer> uvCoordinates = new HashMap<Geometry, VertexBuffer>(); | |
23 | 21 | /** Bind buffer for vertices is stored here and applied when required. */ |
24 | 22 | private Map<Integer, VertexBuffer> bindPoseBuffer = new HashMap<Integer, VertexBuffer>(); |
25 | 23 | /** Bind buffer for normals is stored here and applied when required. */ |
@@ -82,29 +80,6 @@ public class MeshContext { | ||
82 | 80 | } |
83 | 81 | |
84 | 82 | /** |
85 | - * This method adds the mesh's UV-coordinates. | |
86 | - * | |
87 | - * @param geometry | |
88 | - * the mesh that has the UV-coordinates | |
89 | - * @param vertexBuffer | |
90 | - * the mesh's UV-coordinates | |
91 | - */ | |
92 | - public void addUVCoordinates(Geometry geometry, VertexBuffer vertexBuffer) { | |
93 | - uvCoordinates.put(geometry, vertexBuffer); | |
94 | - } | |
95 | - | |
96 | - /** | |
97 | - * This method returns the mesh's UV-coordinates. | |
98 | - * | |
99 | - * @param geometry | |
100 | - * the mesh | |
101 | - * @return the mesh's UV-coordinates | |
102 | - */ | |
103 | - public VertexBuffer getUVCoordinates(Geometry geometry) { | |
104 | - return uvCoordinates.get(geometry); | |
105 | - } | |
106 | - | |
107 | - /** | |
108 | 83 | * This method sets the bind buffer for vertices. |
109 | 84 | * |
110 | 85 | * @param materialIndex |
@@ -71,11 +71,11 @@ public class MeshHelper extends AbstractBlenderHelper { | ||
71 | 71 | * |
72 | 72 | * @param blenderVersion |
73 | 73 | * the version read from the blend file |
74 | - * @param fixUpAxis | |
75 | - * a variable that indicates if the Y asxis is the UP axis or not | |
74 | + * @param blenderContext | |
75 | + * the blender context | |
76 | 76 | */ |
77 | - public MeshHelper(String blenderVersion, boolean fixUpAxis) { | |
78 | - super(blenderVersion, fixUpAxis); | |
77 | + public MeshHelper(String blenderVersion, BlenderContext blenderContext) { | |
78 | + super(blenderVersion, blenderContext); | |
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -28,6 +28,7 @@ import com.jme3.scene.VertexBuffer.Usage; | ||
28 | 28 | import com.jme3.scene.plugins.blender.BlenderContext; |
29 | 29 | import com.jme3.scene.plugins.blender.BlenderContext.LoadedFeatureDataType; |
30 | 30 | import com.jme3.scene.plugins.blender.animations.ArmatureHelper; |
31 | +import com.jme3.scene.plugins.blender.animations.BoneContext; | |
31 | 32 | import com.jme3.scene.plugins.blender.exceptions.BlenderFileException; |
32 | 33 | import com.jme3.scene.plugins.blender.file.FileBlockHeader; |
33 | 34 | import com.jme3.scene.plugins.blender.file.Pointer; |
@@ -72,9 +73,7 @@ import com.jme3.util.BufferUtils; | ||
72 | 73 | */ |
73 | 74 | public ArmatureModifier(Structure objectStructure, Structure modifierStructure, BlenderContext blenderContext) throws BlenderFileException { |
74 | 75 | Structure meshStructure = ((Pointer) objectStructure.getFieldValue("data")).fetchData(blenderContext.getInputStream()).get(0); |
75 | - Pointer pDvert = (Pointer) meshStructure.getFieldValue("dvert");// dvert | |
76 | - // = | |
77 | - // DeformVERTices | |
76 | + Pointer pDvert = (Pointer) meshStructure.getFieldValue("dvert");// dvert = DeformVERTices | |
78 | 77 | |
79 | 78 | // if pDvert==null then there are not vertex groups and no need to load |
80 | 79 | // skeleton (untill bone envelopes are supported) |
@@ -162,9 +161,12 @@ import com.jme3.util.BufferUtils; | ||
162 | 161 | |
163 | 162 | // store the animation data for each bone |
164 | 163 | for (Bone bone : bones) { |
165 | - Long boneOma = armatureHelper.getBoneOMA(bone); | |
166 | - if (boneOma != null) { | |
167 | - blenderContext.setAnimData(boneOma, animData); | |
164 | + if(bone.getName().length() > 0) { | |
165 | + BoneContext boneContext = blenderContext.getBoneContext(bone); | |
166 | + Long boneOma = boneContext.getBoneOma(); | |
167 | + if (boneOma != null) { | |
168 | + blenderContext.setAnimData(boneOma, animData); | |
169 | + } | |
168 | 170 | } |
169 | 171 | } |
170 | 172 | } else { |
@@ -300,39 +302,18 @@ import com.jme3.util.BufferUtils; | ||
300 | 302 | |
301 | 303 | if (pDvert.isNotNull()) {// assigning weights and bone indices |
302 | 304 | boolean warnAboutTooManyVertexWeights = false; |
303 | - List<Structure> dverts = pDvert.fetchData(blenderContext.getInputStream());// dverts.size() | |
304 | - // == | |
305 | - // verticesAmount | |
306 | - // (one | |
307 | - // dvert | |
308 | - // per | |
309 | - // vertex | |
310 | - // in | |
311 | - // blender) | |
305 | + // dverts.size() = verticesAmount (one dvert per vertex in blender) | |
306 | + List<Structure> dverts = pDvert.fetchData(blenderContext.getInputStream()); | |
312 | 307 | int vertexIndex = 0; |
313 | 308 | // use tree map to sort weights from the lowest to the highest ones |
314 | 309 | TreeMap<Float, Integer> weightToIndexMap = new TreeMap<Float, Integer>(); |
315 | 310 | |
316 | 311 | for (Structure dvert : dverts) { |
317 | - List<Integer> vertexIndices = vertexReferenceMap.get(Integer.valueOf(vertexIndex));// we | |
318 | - // fetch | |
319 | - // the | |
320 | - // referenced | |
321 | - // vertices | |
322 | - // here | |
312 | + //we fetch the referenced vertices here | |
313 | + List<Integer> vertexIndices = vertexReferenceMap.get(Integer.valueOf(vertexIndex)); | |
323 | 314 | if (vertexIndices != null) { |
324 | - int totweight = ((Number) dvert.getFieldValue("totweight")).intValue();// total | |
325 | - // amount | |
326 | - // of | |
327 | - // weights | |
328 | - // assignet | |
329 | - // to | |
330 | - // the | |
331 | - // vertex | |
332 | - // (max. | |
333 | - // 4 | |
334 | - // in | |
335 | - // JME) | |
315 | + // total amount of wights assigned to the vertex (max. 4 in JME) | |
316 | + int totweight = ((Number) dvert.getFieldValue("totweight")).intValue(); | |
336 | 317 | Pointer pDW = (Pointer) dvert.getFieldValue("dw"); |
337 | 318 | if (totweight > 0 && groupToBoneIndexMap != null) { |
338 | 319 | weightToIndexMap.clear(); |
@@ -448,9 +429,4 @@ import com.jme3.util.BufferUtils; | ||
448 | 429 | } |
449 | 430 | weightsFloatData.rewind(); |
450 | 431 | } |
451 | - | |
452 | - @Override | |
453 | - public String getType() { | |
454 | - return Modifier.ARMATURE_MODIFIER_DATA; | |
455 | - } | |
456 | 432 | } |
@@ -239,9 +239,4 @@ import java.util.logging.Logger; | ||
239 | 239 | } |
240 | 240 | return node; |
241 | 241 | } |
242 | - | |
243 | - @Override | |
244 | - public String getType() { | |
245 | - return ARRAY_MODIFIER_DATA; | |
246 | - } | |
247 | 242 | } |
@@ -192,9 +192,4 @@ import com.jme3.scene.plugins.blender.objects.ObjectHelper; | ||
192 | 192 | } |
193 | 193 | return node; |
194 | 194 | } |
195 | - | |
196 | - @Override | |
197 | - public String getType() { | |
198 | - return Modifier.MIRROR_MODIFIER_DATA; | |
199 | - } | |
200 | 195 | } |
@@ -42,13 +42,6 @@ public abstract class Modifier { | ||
42 | 42 | public abstract Node apply(Node node, BlenderContext blenderContext); |
43 | 43 | |
44 | 44 | /** |
45 | - * This method returns blender's type of modifier. | |
46 | - * | |
47 | - * @return blender's type of modifier | |
48 | - */ | |
49 | - public abstract String getType(); | |
50 | - | |
51 | - /** | |
52 | 45 | * Determines if the modifier can be applied multiple times over one mesh. |
53 | 46 | * At this moment only armature and object animation modifiers cannot be |
54 | 47 | * applied multiple times. |
@@ -61,11 +61,11 @@ public class ModifierHelper extends AbstractBlenderHelper { | ||
61 | 61 | * |
62 | 62 | * @param blenderVersion |
63 | 63 | * the version read from the blend file |
64 | - * @param fixUpAxis | |
65 | - * a variable that indicates if the Y asxis is the UP axis or not | |
64 | + * @param blenderContext | |
65 | + * the blender context | |
66 | 66 | */ |
67 | - public ModifierHelper(String blenderVersion, boolean fixUpAxis) { | |
68 | - super(blenderVersion, fixUpAxis); | |
67 | + public ModifierHelper(String blenderVersion, BlenderContext blenderContext) { | |
68 | + super(blenderVersion, blenderContext); | |
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
@@ -103,7 +103,6 @@ public class ModifierHelper extends AbstractBlenderHelper { | ||
103 | 103 | if (modifier != null) { |
104 | 104 | if (modifier.isModifying()) { |
105 | 105 | result.add(modifier); |
106 | - blenderContext.addModifier(objectStructure.getOldMemoryAddress(), modifier); | |
107 | 106 | alreadyReadModifiers.add(modifierType); |
108 | 107 | } else { |
109 | 108 | 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 { | ||
155 | 154 | Ipo ipo = ipoHelper.fromIpoStructure(ipoStructure, blenderContext); |
156 | 155 | if (ipo != null) { |
157 | 156 | result = new ObjectAnimationModifier(ipo, objectStructure.getName(), objectStructure.getOldMemoryAddress(), blenderContext); |
158 | - blenderContext.addModifier(objectStructure.getOldMemoryAddress(), result); | |
159 | 157 | } |
160 | 158 | } |
161 | 159 | return result; |
@@ -186,7 +184,6 @@ public class ModifierHelper extends AbstractBlenderHelper { | ||
186 | 184 | Ipo ipo = ipoHelper.fromAction(actionStructure, blenderContext); |
187 | 185 | if (ipo != null) {// ipo can be null if it has no curves applied, ommit such modifier then |
188 | 186 | result = new ObjectAnimationModifier(ipo, actionStructure.getName(), objectStructure.getOldMemoryAddress(), blenderContext); |
189 | - blenderContext.addModifier(objectStructure.getOldMemoryAddress(), result); | |
190 | 187 | } |
191 | 188 | } |
192 | 189 | } |
@@ -86,9 +86,4 @@ import com.jme3.scene.plugins.ogre.AnimData; | ||
86 | 86 | } |
87 | 87 | return node; |
88 | 88 | } |
89 | - | |
90 | - @Override | |
91 | - public String getType() { | |
92 | - return Modifier.OBJECT_ANIMATION_MODIFIER_DATA; | |
93 | - } | |
94 | 89 | } |
@@ -92,9 +92,4 @@ import java.util.logging.Logger; | ||
92 | 92 | node.attachChild(emitter); |
93 | 93 | return node; |
94 | 94 | } |
95 | - | |
96 | - @Override | |
97 | - public String getType() { | |
98 | - return Modifier.PARTICLE_MODIFIER_DATA; | |
99 | - } | |
100 | 95 | } |
@@ -90,11 +90,11 @@ public class ObjectHelper extends AbstractBlenderHelper { | ||
90 | 90 | * |
91 | 91 | * @param blenderVersion |
92 | 92 | * the version read from the blend file |
93 | - * @param fixUpAxis | |
94 | - * a variable that indicates if the Y asxis is the UP axis or not | |
93 | + * @param blenderContext | |
94 | + * the blender context | |
95 | 95 | */ |
96 | - public ObjectHelper(String blenderVersion, boolean fixUpAxis) { | |
97 | - super(blenderVersion, fixUpAxis); | |
96 | + public ObjectHelper(String blenderVersion, BlenderContext blenderContext) { | |
97 | + super(blenderVersion, blenderContext); | |
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -214,7 +214,7 @@ public class ObjectHelper extends AbstractBlenderHelper { | ||
214 | 214 | // parent-children relationships between nodes |
215 | 215 | Node armature = new Node(name); |
216 | 216 | armature.setLocalTransform(t); |
217 | - armature.setUserData(ArmatureHelper.ARMETURE_NODE_MARKER, Boolean.TRUE); | |
217 | + armature.setUserData(ArmatureHelper.ARMATURE_NODE_MARKER, Boolean.TRUE); | |
218 | 218 | |
219 | 219 | if (parent instanceof Node) { |
220 | 220 | ((Node) parent).attachChild(armature); |
@@ -229,9 +229,9 @@ public class ObjectHelper extends AbstractBlenderHelper { | ||
229 | 229 | } |
230 | 230 | |
231 | 231 | if (result != null) { |
232 | - result.updateModelBound();// I prefer do compute bounding box here | |
233 | - // than read it from the file | |
234 | - | |
232 | + // I prefer do compute bounding box here than read it from the file | |
233 | + result.updateModelBound(); | |
234 | + | |
235 | 235 | blenderContext.addLoadedFeatures(objectStructure.getOldMemoryAddress(), name, objectStructure, result); |
236 | 236 | // TODO: this data is only to help during loading, shall I remove it |
237 | 237 | // after all the loading is done ??? |
@@ -341,11 +341,8 @@ public class ObjectHelper extends AbstractBlenderHelper { | ||
341 | 341 | public Matrix4f getMatrix(Structure structure, String matrixName, boolean applyFixUpAxis) { |
342 | 342 | Matrix4f result = new Matrix4f(); |
343 | 343 | DynamicArray<Number> obmat = (DynamicArray<Number>) structure.getFieldValue(matrixName); |
344 | - int rowAndColumnSize = Math.abs((int) Math.sqrt(obmat.getTotalSize()));// the | |
345 | - // matrix | |
346 | - // must | |
347 | - // be | |
348 | - // square | |
344 | + //the matrix must be square | |
345 | + int rowAndColumnSize = Math.abs((int) Math.sqrt(obmat.getTotalSize())); | |
349 | 346 | for (int i = 0; i < rowAndColumnSize; ++i) { |
350 | 347 | for (int j = 0; j < rowAndColumnSize; ++j) { |
351 | 348 | result.set(i, j, obmat.get(j, i).floatValue()); |
@@ -164,22 +164,6 @@ public class Properties implements Cloneable { | ||
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
167 | - * This method returns the description of the property. | |
168 | - * @return the description of the property | |
169 | - */ | |
170 | - public String getDescription() { | |
171 | - return description; | |
172 | - } | |
173 | - | |
174 | - /** | |
175 | - * This method returns the type of the property. | |
176 | - * @return the type of the property | |
177 | - */ | |
178 | - public int getType() { | |
179 | - return type; | |
180 | - } | |
181 | - | |
182 | - /** | |
183 | 167 | * This method returns the value of the property. |
184 | 168 | * The type of the value depends on the type of the property. |
185 | 169 | * @return the value of the property |
@@ -86,11 +86,11 @@ public class ParticlesHelper extends AbstractBlenderHelper { | ||
86 | 86 | * different blender versions. |
87 | 87 | * @param blenderVersion |
88 | 88 | * the version read from the blend file |
89 | - * @param fixUpAxis | |
90 | - * a variable that indicates if the Y asxis is the UP axis or not | |
89 | + * @param blenderContext | |
90 | + * the blender context | |
91 | 91 | */ |
92 | - public ParticlesHelper(String blenderVersion, boolean fixUpAxis) { | |
93 | - super(blenderVersion, fixUpAxis); | |
92 | + public ParticlesHelper(String blenderVersion, BlenderContext blenderContext) { | |
93 | + super(blenderVersion, blenderContext); | |
94 | 94 | } |
95 | 95 | |
96 | 96 | @SuppressWarnings("unchecked") |
@@ -99,7 +99,7 @@ public class TextureHelper extends AbstractBlenderHelper { | ||
99 | 99 | public static final int TEX_VOXELDATA = 15; // v. |
100 | 100 | // 25+ |
101 | 101 | |
102 | - private TextureGeneratorFactory textureGeneratorFactory; | |
102 | + private TextureGeneratorFactory textureGeneratorFactory = new TextureGeneratorFactory(); | |
103 | 103 | |
104 | 104 | /** |
105 | 105 | * This constructor parses the given blender version and stores the result. |
@@ -107,12 +107,11 @@ public class TextureHelper extends AbstractBlenderHelper { | ||
107 | 107 | * |
108 | 108 | * @param blenderVersion |
109 | 109 | * the version read from the blend file |
110 | - * @param fixUpAxis | |
111 | - * a variable that indicates if the Y asxis is the UP axis or not | |
110 | + * @param blenderContext | |
111 | + * the blender context | |
112 | 112 | */ |
113 | - public TextureHelper(String blenderVersion, boolean fixUpAxis) { | |
114 | - super(blenderVersion, false); | |
115 | - textureGeneratorFactory = new TextureGeneratorFactory(blenderVersion); | |
113 | + public TextureHelper(String blenderVersion, BlenderContext blenderContext) { | |
114 | + super(blenderVersion, blenderContext); | |
116 | 115 | } |
117 | 116 | |
118 | 117 | /** |
@@ -51,6 +51,7 @@ public class TextureBlenderAWT extends AbstractTextureBlender { | ||
51 | 51 | super(flag, negateTexture, blendType, materialColor, color, blendFactor); |
52 | 52 | } |
53 | 53 | |
54 | + @Override | |
54 | 55 | public Image blend(Image image, Image baseImage, BlenderContext blenderContext) { |
55 | 56 | this.prepareImagesForBlending(image, baseImage); |
56 | 57 |
@@ -31,11 +31,6 @@ | ||
31 | 31 | */ |
32 | 32 | package com.jme3.scene.plugins.blender.textures.generating; |
33 | 33 | |
34 | -import com.jme3.math.FastMath; | |
35 | -import com.jme3.scene.plugins.blender.AbstractBlenderHelper; | |
36 | -import com.jme3.scene.plugins.blender.BlenderContext; | |
37 | -import com.jme3.scene.plugins.blender.file.Structure; | |
38 | -import com.jme3.scene.plugins.blender.textures.generating.TextureGeneratorMusgrave.MusgraveData; | |
39 | 34 | import java.io.IOException; |
40 | 35 | import java.io.InputStream; |
41 | 36 | import java.io.ObjectInputStream; |
@@ -44,14 +39,16 @@ import java.util.Map; | ||
44 | 39 | import java.util.logging.Level; |
45 | 40 | import java.util.logging.Logger; |
46 | 41 | |
42 | +import com.jme3.math.FastMath; | |
43 | +import com.jme3.scene.plugins.blender.textures.generating.TextureGeneratorMusgrave.MusgraveData; | |
44 | + | |
47 | 45 | /** |
48 | 46 | * This generator is responsible for creating various noises used to create |
49 | 47 | * generated textures loaded from blender. |
50 | - * It derives from AbstractBlenderHelper but is not stored in blender context. | |
51 | 48 | * It is only used by TextureHelper. |
52 | 49 | * @author Marcin Roguski (Kaelthas) |
53 | 50 | */ |
54 | -/* package */class NoiseGenerator extends AbstractBlenderHelper { | |
51 | +/* package */class NoiseGenerator { | |
55 | 52 | private static final Logger LOGGER = Logger.getLogger(NoiseGenerator.class.getName()); |
56 | 53 | |
57 | 54 | // tex->stype |
@@ -79,21 +76,11 @@ import java.util.logging.Logger; | ||
79 | 76 | protected static float[][] g; |
80 | 77 | |
81 | 78 | /** |
82 | - * Constructor. Stores the blender version number and loads the constants needed for computations. | |
83 | - * @param blenderVersion | |
84 | - * the number of blender version | |
79 | + * Constructor. Loads the constants needed for computations. They are exactly like the ones the blender uses. Each | |
80 | + * deriving class should override this method and load its own constraints. | |
85 | 81 | */ |
86 | - public NoiseGenerator(String blenderVersion) { | |
87 | - super(blenderVersion, false); | |
88 | - this.loadConstants(); | |
89 | - } | |
90 | - | |
91 | - /** | |
92 | - * This method loads the constants needed for computations. They are exactly like the ones the blender uses. Each | |
93 | - * deriving class should override this method and load its own constraints. Be carefult with overriding though, if | |
94 | - * an exception will be thrown the class will not be instantiated. | |
95 | - */ | |
96 | - protected void loadConstants() { | |
82 | + public NoiseGenerator() { | |
83 | + LOGGER.fine("Loading noise constants."); | |
97 | 84 | InputStream is = NoiseGenerator.class.getResourceAsStream("noiseconstants.dat"); |
98 | 85 | try { |
99 | 86 | ObjectInputStream ois = new ObjectInputStream(is); |
@@ -791,11 +778,6 @@ import java.util.logging.Logger; | ||
791 | 778 | } |
792 | 779 | } |
793 | 780 | |
794 | - @Override | |
795 | - public boolean shouldBeLoaded(Structure structure, BlenderContext blenderContext) { | |
796 | - return true; | |
797 | - } | |
798 | - | |
799 | 781 | /** |
800 | 782 | * This interface is used for distance calculation classes. Distance metrics for voronoi. e parameter only used in |
801 | 783 | * Minkovsky. |
@@ -4,11 +4,7 @@ import com.jme3.scene.plugins.blender.textures.TextureHelper; | ||
4 | 4 | |
5 | 5 | public class TextureGeneratorFactory { |
6 | 6 | |
7 | - private NoiseGenerator noiseGenerator; | |
8 | - | |
9 | - public TextureGeneratorFactory(String blenderVersion) { | |
10 | - noiseGenerator = new NoiseGenerator(blenderVersion); | |
11 | - } | |
7 | + private NoiseGenerator noiseGenerator = new NoiseGenerator(); | |
12 | 8 | |
13 | 9 | public TextureGenerator createTextureGenerator(int generatedTexture) { |
14 | 10 | switch (generatedTexture) { |