Skip to content

Polygon Meshes

dolphin-mesh.png

Many visible 3D objects are represented by meshes, including built-in shapes and imported models. JME3 has a com.jme3.scene.Mesh class that represents all meshes.

  • A mesh can use triangles, lines, points or other supported primitive modes. For triangle meshes, inspect triangles with getTriangleCount() and getTriangle().

  • getId() is an internal renderer vertex-array identifier, not a persistent application-level mesh ID.

  • Scene transforms such as translation, rotation and scale belong to the Spatial/Geometry that uses the mesh.

  • Meshes have a bounding volume. jME3 can detect intersections (that is, non-physical collisions) between meshes, or between meshes and 3D rays: collideWith().

  • setStatic(), setDynamic() and setStreamed() set buffer-usage hints for the renderer. They do not lock or unlock a mesh; choose a hint appropriate to how often data changes and profile on the target renderer.

You have several options when creating Geometries from meshes:

  • Use built-in Shapes as meshes;

  • Load 3D models (that is, meshes created in external applications); or

  • Create free-form custom meshes programmatically.

Vertex Buffer

The VertexBuffer contains a particular type of geometry data used by Meshes. Vertex buffers contain mesh data such as positions and normals. Some buffers are vertex attributes, while an index buffer selects vertices for primitives.

Mesh Vertex Buffers

Here is the list of VertexBuffer types.

Vertex Buffer Type Description
Type.Position Position of the vertex (3 floats)
Type.Index Specifies the index buffer, must contain integer data.
Type.TexCoord Texture coordinate
Type.TexCoord2 Texture coordinate #2
Type.Normal Normal vector, normalized.
Type.Tangent Tangent vector, normalized.
Type.Binormal Binormal vector, normalized.
Type.Color Color and Alpha (4 floats)
Type.Size The size of the point when using point buffers.
Type.InterleavedData Specifies the source data for various vertex buffers when interleaving is used.
Type.BindPosePosition Initial vertex position, used with animation.
Type.BindPoseNormal Initial vertex normals, used with animation
Type.BoneWeight Bone weights, used with animation
Type.BoneIndex Bone indices, used with animation

Mesh Properties

Some Mesh properties from the Mesh class.

Mesh method Description
setBound(boundingVolume) if you need to specify a custom optimized bounding volume
setStatic() Sets static usage hints on the mesh buffers; it does not prevent modification.
setDynamic() Sets dynamic usage hints for buffers that change occasionally.
setMode(Mesh.Mode.Points) Used to set mesh rendering modes, see below.
getId() returns an internal renderer VAO ID; do not use as a persistent identity
getTriangle(int,tri) returns data of triangle number int into variable tri
scaleTextureCoordinates(Vector2f) How the texture will be stretched over the whole mesh.

Mesh Rendering Modes

Here is the list of Mesh rendering modes.

Mesh Mode Description
Mesh.Mode.Points Show only corner points (vertices) of mesh
Mesh.Mode.Lines Show lines (edges) of mesh
Mesh.Mode.LineLoop Connected line segments, closed back to the first vertex
Mesh.Mode.LineStrip Connected line segments
Mesh.Mode.Triangles Independent triangles
Mesh.Mode.TriangleStrip Connected triangle strip
Mesh.Mode.TriangleFan Triangles sharing a center vertex
Mesh.Mode.Hybrid Combined primitive sections with additional mesh metadata

Level of Detail

Optionally, custom meshes can have a LOD (level of detail optimization) that renders more or less detail, depending on the distance of the mesh from the camera. Provide alternative index buffers, one for each level of detail you want (very far away with few details, close up with all details, and something in the middle). Use setLodLevels(VertexBuffer[] lodLevels).