vkf_model Module

3D models: a model file (3ds, obj, glTF, ... through vsgXchange) in a frame, as OpenFrames' Model.

The model is placed in its frame by its own transform: translate(model_position) * rotate(model_attitude) * scale(model_scale) * translate(-model_pivot), so e.g. the pivot can be the model's center (model_bound) and the scale can size it.


Uses

  • module~~vkf_model~~UsesGraph module~vkf_model vkf_model iso_c_binding iso_c_binding module~vkf_model->iso_c_binding module~vkf_frames vkf_frames module~vkf_model->module~vkf_frames module~vkf_layer vkf_layer module~vkf_model->module~vkf_layer module~vkf_math vkf_math module~vkf_model->module~vkf_math module~vkf_pick vkf_pick module~vkf_model->module~vkf_pick module~vkf_frames->iso_c_binding module~vkf_frames->module~vkf_layer module~vkf_frames->module~vkf_math module~vkf_frames->module~vkf_pick module~vkf_follower vkf_follower module~vkf_frames->module~vkf_follower module~vkf_geometry vkf_geometry module~vkf_frames->module~vkf_geometry module~vkf_text vkf_text module~vkf_frames->module~vkf_text module~vkf_trajectory vkf_trajectory module~vkf_frames->module~vkf_trajectory module~vkf_layer->iso_c_binding iso_fortran_env iso_fortran_env module~vkf_math->iso_fortran_env module~vkf_pick->module~vkf_math module~vkf_follower->module~vkf_math module~vkf_follower->module~vkf_trajectory module~vkf_geometry->iso_c_binding module~vkf_geometry->module~vkf_layer module~vkf_geometry->module~vkf_math module~vkf_text->iso_c_binding module~vkf_text->module~vkf_layer module~vkf_text->module~vkf_math module~vkf_files vkf_files module~vkf_text->module~vkf_files module~vkf_trajectory->iso_c_binding module~vkf_trajectory->module~vkf_math module~vkf_trajectory->iso_fortran_env

Used by

  • module~~vkf_model~~UsedByGraph module~vkf_model vkf_model module~vkframes vkframes module~vkframes->module~vkf_model

Interfaces

public interface Model

The Model constructor: Model(...) makes one (see new_model for its arguments).

  • private function new_model(name, file, color) result(m)

    A model frame named name (decorations of color color), with the model file file if given (see set_model).

    Arguments

    Type IntentOptional Attributes Name
    character(len=*), intent(in) :: name

    the frame's name

    character(len=*), intent(in), optional :: file

    model file (3ds, obj, glTF, ...)

    real(kind=wp), intent(in), optional :: color(:)

    [r, g, b] or [r, g, b, a] (0 to 1)

    Return Value type(Model)


Derived Types

type, public, extends(ReferenceFrame) ::  Model

A model (see the module documentation).

Components

Type Visibility Attributes Name Initial
real(kind=wp), private :: bound_center(3) = 0.0_wp

the model's bounding sphere: center (model coordinates)

real(kind=wp), private :: bound_radius = 0.0_wp

the model's bounding sphere: radius (0: unknown)

character(len=:), private, allocatable :: file

the model file (unallocated: none)

type(c_ptr), private :: model_ = c_null_ptr

the loaded model's node

real(kind=wp), private :: model_attitude_(4) = quat_identity

attitude in the frame (quaternion [x, y, z, w])

type(c_ptr), private :: model_node = c_null_ptr

transform of the model within the frame

real(kind=wp), private :: model_position_(3) = 0.0_wp

where the pivot is in the frame

real(kind=wp), private :: pivot_(3) = 0.0_wp

the model's point at model_position_ (model coordinates)

real(kind=wp), private :: scale_(3) = 1.0_wp

scale along the model's x, y, z

Constructor

The Model constructor: Model(...) makes one (see new_model for its arguments).

private function new_model (name, file, color)

A model frame named name (decorations of color color), with the model file file if given (see set_model).

Type-Bound Procedures

