 Reference Guide Host-API Lua / Python
» Back to Homepage
» Back to Developer's Guide Index
gh_mesh Library
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: 31
gh_mesh.create
Creates a mesh.
: Lua - Python
mesh [INTEGER]: mesh identifier
:
mesh = gh_mesh.create()
gh_mesh.alloc_mesh_data
Allocates memory for mesh data (vertices and faces lists).
: Lua - Python
mesh [INTEGER]: mesh identifier.
num_vertices [INTEGER]: number of vertices.
num_faces [INTEGER]: number of faces
:
mesh_triangle = gh_mesh.create()
gh_mesh.alloc_mesh_data(mesh_triangle, 3, 1)
gh_mesh.create_plane
Creates a mesh plane.
: Lua - Python
width, height [REAL]: size of the plane in the XZ plane.
wsegs, hsegs [INTEGER]: number of subdivisions along the X and Z axis.
mesh [INTEGER]: mesh identifier
:
mesh_plane = gh_mesh.create_plane(20.0, 10.0, 4, 4)
gh_mesh.create_quad
Creates a mesh quad. A quad is a mesh plane with only 4 vertices.
: Lua - Python
width, height [REAL]: size of the quad in the XY plane.
mesh [INTEGER]: mesh identifier
:
mesh_quad = gh_mesh.create_quad(20.0, 10.0)
gh_mesh.update_quad_size
Updates the width and height of a mesh quad.
: Lua - Python
mesh [INTEGER]: mesh identifier.
width, height [REAL]: size of the quad in the XY plane.
:
gh_mesh.update_quad_size(mesh_quad, 20.0, 15.0)
gh_mesh.create_sphere
Creates a mesh sphere.
: Lua - Python
radius [REAL]: Radius of the sphere.
stacks, slices [INTEGER]: number of subdivisions along the X and Y axis.
mesh [INTEGER]: mesh identifier
:
mesh_sphere = gh_mesh.create_sphere(10.0, 20, 20)
gh_mesh.create_torus
Creates a mesh torus.
: Lua - Python
outer_radius [REAL]: outer radius of the torus.
inner_radius [REAL]: inner radius of the torus.
slices [INTEGER]: number of subdivisions or sections.
mesh [INTEGER]: mesh identifier
:
mesh_torus = gh_mesh.create_torus(10.0, 4.0, 20)
gh_mesh.create_triangle
Creates a mesh triangle. Vertices are positioned in the range [-1.0;+1.0].
: Lua - Python
mesh [INTEGER]: mesh identifier
:
mesh_triangle = gh_mesh.create_triangle()
gh_mesh.init_instancing
Initializes the geometry instancing rendering.
: Lua - Python
mesh [INTEGER]: mesh identifier.
num_instances [INTEGER]: number of instances.
:
num_instances = 1000
gh_mesh.init_instancing(mesh, num_instances)
gh_mesh.set_instance_position
Sets the position of a particular instance.
: Lua - Python
mesh [INTEGER]: mesh identifier.
index [INTEGER]: index of the instance from 0 to num_instances-1.
x, y, z [REAL]: position of the instance.
:
local num_instances = 1000
gh_mesh.init_instancing(mesh, num_instances)
local instance_index = 0
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.set_instance_position(mesh, instance_index, x, y, z)
x = math.random(-60, 60)
y = math.random(-60, 60)
z = math.random(-60, 60)
gh_mesh.set_instance_orientation(mesh, instance_index, x, y, z)
instance_index = instance_index+1
end
gh_mesh.set_instance_orientation
Sets the orientation of a particular instance using Euler's angles.
: Lua - Python
mesh [INTEGER]: mesh identifier.
index [INTEGER]: index of the instance from 0 to num_instances-1.
pitch, yaw, roll [REAL]: angles of rotation around X, Y and Z axis.
:
local num_instances = 1000
gh_mesh.init_instancing(mesh, num_instances)
local instance_index = 0
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.set_instance_position(mesh, instance_index, x, y, z)
x = math.random(-60, 60)
y = math.random(-60, 60)
z = math.random(-60, 60)
gh_mesh.set_instance_orientation(mesh, instance_index, x, y, z)
instance_index = instance_index+1
end
gh_mesh.user_geometry_add_vertex
Adds a new vertex to the mesh. Allows to create customized meshes.
: Lua - Python
mesh [INTEGER]: mesh identifier.
x, y, z [REAL]: position of the vertex.
index [INTEGER]: Zero-based index of the new vertex
:
index = gh_mesh.user_geometry_add_vertex(mesh, x, y, z)
gh_mesh.user_geometry_set_vertex_position
Sets the position attribute of a vertex created with user_geometry_add_vertex().
: Lua - Python
mesh [INTEGER]: mesh identifier.
index [INTEGER]: index of the vertex.
x, y, z [REAL]: position of the vertex.
:
gh_mesh.user_geometry_set_vertex_position(mesh, index, x, y, z)
gh_mesh.user_geometry_set_vertex_color
Sets the color attribute of a vertex created with user_geometry_add_vertex().
: Lua - Python
mesh [INTEGER]: mesh identifier.
index [INTEGER]: index of the vertex.
r, g, b, a [REAL]: RGBA color of the vertex.
:
gh_mesh.user_geometry_set_vertex_color(mesh, index, r, g, b, a)
gh_mesh.user_geometry_set_vertex_normal
Sets the normal vector attribute of a vertex created with user_geometry_add_vertex().
: Lua - Python
mesh [INTEGER]: mesh identifier.
index [INTEGER]: index of the vertex.
x, y, z [REAL]: XYZ coordinates of the normal vector.
:
gh_mesh.user_geometry_set_vertex_normal(mesh, index, x, y, z)
gh_mesh.user_geometry_set_vertex_uv0
Sets the texture coordinates UV0 attribute of a vertex created with user_geometry_add_vertex().
: Lua - Python
mesh [INTEGER]: mesh identifier.
index [INTEGER]: index of the vertex.
x, y, z, w [REAL]: XYZW coordinates of UV0. Usually, only XY are used and ZW are set to 0.
:
gh_mesh.user_geometry_set_vertex_uv0(mesh, index, x, y, 0, 0)
gh_mesh.user_geometry_add_face
Adds a new face to the mesh. The face is made up of three vertex indices.
: Lua - Python
mesh [INTEGER]: mesh identifier.
a, b, c [INTEGER]: Indices of three vertices that make up the face.
:
gh_mesh.user_geometry_add_face(mesh, 0, 1, 2)
gh_mesh.build
Builds the mesh. Useful with user_geometry_add_vertex() and user_geometry_add_face() functions.
: Lua - Python
mesh [INTEGER]: mesh identifier.
:
mesh = gh_mesh.create()
gh_object.setpos(mesh, 0, 0, 0)
gh_object.set_euler_angles(mesh, 0, 0, 0)
-- A triangle: 3 vertices and 1 face!
-- See the howto_build_the_triangle.jpg image for some details about how to build the triangle.
-- Step 1: the vertices
--
index = gh_mesh.user_geometry_add_vertex(mesh, -5, -5, 0)
gh_mesh.user_geometry_set_vertex_color(mesh, index, 1, 0, 0, 1)
index = gh_mesh.user_geometry_add_vertex(mesh, 0, 5, 0)
gh_mesh.user_geometry_set_vertex_color(mesh, index, 0, 1, 0, 1)
index = gh_mesh.user_geometry_add_vertex(mesh, 5, -5, 0)
gh_mesh.user_geometry_set_vertex_color(mesh, index, 0, 0, 1, 1)
-- Step 2: the faces
--
gh_mesh.user_geometry_add_face(mesh, 0, 1, 2)
-- Step 3: build the mesh
--
gh_mesh.build(mesh)
gh_mesh.set_vertex_position
Sets the relative position of a particular vertex.
: Lua - Python
object_id [INTEGER]: Object identifier.
vertex_index [INTEGER]: index of the vertex between 0 and gh_object.get_num_vertices()-1.
x, y, z [REAL]: 3D position
:
vertex_index = 0
gh_mesh.set_vertex_position(mesh, vertex_index, x, y, z)
gh_mesh.get_vertex_position
Gets the relative position of a particular vertex.
: Lua - Python
object_id [INTEGER]: Object identifier.
vertex_index [INTEGER]: index of the vertex between 0 and gh_object.get_num_vertices()-1.
x, y, z [REAL]: 3D position
:
vertex_index = 0
x, y, z = gh_mesh.get_vertex_position(mesh, vertex_index)
gh_mesh.get_vertex_absolute_position
Gets the absolute position of a particular vertex.
: Lua - Python
object_id [INTEGER]: Object identifier.
vertex_index [INTEGER]: index of the vertex between 0 and gh_object.get_num_vertices()-1.
x, y, z [REAL]: 3D position
:
vertex_index = 0
x, y, z = gh_mesh.get_vertex_absolute_position(mesh, vertex_index)
gh_mesh.set_vertex_color
Sets the RGBA color of a particular vertex.
: Lua - Python
object_id [INTEGER]: Object identifier.
vertex_index [INTEGER]: index of the vertex between 0 and gh_object.get_num_vertices()-1.
r, g, b, a [REAL]: rgba color of the vertex
:
vertex_index = 0
gh_mesh.set_vertex_color(mesh, vertex_index, r, g, b, a)
gh_mesh.get_vertex_color
Gets the RGBA color of a particular vertex.
: Lua - Python
object_id [INTEGER]: Object identifier.
vertex_index [INTEGER]: index of the vertex between 0 and gh_object.get_num_vertices()-1.
r, g, b, a [REAL]: rgba color of the vertex
:
vertex_index = 0
r, g, b, a = gh_mesh.get_vertex_color(mesh, vertex_index)
gh_mesh.set_vertex_normal
Sets the normal vector of a particular vertex.
: Lua - Python
object_id [INTEGER]: Object identifier.
vertex_index [INTEGER]: index of the vertex between 0 and gh_object.get_num_vertices()-1.
x, y, z [REAL]: normal vector
:
vertex_index = 0
gh_mesh.set_vertex_normal(mesh, vertex_index, x, y, z)
gh_mesh.get_vertex_normal
Gets the normal vector of a particular vertex.
: Lua - Python
object_id [INTEGER]: Object identifier.
vertex_index [INTEGER]: index of the vertex between 0 and gh_object.get_num_vertices()-1.
x, y, z [REAL]: normal vector
:
vertex_index = 0
x, y, z = gh_mesh.get_vertex_normal(mesh, vertex_index)
gh_mesh.set_vertex_tangent
Sets the tangent vector of a particular vertex.
: Lua - Python
object_id [INTEGER]: Object identifier.
vertex_index [INTEGER]: index of the vertex between 0 and gh_object.get_num_vertices()-1.
x, y, z, w [REAL]: tangent vector
:
vertex_index = 0
gh_mesh.set_vertex_tangent(mesh, vertex_index, x, y, z, w)
gh_mesh.get_vertex_tangent
Gets the tangent vector of a particular vertex.
: Lua - Python
object_id [INTEGER]: Object identifier.
vertex_index [INTEGER]: index of the vertex between 0 and gh_object.get_num_vertices()-1.
x, y, z, w [REAL]: tangent vector
:
vertex_index = 0
x, y, z, w = gh_mesh.get_vertex_tangent(mesh, vertex_index)
gh_mesh.set_vertex_uv
Sets the texcoord of a particular vertex.
: Lua - Python
object_id [INTEGER]: Object identifier.
vertex_index [INTEGER]: index of the vertex between 0 and gh_object.get_num_vertices()-1.
x, y, z, w [REAL]: texcoord
texture_unit [INTEGER]: texture unit of the texcoord set. Only two sets are supported.
:
vertex_index = 0
texture_unit = 0
gh_mesh.set_vertex_uv(mesh, vertex_index, x, y, z, w, texture_unit)
gh_mesh.get_vertex_uv
Gets the texcoord of a particular vertex.
: Lua - Python
object_id [INTEGER]: Object identifier.
vertex_index [INTEGER]: index of the vertex between 0 and gh_object.get_num_vertices()-1.
texture_unit [INTEGER]: texture unit of the texcoord set. Only two sets are supported.
x, y, z, w [REAL]: tangent vector
:
vertex_index = 0
texture_unit = 0
x, y, z, w = gh_mesh.get_vertex_uv(mesh, vertex_index, texture_unit)
gh_mesh.set_face_vertex_indices
Sets the vertex indices of a particular face.
: Lua - Python
object_id [INTEGER]: Object identifier.
face_index [INTEGER]: index of the vertex between 0 and gh_object.get_num_vertices()-1.
a, b, c [INTEGER]: vertex indices
:
gh_mesh.set_face_vertex_indices(mesh, face_index, a, b, c)
gh_mesh.get_face_vertex_indices
Gets the vertex indices of a particular face.
: Lua - Python
object_id [INTEGER]: Object identifier.
face_index [INTEGER]: index of the vertex between 0 and gh_object.get_num_vertices()-1.
a, b, c [INTEGER]: vertex indices
:
a, b, c = gh_mesh.get_face_vertex_indices(mesh, face_index)
|