Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

import com.jme3.asset.TextureKey;
import com.jme3.asset.cache.AssetCache;
import com.jme3.asset.cache.WeakRefCloneAssetCache;
import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.jme3.scene.plugins.fbx;

public class FBXLoadingException extends RuntimeException {

private static final long serialVersionUID = -1641318378648889782L;

public FBXLoadingException() {
}

public FBXLoadingException(String message) {
super(message);
}

public FBXLoadingException(Throwable cause) {
super(cause);
}

public FBXLoadingException(String message, Throwable cause) {
super(message, cause);
}

public FBXLoadingException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.jme3.scene.plugins.fbx;

public enum InheritType {

RrSs, RSrs,
/**
* <p>Segment Scale Compensate
* <p>Resets scale of node to (1.0, 1.0, 1.0)
*/
Rrs;

public static final InheritType[] values = values();
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.jme3.scene.plugins.fbx;

import com.jme3.math.FastMath;
import com.jme3.math.Matrix4f;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;

public enum RotationOrder {

EULER_XYZ, EULER_XZY, EULER_YZX, EULER_YXZ, EULER_ZXY, EULER_ZYX, SPHERIC_XYZ;

// Static values field for fast access by an oridinal without Enum.values() overhead
public static final RotationOrder[] values = values();

private RotationOrder() {
Expand All @@ -22,6 +22,14 @@ public Quaternion rotate(float x, float y, float z) {
return fromEuler(x * FastMath.DEG_TO_RAD, y * FastMath.DEG_TO_RAD, z * FastMath.DEG_TO_RAD, this);
}

public Matrix4f rotateToMatrix(Vector3f vec) {
return fromEulerToMatrix(vec.x * FastMath.DEG_TO_RAD, vec.y * FastMath.DEG_TO_RAD, vec.z * FastMath.DEG_TO_RAD, this);
}

public Matrix4f rotateToMatrix(float x, float y, float z) {
return fromEulerToMatrix(x * FastMath.DEG_TO_RAD, y * FastMath.DEG_TO_RAD, z * FastMath.DEG_TO_RAD, this);
}

private static Quaternion fromEuler(float x, float y, float z, RotationOrder order) {
switch(order) {
case EULER_XYZ:
Expand All @@ -42,11 +50,62 @@ private static Quaternion fromEuler(float x, float y, float z, RotationOrder ord
}
}

private static Matrix4f fromEulerToMatrix(float x, float y, float z, RotationOrder order) {
Matrix4f c = new Matrix4f();
switch(order) {
case EULER_XYZ:
return rotationZ(z, null).multLocal(rotationY(y, c)).multLocal(rotationX(x, c));
case EULER_YXZ:
return rotationZ(z, null).multLocal(rotationX(x, c)).multLocal(rotationY(y, c));
case EULER_ZXY:
return rotationY(y, null).multLocal(rotationX(x, c)).multLocal(rotationZ(z, c));
case EULER_ZYX:
return rotationX(x, null).multLocal(rotationY(y, c)).multLocal(rotationZ(z, c));
case EULER_YZX:
return rotationX(x, null).multLocal(rotationZ(z, c)).multLocal(rotationY(y, c));
case EULER_XZY:
return rotationY(y, null).multLocal(rotationZ(z, c)).multLocal(rotationX(x, c));
case SPHERIC_XYZ:
default:
throw new IllegalArgumentException("Spheric rotation is unsupported in this importer");
}
}

private static Quaternion toQuat(float ax1v, Vector3f ax1, float ax2v, Vector3f ax2, float ax3v, Vector3f ax3) {
// TODO It has some potential in optimization
// TODO It has some potential for optimization
Quaternion q1 = new Quaternion().fromAngleNormalAxis(ax1v, ax1);
Quaternion q2 = new Quaternion().fromAngleNormalAxis(ax2v, ax2);
Quaternion q3 = new Quaternion().fromAngleNormalAxis(ax3v, ax3);
return q1.multLocal(q2).multLocal(q3);
return q3.multLocal(q2).multLocal(q1);// FBX uses order opposite of what stated in RotationOrder's names... Because.
}

private static Matrix4f rotationX(float r, Matrix4f out) {
if(out == null)
out = new Matrix4f();
else
out.loadIdentity();
out.m11 = out.m22 = FastMath.cos(r);
out.m12 = -(out.m21 = FastMath.sin(r));
return out;
}

private static Matrix4f rotationY(float r, Matrix4f out) {
if(out == null)
out = new Matrix4f();
else
out.loadIdentity();
out.m00 = out.m22 = FastMath.cos(r);
out.m20 = -(out.m02 = FastMath.sin(r));
return out;
}

private static Matrix4f rotationZ(float r, Matrix4f out) {
if(out == null)
out = new Matrix4f();
else
out.loadIdentity();
out.m00 = out.m11 = FastMath.cos(r);
out.m01 = -(out.m10 = FastMath.sin(r));
return out;
}
}
Loading