Fix a bug with animation when Y axis was UP.
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8270 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
03ffc22446
commit
c58ffe4ddc
@ -34,6 +34,8 @@ package com.jme3.scene.plugins.blender;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.util.List;
|
||||
|
||||
import com.jme3.math.FastMath;
|
||||
import com.jme3.math.Quaternion;
|
||||
import com.jme3.scene.plugins.blender.exceptions.BlenderFileException;
|
||||
import com.jme3.scene.plugins.blender.file.Pointer;
|
||||
import com.jme3.scene.plugins.blender.file.Structure;
|
||||
@ -49,7 +51,11 @@ public abstract class AbstractBlenderHelper {
|
||||
|
||||
/** The version of the blend file. */
|
||||
protected final int blenderVersion;
|
||||
|
||||
/** This variable indicates if the Y asxis is the UP axis or not. */
|
||||
protected boolean fixUpAxis;
|
||||
/** Quaternion used to rotate data when Y is up axis. */
|
||||
protected Quaternion upAxisRotationQuaternion;
|
||||
|
||||
/**
|
||||
* This constructor parses the given blender version and stores the result. Some functionalities may differ in different blender
|
||||
* versions.
|
||||
@ -60,6 +66,18 @@ public abstract class AbstractBlenderHelper {
|
||||
this.blenderVersion = Integer.parseInt(blenderVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method sets the Y is UP axis. By default the UP axis is Z (just like in blender).
|
||||
* @param fixUpAxis
|
||||
* a variable that indicates if the Y asxis is the UP axis or not
|
||||
*/
|
||||
public void setyIsUpAxis(boolean fixUpAxis) {
|
||||
this.fixUpAxis = fixUpAxis;
|
||||
if(fixUpAxis) {
|
||||
upAxisRotationQuaternion = new Quaternion().fromAngles(-FastMath.HALF_PI, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method clears the state of the helper so that it can be used for different calculations of another feature.
|
||||
*/
|
||||
|
@ -205,10 +205,12 @@ public class BlenderLoader extends AbstractBlenderLoader {
|
||||
|
||||
// setting additional data to helpers
|
||||
if (blenderKey.isFixUpAxis()) {
|
||||
ObjectHelper objectHelper = blenderContext.getHelper(ObjectHelper.class);
|
||||
objectHelper.setyIsUpAxis(true);
|
||||
CurvesHelper curvesHelper = blenderContext.getHelper(CurvesHelper.class);
|
||||
curvesHelper.setyIsUpAxis(true);
|
||||
AbstractBlenderHelper helper = blenderContext.getHelper(ObjectHelper.class);
|
||||
helper.setyIsUpAxis(true);
|
||||
helper = blenderContext.getHelper(CurvesHelper.class);
|
||||
helper.setyIsUpAxis(true);
|
||||
helper = blenderContext.getHelper(ArmatureHelper.class);
|
||||
helper.setyIsUpAxis(true);
|
||||
}
|
||||
MaterialHelper materialHelper = blenderContext.getHelper(MaterialHelper.class);
|
||||
materialHelper.setFaceCullMode(blenderKey.getFaceCullMode());
|
||||
|
@ -41,6 +41,7 @@ import java.util.logging.Logger;
|
||||
import com.jme3.animation.Bone;
|
||||
import com.jme3.animation.BoneTrack;
|
||||
import com.jme3.math.Matrix4f;
|
||||
import com.jme3.math.Quaternion;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.scene.plugins.blender.AbstractBlenderHelper;
|
||||
import com.jme3.scene.plugins.blender.BlenderContext;
|
||||
@ -137,6 +138,21 @@ public class ArmatureHelper extends AbstractBlenderHelper {
|
||||
m.set(i, j, boneMat.get(j, i).floatValue());
|
||||
}
|
||||
}
|
||||
|
||||
if(fixUpAxis) {
|
||||
Vector3f translation = m.toTranslationVector();
|
||||
Quaternion rotation = m.toRotationQuat();
|
||||
|
||||
float y = translation.y;
|
||||
translation.y = translation.z;
|
||||
translation.z = -y;
|
||||
|
||||
rotation = upAxisRotationQuaternion.mult(rotation);
|
||||
|
||||
m.setRotationQuaternion(rotation);
|
||||
m.setTranslation(translation);
|
||||
//TODO: what about scale ??
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
|
@ -113,7 +113,7 @@ public class CalculationBone extends Node {
|
||||
|
||||
public void applyCalculatedTracks() {
|
||||
if(track != null) {
|
||||
track.setKeyframes(track.getTimes(), translations, rotations);//TODO:scales
|
||||
track.setKeyframes(track.getTimes(), translations, rotations, scales);
|
||||
} else {
|
||||
bone.setUserControl(true);
|
||||
bone.setUserTransforms(translations[0], rotations[0], scales[0]);
|
||||
|
@ -43,8 +43,6 @@ import com.jme3.util.BufferUtils;
|
||||
public class CurvesHelper extends AbstractBlenderHelper {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(CurvesHelper.class.getName());
|
||||
/** This variable indicates if the Y asxis is the UP axis or not. */
|
||||
protected boolean fixUpAxis;
|
||||
/** Minimum basis U function degree for NURBS curves and surfaces. */
|
||||
protected int minimumBasisUFunctionDegree = 4;
|
||||
/** Minimum basis V function degree for NURBS curves and surfaces. */
|
||||
@ -60,15 +58,6 @@ public class CurvesHelper extends AbstractBlenderHelper {
|
||||
super(blenderVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method sets the Y is UP axis. By default the UP axis is Z (just like in blender).
|
||||
* @param fixUpAxis
|
||||
* a variable that indicates if the Y asxis is the UP axis or not
|
||||
*/
|
||||
public void setyIsUpAxis(boolean fixUpAxis) {
|
||||
this.fixUpAxis = fixUpAxis;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method converts given curve structure into a list of geometries representing the curve. The list is used here because on object
|
||||
* can have several separate curves.
|
||||
|
@ -42,7 +42,6 @@ import com.jme3.light.DirectionalLight;
|
||||
import com.jme3.light.Light;
|
||||
import com.jme3.light.PointLight;
|
||||
import com.jme3.light.SpotLight;
|
||||
import com.jme3.math.FastMath;
|
||||
import com.jme3.math.Matrix4f;
|
||||
import com.jme3.math.Quaternion;
|
||||
import com.jme3.math.Transform;
|
||||
@ -96,11 +95,6 @@ public class ObjectHelper extends AbstractBlenderHelper {
|
||||
invisibleTypes.add(OBJECT_TYPE_ARMATURE);
|
||||
}
|
||||
|
||||
/** This variable indicates if the Y asxis is the UP axis or not. */
|
||||
protected boolean fixUpAxis;
|
||||
/** Quaternion used to rotate data when Y is up axis. */
|
||||
protected Quaternion upAxisRotationQuaternion;
|
||||
|
||||
/**
|
||||
* This constructor parses the given blender version and stores the result. Some functionalities may differ in
|
||||
* different blender versions.
|
||||
@ -111,18 +105,6 @@ public class ObjectHelper extends AbstractBlenderHelper {
|
||||
super(blenderVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method sets the Y is UP axis. By default the UP axis is Z (just like in blender).
|
||||
* @param fixUpAxis
|
||||
* a variable that indicates if the Y asxis is the UP axis or not
|
||||
*/
|
||||
public void setyIsUpAxis(boolean fixUpAxis) {
|
||||
this.fixUpAxis = fixUpAxis;
|
||||
if(fixUpAxis) {
|
||||
upAxisRotationQuaternion = new Quaternion().fromAngles(-FastMath.HALF_PI, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method reads the given structure and createn an object that represents the data.
|
||||
* @param objectStructure
|
||||
|
Loading…
x
Reference in New Issue
Block a user