procedure, public :: add_child
procedure, public :: attitude
procedure, public :: axes_labels_shown
procedure, public :: axes_shown
procedure, public :: axis_label
procedure, public :: bound => model_frame_bound
procedure, public :: build_contents => model_build_contents
procedure, public :: child
procedure, public :: child_index
procedure, public :: color
procedure, public :: contents_shown
procedure, public :: detach
procedure, public :: follow
procedure, public :: follow_frame
procedure, public :: follower
procedure, public :: frame_info => model_frame_info
procedure, public :: frame_string
procedure, public :: has_light_source
procedure, public :: has_model
procedure, public :: is_following
procedure, public :: label_alignment
procedure, public :: label_font
procedure, public :: label_size
procedure, public :: late_update
procedure, public :: light_ambient
procedure, public :: light_diffuse
procedure, public :: light_source_enabled
procedure, public :: light_specular
procedure, public :: local_matrix
procedure, public :: local_matrix_at
procedure, public :: model_attitude
procedure, public :: model_bound
procedure, public :: model_file
procedure, public :: model_pivot
procedure, public :: model_position
procedure, public :: model_scale
procedure, public :: motion_key
procedure, public :: move_x_axis
procedure, public :: move_y_axis
procedure, public :: move_z_axis
procedure, public :: name
procedure, public :: name_label_on_top
procedure, public :: name_label_shown
procedure, public :: node
procedure, public :: num_children
procedure, public :: num_parents
procedure, public :: parent
procedure, public :: parent_index
procedure, public :: pick => model_pick
procedure, public :: pickable
procedure, public :: position
procedure, public :: position_of
procedure, public :: realize
procedure, public :: remove_child
procedure, public :: reposition_axes
procedure, public :: set_attitude
procedure, public :: set_color
procedure, public :: set_label_alignment
procedure, public :: set_label_font
procedure, public :: set_label_size
procedure, public :: set_light_ambient
procedure, public :: set_light_diffuse
procedure, public :: set_light_source_enabled
procedure, public :: set_light_specular
procedure, public :: set_model
procedure, public :: set_model_attitude
procedure, public :: set_model_pivot
procedure, public :: set_model_position
procedure, public :: set_model_scale
procedure, public :: set_name
procedure, public :: set_name_label_on_top
procedure, public :: set_pickable
procedure, public :: set_position
procedure, public :: set_x_label
procedure, public :: set_y_label
procedure, public :: set_z_label
procedure, public :: share_model
procedure, public :: show_axes
procedure, public :: show_axes_labels
procedure, public :: show_contents
procedure, public :: show_decorations
procedure, public :: show_name_label
procedure, public :: sync
procedure, public :: unfollow
procedure, public :: update
procedure, public :: world_matrix
procedure, public :: world_matrix_at

Functions

private pure function has_model(self)

True if a model was read (or shared).

Arguments

Type IntentOptional Attributes Name
class(Model), intent(in) :: self

Return Value logical

private pure function model_attitude(self) result(q)

Attitude of the model in its frame (quaternion [x, y, z, w]).

Arguments

Type IntentOptional Attributes Name
class(Model), intent(in) :: self

Return Value real(kind=wp), (4)

private function model_file(self) result(file)

The model file ('' if none).

Arguments

Type IntentOptional Attributes Name
class(Model), intent(in) :: self

Return Value character(len=:), allocatable

private function model_frame_info(self) result(info)

The kind of frame: 'Model'.

Arguments

Type IntentOptional Attributes Name
class(Model), intent(in) :: self

Return Value character(len=:), allocatable

private pure function model_pivot(self) result(p)

The model's pivot, in its own coordinates (see set_model_pivot).

Arguments

Type IntentOptional Attributes Name
class(Model), intent(in) :: self

Return Value real(kind=wp), (3)

private pure function model_position(self) result(p)

Where the model's pivot is placed in its frame (frame coordinates).

Arguments

Type IntentOptional Attributes Name
class(Model), intent(in) :: self

Return Value real(kind=wp), (3)

private pure function model_scale(self) result(s)

