lecodes-sdk 0.19.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/README.md +114 -0
- package/dist/global.d.ts +503 -0
- package/dist/host.d.ts +61 -0
- package/dist/inject.js +4730 -0
- package/dist/types/animate/animate.d.ts +20 -0
- package/dist/types/animate/bezier.d.ts +2 -0
- package/dist/types/animate/easings.d.ts +21 -0
- package/dist/types/canvas/Canvas.d.ts +168 -0
- package/dist/types/core/Aspect.d.ts +171 -0
- package/dist/types/core/InspectorUI.d.ts +88 -0
- package/dist/types/core/StateMachine.d.ts +81 -0
- package/dist/types/core/color.d.ts +13 -0
- package/dist/types/core/compWrite.d.ts +11 -0
- package/dist/types/core/events.d.ts +11 -0
- package/dist/types/core/fields.d.ts +58 -0
- package/dist/types/core/registry.d.ts +7 -0
- package/dist/types/core/signals.d.ts +29 -0
- package/dist/types/core/time.d.ts +31 -0
- package/dist/types/g2/Camera2D.d.ts +19 -0
- package/dist/types/g2/CharacterController2D.d.ts +134 -0
- package/dist/types/g2/Node2D.d.ts +91 -0
- package/dist/types/g2/OneWay2D.d.ts +24 -0
- package/dist/types/g2/Physics2D.d.ts +147 -0
- package/dist/types/g2/Scene2D.d.ts +72 -0
- package/dist/types/g2/Shape2D.d.ts +58 -0
- package/dist/types/g2/Sprite.d.ts +51 -0
- package/dist/types/g2/SpriteAnimation.d.ts +50 -0
- package/dist/types/g2/SpriteSheet.d.ts +69 -0
- package/dist/types/g2/Texture2D.d.ts +16 -0
- package/dist/types/g2/Tilemap.d.ts +20 -0
- package/dist/types/g2/Tileset.d.ts +32 -0
- package/dist/types/g2/Trigger2D.d.ts +20 -0
- package/dist/types/g2/autotile.d.ts +133 -0
- package/dist/types/g2/cells.d.ts +14 -0
- package/dist/types/g2/defineScene2d.d.ts +141 -0
- package/dist/types/g2/groups2d.d.ts +16 -0
- package/dist/types/g2/loop.d.ts +4 -0
- package/dist/types/g2/scenarios2d.d.ts +30 -0
- package/dist/types/g2/touch.d.ts +2 -0
- package/dist/types/gl/Camera.d.ts +79 -0
- package/dist/types/gl/CameraPlace.d.ts +26 -0
- package/dist/types/gl/CharacterController.d.ts +98 -0
- package/dist/types/gl/Gearbox.d.ts +86 -0
- package/dist/types/gl/Geometry.d.ts +39 -0
- package/dist/types/gl/IK.d.ts +53 -0
- package/dist/types/gl/InstancedMesh.d.ts +46 -0
- package/dist/types/gl/Light.d.ts +73 -0
- package/dist/types/gl/Lightmap.d.ts +85 -0
- package/dist/types/gl/Locomotion.d.ts +279 -0
- package/dist/types/gl/Material.d.ts +100 -0
- package/dist/types/gl/Mesh.d.ts +33 -0
- package/dist/types/gl/Model.d.ts +53 -0
- package/dist/types/gl/NavAgent.d.ts +99 -0
- package/dist/types/gl/NavMesh.d.ts +169 -0
- package/dist/types/gl/Node.d.ts +99 -0
- package/dist/types/gl/Noise.d.ts +20 -0
- package/dist/types/gl/Particles.d.ts +277 -0
- package/dist/types/gl/Physics.d.ts +91 -0
- package/dist/types/gl/Plane.d.ts +19 -0
- package/dist/types/gl/Ragdoll.d.ts +86 -0
- package/dist/types/gl/Ray.d.ts +8 -0
- package/dist/types/gl/Scene.d.ts +221 -0
- package/dist/types/gl/Shape.d.ts +122 -0
- package/dist/types/gl/Terrain.d.ts +280 -0
- package/dist/types/gl/Texture.d.ts +27 -0
- package/dist/types/gl/Trigger.d.ts +10 -0
- package/dist/types/gl/Vehicle.d.ts +191 -0
- package/dist/types/gl/Wheel.d.ts +95 -0
- package/dist/types/gl/animation/AnimationClip.d.ts +60 -0
- package/dist/types/gl/animation/Animator.d.ts +219 -0
- package/dist/types/gl/animation/Layer.d.ts +31 -0
- package/dist/types/gl/animation/Loop.d.ts +17 -0
- package/dist/types/gl/animation/Playback.d.ts +36 -0
- package/dist/types/gl/animation/core.d.ts +367 -0
- package/dist/types/gl/controls.d.ts +19 -0
- package/dist/types/gl/physicsEvents.d.ts +1 -0
- package/dist/types/gl/scenarios.d.ts +98 -0
- package/dist/types/gl/state.d.ts +5 -0
- package/dist/types/gl/terrainMesh.d.ts +46 -0
- package/dist/types/gl/touch.d.ts +2 -0
- package/dist/types/inject.d.ts +123 -0
- package/dist/types/math/Mathf.d.ts +39 -0
- package/dist/types/math/mat4.d.ts +66 -0
- package/dist/types/math/quat.d.ts +53 -0
- package/dist/types/math/vec.d.ts +129 -0
- package/dist/types/net/codec.d.ts +25 -0
- package/dist/types/net/core.d.ts +106 -0
- package/dist/types/net/index.d.ts +80 -0
- package/dist/types/net/replication.d.ts +101 -0
- package/dist/types/plugins/camera.d.ts +25 -0
- package/dist/types/plugins/geolocation.d.ts +39 -0
- package/dist/types/plugins/oauth.d.ts +25 -0
- package/dist/types/plugins/permission.d.ts +1 -0
- package/dist/types/plugins/push.d.ts +46 -0
- package/dist/types/plugins/qr.d.ts +21 -0
- package/dist/types/plugins/service.d.ts +33 -0
- package/dist/types/runtime/app.d.ts +67 -0
- package/dist/types/runtime/appEvents.d.ts +7 -0
- package/dist/types/runtime/channel.d.ts +1 -0
- package/dist/types/runtime/clipboard.d.ts +7 -0
- package/dist/types/runtime/datetime.d.ts +80 -0
- package/dist/types/runtime/device.d.ts +126 -0
- package/dist/types/runtime/fetch.d.ts +31 -0
- package/dist/types/runtime/files.d.ts +33 -0
- package/dist/types/runtime/input.d.ts +121 -0
- package/dist/types/runtime/media.d.ts +46 -0
- package/dist/types/runtime/misc.d.ts +11 -0
- package/dist/types/runtime/net.d.ts +15 -0
- package/dist/types/runtime/rpc.d.ts +44 -0
- package/dist/types/runtime/service.d.ts +1 -0
- package/dist/types/runtime/share.d.ts +2 -0
- package/dist/types/runtime/storage.d.ts +5 -0
- package/dist/types/runtime/touch.d.ts +56 -0
- package/dist/types/scene/defineScene.d.ts +296 -0
- package/dist/types/scene/editorPlugins.d.ts +82 -0
- package/dist/types/scene/gizmos.d.ts +56 -0
- package/dist/types/scene/grammar.d.ts +56 -0
- package/dist/types/scene/level.d.ts +98 -0
- package/dist/types/scene/material.d.ts +76 -0
- package/dist/types/server/auth/appConfig.d.ts +16 -0
- package/dist/types/server/auth/global.d.ts +56 -0
- package/dist/types/server/auth/models.d.ts +164 -0
- package/dist/types/server/auth/types.d.ts +56 -0
- package/dist/types/server/channel.d.ts +28 -0
- package/dist/types/server/context.d.ts +27 -0
- package/dist/types/server/db/defineDb.d.ts +36 -0
- package/dist/types/server/db/fields.d.ts +146 -0
- package/dist/types/server/db/index.d.ts +6 -0
- package/dist/types/server/db/marci/query.d.ts +326 -0
- package/dist/types/server/db/types.d.ts +163 -0
- package/dist/types/server/errors.d.ts +8 -0
- package/dist/types/server/inject.d.ts +5 -0
- package/dist/types/ui/NativeView.d.ts +38 -0
- package/dist/types/ui/UI.d.ts +27 -0
- package/dist/types/ui/UIBottomSheet.d.ts +71 -0
- package/dist/types/ui/UIButton.d.ts +30 -0
- package/dist/types/ui/UIContainer.d.ts +33 -0
- package/dist/types/ui/UIImage.d.ts +35 -0
- package/dist/types/ui/UIInput.d.ts +110 -0
- package/dist/types/ui/UIModal.d.ts +70 -0
- package/dist/types/ui/UINode.d.ts +363 -0
- package/dist/types/ui/UIPager.d.ts +123 -0
- package/dist/types/ui/UIPopover.d.ts +39 -0
- package/dist/types/ui/UIScreen.d.ts +57 -0
- package/dist/types/ui/UIScrollable.d.ts +40 -0
- package/dist/types/ui/UISpacer.d.ts +9 -0
- package/dist/types/ui/UITabs.d.ts +96 -0
- package/dist/types/ui/UIText.d.ts +19 -0
- package/dist/types/ui/UIVideo.d.ts +28 -0
- package/dist/types/ui/UIVirtualizedList.d.ts +97 -0
- package/dist/types/ui/UIWidget.d.ts +65 -0
- package/dist/types/ui/fonts.d.ts +9 -0
- package/dist/types/ui/presentable.d.ts +68 -0
- package/dist/types/ui/router.d.ts +40 -0
- package/dist/types/ui/theme.d.ts +26 -0
- package/dist/types.json +1 -0
- package/package.json +46 -0
- package/prompts/2d.md +395 -0
- package/prompts/3d-scene-files.md +113 -0
- package/prompts/3d-scene.md +119 -0
- package/prompts/3d.md +303 -0
- package/prompts/README.md +142 -0
- package/prompts/ar.md +109 -0
- package/prompts/canvas.md +27 -0
- package/prompts/compose.ts +46 -0
- package/prompts/concept.md +49 -0
- package/prompts/core-design.md +75 -0
- package/prompts/core.md +264 -0
- package/prompts/design.md +218 -0
- package/prompts/dist/2d-game.md +1530 -0
- package/prompts/dist/3d-app.md +1672 -0
- package/prompts/dist/ar-app.md +1548 -0
- package/prompts/dist/concept.md +49 -0
- package/prompts/dist/design.md +498 -0
- package/prompts/dist/ui-app.md +1134 -0
- package/prompts/index.md +37 -0
- package/prompts/intake-prompt.md +33 -0
- package/prompts/namer-prompt.md +12 -0
- package/prompts/router-prompt.md +50 -0
- package/prompts/select.ts +111 -0
- package/prompts/ui-design.md +203 -0
- package/prompts/ui.md +803 -0
- package/src/animate/animate.ts +238 -0
- package/src/animate/bezier.ts +138 -0
- package/src/animate/easings.ts +126 -0
- package/src/bridges.d.ts +1345 -0
- package/src/canvas/Canvas.ts +305 -0
- package/src/compile/__tests__/assetIconMacro.test.ts +219 -0
- package/src/compile/__tests__/assetMacro.test.ts +74 -0
- package/src/compile/__tests__/assetName.test.ts +55 -0
- package/src/compile/__tests__/compile.test.ts +287 -0
- package/src/compile/__tests__/detectEntry.test.ts +132 -0
- package/src/compile/__tests__/fontMacro.test.ts +199 -0
- package/src/compile/aspectMacro.ts +86 -0
- package/src/compile/assetIconMacro.ts +384 -0
- package/src/compile/assetMacro.ts +146 -0
- package/src/compile/assetName.ts +50 -0
- package/src/compile/bundler.ts +287 -0
- package/src/compile/compileProject.ts +127 -0
- package/src/compile/detectEntry.ts +128 -0
- package/src/compile/fontMacro.ts +459 -0
- package/src/compile/fontRegistry.ts +78 -0
- package/src/compile/header.ts +67 -0
- package/src/compile/index.ts +100 -0
- package/src/compile/libraryImports.ts +52 -0
- package/src/compile/liteMaterial.ts +247 -0
- package/src/compile/sceneEditor.ts +88 -0
- package/src/compile/serverSplit.ts +233 -0
- package/src/compile/serverTypes.ts +227 -0
- package/src/compile/sfnt.ts +98 -0
- package/src/compile/shaderSchema.ts +202 -0
- package/src/compile/shaderTargets.ts +77 -0
- package/src/compile/sourcemap.ts +25 -0
- package/src/core/Aspect.ts +568 -0
- package/src/core/InspectorUI.ts +212 -0
- package/src/core/StateMachine.ts +308 -0
- package/src/core/__tests__/stateMachine.test.ts +132 -0
- package/src/core/color.ts +66 -0
- package/src/core/compWrite.ts +42 -0
- package/src/core/events.ts +38 -0
- package/src/core/fields.ts +120 -0
- package/src/core/registry.ts +23 -0
- package/src/core/signals.ts +277 -0
- package/src/core/time.ts +84 -0
- package/src/g2/Camera2D.ts +40 -0
- package/src/g2/CharacterController2D.ts +276 -0
- package/src/g2/Node2D.ts +267 -0
- package/src/g2/OneWay2D.ts +66 -0
- package/src/g2/Physics2D.ts +346 -0
- package/src/g2/Scene2D.ts +209 -0
- package/src/g2/Shape2D.ts +259 -0
- package/src/g2/Sprite.ts +89 -0
- package/src/g2/SpriteAnimation.ts +171 -0
- package/src/g2/SpriteSheet.ts +166 -0
- package/src/g2/Texture2D.ts +47 -0
- package/src/g2/Tilemap.ts +41 -0
- package/src/g2/Tileset.ts +71 -0
- package/src/g2/Trigger2D.ts +77 -0
- package/src/g2/autotile.ts +433 -0
- package/src/g2/cells.ts +91 -0
- package/src/g2/defineScene2d.ts +381 -0
- package/src/g2/groups2d.ts +106 -0
- package/src/g2/loop.ts +50 -0
- package/src/g2/scenarios2d.ts +69 -0
- package/src/g2/touch.ts +83 -0
- package/src/gl/Camera.ts +160 -0
- package/src/gl/CameraPlace.ts +52 -0
- package/src/gl/CharacterController.ts +238 -0
- package/src/gl/Gearbox.ts +212 -0
- package/src/gl/Geometry.ts +279 -0
- package/src/gl/IK.ts +193 -0
- package/src/gl/InstancedMesh.ts +132 -0
- package/src/gl/Light.ts +135 -0
- package/src/gl/Lightmap.ts +402 -0
- package/src/gl/Locomotion.ts +498 -0
- package/src/gl/Material.ts +279 -0
- package/src/gl/Mesh.ts +83 -0
- package/src/gl/Model.ts +124 -0
- package/src/gl/NavAgent.ts +337 -0
- package/src/gl/NavMesh.ts +397 -0
- package/src/gl/Node.ts +350 -0
- package/src/gl/Noise.ts +30 -0
- package/src/gl/Particles.ts +676 -0
- package/src/gl/Physics.ts +222 -0
- package/src/gl/Plane.ts +53 -0
- package/src/gl/Ragdoll.ts +270 -0
- package/src/gl/Ray.ts +16 -0
- package/src/gl/Scene.ts +505 -0
- package/src/gl/Shape.ts +409 -0
- package/src/gl/Terrain.ts +1092 -0
- package/src/gl/Texture.ts +63 -0
- package/src/gl/Trigger.ts +45 -0
- package/src/gl/Vehicle.ts +473 -0
- package/src/gl/Wheel.ts +240 -0
- package/src/gl/animation/AnimationClip.ts +204 -0
- package/src/gl/animation/Animator.ts +329 -0
- package/src/gl/animation/Layer.ts +39 -0
- package/src/gl/animation/Loop.ts +31 -0
- package/src/gl/animation/Playback.ts +52 -0
- package/src/gl/animation/core.ts +670 -0
- package/src/gl/controls.ts +95 -0
- package/src/gl/physicsEvents.ts +20 -0
- package/src/gl/scenarios.ts +291 -0
- package/src/gl/state.ts +6 -0
- package/src/gl/terrainMesh.ts +219 -0
- package/src/gl/touch.ts +68 -0
- package/src/host.d.ts +61 -0
- package/src/inject.ts +203 -0
- package/src/math/Mathf.ts +118 -0
- package/src/math/mat4.ts +278 -0
- package/src/math/quat.ts +232 -0
- package/src/math/vec.ts +255 -0
- package/src/net/codec.ts +119 -0
- package/src/net/core.ts +384 -0
- package/src/net/index.ts +181 -0
- package/src/net/replication.ts +622 -0
- package/src/plugins/camera.ts +81 -0
- package/src/plugins/geolocation.ts +123 -0
- package/src/plugins/oauth.ts +61 -0
- package/src/plugins/permission.ts +7 -0
- package/src/plugins/push.ts +132 -0
- package/src/plugins/qr.ts +73 -0
- package/src/plugins/service.ts +47 -0
- package/src/runtime/app.ts +101 -0
- package/src/runtime/appEvents.ts +54 -0
- package/src/runtime/channel.ts +61 -0
- package/src/runtime/clipboard.ts +20 -0
- package/src/runtime/datetime.ts +329 -0
- package/src/runtime/device.ts +293 -0
- package/src/runtime/fetch.ts +77 -0
- package/src/runtime/files.ts +108 -0
- package/src/runtime/input.ts +175 -0
- package/src/runtime/media.ts +111 -0
- package/src/runtime/misc.ts +16 -0
- package/src/runtime/net.ts +36 -0
- package/src/runtime/rpc.ts +218 -0
- package/src/runtime/service.ts +83 -0
- package/src/runtime/share.ts +9 -0
- package/src/runtime/storage.ts +13 -0
- package/src/runtime/touch.ts +76 -0
- package/src/scene/defineScene.ts +1396 -0
- package/src/scene/editorPlugins.ts +110 -0
- package/src/scene/gizmos.ts +148 -0
- package/src/scene/grammar.ts +120 -0
- package/src/scene/level.ts +296 -0
- package/src/scene/material.ts +188 -0
- package/src/server/auth/appConfig.ts +12 -0
- package/src/server/auth/global.ts +80 -0
- package/src/server/auth/host.ts +318 -0
- package/src/server/auth/models.ts +83 -0
- package/src/server/auth/types.ts +50 -0
- package/src/server/channel.ts +56 -0
- package/src/server/context.ts +36 -0
- package/src/server/db/defineDb.ts +237 -0
- package/src/server/db/fields.ts +132 -0
- package/src/server/db/httpTransport.ts +93 -0
- package/src/server/db/index.ts +7 -0
- package/src/server/db/marci/query.ts +412 -0
- package/src/server/db/types.ts +202 -0
- package/src/server/errors.ts +12 -0
- package/src/server/host.ts +74 -0
- package/src/server/inject.ts +13 -0
- package/src/server/runtime.ts +133 -0
- package/src/server/validate.ts +87 -0
- package/src/ui/NativeView.ts +142 -0
- package/src/ui/UI.ts +39 -0
- package/src/ui/UIBottomSheet.ts +139 -0
- package/src/ui/UIButton.ts +101 -0
- package/src/ui/UIContainer.ts +60 -0
- package/src/ui/UIImage.ts +83 -0
- package/src/ui/UIInput.ts +185 -0
- package/src/ui/UIModal.ts +139 -0
- package/src/ui/UINode.ts +830 -0
- package/src/ui/UIPager.ts +362 -0
- package/src/ui/UIPopover.ts +100 -0
- package/src/ui/UIScreen.ts +123 -0
- package/src/ui/UIScrollable.ts +87 -0
- package/src/ui/UISpacer.ts +14 -0
- package/src/ui/UITabs.ts +236 -0
- package/src/ui/UIText.ts +51 -0
- package/src/ui/UIVideo.ts +88 -0
- package/src/ui/UIVirtualizedList.ts +241 -0
- package/src/ui/UIWidget.ts +127 -0
- package/src/ui/fonts.ts +13 -0
- package/src/ui/presentable.ts +117 -0
- package/src/ui/router.ts +132 -0
- package/src/ui/theme.ts +84 -0
package/src/gl/Node.ts
ADDED
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
// Base 3D scene node — an empty transform. Mesh and Light extend it, so every node operation works
|
|
2
|
+
// on them. Native (creator-gl) owns the authoritative transform; reads decompose a cached local
|
|
3
|
+
// matrix (re-synced lazily, since physics can write the transform from native each frame).
|
|
4
|
+
//
|
|
5
|
+
// Capabilities are aspects: node.aspect(Physics, …) (→ node.physics), node.aspect(Shape, …).
|
|
6
|
+
// A GLB import is the Model node kind (with the Animator aspect at model.anim). Hierarchy lives here.
|
|
7
|
+
|
|
8
|
+
import { AspectHost } from "../core/Aspect"
|
|
9
|
+
import { Registry } from "../core/registry"
|
|
10
|
+
import { Vec3, cx, cy, cz, type Vec3Like } from "../math/vec"
|
|
11
|
+
import { Quat, cw, type QuatLike } from "../math/quat"
|
|
12
|
+
import { Mat4, type Mat4Like } from "../math/mat4"
|
|
13
|
+
import type { Geometry } from "./Geometry"
|
|
14
|
+
import { registerTouchEndEvent, registerTouchStartEvent } from "./touch"
|
|
15
|
+
import { ensurePhysicsEvents } from "./physicsEvents"
|
|
16
|
+
import { Material } from "./Material"
|
|
17
|
+
import type { CompAxis, CompWriter } from "../core/compWrite"
|
|
18
|
+
import type { ClickEvent, TouchStartEvent } from "../runtime/touch"
|
|
19
|
+
|
|
20
|
+
/** id → Node, so host callbacks (touch hits, animation events) route back to the owning object. */
|
|
21
|
+
export const nodeRegistry = new Registry<Node>()
|
|
22
|
+
|
|
23
|
+
export type NodeEvents = {
|
|
24
|
+
click: (ev: ClickEvent<Node | null>) => void
|
|
25
|
+
touchstart: (ev: TouchStartEvent<Node | null>) => void
|
|
26
|
+
/** AR anchors only (`scene.root` / `scene.createAnchor()`): the anchor began tracking. */
|
|
27
|
+
track: () => void
|
|
28
|
+
/** AR anchors only: the anchor lost tracking. */
|
|
29
|
+
untrack: () => void
|
|
30
|
+
/** A physics contact/trigger overlap began (the other body's node). Needs a Shape + Physics/Trigger. */
|
|
31
|
+
enter: (other: Node) => void
|
|
32
|
+
/** A physics contact/trigger overlap ended. */
|
|
33
|
+
exit: (other: Node) => void
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const shortName = (s: string): string => s.slice(s.search(/[^:|]*$/))
|
|
37
|
+
|
|
38
|
+
/** Fallback for hosts without `_creator.findNode` (exact name, then short name, first in tree order —
|
|
39
|
+
* no skin-joint preference: that needs the host's skin knowledge). 0 when absent. */
|
|
40
|
+
const findNodeByWalk = (rootId: number, name: string): number => {
|
|
41
|
+
let exact = 0
|
|
42
|
+
let loose = 0
|
|
43
|
+
const want = shortName(name)
|
|
44
|
+
_creator.traverse(rootId, (id) => {
|
|
45
|
+
if (exact) return
|
|
46
|
+
const n = _creator.getName(id)
|
|
47
|
+
if (n === name) exact = id
|
|
48
|
+
else if (!loose && shortName(n) === want) loose = id
|
|
49
|
+
})
|
|
50
|
+
return exact || loose
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Scratch for the world-position read-back in _setOwnedPosition (one per module, never handed out).
|
|
54
|
+
const worldScratch = new Float32Array(3)
|
|
55
|
+
|
|
56
|
+
export class Node extends AspectHost<NodeEvents> implements CompWriter {
|
|
57
|
+
/** Native entity handle. */
|
|
58
|
+
readonly id: number
|
|
59
|
+
|
|
60
|
+
/** AR anchors only — whether the anchor is currently being tracked. Kept in step with the
|
|
61
|
+
* 'track' / 'untrack' events; `false` for any non-anchor node. */
|
|
62
|
+
isTracked = false
|
|
63
|
+
|
|
64
|
+
private _matrix?: Float32Array
|
|
65
|
+
private _worldMatrix?: Float32Array
|
|
66
|
+
private _boneCache?: Map<string, Node | null>
|
|
67
|
+
/** Materials assigned through setMaterial, by primitive slot (a Mesh fills slot 0 itself). */
|
|
68
|
+
protected _materials?: Material[]
|
|
69
|
+
|
|
70
|
+
constructor(internalId?: number) {
|
|
71
|
+
super()
|
|
72
|
+
this.id = internalId ?? _creator.createEntity()
|
|
73
|
+
nodeRegistry.set(this.id, this)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Geometry, if this node is a Mesh (used by physics auto-shape). Overridden by Mesh. */
|
|
77
|
+
get geometry(): Geometry | undefined { return undefined }
|
|
78
|
+
|
|
79
|
+
// --- name / visibility ---
|
|
80
|
+
get name(): string { return _creator.getName(this.id) }
|
|
81
|
+
set name(value: string) { _creator.setName(this.id, value) }
|
|
82
|
+
get visible(): boolean { return _creator.isVisible(this.id) }
|
|
83
|
+
set visible(value: boolean) { _creator.setVisible(this.id, value) }
|
|
84
|
+
|
|
85
|
+
// --- local transform ---
|
|
86
|
+
// Native owns the authoritative matrix. `_sync()` reads it into a per-node scratch buffer on EVERY
|
|
87
|
+
// call: a bridge read is ~40 ns on QuickJS — what the Date.now() of a staleness check cost — so a
|
|
88
|
+
// cache bought nothing and needed invalidation hooks (physics / controllers / animation rewrite
|
|
89
|
+
// transforms natively between frames). The PUBLIC `matrix` getter hands back a fresh Mat4 *copy*
|
|
90
|
+
// (value semantics — mutating it never touches the node until you assign it back); `_sync()` is
|
|
91
|
+
// the internal hot path for component reads.
|
|
92
|
+
private _sync(): Float32Array {
|
|
93
|
+
const m = this._matrix ?? (this._matrix = new Float32Array(16))
|
|
94
|
+
_creator.getMatrix(this.id, m)
|
|
95
|
+
return m
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
get matrix(): Mat4 { return new Mat4(this._sync()) }
|
|
99
|
+
set matrix(m: Mat4Like) {
|
|
100
|
+
const buf = this._matrix ?? (this._matrix = new Float32Array(16))
|
|
101
|
+
buf.set(matArr(m))
|
|
102
|
+
_creator.setMatrix(this.id, buf)
|
|
103
|
+
// A matrix write on a physics-owned node must move the engine object too, or it is silently
|
|
104
|
+
// overwritten by the next sync. Position always; rotation only for a BODY (see _setOwnedRotation).
|
|
105
|
+
// Scale is never routed — a Jolt shape is built at a fixed size, that is `Shape`'s job.
|
|
106
|
+
// `worldMatrix` composes into this setter, so it is covered here too.
|
|
107
|
+
if (this._xf) {
|
|
108
|
+
this._setOwnedPosition(buf[12], buf[13], buf[14])
|
|
109
|
+
this._setOwnedRotation()
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
get worldMatrix(): Mat4 {
|
|
114
|
+
if (this.parent === null) return this.matrix
|
|
115
|
+
if (!this._worldMatrix) this._worldMatrix = new Float32Array(16)
|
|
116
|
+
_creator.getWorldMatrix(this.id, this._worldMatrix)
|
|
117
|
+
return new Mat4(this._worldMatrix)
|
|
118
|
+
}
|
|
119
|
+
set worldMatrix(m: Mat4Like) {
|
|
120
|
+
const p = this.parent
|
|
121
|
+
if (p === null) { this.matrix = m; return }
|
|
122
|
+
// local = parentWorld⁻¹ · world, composed here: the native setWorldMatrix ignores the parent (it
|
|
123
|
+
// wrote the world matrix as the local one — a bone under a rotated Model wrapper read back with the
|
|
124
|
+
// ancestors' rotation applied twice)
|
|
125
|
+
this.matrix = p.worldMatrix.invert().mul(m)
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** @internal The engine object that mirrors this node's transform, if any — a physics body or a
|
|
129
|
+
* character (0 = none). `position` writes are routed to it as well, because the engine is the
|
|
130
|
+
* authority: on a dynamic body a plain setPosition is overwritten by the next sync, and on a
|
|
131
|
+
* static / pick / trigger body it would leave the COLLIDER behind while the node moved. Set by
|
|
132
|
+
* Shape (bodies) and CharacterController. */
|
|
133
|
+
_xf = 0
|
|
134
|
+
/** @internal What `_xf` is: 1 = character, 2 = physics body. */
|
|
135
|
+
_xfKind = 0
|
|
136
|
+
|
|
137
|
+
// Route a position write to the engine object that owns this node. Kept out of the setters' hot path
|
|
138
|
+
// (they only pay one truthiness check). `position` stays a LOCAL coordinate like on every node, while
|
|
139
|
+
// physics works in world space — so the node is written first and the world point read back natively
|
|
140
|
+
// (one bridge call for any parent depth, no allocation; the native transform manager updates the
|
|
141
|
+
// world matrix synchronously).
|
|
142
|
+
private _setOwnedPosition(x: number, y: number, z: number): void {
|
|
143
|
+
_creator.setPosition(this.id, x, y, z) // keep the node itself right, so a read-back is immediate
|
|
144
|
+
_creator.getWorldPosition(this.id, worldScratch)
|
|
145
|
+
if (this._xfKind === 1) _creator.characterSetPosition(this._xf, worldScratch[0], worldScratch[1], worldScratch[2])
|
|
146
|
+
else _creator.physicsSetBodyPosition(this._xf, worldScratch[0], worldScratch[1], worldScratch[2])
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// The rotation half of the same routing. BODIES ONLY: a character's rotation is node-owned by design
|
|
150
|
+
// (the engine writes its position and nothing else — a capsule is symmetric about its up axis, so its
|
|
151
|
+
// yaw is physically meaningless), and pushing one into Jolt would invent an authority that isn't there.
|
|
152
|
+
// The node has already been written by the caller, so the world rotation is read back from it — that
|
|
153
|
+
// way the engine's own euler convention decides, instead of this file re-deriving it.
|
|
154
|
+
private _setOwnedRotation(): void {
|
|
155
|
+
if (this._xfKind !== 2 || !_creator.physicsSetBodyRotation) return
|
|
156
|
+
const q = this.worldMatrix.rotation
|
|
157
|
+
_creator.physicsSetBodyRotation(this._xf, q.x, q.y, q.z, q.w)
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
get position(): Vec3 { const m = this._sync(); return new Vec3(m[12], m[13], m[14]) }
|
|
161
|
+
set position(v: Vec3Like) {
|
|
162
|
+
if (this._xf) this._setOwnedPosition(cx(v), cy(v), cz(v))
|
|
163
|
+
else _creator.setPosition(this.id, cx(v), cy(v), cz(v))
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Scalar position accessors — one axis without touching the others (`node.x = 3`). The direct spelling
|
|
167
|
+
// `node.position.x = 3` compiles to the same thing (chisel's comp_write pass routes it through
|
|
168
|
+
// `_writeComp` below); only a STORED copy of `position` is still a copy.
|
|
169
|
+
get x(): number { return this._sync()[12] }
|
|
170
|
+
set x(v: number) { const m = this._sync(); if (this._xf) this._setOwnedPosition(v, m[13], m[14]); else _creator.setPosition(this.id, v, m[13], m[14]) }
|
|
171
|
+
get y(): number { return this._sync()[13] }
|
|
172
|
+
set y(v: number) { const m = this._sync(); if (this._xf) this._setOwnedPosition(m[12], v, m[14]); else _creator.setPosition(this.id, m[12], v, m[14]) }
|
|
173
|
+
get z(): number { return this._sync()[14] }
|
|
174
|
+
set z(v: number) { const m = this._sync(); if (this._xf) this._setOwnedPosition(m[12], m[13], v); else _creator.setPosition(this.id, m[12], m[13], v) }
|
|
175
|
+
|
|
176
|
+
/** @internal chisel `comp_write` (see core/compWrite.ts): `node.position.<axis> = v` is compiled to a
|
|
177
|
+
* call here; the scalar setters already carry the physics routing. The list is compile-time data. */
|
|
178
|
+
static _comps = [ "position" ]
|
|
179
|
+
_writeComp(_prop: string, axis: CompAxis, v: number): void {
|
|
180
|
+
if (axis === "x") this.x = v
|
|
181
|
+
else if (axis === "y") this.y = v
|
|
182
|
+
else if (axis === "z") this.z = v
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
get scale(): Vec3 {
|
|
186
|
+
const m = this._sync()
|
|
187
|
+
return new Vec3(Math.hypot(m[0], m[1], m[2]), Math.hypot(m[4], m[5], m[6]), Math.hypot(m[8], m[9], m[10]))
|
|
188
|
+
}
|
|
189
|
+
set scale(v: Vec3Like | number) {
|
|
190
|
+
if (typeof v === "number") _creator.setScale(this.id, v, v, v)
|
|
191
|
+
else _creator.setScale(this.id, cx(v), cy(v), cz(v))
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
get quaternion(): Quat { return new Mat4(this._sync()).rotation }
|
|
195
|
+
set quaternion(v: QuatLike) {
|
|
196
|
+
_creator.setQuaternion(this.id, cx(v), cy(v), cz(v), cw(v))
|
|
197
|
+
if (this._xf) this._setOwnedRotation()
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
get eulerAngles(): Vec3 { return new Mat4(this._sync()).eulerAngles }
|
|
201
|
+
// order 1 = YXZ — the SDK's euler convention (math/quat.ts); the getter also extracts YXZ, so
|
|
202
|
+
// the pair round-trips. (Historically this passed 0/XYZ AND the engine stored the euler matrix
|
|
203
|
+
// transposed — the setter applied the INVERSE rotation. Both fixed 2026-07-10.)
|
|
204
|
+
set eulerAngles(v: Vec3Like) {
|
|
205
|
+
_creator.setEulerAngles(this.id, cx(v), cy(v), cz(v), 1)
|
|
206
|
+
if (this._xf) this._setOwnedRotation()
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// --- world-space reads ---
|
|
210
|
+
get forward(): Vec3 {
|
|
211
|
+
const v = new Float32Array(3)
|
|
212
|
+
_creator.getWorldDirection(this.id, 2, v)
|
|
213
|
+
return new Vec3(-v[0], -v[1], -v[2])
|
|
214
|
+
}
|
|
215
|
+
get worldPosition(): Vec3 {
|
|
216
|
+
const v = new Float32Array(3)
|
|
217
|
+
_creator.getWorldPosition(this.id, v)
|
|
218
|
+
return new Vec3(v[0], v[1], v[2])
|
|
219
|
+
}
|
|
220
|
+
get worldScale(): Vec3 { return this.worldMatrix.scaling }
|
|
221
|
+
get worldQuaternion(): Quat { return this.worldMatrix.rotation }
|
|
222
|
+
get worldEulerAngles(): Vec3 { return this.worldMatrix.eulerAngles }
|
|
223
|
+
|
|
224
|
+
// --- hierarchy ---
|
|
225
|
+
get parent(): Node | null {
|
|
226
|
+
const id = _creator.getParent(this.id)
|
|
227
|
+
return id === 0 ? null : (nodeRegistry.get(id) ?? new Node(id))
|
|
228
|
+
}
|
|
229
|
+
get children(): Node[] {
|
|
230
|
+
return _creator.getChildren(this.id).map((id) => nodeRegistry.get(id) ?? new Node(id))
|
|
231
|
+
}
|
|
232
|
+
get childCount(): number { return _creator.getChildCount(this.id) }
|
|
233
|
+
getChild(index: number): Node | null {
|
|
234
|
+
const id = _creator.getChild(this.id, index)
|
|
235
|
+
return id === 0 ? null : (nodeRegistry.get(id) ?? new Node(id))
|
|
236
|
+
}
|
|
237
|
+
/** Parent the given nodes under this one. */
|
|
238
|
+
add(...children: Node[]): this {
|
|
239
|
+
for (const c of children) _creator.setParent(c.id, this.id, false)
|
|
240
|
+
return this
|
|
241
|
+
}
|
|
242
|
+
setParent(parent: Node | null, worldPositionStays = false): this {
|
|
243
|
+
if (parent === null) _creator.setParentNull(this.id, worldPositionStays)
|
|
244
|
+
else _creator.setParent(this.id, parent.id, worldPositionStays)
|
|
245
|
+
return this
|
|
246
|
+
}
|
|
247
|
+
traverse(callback: (node: Node) => void): void {
|
|
248
|
+
callback(this)
|
|
249
|
+
_creator.traverse(this.id, (id) => callback(nodeRegistry.get(id) ?? new Node(id)))
|
|
250
|
+
}
|
|
251
|
+
// --- materials (any renderable: a Mesh, or an internal node of a loaded Model) ---
|
|
252
|
+
/** The material assigned to slot 0 through this API (null before one is set — a GLB part's own
|
|
253
|
+
* glTF material stays native-side). */
|
|
254
|
+
get material(): Material | null { return this.getMaterial(0) }
|
|
255
|
+
set material(m: Material) { this.setMaterial(m, 0) }
|
|
256
|
+
/** Replace the material of one primitive slot (`index` = the primitive's order in the glTF
|
|
257
|
+
* mesh; a primitive-shape Mesh has one slot). */
|
|
258
|
+
setMaterial(material: Material, index = 0): this {
|
|
259
|
+
(this._materials ??= [])[index] = material
|
|
260
|
+
_creator.setMaterial(this.id, Material.idOf(material), index)
|
|
261
|
+
return this
|
|
262
|
+
}
|
|
263
|
+
/** The material previously assigned to `index` (null when none was — see Mesh for the probe). */
|
|
264
|
+
getMaterial(index = 0): Material | null {
|
|
265
|
+
return this._materials?.[index] ?? null
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** Find a descendant by name — bones of a loaded Model included (`hero.bone('RightHand').add(sword)`).
|
|
269
|
+
* Same rule the Animator binds clips with: exact name first, then the part after the last `:` / `|`
|
|
270
|
+
* (Mixamo `mixamorig:Hips` matches `Hips`); a skinned joint beats a plain node of the same name.
|
|
271
|
+
* Cached per name; null if absent. */
|
|
272
|
+
bone(name: string): Node | null {
|
|
273
|
+
const cache = (this._boneCache ??= new Map<string, Node | null>())
|
|
274
|
+
const hit = cache.get(name)
|
|
275
|
+
if (hit !== undefined) return hit
|
|
276
|
+
const id = _creator.findNode ? _creator.findNode(this.id, name) : findNodeByWalk(this.id, name)
|
|
277
|
+
const found = id ? nodeRegistry.get(id) ?? new Node(id) : null
|
|
278
|
+
cache.set(name, found)
|
|
279
|
+
return found
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// --- behaviors are aspects: node.aspect(Shape, …) / node.aspect(Physics, …) ---
|
|
283
|
+
|
|
284
|
+
/** Orient the node so the given axis (default "-z", "forward") points at a world point. */
|
|
285
|
+
lookAt(point: Vec3Like, mode: "z" | "-z" | "x" | "-x" | "y" | "-y" = "-z", ortho: Vec3Like = [ 0, 1, 0 ]): this {
|
|
286
|
+
const world = this.worldMatrix
|
|
287
|
+
const pos = world.position
|
|
288
|
+
let dir = new Vec3(point).sub(pos)
|
|
289
|
+
const len = dir.length()
|
|
290
|
+
if (len === 0) return this
|
|
291
|
+
let axis: string = mode
|
|
292
|
+
if (mode.startsWith("-")) { dir = dir.scale(-1 / len); axis = mode.slice(1) }
|
|
293
|
+
else dir = dir.scale(1 / len)
|
|
294
|
+
|
|
295
|
+
const o = new Vec3(ortho)
|
|
296
|
+
let forward: Vec3, right: Vec3, up: Vec3
|
|
297
|
+
if (axis === "x") {
|
|
298
|
+
right = dir; up = o.cross(right).normalize(); forward = up.cross(right).normalize()
|
|
299
|
+
} else if (axis === "y") {
|
|
300
|
+
up = dir; right = o.cross(up).normalize(); forward = up.cross(right).normalize()
|
|
301
|
+
} else {
|
|
302
|
+
forward = dir; right = o.cross(dir).normalize(); up = dir.cross(right)
|
|
303
|
+
}
|
|
304
|
+
const s = world.scaling, w = world.m
|
|
305
|
+
this.worldMatrix = Float32Array.of(
|
|
306
|
+
right.x * s.x, right.y * s.x, right.z * s.x, 0,
|
|
307
|
+
up.x * s.y, up.y * s.y, up.z * s.y, 0,
|
|
308
|
+
forward.x * s.z, forward.y * s.z, forward.z * s.z, 0,
|
|
309
|
+
w[12], w[13], w[14], w[15],
|
|
310
|
+
)
|
|
311
|
+
return this
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// --- events ---
|
|
315
|
+
override addEventListener<K extends keyof NodeEvents>(channel: K, callback: NodeEvents[K]): void {
|
|
316
|
+
if (channel === "click") registerTouchEndEvent()
|
|
317
|
+
else if (channel === "touchstart") registerTouchStartEvent()
|
|
318
|
+
else if (channel === "enter" || channel === "exit") ensurePhysicsEvents()
|
|
319
|
+
super.addEventListener(channel, callback)
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** @internal — called by the touch system to deliver a hit. */
|
|
323
|
+
_dispatchEvent<K extends keyof NodeEvents>(channel: K, ...args: Parameters<NodeEvents[K]>): void {
|
|
324
|
+
this.dispatch(channel, ...args)
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/** @internal — emit a physics contact/trigger event (the physics-event router can't reach dispatch). */
|
|
328
|
+
_emitCollision(channel: "enter" | "exit", other: Node): void { this.dispatch(channel, other) }
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
/** Destroy this node and its whole subtree. Every aspect in the subtree is detached first (its
|
|
332
|
+
* `onDetach` runs: physics bodies released, updaters unregistered, listeners dropped) — native
|
|
333
|
+
* `destroyEntity` frees the entity tree but knows nothing about JS-side aspects, and a destroyed
|
|
334
|
+
* node's `update()` must not keep ticking. Deepest nodes go first, then this one. */
|
|
335
|
+
destroy(): void {
|
|
336
|
+
const subtree: Node[] = [this]
|
|
337
|
+
_creator.traverse(this.id, (id) => { const n = nodeRegistry.get(id); if (n) subtree.push(n) })
|
|
338
|
+
for (let i = subtree.length - 1; i >= 0; i--) {
|
|
339
|
+
const n = subtree[i]
|
|
340
|
+
n._detachAll()
|
|
341
|
+
n._xf = 0
|
|
342
|
+
n._xfKind = 0
|
|
343
|
+
nodeRegistry.delete(n.id)
|
|
344
|
+
}
|
|
345
|
+
_creator.destroyEntity(this.id)
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/** Read the raw column-major elements out of a Mat4 wrapper or a plain length-16 array. */
|
|
350
|
+
const matArr = (m: Mat4Like): ArrayLike<number> => (m as { m?: ArrayLike<number> }).m ?? (m as ArrayLike<number>)
|
package/src/gl/Noise.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Native FastNoise (Perlin/fractal) sampler. Ported from worker/src/utils/PerlinNoise.ts.
|
|
2
|
+
|
|
3
|
+
export class Noise {
|
|
4
|
+
private readonly _id: number
|
|
5
|
+
|
|
6
|
+
constructor() {
|
|
7
|
+
this._id = _creator.createNoise()
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Sample 2D noise. */
|
|
11
|
+
get(x: number, y: number): number { return _creator.getNoise2D(this._id, x, y) }
|
|
12
|
+
/** Sample 3D noise. */
|
|
13
|
+
get3d(x: number, y: number, z: number): number { return _creator.getNoise3D(this._id, x, y, z) }
|
|
14
|
+
|
|
15
|
+
private _frequency = 0.01
|
|
16
|
+
get frequency(): number { return this._frequency }
|
|
17
|
+
set frequency(v: number) { this._frequency = v; _creator.setNoiseFrequency(this._id, v) }
|
|
18
|
+
|
|
19
|
+
private _octaves = 1
|
|
20
|
+
get octaves(): number { return this._octaves }
|
|
21
|
+
set octaves(v: number) { this._octaves = v; _creator.setNoiseOctaves(this._id, v) }
|
|
22
|
+
|
|
23
|
+
private _fractalLacunarity = 2
|
|
24
|
+
get fractalLacunarity(): number { return this._fractalLacunarity }
|
|
25
|
+
set fractalLacunarity(v: number) { this._fractalLacunarity = v; _creator.setNoiseFractalLunacrity(this._id, v) }
|
|
26
|
+
|
|
27
|
+
private _fractalGain = 0.5
|
|
28
|
+
get fractalGain(): number { return this._fractalGain }
|
|
29
|
+
set fractalGain(v: number) { this._fractalGain = v; _creator.setNoiseFractalGain(this._id, v) }
|
|
30
|
+
}
|