Jump to content

Mesh Map

From OpenBOR
Revision as of 16:01, 27 November 2026 by Dcurrent (talk | contribs) (→Geometry)

Introduction

Mesh maps provide native terrain in OpenBOR using images to describe the shape of a surface. OpenBOR constructs geometry from the image and uses that geometry for collision, movement, and optional rendering. Creators can use mesh maps to build slopes, hills, valleys, pits, walls, ceilings, elevated platforms, and other terrain features without assembling a large number of individual walls or platform entities.

Each mesh map uses a 16-bit grayscale PNG to define its geometry. Every pixel in the image represents a vertex on a regular grid. The pixel value determines how far the vertex extends along one of OpenBOR's three world axes. An optional second PNG supplies the visual texture. Since both collision and rendering use the same geometry, creators can design the appearance of terrain independently of its physical shape.

Mesh maps work with OpenBOR's native entity movement, gravity, and platform behavior. Configuration in a level header is sufficient to use them. Script access is available for changing terrain during gameplay, querying its surface, controlling groups of maps, or rendering the terrain from custom viewpoints.

Geometry Overview

Geometry defines the shape of a mesh map. The geometry image determines the position of each vertex relative to the map's origin. OpenBOR uses neighboring vertices to form a continuous triangular surface. The image is numerical data rather than visible artwork. See Geometry Images.

Texture Overview

Texture is the optional artwork applied to the surface. Its resolution and colors are independent of the geometry image. Creators can use invisible collision terrain, visible terrain without collision, or both together. See Texture Images.

Collection

Each level owns a collection of mesh maps organized into areas, sectors, and rooms. Creators may use this hierarchy to organize a world and determine which terrain is applicable to an entity. See Mesh Map Collection.

Geometry Images

Image Format

Geometry requires a PNG containing one 16-bit grayscale channel. Each dimension must contain at least two pixels. An RGB image that appears gray, an indexed image, an 8-bit grayscale image, or a grayscale image with an alpha channel does not meet this requirement.

The range of an unsigned 16-bit image sample is 0 through 65535. OpenBOR interprets these values as follows:

Sample value Meaning
0 Vertex is absent.
1 Minimum displacement.
32768 Midpoint between minimum and maximum displacement.
65535 Maximum displacement.
Other nonzero values Linear displacement between the minimum and maximum.

The minimum and maximum are world-space distances relative to the mesh map's origin. For every nonzero sample, OpenBOR calculates displacement as follows:

displacement = minimum + (sample - 1) * (maximum - minimum) / 65534

For example, a Y-axis mesh map with an origin at Y = 100 and a displacement range of -20 through 40 has a surface between world Y = 80 and Y = 140. Set the minimum and maximum to the same value to create a flat surface.

Note: OpenBOR uses the numerical samples as stored in the PNG, without display gamma correction. Preserve the 16-bit grayscale format when editing and exporting geometry. Saving the image as 8-bit grayscale discards precision and produces an invalid geometry resource.

Coordinates and Axes

OpenBOR uses X for horizontal position, Y for altitude, and Z for depth. Each mesh map occupies a grid in two of these axes, while its image supplies displacement along the third. The selected mesh map axis is the direction of displacement, rather than the plane of the image.

Axis Image plane Increasing image column Increasing image row Local vertex position (X, Y, Z)
y / MESHMAP_AXIS_Y X/Z +X +Z (u, w, v)
z / MESHMAP_AXIS_Z X/Y +X -Y (u, -v, w)
x / MESHMAP_AXIS_X Y/Z +Z -Y (w, -v, u)

u is the image column multiplied by U spacing, v is the image row multiplied by V spacing, and w is the decoded displacement. OpenBOR adds the map's XYZ position to the local vertex coordinates to obtain world coordinates.

Y Axis

Y-axis mesh maps describe altitude over the X/Z plane. Use them for ground terrain in a traditional beat 'em up, hills, roads, ramps, and elevated platforms.

Z Axis

Z-axis mesh maps describe depth over the X/Y plane. Image rows descend in world altitude. Use them to describe terrain contours in side-view platform games. For example, a Z-axis mesh map may form a continuous floor and ceiling within an X/Y movement plane. See Side-View Terrain and Movement Plane.

X Axis

X-axis mesh maps describe horizontal displacement over the Y/Z plane. Image columns extend into depth and rows descend in altitude. Use them for barriers, walls, and other surfaces facing along X.

Geometry Spacing

Spacing is the distance in world units between neighboring vertices. U spacing controls the image column direction and V spacing controls the image row direction. Both values default to 1 and must be positive.

Since pixels represent vertices, the surface extends over one fewer interval than the number of pixels in each dimension:

extent_u = (image_width  - 1) * spacing_u
extent_v = (image_height - 1) * spacing_v

For example, an image containing 65 columns and 17 rows, with U and V spacing of 16, occupies 1024 by 256 world units in its image plane.

Use spacing to control the resolution of the physical surface. Small spacing allows detailed geometry, while larger spacing covers more world space with fewer vertices. Texture resolution is independent, so visual detail does not require additional collision geometry.

Cells and Holes

Four neighboring vertices form a cell. OpenBOR divides the cell into two triangles along the diagonal from its upper-left vertex to its lower-right vertex. Surface displacement varies linearly across each triangle, using the same interpolation for collision and rendering.

