< GeeXLab Reference Guide />

> Back to Reference Guide Index


gh_mesh library

Description

gh_mesh is the module that manages meshes. A mesh is a set of triangular faces that allows to represent any type of 3d shape: starting from the basic built-in shapes (plane, torus, sphere) to complex shapes created with modeling softwares such as 3D Studio Max or Blender.


Number of functions: 44

  1. gh_mesh.alloc_mesh_data (Lua - Python)
  2. gh_mesh.create_v2 (Lua - Python)
  3. gh_mesh.create_box (Lua - Python)
  4. gh_mesh.create_cylinder (Lua - Python)
  5. gh_mesh.create_cylinder_xyz (Lua - Python)
  6. gh_mesh.create_disc (Lua - Python)
  7. gh_mesh.create_ellipse (Lua - Python)
  8. gh_mesh.create_gear (Lua - Python)
  9. gh_mesh.create_icosphere (Lua - Python)
  10. gh_mesh.create_plane (Lua - Python)
  11. gh_mesh.create_plane_v3 (Lua - Python)
  12. gh_mesh.create_quad (Lua - Python)
  13. gh_mesh.create_sphere (Lua - Python)
  14. gh_mesh.create_terrain (Lua - Python)
  15. gh_mesh.create_torus (Lua - Python)
  16. gh_mesh.create_triangle (Lua - Python)
  17. gh_mesh.get_face_normal (Lua - Python)
  18. gh_mesh.get_face_vertex_indices (Lua - Python)
  19. gh_mesh.get_vertex_absolute_position (Lua - Python)
  20. gh_mesh.get_vertex_color (Lua - Python)
  21. gh_mesh.get_vertex_normal (Lua - Python)
  22. gh_mesh.get_vertex_position (Lua - Python)
  23. gh_mesh.get_vertex_tangent (Lua - Python)
  24. gh_mesh.get_vertex_uv (Lua - Python)
  25. gh_mesh.instancing_init (Lua - Python)
  26. gh_mesh.instancing_set_axis_angle (Lua - Python)
  27. gh_mesh.instancing_set_color (Lua - Python)
  28. gh_mesh.instancing_set_orientation (Lua - Python)
  29. gh_mesh.instancing_set_position (Lua - Python)
  30. gh_mesh.instancing_set_scale (Lua - Python)
  31. gh_mesh.resize_box (Lua - Python)
  32. gh_mesh.resize_plane (Lua - Python)
  33. gh_mesh.resize_quad (Lua - Python)
  34. gh_mesh.ribbon_create (Lua - Python)
  35. gh_mesh.ribbon_add_point (Lua - Python)
  36. gh_mesh.ribbon_set_cross_vector (Lua - Python)
  37. gh_mesh.set_face_vertex_indices (Lua - Python)
  38. gh_mesh.set_vertex_color (Lua - Python)
  39. gh_mesh.set_vertex_normal (Lua - Python)
  40. gh_mesh.set_vertex_position (Lua - Python)
  41. gh_mesh.set_vertex_tangent (Lua - Python)
  42. gh_mesh.set_vertex_uv (Lua - Python)
  43. gh_mesh.set_vertices_color (Lua - Python)
  44. gh_mesh.voxelize (Lua - Python)



alloc_mesh_data

Description

Allocates memory for mesh data (vertices and faces lists).


Syntax

gh_mesh.alloc_mesh_data(
 mesh,
 num_vertices,
 num_faces
)

Languages

Lua - Python


Parameters


Return Values

This function has no return value(s).


Code sample


mesh_triangle = gh_mesh.create()
gh_mesh.alloc_mesh_data(mesh_triangle, 3, 1)
            


create_v2

Description

Creates a mesh.


Syntax

mesh = gh_mesh.create_v2()

Languages

Lua - Python


Parameters

This function has no input parameter(s).


Return Values


Code sample


mesh = gh_mesh.create_v2()
            


create_box

Description

Creates a mesh box.


Syntax

mesh = gh_mesh.create_box(
 width, height, depth,
 wsegs, hsegs, dsegs
)

Languages

Lua - Python


Parameters


Return Values


Code sample


mesh_box = gh_mesh.create_box(10.0, 10.0, 10.0, 4, 4, 4)
            


create_cylinder

Description

Creates a mesh cylinder.


Syntax

mesh = gh_mesh.create_cylinder(
 radius,
 height,
 stacks,
 slices
)

Languages

Lua - Python


Parameters


Return Values


Code sample


