Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

5.7 KB
Raw Blame

title: "raea/transform" summary: "Where things are: Bevy's Transform and Quat, and nesting." order: 67 sources: ["sdk/raea/src/transform.ts"]

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.

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));
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.

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].

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 24 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 72 more.

Types

EulerRot

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

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

TransformBuilt

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

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

TransformValue

A Transform's value, as Bevy reflects it.

Field Type What it is
translation Vec3 where it is, metres (x, y, z)
rotation Quat its rotation as a quaternion [x, y, z, w]
scale Vec3 its scale along x, y and z

Vec3

type Vec3 = [number, number, number]