All four vertices must be present for a cell to exist. Sample value 0 removes every cell sharing that vertex. OpenBOR does not generate a triangle from the remaining three vertices or treat the absent vertex as a surface at zero altitude.

Note: A single zero-valued pixel can remove up to four cells. Use the vertex grid, rather than the visual appearance of an individual pixel, when determining the size of a hole. Sample 1 represents a real vertex at the minimum displacement, while sample 0 removes geometry.

Solid Side

Mesh maps define a surface and a solid side. The solid side determines which region of the displacement axis is occupied within the map's existing cells.

Native value Script constant Solid region
0 (default) MESHMAP_SIDE_NEGATIVE At or below the surface along the displacement axis.
1 MESHMAP_SIDE_POSITIVE At or above the surface along the displacement axis.

For a Y-axis map, the negative side is the ground underneath the surface. The positive side can describe a solid region above a ceiling. For X and Z maps, the same rule applies to their respective axes.

The minimum and maximum displacement values describe the range of the surface, rather than the thickness of the solid region. The finite grid and its holes limit the solid region along the other two axes. When applicable solid maps overlap, their occupied regions combine. Entering any of these regions is blocked, and boundaries inside the combined region do not form separate exposed walls. Removing a cell from one map does not remove solid terrain supplied by another map.

Texture Images

The texture is a separate PNG image that OpenBOR maps over the complete geometry grid. Texture images may use either 8-bit indexed color with their own palette or 24-bit RGB color. OpenBOR loads RGB artwork into its 32-bit color format.

The texture and geometry images do not need to have matching dimensions. For example, a 65 by 17 geometry image can use a 1024 by 256 texture. OpenBOR maps the full texture across the full grid, with perspective-correct sampling when rendering a projected view.

Texture colors do not determine collision. Black artwork is still artwork, and transparency through the existing renderer's material and color-key controls does not create a hole in the terrain. Use zero samples in the geometry image to remove physical terrain.

Only the geometry surface receives the texture. Solid boundaries along the outer edges of the map or around holes do not automatically acquire textured side faces.

Mesh Map Collection

The mesh map collection belongs to the current level. It uses four address components:

Area
  Sector
    Room
      Mesh Map

Each component is an integer from 0 through 63. The collection supports 64 areas, each containing up to 64 sectors, each containing up to 64 rooms, each containing up to 64 maps. This provides 16,777,216 possible addresses. OpenBOR allocates storage as needed, rather than allocating a map for every possible address.

The names area, sector, and room describe organizational levels. They do not represent predetermined world dimensions or require any particular arrangement of terrain. Creators define the applicable bounds for each level of the hierarchy.

Mesh Map ID

Native level authoring addresses a map using the four individual indices. Script uses a single integer ID representing the same address. Calculate the ID as follows:

int id = area * 262144 + sector * 4096 + room * 64 + index;

For example, area 1, sector 2, room 3, map 4 has an ID of 270532. Valid map IDs range from 0 through 16777215, inclusive. IDs are local to the current level.

Banks

Each bank contains the immediate children of one level of the hierarchy. Use bank depth to specify which bank a command or script function addresses.

Depth Bank Immediate children
0 Collection root Areas
1 Area Sectors
2 Sector Rooms
3 Room Mesh maps

Each existing child has an active state. OpenBOR excludes inactive children from native collision and rendering. Disabling an area also excludes its sectors, rooms, and maps without releasing their resources. The local active settings of the descendants are retained.

Creating a child enables its new slot. This does not reactivate an existing disabled ancestor. Activating a mesh map therefore does not necessarily make it available if one of its parent banks is inactive.

Bounds

Each bank and mesh map may have a creator-defined world-space bounding box used to determine whether its terrain is applicable to an entity. Bounds provide inexpensive rejection of terrain that does not need to participate in a particular collision query. OpenBOR can reject an entire bank without examining its children.

Two gate modes are available:

Native value Script constant Admission condition
0 (default) MESHMAP_GATE_POSITION The entity's current reference position is inside or on the boundary of the box.
1 MESHMAP_GATE_BODY The entity's current body box overlaps or touches the bounds.

The body gate uses the entity's current animation frame body boxes, accounting for facing, with a model-size fallback. Gate tests use current state, not a predicted position or the volume swept during movement. Allow enough overlap between neighboring bounds to accommodate the game's movement speeds and transitions.

Bounds are admission rules, not physical walls. They do not clip the texture, and automatic or scripted rendering does not use entity-position gates. Maps and banks without enabled bounds are unrestricted. Repositioning a mesh map does not move its authored bounds.

Level Header Commands

The following commands configure mesh maps in a level header. Braces describe required arguments and brackets describe optional arguments; do not type the braces, brackets, or type names into the level file. Unless a command specifies otherwise, it operates on the mesh map selected by meshmap_index.

Index

meshmap_index {int area} {int sector} {int room} {int index}

# Default
meshmap_index 0 0 0 0

Select the mesh map addressed by subsequent commands. Each index accepts a value from 0 through 63. The initial selection for every level load is area 0, sector 0, room 0, map 0.

Selecting an index does not create a map or reset an existing one. The first successful property assignment creates the selected map if needed. Selection remains in effect until another meshmap_index command changes it. It does not advance automatically.

Return to a previously selected map at any point to change an individual property without disturbing its other settings.

Geometry

meshmap_geometry {axis} {decimal minimum} {decimal maximum} {path image}

