Creating Meshes

1. What is a mesh?

A mesh, in glare, is a polygon that casts shadows.

Example of mesh:
Mesh creation

You can create meshes in 2 ways:

2. Your first mesh

Create new object. Call it obj_box.
Create a new sprite for your obj_box (e.g. spr_box).

spr_box

Create Event

In the create event, we can create an empty mesh (without vertices) at the object position.
You can set this mesh as static setting the third argument to true Static meshes are a lot faster, but you can't move them (can be useful if you have a wall) Create new object. Call it obj_box.

mesh_id = glr_mesh_create(x, y, false);

Now, you have to create the mesh for your box.
I advise you, to use the Mesh Editor , in this way

  • Load the box sprite
  • Create a mesh in this way

howto

  • Click Save
  • Copy the Output (for example [[32,32],[-32,32],[-32,-32],[32,-32],[32,32]])
  • Use the script glr_mesh_submesh_add_json(mesh_id, json string, xoffset, yoffset)

Example

glr_mesh_submesh_add_json(mesh_id, "[[32,32],[-32,32],[-32,-32],[32,-32],[32,32]]", 0, 0);
  • Finalize the mesh with glr_mesh_update(id) (with this function, all vertices are converted in triangles. In this way the engine can render the shadows. Call this function every time you edit mesh vertices)

Example

glr_mesh_update(mesh_id);

3. Moving your mesh around

To move a mesh around, it must be dynamic (the static parameter in glr_mesh_create should be false)

You can move the mesh using the following functions:

  • glr_mesh_set_position(mesh_id, x, y);
  • glr_mesh_set_rotation(mesh_id, rotation);
  • glr_mesh_set_scaling(mesh_id, xscale, yscale);
  • glr_mesh_set_transform(mesh_id, x, y, xscale, yscale, rotation); [prefer this function if you edit position and rotation together]
important

These functions re-creates the shadow rendering matrix, so use them only if you need to move the object

4. Destroying meshes

You can destroy a mesh with glr_mesh_destroy(mesh_id)

If you want to change level, you can call glr_mesh_destroy_all() to destroy all meshes in one function call.