From 4972fad991b01097a5cd3a46deb525a853208c3c Mon Sep 17 00:00:00 2001 From: "Kae..pl" Date: Tue, 4 Mar 2014 18:09:36 +0000 Subject: [PATCH] Feature: added support for 'Maintain volume' constraint. git-svn-id: https://jmonkeyengine.googlecode.com/svn/branches/gradle-restructure@11068 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../ConstraintDefinitionFactory.java | 2 +- .../ConstraintDefinitionMaintainVolume.java | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 jme3-blender/src/main/java/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinitionMaintainVolume.java diff --git a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinitionFactory.java b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinitionFactory.java index fba5ef1e4..cbf727290 100644 --- a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinitionFactory.java +++ b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinitionFactory.java @@ -52,6 +52,7 @@ public class ConstraintDefinitionFactory { CONSTRAINT_CLASSES.put("bSizeLimitConstraint", ConstraintDefinitionSizeLimit.class); CONSTRAINT_CLASSES.put("bKinematicConstraint", ConstraintDefinitionIK.class); CONSTRAINT_CLASSES.put("bTransLikeConstraint", ConstraintDefinitionTransLike.class);// since blender 2.51 + CONSTRAINT_CLASSES.put("bSameVolumeConstraint", ConstraintDefinitionMaintainVolume.class);// since blender 2.53 } private static final Map UNSUPPORTED_CONSTRAINTS = new HashMap(); @@ -73,7 +74,6 @@ public class ConstraintDefinitionFactory { UNSUPPORTED_CONSTRAINTS.put("bPivotConstraint", "Pivot"); // Blender 2.56+ UNSUPPORTED_CONSTRAINTS.put("bTrackToConstraint", "Track to"); - UNSUPPORTED_CONSTRAINTS.put("bSameVolumeConstraint", "Same volume"); // Blender 2.62+ UNSUPPORTED_CONSTRAINTS.put("bCameraSolverConstraint", "Camera solver"); UNSUPPORTED_CONSTRAINTS.put("bObjectSolverConstraint", "Object solver"); diff --git a/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinitionMaintainVolume.java b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinitionMaintainVolume.java new file mode 100644 index 000000000..75ee9fcbc --- /dev/null +++ b/jme3-blender/src/main/java/com/jme3/scene/plugins/blender/constraints/definitions/ConstraintDefinitionMaintainVolume.java @@ -0,0 +1,45 @@ +package com.jme3.scene.plugins.blender.constraints.definitions; + +import com.jme3.math.Transform; +import com.jme3.scene.plugins.blender.BlenderContext; +import com.jme3.scene.plugins.blender.constraints.ConstraintHelper.Space; +import com.jme3.scene.plugins.blender.file.Structure; + +public class ConstraintDefinitionMaintainVolume extends ConstraintDefinition { + private static final int FLAG_MASK_X = 0; + private static final int FLAG_MASK_Y = 1; + private static final int FLAG_MASK_Z = 2; + + private float volume; + + public ConstraintDefinitionMaintainVolume(Structure constraintData, Long ownerOMA, BlenderContext blenderContext) { + super(constraintData, ownerOMA, blenderContext); + volume = (float) Math.sqrt(((Number) constraintData.getFieldValue("volume")).floatValue()); + } + + @Override + public void bake(Space ownerSpace, Space targetSpace, Transform targetTransform, float influence) { + if (volume != 1 && influence > 0) { + Transform ownerTransform = this.getOwnerTransform(ownerSpace); + switch (flag) { + case FLAG_MASK_X: + ownerTransform.getScale().multLocal(1, volume, volume); + break; + case FLAG_MASK_Y: + ownerTransform.getScale().multLocal(volume, 1, volume); + break; + case FLAG_MASK_Z: + ownerTransform.getScale().multLocal(volume, volume, 1); + break; + default: + throw new IllegalStateException("Unknown flag value: " + flag); + } + this.applyOwnerTransform(ownerTransform, ownerSpace); + } + } + + @Override + public String getConstraintTypeName() { + return "Maintain volume"; + } +}