Load the geometry image and configure its displacement axis and range. Axis accepts x, y, or z (case-insensitive). The minimum must be less than or equal to the maximum. Both accept signed decimal values.

Geometry must be a valid 16-bit grayscale PNG. Replacing geometry preserves position, texture, spacing, and the other properties of the selected map. See Geometry Images.

Position

meshmap_position {decimal x} {decimal y} {decimal z}

# Default
meshmap_position 0 0 0

Set the world-space origin. Each coordinate accepts a finite signed decimal value. Position may be specified before or after loading geometry. Changing position moves the surface and its texture together without reloading either image.

Texture

meshmap_texture {path image}
meshmap_texture none

Assign an optional texture to the selected map. The default is no texture. Use none to remove the texture without modifying geometry or collision. Texture may be assigned before geometry, although there is no surface to render until geometry is available. See Texture Images.

Spacing

meshmap_spacing {decimal u} {decimal v}

# Default
meshmap_spacing 1 1

Set the spacing of vertices along the image column and row directions, respectively. Each spacing value must be positive and finite. See Geometry Spacing.

Configuration

meshmap_config {flag} [flag ...]

# Default
meshmap_config collide draw walkable

Configuration is a set of flags that determine the map's behavior. Supply the names of all desired flags separated by spaces or tabs. Names are case-insensitive, and OpenBOR combines them internally. Each meshmap_config declaration replaces the entire previous selection of flags.

Native name Script constant Effect
collide MESHMAP_COLLIDE Participate in native terrain collision.
draw MESHMAP_DRAW Render automatically as part of the native scene.
walkable MESHMAP_WALKABLE Allow qualifying upward-facing contacts to support an entity.
one_way MESHMAP_ONE_WAY Allow one-way platform behavior.
drop_through MESHMAP_DROP_THROUGH Allow a scripted drop-through request on one-way support.
none MESHMAP_FLAGS_NONE No flags when used alone.
default MESHMAP_FLAGS_DEFAULT Collision, automatic drawing, and walkable support.
all MESHMAP_FLAGS_ALL All available configuration flags.

For example, meshmap_config collide walkable configures invisible collision terrain, even if a texture is present. meshmap_config draw configures visual terrain without native collision. none contributes no flags; when combined with other names, it does not clear those names.

Use the named flags in level authoring, not numerical masks or bitwise expressions. See Automatic Drawing and One-Way Platforms for additional behavior.

Side

meshmap_side {int side}

# Default
meshmap_side 0

Select the negative (0) or positive (1) solid side of the surface. See Solid Side.

Support Group

meshmap_support_group {int group}

# Default (independent support)
meshmap_support_group 4294967295

Assign an unsigned 32-bit support group ID. Maps with the same group can act as one support identity for drop-through purposes. The default value, 4294967295 (MESHMAP_GROUP_NONE in script), gives the map an independent support identity. See Support Groups.

Slope Limit

meshmap_slope_limit {decimal degrees}

# Default
meshmap_slope_limit 45

Set the maximum slope that may provide walkable support on this map. Accepts an angle from 0 through 90 degrees. This works with the entity's own slope limit. See Slopes and Steps.

Layer

meshmap_layer {int layer}

# Default
meshmap_layer 0

Set the map's native drawing layer. This is a signed integer used for painter ordering, independent of the map's XYZ position. It applies to automatic native drawing rather than immediate script drawing into a subscreen.

Active

meshmap_active {int enabled}

# Default
meshmap_active 1

Set the selected map's local active state. 0 disables the map and 1 enables it. Its resources and configuration remain available while inactive. All ancestor banks must also be active for native collision and rendering.

Map Bounds

meshmap_bounds {decimal min_x} {decimal min_y} {decimal min_z} {decimal max_x} {decimal max_y} {decimal max_z} [int gate_mode]

Set and enable the selected map's applicability bounds. Minimum coordinates may not exceed their respective maximum coordinates. Gate mode defaults to 0 (current position); 1 uses the current body box. See Bounds.

Area, Sector, and Room Bounds

meshmap_area {decimal min_x} {decimal min_y} {decimal min_z} {decimal max_x} {decimal max_y} {decimal max_z} [int gate_mode]
meshmap_sector {decimal min_x} {decimal min_y} {decimal min_z} {decimal max_x} {decimal max_y} {decimal max_z} [int gate_mode]
meshmap_room {decimal min_x} {decimal min_y} {decimal min_z} {decimal max_x} {decimal max_y} {decimal max_z} [int gate_mode]

Set applicability bounds for the area, sector, or room of the current meshmap_index selection. These commands may create the corresponding banks before any mesh maps are defined. They do not change the current selection. Their coordinates and gate mode follow the same rules as meshmap_bounds.

Bank Bounds

meshmap_bank {int depth} {decimal min_x} {decimal min_y} {decimal min_z} {decimal max_x} {decimal max_y} {decimal max_z} [int gate_mode]

Set bounds for an ancestor bank of the selected mesh map. Specify depth 0 for the collection root, 1 for the area, 2 for the sector, or 3 for the room. Depth 0 addresses the collection root regardless of the selected map. The other depths use the corresponding components of the current selection. See Banks.

Bank Active Selection

meshmap_mask {int depth} none
meshmap_mask {int depth} all
meshmap_mask {int depth} slots {int slot} [int slot ...]