mesh_cyl = gh_mesh.create_cylinder(radius, height, stacks, slices)
            


create_cylinder_xyz

Description

Creates a mesh cylinder.


Syntax

mesh = gh_mesh.create_cylinder_xyz(
 central_axis,
 radius,
 height,
 stacks,
 slices
)

Languages

Lua - Python


Parameters


Return Values


Code sample


central_axis = 1 -- a Y-axis oriented cylinder             
mesh_cyl = gh_mesh.create_cylinder_xyz(central_axis, radius, height, stacks, slices)
            


create_disc

Description

Creates a mesh disc.


Syntax

mesh = gh_mesh.create_disc(
 radius,
 thickness,
 slices
)

Languages

Lua - Python


Parameters


Return Values


Code sample


mesh_disc = gh_mesh.create_disc(radius, thickness, slices)
            


create_ellipse

Description

Creates a mesh ellipse.


Syntax

mesh = gh_mesh.create_ellipse(
 major_radius,
 minor_radius,
 slices,
 radius_segments,
 opening_angle
)

Languages

Lua - Python


Parameters


Return Values


Code sample


mesh_ellipse = gh_mesh.create_ellipse(major_radius, minor_radius, slices, radius_segments, opening_angle)
mesh_disc = gh_mesh.create_ellipse(radius, radius, 20, 20, 0)
            


create_gear

Description

Creates a mesh gear.


Syntax

mesh = gh_mesh.create_gear(
 inner_radius,
 outer_radius,
 tooth_depth,
 num_teeth,
 width
)

Languages

Lua - Python


Parameters


Return Values


Code sample


mesh_gear = gh_mesh.create_gear(1.0, 4.0,  1.0, 10,  2.0)
            


create_icosphere

Description

Creates an ico-sphere mesh.


Syntax

mesh = gh_mesh.create_icosphere(
 radius,
 recursion_level
)

Languages

Lua - Python


Parameters


Return Values


Code sample


mesh_icosphere = gh_mesh.create_icosphere(10.0, 2)
            


create_plane

Description

Creates a mesh plane.


Syntax

mesh = gh_mesh.create_plane(
 width, height,
 wsegs, hsegs
)

Languages

Lua - Python


Parameters


Return Values


Code sample


mesh_plane = gh_mesh.create_plane(20.0, 10.0, 4, 4)
            


create_plane_v3

Description

Creates a mesh plane with an initial rotation.


Syntax

mesh = gh_mesh.create_plane_v3(
 width, height,
 , hsegs,
 pitch, yaw, roll
)

Languages

Lua - Python


Parameters


Return Values


Code sample


mesh_plane = gh_mesh.create_plane_v3(20.0, 10.0, 4, 4, 45.0, 0, 0)
            


create_quad

Description

Creates a mesh quad. A quad is a mesh plane with only 4 vertices.


Syntax

mesh = gh_mesh.create_quad(
 width, height
)

Languages

Lua - Python


Parameters


Return Values


Code sample


mesh_quad = gh_mesh.create_quad(20.0, 10.0)
            


create_sphere

Description

Creates a mesh sphere.


Syntax

mesh = gh_mesh.create_sphere(
 radius,
 stacks, slices
)

Languages

Lua - Python


Parameters


Return Values


Code sample


mesh_sphere = gh_mesh.create_sphere(10.0, 20, 20)
            


create_terrain

Description

Creates a mesh terrain from a height map.


Syntax

mesh = gh_mesh.create_terrain(
 texture_id,
 num_subdivisions,
 vertical_scale,
 terrain_size,
 height_threshold
)

Languages

Lua - Python


Parameters


Return Values


Code sample


mesh_terrain = gh_mesh.create_terrain(texture_id, num_subdivisions, vertical_scale, terrain_size, height_threshold)
            


create_torus

Description

Creates a mesh torus.


Syntax

mesh = gh_mesh.create_torus(
 outer_radius,
 inner_radius,
 slices
)

Languages

Lua - Python


Parameters


Return Values


Code sample


mesh_torus = gh_mesh.create_torus(10.0, 4.0, 20)
            


create_triangle

Description

Creates a mesh triangle. Vertices are positioned in the range [-1.0;+1.0].


Syntax

mesh = gh_mesh.create_triangle()

Languages

Lua - Python


Parameters

This function has no input parameter(s).


Return Values


Code sample


mesh_triangle = gh_mesh.create_triangle()
            


get_face_normal

Description

Gets the normal vector of a face. Be sure that gh_object.compute_faces_normal() has been called before.


