lecodes-sdk 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/global.d.ts +18 -4
- package/dist/inject.js +260 -361
- package/dist/types/animate/tween/Animation.d.ts +69 -0
- package/dist/types/animate/tween/Timeline.d.ts +55 -0
- package/dist/types/animate/tween/animateValue.d.ts +27 -0
- package/dist/types/animate/tween/easing.d.ts +29 -0
- package/dist/types/animate/tween/spec.d.ts +178 -0
- package/dist/types/g2/Node2D.d.ts +16 -0
- package/dist/types/g2/Sprite.d.ts +11 -1
- package/dist/types/gl/Camera.d.ts +15 -1
- package/dist/types/gl/Foliage.d.ts +47 -0
- package/dist/types/gl/Geometry.d.ts +24 -0
- package/dist/types/gl/Light.d.ts +28 -7
- package/dist/types/gl/Lightmap.d.ts +90 -60
- package/dist/types/gl/Material.d.ts +28 -20
- package/dist/types/gl/Model.d.ts +7 -5
- package/dist/types/gl/Node.d.ts +18 -0
- package/dist/types/gl/Particles.d.ts +55 -1
- package/dist/types/gl/Scene.d.ts +20 -0
- package/dist/types/gl/animation/AnimationClip.d.ts +19 -0
- package/dist/types/gl/animation/Animator.d.ts +27 -0
- package/dist/types/gl/animation/DynamicBone.d.ts +19 -8
- package/dist/types/gl/animation/IK.d.ts +86 -30
- package/dist/types/gl/animation/Locomotion.d.ts +52 -3
- package/dist/types/gl/animation/Warp.d.ts +2 -1
- package/dist/types/gl/animation/core.d.ts +35 -4
- package/dist/types/gl/physics/Ragdoll.d.ts +87 -12
- package/dist/types/gl/terrain/Terrain.d.ts +12 -2
- package/dist/types/inject.d.ts +8 -2
- package/dist/types/runtime/input.d.ts +7 -0
- package/dist/types/scene/defineScene.d.ts +44 -32
- package/dist/types/ui/UIButton.d.ts +3 -1
- package/dist/types/ui/UIInput.d.ts +5 -1
- package/dist/types/ui/UINode.d.ts +24 -24
- package/dist/types.json +1 -1
- package/package.json +1 -1
- package/prompts/README.md +142 -142
- package/prompts/core-design.md +27 -4
- package/prompts/core.md +35 -6
- package/prompts/dist/2d-game.md +197 -408
- package/prompts/dist/3d-app.md +166 -491
- package/prompts/dist/ar-app.md +163 -373
- package/prompts/dist/design.md +87 -83
- package/prompts/dist/ui-app.md +136 -325
- package/prompts/select.ts +19 -4
- package/src/animate/tween/Animation.ts +378 -0
- package/src/animate/tween/Timeline.ts +175 -0
- package/src/animate/tween/animateValue.ts +100 -0
- package/src/animate/tween/easing.ts +172 -0
- package/src/animate/tween/spec.ts +479 -0
- package/src/audio/audio.ts +161 -161
- package/src/bridges.d.ts +235 -65
- package/src/compile/__tests__/assetMacro.test.ts +26 -0
- package/src/compile/__tests__/detectEntry.test.ts +19 -0
- package/src/compile/__tests__/serverSplit.test.ts +27 -0
- package/src/compile/bundler.ts +34 -4
- package/src/compile/compileProject.ts +31 -1
- package/src/compile/detectEntry.ts +8 -3
- package/src/compile/index.ts +2 -0
- package/src/compile/serverSplit.ts +9 -3
- package/src/g2/Node2D.ts +38 -0
- package/src/g2/Sprite.ts +20 -1
- package/src/gl/Camera.ts +34 -1
- package/src/gl/CameraPlace.ts +52 -52
- package/src/gl/Foliage.ts +102 -0
- package/src/gl/Geometry.ts +393 -348
- package/src/gl/Light.ts +49 -16
- package/src/gl/Lightmap.ts +439 -275
- package/src/gl/Material.ts +59 -47
- package/src/gl/Mesh.ts +120 -120
- package/src/gl/Model.ts +23 -12
- package/src/gl/Node.ts +39 -0
- package/src/gl/Particles.ts +80 -2
- package/src/gl/Scene.ts +34 -1
- package/src/gl/animation/AnimationClip.ts +52 -0
- package/src/gl/animation/Animator.ts +42 -2
- package/src/gl/animation/DynamicBone.ts +35 -12
- package/src/gl/animation/IK.ts +173 -152
- package/src/gl/animation/Locomotion.ts +72 -8
- package/src/gl/animation/Playback.ts +5 -4
- package/src/gl/animation/Warp.ts +5 -2
- package/src/gl/animation/core.ts +65 -4
- package/src/gl/physics/Ragdoll.ts +451 -272
- package/src/gl/scenarios.ts +291 -291
- package/src/gl/terrain/Terrain.ts +33 -2
- package/src/inject.ts +236 -226
- package/src/runtime/input.ts +11 -0
- package/src/scene/defineScene.ts +72 -62
- package/src/scene/gizmos.ts +148 -148
- package/src/ui/UIButton.ts +2 -2
- package/src/ui/UIInput.ts +3 -3
- package/src/ui/UINode.ts +61 -36
- package/dist/types/animate/animate.d.ts +0 -20
- package/src/animate/animate.ts +0 -238
package/src/ui/UINode.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { FetchResponse } from "../runtime/fetch"
|
|
2
2
|
import { createBinding, disposeBinding } from "../core/signals"
|
|
3
|
+
import type { Animation } from "../animate/tween/Animation"
|
|
4
|
+
import { CLOCK_UI, DOM_UI, KIND_DISCRETE, KIND_TRANSFORM, KIND_TRANSFORM_MATRIX, parseTransformList, uiValue, type TweenChannel, type TweenMeta } from "../animate/tween/spec"
|
|
5
|
+
import { tweenBag } from "../animate/tween/Timeline"
|
|
3
6
|
|
|
4
7
|
export interface UINode {
|
|
5
8
|
readonly type: string
|
|
@@ -330,8 +333,13 @@ const classHandler: ProxyHandler<any> = {
|
|
|
330
333
|
* static — bindings are extracted at the top level only. */
|
|
331
334
|
export type Reactive<T> = { [K in keyof T]: NonNullable<T[K]> extends object ? T[K] : T[K] | (() => T[K]) }
|
|
332
335
|
|
|
336
|
+
/** The curve of a state block's swap (`$class` / `onPressed` / `onFocused` with a `duration`): a
|
|
337
|
+
* curve name (`outCubic`, `inOutSine`, `smoothstep` — the default — …), `cubic-bezier(x1,y1,x2,y2)`
|
|
338
|
+
* or `steps(n)`. A function cannot ride a style block; use `animateTo` for those. */
|
|
339
|
+
export type LayerEasing = string
|
|
340
|
+
|
|
333
341
|
/** User-defined style classes: any `$`-prefixed key in `.style()` declares a state block toggled
|
|
334
|
-
* from code via the `el.class` proxy; `duration`/`delay` animate the swap. Class state INHERITS
|
|
342
|
+
* from code via the `el.class` proxy; `duration`/`delay`/`easing` animate the swap. Class state INHERITS
|
|
335
343
|
* down the tree (CSS-`.dark`-on-body style): a class set on a node also activates same-name `$`
|
|
336
344
|
* blocks on all descendants within the same root (docs/style-class-cascade-plan.md).
|
|
337
345
|
* `$pressed`/`$focused` are reserved — hosts toggle them on press/focus (they beat other
|
|
@@ -340,7 +348,7 @@ export type Reactive<T> = { [K in keyof T]: NonNullable<T[K]> extends object ? T
|
|
|
340
348
|
* Instantiated with the node's FULL style `T` — a class block accepts everything the node's
|
|
341
349
|
* `.style()` does, like `onLandscape`. Narrowing it wrongly rejects valid props such as
|
|
342
350
|
* `$active: { color }`; guarded by tests/ui-types.test.ts. */
|
|
343
|
-
export type ClassStyles<T> = { [key: `$${string}`]: T & { duration?: number, delay?: number } }
|
|
351
|
+
export type ClassStyles<T> = { [key: `$${string}`]: T & { duration?: number, delay?: number, easing?: LayerEasing } }
|
|
344
352
|
|
|
345
353
|
/** Value accepted by a `el.class` write: a boolean sets the class, a `() => boolean` binds it —
|
|
346
354
|
* the class then tracks the signals the function reads (re-evaluated on change). Reads through
|
|
@@ -425,28 +433,15 @@ export type StyleFn <R, T extends object> = ((style: Reactive<T> & OrientationSt
|
|
|
425
433
|
* installs a reactive binding). */
|
|
426
434
|
export type Style <R, T extends object> = StyleFn<R,T> & T & OrientationStyles<T> & ClassStyles<T>
|
|
427
435
|
|
|
428
|
-
/**
|
|
429
|
-
* (
|
|
430
|
-
export type
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
/** `false` = animate without writing the targets into the element's style (e.g. a fade-out right before `.hide()`). */
|
|
438
|
-
commit?: boolean,
|
|
439
|
-
/** Repeat the animation: `true` = forever, a number = that many cycles. A looping animation is an
|
|
440
|
-
* effect, not a state change — it never commits, and the element ends back at its base style.
|
|
441
|
-
* The loop stops when a later `animateTo`/`animateFrom` runs on the element or it leaves the screen. */
|
|
442
|
-
loop?: boolean | number,
|
|
443
|
-
/** `"ping-pong"` (default) animates there and back each cycle — no jump. `"restart"` snaps back and
|
|
444
|
-
* replays forward — for full-turn spinners (`transform: "rotate(360deg)"`) and shimmers. Only meaningful with `loop`. */
|
|
445
|
-
loopMode?: "restart" | "ping-pong",
|
|
446
|
-
}) => R)
|
|
447
|
-
|
|
448
|
-
/** Meta keys of the animateTo/animateFrom options bag — everything that is not a style target. */
|
|
449
|
-
const ANIMATE_META = new Set(["duration", "delay", "layer", "commit", "loop", "loopMode"])
|
|
436
|
+
/** Style props of an animate bag: a single value (tween from the current value) or an array of
|
|
437
|
+
* KEYFRAMES (`opacity: [1, 0.3, 1]`, offsets via `times`). */
|
|
438
|
+
export type AnimateProps<T extends object> = { [K in keyof T]?: T[K] | T[K][] }
|
|
439
|
+
|
|
440
|
+
/** The `animateTo`/`animateFrom` surface: target style props (single values or keyframe arrays) plus
|
|
441
|
+
* the flat meta keys — `duration` / `delay` / `easing` / `times` / `loop` / `loopMode` / `commit` /
|
|
442
|
+
* `clock`, see {@link TweenMeta}. Returns the {@link Animation} handle (seek, rate, `finished`). */
|
|
443
|
+
export type AnimateStyle<R, T extends object> = ((style: AnimateProps<T> & TweenMeta) => Animation)
|
|
444
|
+
|
|
450
445
|
|
|
451
446
|
export type AppearStyle <R, T> = (arg: { from: T, duration?: number, delay?: number }) => R
|
|
452
447
|
export type DisappearStyle <R, T> = (arg: { to: T, duration?: number, delay?: number }) => R
|
|
@@ -518,20 +513,50 @@ export class Element<T extends string> {
|
|
|
518
513
|
}
|
|
519
514
|
|
|
520
515
|
/** Tween to the target style and commit it (unless `commit: false` or looping — a loop is an
|
|
521
|
-
* effect, not a state change).
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
516
|
+
* effect, not a state change). A prop value may be an array of keyframes; meta keys
|
|
517
|
+
* `duration`/`delay`/`easing`/`times`/`loop`/… — see {@link AnimateStyle}. Returns the
|
|
518
|
+
* {@link Animation} handle. */
|
|
519
|
+
animateTo(style: any): Animation {
|
|
520
|
+
// The last keyframe commits into the stored style at play (Animation.play) — reads and later
|
|
521
|
+
// `.style()` merges see the final state while the host is still tweening, as before.
|
|
522
|
+
return tweenBag(this, style, true)
|
|
523
|
+
}
|
|
524
|
+
/** Tween FROM the given style to the element's current one (entrance animations): the element's
|
|
525
|
+
* own style is the implicit last keyframe. Never modifies the stored style. */
|
|
526
|
+
animateFrom(style: any): Animation {
|
|
527
|
+
return tweenBag(this, style, false)
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/** @internal Keyframe-core target protocol (animate/tween/spec.ts): every style prop is a channel
|
|
531
|
+
* on the UI domain; `text` is a discrete channel on text elements. */
|
|
532
|
+
readonly _tweenClock = CLOCK_UI
|
|
533
|
+
/** @internal */
|
|
534
|
+
_tweenChannel(prop: string): TweenChannel | null {
|
|
535
|
+
if (prop === "text") {
|
|
536
|
+
if (!("text" in this)) return null
|
|
537
|
+
return {
|
|
538
|
+
domain: DOM_UI, id: () => this._id,
|
|
539
|
+
value: (v) => (typeof v === "string" || typeof v === "number" ? { kind: KIND_DISCRETE, str: String(v) } : null),
|
|
540
|
+
commit: (v) => { (this as any).text = String(v) },
|
|
527
541
|
}
|
|
528
542
|
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
543
|
+
if (prop === "transform") {
|
|
544
|
+
// A function list tweens per argument when every key shares the list; anything else is handed
|
|
545
|
+
// to the host as a raw string for matrix decomposition (its old path).
|
|
546
|
+
return {
|
|
547
|
+
domain: DOM_UI, id: () => this._id,
|
|
548
|
+
value: (v) => {
|
|
549
|
+
if (typeof v !== "string") return null
|
|
550
|
+
const list = parseTransformList(v)
|
|
551
|
+
return list ? { kind: KIND_TRANSFORM, sig: list.sig, lanes: list.lanes } : { kind: KIND_TRANSFORM_MATRIX, str: v }
|
|
552
|
+
},
|
|
553
|
+
commit: (v) => { this._style.transform = v },
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
return {
|
|
557
|
+
domain: DOM_UI, id: () => this._id, value: uiValue,
|
|
558
|
+
commit: (v) => { this._style[prop] = v },
|
|
559
|
+
}
|
|
535
560
|
}
|
|
536
561
|
|
|
537
562
|
/** @internal Active style-class names (stored without the `$`). Kept on the element — not just in
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
type mat4 = Float32Array | number[];
|
|
2
|
-
type quat = Float32Array | number[];
|
|
3
|
-
type vec2 = Float32Array | number[];
|
|
4
|
-
type vec3 = Float32Array | number[];
|
|
5
|
-
import type { Easing } from "./easings";
|
|
6
|
-
type AnimateProps = number | string | vec2 | vec3 | quat;
|
|
7
|
-
export type AnimateOptions<T> = {
|
|
8
|
-
from: T;
|
|
9
|
-
to: T;
|
|
10
|
-
duration: number;
|
|
11
|
-
onUpdate(val: T): void;
|
|
12
|
-
onComplete?(): void;
|
|
13
|
-
easing?: Easing;
|
|
14
|
-
};
|
|
15
|
-
export declare const animate: <T extends AnimateProps>(options: AnimateOptions<T>) => number;
|
|
16
|
-
export declare const stopAnimation: (id: number) => void;
|
|
17
|
-
export declare const pauseAnimation: (id: number) => void;
|
|
18
|
-
export declare const resumeAnimation: (id: number) => void;
|
|
19
|
-
export declare const animateMat4: (options: AnimateOptions<mat4>) => number;
|
|
20
|
-
export {};
|
package/src/animate/animate.ts
DELETED
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
// animate self-implements its matrix decompose/recompose; these are just the numeric-array shapes.
|
|
2
|
-
type mat4 = Float32Array | number[]
|
|
3
|
-
type quat = Float32Array | number[]
|
|
4
|
-
type vec2 = Float32Array | number[]
|
|
5
|
-
type vec3 = Float32Array | number[]
|
|
6
|
-
import type { Easing } from "./easings"
|
|
7
|
-
|
|
8
|
-
type AnimateProps = number | string | vec2 | vec3 | quat
|
|
9
|
-
|
|
10
|
-
export type AnimateOptions<T> = {
|
|
11
|
-
from: T,
|
|
12
|
-
to: T,
|
|
13
|
-
duration: number,
|
|
14
|
-
onUpdate(val: T): void,
|
|
15
|
-
onComplete?(): void,
|
|
16
|
-
easing?: Easing,
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const animate = <T extends AnimateProps>(options: AnimateOptions<T>): number => {
|
|
20
|
-
|
|
21
|
-
let onRawUpdate
|
|
22
|
-
if (typeof options.to === "number") {
|
|
23
|
-
const { onUpdate, from, to } = options as AnimateOptions<number>
|
|
24
|
-
onRawUpdate = (t: number) => onUpdate(from + (to - from) * t)
|
|
25
|
-
} else if (options.to === "string") {
|
|
26
|
-
// TODO: Make color animate here
|
|
27
|
-
const { onUpdate, from, to } = options as AnimateOptions<string>
|
|
28
|
-
onRawUpdate = (t: number) => onUpdate(from)
|
|
29
|
-
|
|
30
|
-
// onRawUpdate = (val: number) => onUpdate(from + (to - from) * val)
|
|
31
|
-
} else if (options.to.length === 2) {
|
|
32
|
-
const { onUpdate, from, to } = options as AnimateOptions<vec2>
|
|
33
|
-
const tempVec = new Float32Array(3)
|
|
34
|
-
onRawUpdate = (t: number) => onUpdate(lerp2(tempVec, from, to, t))
|
|
35
|
-
|
|
36
|
-
} else if (options.to.length === 3) {
|
|
37
|
-
const { onUpdate, from, to } = options as AnimateOptions<vec3>
|
|
38
|
-
const tempVec = new Float32Array(3)
|
|
39
|
-
|
|
40
|
-
onRawUpdate = (t: number) => onUpdate(lerp(tempVec, from, to, t))
|
|
41
|
-
} else if (options.to.length === 4) {
|
|
42
|
-
const { onUpdate, from, to } = options as AnimateOptions<quat>
|
|
43
|
-
|
|
44
|
-
const tempQuat = new Float32Array(4)
|
|
45
|
-
onRawUpdate = (t: number) => onUpdate(slerp(tempQuat, from, to, t))
|
|
46
|
-
} else {
|
|
47
|
-
onRawUpdate = () => {}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const animationId = _creatorUtils.animate(val => {
|
|
51
|
-
const _val = options.easing? options.easing(val): val
|
|
52
|
-
onRawUpdate(_val)
|
|
53
|
-
if (val === 1 && options.onComplete) {
|
|
54
|
-
options.onComplete()
|
|
55
|
-
}
|
|
56
|
-
}, options.duration)
|
|
57
|
-
|
|
58
|
-
return animationId
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export const stopAnimation = (id: number): void => _creatorUtils.stopAnimation(id)
|
|
62
|
-
export const pauseAnimation = (id: number): void => _creatorUtils.pauseAnimation(id)
|
|
63
|
-
export const resumeAnimation = (id: number): void => _creatorUtils.resumeAnimation(id)
|
|
64
|
-
|
|
65
|
-
export const animateMat4 = (options: AnimateOptions<mat4>): number => {
|
|
66
|
-
const fromPosition = new Float32Array(3)
|
|
67
|
-
const fromQuaternion = new Float32Array(4)
|
|
68
|
-
const fromScale = new Float32Array(3)
|
|
69
|
-
const toPosition = new Float32Array(3)
|
|
70
|
-
const toQuaternion = new Float32Array(4)
|
|
71
|
-
const toScale = new Float32Array(3)
|
|
72
|
-
decompose(fromQuaternion, fromPosition, fromScale, (options as AnimateOptions<mat4>).from)
|
|
73
|
-
decompose(toQuaternion, toPosition, toScale, (options as AnimateOptions<mat4>).to)
|
|
74
|
-
|
|
75
|
-
const tempPosition = new Float32Array(3)
|
|
76
|
-
const tempQuat = new Float32Array(4)
|
|
77
|
-
const tempScale = new Float32Array(3)
|
|
78
|
-
const tempMat = new Float32Array(16)
|
|
79
|
-
|
|
80
|
-
const onUpdate = (options as AnimateOptions<mat4>).onUpdate
|
|
81
|
-
const onRawUpdate = (t: number) => {
|
|
82
|
-
lerp(tempPosition, fromPosition, toPosition, t)
|
|
83
|
-
slerp(tempQuat, fromQuaternion, toQuaternion, t)
|
|
84
|
-
lerp(tempScale, fromScale, toScale, t)
|
|
85
|
-
|
|
86
|
-
onUpdate(fromRotationTranslationScale(tempMat, tempQuat, tempPosition, tempScale))
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const animationId = _creatorUtils.animate(val => {
|
|
90
|
-
const _val = options.easing? options.easing(val): val
|
|
91
|
-
onRawUpdate(_val)
|
|
92
|
-
if (val === 1 && options.onComplete) {
|
|
93
|
-
options.onComplete()
|
|
94
|
-
}
|
|
95
|
-
}, options.duration)
|
|
96
|
-
|
|
97
|
-
return animationId
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const EPSILON = 1e-6;
|
|
101
|
-
function slerp(out: quat, a: quat, b: quat, t: number) {
|
|
102
|
-
const ax = a[0], ay = a[1], az = a[2], aw = a[3];
|
|
103
|
-
let bx = b[0], by = b[1], bz = b[2], bw = b[3];
|
|
104
|
-
let omega, cosom, sinom, scale0, scale1;
|
|
105
|
-
cosom = ax * bx + ay * by + az * bz + aw * bw;
|
|
106
|
-
if (cosom < 0) {
|
|
107
|
-
cosom = -cosom;
|
|
108
|
-
bx = -bx;
|
|
109
|
-
by = -by;
|
|
110
|
-
bz = -bz;
|
|
111
|
-
bw = -bw;
|
|
112
|
-
}
|
|
113
|
-
if (1 - cosom > EPSILON) {
|
|
114
|
-
omega = Math.acos(cosom);
|
|
115
|
-
sinom = Math.sin(omega);
|
|
116
|
-
scale0 = Math.sin((1 - t) * omega) / sinom;
|
|
117
|
-
scale1 = Math.sin(t * omega) / sinom;
|
|
118
|
-
} else {
|
|
119
|
-
scale0 = 1 - t;
|
|
120
|
-
scale1 = t;
|
|
121
|
-
}
|
|
122
|
-
out[0] = scale0 * ax + scale1 * bx;
|
|
123
|
-
out[1] = scale0 * ay + scale1 * by;
|
|
124
|
-
out[2] = scale0 * az + scale1 * bz;
|
|
125
|
-
out[3] = scale0 * aw + scale1 * bw;
|
|
126
|
-
return out;
|
|
127
|
-
}
|
|
128
|
-
function lerp(out: vec3, a: vec3, b: vec3, t: number) {
|
|
129
|
-
const ax = a[0];
|
|
130
|
-
const ay = a[1];
|
|
131
|
-
const az = a[2];
|
|
132
|
-
out[0] = ax + t * (b[0] - ax);
|
|
133
|
-
out[1] = ay + t * (b[1] - ay);
|
|
134
|
-
out[2] = az + t * (b[2] - az);
|
|
135
|
-
return out;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function lerp2(out: vec2, a: vec2, b: vec2, t: number) {
|
|
139
|
-
const ax = a[0];
|
|
140
|
-
const ay = a[1];
|
|
141
|
-
const az = a[2];
|
|
142
|
-
out[0] = ax + t * (b[0] - ax);
|
|
143
|
-
out[1] = ay + t * (b[1] - ay);
|
|
144
|
-
return out;
|
|
145
|
-
}
|
|
146
|
-
function fromRotationTranslationScale(out: mat4, q: quat, v: vec3, s: vec3) {
|
|
147
|
-
const x = q[0], y = q[1], z = q[2], w = q[3];
|
|
148
|
-
const x2 = x + x;
|
|
149
|
-
const y2 = y + y;
|
|
150
|
-
const z2 = z + z;
|
|
151
|
-
const xx = x * x2;
|
|
152
|
-
const xy = x * y2;
|
|
153
|
-
const xz = x * z2;
|
|
154
|
-
const yy = y * y2;
|
|
155
|
-
const yz = y * z2;
|
|
156
|
-
const zz = z * z2;
|
|
157
|
-
const wx = w * x2;
|
|
158
|
-
const wy = w * y2;
|
|
159
|
-
const wz = w * z2;
|
|
160
|
-
const sx = s[0];
|
|
161
|
-
const sy = s[1];
|
|
162
|
-
const sz = s[2];
|
|
163
|
-
out[0] = (1 - (yy + zz)) * sx;
|
|
164
|
-
out[1] = (xy + wz) * sx;
|
|
165
|
-
out[2] = (xz - wy) * sx;
|
|
166
|
-
out[3] = 0;
|
|
167
|
-
out[4] = (xy - wz) * sy;
|
|
168
|
-
out[5] = (1 - (xx + zz)) * sy;
|
|
169
|
-
out[6] = (yz + wx) * sy;
|
|
170
|
-
out[7] = 0;
|
|
171
|
-
out[8] = (xz + wy) * sz;
|
|
172
|
-
out[9] = (yz - wx) * sz;
|
|
173
|
-
out[10] = (1 - (xx + yy)) * sz;
|
|
174
|
-
out[11] = 0;
|
|
175
|
-
out[12] = v[0];
|
|
176
|
-
out[13] = v[1];
|
|
177
|
-
out[14] = v[2];
|
|
178
|
-
out[15] = 1;
|
|
179
|
-
return out;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
function decompose(out_r: mat4, out_t: vec3, out_s: vec3, mat: mat4) {
|
|
183
|
-
out_t[0] = mat[12];
|
|
184
|
-
out_t[1] = mat[13];
|
|
185
|
-
out_t[2] = mat[14];
|
|
186
|
-
const m11 = mat[0];
|
|
187
|
-
const m12 = mat[1];
|
|
188
|
-
const m13 = mat[2];
|
|
189
|
-
const m21 = mat[4];
|
|
190
|
-
const m22 = mat[5];
|
|
191
|
-
const m23 = mat[6];
|
|
192
|
-
const m31 = mat[8];
|
|
193
|
-
const m32 = mat[9];
|
|
194
|
-
const m33 = mat[10];
|
|
195
|
-
out_s[0] = Math.hypot(m11, m12, m13);
|
|
196
|
-
out_s[1] = Math.hypot(m21, m22, m23);
|
|
197
|
-
out_s[2] = Math.hypot(m31, m32, m33);
|
|
198
|
-
const is1 = 1 / out_s[0];
|
|
199
|
-
const is2 = 1 / out_s[1];
|
|
200
|
-
const is3 = 1 / out_s[2];
|
|
201
|
-
const sm11 = m11 * is1;
|
|
202
|
-
const sm12 = m12 * is2;
|
|
203
|
-
const sm13 = m13 * is3;
|
|
204
|
-
const sm21 = m21 * is1;
|
|
205
|
-
const sm22 = m22 * is2;
|
|
206
|
-
const sm23 = m23 * is3;
|
|
207
|
-
const sm31 = m31 * is1;
|
|
208
|
-
const sm32 = m32 * is2;
|
|
209
|
-
const sm33 = m33 * is3;
|
|
210
|
-
const trace = sm11 + sm22 + sm33;
|
|
211
|
-
let S = 0;
|
|
212
|
-
if (trace > 0) {
|
|
213
|
-
S = Math.sqrt(trace + 1) * 2;
|
|
214
|
-
out_r[3] = 0.25 * S;
|
|
215
|
-
out_r[0] = (sm23 - sm32) / S;
|
|
216
|
-
out_r[1] = (sm31 - sm13) / S;
|
|
217
|
-
out_r[2] = (sm12 - sm21) / S;
|
|
218
|
-
} else if (sm11 > sm22 && sm11 > sm33) {
|
|
219
|
-
S = Math.sqrt(1 + sm11 - sm22 - sm33) * 2;
|
|
220
|
-
out_r[3] = (sm23 - sm32) / S;
|
|
221
|
-
out_r[0] = 0.25 * S;
|
|
222
|
-
out_r[1] = (sm12 + sm21) / S;
|
|
223
|
-
out_r[2] = (sm31 + sm13) / S;
|
|
224
|
-
} else if (sm22 > sm33) {
|
|
225
|
-
S = Math.sqrt(1 + sm22 - sm11 - sm33) * 2;
|
|
226
|
-
out_r[3] = (sm31 - sm13) / S;
|
|
227
|
-
out_r[0] = (sm12 + sm21) / S;
|
|
228
|
-
out_r[1] = 0.25 * S;
|
|
229
|
-
out_r[2] = (sm23 + sm32) / S;
|
|
230
|
-
} else {
|
|
231
|
-
S = Math.sqrt(1 + sm33 - sm11 - sm22) * 2;
|
|
232
|
-
out_r[3] = (sm12 - sm21) / S;
|
|
233
|
-
out_r[0] = (sm31 + sm13) / S;
|
|
234
|
-
out_r[1] = (sm23 + sm32) / S;
|
|
235
|
-
out_r[2] = 0.25 * S;
|
|
236
|
-
}
|
|
237
|
-
return out_r;
|
|
238
|
-
}
|