Package com.jme3.scene
Class Mesh
java.lang.Object
com.jme3.scene.Mesh
- All Implemented Interfaces:
Savable
,JmeCloneable
,Cloneable
- Direct Known Subclasses:
AbstractBox
,ArmatureInterJointsWire
,Arrow
,BoundingSphereDebug
,CenterQuad
,CenterQuad
,Curve
,Cylinder
,Dome
,Grid
,JointShape
,Line
,ParticleMesh
,PQTorus
,Quad
,RectangleMesh
,SkeletonInterBoneWire
,SkeletonPoints
,SkeletonWire
,Sphere
,Surface
,Torus
,WireBox
,WireFrustum
,WireSphere
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:
- Points - Every vertex represents a single point in space.
- Lines - 2 vertices represent a line segment, with the width specified
via
Material.getAdditionalRenderState()
andRenderState.setLineWidth(float)
. - Triangles - 3 vertices represent a solid triangle primitive.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
The mode of the Mesh specifies both the type of primitive represented by the mesh and how the data should be interpreted. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addMorphTarget
(MorphTarget target) void
clearBuffer
(VertexBuffer.Type type) Unsets theVertexBuffer
set on this mesh with the given type.void
Clears any previously generated collision data.clone()
Create a shallow clone of this Mesh.void
cloneFields
(Cloner cloner, Object original) Called internally by com.jme3.util.clone.Cloner.Clone the mesh for animation use.int
collideWith
(Collidable other, Matrix4f worldMatrix, BoundingVolume worldBound, CollisionResults results) Handles collision detection, internal use only.void
Generates a collision tree for the mesh.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'sindex buffer
to index into the attributes of the other mesh.void
Generates theVertexBuffer.Type.BindPosePosition
,VertexBuffer.Type.BindPoseNormal
, andVertexBuffer.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();getBound()
Returns theBoundingVolume
of this Mesh.getBuffer
(VertexBuffer.Type type) Get theVertexBuffer
stored on this mesh with the given type.Returns a list of allvertex buffers
on this Mesh.Returns a map of allvertex buffers
on this Mesh.int[]
Get the element lengths forMesh.Mode.Hybrid
mesh mode.Get theVertexBuffer
data stored on this mesh in float format.int
getId()
Returns the mesh's VAO ID.Get the index buffer for this mesh.Acquires an index buffer that will read the vertices on the mesh as a list.int
Returns the number of instances this mesh contains.float
Deprecated.getLodLevel
(int lod) Returns the lod level at the given index.int
Returns the maximum number of weights per vertex on this mesh.getMode()
Returns the mesh modeint[]
Set the mode start indices forMesh.Mode.Hybrid
mesh mode.int
getMorphIndex
(String morphName) Get the index of the morph that has the given name.getMorphTarget
(int index) Get the MorphTarget at the given indexString[]
Get the name of all morphs in order.int
int
Gets the amount of vertices used for each patch;float
Deprecated.Always returns1.0
since point size is determined in the vertex shader.Get theVertexBuffer
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 theTriangle
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
Returns how many triangles or elements are on this Mesh.int
getTriangleCount
(int lod) Returns the triangle count for the given LOD level.int
Returns the number of vertices on this mesh.boolean
boolean
Determines if the mesh uses bone animation.boolean
isAnimatedByBone
(int boneIndex) Deprecated.use isAnimatedByJointboolean
isAnimatedByJoint
(int jointIndex) Test whether the specified bone animates this 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) removeMorphTarget
(int index) Remove the MorphTarget from the Mesh at the given indexboolean
removeMorphTarget
(MorphTarget target) Remove the given MorphTarget from the Meshvoid
scaleTextureCoordinates
(Vector2f scaleFactor) Scales the texture coordinate buffer on this mesh by the given scale factor.void
setBound
(BoundingVolume modelBound) Sets theBoundingVolume
for this Mesh.void
Sets theVertexBuffer
on the mesh.void
setBuffer
(VertexBuffer.Type type, int components, byte[] buf) void
setBuffer
(VertexBuffer.Type type, int components, float[] buf) void
setBuffer
(VertexBuffer.Type type, int components, int[] buf) void
setBuffer
(VertexBuffer.Type type, int components, short[] buf) void
setBuffer
(VertexBuffer.Type type, int components, VertexBuffer.Format format, Buffer buf) Creates aVertexBuffer
for the mesh or modifies the existing one per the parameters given.void
setBuffer
(VertexBuffer.Type type, int components, ByteBuffer buf) void
setBuffer
(VertexBuffer.Type type, int components, FloatBuffer buf) Set a floating pointVertexBuffer
on the mesh.void
setBuffer
(VertexBuffer.Type type, int components, IntBuffer buf) void
setBuffer
(VertexBuffer.Type type, int components, ShortBuffer buf) void
Indicates to the GPU that this mesh will be modified occasionally (a hint).void
setElementLengths
(int[] elementLengths) Set the element lengths forMesh.Mode.Hybrid
mesh mode.void
setId
(int id) Sets the mesh's VAO ID.void
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
Change the Mesh's mode.void
setModeStart
(int[] modeStart) Get the mode start indices forMesh.Mode.Hybrid
mesh mode.void
setPatchVertexCount
(int patchVertexCount) Sets the count of vertices used for each tessellation patchvoid
Indicates to the GPU that this mesh will not be modified (a hint).void
Indicates to the GPU that this mesh will be modified every frame (a hint).void
Updates the bounding volume of this mesh.void
void
write
(JmeExporter ex)
-
Constructor Details
-
Mesh
public Mesh()Creates a new mesh with novertex buffers
.
-
-
Method Details
-
clone
Create a shallow clone of this Mesh. Thevertex buffers
are shared between this and the clone mesh, the rest of the data is cloned. -
deepClone
Creates a deep clone of this mesh. Thevertex buffers
and the data inside them is cloned.- Returns:
- a deep clone of this mesh.
-
cloneForAnim
Clone the mesh for animation use. This creates a shallow clone of the mesh, sharing most of thevertex buffer
data, however theVertexBuffer.Type.Position
,VertexBuffer.Type.Normal
, andVertexBuffer.Type.Tangent
buffers are deeply cloned.- Returns:
- A clone of the mesh for animation use.
-
jmeClone
Called internally by com.jme3.util.clone.Cloner. Do not call directly.- Specified by:
jmeClone
in interfaceJmeCloneable
- Returns:
- a new instance
-
cloneFields
Called internally by com.jme3.util.clone.Cloner. Do not call directly.- Specified by:
cloneFields
in interfaceJmeCloneable
- Parameters:
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 only clone what it wants.
-
generateBindPose
Deprecated.use generateBindPose();- Parameters:
forSoftwareAnim
- ignored
-
generateBindPose
public void generateBindPose()Generates theVertexBuffer.Type.BindPosePosition
,VertexBuffer.Type.BindPoseNormal
, andVertexBuffer.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. -
prepareForAnim
public void prepareForAnim(boolean forSoftwareAnim) Prepares the mesh for software skinning by converting the bone index and weight buffers to heap buffers.- Parameters:
forSoftwareAnim
- Should be true to enable the conversion.
-
setLodLevels
Set the LOD (level of detail) index buffers on this mesh.- Parameters:
lodLevels
- The LOD levels to set
-
getNumLodLevels
public int getNumLodLevels()- Returns:
- The number of LOD levels set on this mesh, including the main index buffer, returns zero if there are no lod levels.
-
getLodLevel
Returns the lod level at the given index.- Parameters:
lod
- The lod level index, this does not include the main index buffer.- Returns:
- The LOD index buffer at the index
- Throws:
IndexOutOfBoundsException
- If the index is outside of the range [0,getNumLodLevels()
].- See Also:
-
getElementLengths
public int[] getElementLengths()Get the element lengths forMesh.Mode.Hybrid
mesh mode.- Returns:
- element lengths
-
setElementLengths
public void setElementLengths(int[] elementLengths) Set the element lengths forMesh.Mode.Hybrid
mesh mode.- Parameters:
elementLengths
- The element lengths to set
-
getModeStart
public int[] getModeStart()Set the mode start indices forMesh.Mode.Hybrid
mesh mode.- Returns:
- mode start indices
-
setModeStart
public void setModeStart(int[] modeStart) Get the mode start indices forMesh.Mode.Hybrid
mesh mode.- Parameters:
modeStart
- the pre-existing array
-
getMode
Returns the mesh mode- Returns:
- the mesh mode
- See Also:
-
setMode
Change the Mesh's mode. By default the mode isMesh.Mode.Triangles
.- Parameters:
mode
- The new mode to set- See Also:
-
getMaxNumWeights
public int getMaxNumWeights()Returns the maximum number of weights per vertex on this mesh.- Returns:
- maximum number of weights per vertex
- See Also:
-
setMaxNumWeights
public void setMaxNumWeights(int maxNumWeights) Set the maximum number of weights per vertex on this mesh. Only relevant if this mesh has bone index/weight buffers. This value should be between 0 and 4.- Parameters:
maxNumWeights
- the desired number (between 0 and 4, inclusive)
-
getPointSize
Deprecated.Always returns1.0
since point size is determined in the vertex shader.- Returns:
1.0
-
getLineWidth
Deprecated.Returns the line width for line meshes.- Returns:
- the line width
-
setLineWidth
Deprecated.Specify the line width for meshes of the line modes, such asMesh.Mode.Lines
. The line width is specified as on-screen pixels, the default value is 1.0.- Parameters:
lineWidth
- The line width
-
setStatic
public void setStatic()Indicates to the GPU that this mesh will not be modified (a hint). Sets the usage mode toVertexBuffer.Usage.Static
for allvertex buffers
on this Mesh. -
setDynamic
public void setDynamic()Indicates to the GPU that this mesh will be modified occasionally (a hint). Sets the usage mode toVertexBuffer.Usage.Dynamic
for allvertex buffers
on this Mesh. -
setStreamed
public void setStreamed()Indicates to the GPU that this mesh will be modified every frame (a hint). Sets the usage mode toVertexBuffer.Usage.Stream
for allvertex buffers
on this Mesh. -
setInterleaved
Deprecated.Interleaves the data in this mesh. This operation cannot be reversed. Some GPUs may prefer the data in this format, however it is a good idea to avoid using this method as it disables some engine features. -
updateCounts
public void updateCounts()Update thevertex
andtriangle
counts for this mesh based on the current data. This method should be called after thecapacities
of the mesh'svertex buffers
has been altered.- Throws:
IllegalStateException
- If this mesh is ininterleaved
format.
-
getTriangleCount
public int getTriangleCount(int lod) Returns the triangle count for the given LOD level.- Parameters:
lod
- The lod level to look up- Returns:
- The triangle count for that LOD level
-
getTriangleCount
public int getTriangleCount()Returns how many triangles or elements are on this Mesh. This value is only updated whenupdateCounts()
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.- Returns:
- how many triangles/elements are on this Mesh.
-
getVertexCount
public int getVertexCount()Returns the number of vertices on this mesh. The value is computed based on the position buffer, which must be set on all meshes.- Returns:
- Number of vertices on the mesh
-
getInstanceCount
public int getInstanceCount()Returns the number of instances this mesh contains. The instance count is based on any VertexBuffers with instancing set.- Returns:
- the number of instances
-
getTriangle
Gets the triangle vertex positions at the given triangle index and stores them into the v1, v2, v3 arguments.- Parameters:
index
- The index of the triangle. Should be between 0 andgetTriangleCount()
.v1
- Vector to contain first vertex positionv2
- Vector to contain second vertex positionv3
- Vector to contain third vertex position
-
getTriangle
Gets the triangle vertex positions at the given triangle index and stores them into theTriangle
argument. Also sets the triangle index to theindex
argument.- Parameters:
index
- The index of the triangle. Should be between 0 andgetTriangleCount()
.tri
- The triangle to store the positions in
-
getTriangle
public void getTriangle(int index, int[] indices) Gets the triangle vertex indices at the given triangle index and stores them into the given int array.- Parameters:
index
- The index of the triangle. Should be between 0 andgetTriangleCount()
.indices
- Indices of the triangle's vertices
-
getId
public int getId()Returns the mesh's VAO ID. Internal use only.- Returns:
- the array ID
-
setId
public void setId(int id) Sets the mesh's VAO ID. Internal use only.- Parameters:
id
- the array ID
-
createCollisionData
public void createCollisionData()Generates a collision tree for the mesh. Called automatically bycollideWith(com.jme3.collision.Collidable, com.jme3.math.Matrix4f, com.jme3.bounding.BoundingVolume, com.jme3.collision.CollisionResults)
. -
clearCollisionData
public void clearCollisionData()Clears any previously generated collision data. Use this if the mesh has changed in some way that invalidates any previously generated BIHTree. -
collideWith
public int collideWith(Collidable other, Matrix4f worldMatrix, BoundingVolume worldBound, CollisionResults results) Handles collision detection, internal use only. User code should only use collideWith() on scene graph elements such asSpatial
s.- Parameters:
other
- the other CollidableworldMatrix
- the world matrixworldBound
- the world boundresults
- storage for the results- Returns:
- the number of collisions detected (≥0)
-
setBuffer
Sets theVertexBuffer
on the mesh. This will update the vertex/triangle counts if needed.- Parameters:
vb
- The buffer to set- Throws:
IllegalArgumentException
- If the buffer type is already set
-
clearBuffer
Unsets theVertexBuffer
set on this mesh with the given type. Does nothing if the vertex buffer type is not set initially.- Parameters:
type
- The buffer type to remove
-
setBuffer
public void setBuffer(VertexBuffer.Type type, int components, VertexBuffer.Format format, Buffer buf) Creates aVertexBuffer
for the mesh or modifies the existing one per the parameters given.- Parameters:
type
- The type of the buffercomponents
- Number of componentsformat
- Data formatbuf
- The buffer data- Throws:
UnsupportedOperationException
- If the buffer already set is incompatible with the parameters given.
-
setBuffer
Set a floating pointVertexBuffer
on the mesh.- Parameters:
type
- The type ofVertexBuffer
, 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 contain
-
setBuffer
-
setBuffer
-
setBuffer
-
setBuffer
-
setBuffer
-
setBuffer
-
setBuffer
-
getBuffer
Get theVertexBuffer
stored on this mesh with the given type.- Parameters:
type
- The type of VertexBuffer- Returns:
- the VertexBuffer data, or null if not set
-
getFloatBuffer
Get theVertexBuffer
data stored on this mesh in float format.- Parameters:
type
- The type of VertexBuffer- Returns:
- the VertexBuffer data, or null if not set
-
getShortBuffer
Get theVertexBuffer
data stored on this mesh in short format.- Parameters:
type
- The type of VertexBuffer- Returns:
- the VertexBuffer data, or null if not set
-
getIndicesAsList
Acquires an index buffer that will read the vertices on the mesh as a list.- Returns:
- A virtual or wrapped index buffer to read the data as a list
-
getIndexBuffer
Get the index buffer for this mesh. Will returnnull
if no index buffer is set.- Returns:
- The index buffer of this mesh.
- See Also:
-
extractVertexData
Extracts the vertex attributes from the given mesh into this mesh, by using this mesh'sindex 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.- Parameters:
other
- The mesh to extract the vertex data from
-
scaleTextureCoordinates
Scales the texture coordinate buffer on this mesh by the given scale factor.Note that values above 1 will cause the texture to tile, while values below 1 will cause the texture to stretch.
- Parameters:
scaleFactor
- The scale factor to scale by. Every texture coordinate is multiplied by this vector to get the result.- Throws:
IllegalStateException
- If there's no texture coordinate buffer on the meshUnsupportedOperationException
- If the texture coordinate buffer is not in 2D float format.
-
updateBound
public void updateBound()Updates the bounding volume of this mesh. The method does nothing if the mesh has noVertexBuffer.Type.Position
buffer. It is expected that the position buffer is a float buffer with 3 components. -
getBound
Returns theBoundingVolume
of this Mesh. By default the bounding volume is aBoundingBox
.- Returns:
- the bounding volume of this mesh
-
setBound
Sets theBoundingVolume
for this Mesh. The bounding volume is recomputed by callingupdateBound()
.- Parameters:
modelBound
- The model bound to set
-
getBuffers
Returns a map of allvertex buffers
on this Mesh. The integer key for the map is theordinal
of the vertex buffer'sVertexBuffer.Type
. Note that the returned map is a reference to the map used internally, modifying it will cause undefined results.- Returns:
- map of vertex buffers on this mesh.
-
getBufferList
Returns a list of allvertex buffers
on this Mesh. Using a list instead an IntMap via thegetBuffers()
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.- Returns:
- list of vertex buffers on this mesh.
-
isAnimated
public boolean isAnimated()Determines if the mesh uses bone animation. A mesh uses bone animation if it has bone index / weight buffers such asVertexBuffer.Type.BoneIndex
orVertexBuffer.Type.HWBoneIndex
.- Returns:
- true if the mesh uses bone animation, false otherwise
-
isAnimatedByBone
Deprecated.use isAnimatedByJoint- Parameters:
boneIndex
- the bone's index in its skeleton- Returns:
- true if animated by that bone, otherwise false
-
isAnimatedByJoint
public boolean isAnimatedByJoint(int jointIndex) Test whether the specified bone animates this mesh.- Parameters:
jointIndex
- the bone's index in its skeleton- Returns:
- true if the specified bone animates this mesh, otherwise false
-
setPatchVertexCount
public void setPatchVertexCount(int patchVertexCount) Sets the count of vertices used for each tessellation patch- Parameters:
patchVertexCount
- the desired count
-
getPatchVertexCount
public int getPatchVertexCount()Gets the amount of vertices used for each patch;- Returns:
- the count (≥0)
-
addMorphTarget
-
removeMorphTarget
Remove the given MorphTarget from the Mesh- Parameters:
target
- The MorphTarget to remove- Returns:
- If the MorphTarget was removed
-
removeMorphTarget
Remove the MorphTarget from the Mesh at the given index- Parameters:
index
- Index of the MorphTarget to remove- Returns:
- The MorphTarget that was removed
- Throws:
IndexOutOfBoundsException
- if the index outside the number of morph targets
-
getMorphTarget
Get the MorphTarget at the given index- Parameters:
index
- The index of the morph target to get- Returns:
- The MorphTarget at the index
- Throws:
IndexOutOfBoundsException
- if the index outside the number of morph targets
-
getMorphTargets
-
getMorphTargetNames
Get the name of all morphs in order. Morphs without names will be null- Returns:
- an array
-
hasMorphTargets
public boolean hasMorphTargets() -
getMorphIndex
Get the index of the morph that has the given name.- Parameters:
morphName
- The name of the morph to search for- Returns:
- The index of the morph, or -1 if not found.
-
write
- Specified by:
write
in interfaceSavable
- Throws:
IOException
-
read
- Specified by:
read
in interfaceSavable
- Throws:
IOException
-