Syntax

x, y, z = gh_mesh.get_face_normal(
 mesh_id,
 face_index
)

Languages

Lua - Python


Parameters


Return Values


Code sample


x, y, z = gh_mesh.get_face_normal(mesh, face_index)
            


get_face_vertex_indices

Description

Gets the vertex indices of a particular face.


Syntax

a, b, c = gh_mesh.get_face_vertex_indices(
 object_id,
 face_index
)

Languages

Lua - Python


Parameters


Return Values


Code sample


a, b, c = gh_mesh.get_face_vertex_indices(mesh, face_index)
            


get_vertex_absolute_position

Description

Gets the absolute position of a particular vertex.


Syntax

x, y, z = gh_mesh.get_vertex_absolute_position(
 object_id,
 vertex_index
)

Languages

Lua - Python


Parameters


Return Values


Code sample


vertex_index = 0
x, y, z = gh_mesh.get_vertex_absolute_position(mesh, vertex_index)
            


get_vertex_color

Description

Gets the RGBA color of a particular vertex.


Syntax

r, g, b, a = gh_mesh.get_vertex_color(
 object_id,
 vertex_index
)

Languages

Lua - Python


Parameters


Return Values


Code sample


vertex_index = 0
r, g, b, a = gh_mesh.get_vertex_color(mesh, vertex_index)
            


get_vertex_normal

Description

Gets the normal vector of a particular vertex.


Syntax

x, y, z = gh_mesh.get_vertex_normal(
 object_id,
 vertex_index
)

Languages

Lua - Python


Parameters


Return Values


Code sample


vertex_index = 0
x, y, z = gh_mesh.get_vertex_normal(mesh, vertex_index)
            


get_vertex_position

Description

Gets the relative position of a particular vertex.


Syntax

x, y, z, w = gh_mesh.get_vertex_position(
 object_id,
 vertex_index
)

Languages

Lua - Python


Parameters


Return Values


Code sample


vertex_index = 0
x, y, z, w = gh_mesh.get_vertex_position(mesh, vertex_index)
            


get_vertex_tangent

Description

Gets the tangent vector of a particular vertex.


Syntax

x, y, z, w = gh_mesh.get_vertex_tangent(
 object_id,
 vertex_index
)

Languages

Lua - Python


Parameters


Return Values


Code sample


vertex_index = 0
x, y, z, w = gh_mesh.get_vertex_tangent(mesh, vertex_index)
            


get_vertex_uv

Description

Gets the texcoord of a particular vertex.


Syntax

x, y, z, w = gh_mesh.get_vertex_uv(
 object_id,
 vertex_index,
 texture_unit
)

Languages

Lua - Python


Parameters


Return Values


Code sample


vertex_index = 0
texture_unit = 0
x, y, z, w = gh_mesh.get_vertex_uv(mesh, vertex_index, texture_unit)
            


instancing_init

Description

Initializes the geometry instancing rendering.


Syntax

gh_mesh.instancing_init(
 mesh,
 num_instances
)

Languages

Lua - Python


Parameters


Return Values

This function has no return value(s).


Code sample


-- mesh instancing requires separate vertex arrays.
gh_mesh.set_vertex_alloc_params_separate_vertex_arrays(separate_vertex_arrays)

num_instances = 1000
gh_mesh.instancing_init(mesh, num_instances)

local instance_index = 0
local i
for i=0, num_instances-1 do
  x = math.random(-100, 100)
  y = math.random(-50, 50)
  z = 0.0
  gh_mesh.instancing_set_position(mesh, i, x, y, z)
  x = math.random(-60, 60)
  y = math.random(-60, 60)
  z = math.random(-60, 60)
  gh_mesh.instancing_set_orientation(mesh, i, x, y, z)
end
            


instancing_set_axis_angle

Description

Sets the rotation axis and the angle of rotation around this axis for a particular instance.


Syntax

gh_mesh.instancing_set_axis_angle(
 mesh,
 index,
 x, y, z,,
 angle
)

Languages

Lua - Python


Parameters


Return Values

This function has no return value(s).


Code sample


-- mesh instancing requires separate vertex arrays.
gh_mesh.set_vertex_alloc_params_separate_vertex_arrays(separate_vertex_arrays)