Replace the active selection of the specified bank. Bank depth and addressing follow meshmap_bank. The bank must already exist.

  • none - Disable all immediate children.
  • all - Enable all immediate children that currently exist.
  • slots - Enable the specified immediate child indices and disable the others. Each listed slot must already exist and be an integer from 0 through 63.

For example, with areas 0, 1, and 2 already defined, the following enables areas 0 and 2 while disabling area 1:

meshmap_mask 0 slots 0 2

This changes activation, not allocation. Use the slot indices directly rather than constructing a numerical bitmask.

Level Examples

Ground Terrain

Assume data/terrain/trough16.png is a 65 by 17 grayscale16 geometry image whose nonzero samples describe a shallow trough, and data/terrain/road24.png contains the road artwork.

meshmap_index 0 0 0 0
meshmap_geometry y -24 0 data/terrain/trough16.png
meshmap_position 0 0 0
meshmap_texture data/terrain/road24.png
meshmap_spacing 16 16
meshmap_config collide draw walkable
meshmap_side 0
meshmap_slope_limit 45
meshmap_layer -1000

The terrain spans 1024 units along X and 256 units along Z, with a surface between Y = -24 and Y = 0. Negative solid side supplies ground underneath the surface. The negative drawing layer places the automatic terrain entry behind ordinary higher-layer entries.

Side-View Terrain

Assume data/terrain/side16.png is a 17 by 17 grayscale16 geometry image. Draw the intended solid portions of a side-view level using sample 65535 and the traversable portions using sample 1.

meshmap_index 0 0 0 0
meshmap_geometry z -1 1 data/terrain/side16.png
meshmap_position 0 128 0
meshmap_spacing 8 8
meshmap_config collide walkable
meshmap_side 0

The surface spans X = 0 through 128 and Y = 0 through 128. At the Z = 0 play plane, a maximum-displacement sample places that location on the solid side, while a minimum-displacement sample leaves it free. The transition between samples forms the physical contour through triangle interpolation. Set entities to a Z-axis movement plane to constrain native movement to this X/Y slice. See Movement Plane.

X-Axis Barrier

Assume data/terrain/flat16.png is a two by two grayscale16 image containing four nonzero samples.

meshmap_index 0 0 0 1
meshmap_geometry x 0 0 data/terrain/flat16.png
meshmap_position 300 128 0
meshmap_spacing 128 128
meshmap_config collide
meshmap_side 1

The solid region begins at X = 300 within the Y = 0 through 128 and Z = 0 through 128 domain. The map supplies a barrier to movement toward increasing X, without a texture or walkable support.

Entity Movement

Native mesh collision is enabled for entities by default. An entity may use map geometry for movement obstruction, standing support, slope traversal, steps, and one-way platforms. Creators can configure these capabilities independently of the terrain, using the entity properties listed in Entity Properties.

Legacy Floors and Platforms

When a level contains at least one mesh map, mesh-enabled entities use the authored terrain and explicit legacy support objects instead of the ordinary implicit Y = 0 floor. This allows entities to enter terrain below Y = 0 or fall through holes. Explicit basemaps, walls with supporting surfaces, and platform entities remain available. OpenBOR also accounts for the terrain's lower extent when determining the pit cutoff.

Merely creating the empty collection does not change the ordinary floor. However, inactive maps and maps configured only for drawing still count as map objects. Disabling their collision or their active banks does not restore the implicit floor. Supply ground terrain where needed, or disable mesh collision for a particular entity to retain ordinary legacy terrain behavior for that entity.

Slopes and Steps

Supporting contacts require an upward-facing surface and the map's walkable configuration flag. The supporting slope must satisfy both the map's slope limit and the entity's maximum slope. Angles are measured relative to a horizontal floor.

Entities default to a maximum slope of 45 degrees and a step height of four world units. Step height controls the entity's ability to negotiate an upward terrain transition during native movement. It is separate from the limit on the angle of a supporting surface.

Movement Plane

Native mesh movement may be constrained to a two-dimensional plane by holding one world axis fixed. This is useful for side-view platformers using Z-axis terrain. In this case, the Z coordinate remains fixed during native movement and slope evaluation uses the terrain normal projected into the X/Y plane.

void main()
{
    void self = getlocalvar("self");

    set_entity_property(self,
        openborconstant("ENTITY_PROPERTY_POSITION_Z"), 0);
    set_entity_property(self,
        openborconstant("ENTITY_PROPERTY_MESHMAP_MOVEMENT_PLANE"),
        openborconstant("MESHMAP_AXIS_Z"));
}

Use MESHMAP_PLANE_NONE to remove the plane constraint (default). Selecting the Y axis holds altitude fixed and clears vertical velocity. Direct script assignments to entity positions remain possible, and explicit legacy platform bindings retain their own behavior.

Detailed mesh movement tests use the entity's reference X/Z position and vertical body interval. The optional body bounds gate is an admission test and does not make movement a sweep of the entire body-box volume.

One-Way Platforms

The one_way configuration permits entities to pass upward through a map that provides an eligible supporting surface. The map does not apply its usual lateral solid obstruction. An entity falling onto its eligible upper surface may establish support.

For example, use the same two by two flat geometry image to define a platform above the earlier ground terrain:

