lv_gltf.h

Defines

LV_GLTF_DEFAULT_CAMERA
LV_GLTF_ANIM_SPEED_TENTH
LV_GLTF_ANIM_SPEED_QUARTER
LV_GLTF_ANIM_SPEED_HALF
LV_GLTF_ANIM_SPEED_NORMAL
LV_GLTF_ANIM_SPEED_2X
LV_GLTF_ANIM_SPEED_3X
LV_GLTF_ANIM_SPEED_4X

Typedefs

typedef lv_3dplane_t lv_3dray_t

Enums

enum lv_gltf_aa_mode_t

Values:

enumerator LV_GLTF_AA_MODE_OFF
enumerator LV_GLTF_AA_MODE_ON

Anti aliasing off

enumerator LV_GLTF_AA_MODE_DYNAMIC

Anti aliasing on

enum lv_gltf_bg_mode_t

Values:

enumerator LV_GLTF_BG_MODE_SOLID
enumerator LV_GLTF_BG_MODE_ENVIRONMENT

Solid background. Use lv_obj_set_style_bg_color to set the background color

Functions

lv_obj_t *lv_gltf_create(lv_obj_t *parent)

Create a glTF object

Parameters:

parent – pointer to the parent object

Returns:

pointer to the created glTF object

void lv_gltf_set_environment(lv_obj_t *obj, lv_gltf_environment_t *environment)

Assign an environment to a glTF object for IBL rendering

Note

The environment can be shared across multiple glTF objects

Note

If no environment is set before attempting to load a file, a default one will be created for you

Parameters:
  • obj – pointer to a glTF viewer object

  • environment – pointer to the environment to use

lv_gltf_model_t *lv_gltf_load_model_from_file(lv_obj_t *obj, const char *path)

Load a glTF model from a file into the viewer

Parameters:
  • obj – pointer to a glTF viewer object

  • path – file path to the glTF model to load

Returns:

pointer to the loaded glTF model, or NULL on failure

size_t lv_gltf_get_model_count(lv_obj_t *obj)

Get the number of models loaded in the glTF viewer

Parameters:

obj – pointer to a glTF viewer object

Returns:

the total number of models in the viewer

lv_gltf_model_t *lv_gltf_get_model_by_index(lv_obj_t *obj, size_t id)

Get a specific model by its index

Parameters:
  • obj – pointer to a glTF viewer object

  • id – index of the model to retrieve (0-based)

Returns:

pointer to the model at the specified index, or NULL if index is invalid

lv_gltf_model_t *lv_gltf_get_primary_model(lv_obj_t *obj)

Get the primary model from the glTF viewer The primary model is the first model added to the viewer and can be used for camera selection and other primary operations

Parameters:

obj – pointer to a glTF viewer object

Returns:

pointer to the primary model, or NULL if no models are loaded

void lv_gltf_set_yaw(lv_obj_t *obj, float yaw)

Set the yaw (horizontal rotation) of the camera

Parameters:
  • obj – pointer to a glTF viewer object

  • yaw – yaw angle in degrees

float lv_gltf_get_yaw(const lv_obj_t *obj)

Get the yaw (horizontal rotation) of the camera

Parameters:

obj – pointer to a glTF viewer object

Returns:

yaw angle in degrees

void lv_gltf_set_pitch(lv_obj_t *obj, float pitch)

Set the pitch (vertical rotation) of the camera

Parameters:
  • obj – pointer to a glTF viewer object

  • pitch – pitch angle in degrees

float lv_gltf_get_pitch(const lv_obj_t *obj)

Get the pitch (vertical rotation) of the camera

Parameters:

obj – pointer to a glTF viewer object

Returns:

pitch angle in degrees

void lv_gltf_set_distance(lv_obj_t *obj, float value)

Set the camera distance from the focal point

Parameters:
  • obj – pointer to a glTF viewer object

  • value – distance value

float lv_gltf_get_distance(const lv_obj_t *obj)

Get the camera distance scale factor from the focal point

Parameters:

obj – pointer to a glTF viewer object