local num_instances = 1000
gh_mesh.instancing_init(mesh, num_instances)
local i
for i=0, num_instances do
  x = math.random(-10, 10)
  y = math.random(-10, 10)
  z = math.random(-10, 10)
  gh_mesh.instancing_set_position(mesh, i, x, y, z)
  gh_mesh.instancing_set_axis_angle(mesh, i, 0.0, 0.0, 1.0, 60.0)
  gh_mesh.instancing_set_color(mesh, i, 1.0, 1.0, 1.0, 1.0)
end
            


instancing_set_color

Description

Sets the color of a particular instance.


Syntax

gh_mesh.instancing_set_color(
 mesh,
 index,
 r, g, b, a,
)

Languages

Lua - Python


Parameters


Return Values

This function has no return value(s).


Code sample


-- mesh instancing requires separate vertex arrays.
gh_mesh.set_vertex_alloc_params_separate_vertex_arrays(separate_vertex_arrays)

local num_instances = 1000
gh_mesh.instancing_init(mesh, num_instances)
local i
for i=0, num_instances do
  x = math.random(-10, 10)
  y = math.random(-10, 10)
  z = math.random(-10, 10)
  gh_mesh.instancing_set_position(mesh, i, x, y, z)
  gh_mesh.instancing_set_color(mesh, i, 1.0, 1.0, 1.0, 1.0)
end
            


instancing_set_orientation

Description

Sets the orientation of a particular instance using Euler's angles.


Syntax

gh_mesh.instancing_set_orientation(
 mesh,
 index,
 pitch, yaw, roll
)

Languages

Lua - Python


Parameters


Return Values

This function has no return value(s).


Code sample


-- mesh instancing requires separate vertex arrays.
gh_mesh.set_vertex_alloc_params_separate_vertex_arrays(separate_vertex_arrays)

local num_instances = 1000
gh_mesh.instancing_init(mesh, num_instances)
local i
for i=0, num_instances do
  x = math.random(-10, 10)
  y = math.random(-10, 10)
  z = math.random(-10, 10)
  gh_mesh.instancing_set_position(mesh, i, x, y, z)
  x = math.random(-60, 60)
  y = math.random(-60, 60)
  z = math.random(-60, 60)
  gh_mesh.instancing_set_orientation(mesh, i, x, y, z)
end
            


instancing_set_position

Description

Sets the position of a particular instance.


Syntax

gh_mesh.instancing_set_position(
 mesh,
 index,
 x, y, z
)

Languages

Lua - Python


Parameters


Return Values

This function has no return value(s).


Code sample


-- mesh instancing requires separate vertex arrays.
gh_mesh.set_vertex_alloc_params_separate_vertex_arrays(separate_vertex_arrays)

local num_instances = 1000
gh_mesh.instancing_init(mesh, num_instances)
local i
for i=0, num_instances do
  x = math.random(-10, 10)
  y = math.random(-10, 10)
  z = math.random(-10, 10)
  gh_mesh.instancing_set_position(mesh, i, x, y, z)
  x = math.random(-60, 60)
  y = math.random(-60, 60)
  z = math.random(-60, 60)
  gh_mesh.instancing_set_orientation(mesh, i, x, y, z)
end
            


instancing_set_scale

Description

Sets the scaling factor of a particular instance.


Syntax

gh_mesh.instancing_set_scale(
 mesh,
 index,
 x, y, z
)

Languages

Lua - Python


Parameters


Return Values

This function has no return value(s).


Code sample


-- mesh instancing requires separate vertex arrays.
gh_mesh.set_vertex_alloc_params_separate_vertex_arrays(separate_vertex_arrays)

local num_instances = 1000
gh_mesh.instancing_init(mesh, num_instances)
local i
for i=0, num_instances do
  x = math.random(-10, 10)
  y = math.random(-10, 10)
  z = math.random(-10, 10)
  gh_mesh.instancing_set_position(mesh, i, x, y, z)
  gh_mesh.instancing_set_scale(mesh, i, 1.0, 1.0, 1.0)
end
            


resize_box

Description

Updates the size of the mesh box (update the position of all vertices).


Syntax

mesh = gh_mesh.resize_box(
 width, height, depth
)

Languages

Lua - Python


Parameters


Return Values


Code sample


gh_mesh.resize_box(mesh_box, 10.0, 10.0, 10.0)
            


resize_plane

Description

Updates the width and height of a mesh plane.


Syntax

gh_mesh.resize_plane(
 mesh,
 width, height
)

Languages

Lua - Python


Parameters


Return Values

This function has no return value(s).


Code sample


gh_mesh.resize_plane(mesh_quad, 20.0, 15.0)
            


resize_quad

Description

Updates the width and height of a mesh quad.


Syntax

