|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jmex.subdivision.Subdivision
public abstract class Subdivision
An abstract class for subdivision of surfaces.
Implementing classes must implement prepare()
and doSubdivide()
and preferrably override computeNormals(TriMesh batch)
Usage of subclass SubdivisionButterfly
:
TriMesh mesh = {some trimesh};
Subdivision subdivision = new SubdivisionButterfly(mesh.getBatch(0)); // prepare for subdivision
subdivision.subdivide(); // subdivide
subdivision.apply(); // Applies the new subdivided buffers to the batch
subdivision.computeNormals(); // calculate new normals
Or you can use it without giving it a batch:
Subdivision subdivision = new SubdivisionButterfly();
subdivision.setVertexBuffer(batch.getVertexBuffer());
subdivision.setIndexBuffer(batch.getIndexBuffer());
subdivision.addToBufferList(batch.getTextureBuffer(0), Subdivision.BufferType.TEXTUREBUFFER);
subdivision.addToBufferList(batch.getTextureBuffer(1), Subdivision.BufferType.TEXTUREBUFFER);
subdivision.addToBufferList(batch.getColorBuffer(), Subdivision.BufferType.COLORBUFFER);
subdivision.subdivide(); // subdivide
subdivision.apply(mesh.getBatch(0)); // Applies the new subdivided buffers to the batch
subdivision.computeNormals(mesh.getBatch(0)); // calculate new normals
Nested Class Summary | |
---|---|
static class |
Subdivision.BufferType
Buffer types. |
protected class |
Subdivision.SubdivisionBuffer
|
Field Summary | |
---|---|
protected java.util.ArrayList<Subdivision.SubdivisionBuffer> |
buffers
|
protected java.nio.IntBuffer |
indexBuffer
|
protected java.util.ArrayList<Subdivision.SubdivisionBuffer> |
newBuffers
|
protected java.nio.IntBuffer |
newIndexBuffer
|
protected java.nio.FloatBuffer |
newVertexBuffer
|
protected java.nio.FloatBuffer |
vertexBuffer
|
Constructor Summary | |
---|---|
Subdivision()
Constructor for Subdivision |
|
Subdivision(java.nio.FloatBuffer vertexBuffer,
java.nio.IntBuffer indexBuffer)
Constructor for Subdivision |
|
Subdivision(TriMesh batch)
Constructor for Subdivision |
Method Summary | |
---|---|
void |
addToBufferList(java.nio.FloatBuffer buffer,
int elemSize,
boolean linear,
Subdivision.BufferType type)
Add a buffer to the list of buffers who are to be subdivided |
void |
addToBufferList(java.nio.FloatBuffer buffer,
Subdivision.BufferType type)
Add a buffer to the list of buffers who are to be subdivided |
boolean |
apply()
Applies the buffers to the set batch |
boolean |
apply(TriMesh batch)
Applies the buffers to the given batch |
void |
clearBufferList()
Clear the list of buffers to be interpolated |
void |
computeNormals()
Computes the normals for the set batch |
void |
computeNormals(TriMesh batch)
Computes normals for the given batch. |
protected abstract boolean |
doSubdivide()
The actual subdivision, places the new buffers in the members newVertexBuffer, newIndexBuffer, newBuffers |
TriMesh |
getBatch()
|
java.nio.IntBuffer |
getIndexBuffer()
|
java.nio.FloatBuffer |
getVertexBuffer()
|
int |
getVertexCount()
Get the vertex count of the set vertex buffer (capacity / 3) |
boolean |
isValid()
Checks whether the buffers submitted to this Subdivision are valid (i.e. |
abstract boolean |
prepare()
Whichever preparations are needed are to be performed here |
void |
removeBuffer(java.nio.FloatBuffer buffer)
Removes a buffer from the bufferlist |
void |
setBatch(TriMesh batch)
Sets a batch that this Subdivision should subdivide. |
void |
setIndexBuffer(java.nio.IntBuffer indexBuffer)
|
void |
setVertexBuffer(java.nio.FloatBuffer vertexBuffer)
|
boolean |
subdivide()
Performs the subdivision after checking that everything is ok |
void |
unsetBatch()
Unsets the batch. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.nio.FloatBuffer vertexBuffer
protected java.nio.FloatBuffer newVertexBuffer
protected java.nio.IntBuffer indexBuffer
protected java.nio.IntBuffer newIndexBuffer
protected java.util.ArrayList<Subdivision.SubdivisionBuffer> buffers
protected java.util.ArrayList<Subdivision.SubdivisionBuffer> newBuffers
Constructor Detail |
---|
public Subdivision()
public Subdivision(java.nio.FloatBuffer vertexBuffer, java.nio.IntBuffer indexBuffer)
vertexBuffer
- The vertex buffer to use when subdividing. Specify other buffers (normals,colors,texcoords) with addToBufferList
indexBuffer
- The index buffer to use when subdividingpublic Subdivision(TriMesh batch)
batch
- The TriMesh that are to be subdividedMethod Detail |
---|
public abstract boolean prepare()
true
if the preparation succeededprotected abstract boolean doSubdivide()
true
if the subdivision succeededpublic void setBatch(TriMesh batch)
addToBufferList(FloatBuffer buffer, int elemSize, boolean linear)
if you don't use this method.
Removes all other buffers. Replaces a previous batch.
Normals are not interpolated by default, since it gives poor results, call computeNormals() after subdividing instead. However, to interpolate the normals as well, just call addToBufferList() with the normal buffer after calling this method.
batch
- The batch to set.public boolean subdivide()
true
if the subdivision succeededpublic boolean apply()
true
if appliedpublic boolean apply(TriMesh batch)
batch
- The batch to apply the buffers to
true
if appliedpublic void computeNormals()
public void computeNormals(TriMesh batch)
batch
- public void unsetBatch()
public void addToBufferList(java.nio.FloatBuffer buffer, int elemSize, boolean linear, Subdivision.BufferType type)
buffer
- The buffer to be addedelemSize
- The size of the elements in the buffer (e.g. 3 for normal buffers, 2 for texture buffers, 4 for color buffers)linear
- Whether or not the buffer should be linearly interpolated (for example, it doesn't make sense to use higher-order interpolation on texture coordinates). Should probably be false
in most casestype
- The type of buffer, needed when applying buffers back to the batchpublic void addToBufferList(java.nio.FloatBuffer buffer, Subdivision.BufferType type)
buffer
- The buffer to be addedtype
- The type of buffer, needed when applying buffers back to the batchpublic void removeBuffer(java.nio.FloatBuffer buffer)
buffer
- The buffer to remove from the list of buffers to be subdividedpublic void clearBufferList()
public boolean isValid()
true
if validpublic TriMesh getBatch()
public java.nio.IntBuffer getIndexBuffer()
public void setIndexBuffer(java.nio.IntBuffer indexBuffer)
indexBuffer
- The indexBuffer to set.public java.nio.FloatBuffer getVertexBuffer()
public void setVertexBuffer(java.nio.FloatBuffer vertexBuffer)
vertexBuffer
- The vertexBuffer to set.public int getVertexCount()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |