Model geometry

To use this module, require it in a generator script:

require engine.gen_geometry.model_structures

The result of a [model_generator]: a ModelGeometry of meshes, materials and nodes, and the collider shapes of a model node. It also gives collider for a node of a csg scene. The module brings the [model_generator] annotation, as engine.gen_geometry.mesh_structures does.

Enumerations

AxisDirection

The axis of a cylinder or a capsule shape, in the space of its node.

Values:
  • XAxis = 0 - Along x

  • YAxis = 1 - Along y

  • ZAxis = 2 - Along z

ModelShapeKind

The kind of a ModelShape.

Values:
  • Box = 0 - A box, box_shape

  • Sphere = 1 - A sphere, sphere_shape

  • Cylinder = 2 - A cylinder, cylinder_shape

  • Capsule = 3 - A capsule, capsule_shape

  • Mesh = 4 - The triangles of all the meshes of the node, mesh_shape

  • Convex = 5 - The convex hull of all the meshes of the node, convex_shape

Structures

ModelMaterial

A material of a generated model: the standard_metallic_shader with these values, or a .material asset.

Fields:
  • name : string - Unique in the model; the name of the material resource

  • color : float4 = float4(1f,1f,1f,1f) - Albedo, sRGB like the color property of a material; alpha is the opacity of a transparent material

  • metalness : float = 0f - 0 dielectric, 1 metal

  • roughness : float = 0.5f - 0 mirror, 1 rough

  • twoSided : bool - Draws the back faces too

  • transparent : bool - Blends by the alpha of color

  • texture : string - An albedo texture asset, by the path request_texture takes; color tints it

  • asset : string - A .material asset, by the path request_material takes, used as is: of the fields above only name is used

ModelShape

A collider shape of a model node, in the space of the node. Make it with box_shape, sphere_shape, cylinder_shape, capsule_shape, mesh_shape or convex_shape.

Fields:
  • kind : ModelShapeKind - The kind of the shape

  • params : float3 - Box: the size; sphere: the radius; cylinder and capsule: the height, the radius and the AxisDirection

  • translation : float3 - The center of the shape

  • rotation : quat4 = quat4() - The rotation of the shape

ModelPart

A mesh of a node, drawn with a material.

Fields:
  • mesh : int - Index in ModelGeometry.meshes; a mesh with no triangles leaves the part out

  • material : int = -1 - Index in ModelGeometry.materials, -1 for the default material

ModelNode

A node of a generated model.

Fields:
  • name : string - The name of the scene node

  • parent : int = -1 - Index of an earlier node in ModelGeometry.nodes; -1 only for the root, node 0

  • position : float3 - Position relative to the parent

  • rotation : float4 = float4(0f,0f,0f,1f) - Rotation relative to the parent, a quaternion (x, y, z, w)

  • scale : float3 = float3(1f,1f,1f) - Scale relative to the parent

  • parts : array< ModelPart> - The meshes of the node. Each part left is a scene node of its own: child nodes go under the first part left, and a root with several parts left gets an empty parent

  • shapes : array< ModelShape> - The collider of the node, one shape or more; on the scene node of its first part left, or on the node itself when it has no parts left (a mesh or convex shape is dropped then). Empty: no collider

ModelGeometry

What a das [model_generator] function returns: a tree of nodes with meshes and materials. Such a function may return a csg Solid or a scene Node instead.

Fields:

Collider shapes

box_shape(size: float3 = float3(1f, 1f, 1f); translation: float3 = float3(0f, 0f, 0f); rotation: quat4 = quat4()): ModelShape

A box collider shape of a model node: size is its full size, translation its center in the space of the node.

Arguments:
  • size : float3

  • translation : float3

  • rotation : quat4

capsule_shape(radius: float = 0.5f; height: float = 2f; axis: AxisDirection = model_structures::AxisDirection.YAxis; translation: float3 = float3(0f, 0f, 0f); rotation: quat4 = quat4()): ModelShape

A capsule collider shape of a model node: height along axis, its center at translation in the space of the node.

Arguments:
  • radius : float

  • height : float

  • axis : AxisDirection

  • translation : float3

  • rotation : quat4

collider(n: Node; shape: ModelShape): Node

Adds a collider shape to a node of a csg scene, in the frame of the node. Several calls make one compound collider.

Arguments:
convex_shape(): ModelShape

A collider shape that is the convex hull of all the meshes of the node. A node has one mesh_shape or convex_shape at most.

cylinder_shape(radius: float = 0.5f; height: float = 2f; axis: AxisDirection = model_structures::AxisDirection.YAxis; translation: float3 = float3(0f, 0f, 0f); rotation: quat4 = quat4()): ModelShape

A cylinder collider shape of a model node: height along axis, its center at translation in the space of the node.

Arguments:
  • radius : float

  • height : float

  • axis : AxisDirection

  • translation : float3

  • rotation : quat4

mesh_shape(): ModelShape

A triangle mesh collider shape made from all the meshes of the node. A node has one mesh_shape or convex_shape at most.

sphere_shape(radius: float = 0.5f; translation: float3 = float3(0f, 0f, 0f)): ModelShape

A sphere collider shape of a model node, its center at translation in the space of the node.

Arguments:
  • radius : float

  • translation : float3