gh_mesh.resize_quad(
 mesh,
 width, height
)

Languages

Lua - Python


Parameters


Return Values

This function has no return value(s).


Code sample


gh_mesh.resize_quad(mesh_quad, 20.0, 15.0)
            


ribbon_create

Description

Creates a mesh ribbon. Once the ribbon object is created you need to call ribbon_add_point() to create vertices.


Syntax

mesh = gh_mesh.ribbon_create(
 thickness
)

Languages

Lua - Python


Parameters


Return Values


Code sample


ribbon = gh_mesh.ribbon_create(2.0)
            


ribbon_add_point

Description

Adds a new point to the ribbon. Each new point will generate the real geometry.


Syntax

gh_mesh.ribbon_add_point(
 mesh,
 x, y, z, w
)

Languages

Lua - Python


Parameters


Return Values

This function has no return value(s).


Code sample


gh_mesh.ribbon_add_point(ribbon, x, y, z, 1.0)
            


ribbon_set_cross_vector

Description

Sets the cross vector that tunes the orientation of the ribbon.


Syntax

gh_mesh.ribbon_set_cross_vector(
 mesh,
 x, y, z, w
)

Languages

Lua - Python


Parameters


Return Values

This function has no return value(s).


Code sample


gh_mesh.ribbon_set_cross_vector(ribbon, x, y, z)
            


set_face_vertex_indices

Description

Sets the vertex indices of a particular face.


Syntax

gh_mesh.set_face_vertex_indices(
 object_id,
 face_index,
 a, b, c
)

Languages

Lua - Python


Parameters


Return Values

This function has no return value(s).


Code sample


gh_mesh.set_face_vertex_indices(mesh, face_index, a, b, c)
            


set_vertex_color

Description

Sets the RGBA color of a particular vertex.


Syntax

gh_mesh.set_vertex_color(
 object_id,
 vertex_index,
 r, g, b, a
)

Languages

Lua - Python


Parameters


Return Values

This function has no return value(s).


Code sample


vertex_index = 0
gh_mesh.set_vertex_color(mesh, vertex_index, r, g, b, a)
            


set_vertex_normal

Description

Sets the normal vector of a particular vertex.


Syntax

gh_mesh.set_vertex_normal(
 object_id,
 vertex_index,
 x, y, z
)

Languages

Lua - Python


Parameters


Return Values

This function has no return value(s).


Code sample


vertex_index = 0
gh_mesh.set_vertex_normal(mesh, vertex_index, x, y, z)
            


set_vertex_position

Description

Sets the relative position of a particular vertex.


Syntax

gh_mesh.set_vertex_position(
 object_id,
 vertex_index,
 x, y, z, w
)

Languages

Lua - Python


Parameters


Return Values

This function has no return value(s).


Code sample


vertex_index = 0
gh_mesh.set_vertex_position(mesh, vertex_index, x, y, z, 1.0)
            


set_vertex_tangent

Description

Sets the tangent vector of a particular vertex.


Syntax

gh_mesh.set_vertex_tangent(
 object_id,
 vertex_index,
 x, y, z, w
)

Languages

Lua - Python


Parameters


Return Values

This function has no return value(s).


Code sample


vertex_index = 0
gh_mesh.set_vertex_tangent(mesh, vertex_index, x, y, z, w)
            


set_vertex_uv

Description

Sets the texcoord of a particular vertex.


Syntax

gh_mesh.set_vertex_uv(
 object_id,
 vertex_index,
 x, y, z, w,
 texture_unit
)

Languages

Lua - Python


Parameters


Return Values

This function has no return value(s).


Code sample


vertex_index = 0
texture_unit = 0
gh_mesh.set_vertex_uv(mesh, vertex_index, x, y, z, w, texture_unit)
            


set_vertices_color

Description

Sets the RGBA color of all vertices.


Syntax

gh_mesh.set_vertices_color(
 object_id,
 r, g, b, a
)

Languages

Lua - Python


Parameters


Return Values

This function has no return value(s).


Code sample


gh_mesh.set_vertices_color(mesh, r, g, b, a)
            


voxelize

Description

Voxelizes a mesh.


Syntax

gh_mesh.voxelize(
 mesh_id,
 voxelsizex,
 voxelsizey,
 voxelsizez
)

Languages

Lua - Python


Parameters


Return Values

This function has no return value(s).


Code sample


gh_mesh.voxelize(mesh, 4, 4, 4)
            






GeeXLab Rootard Guide | Downloads | Contact | Newsletter