meshmap_index 0 0 0 2
meshmap_geometry y 0 0 data/terrain/flat16.png
meshmap_position 160 80 96
meshmap_spacing 160 32
meshmap_config collide walkable one_way drop_through
meshmap_support_group 12
meshmap_slope_limit 45

The platform occupies X = 160 through 320 and Z = 96 through 128, at Y = 80. Since the example has no texture or draw configuration, only its collision is present.

Drop Through

The drop_through flag enables a scripted request to pass downward through a supporting one-way map. It does not assign a control input. Invoke the request from the game's chosen control behavior:

int started_drop = set_entity_property(self,
    openborconstant("ENTITY_PROPERTY_MESHMAP_DROP_REQUEST"), 1);

Both one_way and drop_through must be configured on the current support. The action returns 1 if the request succeeds. OpenBOR temporarily excludes the relevant support for this entity and begins downward movement when needed. The exception clears after the entity passes the relevant support. Other entities and unrelated lower platforms remain unaffected.

Set the property to 0 to cancel the drop exception. Read the same property to test whether an exception is active.

Support Groups

Support groups allow several maps forming one platform to share a drop-through identity. Set the same support group ID on each piece to exclude them together when an entity drops through that support.

The default independent support identity uses the individual map ID and allocation generation. Removing a map and creating another at the same ID does not transfer an old independent drop exception to the new map.

Movement Events

Native slope and step adjustments that change entity altitude during lateral movement invoke the existing onmoveyscript event. Upward movement blocked by a mesh ceiling invokes onblockyscript with obstacle set to NULL(), since the obstruction is not a platform entity. Lateral mesh contacts do not supply a legacy wall object.

Script API

The mesh map API operates on the current level's collection. Map and bank properties use constant IDs obtained with openborconstant(). These functions operate on explicit map IDs or bank addresses and do not use the current level-header authoring selection. The script API uses the property names FLAGS for configuration and ARTWORK for texture.

Level Properties

Get Collection

void maps = get_level_property(NULL(),
    openborconstant("LEVEL_PROPERTY_MESHMAP_COLLECTION"));

Returns the current level's collection handle, creating an empty collection if necessary. The collection is owned by the level. Do not free the handle or retain it across level transitions. Obtain a new handle after the next level loads.

Get Map Count

int count = get_level_property(NULL(),
    openborconstant("LEVEL_PROPERTY_MESHMAP_COUNT"));

Returns the number of existing map objects in the collection, including inactive maps. Both collection-related level properties are read-only.

Map Properties

Get Map Property

get_meshmap_property(collection, id, property);
get_meshmap_property(collection, id, property, column, row);
get_meshmap_property(collection, id, property, world_x, world_y, world_z);

Returns the selected property of the specified map. Column and row are required for the sample property. World coordinates are required for the surface properties. See Geometry Samples and Surface Queries.

Set Map Property

set_meshmap_property(collection, id, property, value);
set_meshmap_property(collection, id, property, value, column, row);

Sets a writable property of the specified map. Successful assignments return 1. Invalid assignments report a script error and preserve the previous property or resource. Create the map before setting its other properties. Each successful assignment takes effect independently, so maintain a valid displacement range and gate bounds while changing individual values.

Map Property Reference

Prefix each name below with MESHMAP_PROPERTY_. For example, use openborconstant("MESHMAP_PROPERTY_EXISTS") to access EXISTS.

Property Access Description
EXISTS Read/Write Read presence. Set to 1 to create, or 0 to remove the map and its resources.
ID Read Level-local map ID.
AREA, SECTOR, ROOM, INDEX Read Individual address components.
ENABLED Read/Write Read effective activation including ancestry. Write the map's local active state (0/1).
AXIS Read/Write MESHMAP_AXIS_X, MESHMAP_AXIS_Y, or MESHMAP_AXIS_Z.
ORIGIN_X, ORIGIN_Y, ORIGIN_Z Read/Write World-space origin coordinates.
MINIMUM, MAXIMUM Read/Write Local displacement range.
SPACING_U, SPACING_V Read/Write Positive vertex spacing in world units.
FLAGS Read/Write Complete configuration flags. Use the named constants in Configuration.
COLLIDE, DRAW, WALKABLE, ONE_WAY, DROP_THROUGH Read/Write Individual configuration flags as 0/1.
SIDE Read/Write MESHMAP_SIDE_NEGATIVE or MESHMAP_SIDE_POSITIVE.
SUPPORT_GROUP Read/Write Unsigned support group ID or MESHMAP_GROUP_NONE.
SLOPE_LIMIT Read/Write Maximum supporting slope, 0 through 90 degrees.
LAYER Read/Write Native painter layer.
WIDTH, HEIGHT Read Geometry dimensions in vertices.
PRESENT_CELLS Read Number of cells containing all four required vertices.
SAMPLE Read/Write Raw 16-bit geometry value at an indexed column and row.
GEOMETRY Read/Write Geometry image path. Assign a path to load or replace geometry.
ARTWORK Read/Write Texture image path. Assign a path to load or replace artwork; assign an empty string to remove it.
REVISION Read Current resource/configuration revision.
GENERATION Read Allocation identity. Changes when a removed ID is recreated.
GATE_ENABLED Read/Write Enable bounds admission (1) or make the gate unrestricted (0).
GATE_MODE Read/Write MESHMAP_GATE_POSITION or MESHMAP_GATE_BODY.
MIN_X, MIN_Y, MIN_Z, MAX_X, MAX_Y, MAX_Z Read/Write World-space bounds of the applicability gate.

