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 SummaryNested ClassesModifier and TypeClassDescriptionstatic enumThe mode of the Mesh specifies both the type of primitive represented by the mesh and how the data should be interpreted.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddMorphTarget(MorphTarget target) voidclearBuffer(VertexBuffer.Type type) Unsets theVertexBufferset on this mesh with the given type.voidClears any previously generated collision data.clone()Create a shallow clone of this Mesh.voidcloneFields(Cloner cloner, Object original) Called internally by com.jme3.util.clone.Cloner.Clone the mesh for animation use.intcollideWith(Collidable other, Matrix4f worldMatrix, BoundingVolume worldBound, CollisionResults results) Handles collision detection, internal use only.voidGenerates a collision tree for the mesh.Creates a deep clone of this mesh.voidextractVertexData(Mesh other) Extracts the vertex attributes from the given mesh into this mesh, by using this mesh'sindex bufferto index into the attributes of the other mesh.voidGenerates theVertexBuffer.Type.BindPosePosition,VertexBuffer.Type.BindPoseNormal, andVertexBuffer.Type.BindPoseTangentbuffers for this mesh by duplicating them based on the position and normal buffers already set on the mesh.voidgenerateBindPose(boolean forSoftwareAnim) Deprecated.use generateBindPose();getBound()Returns theBoundingVolumeof this Mesh.getBuffer(VertexBuffer.Type type) Get theVertexBufferstored on this mesh with the given type.Returns a list of allvertex bufferson this Mesh.Returns a map of allvertex bufferson this Mesh.int[]Get the element lengths forMesh.Mode.Hybridmesh mode.Get theVertexBufferdata stored on this mesh in float format.intgetId()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.intReturns the number of instances this mesh contains.floatDeprecated.getLodLevel(int lod) Returns the lod level at the given index.intReturns the maximum number of weights per vertex on this mesh.getMode()Returns the mesh modeint[]Set the mode start indices forMesh.Mode.Hybridmesh mode.intgetMorphIndex(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.intintGets the amount of vertices used for each patch;floatDeprecated.Always returns1.0since point size is determined in the vertex shader.Get theVertexBufferdata stored on this mesh in short format.voidgetTriangle(int index, int[] indices) Gets the triangle vertex indices at the given triangle index and stores them into the given int array.voidgetTriangle(int index, Triangle tri) Gets the triangle vertex positions at the given triangle index and stores them into theTriangleargument.voidgetTriangle(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.intReturns how many triangles or elements are on this Mesh.intgetTriangleCount(int lod) Returns the triangle count for the given LOD level.intReturns the number of vertices on this mesh.booleanbooleanDetermines if the mesh uses bone animation.booleanisAnimatedByBone(int boneIndex) Deprecated.use isAnimatedByJointbooleanisAnimatedByJoint(int jointIndex) Test whether the specified bone animates this mesh.jmeClone()Called internally by com.jme3.util.clone.Cloner.voidprepareForAnim(boolean forSoftwareAnim) Prepares the mesh for software skinning by converting the bone index and weight buffers to heap buffers.voidread(JmeImporter im) removeMorphTarget(int index) Remove the MorphTarget from the Mesh at the given indexbooleanremoveMorphTarget(MorphTarget target) Remove the given MorphTarget from the MeshvoidscaleTextureCoordinates(Vector2f scaleFactor) Scales the texture coordinate buffer on this mesh by the given scale factor.voidsetBound(BoundingVolume modelBound) Sets theBoundingVolumefor this Mesh.voidSets theVertexBufferon the mesh.voidsetBuffer(VertexBuffer.Type type, int components, byte[] buf) voidsetBuffer(VertexBuffer.Type type, int components, float[] buf) voidsetBuffer(VertexBuffer.Type type, int components, int[] buf) voidsetBuffer(VertexBuffer.Type type, int components, short[] buf) voidsetBuffer(VertexBuffer.Type type, int components, VertexBuffer.Format format, Buffer buf) Creates aVertexBufferfor the mesh or modifies the existing one per the parameters given.voidsetBuffer(VertexBuffer.Type type, int components, ByteBuffer buf) voidsetBuffer(VertexBuffer.Type type, int components, FloatBuffer buf) Set a floating pointVertexBufferon the mesh.voidsetBuffer(VertexBuffer.Type type, int components, IntBuffer buf) voidsetBuffer(VertexBuffer.Type type, int components, ShortBuffer buf) voidIndicates to the GPU that this mesh will be modified occasionally (a hint).voidsetElementLengths(int[] elementLengths) Set the element lengths forMesh.Mode.Hybridmesh mode.voidsetId(int id) Sets the mesh's VAO ID.voidDeprecated.voidsetLineWidth(float lineWidth) Deprecated.voidsetLodLevels(VertexBuffer[] lodLevels) Set the LOD (level of detail) index buffers on this mesh.voidsetMaxNumWeights(int maxNumWeights) Set the maximum number of weights per vertex on this mesh.voidChange the Mesh's mode.voidsetModeStart(int[] modeStart) Get the mode start indices forMesh.Mode.Hybridmesh mode.voidsetPatchVertexCount(int patchVertexCount) Sets the count of vertices used for each tessellation patchvoidIndicates to the GPU that this mesh will not be modified (a hint).voidIndicates to the GPU that this mesh will be modified every frame (a hint).voidUpdates the bounding volume of this mesh.voidvoidwrite(JmeExporter ex) 
- 
Constructor Details- 
Meshpublic Mesh()Creates a new mesh with novertex buffers.
 
