|
|
@ -39,11 +39,12 @@ import java.util.Iterator; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* A <code>Curve</code> is a visual, line-based representation of a {@link Spline}. |
|
|
|
* A |
|
|
|
* The underlying Spline will be sampled N times where N is the number of |
|
|
|
* <code>Curve</code> is a visual, line-based representation of a {@link Spline}. |
|
|
|
* segments as specified in the constructor. Each segment will represent |
|
|
|
* The underlying Spline will be sampled N times where N is the number of |
|
|
|
* one line in the generated mesh. |
|
|
|
* segments as specified in the constructor. Each segment will represent one |
|
|
|
* |
|
|
|
* line in the generated mesh. |
|
|
|
|
|
|
|
* |
|
|
|
* @author Nehon |
|
|
|
* @author Nehon |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class Curve extends Mesh { |
|
|
|
public class Curve extends Mesh { |
|
|
@ -54,13 +55,12 @@ public class Curve extends Mesh { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Serialization only. Do not use. |
|
|
|
* Serialization only. Do not use. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public Curve(){ |
|
|
|
public Curve() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Create a curve mesh. |
|
|
|
* Create a curve mesh. Use a CatmullRom spline model that does not cycle. |
|
|
|
* Use a CatmullRom spline model that does not cycle. |
|
|
|
* |
|
|
|
* |
|
|
|
|
|
|
|
* @param controlPoints the control points to use to create this curve |
|
|
|
* @param controlPoints the control points to use to create this curve |
|
|
|
* @param nbSubSegments the number of subsegments between the control points |
|
|
|
* @param nbSubSegments the number of subsegments between the control points |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -70,7 +70,7 @@ public class Curve extends Mesh { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Create a curve mesh from a Spline |
|
|
|
* Create a curve mesh from a Spline |
|
|
|
* |
|
|
|
* |
|
|
|
* @param spline the spline to use |
|
|
|
* @param spline the spline to use |
|
|
|
* @param nbSubSegments the number of subsegments between the control points |
|
|
|
* @param nbSubSegments the number of subsegments between the control points |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -79,17 +79,17 @@ public class Curve extends Mesh { |
|
|
|
this.spline = spline; |
|
|
|
this.spline = spline; |
|
|
|
switch (spline.getType()) { |
|
|
|
switch (spline.getType()) { |
|
|
|
case CatmullRom: |
|
|
|
case CatmullRom: |
|
|
|
this.createCatmullRomMesh(nbSubSegments); |
|
|
|
this.createCatmullRomMesh(nbSubSegments); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Bezier: |
|
|
|
case Bezier: |
|
|
|
this.createBezierMesh(nbSubSegments); |
|
|
|
this.createBezierMesh(nbSubSegments); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Nurb: |
|
|
|
case Nurb: |
|
|
|
this.createNurbMesh(nbSubSegments); |
|
|
|
this.createNurbMesh(nbSubSegments); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case Linear: |
|
|
|
case Linear: |
|
|
|
default: |
|
|
|
default: |
|
|
|
this.createLinearMesh(); |
|
|
|
this.createLinearMesh(); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -122,7 +122,7 @@ public class Curve extends Mesh { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
i = 0; |
|
|
|
i = 0; |
|
|
|
int k = 0; |
|
|
|
int k; |
|
|
|
for (int j = 0; j < (spline.getControlPoints().size() - 1) * nbSubSegments; j++) { |
|
|
|
for (int j = 0; j < (spline.getControlPoints().size() - 1) * nbSubSegments; j++) { |
|
|
|
k = j; |
|
|
|
k = j; |
|
|
|
indices[i] = (short) k; |
|
|
|
indices[i] = (short) k; |
|
|
@ -140,100 +140,101 @@ public class Curve extends Mesh { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* This method creates the Bezier path for this curve. |
|
|
|
* This method creates the Bezier path for this curve. |
|
|
|
* |
|
|
|
* |
|
|
|
* @param nbSubSegments |
|
|
|
* @param nbSubSegments amount of subsegments between position control |
|
|
|
* amount of subsegments between position control points |
|
|
|
* points |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void createBezierMesh(int nbSubSegments) { |
|
|
|
private void createBezierMesh(int nbSubSegments) { |
|
|
|
if(nbSubSegments==0) { |
|
|
|
if (nbSubSegments == 0) { |
|
|
|
nbSubSegments = 1; |
|
|
|
nbSubSegments = 1; |
|
|
|
} |
|
|
|
} |
|
|
|
int centerPointsAmount = (spline.getControlPoints().size() + 2) / 3; |
|
|
|
int centerPointsAmount = (spline.getControlPoints().size() + 2) / 3; |
|
|
|
|
|
|
|
|
|
|
|
//calculating vertices
|
|
|
|
//calculating vertices
|
|
|
|
float[] array = new float[((centerPointsAmount - 1) * nbSubSegments + 1) * 3]; |
|
|
|
float[] array = new float[((centerPointsAmount - 1) * nbSubSegments + 1) * 3]; |
|
|
|
int currentControlPoint = 0; |
|
|
|
int currentControlPoint = 0; |
|
|
|
List<Vector3f> controlPoints = spline.getControlPoints(); |
|
|
|
List<Vector3f> controlPoints = spline.getControlPoints(); |
|
|
|
int lineIndex = 0; |
|
|
|
int lineIndex = 0; |
|
|
|
for (int i = 0; i < centerPointsAmount - 1; ++i) { |
|
|
|
for (int i = 0; i < centerPointsAmount - 1; ++i) { |
|
|
|
Vector3f vector3f = controlPoints.get(currentControlPoint); |
|
|
|
Vector3f vector3f = controlPoints.get(currentControlPoint); |
|
|
|
array[lineIndex++] = vector3f.x; |
|
|
|
array[lineIndex++] = vector3f.x; |
|
|
|
array[lineIndex++] = vector3f.y; |
|
|
|
array[lineIndex++] = vector3f.y; |
|
|
|
array[lineIndex++] = vector3f.z; |
|
|
|
array[lineIndex++] = vector3f.z; |
|
|
|
for (int j = 1; j < nbSubSegments; ++j) { |
|
|
|
for (int j = 1; j < nbSubSegments; ++j) { |
|
|
|
spline.interpolate((float) j / nbSubSegments, currentControlPoint, temp); |
|
|
|
spline.interpolate((float) j / nbSubSegments, currentControlPoint, temp); |
|
|
|
array[lineIndex++] = temp.getX(); |
|
|
|
array[lineIndex++] = temp.getX(); |
|
|
|
array[lineIndex++] = temp.getY(); |
|
|
|
array[lineIndex++] = temp.getY(); |
|
|
|
array[lineIndex++] = temp.getZ(); |
|
|
|
array[lineIndex++] = temp.getZ(); |
|
|
|
} |
|
|
|
} |
|
|
|
currentControlPoint += 3; |
|
|
|
currentControlPoint += 3; |
|
|
|
} |
|
|
|
} |
|
|
|
Vector3f vector3f = controlPoints.get(currentControlPoint); |
|
|
|
Vector3f vector3f = controlPoints.get(currentControlPoint); |
|
|
|
array[lineIndex++] = vector3f.x; |
|
|
|
array[lineIndex++] = vector3f.x; |
|
|
|
array[lineIndex++] = vector3f.y; |
|
|
|
array[lineIndex++] = vector3f.y; |
|
|
|
array[lineIndex++] = vector3f.z; |
|
|
|
array[lineIndex++] = vector3f.z; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//calculating indexes
|
|
|
|
|
|
|
|
int i = 0, k; |
|
|
|
|
|
|
|
short[] indices = new short[(centerPointsAmount - 1) * nbSubSegments << 1]; |
|
|
|
|
|
|
|
for (int j = 0; j < (centerPointsAmount - 1) * nbSubSegments; ++j) { |
|
|
|
|
|
|
|
k = j; |
|
|
|
|
|
|
|
indices[i++] = (short) k; |
|
|
|
|
|
|
|
++k; |
|
|
|
|
|
|
|
indices[i++] = (short) k; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.setMode(Mesh.Mode.Lines); |
|
|
|
|
|
|
|
this.setBuffer(VertexBuffer.Type.Position, 3, array); |
|
|
|
|
|
|
|
this.setBuffer(VertexBuffer.Type.Index, 2, indices); |
|
|
|
|
|
|
|
this.updateBound(); |
|
|
|
|
|
|
|
this.updateCounts(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* This method creates the Nurb path for this curve. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param nbSubSegments amount of subsegments between position control |
|
|
|
|
|
|
|
* points |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private void createNurbMesh(int nbSubSegments) { |
|
|
|
|
|
|
|
float minKnot = spline.getMinNurbKnot(); |
|
|
|
|
|
|
|
float maxKnot = spline.getMaxNurbKnot(); |
|
|
|
|
|
|
|
float deltaU = (maxKnot - minKnot) / nbSubSegments; |
|
|
|
|
|
|
|
|
|
|
|
//calculating indexes
|
|
|
|
float[] array = new float[(nbSubSegments + 1) * 3]; |
|
|
|
int i = 0, k = 0; |
|
|
|
|
|
|
|
short[] indices = new short[(centerPointsAmount - 1) * nbSubSegments << 1]; |
|
|
|
|
|
|
|
for (int j = 0; j < (centerPointsAmount - 1) * nbSubSegments; ++j) { |
|
|
|
|
|
|
|
k = j; |
|
|
|
|
|
|
|
indices[i++] = (short) k; |
|
|
|
|
|
|
|
++k; |
|
|
|
|
|
|
|
indices[i++] = (short) k; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.setMode(Mesh.Mode.Lines); |
|
|
|
float u = minKnot; |
|
|
|
this.setBuffer(VertexBuffer.Type.Position, 3, array); |
|
|
|
Vector3f interpolationResult = new Vector3f(); |
|
|
|
this.setBuffer(VertexBuffer.Type.Index, 2, indices); |
|
|
|
for (int i = 0; i < array.length; i += 3) { |
|
|
|
this.updateBound(); |
|
|
|
spline.interpolate(u, 0, interpolationResult); |
|
|
|
this.updateCounts(); |
|
|
|
array[i] = interpolationResult.x; |
|
|
|
} |
|
|
|
array[i + 1] = interpolationResult.y; |
|
|
|
|
|
|
|
array[i + 2] = interpolationResult.z; |
|
|
|
/** |
|
|
|
u += deltaU; |
|
|
|
* This method creates the Nurb path for this curve. |
|
|
|
} |
|
|
|
* @param nbSubSegments |
|
|
|
|
|
|
|
* amount of subsegments between position control points |
|
|
|
//calculating indexes
|
|
|
|
*/ |
|
|
|
int i = 0; |
|
|
|
private void createNurbMesh(int nbSubSegments) { |
|
|
|
short[] indices = new short[nbSubSegments << 1]; |
|
|
|
float minKnot = spline.getMinNurbKnot(); |
|
|
|
for (int j = 0; j < nbSubSegments; ++j) { |
|
|
|
float maxKnot = spline.getMaxNurbKnot(); |
|
|
|
indices[i++] = (short) j; |
|
|
|
float deltaU = (maxKnot - minKnot)/nbSubSegments; |
|
|
|
indices[i++] = (short) (j + 1); |
|
|
|
|
|
|
|
} |
|
|
|
float[] array = new float[(nbSubSegments + 1) * 3]; |
|
|
|
|
|
|
|
|
|
|
|
this.setMode(Mesh.Mode.Lines); |
|
|
|
float u = minKnot; |
|
|
|
this.setBuffer(VertexBuffer.Type.Position, 3, array); |
|
|
|
Vector3f interpolationResult = new Vector3f(); |
|
|
|
this.setBuffer(VertexBuffer.Type.Index, 2, indices); |
|
|
|
for(int i=0;i<array.length;i+=3) { |
|
|
|
this.updateBound(); |
|
|
|
spline.interpolate(u, 0, interpolationResult); |
|
|
|
this.updateCounts(); |
|
|
|
array[i] = interpolationResult.x; |
|
|
|
} |
|
|
|
array[i + 1] = interpolationResult.y; |
|
|
|
|
|
|
|
array[i + 2] = interpolationResult.z; |
|
|
|
|
|
|
|
u += deltaU; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//calculating indexes
|
|
|
|
|
|
|
|
int i = 0; |
|
|
|
|
|
|
|
short[] indices = new short[nbSubSegments << 1]; |
|
|
|
|
|
|
|
for (int j = 0; j < nbSubSegments; ++j) { |
|
|
|
|
|
|
|
indices[i++] = (short) j; |
|
|
|
|
|
|
|
indices[i++] = (short) (j + 1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.setMode(Mesh.Mode.Lines); |
|
|
|
|
|
|
|
this.setBuffer(VertexBuffer.Type.Position, 3, array); |
|
|
|
|
|
|
|
this.setBuffer(VertexBuffer.Type.Index, 2, indices); |
|
|
|
|
|
|
|
this.updateBound(); |
|
|
|
|
|
|
|
this.updateCounts(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void createLinearMesh() { |
|
|
|
private void createLinearMesh() { |
|
|
|
float[] array = new float[spline.getControlPoints().size() * 3]; |
|
|
|
float[] array = new float[spline.getControlPoints().size() * 3]; |
|
|
|
short[] indices = new short[(spline.getControlPoints().size() - 1) * 2]; |
|
|
|
short[] indices = new short[(spline.getControlPoints().size() - 1) * 2]; |
|
|
|
int i = 0; |
|
|
|
int i = 0; |
|
|
|
int cpt = 0; |
|
|
|
int cpt = 0; |
|
|
|
int k = 0; |
|
|
|
int k; |
|
|
|
int j = 0; |
|
|
|
int j = 0; |
|
|
|
for (Iterator<Vector3f> it = spline.getControlPoints().iterator(); it.hasNext();) { |
|
|
|
for (Iterator<Vector3f> it = spline.getControlPoints().iterator(); it.hasNext();) { |
|
|
|
Vector3f vector3f = it.next(); |
|
|
|
Vector3f vector3f = it.next(); |
|
|
@ -260,12 +261,13 @@ public class Curve extends Mesh { |
|
|
|
this.updateBound(); |
|
|
|
this.updateBound(); |
|
|
|
this.updateCounts(); |
|
|
|
this.updateCounts(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* This method returns the length of the curve. |
|
|
|
* This method returns the length of the curve. |
|
|
|
|
|
|
|
* |
|
|
|
* @return the length of the curve |
|
|
|
* @return the length of the curve |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public float getLength() { |
|
|
|
public float getLength() { |
|
|
|
return spline.getTotalLength(); |
|
|
|
return spline.getTotalLength(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|