Scale along the model's x, y and z axes.

Arguments

Type IntentOptional Attributes Name
class(Model), intent(in) :: self

Return Value real(kind=wp), (3)

private function new_model(name, file, color) result(m)

A model frame named name (decorations of color color), with the model file file if given (see set_model).

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: name

the frame's name

character(len=*), intent(in), optional :: file

model file (3ds, obj, glTF, ...)

real(kind=wp), intent(in), optional :: color(:)

[r, g, b] or [r, g, b, a] (0 to 1)

Return Value type(Model)

private function set_model(self, file) result(ok)

Read the model file (now, so its bound is known). Returns false if it could not be read. Set it before a window first shows the model.

Arguments

Type IntentOptional Attributes Name
class(Model), intent(inout) :: self
character(len=*), intent(in) :: file

model file (3ds, obj, glTF, ...)

Return Value logical

private function share_model(self, other) result(ok)

Use the model already read by other (no second copy in memory).

Arguments

Type IntentOptional Attributes Name
class(Model), intent(inout) :: self
class(Model), intent(in) :: other

a model with its model read

Return Value logical


Subroutines

private subroutine model_bound(self, center, radius)

The model's bounding sphere, in the model's own coordinates (before its transform).

Arguments

Type IntentOptional Attributes Name
class(Model), intent(in) :: self
real(kind=wp), intent(out) :: center(3)

the bounding sphere, model coordinates

real(kind=wp), intent(out) :: radius

the bounding sphere, model coordinates

private subroutine model_build_contents(self, viewer, group)

The model under the model transform.

Arguments

Type IntentOptional Attributes Name
class(Model), intent(inout) :: self
type(c_ptr), intent(in) :: viewer

a window's viewer handle (null: headless)

type(c_ptr), intent(in) :: group

the group node to build under

private subroutine model_frame_bound(self, center, radius)

The model's bounding sphere in the frame (through the model transform).

Arguments

Type IntentOptional Attributes Name
class(Model), intent(in) :: self
real(kind=wp), intent(out) :: center(3)

the bounding sphere, frame coordinates (scene units)

real(kind=wp), intent(out) :: radius

the bounding sphere, frame coordinates (scene units)

private subroutine model_pick(self, cam, to_root, hits, n)

Picked on the model's bounding sphere (not its triangles); else at the frame's origin.

Arguments

Type IntentOptional Attributes Name
class(Model), intent(in), target :: self
type(PickCamera), intent(in) :: cam

the cursor's ray and the pick's settings

real(kind=wp), intent(in) :: to_root(4,4)

the frame's transform to the root frame

type(PickHit), intent(inout), allocatable :: hits(:)

hits so far (grown as needed)

integer, intent(inout) :: n

number of hits in hits

private subroutine set_model_attitude(self, q)

Attitude of the model in its frame (quaternion [x, y, z, w]).

Arguments

Type IntentOptional Attributes Name
class(Model), intent(inout) :: self
real(kind=wp), intent(in) :: q(4)

quaternion [x, y, z, w] (normalized here)

private subroutine set_model_pivot(self, pivot)

The point of the model (in its own coordinates) placed at model_position, about which it is rotated and scaled.

Arguments

Type IntentOptional Attributes Name
class(Model), intent(inout) :: self
real(kind=wp), intent(in) :: pivot(3)

(model coordinates)

private subroutine set_model_position(self, position)

Where the model's pivot is placed in its frame (frame coordinates).

Arguments

Type IntentOptional Attributes Name
class(Model), intent(inout) :: self
real(kind=wp), intent(in) :: position(3)

frame coordinates

private subroutine set_model_scale(self, scale)

Scale along the model's x, y and z axes.

Arguments

Type IntentOptional Attributes Name
class(Model), intent(inout) :: self
real(kind=wp), intent(in) :: scale(3)

along the model's x, y and z

private subroutine update_model_transform(self)

Give the model transform to its node (once built).

Arguments

Type IntentOptional Attributes Name
type(Model), intent(inout) :: self