- 
- 
Method Details- 
cloneCreate a shallow clone of this Mesh. Thevertex buffersare shared between this and the clone mesh, the rest of the data is cloned.
- 
deepCloneCreates a deep clone of this mesh. Thevertex buffersand the data inside them is cloned.- Returns:
- a deep clone of this mesh.
 
- 
cloneForAnimClone the mesh for animation use. This creates a shallow clone of the mesh, sharing most of thevertex bufferdata, however theVertexBuffer.Type.Position,VertexBuffer.Type.Normal, andVertexBuffer.Type.Tangentbuffers are deeply cloned.- Returns:
- A clone of the mesh for animation use.
 
- 
jmeCloneCalled internally by com.jme3.util.clone.Cloner. Do not call directly.- Specified by:
- jmeClonein interface- JmeCloneable
- Returns:
- a new instance
 
- 
cloneFieldsCalled internally by com.jme3.util.clone.Cloner. Do not call directly.- Specified by:
- cloneFieldsin interface- JmeCloneable
- 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.
 
- 
generateBindPoseDeprecated.use generateBindPose();- Parameters:
- forSoftwareAnim- ignored
 
- 
generateBindPosepublic void generateBindPose()Generates theVertexBuffer.Type.BindPosePosition,VertexBuffer.Type.BindPoseNormal, andVertexBuffer.Type.BindPoseTangentbuffers 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.
- 
prepareForAnimpublic 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.
 
- 
setLodLevelsSet the LOD (level of detail) index buffers on this mesh.- Parameters:
- lodLevels- The LOD levels to set
 
- 
getNumLodLevelspublic 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.
 
- 
getLodLevelReturns 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:
 
- 
getElementLengthspublic int[] getElementLengths()Get the element lengths forMesh.Mode.Hybridmesh mode.- Returns:
- element lengths
 
- 
setElementLengthspublic void setElementLengths(int[] elementLengths) Set the element lengths forMesh.Mode.Hybridmesh mode.- Parameters:
- elementLengths- The element lengths to set
 
- 
getModeStartpublic int[] getModeStart()Set the mode start indices forMesh.Mode.Hybridmesh mode.- Returns:
- mode start indices
 
- 
setModeStartpublic void setModeStart(int[] modeStart) Get the mode start indices forMesh.Mode.Hybridmesh mode.- Parameters:
- modeStart- the pre-existing array
 
- 
getModeReturns the mesh mode- Returns:
- the mesh mode
- See Also:
 
- 
setModeChange the Mesh's mode. By default the mode isMesh.Mode.Triangles.- Parameters:
- mode- The new mode to set
- See Also:
 
- 
getMaxNumWeightspublic int getMaxNumWeights()Returns the maximum number of weights per vertex on this mesh.- Returns:
- maximum number of weights per vertex
- See Also:
 
- 
setMaxNumWeightspublic 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)
 
- 
getPointSizeDeprecated.Always returns1.0since point size is determined in the vertex shader.- Returns:
- 1.0
 
- 
getLineWidthDeprecated.Returns the line width for line meshes.- Returns:
- the line width
 
- 
setLineWidthDeprecated.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
 
- 
setStaticpublic void setStatic()Indicates to the GPU that this mesh will not be modified (a hint). Sets the usage mode toVertexBuffer.Usage.Staticfor allvertex bufferson this Mesh.
- 
setDynamicpublic void setDynamic()Indicates to the GPU that this mesh will be modified occasionally (a hint). Sets the usage mode toVertexBuffer.Usage.Dynamicfor allvertex bufferson this Mesh.
- 
setStreamedpublic void setStreamed()Indicates to the GPU that this mesh will be modified every frame (a hint). Sets the usage mode toVertexBuffer.Usage.Streamfor allvertex bufferson this Mesh.
- 
setInterleavedDeprecated.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.
- 
updateCountspublic void updateCounts()Update thevertexandtrianglecounts for this mesh based on the current data. This method should be called after thecapacitiesof the mesh'svertex buffershas been altered.- Throws:
- IllegalStateException- If this mesh is in- interleavedformat.
 
- 
getTriangleCountpublic 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
 
- 
getTriangleCountpublic 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.
 
- 
getVertexCountpublic 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
 
- 
getInstanceCountpublic 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
 
- 
getTriangleGets 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 and- getTriangleCount().
- v1- Vector to contain first vertex position
- v2- Vector to contain second vertex position
- v3- Vector to contain third vertex position
 
- 
getTriangleGets the triangle vertex positions at the given triangle index and stores them into theTriangleargument. Also sets the triangle index to theindexargument.- Parameters:
- index- The index of the triangle. Should be between 0 and- getTriangleCount().
- tri- The triangle to store the positions in
 