Returns:

distance scaling factor value

float lv_gltf_get_world_distance(const lv_obj_t *obj)

Get the camera distance from the focal point in world units

Parameters:

obj – pointer to a GLTF viewer object

Returns:

world unit distance value

void lv_gltf_set_fov(lv_obj_t *obj, float value)

Set the field of view

Parameters:
  • obj – pointer to a glTF viewer object

  • value – vertical FOV in degrees. If zero, the view will be orthographic (non-perspective)

float lv_gltf_get_fov(const lv_obj_t *obj)

Get the field of view

Parameters:

obj – pointer to a glTF viewer object

Returns:

vertical FOV in degrees

void lv_gltf_set_focal_x(lv_obj_t *obj, float value)

Set the X coordinate of the camera focal point

Parameters:
  • obj – pointer to a glTF viewer object

  • value – X coordinate

float lv_gltf_get_focal_x(const lv_obj_t *obj)

Get the X coordinate of the camera focal point

Parameters:

obj – pointer to a glTF viewer object

Returns:

X coordinate

void lv_gltf_set_focal_y(lv_obj_t *obj, float value)

Set the Y coordinate of the camera focal point

Parameters:
  • obj – pointer to a glTF viewer object

  • value – Y coordinate

float lv_gltf_get_focal_y(const lv_obj_t *obj)

Get the Y coordinate of the camera focal point

Parameters:

obj – pointer to a glTF viewer object

Returns:

Y coordinate

void lv_gltf_set_focal_z(lv_obj_t *obj, float value)

Set the Z coordinate of the camera focal point

Parameters:
  • obj – pointer to a glTF viewer object

  • value – Z coordinate

float lv_gltf_get_focal_z(const lv_obj_t *obj)

Get the Z coordinate of the camera focal point

Parameters:

obj – pointer to a glTF viewer object

Returns:

Z coordinate

void lv_gltf_recenter(lv_obj_t *obj, lv_gltf_model_t *model)

Set the focal coordinates to the center point of the model object

Parameters:
  • obj – pointer to a glTF viewer object

  • model – a model attached to this viewer or NULL for the first model

void lv_gltf_set_camera(lv_obj_t *obj, uint32_t value)

Set the active camera index The camera is selected from the first glTF model added to the viewer

Note

Values higher than the scene's camera count will be clamped to the maximum available camera index

Parameters:
  • obj – pointer to a glTF viewer object

  • value – camera index (0 for default camera, 1+ for scene camera index)

uint32_t lv_gltf_get_camera(const lv_obj_t *obj)

Get the active camera index

Parameters:

obj – pointer to a glTF viewer object

Returns:

active camera index

uint32_t lv_gltf_get_camera_count(const lv_obj_t *obj)

Get the number of cameras in the first glTF model added to the viewer This count represents the valid range for the camera index parameter used with lv_gltf_set_camera()

To get the camera count of other models, call lv_gltf_model_get_camera_count(model) directly with the specific model

Parameters:

obj – pointer to a glTF viewer object

Returns:

number of available cameras

void lv_gltf_set_animation_speed(lv_obj_t *obj, uint32_t value)

Set the animation speed ratio

The actual ratio is the value parameter / LV_GLTF_ANIM_SPEED_NORMAL Values greater than LV_GLTF_ANIM_SPEED_NORMAL will speed-up the animation Values less than LV_GLTF_ANIM_SPEED_NORMAL will slow down the animation

Parameters:
  • obj – pointer to a glTF viewer object

  • value – speed-up ratio of the animation

uint32_t lv_gltf_get_animation_speed(const lv_obj_t *obj)

Get the animation speed ratio

The actual ratio is the return value / LV_GLTF_ANIM_SPEED_NORMAL

Parameters:

obj – pointer to a glTF viewer object

void lv_gltf_set_background_mode(lv_obj_t *obj, lv_gltf_bg_mode_t value)

Set the background mode

Parameters:
  • obj – pointer to a glTF viewer object

  • value – background mode