Except for EXISTS, properties require an existing map. Use finite numeric values for geometric quantities and integer values for IDs, indices, and Boolean selectors. To set a gate through script, disable it while assigning its individual coordinates, then enable it after the coordinates form a valid box.

Create a Map

The following example creates a ground map at ID 0 if it does not already exist. The same result can be authored in the level header instead.

void main()
{
    void maps = get_level_property(NULL(),
        openborconstant("LEVEL_PROPERTY_MESHMAP_COLLECTION"));
    int id = 0;

    if(!get_meshmap_property(maps, id,
        openborconstant("MESHMAP_PROPERTY_EXISTS")))
    {
        set_meshmap_property(maps, id,
            openborconstant("MESHMAP_PROPERTY_EXISTS"), 1);
        set_meshmap_property(maps, id,
            openborconstant("MESHMAP_PROPERTY_AXIS"),
            openborconstant("MESHMAP_AXIS_Y"));
        set_meshmap_property(maps, id,
            openborconstant("MESHMAP_PROPERTY_MINIMUM"), -24);
        set_meshmap_property(maps, id,
            openborconstant("MESHMAP_PROPERTY_MAXIMUM"), 0);
        set_meshmap_property(maps, id,
            openborconstant("MESHMAP_PROPERTY_SPACING_U"), 16);
        set_meshmap_property(maps, id,
            openborconstant("MESHMAP_PROPERTY_SPACING_V"), 16);
        set_meshmap_property(maps, id,
            openborconstant("MESHMAP_PROPERTY_GEOMETRY"),
            "data/terrain/trough16.png");
        set_meshmap_property(maps, id,
            openborconstant("MESHMAP_PROPERTY_ARTWORK"),
            "data/terrain/road24.png");
        set_meshmap_property(maps, id,
            openborconstant("MESHMAP_PROPERTY_LAYER"), -1000);
    }
}

Configuration Flags

Set the complete configuration using the named constants. Combine multiple constants with bitwise OR, as in the following example:

set_meshmap_property(maps, id,
    openborconstant("MESHMAP_PROPERTY_FLAGS"),
    openborconstant("MESHMAP_COLLIDE") |
    openborconstant("MESHMAP_WALKABLE"));

The map retains collision and walkable support but no longer draws automatically. To change only one flag, use its corresponding individual property instead:

set_meshmap_property(maps, id,
    openborconstant("MESHMAP_PROPERTY_DRAW"), 0);

Use constants rather than literal numeric masks.

Geometry Samples

Supply a zero-based column and row to read or modify a vertex's raw 16-bit sample. Column must be less than the image width and row must be less than the image height.

int sample = get_meshmap_property(maps, id,
    openborconstant("MESHMAP_PROPERTY_SAMPLE"), 10, 4);

/* Remove the vertex at column 10, row 4. */
set_meshmap_property(maps, id,
    openborconstant("MESHMAP_PROPERTY_SAMPLE"), 0, 10, 4);

The setter accepts the new sample before its column and row. In the example, the removed vertex opens the neighboring cells in the live mesh map. The original PNG file is not modified. See Cells and Holes.

Surface Queries

Surface properties read the position and normal of the exact triangle at a supplied world position. They provide access to the terrain used by native collision, and are useful for placing scenery, adjusting cameras, or orienting vehicles and other sprites along a surface.

get_meshmap_property(collection, id, property, world_x, world_y, world_z);

Supply all three finite world coordinates. OpenBOR uses the two coordinates in the image plane and replaces the coordinate on the displacement axis with the calculated surface coordinate. For a Y-axis map, X and Z determine the sample location and Y is the resulting ground altitude.

Prefix each property below with MESHMAP_PROPERTY_:

Property Description
SURFACE_PRESENT 1 if a surface exists at the probe; otherwise 0.
SURFACE_X, SURFACE_Y, SURFACE_Z Calculated world-space surface coordinates.
SURFACE_NORMAL_X, SURFACE_NORMAL_Y, SURFACE_NORMAL_Z Components of the outward unit surface normal.
SURFACE_COLUMN, SURFACE_ROW Zero-based column and row of the sampled cell.
SURFACE_TRIANGLE Triangle index within the sampled cell.

All surface properties are read-only. Properties other than SURFACE_PRESENT return NULL() when there is no surface. Surface queries inspect the geometry directly, regardless of the map's active state or collision bounds. They do not establish an entity's support or perform a movement test.

if(get_meshmap_property(maps, id,
    openborconstant("MESHMAP_PROPERTY_SURFACE_PRESENT"), x, 0, z))
{
    float ground_y = get_meshmap_property(maps, id,
        openborconstant("MESHMAP_PROPERTY_SURFACE_Y"), x, 0, z);
}

For a Y-axis map, the example obtains the ground altitude at X/Z. Checking presence distinguishes a real surface at altitude zero from missing terrain.

Remove or Disable a Map

/* Disable the local slot and retain its resources. */
set_meshmap_property(maps, id,
    openborconstant("MESHMAP_PROPERTY_ENABLED"), 0);

/* Remove the map and its resources. */
set_meshmap_property(maps, id,
    openborconstant("MESHMAP_PROPERTY_EXISTS"), 0);

Removing a map does not automatically remove its empty ancestor banks. An inactive map remains accessible to script.

