 Reference Guide Host-API Lua / Python
» Back to Homepage
» Back to Developer's Guide Index
gh_utils Library
gh_utils is the module that provides various utility functions.
Number of functions: 22
gh_utils.renderer_getptr
Gets the pointer to the renderer.
: Lua - Python
ID [INTEGER]: identifier of the current scene (core3d).
R_ptr [POINTER]: pointer to the underlying renderer.
:
R_ptr = gh_utils.renderer_getptr()
gh_utils.render_window_getptr
Gets the pointer to the render window. The render window is the object that makes the link between the renderer and the host application. In short, the renderer draw in the render window.
: Lua - Python
ID [INTEGER]: identifier of the current scene (core3d).
rw_ptr [POINTER]: pointer to the underlying render window.
:
R_ptr = gh_utils.renderer_getptr()
rw_ptr = gh_utils.render_window_getptr()
gh_utils.exe_script
Executes a script.
: Lua - Python
name [STRING]: Name of the script.
threaded [INTEGER]: Runs (1) the script in a separate system thread or not (0).
:
local threaded = 0
gh_utils.exe_script("init_meshes", threaded)
gh_utils.get_elapsed_time
Gets the elapsed time since the start of the current scene.
: Lua - Python
elapsed_time [REAL]: elapsed time in seconds.
:
elapsed_time = gh_utils.get_elapsed_time()
gh_utils.trace
Writes a trace in the log file and in the debug window.
: Lua - Python
str [STRING]: Trace to write.
:
gh_utils.trace("Hello world!")
gh_utils.font_getptr
Returns the pointer to a font node.
: Lua - Python
ID [INTEGER]: identifier of the current scene (core3d).
font [INTEGER]: font identifier.
font_ptr [POINTER]: Pointer on the font node.
:
font_ptr = gh_utils.font_getptr(ID, font)
gh_utils.font_create
Creates a new font.
: Lua - Python
font_name [STRING]: True type font name, ex: Arial, Verdana.
height [INTEGER]: font height.
font [INTEGER]: font identifier.
:
font = gh_utils.font_create("Arial", 14)
gh_utils.font_set_viewport_info
Sets the viewport information. You have to call this function when the window is resized.
: Lua - Python
font [INTEGER]: font identifier.
x, y [INTEGER]: viewport offsets.
width, height [INTEGER]: viewport size.
:
gh_utils.font_set_viewport_info(font, 0, 0, width, height)
gh_utils.font_set_viewport_info_ptr
Sets the viewport information. You have to call this function when the window is resized.
: Lua - Python
font_ptr [POINTER]: pointer on the font node.
x, y [INTEGER]: viewport offsets.
width, height [INTEGER]: viewport size.
:
gh_utils.font_set_viewport_info_ptr(font_ptr, 0, 0, width, height)
gh_utils.font_render
Renders (draws) a text.
: Lua - Python
font [INTEGER]: font identifier.
x, y [INTEGER]: X and Y start offsets in the current viewport.
r, g, b, a [REAL]: RGBA color of the text.
text [STRING]: text to render.
:
gh_utils.font_set_viewport_info(font, 0, 0, width, height)
gh_utils.font_render(font, 10, 40, 0.2, 1.0, 0.0, 1.0, string.format("Image filename: %s", texture_filename))
gh_utils.font_render_ptr
Renders (draws) a text.
: Lua - Python
R_ptr [POINTER]: pointer on the renderer.
rw_ptr [POINTER]: pointer on the render window.
font_ptr [POINTER]: pointer on the font node.
x, y [INTEGER]: X and Y start offsets in the current viewport.
r, g, b, a [REAL]: RGBA color of the text.
text [STRING]: text to render.
:
gh_utils.font_set_viewport_info_ptr(font_ptr, 0, 0, width, height)
gh_utils.font_render_ptr(R_ptr, rw_ptr, font_ptr, 10, 40, 0.2, 1.0, 0.0, 1.0, string.format("Image filename: %s", texture_filename))
gh_utils.font_render3d
Renders (draws) a text at a 3D position.
: Lua - Python
font [INTEGER]: font identifier.
x, y, z [REAL]: 3D position of the beginning of the text.
r, g, b, a [REAL]: RGBA color of the text.
text [STRING]: text to render.
:
gh_utils.font_render3d(font, 0, 20.0, -20.0, 0.2, 1.0, 0.0, 1.0, "V1")
gh_utils.font_render3d_ptr
Renders (draws) a text at a 3D position.
: Lua - Python
R_ptr [POINTER]: pointer on the renderer.
font_ptr [POINTER]: pointer on the font node.
x, y, z [REAL]: 3D position of the beginning of the text.
r, g, b, a [REAL]: RGBA color of the text.
text [STRING]: text to render.
:
gh_utils.font_render3d_ptr(R_ptr, font_ptr, 0, 20.0, -20.0, 0.2, 1.0, 0.0, 1.0, "V1")
gh_utils.thread_sleep
Allows to pause the current thread.
: Lua - Python
delay [INTEGER]: pause delay in milliseconds.
:
gh_utils.thread_sleep(2000)
gh_utils.get_scenegraph_dir
Gets the directory of the current scene file.
: Lua - Python
dir [STRING]: directory of the current scene file.
:
demo_dir = gh_utils.get_scenegraph_dir()
gh_utils.is_64bit
Checks if the host application is a 64-bit or a 32-bit application.
: Lua - Python
state [INTEGER]: 1 for 64-bit and 0 otherwise.
:
app_64bit = gh_utils.is_64bit()
gh_utils.random
Returns a random floating point number between 0.0 and 1.0.
: Lua - Python
x [REAL]: randon number.
:
local x = gh_utils.random()
local y = gh_utils.random()
local z = gh_utils.random()
gh_utils.drop_files_get_num_files
Windows only - Returns the number of files that have been dropped on the application. This function is useful in a DRAG_N_DROP script.
: Lua - Python
num_files [INTEGER]: number of dropped files
:
num_files = gh_utils.drop_files_get_num_files()
gh_utils.drop_files_get_file_by_index
Windows only - Returns the name of a particular file that has been dropped on the application. This function is useful in a DRAG_N_DROP script.
: Lua - Python
index [INTEGER]: index of the file: from 0 to drop_files_get_num_files()-1.
filename [STRING]: name of a dropped file
:
num_files = gh_utils.drop_files_get_num_files()
if (num_files > 0) then
-- Gets the first dropped file:
filename = gh_utils.drop_files_get_file_by_index(0)
end
gh_utils.set_progress_bar_percent
Sets the progress bar size in percent of the current window width. Coupled with gh_renderer.display_progress_bar(), these functions can be used in an INIT script to draw a progress bar while loading data.
: Lua - Python
percent [REAL]: size of the progress bar: 100% means the window width.
:
gh_utils.set_progress_bar_percent(20)
gh_renderer.display_progress_bar()
...
... do some stuff
...
gh_utils.set_progress_bar_percent(60)
gh_renderer.display_progress_bar()
...
... do some stuff
...
gh_utils.set_progress_bar_percent(100)
gh_renderer.display_progress_bar()
gh_utils.set_progress_bar_caption
Sets the caption (or title) of the progress bar.
: Lua - Python
caption [STRING]: title of the progress bar.
:
gh_utils.set_progress_bar_caption("Loading scene data...")
gh_utils.set_progress_bar_percent(20)
gh_renderer.display_progress_bar()
gh_utils.do_screenshot
Does a screenshot and write it to a file (JPEG file).
: Lua - Python
filename [STRING]: name of the screenshot file.
is_absolute_path [INTEGER]: specifies whether the filename is absolute or relative to the main demo XML script.
:
gh_utils.do_screenshot("image.jpg", 0)
|