lv_gltf_bg_mode_t lv_gltf_get_background_mode(const lv_obj_t *obj)

Get the background mode

Parameters:

obj – pointer to a glTF viewer object

Returns:

background mode

void lv_gltf_set_background_blur(lv_obj_t *obj, uint32_t value)

Set the background blur amount

Parameters:
  • obj – pointer to a glTF viewer object

  • value – blur amount between 0 and 100

uint32_t lv_gltf_get_background_blur(const lv_obj_t *obj)

Get the background blur amount

Parameters:

obj – pointer to a glTF viewer object

Returns:

blur amount between 0 and 100

void lv_gltf_set_env_brightness(lv_obj_t *obj, uint32_t value)

Set the environmental brightness/power

Parameters:
  • obj – pointer to a glTF viewer object

  • value – brightness multiplier

uint32_t lv_gltf_get_env_brightness(const lv_obj_t *obj)

Get the environmental brightness/power

Parameters:

obj – pointer to a glTF viewer object

Returns:

brightness multiplier

void lv_gltf_set_image_exposure(lv_obj_t *obj, float value)

Set the image exposure level

Parameters:
  • obj – pointer to a glTF viewer object

  • value – exposure level (1.0 is default)

float lv_gltf_get_image_exposure(const lv_obj_t *obj)

Get the image exposure level

Parameters:

obj – pointer to a glTF viewer object

Returns:

exposure level

void lv_gltf_set_antialiasing_mode(lv_obj_t *obj, lv_gltf_aa_mode_t value)

Set the anti-aliasing mode

Parameters:
  • obj – pointer to a glTF viewer object

  • value – anti-aliasing mode

lv_gltf_aa_mode_t lv_gltf_get_antialiasing_mode(const lv_obj_t *obj)

Get the anti-aliasing mode

Parameters:

obj – pointer to a glTF viewer object

Returns:

anti-aliasing mode

lv_3dplane_t lv_gltf_get_current_view_plane(lv_obj_t *obj, float distance)

Get a plane that faces the current view camera, centered some units in front of it

Parameters:
  • obj – pointer to a GLTF viewer object

  • distance – distance in front of the camera to set the plane, in world units. see lv_gltf_get_world_distance to get the auto-distance

Returns:

camera facing plane

lv_3dplane_t lv_gltf_get_ground_plane(float elevation)

Get a plane that faces upward, centered at a given height

Parameters:
  • obj – pointer to a GLTF viewer object

  • elevation – elevation of the ground plane, in world units. this is usually zero

Returns:

ground plane

lv_3dray_t lv_gltf_get_ray_from_2d_coordinate(lv_obj_t *obj, const lv_point_t *screen_pos)

Calculates a ray originating from the camera and passing through the specified mouse position on the screen.

Parameters:
  • obj – pointer to a GLTF viewer object

  • screen_pos – screen co-ordinate, in pixels

Returns:

mouse point ray

lv_result_t lv_gltf_intersect_ray_with_plane(const lv_3dray_t *ray, const lv_3dplane_t *plane, lv_3dpoint_t *collision_point)

Get the point that a given ray intersects with a specified plane at, if any

Parameters:
  • ray – the intersection test ray

  • screen_y – the plane to test ray intersection with

  • collision_point – output lv_3dpoint_t holder, values are only valid if true is the return value

Returns:

LV_RESULT_OK if intersection, LV_RESULT_INVALID if no intersection

lv_result_t lv_gltf_world_to_screen(lv_obj_t *obj, const lv_3dpoint_t world_pos, lv_point_t *screen_pos)

Get the screen position of a 3d point

Parameters:
  • obj – pointer to a GLTF viewer object

  • world_pos – world position to convert

  • lv_point_t – the resulting point, in pixels. only valid if return value is true

Returns:

LV_RESULT_OK if conversion valid, LV_RESULT_INVALID if no valid conversion

struct lv_3dpoint_t

Public Members

float x
float y
float z
struct lv_3dplane_t

Public Members

lv_3dpoint_t origin
lv_3dpoint_t direction