Bugfix: improved the computation precision for bezier curves (using
float's caused animations to be visibly different from the blender ).
This commit is contained in:
parent
5842613c2b
commit
e5cba265eb
@ -70,7 +70,7 @@ public class Ipo {
|
|||||||
* the frame for which the value is calculated
|
* the frame for which the value is calculated
|
||||||
* @return calculated ipo value
|
* @return calculated ipo value
|
||||||
*/
|
*/
|
||||||
public float calculateValue(int frame) {
|
public double calculateValue(int frame) {
|
||||||
return this.calculateValue(frame, 0);
|
return this.calculateValue(frame, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ public class Ipo {
|
|||||||
* the index of the curve
|
* the index of the curve
|
||||||
* @return calculated ipo value
|
* @return calculated ipo value
|
||||||
*/
|
*/
|
||||||
public float calculateValue(int frame, int curveIndex) {
|
public double calculateValue(int frame, int curveIndex) {
|
||||||
return bezierCurves[curveIndex].evaluate(frame, BezierCurve.Y_VALUE);
|
return bezierCurves[curveIndex].evaluate(frame, BezierCurve.Y_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,7 +170,7 @@ public class Ipo {
|
|||||||
for (int j = 0; j < bezierCurves.length; ++j) {
|
for (int j = 0; j < bezierCurves.length; ++j) {
|
||||||
double value = bezierCurves[j].evaluate(frame, BezierCurve.Y_VALUE);
|
double value = bezierCurves[j].evaluate(frame, BezierCurve.Y_VALUE);
|
||||||
switch (bezierCurves[j].getType()) {
|
switch (bezierCurves[j].getType()) {
|
||||||
// LOCATION
|
// LOCATION
|
||||||
case AC_LOC_X:
|
case AC_LOC_X:
|
||||||
translation[0] = (float) value;
|
translation[0] = (float) value;
|
||||||
break;
|
break;
|
||||||
@ -282,12 +282,12 @@ public class Ipo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float calculateValue(int frame) {
|
public double calculateValue(int frame) {
|
||||||
return constValue;
|
return constValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float calculateValue(int frame, int curveIndex) {
|
public double calculateValue(int frame, int curveIndex) {
|
||||||
return constValue;
|
return constValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ public abstract class Constraint {
|
|||||||
*/
|
*/
|
||||||
public void apply(int frame) {
|
public void apply(int frame) {
|
||||||
Transform targetTransform = targetOMA != null ? constraintHelper.getTransform(targetOMA, subtargetName, targetSpace) : null;
|
Transform targetTransform = targetOMA != null ? constraintHelper.getTransform(targetOMA, subtargetName, targetSpace) : null;
|
||||||
constraintDefinition.bake(ownerSpace, targetSpace, targetTransform, ipo.calculateValue(frame));
|
constraintDefinition.bake(ownerSpace, targetSpace, targetTransform, (float)ipo.calculateValue(frame));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -24,9 +24,9 @@ public class BezierCurve {
|
|||||||
/** The dimension of the curve. */
|
/** The dimension of the curve. */
|
||||||
private int dimension;
|
private int dimension;
|
||||||
/** A table of the bezier points. */
|
/** A table of the bezier points. */
|
||||||
private float[][][] bezierPoints;
|
private double[][][] bezierPoints;
|
||||||
/** Array that stores a radius for each bezier triple. */
|
/** Array that stores a radius for each bezier triple. */
|
||||||
private float[] radiuses;
|
private double[] radiuses;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public BezierCurve(final int type, final List<Structure> bezTriples, final int dimension) {
|
public BezierCurve(final int type, final List<Structure> bezTriples, final int dimension) {
|
||||||
@ -38,8 +38,8 @@ public class BezierCurve {
|
|||||||
// first index of the bezierPoints table has the length of triples amount
|
// first index of the bezierPoints table has the length of triples amount
|
||||||
// the second index points to a table od three points of a bezier triple (handle, point, handle)
|
// the second index points to a table od three points of a bezier triple (handle, point, handle)
|
||||||
// the third index specifies the coordinates of the specific point in a bezier triple
|
// the third index specifies the coordinates of the specific point in a bezier triple
|
||||||
bezierPoints = new float[bezTriples.size()][3][dimension];
|
bezierPoints = new double[bezTriples.size()][3][dimension];
|
||||||
radiuses = new float[bezTriples.size()];
|
radiuses = new double[bezTriples.size()];
|
||||||
int i = 0, j, k;
|
int i = 0, j, k;
|
||||||
for (Structure bezTriple : bezTriples) {
|
for (Structure bezTriple : bezTriples) {
|
||||||
DynamicArray<Number> vec = (DynamicArray<Number>) bezTriple.getFieldValue("vec");
|
DynamicArray<Number> vec = (DynamicArray<Number>) bezTriple.getFieldValue("vec");
|
||||||
@ -62,13 +62,13 @@ public class BezierCurve {
|
|||||||
* Z_VALUE - the Z factor of the result
|
* Z_VALUE - the Z factor of the result
|
||||||
* @return the value of the curve
|
* @return the value of the curve
|
||||||
*/
|
*/
|
||||||
public float evaluate(int frame, int valuePart) {
|
public double evaluate(int frame, int valuePart) {
|
||||||
for (int i = 0; i < bezierPoints.length - 1; ++i) {
|
for (int i = 0; i < bezierPoints.length - 1; ++i) {
|
||||||
if (frame >= bezierPoints[i][1][0] && frame <= bezierPoints[i + 1][1][0]) {
|
if (frame >= bezierPoints[i][1][0] && frame <= bezierPoints[i + 1][1][0]) {
|
||||||
float t = (frame - bezierPoints[i][1][0]) / (bezierPoints[i + 1][1][0] - bezierPoints[i][1][0]);
|
double t = (frame - bezierPoints[i][1][0]) / (bezierPoints[i + 1][1][0] - bezierPoints[i][1][0]);
|
||||||
float oneMinusT = 1.0f - t;
|
double oneMinusT = 1.0f - t;
|
||||||
float oneMinusT2 = oneMinusT * oneMinusT;
|
double oneMinusT2 = oneMinusT * oneMinusT;
|
||||||
float t2 = t * t;
|
double t2 = t * t;
|
||||||
return bezierPoints[i][1][valuePart] * oneMinusT2 * oneMinusT + 3.0f * bezierPoints[i][2][valuePart] * t * oneMinusT2 + 3.0f * bezierPoints[i + 1][0][valuePart] * t2 * oneMinusT + bezierPoints[i + 1][1][valuePart] * t2 * t;
|
return bezierPoints[i][1][valuePart] * oneMinusT2 * oneMinusT + 3.0f * bezierPoints[i][2][valuePart] * t * oneMinusT2 + 3.0f * bezierPoints[i + 1][0][valuePart] * t2 * oneMinusT + bezierPoints[i + 1][1][valuePart] * t2 * t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -103,7 +103,7 @@ public class BezierCurve {
|
|||||||
* index of the bezier triple
|
* index of the bezier triple
|
||||||
* @return radius of the required bezier triple
|
* @return radius of the required bezier triple
|
||||||
*/
|
*/
|
||||||
public float getRadius(int bezierTripleIndex) {
|
public double getRadius(int bezierTripleIndex) {
|
||||||
return radiuses[bezierTripleIndex];
|
return radiuses[bezierTripleIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,9 +114,9 @@ public class BezierCurve {
|
|||||||
public List<Vector3f> getControlPoints() {
|
public List<Vector3f> getControlPoints() {
|
||||||
List<Vector3f> controlPoints = new ArrayList<Vector3f>(bezierPoints.length * 3);
|
List<Vector3f> controlPoints = new ArrayList<Vector3f>(bezierPoints.length * 3);
|
||||||
for (int i = 0; i < bezierPoints.length; ++i) {
|
for (int i = 0; i < bezierPoints.length; ++i) {
|
||||||
controlPoints.add(new Vector3f(bezierPoints[i][0][0], bezierPoints[i][0][1], bezierPoints[i][0][2]));
|
controlPoints.add(new Vector3f((float)bezierPoints[i][0][0], (float)bezierPoints[i][0][1], (float)bezierPoints[i][0][2]));
|
||||||
controlPoints.add(new Vector3f(bezierPoints[i][1][0], bezierPoints[i][1][1], bezierPoints[i][1][2]));
|
controlPoints.add(new Vector3f((float)bezierPoints[i][1][0], (float)bezierPoints[i][1][1], (float)bezierPoints[i][1][2]));
|
||||||
controlPoints.add(new Vector3f(bezierPoints[i][2][0], bezierPoints[i][2][1], bezierPoints[i][2][2]));
|
controlPoints.add(new Vector3f((float)bezierPoints[i][2][0], (float)bezierPoints[i][2][1], (float)bezierPoints[i][2][2]));
|
||||||
}
|
}
|
||||||
return controlPoints;
|
return controlPoints;
|
||||||
}
|
}
|
||||||
@ -137,7 +137,7 @@ public class BezierCurve {
|
|||||||
* @return text representation of the triple
|
* @return text representation of the triple
|
||||||
*/
|
*/
|
||||||
private String toStringBezTriple(int tripleIndex) {
|
private String toStringBezTriple(int tripleIndex) {
|
||||||
if (this.dimension == 2) {
|
if (dimension == 2) {
|
||||||
return "[(" + bezierPoints[tripleIndex][0][0] + ", " + bezierPoints[tripleIndex][0][1] + ") (" + bezierPoints[tripleIndex][1][0] + ", " + bezierPoints[tripleIndex][1][1] + ") (" + bezierPoints[tripleIndex][2][0] + ", " + bezierPoints[tripleIndex][2][1] + ")]";
|
return "[(" + bezierPoints[tripleIndex][0][0] + ", " + bezierPoints[tripleIndex][0][1] + ") (" + bezierPoints[tripleIndex][1][0] + ", " + bezierPoints[tripleIndex][1][1] + ") (" + bezierPoints[tripleIndex][2][0] + ", " + bezierPoints[tripleIndex][2][1] + ")]";
|
||||||
} else {
|
} else {
|
||||||
return "[(" + bezierPoints[tripleIndex][0][0] + ", " + bezierPoints[tripleIndex][0][1] + ", " + bezierPoints[tripleIndex][0][2] + ") (" + bezierPoints[tripleIndex][1][0] + ", " + bezierPoints[tripleIndex][1][1] + ", " + bezierPoints[tripleIndex][1][2] + ") (" + bezierPoints[tripleIndex][2][0] + ", " + bezierPoints[tripleIndex][2][1] + ", " + bezierPoints[tripleIndex][2][2] + ")]";
|
return "[(" + bezierPoints[tripleIndex][0][0] + ", " + bezierPoints[tripleIndex][0][1] + ", " + bezierPoints[tripleIndex][0][2] + ") (" + bezierPoints[tripleIndex][1][0] + ", " + bezierPoints[tripleIndex][1][1] + ", " + bezierPoints[tripleIndex][1][2] + ") (" + bezierPoints[tripleIndex][2][0] + ", " + bezierPoints[tripleIndex][2][1] + ", " + bezierPoints[tripleIndex][2][2] + ")]";
|
||||||
|
@ -289,7 +289,7 @@ public class CurvesHelper extends AbstractBlenderHelper {
|
|||||||
int triplesCount = controlPoints.size() / 3;
|
int triplesCount = controlPoints.size() / 3;
|
||||||
List<Vector3f> taperControlPoints = new ArrayList<Vector3f>(triplesCount);
|
List<Vector3f> taperControlPoints = new ArrayList<Vector3f>(triplesCount);
|
||||||
for (int i = 0; i < triplesCount; ++i) {
|
for (int i = 0; i < triplesCount; ++i) {
|
||||||
taperControlPoints.add(new Vector3f(controlPoints.get(i * 3 + 1).x, bezierCurve.getRadius(i), 0));
|
taperControlPoints.add(new Vector3f(controlPoints.get(i * 3 + 1).x, (float)bezierCurve.getRadius(i), 0));
|
||||||
}
|
}
|
||||||
taperObject = new Spline(SplineType.Linear, taperControlPoints, 0, false);
|
taperObject = new Spline(SplineType.Linear, taperControlPoints, 0, false);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user