Hey @all,
i wanna use bezier curves in my program like they were available on jme2. Is it planned to port the curve-, beziercurve, … -classes to jme3? Or are there similar classes? I also needed to port the disk class from jme2 to jme3. Maybe someone wanna use it.
[java]public class Disk extends Mesh {
private float centralAngle;
private int shellSamples;
private int radialSamples;
private float radius;
private boolean createBuffers = true;
public Disk() {
setMode(Mode.Triangles);
}
public Disk(int shellSamples, int radialSamples, float radius) {
this(FastMath.TWO_PI, shellSamples, radialSamples, radius);
}
/**
- Creates a flat sector of a disk (circle) at the origin flat along the Z.
- Usually, a higher sample number creates a better looking cylinder, but
- at the cost of more vertex information.
*
-
@param name
-
The name of the disk.<br />
-
@param shellSamples
-
The number of shell samples.<br />
-
@param radialSamples
-
The number of radial samples.<br />
-
@param radius
-
The radius of the disk.<br />
-
@param centralAngle
-
The central angle of the sector.<br />
*/
public Disk(float centralAngle, int shellSamples, int radialSamples, float radius) {
setMode(Mode.Triangles);
updateGeometry(centralAngle, shellSamples, radialSamples, radius);
}
public float getCentralAngle() {
return centralAngle;
}
public int getRadialSamples() {
return radialSamples;
}
public float getRadius() {
return radius;
}
public int getShellSamples() {
return shellSamples;
}
public void updateGeometry(float centralAngle, int shellSamples, int radialSamples, float radius) {
this.centralAngle = FastMath.normalize(centralAngle, -FastMath.TWO_PI, FastMath.TWO_PI);
this.shellSamples = shellSamples;
this.radialSamples = radialSamples;
this.radius = radius;
int shellLess = shellSamples - 1;
int vertexCount = 1 + (radialSamples + 1) * shellLess;
int triangleCount = radialSamples * (2 * shellLess - 1);
setVertexCount(vertexCount);
setTriangleCount(triangleCount);
FloatBuffer posBuffer = BufferUtils.createVector3Buffer(vertexCount);
FloatBuffer normBuffer = BufferUtils.createVector3Buffer(vertexCount);
IntBuffer indexBuffer = BufferUtils.createIntBuffer(3 * triangleCount);
FloatBuffer texBuffer = BufferUtils.createVector2Buffer(vertexCount);
// generate geometry
// center of disk
posBuffer.put(0).put(0).put(0);
for (int x = 0; x < getVertexCount(); x++) {
normBuffer.put(0).put(0).put(1);
}
texBuffer.put(.5f).put(.5f);
float inverseShellLess = 1.0f / shellLess;
float inverseRadial = 1.0f / radialSamples;
Vector3f radialFraction = new Vector3f();
Vector2f texCoord = new Vector2f();
for (int radialCount = 0; radialCount <= radialSamples; radialCount++) {
float angle = centralAngle * inverseRadial * radialCount;
float cos = FastMath.cos(angle);
float sin = FastMath.sin(angle);
Vector3f radial = new Vector3f(cos, sin, 0);
for (int shellCount = 1; shellCount < shellSamples; shellCount++) {
float fraction = inverseShellLess * shellCount; // in (0,R]
radialFraction.set(radial).multLocal(fraction);
int i = shellCount + shellLess * radialCount;
texCoord.x = 0.5f * (1.0f + radialFraction.x);
texCoord.y = 0.5f * (1.0f + radialFraction.y);
// BufferUtils.setInBuffer(texCoord, getTextureCoords().get(0).coords, i);
BufferUtils.setInBuffer(texCoord, texBuffer, i);
radialFraction.multLocal(radius);
BufferUtils.setInBuffer(radialFraction, posBuffer, i);
}
}
// Generate connectivity
int index = 0;
for (int radialCount0 = 0, radialCount1 = 1; radialCount1 <= radialSamples; radialCount0 = radialCount1++) {
indexBuffer.put(0).put(1 + shellLess * radialCount0).put(1 + shellLess * radialCount1);
index += 3;
for (int iS = 1; iS < shellLess; iS++, index += 6) {
int i00 = iS + shellLess * radialCount0;
int i01 = iS + shellLess * radialCount1;
int i10 = i00 + 1;
int i11 = i01 + 1;
indexBuffer
.put(i00).put(i10).put(i11)
.put(i00).put(i11).put(i01);
}
}
if (createBuffers) {
setBuffer(Type.Position, 3, posBuffer);
setBuffer(Type.Normal, 3, normBuffer);
setBuffer(Type.Index, 3, indexBuffer);
setBuffer(Type.TexCoord, 2, texBuffer);
createBuffers = false;
} else {
getBuffer(Type.Position).updateData(posBuffer);
getBuffer(Type.Normal).updateData(normBuffer);
getBuffer(Type.Index).updateData(indexBuffer);
getBuffer(Type.TexCoord).updateData(texBuffer);
}
updateBound();
updateCounts();
}
}[/java]
Regards
Moe