Almost every visible thing in Polycode is rendered via the SceneMesh class, which is an Entity subclass that wraps the Mesh class, which contains the actual geometry information. You can load meshes from files or create them manually. Higher level classes in Polycode like ScenePrimitives and SceneLabels all subclass SceneMesh.


Meshes and mesh types.

Polycode's Mesh class is the base for all mesh geometry in Polycode. It contains vertex information and a mesh type that defines how these vertices are rendered (as lines, points or polygons). The image below demonstrates the various mesh types and how they render their vertex data.

Creating meshes programatically.

To create and render a mesh, you need to create a SceneMesh instance and add it to your scene, then add vertices to its Mesh. Alternatively, you can create a Mesh first, and then initialize a SceneMesh (or multiple SceneMesh instances) with the Mesh.

Let's look at creating and adding a simple single-quad mesh to a scene.

Scene *scene = new Scene(Scene::SCENE_2D);
SceneMesh *sceneMesh = new SceneMesh(Mesh::QUAD_MESH);

sceneMesh->getMesh()->addVertex(0.2, -0.2, 0.0);
sceneMesh->getMesh()->addVertex(0.2, 0.2, 0.0);
sceneMesh->getMesh()->addVertex(-0.2, 0.2, 0.0);
sceneMesh->getMesh()->addVertex(-0.2, -0.2, 0.0);

scene = Scene(Scene.SCENE_2D)
sceneMesh = SceneMesh.SceneMeshWithType(Mesh.QUAD_MESH)
sceneMesh:getMesh():addVertex(0.2, -0.2, 0.0)
sceneMesh:getMesh():addVertex(0.2, 0.2, 0.0)
sceneMesh:getMesh():addVertex(-0.2, 0.2, 0.0)
sceneMesh:getMesh():addVertex(-0.2, -0.2, 0.0)

When adding vertices to a mesh, it's important to note that they have to be added in counter-clockwise order from the front of each face. If you want a face to be visible from both sides, you need to disable backface culling on the SceneMesh instance (backfaceCulled = false).

Loading meshes from file.

Polycode uses a custom mesh format (.mesh), which you can convert to from a variety of different 3d file formats using the Polycode import tool (see Importing Assets). Meshes can be loaded by intializing a SceneMesh with the path of the mesh file.

Scene *scene = new Scene(Scene::SCENE_3D);
SceneMesh *mesh = new SceneMesh("dummy.mesh");
scene = Scene(Scene.SCENE_3D)
mesh = SceneMesh("dummy.mesh")