raea/transform

Where things are: Bevy's Transform and Quat, and nesting.

View as Markdown

Transform and Quat are Bevy's, with Bevy's methods: Transform.fromXyz(...), .lookingAt(...), .withRotation(...), Quat.fromEuler(...) and the rest. Every 3D component takes a transform, and children of an entity are placed relative to it.

TS
import { Quat, Transform } from "raea/transform";

const camera = Transform.fromXyz(0, 1.6, 5).lookingAt([0, 0.5, 0]);
const turned = Transform.IDENTITY.withRotation(Quat.fromEuler("XYZ", 0, Math.PI / 4, 0));
TS
import { eulerOf, Quat, surfaceTurn, Transform } from "raea/transform"

raea/transform exports 2 functions, 2 values, 4 types. Bevy's counterpart: bevy_transform. Source: sdk/raea/src/transform.ts.

Functions

eulerOf

A part's Euler angles of a quaternion: a composition's rotation [x, y, z] is composed as three.js composes it, Quat::from_euler(EulerRot::XYZ, x, y, z) (runtime/scene local; the YXZ rot_x/rot_y/rot_z of raea-render's rows are read back from the world matrix), so this is that order's inverse.

TS
function eulerOf(q: [number, number, number, number]): Vec3

Used in: 3d/3d_scene, shader_advanced/compute_mesh, shader_advanced/custom_render_phase.

surfaceTurn

The turn that takes +y to normal, with the picture's top (a decal's -z) toward world up on a wall, toward -z on a floor, turned spin about the normal: a quaternion [x, y, z, w].

TS
function surfaceTurn(normal: Vec3, spin?: number): [number, number, number, number]

Values

Quat

A rotation as glam's Quat: [x, y, z, w]. glam's Quat constructors, by their Rust names in camelCase.

Used in: ui/render_ui_to_texture, 3d/3d_shapes, 3d/texture, 3d/shadow_caster_receiver, 3d/split_screen, 3d/spotlight, 3d/mesh_ray_cast, 3d/3d_scene, and 23 more.

Transform

Bevy's Transform: the component's handle for a program (with(Transform, Transform.fromXyz(1, 0, 0))) and its builders for a scene (<Mesh3d transform={Transform.fromXyz(0, 1, 0)}>).

Used in: ui/render_ui_to_texture, ui/widgets/viewport_node, 3d/fog_volumes, 3d/fog, 3d/vertex_colors, 3d/rotate_environment_map, 3d/transparency_3d, 3d/spherical_area_lights, and 71 more.

Types

EulerRot

glam's EulerRot, the intrinsic orders: "YXZ" turns about Y, then the turned X, then the turned Z.

TS
type EulerRot = "XYZ" | "XZY" | "YXZ" | "YZX" | "ZXY" | "ZYX"

TransformBuilt

A Transform built with Bevy's builders: each returns a new one.

FieldTypeWhat it is
withTranslation (required)(v: Vec3) => TransformBuiltthe same transform, moved to v
withRotation (required)(q: Quat) => TransformBuiltthe same transform, turned to q
withScale (required)(s: number | Vec3) => TransformBuiltthe same transform, scaled to s (one number for all three axes)
lookingAt (required)(target: Vec3, up?: Vec3 | undefined) => TransformBuiltthe same transform, turned so its -Z faces target with up (+Y) up, as Bevy's looking_at
translation (required)Vec3where it is, metres (x, y, z)
rotation (required)Quatits rotation as a quaternion [x, y, z, w]
scale (required)Vec3its scale along x, y and z

TransformValue

A Transform's value, as Bevy reflects it.

FieldTypeWhat it is
translationVec3where it is, metres (x, y, z)
rotationQuatits rotation as a quaternion [x, y, z, w]
scaleVec3its scale along x, y and z

Vec3

TS
type Vec3 = [number, number, number]