- 
getTrianglepublic 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 and- getTriangleCount().
- indices- Indices of the triangle's vertices
 
- 
getIdpublic int getId()Returns the mesh's VAO ID. Internal use only.- Returns:
- the array ID
 
- 
setIdpublic void setId(int id) Sets the mesh's VAO ID. Internal use only.- Parameters:
- id- the array ID
 
- 
createCollisionDatapublic 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).
- 
clearCollisionDatapublic void clearCollisionData()Clears any previously generated collision data. Use this if the mesh has changed in some way that invalidates any previously generated BIHTree.
- 
collideWithpublic 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 asSpatials.- Parameters:
- other- the other Collidable
- worldMatrix- the world matrix
- worldBound- the world bound
- results- storage for the results
- Returns:
- the number of collisions detected (≥0)
 
- 
setBufferSets theVertexBufferon 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
 
- 
clearBufferUnsets theVertexBufferset 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
 
- 
setBufferpublic void setBuffer(VertexBuffer.Type type, int components, VertexBuffer.Format format, Buffer buf) Creates aVertexBufferfor the mesh or modifies the existing one per the parameters given.- Parameters:
- type- The type of the buffer
- components- Number of components
- format- Data format
- buf- The buffer data
- Throws:
- UnsupportedOperationException- If the buffer already set is incompatible with the parameters given.
 
- 
setBufferSet a floating pointVertexBufferon the mesh.- Parameters:
- 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 contain
 
- 
setBuffer
- 
setBuffer
- 
setBuffer
- 
setBuffer
- 
setBuffer
- 
setBuffer
- 
setBuffer
- 
getBufferGet theVertexBufferstored on this mesh with the given type.- Parameters:
- type- The type of VertexBuffer
- Returns:
- the VertexBuffer data, or null if not set
 
- 
getFloatBufferGet theVertexBufferdata stored on this mesh in float format.- Parameters:
- type- The type of VertexBuffer
- Returns:
- the VertexBuffer data, or null if not set
 
- 
getShortBufferGet theVertexBufferdata stored on this mesh in short format.- Parameters:
- type- The type of VertexBuffer
- Returns:
- the VertexBuffer data, or null if not set
 
- 
getIndicesAsListAcquires 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
 
- 
getIndexBufferGet the index buffer for this mesh. Will returnnullif no index buffer is set.- Returns:
- The index buffer of this mesh.
- See Also:
 
- 
extractVertexDataExtracts the vertex attributes from the given mesh into this mesh, by using this mesh'sindex bufferto 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
 
- 
scaleTextureCoordinatesScales 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 mesh
- UnsupportedOperationException- If the texture coordinate buffer is not in 2D float format.
 
- 
updateBoundpublic void updateBound()Updates the bounding volume of this mesh. The method does nothing if the mesh has noVertexBuffer.Type.Positionbuffer. It is expected that the position buffer is a float buffer with 3 components.
- 
getBoundReturns theBoundingVolumeof this Mesh. By default the bounding volume is aBoundingBox.- Returns:
- the bounding volume of this mesh
 
- 
setBoundSets theBoundingVolumefor this Mesh. The bounding volume is recomputed by callingupdateBound().- Parameters:
- modelBound- The model bound to set
 
- 
getBuffersReturns a map of allvertex bufferson this Mesh. The integer key for the map is theordinalof 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.
 
- 
getBufferListReturns a list of allvertex bufferson 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.
 
- 
isAnimatedpublic boolean isAnimated()Determines if the mesh uses bone animation. A mesh uses bone animation if it has bone index / weight buffers such asVertexBuffer.Type.BoneIndexorVertexBuffer.Type.HWBoneIndex.- Returns:
- true if the mesh uses bone animation, false otherwise
 
- 
isAnimatedByBoneDeprecated.use isAnimatedByJoint- Parameters:
- boneIndex- the bone's index in its skeleton
- Returns:
- true if animated by that bone, otherwise false
 
- 
isAnimatedByJointpublic 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
 
- 
setPatchVertexCountpublic void setPatchVertexCount(int patchVertexCount) Sets the count of vertices used for each tessellation patch- Parameters:
- patchVertexCount- the desired count
 
- 
getPatchVertexCountpublic int getPatchVertexCount()Gets the amount of vertices used for each patch;- Returns:
- the count (≥0)
 
- 
addMorphTarget
- 
removeMorphTargetRemove the given MorphTarget from the Mesh- Parameters:
- target- The MorphTarget to remove
- Returns:
- If the MorphTarget was removed
 
- 
removeMorphTargetRemove 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
 
- 
getMorphTargetGet 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
- 
getMorphTargetNamesGet the name of all morphs in order. Morphs without names will be null- Returns:
- an array
 
- 
hasMorphTargetspublic boolean hasMorphTargets()
- 
getMorphIndexGet 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:
- writein interface- Savable
- Throws:
- IOException
 
- 
read- Specified by:
- readin interface- Savable
- Throws:
- IOException
 
 
-