Bugfix: fixed a bug that caused NURB lines did not use their proper

resolution.
cleanup_build_scripts
jmekaelthas 9 years ago
parent 7e185b25df
commit 8958459ef9
  1. 57
      jme3-core/src/main/java/com/jme3/scene/shape/Curve.java

@ -198,35 +198,42 @@ public class Curve extends Mesh {
* points * points
*/ */
private void createNurbMesh(int nbSubSegments) { private void createNurbMesh(int nbSubSegments) {
float minKnot = spline.getMinNurbKnot(); if(spline.getControlPoints() != null && spline.getControlPoints().size() > 0) {
float maxKnot = spline.getMaxNurbKnot(); if(nbSubSegments == 0) {
float deltaU = (maxKnot - minKnot) / nbSubSegments; nbSubSegments = spline.getControlPoints().size() + 1;
} else {
nbSubSegments = spline.getControlPoints().size() * nbSubSegments + 1;
}
float minKnot = spline.getMinNurbKnot();
float maxKnot = spline.getMaxNurbKnot();
float deltaU = (maxKnot - minKnot) / nbSubSegments;
float[] array = new float[(nbSubSegments + 1) * 3]; float[] array = new float[(nbSubSegments + 1) * 3];
float u = minKnot; float u = minKnot;
Vector3f interpolationResult = new Vector3f(); Vector3f interpolationResult = new Vector3f();
for (int i = 0; i < array.length; i += 3) { for (int i = 0; i < array.length; i += 3) {
spline.interpolate(u, 0, interpolationResult); spline.interpolate(u, 0, interpolationResult);
array[i] = interpolationResult.x; array[i] = interpolationResult.x;
array[i + 1] = interpolationResult.y; array[i + 1] = interpolationResult.y;
array[i + 2] = interpolationResult.z; array[i + 2] = interpolationResult.z;
u += deltaU; u += deltaU;
} }
//calculating indexes //calculating indexes
int i = 0; int i = 0;
short[] indices = new short[nbSubSegments << 1]; short[] indices = new short[nbSubSegments << 1];
for (int j = 0; j < nbSubSegments; ++j) { for (int j = 0; j < nbSubSegments; ++j) {
indices[i++] = (short) j; indices[i++] = (short) j;
indices[i++] = (short) (j + 1); indices[i++] = (short) (j + 1);
} }
this.setMode(Mesh.Mode.Lines); this.setMode(Mesh.Mode.Lines);
this.setBuffer(VertexBuffer.Type.Position, 3, array); this.setBuffer(VertexBuffer.Type.Position, 3, array);
this.setBuffer(VertexBuffer.Type.Index, 2, indices); this.setBuffer(VertexBuffer.Type.Index, 2, indices);
this.updateBound(); this.updateBound();
this.updateCounts(); this.updateCounts();
}
} }
private void createLinearMesh() { private void createLinearMesh() {

Loading…
Cancel
Save