public class Mesh extends java.lang.Object implements Savable, java.lang.Cloneable, JmeCloneable
Mesh
is used to store rendering data.
All visible elements in a scene are represented by meshes. Meshes may contain three types of geometric primitives:
point
sprite
mode.Material.getAdditionalRenderState()
and RenderState.setLineWidth(float)
.Modifier and Type | Class and Description |
---|---|
static class |
Mesh.Mode
The mode of the Mesh specifies both the type of primitive represented
by the mesh and how the data should be interpreted.
|
Constructor and Description |
---|
Mesh()
Creates a new mesh with no
vertex buffers . |
Modifier and Type | Method and Description |
---|---|
void |
addMorphTarget(MorphTarget target) |
void |
clearBuffer(VertexBuffer.Type type)
Unsets the
VertexBuffer set on this mesh
with the given type. |
void |
clearCollisionData()
Clears any previously generated collision data.
|
Mesh |
clone()
Create a shallow clone of this Mesh.
|
void |
cloneFields(Cloner cloner,
java.lang.Object original)
Called internally by com.jme3.util.clone.Cloner.
|
Mesh |
cloneForAnim()
Clone the mesh for animation use.
|
int |
collideWith(Collidable other,
Matrix4f worldMatrix,
BoundingVolume worldBound,
CollisionResults results)
Handles collision detection, internal use only.
|
void |
createCollisionData()
Generates a collision tree for the mesh.
|
Mesh |
deepClone()
Creates a deep clone of this mesh.
|
void |
extractVertexData(Mesh other)
Extracts the vertex attributes from the given mesh into
this mesh, by using this mesh's
index buffer
to index into the attributes of the other mesh. |
void |
generateBindPose()
Generates the
VertexBuffer.Type.BindPosePosition , VertexBuffer.Type.BindPoseNormal ,
and VertexBuffer.Type.BindPoseTangent
buffers for this mesh by duplicating them based on the position and normal
buffers already set on the mesh. |
void |
generateBindPose(boolean forSoftwareAnim)
Deprecated.
use generateBindPose();
|
BoundingVolume |
getBound()
Returns the
BoundingVolume of this Mesh. |
VertexBuffer |
getBuffer(VertexBuffer.Type type)
Get the
VertexBuffer stored on this mesh with the given
type. |
SafeArrayList<VertexBuffer> |
getBufferList()
Returns a list of all
vertex buffers on this Mesh. |
IntMap<VertexBuffer> |
getBuffers()
Returns a map of all
vertex buffers on this Mesh. |
int[] |
getElementLengths()
Get the element lengths for
Mesh.Mode.Hybrid mesh mode. |
java.nio.FloatBuffer |
getFloatBuffer(VertexBuffer.Type type)
Get the
VertexBuffer data stored on this mesh in float
format. |
int |
getId()
Returns the mesh's VAO ID.
|
IndexBuffer |
getIndexBuffer()
Get the index buffer for this mesh.
|
IndexBuffer |
getIndicesAsList()
Acquires an index buffer that will read the vertices on the mesh
as a list.
|
int |
getInstanceCount()
Returns the number of instances this mesh contains.
|
float |
getLineWidth()
Deprecated.
|
VertexBuffer |
getLodLevel(int lod)
Returns the lod level at the given index.
|
int |
getMaxNumWeights()
Returns the maximum number of weights per vertex on this mesh.
|
Mesh.Mode |
getMode()
Returns the mesh mode
|
int[] |
getModeStart()
Set the mode start indices for
Mesh.Mode.Hybrid mesh mode. |
int |
getMorphIndex(java.lang.String morphName)
Get the index of the morph that has the given name.
|
MorphTarget |
getMorphTarget(int index)
Get the MorphTarget at the given index
|
java.lang.String[] |
getMorphTargetNames()
Get the name of all morphs in order.
|
MorphTarget[] |
getMorphTargets() |
int |
getNumLodLevels() |
int |
getPatchVertexCount()
Gets the amount of vertices used for each patch;
|
float |
getPointSize()
Deprecated.
Always returns
1.0 since point size is
determined in the vertex shader. |
java.nio.ShortBuffer |
getShortBuffer(VertexBuffer.Type type)
Get the
VertexBuffer data stored on this mesh in short
format. |
void |
getTriangle(int index,
int[] indices)
Gets the triangle vertex indices at the given triangle index
and stores them into the given int array.
|
void |
getTriangle(int index,
Triangle tri)
Gets the triangle vertex positions at the given triangle index
and stores them into the
Triangle argument. |
void |
getTriangle(int index,
Vector3f v1,
Vector3f v2,
Vector3f v3)
Gets the triangle vertex positions at the given triangle index
and stores them into the v1, v2, v3 arguments.
|
int |
getTriangleCount()
Returns how many triangles or elements are on this Mesh.
|
int |
getTriangleCount(int lod)
Returns the triangle count for the given LOD level.
|
int |
getVertexCount()
Returns the number of vertices on this mesh.
|
boolean |
hasMorphTargets() |
boolean |
isAnimated()
Determines if the mesh uses bone animation.
|
boolean |
isAnimatedByBone(int boneIndex)
Deprecated.
use isAnimatedByJoint
|
boolean |
isAnimatedByJoint(int jointIndex)
Test whether the specified bone animates this mesh.
|
Mesh |
jmeClone()
Called internally by com.jme3.util.clone.Cloner.
|
void |
prepareForAnim(boolean forSoftwareAnim)
Prepares the mesh for software skinning by converting the bone index
and weight buffers to heap buffers.
|
void |
read(JmeImporter im) |
MorphTarget |
removeMorphTarget(int index)
Remove the MorphTarget from the Mesh at the given index
|
boolean |
removeMorphTarget(MorphTarget target)
Remove the given MorphTarget from the Mesh
|
void |
scaleTextureCoordinates(Vector2f scaleFactor)
Scales the texture coordinate buffer on this mesh by the given scale
factor.
|
void |
setBound(BoundingVolume modelBound)
Sets the
BoundingVolume for this Mesh. |
void |
setBuffer(VertexBuffer.Type type,
int components,
byte[] buf) |
void |
setBuffer(VertexBuffer.Type type,
int components,
java.nio.ByteBuffer buf) |
void |
setBuffer(VertexBuffer.Type type,
int components,
float[] buf) |
void |
setBuffer(VertexBuffer.Type type,
int components,
java.nio.FloatBuffer buf)
Set a floating point
VertexBuffer on the mesh. |
void |
setBuffer(VertexBuffer.Type type,
int components,
int[] buf) |
void |
setBuffer(VertexBuffer.Type type,
int components,
java.nio.IntBuffer buf) |
void |
setBuffer(VertexBuffer.Type type,
int components,
short[] buf) |
void |
setBuffer(VertexBuffer.Type type,
int components,
java.nio.ShortBuffer buf) |
void |
setBuffer(VertexBuffer.Type type,
int components,
VertexBuffer.Format format,
java.nio.Buffer buf)
Creates a
VertexBuffer for the mesh or modifies
the existing one per the parameters given. |
void |
setBuffer(VertexBuffer vb)
Sets the
VertexBuffer on the mesh. |
void |
setDynamic()
Indicates to the GPU that this mesh will be modified occasionally (a hint).
|
void |
setElementLengths(int[] elementLengths)
Set the element lengths for
Mesh.Mode.Hybrid mesh mode. |
void |
setId(int id)
Sets the mesh's VAO ID.
|
void |
setInterleaved()
Deprecated.
|
void |
setLineWidth(float lineWidth)
Deprecated.
|
void |
setLodLevels(VertexBuffer[] lodLevels)
Set the LOD (level of detail) index buffers on this mesh.
|
void |
setMaxNumWeights(int maxNumWeights)
Set the maximum number of weights per vertex on this mesh.
|
void |
setMode(Mesh.Mode mode)
Change the Mesh's mode.
|
void |
setModeStart(int[] modeStart)
Get the mode start indices for
Mesh.Mode.Hybrid mesh mode. |
void |
setPatchVertexCount(int patchVertexCount)
Sets the count of vertices used for each tessellation patch
|
void |
setPointSize(float pointSize)
Deprecated.
Does nothing, since the size of
points is
determined via the vertex shader's gl_PointSize output. |
void |
setStatic()
Indicates to the GPU that this mesh will not be modified (a hint).
|
void |
setStreamed()
Indicates to the GPU that this mesh will be modified every frame (a hint).
|
void |
updateBound()
Updates the bounding volume of this mesh.
|
void |
updateCounts()
|
void |
write(JmeExporter ex) |
public Mesh()
vertex buffers
.public Mesh clone()
vertex
buffers
are shared between this and the clone mesh, the rest
of the data is cloned.clone
in class java.lang.Object
public Mesh deepClone()
vertex buffers
and the data inside them
is cloned.public Mesh cloneForAnim()
vertex buffer
data, however the
VertexBuffer.Type.Position
, VertexBuffer.Type.Normal
, and VertexBuffer.Type.Tangent
buffers
are deeply cloned.public Mesh jmeClone()
jmeClone
in interface JmeCloneable
public void cloneFields(Cloner cloner, java.lang.Object original)
cloneFields
in interface JmeCloneable
cloner
- The cloner that is performing the cloning operation. The
cloneFields method can call back into the cloner to make
clones of its subordinate fields.original
- The original object from which this object was cloned.
This is provided for the very rare case that this object needs
to refer to its original for some reason. In general, all of
the relevant values should have been transferred during the
shallow clone and this object need merely clone what it wants.@Deprecated public void generateBindPose(boolean forSoftwareAnim)
forSoftwareAnim
- ignoredpublic void generateBindPose()
VertexBuffer.Type.BindPosePosition
, VertexBuffer.Type.BindPoseNormal
,
and VertexBuffer.Type.BindPoseTangent
buffers for this mesh by duplicating them based on the position and normal
buffers already set on the mesh.
This method does nothing if the mesh has no bone weight or index
buffers.public void prepareForAnim(boolean forSoftwareAnim)
forSoftwareAnim
- Should be true to enable the conversion.public void setLodLevels(VertexBuffer[] lodLevels)
lodLevels
- The LOD levels to setpublic int getNumLodLevels()
public VertexBuffer getLodLevel(int lod)
lod
- The lod level index, this does not include
the main index buffer.java.lang.IndexOutOfBoundsException
- If the index is outside of the
range [0, getNumLodLevels()
].setLodLevels(com.jme3.scene.VertexBuffer[])
public int[] getElementLengths()
Mesh.Mode.Hybrid
mesh mode.public void setElementLengths(int[] elementLengths)
Mesh.Mode.Hybrid
mesh mode.elementLengths
- The element lengths to setpublic int[] getModeStart()
Mesh.Mode.Hybrid
mesh mode.public void setModeStart(int[] modeStart)
Mesh.Mode.Hybrid
mesh mode.modeStart
- the pre-existing arraypublic Mesh.Mode getMode()
setMode(com.jme3.scene.Mesh.Mode)
public void setMode(Mesh.Mode mode)
Mesh.Mode.Triangles
.mode
- The new mode to setMesh.Mode
public int getMaxNumWeights()
setMaxNumWeights(int)
public void setMaxNumWeights(int maxNumWeights)
maxNumWeights
- the desired number (between 0 and 4, inclusive)@Deprecated public float getPointSize()
1.0
since point size is
determined in the vertex shader.1.0
setPointSize(float)
@Deprecated public void setPointSize(float pointSize)
points
is
determined via the vertex shader's gl_PointSize
output.pointSize
- ignored@Deprecated public float getLineWidth()
Material.getAdditionalRenderState()
and RenderState.getLineWidth()
@Deprecated public void setLineWidth(float lineWidth)
Material.getAdditionalRenderState()
and RenderState.setLineWidth(float)
Mesh.Mode.Lines
. The line width is specified as on-screen pixels,
the default value is 1.0.lineWidth
- The line widthpublic void setStatic()
VertexBuffer.Usage.Static
for all vertex buffers
on this Mesh.public void setDynamic()
VertexBuffer.Usage.Dynamic
for all vertex buffers
on this Mesh.public void setStreamed()
VertexBuffer.Usage.Stream
for all vertex buffers
on this Mesh.@Deprecated public void setInterleaved()
public void updateCounts()
vertex
and
triangle
counts for this mesh
based on the current data. This method should be called
after the capacities
of the mesh's
vertex buffers
has been altered.java.lang.IllegalStateException
- If this mesh is in
interleaved
format.public int getTriangleCount(int lod)
lod
- The lod level to look uppublic int getTriangleCount()
updateCounts()
is called.
If the mesh mode is not a triangle mode, then this returns the
number of elements/primitives, e.g. how many lines or how many points,
instead of how many triangles.public int getVertexCount()
public int getInstanceCount()
public void getTriangle(int index, Vector3f v1, Vector3f v2, Vector3f v3)
index
- The index of the triangle.
Should be between 0 and getTriangleCount()
.v1
- Vector to contain first vertex positionv2
- Vector to contain second vertex positionv3
- Vector to contain third vertex positionpublic void getTriangle(int index, Triangle tri)
Triangle
argument.
Also sets the triangle index to the index
argument.index
- The index of the triangle.
Should be between 0 and getTriangleCount()
.tri
- The triangle to store the positions inpublic void getTriangle(int index, int[] indices)
index
- The index of the triangle.
Should be between 0 and getTriangleCount()
.indices
- Indices of the triangle's verticespublic int getId()
public void setId(int id)
id
- the array IDpublic void createCollisionData()
collideWith(com.jme3.collision.Collidable,
com.jme3.math.Matrix4f,
com.jme3.bounding.BoundingVolume,
com.jme3.collision.CollisionResults)
.public void clearCollisionData()
public int collideWith(Collidable other, Matrix4f worldMatrix, BoundingVolume worldBound, CollisionResults results)
Spatial
s.other
- the other CollidableworldMatrix
- the world matrixworldBound
- the world boundresults
- storage for the resultspublic void setBuffer(VertexBuffer vb)
VertexBuffer
on the mesh.
This will update the vertex/triangle counts if needed.vb
- The buffer to setjava.lang.IllegalArgumentException
- If the buffer type is already setpublic void clearBuffer(VertexBuffer.Type type)
VertexBuffer
set on this mesh
with the given type. Does nothing if the vertex buffer type is not set
initially.type
- The buffer type to removepublic void setBuffer(VertexBuffer.Type type, int components, VertexBuffer.Format format, java.nio.Buffer buf)
VertexBuffer
for the mesh or modifies
the existing one per the parameters given.type
- The type of the buffercomponents
- Number of componentsformat
- Data formatbuf
- The buffer datajava.lang.UnsupportedOperationException
- If the buffer already set is
incompatible with the parameters given.public void setBuffer(VertexBuffer.Type type, int components, java.nio.FloatBuffer buf)
VertexBuffer
on the mesh.type
- The type of VertexBuffer
,
e.g. VertexBuffer.Type.Position
, VertexBuffer.Type.Normal
, etc.components
- Number of components on the vertex buffer, should
be between 1 and 4.buf
- The floating point data to containpublic void setBuffer(VertexBuffer.Type type, int components, float[] buf)
public void setBuffer(VertexBuffer.Type type, int components, java.nio.IntBuffer buf)
public void setBuffer(VertexBuffer.Type type, int components, int[] buf)
public void setBuffer(VertexBuffer.Type type, int components, java.nio.ShortBuffer buf)
public void setBuffer(VertexBuffer.Type type, int components, byte[] buf)
public void setBuffer(VertexBuffer.Type type, int components, java.nio.ByteBuffer buf)
public void setBuffer(VertexBuffer.Type type, int components, short[] buf)
public VertexBuffer getBuffer(VertexBuffer.Type type)
VertexBuffer
stored on this mesh with the given
type.type
- The type of VertexBufferpublic java.nio.FloatBuffer getFloatBuffer(VertexBuffer.Type type)
VertexBuffer
data stored on this mesh in float
format.type
- The type of VertexBufferpublic java.nio.ShortBuffer getShortBuffer(VertexBuffer.Type type)
VertexBuffer
data stored on this mesh in short
format.type
- The type of VertexBufferpublic IndexBuffer getIndicesAsList()
public IndexBuffer getIndexBuffer()
null
if no index buffer is set.VertexBuffer.Type.Index
public void extractVertexData(Mesh other)
index buffer
to index into the attributes of the other mesh.
Note that this will also change this mesh's index buffer so that
the references to the vertex data match the new indices.other
- The mesh to extract the vertex data frompublic void scaleTextureCoordinates(Vector2f scaleFactor)
Note that values above 1 will cause the texture to tile, while values below 1 will cause the texture to stretch.
scaleFactor
- The scale factor to scale by. Every texture
coordinate is multiplied by this vector to get the result.java.lang.IllegalStateException
- If there's no texture coordinate
buffer on the meshjava.lang.UnsupportedOperationException
- If the texture coordinate
buffer is not in 2D float format.public void updateBound()
VertexBuffer.Type.Position
buffer.
It is expected that the position buffer is a float buffer with 3 components.public BoundingVolume getBound()
BoundingVolume
of this Mesh.
By default the bounding volume is a BoundingBox
.public void setBound(BoundingVolume modelBound)
BoundingVolume
for this Mesh.
The bounding volume is recomputed by calling updateBound()
.modelBound
- The model bound to setpublic IntMap<VertexBuffer> getBuffers()
vertex buffers
on this Mesh.
The integer key for the map is the ordinal
of the vertex buffer's VertexBuffer.Type
.
Note that the returned map is a reference to the map used internally,
modifying it will cause undefined results.public SafeArrayList<VertexBuffer> getBufferList()
vertex buffers
on this Mesh.
Using a list instead an IntMap via the getBuffers()
method is
better for iteration as there's no need to create an iterator instance.
Note that the returned list is a reference to the list used internally,
modifying it will cause undefined results.public boolean isAnimated()
VertexBuffer.Type.BoneIndex
or VertexBuffer.Type.HWBoneIndex
.@Deprecated public boolean isAnimatedByBone(int boneIndex)
boneIndex
- the bone's index in its skeletonpublic boolean isAnimatedByJoint(int jointIndex)
jointIndex
- the bone's index in its skeletonpublic void setPatchVertexCount(int patchVertexCount)
patchVertexCount
- the desired countpublic int getPatchVertexCount()
public void addMorphTarget(MorphTarget target)
public boolean removeMorphTarget(MorphTarget target)
target
- The MorphTarget to removepublic MorphTarget removeMorphTarget(int index)
index
- Index of the MorphTarget to removejava.lang.IndexOutOfBoundsException
- if the index outside the number of morph targetspublic MorphTarget getMorphTarget(int index)
index
- The index of the morph target to getjava.lang.IndexOutOfBoundsException
- if the index outside the number of morph targetspublic MorphTarget[] getMorphTargets()
public java.lang.String[] getMorphTargetNames()
public boolean hasMorphTargets()
public int getMorphIndex(java.lang.String morphName)
morphName
- The name of the morph to search forpublic void write(JmeExporter ex) throws java.io.IOException
public void read(JmeImporter im) throws java.io.IOException