Library mesh
Mesh library to facilitate drawing dynamic meshes.
Functions
| advanceVertex() |
Advances the current mesh to the next vertex, committing any written data for the current vertex. |
| generate( primitiveType, primitiveCount, generatorFunc, meshInstance ) |
Generates a mesh, either writing to the given mesh object, or otherwise drawing the result directly. |
| writeColor( r, g, b, a ) |
Sets the colour of the current vertex. |
| writeNormal( normal ) |
Sets the normal of the current vertex (used for lighting). |
| writePosition( pos ) |
Sets the position of the current vertex. |
| writeQuadFromPlane( position, normal, width, height, color ) |
Writes 4 vertices to the mesh based on the given plane and size, all with the given colour. |
| writeQuadFromVertices( vertex1, vertex2, vertex3, vertex4, color ) |
Writes 4 vertices to the mesh, all with the given colour. |
| writeTexCoord( stage, u, v ) |
Sets the texture co-ordinates of the current vertex. |
| writeUserData( tangentX, tangentY, tangentZ, tangentHandedness ) |
Sets the user data for the current vertex. |
Fields
Functions
- mesh.advanceVertex()
-
Advances the current mesh to the next vertex, committing any written data for the current vertex.
Environment:
Client
- mesh.generate( primitiveType, primitiveCount, generatorFunc, meshInstance )
-
Generates a mesh, either writing to the given mesh object, or otherwise drawing the result directly.
Writing to an IMesh can be done outside a rendering hook.
Note that you cannot yield in the callback as mesh generation must occur synchronously in a single frame.
Environment:
Client
Parameters:
-
primitiveType: The type of primitives to draw (mesh.MATERIAL_*).
-
primitiveCount: The number of primitives that will be drawn.
-
generatorFunc: A function that, when called, should write the mesh.
-
meshInstance: An optional IMesh object to write the mesh values to.
Usage:
-- Generates a 64x64 white rectangle at (0, 0)
local function GenerateMesh()
mesh.writeQuadFromPlane( Vector( 32, 32, 0 ), Vector( 0, 0, -1 ), 64, 64 )
end
-- In a render hook, call mesh.generate to draw the mesh dynamically.
-- Alternatively, pass an IMesh to store the mesh data to be drawn later.
hook.add( "render", "mesh", function()
render.clear( 0, 0, 0, 255 )
mesh.generate( mesh.MATERIAL_QUADS, 1, GenerateMesh )
end )
- mesh.writeColor( r, g, b, a )
-
Sets the colour of the current vertex.
Environment:
Client
Parameters:
-
r: The red value (0-255).
-
g: The green value (0-255).
-
b: The blue value (0-255).
-
a: The alpha value (0-255).
- mesh.writeNormal( normal )
-
Sets the normal of the current vertex (used for lighting).
Environment:
Client
Parameters:
-
normal: The normal vector to write.
- mesh.writePosition( pos )
-
Sets the position of the current vertex. Every vertex must have a unique position.
Environment:
Client
Parameters:
-
pos: The position to write.
- mesh.writeQuadFromPlane( position, normal, width, height, color )
-
Writes 4 vertices to the mesh based on the given plane and size, all with the given colour.
Environment:
Client
Parameters:
-
(Vector) position: The centre point for the quad.
-
(Vector) normal: The plane's normal.
-
(number) width: The width of the quad.
-
(number) height: The height of the quad.
-
(Color?) color: (Optional) The colour to apply to each vertex in the quad (default is white).
- mesh.writeQuadFromVertices( vertex1, vertex2, vertex3, vertex4, color )
-
Writes 4 vertices to the mesh, all with the given colour.
Environment:
Client
Parameters:
-
(Vector) vertex1: The top-left corner.
-
(Vector) vertex2: The top-right corner.
-
(Vector) vertex3: The bottom-right corner.
-
(Vector) vertex4: The bottom-left corner.
-
(Color?) color: (Optional) The colour to apply to each vertex in the quad (default is white).
- mesh.writeTexCoord( stage, u, v )
-
Sets the texture co-ordinates of the current vertex.
Environment:
Client
Parameters:
-
stage: The stage to write the co-ordinates to. Stage 0 is the main texture, stages 1 and 2 are used for lightmaps.
-
u: The u co-ordinate.
-
v: The v co-ordinate.
- mesh.writeUserData( tangentX, tangentY, tangentZ, tangentHandedness )
-
Sets the user data for the current vertex. This is used to define the tangent.
Environment:
Client
Parameters:
-
tangentX: The x component of the tangent vector.
-
tangentY: The y component of the tangent vector.
-
tangentZ: The z component of the tangent vector.
-
tangentHandedness: The handedness of the tangent vector (either -1 or 1).