Shapes

The simplest type of Meshes are the built-in JME Shapes. You can create Shapes without using the AssetManager.

List of 3D shapes

List of Non-3D shapes

Math versus Shape?

Do not mix up these visible Shapes with similarly named classes from the maths package. Choose the right package when letting your IDE fill in the import statements!

These maths objects are invisible and are used for collision testing (ray casting) or to describe motion paths. They cannot be wrapped into a Geometry.

Usage

Basic Usage

To add a shape to the scene:

  1. Create the base mesh shape.
  2. Wrap it into a Geometry.
  3. Assign a Material to the Geometry.
  4. Attach the Geometry to the rootNode to make it visible.

Complex Shapes

You can compose more complex custom Geometries out of simple Shapes. Think of the buildings in games like Angry Birds, or the building blocks in Second Life ("prims") and in Tetris ("Tetrominos").

  1. Create a Node. By default it is located at the origin (0/0/0) – leave the Node there for now.
  2. Create your shapes and wrap each into a Geometry, as just described.
  3. Attach each Geometry to the Node.
  4. Arrange the Geometries around the Node (using setLocalTranslation()) so that the Node is in the center of the new constellation. The central Node is the pivot point for transformations (move/scale/rotate).
  5. Move the pivot Node to its final location in the scene. Moving the pivot Node moves the attached constellation of Geometries with it.

The order is important: First arrange around origin, then transform. Otherwise, transformations are applied around the wrong center (pivot). Of course, you can attach your constellation to other pivot Nodes to create even more complex shapes (a chair, a furnished room, a house, a city, …), but again, arrange them around the origin first before you transform them.
Note: Obviously, these composed Geometries are simpler than hand-sculpted meshes from a mesh editor.

Code Examples

Sphere mesh = new Sphere(32, 32, 10, false, true);
Dome mesh = new Dome(Vector3f.ZERO, 2, 4, 1f,false); // Pyramid
Dome mesh = new Dome(Vector3f.ZERO, 2, 32, 1f,false); // Cone
Dome mesh = new Dome(Vector3f.ZERO, 32, 32, 1f,false); // Small hemisphere
Dome mesh = new Dome(Vector3f.ZERO, 32, 32, 1000f,true); // SkyDome
PQTorus mesh = new PQTorus(5,3, 2f, 1f, 32, 32); // Spiral torus
PQTorus mesh = new PQTorus(3,8, 2f, 1f, 32, 32); // Flower torus

Use one of the above examples together with the following geometry in a scene:

Geometry geom = new Geometry("A shape", mesh);
Material mat = new Material(assetManager,
    "Common/MatDefs/Misc/ShowNormals.j3md");
geom.setMaterial(mat);
rootNode.attachChild(geom);

view online version