Bank Properties

Get Bank Property

get_meshmap_bank_property(collection, depth, prefix, property);
get_meshmap_bank_property(collection, depth, prefix, property, slot);

Set Bank Property

set_meshmap_bank_property(collection, depth, prefix, property, value);
set_meshmap_bank_property(collection, depth, prefix, property, value, slot);

Bank depth selects the root, area, sector, or room. Prefix is an ordinary full-format mesh map ID identifying the desired path. Components below the bank depth are ignored. Use depth 0 and prefix 0 to access the collection root. The optional slot argument is required for immediate-child properties and follows the value in the setter. See Banks.

Bank Property Reference

Prefix each name below with MESHMAP_BANK_PROPERTY_.

Property Access Description
EXISTS Read/Write Read presence. Set to 1 to create a bank or 0 to remove it and its descendants.
DEPTH Read Bank depth (0 through 3).
PRESENT_MASK Read Opaque selection of all existing immediate children.
ACTIVE_MASK Read/Write Opaque selection of locally active immediate children. Use a returned selection or MESHMAP_BANK_MASK_NONE.
CHILD_PRESENT Read Presence of an immediate child at the additional slot argument.
CHILD_ACTIVE Read/Write Local active state (0/1) of an immediate child at the additional slot argument.
CHILD_COUNT Read Number of existing immediate children.
GATE_ENABLED Read/Write Gate enabled or unrestricted.
GATE_MODE Read/Write MESHMAP_GATE_POSITION or MESHMAP_GATE_BODY.
MIN_X, MIN_Y, MIN_Z, MAX_X, MAX_Y, MAX_Z Read/Write World-space gate bounds.

Removing the root clears the collection but preserves the collection handle. Other bank removals also remove all descendants. Except for EXISTS, bank properties require the bank to exist. The immediate-child active getter reports local state; use the map's ENABLED property to inspect effective activation through its ancestry.

Change an Individual Child

Disable area 1 while preserving all other areas' local active states:

if(get_meshmap_bank_property(maps, 0, 0,
    openborconstant("MESHMAP_BANK_PROPERTY_CHILD_PRESENT"), 1))
{
    set_meshmap_bank_property(maps, 0, 0,
        openborconstant("MESHMAP_BANK_PROPERTY_CHILD_ACTIVE"), 0, 1);
}

Enable All Existing Children

Assign the bank's present selection to its active selection:

set_meshmap_bank_property(maps, 0, 0,
    openborconstant("MESHMAP_BANK_PROPERTY_ACTIVE_MASK"),
    get_meshmap_bank_property(maps, 0, 0,
        openborconstant("MESHMAP_BANK_PROPERTY_PRESENT_MASK")));

Save and Restore Active Selection

Bank selections may be stored and restored as opaque values. Retain the returned value without converting it into a decimal or a narrower integer. Do not author literal numeric masks.

void saved_selection = get_meshmap_bank_property(maps, 0, 0,
    openborconstant("MESHMAP_BANK_PROPERTY_ACTIVE_MASK"));

/* Disable all areas. */
set_meshmap_bank_property(maps, 0, 0,
    openborconstant("MESHMAP_BANK_PROPERTY_ACTIVE_MASK"),
    openborconstant("MESHMAP_BANK_MASK_NONE"));

/* Restore the previous selection while its children still exist. */
set_meshmap_bank_property(maps, 0, 0,
    openborconstant("MESHMAP_BANK_PROPERTY_ACTIVE_MASK"),
    saved_selection);

Diagnostic Output

Use the common PROPERTY_ACCESS_DUMP constant to log information about a map or bank. Bank diagnostics list ordinary child-slot indices rather than numerical masks.

get_meshmap_property(maps, id,
    openborconstant("PROPERTY_ACCESS_DUMP"));

get_meshmap_bank_property(maps, 0, 0,
    openborconstant("PROPERTY_ACCESS_DUMP"));

Entity Properties

Mesh movement configuration and contact information are accessible through the existing entity property functions:

get_entity_property(entity, property);
set_entity_property(entity, property, value);

Prefix each property below with ENTITY_PROPERTY_MESHMAP_.

Property Access Description
ENABLED Read/Write Enable mesh collision (1, default) or use ordinary legacy terrain behavior (0).
MAX_SLOPE Read/Write Maximum supporting slope, 0 through 90 degrees (default 45).
STEP_HEIGHT Read/Write Nonnegative step capability in world units (default 4).
MOVEMENT_PLANE Read/Write Axis constant for the fixed coordinate, or MESHMAP_PLANE_NONE (default).
SUPPORT_ID Read Current supporting mesh map ID, or -1.
SUPPORT_GROUP Read Current support group or MESHMAP_GROUP_NONE.
SUPPORT_GENERATION Read Current support's allocation generation.
SUPPORT_Y Read Recorded support altitude.
DROP_REQUEST Read/Write Request (1) or cancel (0) drop-through. Getter indicates an active drop exception.
DROP_ID, DROP_GROUP, DROP_GENERATION, DROP_Y Read Recorded drop exception identity and altitude.

Read SUPPORT_ID or DROP_ID before using the corresponding recorded contact altitude. See Entity Movement for the behavior of these properties.

Rendering

Automatic Drawing

