Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/flo-bit/shapecraft. flo-bit.dev/shapecraft
Something went wrong. Try again.
1.3 kB · 38 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839import * as THREE from 'three'import type { Vec3, ColorInput } from './types'
export function vec3(x: number, y: number, z: number): THREE.Vector3 { return new THREE.Vector3(x, y, z)}
export function mat4(): THREE.Matrix4 { return new THREE.Matrix4()}
export function makeTranslation(x: number, y: number, z: number): THREE.Matrix4 { return new THREE.Matrix4().makeTranslation(x, y, z)}
export function makeRotation(axis: Vec3 | 'x' | 'y' | 'z', angle: number): THREE.Matrix4 { let axisVec: THREE.Vector3 if (axis === 'x') axisVec = new THREE.Vector3(1, 0, 0) else if (axis === 'y') axisVec = new THREE.Vector3(0, 1, 0) else if (axis === 'z') axisVec = new THREE.Vector3(0, 0, 1) else axisVec = new THREE.Vector3(axis[0], axis[1], axis[2]).normalize() return new THREE.Matrix4().makeRotationAxis(axisVec, angle)}
export function makeScale(x: number, y: number, z: number): THREE.Matrix4 { return new THREE.Matrix4().makeScale(x, y, z)}
export function parseColor(input: ColorInput): THREE.Color { if (typeof input === 'number') { return new THREE.Color(input) } if (typeof input === 'string') { return new THREE.Color(input) } // Vec3 or Vec4 — rgb values 0-1 return new THREE.Color(input[0], input[1], input[2])}