Mesh Map: Difference between revisions
No edit summary |
|||
| Line 1: | Line 1: | ||
== Introduction == | == 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. | 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. | 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. Optional artwork supplies the visual texture, and a separate drawing depth mask can adjust its per-pixel drawing priority. 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. | 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. Banks and individual meshes can also own entry and exit handlers, while meshes can respond to blocking contacts. These events support encounters, environmental effects, and creator-controlled terrain loading. | ||
=== Geometry Overview === | === Geometry Overview === | ||
| Line 19: | Line 18: | ||
=== Image Format === | === Image Format === | ||
Geometry requires a PNG containing one 16-bit grayscale channel. Each dimension must contain at least two pixels. | Geometry requires a PNG containing one 16-bit grayscale channel. Each dimension must contain at least two pixels. RGB images that appear gray, indexed images, 8-bit grayscale images, and grayscale images with an alpha channel do not meet this requirement. | ||
The range of an unsigned 16-bit image sample is <code>0</code> through <code>65535</code>. OpenBOR interprets these values as follows: | The range of an unsigned 16-bit image sample is <code>0</code> through <code>65535</code>. OpenBOR interprets these values as follows: | ||
| Line 41: | Line 40: | ||
|Linear displacement between the minimum and maximum. | |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:<syntaxhighlight lang="text"> | The minimum and maximum are world-space distances relative to the mesh map's origin. For every nonzero sample, OpenBOR calculates displacement as follows: | ||
<syntaxhighlight lang="text"> | |||
displacement = minimum + (sample - 1) * (maximum - minimum) / 65534 | displacement = minimum + (sample - 1) * (maximum - minimum) / 65534 | ||
</syntaxhighlight>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. | </syntaxhighlight> | ||
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. | '''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. | ||
| Line 88: | Line 90: | ||
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 <code>1</code> and must be positive. | 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 <code>1</code> and must be positive. | ||
Since pixels represent vertices, the surface extends over one fewer interval than the number of pixels in each dimension:<syntaxhighlight lang="text"> | Since pixels represent vertices, the surface extends over one fewer interval than the number of pixels in each dimension: | ||
<syntaxhighlight lang="text"> | |||
extent_u = (image_width - 1) * spacing_u | extent_u = (image_width - 1) * spacing_u | ||
extent_v = (image_height - 1) * spacing_v | extent_v = (image_height - 1) * spacing_v | ||
</syntaxhighlight>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. | </syntaxhighlight> | ||
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. | 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. | ||
| Line 100: | Line 105: | ||
All four vertices must be present for a cell to exist. Sample value <code>0</code> 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. | All four vertices must be present for a cell to exist. Sample value <code>0</code> 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:''' | '''Note:''' One 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 <code>1</code> represents a real vertex at the minimum displacement, while sample <code>0</code> removes geometry. | ||
=== Solid Side === | === Solid Side === | ||
| Line 129: | Line 134: | ||
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. | 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. | ||
=== Drawing Depth Images === | |||
Mesh artwork can have a companion 16-bit grayscale PNG that adjusts drawing priority per pixel. Use it when different portions of one textured surface should pass in front of or behind entities and other scene elements. | |||
The image must contain a single 16-bit grayscale channel, with dimensions matching the visual texture canvas. It does not need to match the geometry grid. Each sample supplies a signed adjustment to the mesh's drawing layer: | |||
<syntaxhighlight lang="text"> | |||
adjustment = adjust_0 + (sample / 65535.0) * (adjust_65535 - adjust_0) | |||
pixel_drawing_z = meshmap_layer + adjustment | |||
</syntaxhighlight> | |||
Greater drawing Z takes precedence. The two adjustments may be fractional, equal, or reversed. They describe the results at sample 0 and sample 65535, rather than a required low-to-high ordering of adjustment values. | |||
Unlike geometry data, drawing depth uses the complete range from 0 through 65535. Sample 0 is valid depth information and does not create a hole. The default range used when script omits the endpoints is -32768 through +32767, giving a direct one-for-one adjustment: | |||
<syntaxhighlight lang="text"> | |||
adjustment = sample - 32768 | |||
</syntaxhighlight> | |||
With that range, sample 32768 makes no adjustment. Lower values move the pixel's drawing priority backward and higher values move it forward. Level text supplies the endpoint adjustments explicitly through <code>meshmap_depth</code>. | |||
Depth images affect drawing priority only. They do not change collision geometry, displace texture coordinates, remove geometry, or supply artwork for the other side of a surface. Use the geometry image to shape terrain and the drawing depth image to control how its artwork overlaps other drawing. See [[Mesh Map#Draw Ordering|Draw Ordering]] and [[Drawmethod#Drawing depth|Drawmethod]]. | |||
== Mesh Map Collection == | == Mesh Map Collection == | ||
The mesh map collection belongs to the current level. It uses four address components:<syntaxhighlight lang="text"> | The mesh map collection belongs to the current level. It uses four address components: | ||
<syntaxhighlight lang="text"> | |||
Area | Area | ||
Sector | Sector | ||
Room | Room | ||
Mesh Map | Mesh Map | ||
</syntaxhighlight>Each component is an integer from <code>0</code> through <code>63</code>. 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. | </syntaxhighlight> | ||
Each component is an integer from <code>0</code> through <code>63</code>. 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. | 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 === | === 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:<syntaxhighlight lang="c"> | 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: | ||
<syntaxhighlight lang="c"> | |||
int id = area * 262144 + sector * 4096 + room * 64 + index; | int id = area * 262144 + sector * 4096 + room * 64 + index; | ||
</syntaxhighlight>For example, area 1, sector 2, room 3, map 4 has an ID of 270532. Valid map IDs range from <code>0</code> through <code>16777215</code>, inclusive. IDs are local to the current level. | </syntaxhighlight> | ||
For example, area 1, sector 2, room 3, map 4 has an ID of 270532. Valid map IDs range from <code>0</code> through <code>16777215</code>, inclusive. IDs are local to the current level. | |||
=== Banks === | === Banks === | ||
Each bank | The level collection, each area, each sector, and each room form banks in the hierarchy. Each bank manages its immediate children. Commands also accept the individual mesh as an owner for bounds, entry and exit handlers, and common node properties. | ||
Select the owner by name in level text and by its named constant in script: | |||
{| class="wikitable" | {| class="wikitable" | ||
! | !Level text | ||
! | !Script constant | ||
!Selected owner | |||
!Immediate children | !Immediate children | ||
|- | |- | ||
| | |<code>level</code> | ||
| | |<code>MESHMAP_BANK_LEVEL</code> | ||
|Areas | |Current level's collection root. | ||
|Areas. | |||
|- | |||
|<code>area</code> | |||
|<code>MESHMAP_BANK_AREA</code> | |||
|Selected area. | |||
|Sectors. | |||
|- | |- | ||
| | |<code>sector</code> | ||
| | |<code>MESHMAP_BANK_SECTOR</code> | ||
| | |Selected sector within its area. | ||
|Rooms. | |||
|- | |- | ||
| | |<code>room</code> | ||
| | |<code>MESHMAP_BANK_ROOM</code> | ||
| | |Selected room within its area and sector. | ||
|Mesh maps. | |||
|- | |- | ||
| | |<code>mesh</code> | ||
| | |<code>MESHMAP_BANK_MESH</code> | ||
| | |Selected individual mesh map. | ||
|None. | |||
|} | |} | ||
Each existing child has | Names are case-insensitive. Level text requires these names rather than numeric depth selectors. Script constants are distinct bit flags, but each bank operation takes exactly one owner type. <code>MESHMAP_BANK_NONE</code> represents no selection and is not a valid target; combined flags are not valid targets either. | ||
The selector names the owner being addressed. For example, <code>meshmap_mask area slots 2</code> selects sector 2 within the current area. Use <code>meshmap_mask level slots 2</code> to select area 2 within the level. The <code>mesh</code> owner has no children and does not accept child-selection operations. | |||
Each existing child has a local 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 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. | 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. | ||
Entry and exit observation is independent of these active states. Existing inactive banks and meshes can still detect an entity entering their bounds, allowing its handler to activate or load terrain. See [[Mesh Map#Events|Events]]. | |||
=== Bounds === | === Bounds === | ||
| Line 189: | Line 236: | ||
|The entity's current body box overlaps or touches the bounds. | |The entity's current body box overlaps or touches the bounds. | ||
|} | |} | ||
The body gate uses the | The body gate uses one enclosing world-space box around the active frame's valid body boxes, accounting for facing. If no valid active boxes are available, it falls back to model width and entity height with no Z thickness. Collision admission tests use the current state, rather than a predicted position or the volume swept during movement. Allow enough overlap between neighboring bounds to accommodate the game's movement speeds and transitions. Entry and exit observation also follows committed movement through the bounds, so crossing a complete region within one update can produce both events. See [[Mesh Map#Range Detection|Range Detection]]. | ||
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. | 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 at that node, subject to their ancestors' bounds. Repositioning a mesh map does not move its authored bounds. Bounds are independent of geometry dimensions: loading or replacing a geometry image does not define an event detection range. | ||
== Level Header Commands == | == Level Header Commands == | ||
| Line 202: | Line 249: | ||
# Default | # Default | ||
meshmap_index 0 0 0 0 | meshmap_index 0 0 0 0 | ||
</syntaxhighlight>Select the mesh map addressed by subsequent commands. Each index accepts a value from <code>0</code> through <code>63</code>. The initial selection for every level load is area 0, sector 0, room 0, map 0. | </syntaxhighlight> | ||
Select the mesh map addressed by subsequent commands. Each index accepts a value from <code>0</code> through <code>63</code>. 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 <code>meshmap_index</code> command changes it. It does not advance automatically. | 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 <code>meshmap_index</code> command changes it. It does not advance automatically. | ||
| Line 211: | Line 260: | ||
<syntaxhighlight lang="text"> | <syntaxhighlight lang="text"> | ||
meshmap_geometry {axis} {decimal minimum} {decimal maximum} {path image} | meshmap_geometry {axis} {decimal minimum} {decimal maximum} {path image} | ||
</syntaxhighlight>Load the geometry image and configure its displacement axis and range. Axis accepts <code>x</code>, <code>y</code>, or <code>z</code> (case-insensitive). The minimum must be less than or equal to the maximum. Both accept signed decimal values. | </syntaxhighlight> | ||
Load the geometry image and configure its displacement axis and range. Axis accepts <code>x</code>, <code>y</code>, or <code>z</code> (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 [[Mesh Map#Geometry Images|Geometry Images]]. | Geometry must be a valid 16-bit grayscale PNG. Replacing geometry preserves position, texture, spacing, and the other properties of the selected map. See [[Mesh Map#Geometry Images|Geometry Images]]. | ||
| Line 221: | Line 272: | ||
# Default | # Default | ||
meshmap_position 0 0 0 | meshmap_position 0 0 0 | ||
</syntaxhighlight>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. | </syntaxhighlight> | ||
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 === | === Texture === | ||
| Line 227: | Line 280: | ||
meshmap_texture {path image} | meshmap_texture {path image} | ||
meshmap_texture none | meshmap_texture none | ||
</syntaxhighlight>Assign an optional texture to the selected map. The default is no texture. Use <code>none</code> 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 [[Mesh Map#Texture Images|Texture Images]]. | </syntaxhighlight> | ||
Assign an optional texture to the selected map. The default is no texture. Use <code>none</code> 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 [[Mesh Map#Texture Images|Texture Images]]. | |||
=== Drawing Depth === | |||
<syntaxhighlight lang="text"> | |||
meshmap_depth {decimal adjust_0} {decimal adjust_65535} {path image} | |||
meshmap_depth none | |||
</syntaxhighlight> | |||
Assign a drawing depth image to the selected map. The two signed adjustments apply to samples 0 and 65535, respectively. Both endpoints are required when supplying an image in level text. Use <code>none</code> to remove the depth companion. | |||
For example: | |||
<syntaxhighlight lang="text"> | |||
meshmap_index 0 0 0 2 | |||
meshmap_texture data/terrain/wall.png | |||
meshmap_depth -24 24 data/terrain/wall_depth16.png | |||
</syntaxhighlight> | |||
The depth image must be 16-bit grayscale and match the texture's pixel dimensions. Texture and depth may be declared in either order. Removing the texture retains the separately assigned depth image. Failed loads or replacements with incompatible dimensions preserve the existing resources. | |||
See [[Mesh Map#Drawing Depth Images|Drawing Depth Images]] for sample interpretation and [[Mesh Map#Depth Range Override|Depth Range Override]] for adjusting the range during scripted drawing. | |||
=== Spacing === | === Spacing === | ||
| Line 235: | Line 307: | ||
# Default | # Default | ||
meshmap_spacing 1 1 | meshmap_spacing 1 1 | ||
</syntaxhighlight>Set the spacing of vertices along the image column and row directions, respectively. Each spacing value must be positive and finite. See [[Mesh Map#Geometry Spacing|Geometry Spacing]]. | </syntaxhighlight> | ||
Set the spacing of vertices along the image column and row directions, respectively. Each spacing value must be positive and finite. See [[Mesh Map#Geometry Spacing|Geometry Spacing]]. | |||
=== Configuration === | === Configuration === | ||
| Line 243: | Line 317: | ||
# Default | # Default | ||
meshmap_config collide draw walkable | meshmap_config collide draw walkable | ||
</syntaxhighlight>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 <code>meshmap_config</code> declaration replaces the entire previous selection of flags. | </syntaxhighlight> | ||
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 <code>meshmap_config</code> declaration replaces the entire previous selection of flags. | |||
{| class="wikitable" | {| class="wikitable" | ||
!Native name | !Native name | ||
| Line 291: | Line 367: | ||
# Default | # Default | ||
meshmap_side 0 | meshmap_side 0 | ||
</syntaxhighlight>Select the negative (<code>0</code>) or positive (<code>1</code>) solid side of the surface. See [[Mesh Map#Solid Side|Solid Side]]. | </syntaxhighlight> | ||
Select the negative (<code>0</code>) or positive (<code>1</code>) solid side of the surface. See [[Mesh Map#Solid Side|Solid Side]]. | |||
=== Support Group === | === Support Group === | ||
| Line 299: | Line 377: | ||
# Default (independent support) | # Default (independent support) | ||
meshmap_support_group 4294967295 | meshmap_support_group 4294967295 | ||
</syntaxhighlight>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, <code>4294967295</code> (<code>MESHMAP_GROUP_NONE</code> in script), gives the map an independent support identity. See [[Mesh Map#Support Groups|Support Groups]]. | </syntaxhighlight> | ||
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, <code>4294967295</code> (<code>MESHMAP_GROUP_NONE</code> in script), gives the map an independent support identity. See [[Mesh Map#Support Groups|Support Groups]]. | |||
=== Slope Limit === | === Slope Limit === | ||
| Line 307: | Line 387: | ||
# Default | # Default | ||
meshmap_slope_limit 45 | meshmap_slope_limit 45 | ||
</syntaxhighlight>Set the maximum slope that may provide walkable support on this map. Accepts an angle from <code>0</code> through <code>90</code> degrees. This works with the entity's own slope limit. See [[Mesh Map#Slopes and Steps|Slopes and Steps]]. | </syntaxhighlight> | ||
Set the maximum slope that may provide walkable support on this map. Accepts an angle from <code>0</code> through <code>90</code> degrees. This works with the entity's own slope limit. See [[Mesh Map#Slopes and Steps|Slopes and Steps]]. | |||
=== Layer === | === Layer === | ||
| Line 315: | Line 397: | ||
# Default | # Default | ||
meshmap_layer 0 | meshmap_layer 0 | ||
</syntaxhighlight>Set the map's | </syntaxhighlight> | ||
Set the map's drawing layer. This signed integer supplies its baseline drawing Z, independently of the map's XYZ position. Native queued drawing uses it for ordering. Immediate <code>draw_meshmap()</code> and <code>draw_meshmap_projected()</code> calls also use the map's current layer within an explicit depth pass. Drawing depth images add their per-pixel adjustments to this baseline. | |||
=== Active === | === Active === | ||
| Line 323: | Line 407: | ||
# Default | # Default | ||
meshmap_active 1 | meshmap_active 1 | ||
</syntaxhighlight>Set the selected map's local active state. <code>0</code> disables the map and <code>1</code> enables it. Its resources and configuration remain available while inactive. All ancestor banks must also be active for native collision and rendering. | </syntaxhighlight> | ||
Set the selected map's local active state. <code>0</code> disables the map and <code>1</code> enables it. Its resources and configuration remain available while inactive. All ancestor banks must also be active for native collision and rendering. | |||
=== Map Bounds === | === Map Bounds === | ||
<syntaxhighlight lang="text"> | <syntaxhighlight lang="text"> | ||
meshmap_bounds {decimal min_x} {decimal min_y} {decimal min_z} {decimal max_x} {decimal max_y} {decimal max_z} [int gate_mode] | meshmap_bounds {decimal min_x} {decimal min_y} {decimal min_z} {decimal max_x} {decimal max_y} {decimal max_z} [int gate_mode] | ||
</syntaxhighlight>Set and enable the selected map's applicability bounds. Minimum coordinates may not exceed their respective maximum coordinates. Gate mode defaults to <code>0</code> (current position); <code>1</code> uses the current body box. See [[Mesh Map#Bounds|Bounds]]. | </syntaxhighlight> | ||
Set and enable the selected map's applicability bounds. Minimum coordinates may not exceed their respective maximum coordinates. Gate mode defaults to <code>0</code> (current position); <code>1</code> uses the current body box. See [[Mesh Map#Bounds|Bounds]]. | |||
=== Area, Sector, and Room Bounds === | === Area, Sector, and Room Bounds === | ||
| Line 335: | Line 423: | ||
meshmap_sector {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] | meshmap_room {decimal min_x} {decimal min_y} {decimal min_z} {decimal max_x} {decimal max_y} {decimal max_z} [int gate_mode] | ||
</syntaxhighlight>Set applicability bounds for the area, sector, or room of the current <code>meshmap_index</code> 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 <code>meshmap_bounds</code>. | </syntaxhighlight> | ||
Set applicability bounds for the area, sector, or room of the current <code>meshmap_index</code> 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 <code>meshmap_bounds</code>. | |||
=== Bank Bounds === | === Bank Bounds === | ||
<syntaxhighlight lang="text"> | <syntaxhighlight lang="text"> | ||
meshmap_bank { | meshmap_bank {bank_type} {decimal min_x} {decimal min_y} {decimal min_z} {decimal max_x} {decimal max_y} {decimal max_z} [int gate_mode] | ||
</syntaxhighlight>Set bounds | </syntaxhighlight> | ||
Set and enable the bounds of the specified owner. <code>bank_type</code> accepts <code>level</code>, <code>area</code>, <code>sector</code>, <code>room</code>, or <code>mesh</code>. The selected <code>meshmap_index</code> supplies the applicable address components; <code>level</code> always selects the current collection root. The command creates the selected owner if necessary. Coordinate and gate-mode rules are the same as <code>meshmap_bounds</code>. | |||
For example: | |||
<syntaxhighlight lang="text"> | |||
meshmap_index 1 2 3 4 | |||
# Bounds for the complete collection. | |||
meshmap_bank level -1024 -512 -1024 8192 2048 8192 | |||
# Bounds for room 1/2/3. | |||
meshmap_bank room 0 -128 0 1024 512 256 | |||
# Bounds for mesh 1/2/3/4. | |||
meshmap_bank mesh 128 -64 32 512 256 224 | |||
</syntaxhighlight> | |||
<code>meshmap_bank area</code>, <code>sector</code>, and <code>room</code> are equivalent to <code>meshmap_area</code>, <code>meshmap_sector</code>, and <code>meshmap_room</code>, respectively. <code>meshmap_bank mesh</code> is equivalent to <code>meshmap_bounds</code>. See [[Mesh Map#Banks|Banks]]. | |||
=== Bank Active Selection === | === Bank Active Selection === | ||
<syntaxhighlight lang="text"> | <syntaxhighlight lang="text"> | ||
meshmap_mask { | meshmap_mask {bank_type} none | ||
meshmap_mask { | meshmap_mask {bank_type} all | ||
meshmap_mask { | meshmap_mask {bank_type} slots {int slot} [int slot ...] | ||
</syntaxhighlight>Replace the active selection of the specified bank. | </syntaxhighlight> | ||
Replace the active selection of the specified bank. <code>bank_type</code> accepts <code>level</code>, <code>area</code>, <code>sector</code>, or <code>room</code>. The bank must already exist. The <code>mesh</code> selector is not valid because an individual mesh has no children. | |||
* <code>none</code> - Disable all immediate children. | * <code>none</code> - Disable all immediate children. | ||
| Line 353: | Line 463: | ||
* <code>slots</code> - Enable the specified immediate child indices and disable the others. Each listed slot must already exist and be an integer from 0 through 63. | * <code>slots</code> - 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:<syntaxhighlight lang="text"> | 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 | <syntaxhighlight lang="text"> | ||
</syntaxhighlight> | meshmap_mask level slots 0 2 | ||
</syntaxhighlight> | |||
To enable sectors 0 and 2 within area 1 instead, select that area and address its bank: | |||
<syntaxhighlight lang="text"> | |||
meshmap_index 1 0 0 0 | |||
meshmap_mask area slots 0 2 | |||
</syntaxhighlight> | |||
These commands change activation while retaining the existing resources. Supply slot indices directly rather than constructing a numerical bitmask. Entry and exit observation continues while children are inactive. | |||
=== Mesh Event Handlers === | |||
<syntaxhighlight lang="text"> | |||
meshmap_script_enter {path script} | |||
meshmap_script_exit {path script} | |||
meshmap_script_block {path script} | |||
</syntaxhighlight> | |||
Assign entry, exit, and blocking handlers to the individual mesh selected by <code>meshmap_index</code>. The default is no handler. Each command accepts <code>none</code> in place of the path to remove that handler: | |||
<syntaxhighlight lang="text"> | |||
meshmap_index 1 2 3 4 | |||
meshmap_script_enter data/scripts/terrain/mesh_enter.c | |||
meshmap_script_exit data/scripts/terrain/mesh_exit.c | |||
meshmap_script_block data/scripts/terrain/mesh_block.c | |||
# Remove only the entry handler. | |||
meshmap_script_enter none | |||
</syntaxhighlight> | |||
Each assignment creates the selected mesh descriptor if needed. Entry and exit use authored bounds and do not require geometry; blocking events require actual mesh collision. See [[Mesh Map#Events|Events]]. | |||
=== Bank Event Handlers === | |||
<syntaxhighlight lang="text"> | |||
meshmap_bank_script_enter {bank_type} {path script} | |||
meshmap_bank_script_exit {bank_type} {path script} | |||
</syntaxhighlight> | |||
Assign entry and exit handlers to the selected owner. <code>bank_type</code> accepts <code>level</code>, <code>area</code>, <code>sector</code>, <code>room</code>, or <code>mesh</code>. Use <code>none</code> instead of a script path to clear the corresponding handler. Names and <code>none</code> are case-insensitive. | |||
The command creates an empty owner if needed. Banks can observe their bounds without containing any geometry or active children. <code>meshmap_bank_script_enter mesh</code> and <code>meshmap_bank_script_exit mesh</code> address the same handlers as <code>meshmap_script_enter</code> and <code>meshmap_script_exit</code>. | |||
For example, the following attaches separate entry handlers at every hierarchy level along the selected path: | |||
<syntaxhighlight lang="text"> | |||
meshmap_index 1 2 3 4 | |||
meshmap_bank_script_enter level data/scripts/terrain/level_enter.c | |||
meshmap_bank_script_enter area data/scripts/terrain/area_enter.c | |||
meshmap_bank_script_enter sector data/scripts/terrain/sector_enter.c | |||
meshmap_bank_script_enter room data/scripts/terrain/room_enter.c | |||
meshmap_bank_script_enter mesh data/scripts/terrain/mesh_enter.c | |||
</syntaxhighlight> | |||
Define bounds for each region that needs a limited detection range. Without enabled bounds, that owner admits every entity admitted by its ancestors. Blocking handlers belong to individual meshes and use <code>meshmap_script_block</code>. | |||
== Level Examples == | == Level Examples == | ||
=== Ground Terrain === | === Ground Terrain === | ||
Assume <code>data/terrain/trough16.png</code> is a 65 by 17 grayscale16 geometry image whose nonzero samples describe a shallow trough, and <code>data/terrain/road24.png</code> contains the road artwork.<syntaxhighlight lang="text"> | Assume <code>data/terrain/trough16.png</code> is a 65 by 17 grayscale16 geometry image whose nonzero samples describe a shallow trough, and <code>data/terrain/road24.png</code> contains the road artwork. | ||
<syntaxhighlight lang="text"> | |||
meshmap_index 0 0 0 0 | meshmap_index 0 0 0 0 | ||
meshmap_geometry y -24 0 data/terrain/trough16.png | meshmap_geometry y -24 0 data/terrain/trough16.png | ||
| Line 370: | Line 532: | ||
meshmap_slope_limit 45 | meshmap_slope_limit 45 | ||
meshmap_layer -1000 | meshmap_layer -1000 | ||
</syntaxhighlight>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. | </syntaxhighlight> | ||
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 === | === Side-View Terrain === | ||
Assume <code>data/terrain/side16.png</code> is a 17 by 17 grayscale16 geometry image. Draw the intended solid portions of a side-view level using sample <code>65535</code> and the traversable portions using sample <code>1</code>.<syntaxhighlight lang="text"> | Assume <code>data/terrain/side16.png</code> is a 17 by 17 grayscale16 geometry image. Draw the intended solid portions of a side-view level using sample <code>65535</code> and the traversable portions using sample <code>1</code>. | ||
<syntaxhighlight lang="text"> | |||
meshmap_index 0 0 0 0 | meshmap_index 0 0 0 0 | ||
meshmap_geometry z -1 1 data/terrain/side16.png | meshmap_geometry z -1 1 data/terrain/side16.png | ||
| Line 380: | Line 545: | ||
meshmap_config collide walkable | meshmap_config collide walkable | ||
meshmap_side 0 | meshmap_side 0 | ||
</syntaxhighlight>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 [[Mesh Map#Movement Plane|Movement Plane]]. | </syntaxhighlight> | ||
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 [[Mesh Map#Movement Plane|Movement Plane]]. | |||
=== X-Axis Barrier === | === X-Axis Barrier === | ||
Assume <code>data/terrain/flat16.png</code> is a two by two grayscale16 image containing four nonzero samples.<syntaxhighlight lang="text"> | Assume <code>data/terrain/flat16.png</code> is a two by two grayscale16 image containing four nonzero samples. | ||
<syntaxhighlight lang="text"> | |||
meshmap_index 0 0 0 1 | meshmap_index 0 0 0 1 | ||
meshmap_geometry x 0 0 data/terrain/flat16.png | meshmap_geometry x 0 0 data/terrain/flat16.png | ||
| Line 390: | Line 558: | ||
meshmap_config collide | meshmap_config collide | ||
meshmap_side 1 | meshmap_side 1 | ||
</syntaxhighlight>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. | </syntaxhighlight> | ||
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 == | == Entity Movement == | ||
Native mesh collision is enabled for entities by default. | Native mesh collision is enabled for entities by default. Entities 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 [[Mesh Map#Entity Properties|Entity Properties]]. | ||
=== Legacy Floors and Platforms === | === Legacy Floors and Platforms === | ||
| Line 406: | Line 576: | ||
=== Movement Plane === | === 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.<syntaxhighlight lang="c"> | 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. | ||
<syntaxhighlight lang="c"> | |||
void main() | void main() | ||
{ | { | ||
| Line 417: | Line 588: | ||
openborconstant("MESHMAP_AXIS_Z")); | openborconstant("MESHMAP_AXIS_Z")); | ||
} | } | ||
</syntaxhighlight>Use <code>MESHMAP_PLANE_NONE</code> 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. | </syntaxhighlight> | ||
Use <code>MESHMAP_PLANE_NONE</code> 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. | 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 === | === One-Way Platforms === | ||
The <code>one_way</code> 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. | The <code>one_way</code> 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. Falling entities may establish support on its eligible upper surface. | ||
For example, use the same two by two flat geometry image to define a platform above the earlier ground terrain:<syntaxhighlight lang="text"> | For example, use the same two by two flat geometry image to define a platform above the earlier ground terrain: | ||
<syntaxhighlight lang="text"> | |||
meshmap_index 0 0 0 2 | meshmap_index 0 0 0 2 | ||
meshmap_geometry y 0 0 data/terrain/flat16.png | meshmap_geometry y 0 0 data/terrain/flat16.png | ||
| Line 432: | Line 606: | ||
meshmap_support_group 12 | meshmap_support_group 12 | ||
meshmap_slope_limit 45 | meshmap_slope_limit 45 | ||
</syntaxhighlight>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. | </syntaxhighlight> | ||
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 ==== | ==== Drop Through ==== | ||
The <code>drop_through</code> 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:<syntaxhighlight lang="c"> | The <code>drop_through</code> 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: | ||
<syntaxhighlight lang="c"> | |||
int started_drop = set_entity_property(self, | int started_drop = set_entity_property(self, | ||
openborconstant("ENTITY_PROPERTY_MESHMAP_DROP_REQUEST"), 1); | openborconstant("ENTITY_PROPERTY_MESHMAP_DROP_REQUEST"), 1); | ||
</syntaxhighlight>Both <code>one_way</code> and <code>drop_through</code> must be configured on the current support. The action returns <code>1</code> 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. | </syntaxhighlight> | ||
Both <code>one_way</code> and <code>drop_through</code> must be configured on the current support. The action returns <code>1</code> 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 <code>0</code> to cancel the drop exception. Read the same property to test whether an exception is active. | Set the property to <code>0</code> to cancel the drop exception. Read the same property to test whether an exception is active. | ||
| Line 448: | Line 627: | ||
=== Movement Events === | === Movement Events === | ||
Native slope and step adjustments that change entity altitude during lateral movement invoke the existing <code>onmoveyscript</code> event. Upward movement blocked by a mesh ceiling invokes <code>onblockyscript</code> with <code>obstacle</code> set to <code>NULL()</code>, since the obstruction is not a platform entity. Lateral mesh contacts do not supply a legacy wall object. | Native slope and step adjustments that change entity altitude during lateral movement invoke the existing <code>onmoveyscript</code> event. Upward movement blocked by a mesh ceiling invokes <code>onblockyscript</code> with <code>obstacle</code> set to <code>NULL()</code>, since the obstruction is not a platform entity. Lateral mesh contacts do not supply a legacy wall object. Mesh-owned blocking handlers provide the mesh ID, contact kind, position, normal, and accepted movement for side contacts, ceilings, and landings. See [[Mesh Map#Blocking Events|Blocking Events]]. | ||
== Events == | |||
Banks and individual meshes can own scripts that respond when entities enter or leave their detection ranges. Individual meshes can also own a blocking script that responds to collision contacts. Handlers belong to the terrain owner and receive the triggering entity as <code>self</code>. | |||
For example, a room can start an encounter when the first entity enters, a sector can load its terrain as entities approach, and a particular mesh can respond to a landing or wall contact. No handler is required on the entity's model. | |||
=== Range Detection === | |||
Entry and exit use the owner's authored bounds together with every enabled ancestor bound. The entity must satisfy all of those gates, including bounds on ancestors without handlers. The detection range is independent of the geometry image, texture, and solid-side configuration. Overlapping owners observe their own ranges independently. | |||
* <code>MESHMAP_GATE_POSITION</code> observes the entity's reference position. | |||
* <code>MESHMAP_GATE_BODY</code> observes overlap with the current entity body box. | |||
* Disabled bounds impose no additional restriction at that node. Ancestor bounds still apply. | |||
Define a finite range with <code>meshmap_bank</code>, one of the named bank-bound commands, or <code>meshmap_bounds</code>. Unbounded owners observe every entity admitted by their ancestors, even when their geometry covers only a small part of that area. | |||
Range observation continues while a map or ancestor is inactive, while collision or drawing is disabled, while the entity has mesh collision disabled, and while a bank has no loaded children. This allows an entry handler on an empty room to load its terrain. Removing the room itself also removes its observer, so retain the room when it must detect a later return. | |||
Committed movement is observed along its accepted path. Entities can enter and exit a narrow region during one update and produce both events even if they finish outside. Direct script position changes reconcile membership at the resulting position without treating the change as movement through every intervening region. Body-gated membership can also change when animation or facing changes the current body bounds. | |||
Contact with a bound counts as inside. Merely touching a bound while passing between two outside positions, without an interval inside the region, does not produce a zero-duration visit. | |||
=== Event Timing and Lifetime === | |||
Handlers execute after native entity updates, once the terrain traversal has finished. Scripts may change terrain, replace handlers, or remove an owner from within a callback. Events caused by those callbacks wait for a subsequent dispatch rather than interrupting the current callback batch. | |||
Crossings along one movement segment are delivered in travel order. At the same point, exits precede entries. When several owners are entered at the same point, the outer owner enters first. When several owners are exited at the same point, the inner owner exits first. For example, simultaneous entry into an area, sector, room, and mesh reaches the area handler first; simultaneous exit reaches the mesh handler first. | |||
Event locals describe the recorded transition. The entity may have moved farther by the time its handler executes, so use the event's <code>x</code>, <code>y</code>, and <code>z</code> when the crossing position matters. Query the entity when its current position is needed instead. | |||
Queued events retain the handler assigned when they were recorded. Replacing a handler affects later events. Pending entry and blocking events are discarded if their owner or triggering entity no longer matches the recorded lifetime. Exit events retain their original owner and entity identity so cleanup can still run after removal. | |||
Callback locals are cleared after the handler returns. Copy any values needed later into the game's own state. | |||
The <code>self</code> local may be <code>NULL()</code> in an exit handler if the entity allocation has been removed or reused. The pointer may also refer to an entity whose active lifetime has ended. Use the captured <code>pool_id</code>, <code>unique_id</code>, <code>entity_type</code>, and <code>playerindex</code> for identity that must survive removal. Before changing an owner from a retained exit callback, confirm that it still exists and its generation matches the event. See [[Mesh Map#Load Terrain on Entry|Load Terrain on Entry]]. | |||
Level teardown discards pending events. Use the level's teardown behavior for whole-level cleanup rather than relying on a final exit callback from every owner. | |||
=== Blocking Events === | |||
<code>meshmap_script_block</code> responds to actual native movement contacts with that mesh. These include lateral obstruction, a ceiling stopping upward movement, and a mesh surface stopping downward movement. Speculative collision probes used by movement or AI do not call the handler. Successfully walking a slope or stepping onto terrain does not generate a block for an obstruction that the accepted route avoids. | |||
The event identifies the blocking mesh and the obstructed movement axis. The <code>axis</code> local uses <code>MESHMAP_AXIS_X</code>, <code>MESHMAP_AXIS_Y</code>, or <code>MESHMAP_AXIS_Z</code>; it is not the mesh's displacement orientation. For example, a Z-oriented map can obstruct an entity's X movement or provide a Y landing in a side-view level. | |||
The <code>contact_kind</code> local distinguishes: | |||
{| class="wikitable" | |||
!Constant | |||
!Contact | |||
|- | |||
|<code>MESHMAP_CONTACT_SIDE</code> | |||
|Movement blocked laterally by terrain. | |||
|- | |||
|<code>MESHMAP_CONTACT_CEILING</code> | |||
|Upward movement stopped by terrain overhead. | |||
|- | |||
|<code>MESHMAP_CONTACT_LANDING</code> | |||
|Downward movement is stopped by a mesh surface. Check <code>walkable</code> when the response requires standing support. | |||
|} | |||
The handler also receives the contact position, surface normal, requested movement, and accepted movement. Requested and accepted values are movement deltas, not destination coordinates. Repeated reporting of the same entity's landing on the same mesh within one logical tick is consolidated. Standing on a mesh does not continuously produce landing events. Repeated movement into an obstacle can produce repeated blocking events; this is a movement notification rather than a contact-entry/contact-exit pair. | |||
Range callbacks report membership changes. Blocking callbacks report collision responses from participating meshes. Entering the bounds does not require touching the mesh geometry. The blocking callback reports a completed collision response; script changes affect subsequent behavior rather than canceling the reported result. | |||
=== Handler Local Variables === | |||
Read callback values with <code>getlocalvar("name")</code>. Event kinds are <code>MESHMAP_EVENT_ENTER</code>, <code>MESHMAP_EVENT_EXIT</code>, and <code>MESHMAP_EVENT_BLOCK</code>, obtained through <code>openborconstant()</code>. | |||
==== Owner and Entity ==== | |||
{| class="wikitable" | |||
!Local | |||
!Meaning | |||
|- | |||
|<code>self</code> | |||
|Triggering entity, or <code>NULL()</code> when the original entity no longer occupies its pool slot. The retained entity can also have its existence flag cleared. | |||
|- | |||
|<code>collection</code> | |||
|Level-owned mesh collection handle. | |||
|- | |||
|<code>event</code> | |||
|Event kind: enter, exit, or block. | |||
|- | |||
|<code>reason</code> | |||
|Reason for the transition, using a <code>MESHMAP_EVENT_REASON_*</code> constant. | |||
|- | |||
|<code>bank</code> | |||
|Owner type using <code>MESHMAP_BANK_LEVEL</code>, <code>AREA</code>, <code>SECTOR</code>, <code>ROOM</code>, or <code>MESH</code>. See the complete constant names below. | |||
|- | |||
|<code>scope</code> | |||
|Owner scope using the corresponding <code>MESHMAP_EVENT_SCOPE_*</code> constant. This is separate from the bank selector. | |||
|- | |||
|<code>id</code> | |||
|Normalized packed owner prefix, or the complete map ID for a mesh. Components below a bank's scope are zero in this packed value. | |||
|- | |||
|<code>generation</code> | |||
|Recorded allocation identity of the owner. | |||
|- | |||
|<code>area</code>, <code>sector</code>, <code>room</code>, <code>index</code> | |||
|Owner address components. Components below the owner's scope are <code>-1</code>; all four are <code>-1</code> for the level owner. | |||
|- | |||
|<code>pool_id</code> | |||
|Stable allocation slot of the triggering entity. | |||
|- | |||
|<code>unique_id</code> | |||
|Identity of the triggering entity's particular lifetime. | |||
|- | |||
|<code>entity_type</code>, <code>playerindex</code> | |||
|Entity classification and player index captured with the event. These remain available when <code>self</code> is unavailable. | |||
|} | |||
==== Owner Constants ==== | |||
{| class="wikitable" | |||
!Owner | |||
!<code>bank</code> | |||
!<code>scope</code> | |||
|- | |||
|Level collection | |||
|<code>MESHMAP_BANK_LEVEL</code> | |||
|<code>MESHMAP_EVENT_SCOPE_LEVEL</code> | |||
|- | |||
|Area | |||
|<code>MESHMAP_BANK_AREA</code> | |||
|<code>MESHMAP_EVENT_SCOPE_AREA</code> | |||
|- | |||
|Sector | |||
|<code>MESHMAP_BANK_SECTOR</code> | |||
|<code>MESHMAP_EVENT_SCOPE_SECTOR</code> | |||
|- | |||
|Room | |||
|<code>MESHMAP_BANK_ROOM</code> | |||
|<code>MESHMAP_EVENT_SCOPE_ROOM</code> | |||
|- | |||
|Mesh | |||
|<code>MESHMAP_BANK_MESH</code> | |||
|<code>MESHMAP_EVENT_SCOPE_MESH</code> | |||
|} | |||
Pass the callback's <code>collection</code>, <code>bank</code>, and <code>id</code> directly to the bank property functions for common owner properties, including mesh bounds, entry and exit handlers, occupancy, and generation. Use <code>bank</code> for that argument, not <code>scope</code>. Mesh-specific properties remain available through <code>get_meshmap_property()</code> and <code>set_meshmap_property()</code>. | |||
==== Range and Position ==== | |||
{| class="wikitable" | |||
!Local | |||
!Meaning | |||
|- | |||
|<code>occupants_before</code>, <code>occupants_after</code> | |||
|Observed membership counts immediately before and after this event's transition. Blocking events leave both counts equal; with only a blocking handler assigned, both are zero. | |||
|- | |||
|<code>x</code>, <code>y</code>, <code>z</code> | |||
|Entity reference position recorded for the event. | |||
|- | |||
|<code>fraction</code> | |||
|For a range crossing, a value from 0 through 1 locating the transition along that committed movement segment. Endpoint reconciliation uses 1; removal and observation-reconfiguration exits use 0. This is not elapsed time or a fraction of the whole update. Blocking events leave it at 0. | |||
|} | |||
==== Blocking Contact ==== | |||
The following locals describe blocking events. Range events leave these contact fields at zero; do not interpret them as contact information unless <code>event</code> is <code>MESHMAP_EVENT_BLOCK</code>. | |||
{| class="wikitable" | |||
!Local | |||
!Meaning | |||
|- | |||
|<code>axis</code> | |||
|Obstructed world movement axis. | |||
|- | |||
|<code>contact_kind</code> | |||
|<code>MESHMAP_CONTACT_SIDE</code>, <code>MESHMAP_CONTACT_CEILING</code>, or <code>MESHMAP_CONTACT_LANDING</code>. | |||
|- | |||
|<code>contact_x</code>, <code>contact_y</code>, <code>contact_z</code> | |||
|World-space contact position. | |||
|- | |||
|<code>normal_x</code>, <code>normal_y</code>, <code>normal_z</code> | |||
|Components of the outward contact normal. | |||
|- | |||
|<code>requested_x</code>, <code>requested_y</code>, <code>requested_z</code> | |||
|Requested movement deltas. | |||
|- | |||
|<code>accepted_x</code>, <code>accepted_y</code>, <code>accepted_z</code> | |||
|Accepted movement deltas after collision resolution. | |||
|- | |||
|<code>boundary</code> | |||
|1 for a finite-grid or hole-edge boundary contact; 0 for a sampled surface contact. | |||
|- | |||
|<code>walkable</code> | |||
|Whether the reported contact qualifies as walkable support for this movement result. | |||
|} | |||
==== Transition Reasons ==== | |||
{| class="wikitable" | |||
!Constant | |||
!Meaning | |||
|- | |||
|<code>MESHMAP_EVENT_REASON_UPDATE</code> | |||
|Membership reconciled with current entity state. This includes ordinary direct script position changes, bounds or body changes observed during refresh, and newly installed observation. | |||
|- | |||
|<code>MESHMAP_EVENT_REASON_MOVE</code> | |||
|Committed native movement, including blocking contacts. | |||
|- | |||
|<code>MESHMAP_EVENT_REASON_SPAWN</code> | |||
|Membership established for a spawned entity. | |||
|- | |||
|<code>MESHMAP_EVENT_REASON_REMOVE</code> | |||
|Entity or terrain owner removed from observation. | |||
|- | |||
|<code>MESHMAP_EVENT_REASON_RECONFIGURE</code> | |||
|Existing membership retired when the final entry or exit handler is removed from an owner. Ordinary bounds edits use <code>UPDATE</code> when refreshed. | |||
|- | |||
|<code>MESHMAP_EVENT_REASON_TELEPORT</code> | |||
|Defined teleport reason identifier. Standard movement and position setters do not emit it. Direct script position assignments use endpoint reconciliation with <code>UPDATE</code>. | |||
|} | |||
=== Occupancy and Loading === | |||
Owners with at least one entry or exit handler maintain observed membership. The engine tracks this in a lazily allocated bit table indexed by stable entity pool slot. Installing only a blocking handler does not enable range membership. Counts belong to each observed owner; they are not sums of descendant counts. Parents without a range handler can therefore report zero while one of their observed children has occupants. | |||
Installing an entry or exit handler establishes membership during the next movement or membership refresh. Immediately querying occupancy after assignment can therefore still return zero. Replacing a handler while range observation remains enabled preserves existing membership. Removing the final range handler clears it; if the outgoing handler set includes an exit script, that script can receive retirement exits with reason <code>MESHMAP_EVENT_REASON_RECONFIGURE</code>. | |||
Counts include all observed entities, not only players. Handlers can use <code>entity_type</code>, <code>playerindex</code>, or entity properties to choose which transitions should trigger game behavior. Such filtering does not change the owner's native occupancy count. | |||
For an entry event, <code>occupants_before == 0</code> identifies the first observed occupant at that transition. For an exit event, <code>occupants_after == 0</code> identifies a transition to an empty region. These are historical values from the individual event. Multiple transitions can be waiting for their callbacks, and another entity may have entered before an earlier exit handler runs. | |||
Before unloading terrain, check the owner's current <code>OCCUPANT_COUNT</code> and require it to be zero. Also check <code>EXISTS</code> and <code>GENERATION</code> before acting on an owner from an exit callback: its original owner may have been removed, or the same address may now identify a replacement. The following example applies all three checks. | |||
==== Load Terrain on Entry ==== | |||
This example reserves mesh slot 0 in room 0/0/0. The room persists as a detection region while its terrain loads on entry and is removed when empty. It uses the trough geometry and artwork described in [[Mesh Map#Ground Terrain|Ground Terrain]]. | |||
Level header: | |||
<syntaxhighlight lang="text"> | |||
meshmap_index 0 0 0 0 | |||
meshmap_bank room -64 -128 -64 1088 512 320 | |||
meshmap_bank_script_enter room data/scripts/terrain/room_enter.c | |||
meshmap_bank_script_exit room data/scripts/terrain/room_exit.c | |||
</syntaxhighlight> | |||
The bounds extend beyond the terrain so detection can occur before an entity needs the terrain's collision. Choose that margin for the game's movement speeds and loading behavior. | |||
<code>data/scripts/terrain/room_enter.c</code>: | |||
<syntaxhighlight lang="c"> | |||
void main() | |||
{ | |||
void maps = getlocalvar("collection"); | |||
int bank = getlocalvar("bank"); | |||
int prefix = getlocalvar("id"); | |||
int map_id = prefix; // Mesh slot 0 in this room. | |||
if(bank != openborconstant("MESHMAP_BANK_ROOM")) return; | |||
if(!get_meshmap_bank_property(maps, bank, prefix, | |||
openborconstant("MESHMAP_BANK_PROPERTY_EXISTS"))) return; | |||
if(get_meshmap_bank_property(maps, bank, prefix, | |||
openborconstant("MESHMAP_BANK_PROPERTY_GENERATION")) | |||
!= getlocalvar("generation")) return; | |||
if(get_meshmap_bank_property(maps, bank, prefix, | |||
openborconstant("MESHMAP_BANK_PROPERTY_OCCUPANT_COUNT")) == 0) return; | |||
if(get_meshmap_property(maps, map_id, | |||
openborconstant("MESHMAP_PROPERTY_EXISTS"))) return; | |||
set_meshmap_property(maps, map_id, | |||
openborconstant("MESHMAP_PROPERTY_EXISTS"), 1); | |||
set_meshmap_property(maps, map_id, | |||
openborconstant("MESHMAP_PROPERTY_AXIS"), | |||
openborconstant("MESHMAP_AXIS_Y")); | |||
set_meshmap_property(maps, map_id, | |||
openborconstant("MESHMAP_PROPERTY_MINIMUM"), -24); | |||
set_meshmap_property(maps, map_id, | |||
openborconstant("MESHMAP_PROPERTY_MAXIMUM"), 0); | |||
set_meshmap_property(maps, map_id, | |||
openborconstant("MESHMAP_PROPERTY_SPACING_U"), 16); | |||
set_meshmap_property(maps, map_id, | |||
openborconstant("MESHMAP_PROPERTY_SPACING_V"), 16); | |||
set_meshmap_property(maps, map_id, | |||
openborconstant("MESHMAP_PROPERTY_GEOMETRY"), | |||
"data/terrain/trough16.png"); | |||
set_meshmap_property(maps, map_id, | |||
openborconstant("MESHMAP_PROPERTY_ARTWORK"), | |||
"data/terrain/road24.png"); | |||
set_meshmap_property(maps, map_id, | |||
openborconstant("MESHMAP_PROPERTY_LAYER"), -1000); | |||
} | |||
</syntaxhighlight> | |||
<code>data/scripts/terrain/room_exit.c</code>: | |||
<syntaxhighlight lang="c"> | |||
void main() | |||
{ | |||
void maps = getlocalvar("collection"); | |||
int bank = getlocalvar("bank"); | |||
int prefix = getlocalvar("id"); | |||
int map_id = prefix; // Same reserved mesh slot 0. | |||
if(bank != openborconstant("MESHMAP_BANK_ROOM")) return; | |||
if(!get_meshmap_bank_property(maps, bank, prefix, | |||
openborconstant("MESHMAP_BANK_PROPERTY_EXISTS"))) return; | |||
if(get_meshmap_bank_property(maps, bank, prefix, | |||
openborconstant("MESHMAP_BANK_PROPERTY_GENERATION")) | |||
!= getlocalvar("generation")) return; | |||
if(get_meshmap_bank_property(maps, bank, prefix, | |||
openborconstant("MESHMAP_BANK_PROPERTY_OCCUPANT_COUNT")) != 0) return; | |||
if(get_meshmap_property(maps, map_id, | |||
openborconstant("MESHMAP_PROPERTY_EXISTS"))) | |||
{ | |||
set_meshmap_property(maps, map_id, | |||
openborconstant("MESHMAP_PROPERTY_EXISTS"), 0); | |||
} | |||
} | |||
</syntaxhighlight> | |||
The exit handler removes the reserved mesh, leaving the room and its handlers available for a later return. Larger rooms can manage several reserved mesh slots in the same way. Loading only when resources are absent and checking current occupancy before release prevents repeated work for every entering entity and avoids unloading beneath an entity that has already entered. | |||
==== Respond to a Landing ==== | |||
Assign this script with <code>meshmap_script_block</code>. It records landings on that mesh while ignoring side and ceiling contacts: | |||
<syntaxhighlight lang="c"> | |||
void main() | |||
{ | |||
if(getlocalvar("contact_kind") != | |||
openborconstant("MESHMAP_CONTACT_LANDING")) return; | |||
log("\nMesh landing: " + getlocalvar("id") | |||
+ "; entity pool slot: " + getlocalvar("pool_id")); | |||
} | |||
</syntaxhighlight> | |||
Replace the logging with the intended terrain response, such as a landing effect, a sound, or a scripted reaction. Use the supplied contact position and normal to place and orient an effect. | |||
== Script API == | == Script API == | ||
| Line 459: | Line 951: | ||
void maps = get_level_property(NULL(), | void maps = get_level_property(NULL(), | ||
openborconstant("LEVEL_PROPERTY_MESHMAP_COLLECTION")); | openborconstant("LEVEL_PROPERTY_MESHMAP_COLLECTION")); | ||
</syntaxhighlight>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. | </syntaxhighlight> | ||
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 ==== | ==== Get Map Count ==== | ||
| Line 465: | Line 959: | ||
int count = get_level_property(NULL(), | int count = get_level_property(NULL(), | ||
openborconstant("LEVEL_PROPERTY_MESHMAP_COUNT")); | openborconstant("LEVEL_PROPERTY_MESHMAP_COUNT")); | ||
</syntaxhighlight>Returns the number of existing map objects in the collection, including inactive maps. Both collection-related level properties are read-only. | </syntaxhighlight> | ||
Returns the number of existing map objects in the collection, including inactive maps. Both collection-related level properties are read-only. | |||
=== Map Properties === | === Map Properties === | ||
| Line 473: | Line 969: | ||
get_meshmap_property(collection, id, property); | get_meshmap_property(collection, id, property); | ||
get_meshmap_property(collection, id, property, column, row); | get_meshmap_property(collection, id, property, column, row); | ||
get_meshmap_property(collection, id, property, pool_id); | |||
get_meshmap_property(collection, id, property, world_x, world_y, world_z); | get_meshmap_property(collection, id, property, world_x, world_y, world_z); | ||
</syntaxhighlight>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 [[Mesh Map#Geometry Samples|Geometry Samples]] and [[Mesh Map#Surface Queries|Surface Queries]]. | </syntaxhighlight> | ||
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. The <code>OCCUPANT</code> property takes an entity pool ID as its additional argument. See [[Mesh Map#Geometry Samples|Geometry Samples]] and [[Mesh Map#Surface Queries|Surface Queries]]. | |||
==== Set Map Property ==== | ==== Set Map Property ==== | ||
| Line 480: | Line 979: | ||
set_meshmap_property(collection, id, property, value); | set_meshmap_property(collection, id, property, value); | ||
set_meshmap_property(collection, id, property, value, column, row); | set_meshmap_property(collection, id, property, value, column, row); | ||
</syntaxhighlight>Sets a writable property of the specified map. Successful assignments return <code>1</code>. 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. | set_meshmap_property(collection, id, property, path, adjust_0, adjust_65535); | ||
</syntaxhighlight> | |||
Sets a writable property of the specified map. Successful assignments return <code>1</code>. 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. The last signature applies to <code>MESHMAP_PROPERTY_DEPTH</code> and replaces its image and adjustment pair together. Supply both adjustments or omit both. | |||
==== Map Property Reference ==== | ==== Map Property Reference ==== | ||
| Line 543: | Line 1,045: | ||
|<code>LAYER</code> | |<code>LAYER</code> | ||
|Read/Write | |Read/Write | ||
| | |Baseline drawing Z for native queued drawing and immediate drawing within an explicit depth pass. | ||
|- | |- | ||
|<code>WIDTH</code>, <code>HEIGHT</code> | |<code>WIDTH</code>, <code>HEIGHT</code> | ||
| Line 564: | Line 1,066: | ||
|Read/Write | |Read/Write | ||
|Texture image path. Assign a path to load or replace artwork; assign an empty string to remove it. | |Texture image path. Assign a path to load or replace artwork; assign an empty string to remove it. | ||
|- | |||
|<code>DEPTH</code> | |||
|Read/Write | |||
|Drawing depth image path. Assign a string path, optionally followed by both adjustment endpoints. Assign an empty string to remove the companion. | |||
|- | |||
|<code>DEPTH_ADJUST0</code>, <code>DEPTH_ADJUST65535</code> | |||
|Read | |||
|Authored drawing-Z adjustments for samples 0 and 65535. Read the stored endpoints; change them by assigning <code>DEPTH</code> with an image path and both values. | |||
|- | |||
|<code>SCRIPT_ENTER</code>, <code>SCRIPT_EXIT</code>, <code>SCRIPT_BLOCK</code> | |||
|Read/Write | |||
|Handler script paths. Assign a path to load or replace a handler; assign <code>NULL()</code> or an empty string to remove it. | |||
|- | |||
|<code>OCCUPANT_COUNT</code> | |||
|Read | |||
|Current number of entities observed inside the mesh's range. Requires an entry or exit handler. | |||
|- | |||
|<code>OCCUPANT</code> | |||
|Read | |||
|Membership as 0 or 1. Supply the entity pool ID as the additional argument. | |||
|- | |- | ||
|<code>REVISION</code> | |<code>REVISION</code> | ||
| Line 588: | Line 1,110: | ||
==== Create a Map ==== | ==== 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.<syntaxhighlight lang="c"> | 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. | ||
<syntaxhighlight lang="c"> | |||
void main() | void main() | ||
{ | { | ||
| Line 624: | Line 1,147: | ||
==== Configuration Flags ==== | ==== Configuration Flags ==== | ||
Set the complete configuration using the named constants. Combine multiple constants with bitwise OR, as in the following example:<syntaxhighlight lang="c"> | Set the complete configuration using the named constants. Combine multiple constants with bitwise OR, as in the following example: | ||
<syntaxhighlight lang="c"> | |||
set_meshmap_property(maps, id, | set_meshmap_property(maps, id, | ||
openborconstant("MESHMAP_PROPERTY_FLAGS"), | openborconstant("MESHMAP_PROPERTY_FLAGS"), | ||
openborconstant("MESHMAP_COLLIDE") | | openborconstant("MESHMAP_COLLIDE") | | ||
openborconstant("MESHMAP_WALKABLE")); | openborconstant("MESHMAP_WALKABLE")); | ||
</syntaxhighlight>The map retains collision and walkable support but no longer draws automatically. To change only one flag, use its corresponding individual property instead:<syntaxhighlight lang="c"> | </syntaxhighlight> | ||
The map retains collision and walkable support but no longer draws automatically. To change only one flag, use its corresponding individual property instead: | |||
<syntaxhighlight lang="c"> | |||
set_meshmap_property(maps, id, | set_meshmap_property(maps, id, | ||
openborconstant("MESHMAP_PROPERTY_DRAW"), 0); | openborconstant("MESHMAP_PROPERTY_DRAW"), 0); | ||
</syntaxhighlight>Use constants rather than literal numeric masks. | </syntaxhighlight> | ||
Use constants rather than literal numeric masks. | |||
==== Drawing Depth Properties ==== | |||
Assign a depth image with the default one-for-one range, or supply both endpoint adjustments explicitly: | |||
<syntaxhighlight lang="c"> | |||
/* Default: sample 32768 is neutral. */ | |||
set_meshmap_property(maps, id, | |||
openborconstant("MESHMAP_PROPERTY_DEPTH"), | |||
"data/terrain/wall_depth16.png"); | |||
/* Replace the image and endpoint pair together. */ | |||
set_meshmap_property(maps, id, | |||
openborconstant("MESHMAP_PROPERTY_DEPTH"), | |||
"data/terrain/wall_depth16.png", -24, 24); | |||
</syntaxhighlight> | |||
Read the assigned path and authored endpoints: | |||
<syntaxhighlight lang="c"> | |||
void path = get_meshmap_property(maps, id, | |||
openborconstant("MESHMAP_PROPERTY_DEPTH")); | |||
float adjust_0 = get_meshmap_property(maps, id, | |||
openborconstant("MESHMAP_PROPERTY_DEPTH_ADJUST0")); | |||
float adjust_65535 = get_meshmap_property(maps, id, | |||
openborconstant("MESHMAP_PROPERTY_DEPTH_ADJUST65535")); | |||
</syntaxhighlight> | |||
Without a companion, the path is an empty string and the endpoint getters return -32768 and +32767. Remove the companion by assigning an empty string: | |||
<syntaxhighlight lang="c"> | |||
set_meshmap_property(maps, id, | |||
openborconstant("MESHMAP_PROPERTY_DEPTH"), ""); | |||
</syntaxhighlight> | |||
This property requires a string path; <code>NULL()</code> is not its removal value. To adjust depth during one drawing operation while keeping the map's authored endpoints, use a drawmethod override. See [[Mesh Map#Depth Range Override|Depth Range Override]]. | |||
==== Geometry Samples ==== | ==== 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.<syntaxhighlight lang="c"> | 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. | ||
<syntaxhighlight lang="c"> | |||
int sample = get_meshmap_property(maps, id, | int sample = get_meshmap_property(maps, id, | ||
openborconstant("MESHMAP_PROPERTY_SAMPLE"), 10, 4); | openborconstant("MESHMAP_PROPERTY_SAMPLE"), 10, 4); | ||
| Line 642: | Line 1,201: | ||
set_meshmap_property(maps, id, | set_meshmap_property(maps, id, | ||
openborconstant("MESHMAP_PROPERTY_SAMPLE"), 0, 10, 4); | openborconstant("MESHMAP_PROPERTY_SAMPLE"), 0, 10, 4); | ||
</syntaxhighlight>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 [[Mesh Map#Cells and Holes|Cells and Holes]]. | </syntaxhighlight> | ||
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 [[Mesh Map#Cells and Holes|Cells and Holes]]. | |||
==== Surface Queries ==== | ==== 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.<syntaxhighlight lang="c"> | 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. | ||
<syntaxhighlight lang="c"> | |||
get_meshmap_property(collection, id, property, world_x, world_y, world_z); | get_meshmap_property(collection, id, property, world_x, world_y, world_z); | ||
</syntaxhighlight>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. | </syntaxhighlight> | ||
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 <code>MESHMAP_PROPERTY_</code>: | Prefix each property below with <code>MESHMAP_PROPERTY_</code>: | ||
| Line 669: | Line 1,233: | ||
|Triangle index within the sampled cell. | |Triangle index within the sampled cell. | ||
|} | |} | ||
All surface properties are read-only. Properties other than <code>SURFACE_PRESENT</code> return <code>NULL()</code> 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.<syntaxhighlight lang="c"> | All surface properties are read-only. Properties other than <code>SURFACE_PRESENT</code> return <code>NULL()</code> 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. | ||
<syntaxhighlight lang="c"> | |||
if(get_meshmap_property(maps, id, | if(get_meshmap_property(maps, id, | ||
openborconstant("MESHMAP_PROPERTY_SURFACE_PRESENT"), x, 0, z)) | openborconstant("MESHMAP_PROPERTY_SURFACE_PRESENT"), x, 0, z)) | ||
| Line 676: | Line 1,241: | ||
openborconstant("MESHMAP_PROPERTY_SURFACE_Y"), x, 0, z); | openborconstant("MESHMAP_PROPERTY_SURFACE_Y"), x, 0, z); | ||
} | } | ||
</syntaxhighlight>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. | </syntaxhighlight> | ||
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 ==== | ==== Remove or Disable a Map ==== | ||
| Line 687: | Line 1,254: | ||
set_meshmap_property(maps, id, | set_meshmap_property(maps, id, | ||
openborconstant("MESHMAP_PROPERTY_EXISTS"), 0); | openborconstant("MESHMAP_PROPERTY_EXISTS"), 0); | ||
</syntaxhighlight>Removing a map does not automatically remove its empty ancestor banks. | </syntaxhighlight> | ||
Removing a map does not automatically remove its empty ancestor banks. Inactive maps remain accessible to script and can continue observing entry and exit. | |||
=== Bank Properties === | === Bank Properties === | ||
| Line 693: | Line 1,262: | ||
==== Get Bank Property ==== | ==== Get Bank Property ==== | ||
<syntaxhighlight lang="c"> | <syntaxhighlight lang="c"> | ||
get_meshmap_bank_property(collection, | get_meshmap_bank_property(collection, bank_type, prefix, property); | ||
get_meshmap_bank_property(collection, | get_meshmap_bank_property(collection, bank_type, prefix, property, slot); | ||
get_meshmap_bank_property(collection, bank_type, prefix, property, pool_id); | |||
</syntaxhighlight> | </syntaxhighlight> | ||
The additional argument is a child slot for <code>CHILD_PRESENT</code> and <code>CHILD_ACTIVE</code>, or an entity pool ID for <code>OCCUPANT</code>. Other bank properties do not accept an additional index. | |||
==== Set Bank Property ==== | ==== Set Bank Property ==== | ||
<syntaxhighlight lang="c"> | <syntaxhighlight lang="c"> | ||
set_meshmap_bank_property(collection, | set_meshmap_bank_property(collection, bank_type, prefix, property, value); | ||
set_meshmap_bank_property(collection, | set_meshmap_bank_property(collection, bank_type, prefix, property, value, slot); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Pass one of <code>MESHMAP_BANK_LEVEL</code>, <code>MESHMAP_BANK_AREA</code>, <code>MESHMAP_BANK_SECTOR</code>, <code>MESHMAP_BANK_ROOM</code>, or <code>MESHMAP_BANK_MESH</code> as <code>bank_type</code>, using <code>openborconstant()</code>. The argument is a bank type flag, not a numerical hierarchy depth. <code>MESHMAP_BANK_NONE</code>, combined flags, and unknown selectors are invalid. | |||
<code>prefix</code> is a full-format mesh map ID identifying the desired path. Address components below the selected owner are ignored. Use <code>MESHMAP_BANK_LEVEL</code> and prefix <code>0</code> for the collection root. For <code>MESHMAP_BANK_MESH</code>, the complete ID selects the individual mesh. The additional slot argument for <code>CHILD_ACTIVE</code> follows the value in the setter. | |||
For example, prefix <code>270532</code> represents 1/2/3/4. With <code>MESHMAP_BANK_AREA</code> it selects area 1; with <code>MESHMAP_BANK_SECTOR</code> it selects sector 1/2; with <code>MESHMAP_BANK_ROOM</code> it selects room 1/2/3; with <code>MESHMAP_BANK_MESH</code> it selects mesh 1/2/3/4. See [[Mesh Map#Banks|Banks]]. | |||
==== Bank Property Reference ==== | ==== Bank Property Reference ==== | ||
| Line 716: | Line 1,294: | ||
|<code>DEPTH</code> | |<code>DEPTH</code> | ||
|Read | |Read | ||
| | |Selected <code>MESHMAP_BANK_*</code> type flag. The result can be reused as <code>bank_type</code>. | ||
|- | |- | ||
|<code>PRESENT_MASK</code> | |<code>PRESENT_MASK</code> | ||
|Read | |Read | ||
|Opaque selection of all existing immediate children. | |Opaque selection of all existing immediate children. Container banks only. | ||
|- | |- | ||
|<code>ACTIVE_MASK</code> | |<code>ACTIVE_MASK</code> | ||
|Read/Write | |Read/Write | ||
|Opaque selection of locally active immediate children. Use a returned selection or <code>MESHMAP_BANK_MASK_NONE</code>. | |Opaque selection of locally active immediate children. Use a returned selection or <code>MESHMAP_BANK_MASK_NONE</code>. Container banks only. | ||
|- | |- | ||
|<code>CHILD_PRESENT</code> | |<code>CHILD_PRESENT</code> | ||
|Read | |Read | ||
|Presence of an immediate child at the additional slot argument. | |Presence of an immediate child at the additional slot argument. Container banks only. | ||
|- | |- | ||
|<code>CHILD_ACTIVE</code> | |<code>CHILD_ACTIVE</code> | ||
|Read/Write | |Read/Write | ||
|Local active state (0/1) of an immediate child at the additional slot argument. | |Local active state (0/1) of an immediate child at the additional slot argument. Container banks only. | ||
|- | |- | ||
|<code>CHILD_COUNT</code> | |<code>CHILD_COUNT</code> | ||
|Read | |Read | ||
|Number of existing immediate children. | |Number of existing immediate children. Container banks only. | ||
|- | |- | ||
|<code>GATE_ENABLED</code> | |<code>GATE_ENABLED</code> | ||
| Line 749: | Line 1,327: | ||
|Read/Write | |Read/Write | ||
|World-space gate bounds. | |World-space gate bounds. | ||
|- | |||
|<code>SCRIPT_ENTER</code>, <code>SCRIPT_EXIT</code> | |||
|Read/Write | |||
|Handler script paths. Assign a path to load or replace a handler; assign <code>NULL()</code> or an empty string to remove it. | |||
|- | |||
|<code>OCCUPANT_COUNT</code> | |||
|Read | |||
|Current number of entities observed inside the owner's range. Requires an entry or exit handler. | |||
|- | |||
|<code>OCCUPANT</code> | |||
|Read | |||
|Membership as 0 or 1. Supply the entity pool ID as the additional argument. | |||
|- | |||
|<code>GENERATION</code> | |||
|Read | |||
|Owner allocation identity. Changes when a removed owner is recreated. | |||
|} | |} | ||
Removing the root clears | Removing the <code>MESHMAP_BANK_LEVEL</code> root clears its children, bounds, and handlers while preserving the collection handle with a new root generation. Removing an area, sector, or room also removes all its descendants. Removing <code>MESHMAP_BANK_MESH</code> removes only that mesh. Except for <code>EXISTS</code>, bank properties require the bank to exist. The immediate-child active getter reports local state; use the map's <code>ENABLED</code> property to inspect effective activation through its ancestry. | ||
The mesh selector supports the common owner properties: presence, type, bounds, entry and exit handlers, occupancy, and generation. Child masks, counts, and slot operations apply only to level, area, sector, and room banks. Use <code>MESHMAP_PROPERTY_SCRIPT_BLOCK</code> through the map API for a mesh's blocking handler. | |||
==== Change an Individual Child ==== | ==== Change an Individual Child ==== | ||
Disable area 1 while preserving all other areas' local active states:<syntaxhighlight lang="c"> | Disable area 1 while preserving all other areas' local active states: | ||
if(get_meshmap_bank_property(maps, | <syntaxhighlight lang="c"> | ||
if(get_meshmap_bank_property(maps, openborconstant("MESHMAP_BANK_LEVEL"), 0, | |||
openborconstant("MESHMAP_BANK_PROPERTY_CHILD_PRESENT"), 1)) | openborconstant("MESHMAP_BANK_PROPERTY_CHILD_PRESENT"), 1)) | ||
{ | { | ||
set_meshmap_bank_property(maps, | set_meshmap_bank_property(maps, openborconstant("MESHMAP_BANK_LEVEL"), 0, | ||
openborconstant("MESHMAP_BANK_PROPERTY_CHILD_ACTIVE"), 0, 1); | openborconstant("MESHMAP_BANK_PROPERTY_CHILD_ACTIVE"), 0, 1); | ||
} | } | ||
| Line 763: | Line 1,360: | ||
==== Enable All Existing Children ==== | ==== Enable All Existing Children ==== | ||
Assign the bank's present selection to its active selection:<syntaxhighlight lang="c"> | Assign the bank's present selection to its active selection: | ||
set_meshmap_bank_property(maps, | <syntaxhighlight lang="c"> | ||
set_meshmap_bank_property(maps, openborconstant("MESHMAP_BANK_LEVEL"), 0, | |||
openborconstant("MESHMAP_BANK_PROPERTY_ACTIVE_MASK"), | openborconstant("MESHMAP_BANK_PROPERTY_ACTIVE_MASK"), | ||
get_meshmap_bank_property(maps, | get_meshmap_bank_property(maps, openborconstant("MESHMAP_BANK_LEVEL"), 0, | ||
openborconstant("MESHMAP_BANK_PROPERTY_PRESENT_MASK"))); | openborconstant("MESHMAP_BANK_PROPERTY_PRESENT_MASK"))); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==== Save and Restore Active Selection ==== | ==== 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.<syntaxhighlight lang="c"> | 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, | <syntaxhighlight lang="c"> | ||
void saved_selection = get_meshmap_bank_property(maps, openborconstant("MESHMAP_BANK_LEVEL"), 0, | |||
openborconstant("MESHMAP_BANK_PROPERTY_ACTIVE_MASK")); | openborconstant("MESHMAP_BANK_PROPERTY_ACTIVE_MASK")); | ||
/* Disable all areas. */ | /* Disable all areas. */ | ||
set_meshmap_bank_property(maps, | set_meshmap_bank_property(maps, openborconstant("MESHMAP_BANK_LEVEL"), 0, | ||
openborconstant("MESHMAP_BANK_PROPERTY_ACTIVE_MASK"), | openborconstant("MESHMAP_BANK_PROPERTY_ACTIVE_MASK"), | ||
openborconstant("MESHMAP_BANK_MASK_NONE")); | openborconstant("MESHMAP_BANK_MASK_NONE")); | ||
/* Restore the previous selection while its children still exist. */ | /* Restore the previous selection while its children still exist. */ | ||
set_meshmap_bank_property(maps, | set_meshmap_bank_property(maps, openborconstant("MESHMAP_BANK_LEVEL"), 0, | ||
openborconstant("MESHMAP_BANK_PROPERTY_ACTIVE_MASK"), | openborconstant("MESHMAP_BANK_PROPERTY_ACTIVE_MASK"), | ||
saved_selection); | saved_selection); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Handler Assignment and Membership === | |||
Handler properties read the assigned path, or an empty string when unassigned, and accept a replacement path. Set <code>NULL()</code> or an empty string to remove a handler. The special word <code>none</code> belongs to level text; the script string <code>"none"</code> is treated as a file path. Replacement loads and compiles the script before replacing the current handler; a failed replacement preserves the current assignment. | |||
The following assigns room handlers through script. Room 1/2/3 must already exist: | |||
<syntaxhighlight lang="c"> | |||
int bank = openborconstant("MESHMAP_BANK_ROOM"); | |||
int prefix = 1 * 262144 + 2 * 4096 + 3 * 64; | |||
set_meshmap_bank_property(maps, bank, prefix, | |||
openborconstant("MESHMAP_BANK_PROPERTY_SCRIPT_ENTER"), | |||
"data/scripts/terrain/room_enter.c"); | |||
set_meshmap_bank_property(maps, bank, prefix, | |||
openborconstant("MESHMAP_BANK_PROPERTY_SCRIPT_EXIT"), | |||
"data/scripts/terrain/room_exit.c"); | |||
</syntaxhighlight> | |||
For individual mesh handlers: | |||
<syntaxhighlight lang="c"> | |||
set_meshmap_property(maps, id, | |||
openborconstant("MESHMAP_PROPERTY_SCRIPT_BLOCK"), | |||
"data/scripts/terrain/mesh_block.c"); | |||
/* Remove only this mesh's blocking handler. */ | |||
set_meshmap_property(maps, id, | |||
openborconstant("MESHMAP_PROPERTY_SCRIPT_BLOCK"), NULL()); | |||
</syntaxhighlight> | |||
Use an entity's pool ID to query observed membership. The following assumes <code>entity</code> is a live entity and the selected room exists with an entry or exit handler: | |||
<syntaxhighlight lang="c"> | |||
int pool_id = get_entity_property(entity, | |||
openborconstant("ENTITY_PROPERTY_POOL_ID")); | |||
int inside_room = get_meshmap_bank_property(maps, bank, prefix, | |||
openborconstant("MESHMAP_BANK_PROPERTY_OCCUPANT"), pool_id); | |||
int room_count = get_meshmap_bank_property(maps, bank, prefix, | |||
openborconstant("MESHMAP_BANK_PROPERTY_OCCUPANT_COUNT")); | |||
</syntaxhighlight> | |||
The equivalent mesh queries are: | |||
<syntaxhighlight lang="c"> | |||
int inside_mesh = get_meshmap_property(maps, id, | |||
openborconstant("MESHMAP_PROPERTY_OCCUPANT"), pool_id); | |||
int mesh_count = get_meshmap_property(maps, id, | |||
openborconstant("MESHMAP_PROPERTY_OCCUPANT_COUNT")); | |||
</syntaxhighlight> | |||
Membership and counts report the currently observed state, which can be later than a queued event's snapshot. Only owners with an entry or exit handler maintain membership. With neither handler, these queries return zero; a blocking handler alone does not enable range tracking. See [[Mesh Map#Occupancy and Loading|Occupancy and Loading]]. | |||
=== Diagnostic Output === | === Diagnostic Output === | ||
Use the common <code>PROPERTY_ACCESS_DUMP</code> constant to log information about a map or bank. Bank diagnostics list ordinary child-slot indices rather than numerical masks.<syntaxhighlight lang="c"> | Use the common <code>PROPERTY_ACCESS_DUMP</code> constant to log information about a map or bank. Bank diagnostics list ordinary child-slot indices rather than numerical masks. | ||
<syntaxhighlight lang="c"> | |||
get_meshmap_property(maps, id, | get_meshmap_property(maps, id, | ||
openborconstant("PROPERTY_ACCESS_DUMP")); | openborconstant("PROPERTY_ACCESS_DUMP")); | ||
get_meshmap_bank_property(maps, | get_meshmap_bank_property(maps, openborconstant("MESHMAP_BANK_LEVEL"), 0, | ||
openborconstant("PROPERTY_ACCESS_DUMP")); | openborconstant("PROPERTY_ACCESS_DUMP")); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Entity Properties === | === Entity Properties === | ||
Mesh movement configuration and contact information are accessible through the existing entity property functions:<syntaxhighlight lang="c"> | Mesh movement configuration and contact information are accessible through the existing entity property functions: | ||
<syntaxhighlight lang="c"> | |||
get_entity_property(entity, property); | get_entity_property(entity, property); | ||
set_entity_property(entity, property, value); | set_entity_property(entity, property, value); | ||
</syntaxhighlight>Prefix each property below with <code>ENTITY_PROPERTY_MESHMAP_</code>. | </syntaxhighlight> | ||
Prefix each property below with <code>ENTITY_PROPERTY_MESHMAP_</code>. | |||
{| class="wikitable" | {| class="wikitable" | ||
!Property | !Property | ||
| Line 846: | Line 1,497: | ||
|} | |} | ||
Read <code>SUPPORT_ID</code> or <code>DROP_ID</code> before using the corresponding recorded contact altitude. See [[Mesh Map#Entity Movement|Entity Movement]] for the behavior of these properties. | Read <code>SUPPORT_ID</code> or <code>DROP_ID</code> before using the corresponding recorded contact altitude. See [[Mesh Map#Entity Movement|Entity Movement]] for the behavior of these properties. | ||
==== Entity Pool ID ==== | |||
<syntaxhighlight lang="c"> | |||
int pool_id = get_entity_property(entity, | |||
openborconstant("ENTITY_PROPERTY_POOL_ID")); | |||
</syntaxhighlight> | |||
<code>ENTITY_PROPERTY_POOL_ID</code> is a read-only identifier for the entity's allocation slot. Its value stays stable when the active entity list is sorted or compacted. It is separate from the active-list index and from the entity's lifetime identity. | |||
Mesh event membership uses one bit per stable pool slot. Pass the pool ID to a map or bank <code>OCCUPANT</code> query. Unregistered entity objects use <code>ENTITY_POOL_ID_NONE</code>. | |||
When OpenBOR reuses an allocation for another entity, that allocation retains its pool ID while the spawned entity receives a different <code>ENTITY_PROPERTY_UNIQUE_ID</code>. Use the unique ID as well when retaining records across entity lifetimes. Event locals include both values captured when the event was recorded, and membership for the previous occupant is cleared before the slot is reused. | |||
== Rendering == | == Rendering == | ||
=== Automatic Drawing === | === Automatic Drawing === | ||
By default, a mesh map configured with <code>draw</code> 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:<syntaxhighlight lang="text"> | By default, a mesh map configured with <code>draw</code> 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: | ||
<syntaxhighlight lang="text"> | |||
screen_x = world_x - screenx + gfx_x_offset | screen_x = world_x - screenx + gfx_x_offset | ||
screen_y = world_z - world_y - screeny + gfx_y_offset | screen_y = world_z - world_y - screeny + gfx_y_offset | ||
</syntaxhighlight>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. | </syntaxhighlight> | ||
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 === | === Script Drawing === | ||
| Line 866: | Line 1,532: | ||
draw_meshmap(collection, id, target_screen, drawmethod); | draw_meshmap(collection, id, target_screen, drawmethod); | ||
draw_meshmap(collection, id, target_screen, drawmethod, offset_x, offset_y); | draw_meshmap(collection, id, target_screen, drawmethod, offset_x, offset_y); | ||
</syntaxhighlight>Draw the selected map immediately into the destination screen using the ordinary projection <code>X</code>, <code>Z - Y</code>, plus optional screen-space offsets. Supply both offsets or neither. The default offsets are zero. | </syntaxhighlight> | ||
Draw the selected map immediately into the destination screen using the ordinary projection <code>X</code>, <code>Z - Y</code>, plus optional screen-space offsets. Supply both offsets or neither. The default offsets are zero. | |||
==== draw_meshmap_projected() ==== | ==== draw_meshmap_projected() ==== | ||
| Line 874: | Line 1,542: | ||
m10, m11, m12, m13, | m10, m11, m12, m13, | ||
m20, m21, m22, m23, near_w); | m20, m21, m22, m23, near_w); | ||
</syntaxhighlight>Draw the selected map immediately into the destination screen using a custom three-row, four-column view matrix. The last argument, <code>near_w</code>, is optional and defaults to <code>0.0001</code>. All coefficients must be finite, and the near value must be positive. | </syntaxhighlight> | ||
Draw the selected map immediately into the destination screen using a custom three-row, four-column view matrix. The last argument, <code>near_w</code>, is optional and defaults to <code>0.0001</code>. 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:<syntaxhighlight lang="text"> | The coefficients are supplied in row-major order and transform world coordinates into homogeneous screen coordinates: | ||
<syntaxhighlight lang="text"> | |||
sx = m00 * X + m01 * Y + m02 * Z + m03 | sx = m00 * X + m01 * Y + m02 * Z + m03 | ||
sy = m10 * X + m11 * Y + m12 * Z + m13 | sy = m10 * X + m11 * Y + m12 * Z + m13 | ||
| Line 883: | Line 1,554: | ||
screen_x = sx / w | screen_x = sx / w | ||
screen_y = sy / w | screen_y = sy / w | ||
</syntaxhighlight>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. | </syntaxhighlight> | ||
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 ===== | ===== 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.<syntaxhighlight lang="c"> | 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. | ||
<syntaxhighlight lang="c"> | |||
draw_meshmap_projected(maps, id, surface, NULL(), | draw_meshmap_projected(maps, id, surface, NULL(), | ||
1, 0, 0, offset_x, | 1, 0, 0, offset_x, | ||
| Line 894: | Line 1,568: | ||
===== Perspective Projection ===== | ===== Perspective Projection ===== | ||
For a camera looking along increasing Z, calculate the view from its world position, focal length, and the intended screen center:<syntaxhighlight lang="text"> | For a camera looking along increasing Z, calculate the view from its world position, focal length, and the intended screen center: | ||
<syntaxhighlight lang="text"> | |||
sx = focal * (X - camera_x) + center_x * (Z - camera_z) | sx = focal * (X - camera_x) + center_x * (Z - camera_z) | ||
sy = focal * (camera_y - Y) + center_y * (Z - camera_z) | sy = focal * (camera_y - Y) + center_y * (Z - camera_z) | ||
w = Z - camera_z | w = Z - camera_z | ||
</syntaxhighlight>For example, assume the Y-axis ground terrain from [[Mesh Map#Ground Terrain|Ground Terrain]] is at ID 0. Disable its automatic drawing during setup:<syntaxhighlight lang="c"> | </syntaxhighlight> | ||
For example, assume the Y-axis ground terrain from [[Mesh Map#Ground Terrain|Ground Terrain]] is at ID 0. Disable its automatic drawing during setup: | |||
<syntaxhighlight lang="c"> | |||
set_meshmap_property(maps, 0, | set_meshmap_property(maps, 0, | ||
openborconstant("MESHMAP_PROPERTY_DRAW"), 0); | openborconstant("MESHMAP_PROPERTY_DRAW"), 0); | ||
</syntaxhighlight>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).<syntaxhighlight lang="c"> | </syntaxhighlight> | ||
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). | |||
<syntaxhighlight lang="c"> | |||
void main() | void main() | ||
{ | { | ||
| Line 924: | Line 1,605: | ||
drawscreen(surface, 0, 0, 100); | drawscreen(surface, 0, 0, 100); | ||
} | } | ||
</syntaxhighlight>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. | </syntaxhighlight> | ||
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. | |||
=== Explicit Depth Composition === | |||
Use an explicit depth pass when composing several immediate draws into a script-owned RGB32 screen: | |||
<syntaxhighlight lang="c"> | |||
begin_draw_depth(target_screen, minimum_z, maximum_z); | |||
set_draw_depth(drawing_z); | |||
end_draw_depth(target_screen); | |||
</syntaxhighlight> | |||
The range must be finite, with <code>minimum_z</code> less than <code>maximum_z</code>, and must contain the final drawing-Z values used by the pass, including depth-image adjustments. Beginning a pass clears the target's transient depth data while preserving its color. End the pass on the same target after the immediate drawing operations have finished. | |||
Each immediate mesh draw supplies its current <code>LAYER</code> property as its baseline. <code>set_draw_depth()</code> selects the baseline for other immediate drawing operations; it does not replace the baseline selected by <code>draw_meshmap()</code> or <code>draw_meshmap_projected()</code>. | |||
For example, assume two existing textured maps have IDs <code>floor_id</code> and <code>wall_id</code>, their final drawing-Z values fit within -128 through 128, and <code>surface</code> is a script-owned RGB32 screen: | |||
<syntaxhighlight lang="c"> | |||
clearscreen(surface); | |||
if(begin_draw_depth(surface, -128, 128)) | |||
{ | |||
draw_meshmap(maps, floor_id, surface, NULL()); | |||
draw_meshmap(maps, wall_id, surface, NULL()); | |||
end_draw_depth(surface); | |||
} | |||
</syntaxhighlight> | |||
These functions return <code>1</code> for success or <code>0</code> when the depth operation is unavailable or does not match the active pass. Invalid arguments report script errors. Native queued scene drawing manages its depth pass automatically; this explicit pass is for immediate screen composition. | |||
=== Depth Range Override === | |||
The drawmethod <code>DM_DEPTH_RANGE</code> property replaces a depth image's adjustment pair for that drawing operation. The override requires an enabled drawmethod and a depth image. Assigning the property does not itself enable a disabled drawmethod. | |||
With an existing enabled drawmethod handle named <code>method</code>: | |||
<syntaxhighlight lang="c"> | |||
set_draw_method(method, openborconstant("DM_DEPTH_RANGE"), -48, 48); | |||
/* Use this material for the mesh within the active depth pass. */ | |||
draw_meshmap(maps, id, surface, method); | |||
/* Return to the companion image's authored range. */ | |||
set_draw_method(method, openborconstant("DM_DEPTH_RANGE"), NULL()); | |||
</syntaxhighlight> | |||
Pass the intended drawmethod handle to the mesh drawing function. Passing <code>NULL()</code> as its drawmethod selects the plain material; it does not inherit the common script drawmethod. | |||
The range getter uses the following component constants: | |||
{| class="wikitable" | |||
!Component | |||
!Result | |||
|- | |||
|<code>DM_DEPTH_SAMPLE_MIN</code> | |||
|Override adjustment for grayscale sample 0, or <code>NULL()</code> when inheriting. | |||
|- | |||
|<code>DM_DEPTH_SAMPLE_MAX</code> | |||
|Override adjustment for grayscale sample 65535, or <code>NULL()</code> when inheriting. | |||
|- | |||
|<code>DM_DEPTH_INHERIT</code> | |||
|1 when using the companion's authored range, or 0 when overriding it. | |||
|} | |||
For example: | |||
<syntaxhighlight lang="c"> | |||
int inherits = get_draw_method(method, | |||
openborconstant("DM_DEPTH_RANGE"), | |||
openborconstant("DM_DEPTH_INHERIT")); | |||
void sample_min = get_draw_method(method, | |||
openborconstant("DM_DEPTH_RANGE"), | |||
openborconstant("DM_DEPTH_SAMPLE_MIN")); | |||
void sample_max = get_draw_method(method, | |||
openborconstant("DM_DEPTH_RANGE"), | |||
openborconstant("DM_DEPTH_SAMPLE_MAX")); | |||
</syntaxhighlight> | |||
<code>MIN</code> and <code>MAX</code> name the grayscale sample endpoints, so the adjustment pair can still be reversed. The map's own endpoint getters remain <code>MESHMAP_PROPERTY_DEPTH_ADJUST0</code> and <code>MESHMAP_PROPERTY_DEPTH_ADJUST65535</code>. See [[Drawmethod]] for general drawmethod configuration. | |||
=== Draw Ordering === | === Draw Ordering === | ||
Mesh maps | Mesh maps retain their configured drawing layer as the baseline for ordering. When a drawing depth image is attached, the GPU adds its sampled adjustment to that baseline and compares the resulting drawing Z with other pixels in the same depth pass. Greater drawing Z takes precedence; equal values retain the established draw order. | ||
Native queued sprites, screens, and mesh maps participate in this comparison automatically when a depth companion is present. Ordinary entries within the affected drawing-Z range participate as well. Immediate scripted composition uses an explicit depth pass; without one, immediate draws follow their ordinary submission order. Opaque pixels and fully covered cutouts test and write depth. Partially covered or blended pixels test depth while retaining ordered composition. | |||
Custom projection controls screen position and perspective texture sampling. Mesh geometry and the view matrix do not automatically supply camera-distance depth. Authored drawing-depth values control per-pixel ordering. | |||
== Design Considerations == | == Design Considerations == | ||
| Line 934: | Line 1,689: | ||
* Use mesh maps for detailed static terrain and the existing entity systems for moving platforms, destructible objects, and other independently interactive elements. | * 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. | * 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; | * Organize large terrain sets into useful areas, sectors, and rooms with appropriately overlapping applicability bounds. Bounds help reject irrelevant collision geometry. Entry and exit handlers can activate, load, or release terrain under creator control; bounds alone do not clip rendering or load 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. | * 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 == | == See Also == | ||
* [ | * [[Drawmethod]] - Drawing configuration and per-pixel depth controls. | ||
* [[Time]] - Logical timing for scripted behavior. | |||
[[Category:Level]] | [[Category:Level]] | ||
[[Category:OpenBOR Index]] | [[Category:OpenBOR Index]] | ||
Latest revision as of 00:35, 29 November 2026
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. Optional artwork supplies the visual texture, and a separate drawing depth mask can adjust its per-pixel drawing priority. 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. Banks and individual meshes can also own entry and exit handlers, while meshes can respond to blocking contacts. These events support encounters, environmental effects, and creator-controlled terrain loading.
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. RGB images that appear gray, indexed images, 8-bit grayscale images, and grayscale images with an alpha channel do 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) / 65534For 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_vFor 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: One 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.
Drawing Depth Images
Mesh artwork can have a companion 16-bit grayscale PNG that adjusts drawing priority per pixel. Use it when different portions of one textured surface should pass in front of or behind entities and other scene elements.
The image must contain a single 16-bit grayscale channel, with dimensions matching the visual texture canvas. It does not need to match the geometry grid. Each sample supplies a signed adjustment to the mesh's drawing layer:
adjustment = adjust_0 + (sample / 65535.0) * (adjust_65535 - adjust_0)
pixel_drawing_z = meshmap_layer + adjustmentGreater drawing Z takes precedence. The two adjustments may be fractional, equal, or reversed. They describe the results at sample 0 and sample 65535, rather than a required low-to-high ordering of adjustment values.
Unlike geometry data, drawing depth uses the complete range from 0 through 65535. Sample 0 is valid depth information and does not create a hole. The default range used when script omits the endpoints is -32768 through +32767, giving a direct one-for-one adjustment:
adjustment = sample - 32768With that range, sample 32768 makes no adjustment. Lower values move the pixel's drawing priority backward and higher values move it forward. Level text supplies the endpoint adjustments explicitly through meshmap_depth.
Depth images affect drawing priority only. They do not change collision geometry, displace texture coordinates, remove geometry, or supply artwork for the other side of a surface. Use the geometry image to shape terrain and the drawing depth image to control how its artwork overlaps other drawing. See Draw Ordering and Drawmethod.
Mesh Map Collection
The mesh map collection belongs to the current level. It uses four address components:
Area
Sector
Room
Mesh MapEach 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
The level collection, each area, each sector, and each room form banks in the hierarchy. Each bank manages its immediate children. Commands also accept the individual mesh as an owner for bounds, entry and exit handlers, and common node properties.
Select the owner by name in level text and by its named constant in script:
| Level text | Script constant | Selected owner | Immediate children |
|---|---|---|---|
level
|
MESHMAP_BANK_LEVEL
|
Current level's collection root. | Areas. |
area
|
MESHMAP_BANK_AREA
|
Selected area. | Sectors. |
sector
|
MESHMAP_BANK_SECTOR
|
Selected sector within its area. | Rooms. |
room
|
MESHMAP_BANK_ROOM
|
Selected room within its area and sector. | Mesh maps. |
mesh
|
MESHMAP_BANK_MESH
|
Selected individual mesh map. | None. |
Names are case-insensitive. Level text requires these names rather than numeric depth selectors. Script constants are distinct bit flags, but each bank operation takes exactly one owner type. MESHMAP_BANK_NONE represents no selection and is not a valid target; combined flags are not valid targets either.
The selector names the owner being addressed. For example, meshmap_mask area slots 2 selects sector 2 within the current area. Use meshmap_mask level slots 2 to select area 2 within the level. The mesh owner has no children and does not accept child-selection operations.
Each existing child has a local 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 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.
Entry and exit observation is independent of these active states. Existing inactive banks and meshes can still detect an entity entering their bounds, allowing its handler to activate or load terrain. See Events.
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 one enclosing world-space box around the active frame's valid body boxes, accounting for facing. If no valid active boxes are available, it falls back to model width and entity height with no Z thickness. Collision admission tests use the current state, rather than a predicted position or the volume swept during movement. Allow enough overlap between neighboring bounds to accommodate the game's movement speeds and transitions. Entry and exit observation also follows committed movement through the bounds, so crossing a complete region within one update can produce both events. See Range Detection.
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 at that node, subject to their ancestors' bounds. Repositioning a mesh map does not move its authored bounds. Bounds are independent of geometry dimensions: loading or replacing a geometry image does not define an event detection range.
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 0Select 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 0Set 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 noneAssign 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.
Drawing Depth
meshmap_depth {decimal adjust_0} {decimal adjust_65535} {path image}
meshmap_depth noneAssign a drawing depth image to the selected map. The two signed adjustments apply to samples 0 and 65535, respectively. Both endpoints are required when supplying an image in level text. Use none to remove the depth companion.
For example:
meshmap_index 0 0 0 2
meshmap_texture data/terrain/wall.png
meshmap_depth -24 24 data/terrain/wall_depth16.pngThe depth image must be 16-bit grayscale and match the texture's pixel dimensions. Texture and depth may be declared in either order. Removing the texture retains the separately assigned depth image. Failed loads or replacements with incompatible dimensions preserve the existing resources.
See Drawing Depth Images for sample interpretation and Depth Range Override for adjusting the range during scripted drawing.
Spacing
meshmap_spacing {decimal u} {decimal v}
# Default
meshmap_spacing 1 1Set 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 walkableConfiguration 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.
See Automatic Drawing and One-Way Platforms for additional behavior.
Side
meshmap_side {int side}
# Default
meshmap_side 0Select 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 4294967295Assign 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 45Set 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 0Set the map's drawing layer. This signed integer supplies its baseline drawing Z, independently of the map's XYZ position. Native queued drawing uses it for ordering. Immediate draw_meshmap() and draw_meshmap_projected() calls also use the map's current layer within an explicit depth pass. Drawing depth images add their per-pixel adjustments to this baseline.
Active
meshmap_active {int enabled}
# Default
meshmap_active 1Set 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 {bank_type} {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 bounds of the specified owner. bank_type accepts level, area, sector, room, or mesh. The selected meshmap_index supplies the applicable address components; level always selects the current collection root. The command creates the selected owner if necessary. Coordinate and gate-mode rules are the same as meshmap_bounds.
For example:
meshmap_index 1 2 3 4
# Bounds for the complete collection.
meshmap_bank level -1024 -512 -1024 8192 2048 8192
# Bounds for room 1/2/3.
meshmap_bank room 0 -128 0 1024 512 256
# Bounds for mesh 1/2/3/4.
meshmap_bank mesh 128 -64 32 512 256 224meshmap_bank area, sector, and room are equivalent to meshmap_area, meshmap_sector, and meshmap_room, respectively. meshmap_bank mesh is equivalent to meshmap_bounds. See Banks.
Bank Active Selection
meshmap_mask {bank_type} none
meshmap_mask {bank_type} all
meshmap_mask {bank_type} slots {int slot} [int slot ...]Replace the active selection of the specified bank. bank_type accepts level, area, sector, or room. The bank must already exist. The mesh selector is not valid because an individual mesh has no children.
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 level slots 0 2To enable sectors 0 and 2 within area 1 instead, select that area and address its bank:
meshmap_index 1 0 0 0
meshmap_mask area slots 0 2These commands change activation while retaining the existing resources. Supply slot indices directly rather than constructing a numerical bitmask. Entry and exit observation continues while children are inactive.
Mesh Event Handlers
meshmap_script_enter {path script}
meshmap_script_exit {path script}
meshmap_script_block {path script}Assign entry, exit, and blocking handlers to the individual mesh selected by meshmap_index. The default is no handler. Each command accepts none in place of the path to remove that handler:
meshmap_index 1 2 3 4
meshmap_script_enter data/scripts/terrain/mesh_enter.c
meshmap_script_exit data/scripts/terrain/mesh_exit.c
meshmap_script_block data/scripts/terrain/mesh_block.c
# Remove only the entry handler.
meshmap_script_enter noneEach assignment creates the selected mesh descriptor if needed. Entry and exit use authored bounds and do not require geometry; blocking events require actual mesh collision. See Events.
Bank Event Handlers
meshmap_bank_script_enter {bank_type} {path script}
meshmap_bank_script_exit {bank_type} {path script}Assign entry and exit handlers to the selected owner. bank_type accepts level, area, sector, room, or mesh. Use none instead of a script path to clear the corresponding handler. Names and none are case-insensitive.
The command creates an empty owner if needed. Banks can observe their bounds without containing any geometry or active children. meshmap_bank_script_enter mesh and meshmap_bank_script_exit mesh address the same handlers as meshmap_script_enter and meshmap_script_exit.
For example, the following attaches separate entry handlers at every hierarchy level along the selected path:
meshmap_index 1 2 3 4
meshmap_bank_script_enter level data/scripts/terrain/level_enter.c
meshmap_bank_script_enter area data/scripts/terrain/area_enter.c
meshmap_bank_script_enter sector data/scripts/terrain/sector_enter.c
meshmap_bank_script_enter room data/scripts/terrain/room_enter.c
meshmap_bank_script_enter mesh data/scripts/terrain/mesh_enter.cDefine bounds for each region that needs a limited detection range. Without enabled bounds, that owner admits every entity admitted by its ancestors. Blocking handlers belong to individual meshes and use meshmap_script_block.
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 -1000The 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 0The 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 1The 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. Entities 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. Falling entities may establish support on its eligible upper surface.
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 45The 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. Mesh-owned blocking handlers provide the mesh ID, contact kind, position, normal, and accepted movement for side contacts, ceilings, and landings. See Blocking Events.
Events
Banks and individual meshes can own scripts that respond when entities enter or leave their detection ranges. Individual meshes can also own a blocking script that responds to collision contacts. Handlers belong to the terrain owner and receive the triggering entity as self.
For example, a room can start an encounter when the first entity enters, a sector can load its terrain as entities approach, and a particular mesh can respond to a landing or wall contact. No handler is required on the entity's model.
Range Detection
Entry and exit use the owner's authored bounds together with every enabled ancestor bound. The entity must satisfy all of those gates, including bounds on ancestors without handlers. The detection range is independent of the geometry image, texture, and solid-side configuration. Overlapping owners observe their own ranges independently.
MESHMAP_GATE_POSITIONobserves the entity's reference position.MESHMAP_GATE_BODYobserves overlap with the current entity body box.- Disabled bounds impose no additional restriction at that node. Ancestor bounds still apply.
Define a finite range with meshmap_bank, one of the named bank-bound commands, or meshmap_bounds. Unbounded owners observe every entity admitted by their ancestors, even when their geometry covers only a small part of that area.
Range observation continues while a map or ancestor is inactive, while collision or drawing is disabled, while the entity has mesh collision disabled, and while a bank has no loaded children. This allows an entry handler on an empty room to load its terrain. Removing the room itself also removes its observer, so retain the room when it must detect a later return.
Committed movement is observed along its accepted path. Entities can enter and exit a narrow region during one update and produce both events even if they finish outside. Direct script position changes reconcile membership at the resulting position without treating the change as movement through every intervening region. Body-gated membership can also change when animation or facing changes the current body bounds.
Contact with a bound counts as inside. Merely touching a bound while passing between two outside positions, without an interval inside the region, does not produce a zero-duration visit.
Event Timing and Lifetime
Handlers execute after native entity updates, once the terrain traversal has finished. Scripts may change terrain, replace handlers, or remove an owner from within a callback. Events caused by those callbacks wait for a subsequent dispatch rather than interrupting the current callback batch.
Crossings along one movement segment are delivered in travel order. At the same point, exits precede entries. When several owners are entered at the same point, the outer owner enters first. When several owners are exited at the same point, the inner owner exits first. For example, simultaneous entry into an area, sector, room, and mesh reaches the area handler first; simultaneous exit reaches the mesh handler first.
Event locals describe the recorded transition. The entity may have moved farther by the time its handler executes, so use the event's x, y, and z when the crossing position matters. Query the entity when its current position is needed instead.
Queued events retain the handler assigned when they were recorded. Replacing a handler affects later events. Pending entry and blocking events are discarded if their owner or triggering entity no longer matches the recorded lifetime. Exit events retain their original owner and entity identity so cleanup can still run after removal.
Callback locals are cleared after the handler returns. Copy any values needed later into the game's own state.
The self local may be NULL() in an exit handler if the entity allocation has been removed or reused. The pointer may also refer to an entity whose active lifetime has ended. Use the captured pool_id, unique_id, entity_type, and playerindex for identity that must survive removal. Before changing an owner from a retained exit callback, confirm that it still exists and its generation matches the event. See Load Terrain on Entry.
Level teardown discards pending events. Use the level's teardown behavior for whole-level cleanup rather than relying on a final exit callback from every owner.
Blocking Events
meshmap_script_block responds to actual native movement contacts with that mesh. These include lateral obstruction, a ceiling stopping upward movement, and a mesh surface stopping downward movement. Speculative collision probes used by movement or AI do not call the handler. Successfully walking a slope or stepping onto terrain does not generate a block for an obstruction that the accepted route avoids.
The event identifies the blocking mesh and the obstructed movement axis. The axis local uses MESHMAP_AXIS_X, MESHMAP_AXIS_Y, or MESHMAP_AXIS_Z; it is not the mesh's displacement orientation. For example, a Z-oriented map can obstruct an entity's X movement or provide a Y landing in a side-view level.
The contact_kind local distinguishes:
| Constant | Contact |
|---|---|
MESHMAP_CONTACT_SIDE
|
Movement blocked laterally by terrain. |
MESHMAP_CONTACT_CEILING
|
Upward movement stopped by terrain overhead. |
MESHMAP_CONTACT_LANDING
|
Downward movement is stopped by a mesh surface. Check walkable when the response requires standing support.
|
The handler also receives the contact position, surface normal, requested movement, and accepted movement. Requested and accepted values are movement deltas, not destination coordinates. Repeated reporting of the same entity's landing on the same mesh within one logical tick is consolidated. Standing on a mesh does not continuously produce landing events. Repeated movement into an obstacle can produce repeated blocking events; this is a movement notification rather than a contact-entry/contact-exit pair.
Range callbacks report membership changes. Blocking callbacks report collision responses from participating meshes. Entering the bounds does not require touching the mesh geometry. The blocking callback reports a completed collision response; script changes affect subsequent behavior rather than canceling the reported result.
Handler Local Variables
Read callback values with getlocalvar("name"). Event kinds are MESHMAP_EVENT_ENTER, MESHMAP_EVENT_EXIT, and MESHMAP_EVENT_BLOCK, obtained through openborconstant().
Owner and Entity
| Local | Meaning |
|---|---|
self
|
Triggering entity, or NULL() when the original entity no longer occupies its pool slot. The retained entity can also have its existence flag cleared.
|
collection
|
Level-owned mesh collection handle. |
event
|
Event kind: enter, exit, or block. |
reason
|
Reason for the transition, using a MESHMAP_EVENT_REASON_* constant.
|
bank
|
Owner type using MESHMAP_BANK_LEVEL, AREA, SECTOR, ROOM, or MESH. See the complete constant names below.
|
scope
|
Owner scope using the corresponding MESHMAP_EVENT_SCOPE_* constant. This is separate from the bank selector.
|
id
|
Normalized packed owner prefix, or the complete map ID for a mesh. Components below a bank's scope are zero in this packed value. |
generation
|
Recorded allocation identity of the owner. |
area, sector, room, index
|
Owner address components. Components below the owner's scope are -1; all four are -1 for the level owner.
|
pool_id
|
Stable allocation slot of the triggering entity. |
unique_id
|
Identity of the triggering entity's particular lifetime. |
entity_type, playerindex
|
Entity classification and player index captured with the event. These remain available when self is unavailable.
|
Owner Constants
| Owner | bank
|
scope
|
|---|---|---|
| Level collection | MESHMAP_BANK_LEVEL
|
MESHMAP_EVENT_SCOPE_LEVEL
|
| Area | MESHMAP_BANK_AREA
|
MESHMAP_EVENT_SCOPE_AREA
|
| Sector | MESHMAP_BANK_SECTOR
|
MESHMAP_EVENT_SCOPE_SECTOR
|
| Room | MESHMAP_BANK_ROOM
|
MESHMAP_EVENT_SCOPE_ROOM
|
| Mesh | MESHMAP_BANK_MESH
|
MESHMAP_EVENT_SCOPE_MESH
|
Pass the callback's collection, bank, and id directly to the bank property functions for common owner properties, including mesh bounds, entry and exit handlers, occupancy, and generation. Use bank for that argument, not scope. Mesh-specific properties remain available through get_meshmap_property() and set_meshmap_property().
Range and Position
| Local | Meaning |
|---|---|
occupants_before, occupants_after
|
Observed membership counts immediately before and after this event's transition. Blocking events leave both counts equal; with only a blocking handler assigned, both are zero. |
x, y, z
|
Entity reference position recorded for the event. |
fraction
|
For a range crossing, a value from 0 through 1 locating the transition along that committed movement segment. Endpoint reconciliation uses 1; removal and observation-reconfiguration exits use 0. This is not elapsed time or a fraction of the whole update. Blocking events leave it at 0. |
Blocking Contact
The following locals describe blocking events. Range events leave these contact fields at zero; do not interpret them as contact information unless event is MESHMAP_EVENT_BLOCK.
| Local | Meaning |
|---|---|
axis
|
Obstructed world movement axis. |
contact_kind
|
MESHMAP_CONTACT_SIDE, MESHMAP_CONTACT_CEILING, or MESHMAP_CONTACT_LANDING.
|
contact_x, contact_y, contact_z
|
World-space contact position. |
normal_x, normal_y, normal_z
|
Components of the outward contact normal. |
requested_x, requested_y, requested_z
|
Requested movement deltas. |
accepted_x, accepted_y, accepted_z
|
Accepted movement deltas after collision resolution. |
boundary
|
1 for a finite-grid or hole-edge boundary contact; 0 for a sampled surface contact. |
walkable
|
Whether the reported contact qualifies as walkable support for this movement result. |
Transition Reasons
| Constant | Meaning |
|---|---|
MESHMAP_EVENT_REASON_UPDATE
|
Membership reconciled with current entity state. This includes ordinary direct script position changes, bounds or body changes observed during refresh, and newly installed observation. |
MESHMAP_EVENT_REASON_MOVE
|
Committed native movement, including blocking contacts. |
MESHMAP_EVENT_REASON_SPAWN
|
Membership established for a spawned entity. |
MESHMAP_EVENT_REASON_REMOVE
|
Entity or terrain owner removed from observation. |
MESHMAP_EVENT_REASON_RECONFIGURE
|
Existing membership retired when the final entry or exit handler is removed from an owner. Ordinary bounds edits use UPDATE when refreshed.
|
MESHMAP_EVENT_REASON_TELEPORT
|
Defined teleport reason identifier. Standard movement and position setters do not emit it. Direct script position assignments use endpoint reconciliation with UPDATE.
|
Occupancy and Loading
Owners with at least one entry or exit handler maintain observed membership. The engine tracks this in a lazily allocated bit table indexed by stable entity pool slot. Installing only a blocking handler does not enable range membership. Counts belong to each observed owner; they are not sums of descendant counts. Parents without a range handler can therefore report zero while one of their observed children has occupants.
Installing an entry or exit handler establishes membership during the next movement or membership refresh. Immediately querying occupancy after assignment can therefore still return zero. Replacing a handler while range observation remains enabled preserves existing membership. Removing the final range handler clears it; if the outgoing handler set includes an exit script, that script can receive retirement exits with reason MESHMAP_EVENT_REASON_RECONFIGURE.
Counts include all observed entities, not only players. Handlers can use entity_type, playerindex, or entity properties to choose which transitions should trigger game behavior. Such filtering does not change the owner's native occupancy count.
For an entry event, occupants_before == 0 identifies the first observed occupant at that transition. For an exit event, occupants_after == 0 identifies a transition to an empty region. These are historical values from the individual event. Multiple transitions can be waiting for their callbacks, and another entity may have entered before an earlier exit handler runs.
Before unloading terrain, check the owner's current OCCUPANT_COUNT and require it to be zero. Also check EXISTS and GENERATION before acting on an owner from an exit callback: its original owner may have been removed, or the same address may now identify a replacement. The following example applies all three checks.
Load Terrain on Entry
This example reserves mesh slot 0 in room 0/0/0. The room persists as a detection region while its terrain loads on entry and is removed when empty. It uses the trough geometry and artwork described in Ground Terrain.
Level header:
meshmap_index 0 0 0 0
meshmap_bank room -64 -128 -64 1088 512 320
meshmap_bank_script_enter room data/scripts/terrain/room_enter.c
meshmap_bank_script_exit room data/scripts/terrain/room_exit.cThe bounds extend beyond the terrain so detection can occur before an entity needs the terrain's collision. Choose that margin for the game's movement speeds and loading behavior.
data/scripts/terrain/room_enter.c:
void main()
{
void maps = getlocalvar("collection");
int bank = getlocalvar("bank");
int prefix = getlocalvar("id");
int map_id = prefix; // Mesh slot 0 in this room.
if(bank != openborconstant("MESHMAP_BANK_ROOM")) return;
if(!get_meshmap_bank_property(maps, bank, prefix,
openborconstant("MESHMAP_BANK_PROPERTY_EXISTS"))) return;
if(get_meshmap_bank_property(maps, bank, prefix,
openborconstant("MESHMAP_BANK_PROPERTY_GENERATION"))
!= getlocalvar("generation")) return;
if(get_meshmap_bank_property(maps, bank, prefix,
openborconstant("MESHMAP_BANK_PROPERTY_OCCUPANT_COUNT")) == 0) return;
if(get_meshmap_property(maps, map_id,
openborconstant("MESHMAP_PROPERTY_EXISTS"))) return;
set_meshmap_property(maps, map_id,
openborconstant("MESHMAP_PROPERTY_EXISTS"), 1);
set_meshmap_property(maps, map_id,
openborconstant("MESHMAP_PROPERTY_AXIS"),
openborconstant("MESHMAP_AXIS_Y"));
set_meshmap_property(maps, map_id,
openborconstant("MESHMAP_PROPERTY_MINIMUM"), -24);
set_meshmap_property(maps, map_id,
openborconstant("MESHMAP_PROPERTY_MAXIMUM"), 0);
set_meshmap_property(maps, map_id,
openborconstant("MESHMAP_PROPERTY_SPACING_U"), 16);
set_meshmap_property(maps, map_id,
openborconstant("MESHMAP_PROPERTY_SPACING_V"), 16);
set_meshmap_property(maps, map_id,
openborconstant("MESHMAP_PROPERTY_GEOMETRY"),
"data/terrain/trough16.png");
set_meshmap_property(maps, map_id,
openborconstant("MESHMAP_PROPERTY_ARTWORK"),
"data/terrain/road24.png");
set_meshmap_property(maps, map_id,
openborconstant("MESHMAP_PROPERTY_LAYER"), -1000);
}data/scripts/terrain/room_exit.c:
void main()
{
void maps = getlocalvar("collection");
int bank = getlocalvar("bank");
int prefix = getlocalvar("id");
int map_id = prefix; // Same reserved mesh slot 0.
if(bank != openborconstant("MESHMAP_BANK_ROOM")) return;
if(!get_meshmap_bank_property(maps, bank, prefix,
openborconstant("MESHMAP_BANK_PROPERTY_EXISTS"))) return;
if(get_meshmap_bank_property(maps, bank, prefix,
openborconstant("MESHMAP_BANK_PROPERTY_GENERATION"))
!= getlocalvar("generation")) return;
if(get_meshmap_bank_property(maps, bank, prefix,
openborconstant("MESHMAP_BANK_PROPERTY_OCCUPANT_COUNT")) != 0) return;
if(get_meshmap_property(maps, map_id,
openborconstant("MESHMAP_PROPERTY_EXISTS")))
{
set_meshmap_property(maps, map_id,
openborconstant("MESHMAP_PROPERTY_EXISTS"), 0);
}
}The exit handler removes the reserved mesh, leaving the room and its handlers available for a later return. Larger rooms can manage several reserved mesh slots in the same way. Loading only when resources are absent and checking current occupancy before release prevents repeated work for every entering entity and avoids unloading beneath an entity that has already entered.
Respond to a Landing
Assign this script with meshmap_script_block. It records landings on that mesh while ignoring side and ceiling contacts:
void main()
{
if(getlocalvar("contact_kind") !=
openborconstant("MESHMAP_CONTACT_LANDING")) return;
log("\nMesh landing: " + getlocalvar("id")
+ "; entity pool slot: " + getlocalvar("pool_id"));
}Replace the logging with the intended terrain response, such as a landing effect, a sound, or a scripted reaction. Use the supplied contact position and normal to place and orient an effect.
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, pool_id);
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. The OCCUPANT property takes an entity pool ID as its additional argument. 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);
set_meshmap_property(collection, id, property, path, adjust_0, adjust_65535);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. The last signature applies to MESHMAP_PROPERTY_DEPTH and replaces its image and adjustment pair together. Supply both adjustments or omit both.
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 | Baseline drawing Z for native queued drawing and immediate drawing within an explicit depth pass. |
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. |
DEPTH
|
Read/Write | Drawing depth image path. Assign a string path, optionally followed by both adjustment endpoints. Assign an empty string to remove the companion. |
DEPTH_ADJUST0, DEPTH_ADJUST65535
|
Read | Authored drawing-Z adjustments for samples 0 and 65535. Read the stored endpoints; change them by assigning DEPTH with an image path and both values.
|
SCRIPT_ENTER, SCRIPT_EXIT, SCRIPT_BLOCK
|
Read/Write | Handler script paths. Assign a path to load or replace a handler; assign NULL() or an empty string to remove it.
|
OCCUPANT_COUNT
|
Read | Current number of entities observed inside the mesh's range. Requires an entry or exit handler. |
OCCUPANT
|
Read | Membership as 0 or 1. Supply the entity pool ID as the additional argument. |
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.
Drawing Depth Properties
Assign a depth image with the default one-for-one range, or supply both endpoint adjustments explicitly:
/* Default: sample 32768 is neutral. */
set_meshmap_property(maps, id,
openborconstant("MESHMAP_PROPERTY_DEPTH"),
"data/terrain/wall_depth16.png");
/* Replace the image and endpoint pair together. */
set_meshmap_property(maps, id,
openborconstant("MESHMAP_PROPERTY_DEPTH"),
"data/terrain/wall_depth16.png", -24, 24);Read the assigned path and authored endpoints:
void path = get_meshmap_property(maps, id,
openborconstant("MESHMAP_PROPERTY_DEPTH"));
float adjust_0 = get_meshmap_property(maps, id,
openborconstant("MESHMAP_PROPERTY_DEPTH_ADJUST0"));
float adjust_65535 = get_meshmap_property(maps, id,
openborconstant("MESHMAP_PROPERTY_DEPTH_ADJUST65535"));Without a companion, the path is an empty string and the endpoint getters return -32768 and +32767. Remove the companion by assigning an empty string:
set_meshmap_property(maps, id,
openborconstant("MESHMAP_PROPERTY_DEPTH"), "");This property requires a string path; NULL() is not its removal value. To adjust depth during one drawing operation while keeping the map's authored endpoints, use a drawmethod override. See Depth Range Override.
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. Inactive maps remain accessible to script and can continue observing entry and exit.
Bank Properties
Get Bank Property
get_meshmap_bank_property(collection, bank_type, prefix, property);
get_meshmap_bank_property(collection, bank_type, prefix, property, slot);
get_meshmap_bank_property(collection, bank_type, prefix, property, pool_id);The additional argument is a child slot for CHILD_PRESENT and CHILD_ACTIVE, or an entity pool ID for OCCUPANT. Other bank properties do not accept an additional index.
Set Bank Property
set_meshmap_bank_property(collection, bank_type, prefix, property, value);
set_meshmap_bank_property(collection, bank_type, prefix, property, value, slot);Pass one of MESHMAP_BANK_LEVEL, MESHMAP_BANK_AREA, MESHMAP_BANK_SECTOR, MESHMAP_BANK_ROOM, or MESHMAP_BANK_MESH as bank_type, using openborconstant(). The argument is a bank type flag, not a numerical hierarchy depth. MESHMAP_BANK_NONE, combined flags, and unknown selectors are invalid.
prefix is a full-format mesh map ID identifying the desired path. Address components below the selected owner are ignored. Use MESHMAP_BANK_LEVEL and prefix 0 for the collection root. For MESHMAP_BANK_MESH, the complete ID selects the individual mesh. The additional slot argument for CHILD_ACTIVE follows the value in the setter.
For example, prefix 270532 represents 1/2/3/4. With MESHMAP_BANK_AREA it selects area 1; with MESHMAP_BANK_SECTOR it selects sector 1/2; with MESHMAP_BANK_ROOM it selects room 1/2/3; with MESHMAP_BANK_MESH it selects mesh 1/2/3/4. 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 | Selected MESHMAP_BANK_* type flag. The result can be reused as bank_type.
|
PRESENT_MASK
|
Read | Opaque selection of all existing immediate children. Container banks only. |
ACTIVE_MASK
|
Read/Write | Opaque selection of locally active immediate children. Use a returned selection or MESHMAP_BANK_MASK_NONE. Container banks only.
|
CHILD_PRESENT
|
Read | Presence of an immediate child at the additional slot argument. Container banks only. |
CHILD_ACTIVE
|
Read/Write | Local active state (0/1) of an immediate child at the additional slot argument. Container banks only. |
CHILD_COUNT
|
Read | Number of existing immediate children. Container banks only. |
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. |
SCRIPT_ENTER, SCRIPT_EXIT
|
Read/Write | Handler script paths. Assign a path to load or replace a handler; assign NULL() or an empty string to remove it.
|
OCCUPANT_COUNT
|
Read | Current number of entities observed inside the owner's range. Requires an entry or exit handler. |
OCCUPANT
|
Read | Membership as 0 or 1. Supply the entity pool ID as the additional argument. |
GENERATION
|
Read | Owner allocation identity. Changes when a removed owner is recreated. |
Removing the MESHMAP_BANK_LEVEL root clears its children, bounds, and handlers while preserving the collection handle with a new root generation. Removing an area, sector, or room also removes all its descendants. Removing MESHMAP_BANK_MESH removes only that mesh. 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.
The mesh selector supports the common owner properties: presence, type, bounds, entry and exit handlers, occupancy, and generation. Child masks, counts, and slot operations apply only to level, area, sector, and room banks. Use MESHMAP_PROPERTY_SCRIPT_BLOCK through the map API for a mesh's blocking handler.
Change an Individual Child
Disable area 1 while preserving all other areas' local active states:
if(get_meshmap_bank_property(maps, openborconstant("MESHMAP_BANK_LEVEL"), 0,
openborconstant("MESHMAP_BANK_PROPERTY_CHILD_PRESENT"), 1))
{
set_meshmap_bank_property(maps, openborconstant("MESHMAP_BANK_LEVEL"), 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, openborconstant("MESHMAP_BANK_LEVEL"), 0,
openborconstant("MESHMAP_BANK_PROPERTY_ACTIVE_MASK"),
get_meshmap_bank_property(maps, openborconstant("MESHMAP_BANK_LEVEL"), 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, openborconstant("MESHMAP_BANK_LEVEL"), 0,
openborconstant("MESHMAP_BANK_PROPERTY_ACTIVE_MASK"));
/* Disable all areas. */
set_meshmap_bank_property(maps, openborconstant("MESHMAP_BANK_LEVEL"), 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, openborconstant("MESHMAP_BANK_LEVEL"), 0,
openborconstant("MESHMAP_BANK_PROPERTY_ACTIVE_MASK"),
saved_selection);Handler Assignment and Membership
Handler properties read the assigned path, or an empty string when unassigned, and accept a replacement path. Set NULL() or an empty string to remove a handler. The special word none belongs to level text; the script string "none" is treated as a file path. Replacement loads and compiles the script before replacing the current handler; a failed replacement preserves the current assignment.
The following assigns room handlers through script. Room 1/2/3 must already exist:
int bank = openborconstant("MESHMAP_BANK_ROOM");
int prefix = 1 * 262144 + 2 * 4096 + 3 * 64;
set_meshmap_bank_property(maps, bank, prefix,
openborconstant("MESHMAP_BANK_PROPERTY_SCRIPT_ENTER"),
"data/scripts/terrain/room_enter.c");
set_meshmap_bank_property(maps, bank, prefix,
openborconstant("MESHMAP_BANK_PROPERTY_SCRIPT_EXIT"),
"data/scripts/terrain/room_exit.c");For individual mesh handlers:
set_meshmap_property(maps, id,
openborconstant("MESHMAP_PROPERTY_SCRIPT_BLOCK"),
"data/scripts/terrain/mesh_block.c");
/* Remove only this mesh's blocking handler. */
set_meshmap_property(maps, id,
openborconstant("MESHMAP_PROPERTY_SCRIPT_BLOCK"), NULL());Use an entity's pool ID to query observed membership. The following assumes entity is a live entity and the selected room exists with an entry or exit handler:
int pool_id = get_entity_property(entity,
openborconstant("ENTITY_PROPERTY_POOL_ID"));
int inside_room = get_meshmap_bank_property(maps, bank, prefix,
openborconstant("MESHMAP_BANK_PROPERTY_OCCUPANT"), pool_id);
int room_count = get_meshmap_bank_property(maps, bank, prefix,
openborconstant("MESHMAP_BANK_PROPERTY_OCCUPANT_COUNT"));The equivalent mesh queries are:
int inside_mesh = get_meshmap_property(maps, id,
openborconstant("MESHMAP_PROPERTY_OCCUPANT"), pool_id);
int mesh_count = get_meshmap_property(maps, id,
openborconstant("MESHMAP_PROPERTY_OCCUPANT_COUNT"));Membership and counts report the currently observed state, which can be later than a queued event's snapshot. Only owners with an entry or exit handler maintain membership. With neither handler, these queries return zero; a blocking handler alone does not enable range tracking. See Occupancy and Loading.
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, openborconstant("MESHMAP_BANK_LEVEL"), 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.
Entity Pool ID
int pool_id = get_entity_property(entity,
openborconstant("ENTITY_PROPERTY_POOL_ID"));ENTITY_PROPERTY_POOL_ID is a read-only identifier for the entity's allocation slot. Its value stays stable when the active entity list is sorted or compacted. It is separate from the active-list index and from the entity's lifetime identity.
Mesh event membership uses one bit per stable pool slot. Pass the pool ID to a map or bank OCCUPANT query. Unregistered entity objects use ENTITY_POOL_ID_NONE.
When OpenBOR reuses an allocation for another entity, that allocation retains its pool ID while the spawned entity receives a different ENTITY_PROPERTY_UNIQUE_ID. Use the unique ID as well when retaining records across entity lifetimes. Event locals include both values captured when the event was recorded, and membership for the previous occupant is cleared before the slot is reused.
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_offsetNative 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 / wOpenBOR 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_zFor 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.
Explicit Depth Composition
Use an explicit depth pass when composing several immediate draws into a script-owned RGB32 screen:
begin_draw_depth(target_screen, minimum_z, maximum_z);
set_draw_depth(drawing_z);
end_draw_depth(target_screen);The range must be finite, with minimum_z less than maximum_z, and must contain the final drawing-Z values used by the pass, including depth-image adjustments. Beginning a pass clears the target's transient depth data while preserving its color. End the pass on the same target after the immediate drawing operations have finished.
Each immediate mesh draw supplies its current LAYER property as its baseline. set_draw_depth() selects the baseline for other immediate drawing operations; it does not replace the baseline selected by draw_meshmap() or draw_meshmap_projected().
For example, assume two existing textured maps have IDs floor_id and wall_id, their final drawing-Z values fit within -128 through 128, and surface is a script-owned RGB32 screen:
clearscreen(surface);
if(begin_draw_depth(surface, -128, 128))
{
draw_meshmap(maps, floor_id, surface, NULL());
draw_meshmap(maps, wall_id, surface, NULL());
end_draw_depth(surface);
}These functions return 1 for success or 0 when the depth operation is unavailable or does not match the active pass. Invalid arguments report script errors. Native queued scene drawing manages its depth pass automatically; this explicit pass is for immediate screen composition.
Depth Range Override
The drawmethod DM_DEPTH_RANGE property replaces a depth image's adjustment pair for that drawing operation. The override requires an enabled drawmethod and a depth image. Assigning the property does not itself enable a disabled drawmethod.
With an existing enabled drawmethod handle named method:
set_draw_method(method, openborconstant("DM_DEPTH_RANGE"), -48, 48);
/* Use this material for the mesh within the active depth pass. */
draw_meshmap(maps, id, surface, method);
/* Return to the companion image's authored range. */
set_draw_method(method, openborconstant("DM_DEPTH_RANGE"), NULL());Pass the intended drawmethod handle to the mesh drawing function. Passing NULL() as its drawmethod selects the plain material; it does not inherit the common script drawmethod.
The range getter uses the following component constants:
| Component | Result |
|---|---|
DM_DEPTH_SAMPLE_MIN
|
Override adjustment for grayscale sample 0, or NULL() when inheriting.
|
DM_DEPTH_SAMPLE_MAX
|
Override adjustment for grayscale sample 65535, or NULL() when inheriting.
|
DM_DEPTH_INHERIT
|
1 when using the companion's authored range, or 0 when overriding it. |
For example:
int inherits = get_draw_method(method,
openborconstant("DM_DEPTH_RANGE"),
openborconstant("DM_DEPTH_INHERIT"));
void sample_min = get_draw_method(method,
openborconstant("DM_DEPTH_RANGE"),
openborconstant("DM_DEPTH_SAMPLE_MIN"));
void sample_max = get_draw_method(method,
openborconstant("DM_DEPTH_RANGE"),
openborconstant("DM_DEPTH_SAMPLE_MAX"));MIN and MAX name the grayscale sample endpoints, so the adjustment pair can still be reversed. The map's own endpoint getters remain MESHMAP_PROPERTY_DEPTH_ADJUST0 and MESHMAP_PROPERTY_DEPTH_ADJUST65535. See Drawmethod for general drawmethod configuration.
Draw Ordering
Mesh maps retain their configured drawing layer as the baseline for ordering. When a drawing depth image is attached, the GPU adds its sampled adjustment to that baseline and compares the resulting drawing Z with other pixels in the same depth pass. Greater drawing Z takes precedence; equal values retain the established draw order.
Native queued sprites, screens, and mesh maps participate in this comparison automatically when a depth companion is present. Ordinary entries within the affected drawing-Z range participate as well. Immediate scripted composition uses an explicit depth pass; without one, immediate draws follow their ordinary submission order. Opaque pixels and fully covered cutouts test and write depth. Partially covered or blended pixels test depth while retaining ordered composition.
Custom projection controls screen position and perspective texture sampling. Mesh geometry and the view matrix do not automatically supply camera-distance depth. Authored drawing-depth values control per-pixel ordering.
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. Entry and exit handlers can activate, load, or release terrain under creator control; bounds alone do not clip rendering or load 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
- Drawmethod - Drawing configuration and per-pixel depth controls.
- Time - Logical timing for scripted behavior.