By default, a mesh map configured with draw participates in the native scene's rendering queue when its ancestry is active and it has geometry cells and a texture. OpenBOR projects each surface into the usual sprite-based view of the world:

screen_x = world_x - screenx + gfx_x_offset
screen_y = world_z - world_y - screeny + gfx_y_offset

Native drawing uses the map's configured layer to order the terrain with other scene entries. The layer is independent of the map's physical position. Removing a texture leaves collision available. Maps without present geometry cells have no surface to draw.

Script Drawing

Creators can draw mesh maps explicitly into a script-owned RGB32 screen, such as a screen created with allocscreen(). This permits custom cameras, perspective views, and independent terrain composition in subscreens.

Explicit drawing honors the map's active ancestry and available geometry and artwork, but does not require the draw configuration flag. Disable automatic drawing when rendering a map exclusively through script. Both drawing functions return 1 for a successful draw or an eligible no-op, and 0 when the drawing operation fails. Invalid arguments or nonexistent map IDs report script errors.

Pass a drawmethod object or NULL() for a plain material. The null drawmethod here does not inherit the common script drawmethod. Supported material and sampling settings use the existing renderer. Position and projection are controlled by mesh map geometry and the selected view rather than drawmethod affine or curve transforms.

draw_meshmap()

draw_meshmap(collection, id, target_screen, drawmethod);
draw_meshmap(collection, id, target_screen, drawmethod, offset_x, offset_y);

Draw the selected map immediately into the destination screen using the ordinary projection X, Z - Y, plus optional screen-space offsets. Supply both offsets or neither. The default offsets are zero.

draw_meshmap_projected()

draw_meshmap_projected(collection, id, target_screen, drawmethod,
    m00, m01, m02, m03,
    m10, m11, m12, m13,
    m20, m21, m22, m23, near_w);

Draw the selected map immediately into the destination screen using a custom three-row, four-column view matrix. The last argument, near_w, is optional and defaults to 0.0001. All coefficients must be finite, and the near value must be positive. The coefficients are supplied in row-major order and transform world coordinates into homogeneous screen coordinates:

sx = m00 * X + m01 * Y + m02 * Z + m03
sy = m10 * X + m11 * Y + m12 * Z + m13
w  = m20 * X + m21 * Y + m22 * Z + m23

screen_x = sx / w
screen_y = sy / w

OpenBOR clips geometry against the near plane and the target screen's edges. The W coordinate is retained for perspective-correct texture interpolation. This allows orthographic or perspective views without changing the map's physical position, axis, or collision geometry.

Side-View Projection

The following matrix displays X horizontally and altitude Y vertically, ignoring Z for visual projection. The final entry of the first two rows supplies the screen offset.

draw_meshmap_projected(maps, id, surface, NULL(),
    1,  0, 0, offset_x,
    0, -1, 0, offset_y,
    0,  0, 0, 1);
Perspective Projection

For a camera looking along increasing Z, calculate the view from its world position, focal length, and the intended screen center:

sx = focal * (X - camera_x) + center_x * (Z - camera_z)
sy = focal * (camera_y - Y) + center_y * (Z - camera_z)
w  = Z - camera_z

For example, assume the Y-axis ground terrain from Ground Terrain is at ID 0. Disable its automatic drawing during setup:

set_meshmap_property(maps, 0,
    openborconstant("MESHMAP_PROPERTY_DRAW"), 0);

The following drawing script creates and reuses a 320 by 240 screen. The camera is at (512, 180, -256), looking along increasing Z with focal length 240 and image center (160, 48).

void main()
{
    void maps = get_level_property(NULL(),
        openborconstant("LEVEL_PROPERTY_MESHMAP_COLLECTION"));
    void surface = getglobalvar("meshmap_road_screen");

    if(surface == NULL())
    {
        surface = allocscreen(320, 240);
        setglobalvar("meshmap_road_screen", surface);
    }

    clearscreen(surface);

    draw_meshmap_projected(maps, 0, surface, NULL(),
         240,    0, 160, -81920,
           0, -240,  48,  55488,
           0,    0,   1,    256,
         1);

    drawscreen(surface, 0, 0, 100);
}

Use this script during the normal drawing phase while the map exists. The projection affects the terrain only; the creator supplies any corresponding transformation of entities and other scene objects. The screen remains a script-owned resource. Release it at the appropriate teardown point, after no queued drawing operation references it, and clear its stored global handle.

Draw Ordering

Mesh maps use OpenBOR's painter ordering and screen composition. There is no scene depth buffer that automatically resolves visibility between terrain, entities, and other maps. Custom projection determines screen positions and perspective sampling, not mutual occlusion. Overlapping triangles and surfaces follow their submission order.

Design Considerations

  • Mesh maps represent fixed-axis displacement surfaces. Use additional maps or entities for terrain requiring several surfaces or other orientations.
  • Use mesh maps for detailed static terrain and the existing entity systems for moving platforms, destructible objects, and other independently interactive elements.
  • Choose geometry spacing according to the smallest physical feature needed for gameplay. Use separate texture resolution for fine visual detail.
  • Organize large terrain sets into useful areas, sectors, and rooms with appropriately overlapping applicability bounds. Bounds help reject irrelevant collision geometry; they do not clip automatic drawing or stream resources.
  • Mesh maps are not general-purpose rigid-body physics or arbitrary 3D models. They provide a native terrain representation for OpenBOR's sprite-based world.

See Also