@auraindustry/aurajs 0.0.7 → 0.1.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 +98 -2
- package/benchmarks/perf-thresholds.json +54 -0
- package/package.json +4 -7
- package/src/asset-pack.mjs +5 -1
- package/src/authored-project.mjs +1449 -0
- package/src/authored-runtime.mjs +2016 -0
- package/src/authoring/avatar-animation-graph.mjs +648 -0
- package/src/bin-integrity.mjs +272 -0
- package/src/build-contract/assets.mjs +130 -0
- package/src/build-contract/capabilities.mjs +116 -0
- package/src/build-contract/constants.mjs +6 -0
- package/src/build-contract/helpers.mjs +44 -0
- package/src/build-contract/web-templates.mjs +5993 -0
- package/src/build-contract.mjs +27 -2910
- package/src/bundler.mjs +188 -55
- package/src/cli.mjs +4825 -1512
- package/src/commands/project-authoring.mjs +434 -0
- package/src/config.mjs +27 -0
- package/src/conformance/cases/app-and-ui-runtime-cases.mjs +3309 -0
- package/src/conformance/cases/core-runtime-cases.mjs +1431 -0
- package/src/conformance/cases/index.mjs +11 -0
- package/src/conformance/cases/scene3d-and-media-cases.mjs +2094 -0
- package/src/conformance/cases/systems-and-gameplay-cases.mjs +1776 -0
- package/src/conformance/shared.mjs +27 -0
- package/src/conformance-runner.mjs +25 -13
- package/src/conformance.mjs +619 -4020
- package/src/cutscene.mjs +362 -5
- package/src/dev-cli-action.mjs +249 -0
- package/src/dev-cli-inspect.mjs +92 -0
- package/src/dev-cli-state.mjs +80 -0
- package/src/external-asset-cache.mjs +587 -0
- package/src/external-asset-policy.mjs +217 -0
- package/src/external-package-surface.mjs +206 -0
- package/src/game-action-runtime.mjs +869 -0
- package/src/game-state-runtime.mjs +206 -6
- package/src/headless-action.mjs +186 -0
- package/src/headless-test/runtime-animation.mjs +1173 -0
- package/src/headless-test/runtime-coordinator.mjs +1514 -0
- package/src/headless-test/runtime-primitives.mjs +320 -0
- package/src/headless-test/runtime-world.mjs +2253 -0
- package/src/headless-test.mjs +392 -4298
- package/src/host-binary.mjs +342 -14
- package/src/icon-discovery.mjs +64 -0
- package/src/make-catalog.mjs +109 -0
- package/src/make.mjs +197 -0
- package/src/package-integrity.mjs +586 -0
- package/src/perf-benchmark.mjs +353 -0
- package/src/postinstall.mjs +5 -5
- package/src/prefabs/index.mjs +34 -0
- package/src/prefabs/scene-serialization.mjs +184 -0
- package/src/project-importer.mjs +620 -0
- package/src/project-registry.mjs +24 -0
- package/src/publish-command.mjs +195 -0
- package/src/publish-env-example.mjs +83 -0
- package/src/publish-validation.mjs +708 -0
- package/src/retro/assets/compile.mjs +232 -0
- package/src/retro/backend-gba/authoring.mjs +1029 -0
- package/src/retro/backend-gba/rom.mjs +363 -0
- package/src/retro/backend-gbc/rom.mjs +85 -0
- package/src/retro/build.mjs +278 -0
- package/src/retro/cli/commands.mjs +292 -0
- package/src/retro/cli/templates.mjs +84 -0
- package/src/retro/diagnostics/catalog.mjs +110 -0
- package/src/retro/diagnostics/emit.mjs +72 -0
- package/src/retro/emulator/case-overlay.mjs +64 -0
- package/src/retro/emulator/discovery.mjs +158 -0
- package/src/retro/emulator/macos-case-overlay.swift +220 -0
- package/src/retro/emulator/profiles.mjs +146 -0
- package/src/retro/emulator/runner.mjs +289 -0
- package/src/retro/frontend/load-project.mjs +98 -0
- package/src/retro/index.mjs +30 -0
- package/src/retro/ir/build-ir.mjs +108 -0
- package/src/retro/runtime-gba/contract.mjs +151 -0
- package/src/retro/runtime-gbc/contract.mjs +117 -0
- package/src/retro/shared/span.mjs +26 -0
- package/src/retro/shared/targets.mjs +64 -0
- package/src/retro/validator/check-project.mjs +114 -0
- package/src/runtime-hotspot-audit.mjs +707 -0
- package/src/scaffold/config.mjs +1000 -0
- package/src/scaffold/fs.mjs +56 -0
- package/src/scaffold/layout.mjs +318 -0
- package/src/scaffold/project-docs.mjs +438 -0
- package/src/scaffold.mjs +93 -596
- package/src/scene-composition/index.mjs +326 -0
- package/src/scene-composition/runtime.mjs +751 -0
- package/src/self-hosted-assets.mjs +604 -0
- package/src/session-client.mjs +750 -0
- package/src/session-native-launcher.mjs +74 -0
- package/src/session-protocol.mjs +75 -0
- package/src/session-runtime.mjs +321 -0
- package/src/session-server.mjs +360 -0
- package/src/shader-kits/index.mjs +773 -0
- package/src/starter-content-registry.mjs +292 -0
- package/src/state-artifacts.mjs +662 -24
- package/src/state-dev-reload.mjs +99 -2
- package/src/terminal-ui.mjs +245 -0
- package/src/web-conformance.mjs +219 -0
- package/templates/create/2d/config/gameplay/shooter.config.js +26 -0
- package/templates/create/2d/content/gameplay/waves.json +26 -0
- package/templates/create/2d/content/registries/.gitkeep +1 -0
- package/templates/create/2d/docs/design/.gitkeep +1 -0
- package/templates/create/2d/docs/design/loop.md +5 -0
- package/templates/create/2d/prefabs/enemies.prefab.js +90 -0
- package/templates/create/2d/prefabs/enemy-basic.prefab.js +18 -0
- package/templates/create/2d/prefabs/player.prefab.js +36 -0
- package/templates/create/2d/prefabs/projectiles.prefab.js +35 -0
- package/templates/create/2d/scenes/boot.scene.js +12 -0
- package/templates/create/2d/scenes/gameplay.scene.js +230 -0
- package/templates/create/2d/scenes/menu.scene.js +9 -0
- package/templates/create/2d/src/main.js +6 -185
- package/templates/create/2d/src/runtime/app.js +49 -0
- package/templates/create/2d/src/runtime/capabilities.js +35 -0
- package/templates/create/2d/ui/hud.screen.js +40 -0
- package/templates/create/2d/ui/pause.screen.js +149 -0
- package/templates/create/2d/ui/settings.screen.js +347 -0
- package/templates/create/2d/ui/title.screen.js +13 -0
- package/templates/create/2d-adventure/aura.config.json +28 -0
- package/templates/create/2d-adventure/config/gameplay/adventure.config.js +14 -0
- package/templates/create/2d-adventure/content/gameplay/world.js +46 -0
- package/templates/create/2d-adventure/content/registries/.gitkeep +1 -0
- package/templates/create/2d-adventure/docs/design/loop.md +5 -0
- package/templates/create/2d-adventure/prefabs/player.prefab.js +54 -0
- package/templates/create/2d-adventure/prefabs/relic.prefab.js +38 -0
- package/templates/create/2d-adventure/prefabs/world.prefab.js +125 -0
- package/templates/create/2d-adventure/scenes/gameplay.scene.js +256 -0
- package/templates/create/2d-adventure/src/runtime/capabilities.js +34 -0
- package/templates/create/2d-adventure/ui/hud.screen.js +60 -0
- package/templates/create/2d-survivor/config/gameplay/survivor.config.js +33 -0
- package/templates/create/2d-survivor/content/gameplay/spawn-zones.json +29 -0
- package/templates/create/2d-survivor/content/registries/.gitkeep +1 -0
- package/templates/create/2d-survivor/docs/design/.gitkeep +1 -0
- package/templates/create/2d-survivor/docs/design/loop.md +5 -0
- package/templates/create/2d-survivor/prefabs/enemies.prefab.js +178 -0
- package/templates/create/2d-survivor/prefabs/enemy-swarm.prefab.js +18 -0
- package/templates/create/2d-survivor/prefabs/player.prefab.js +42 -0
- package/templates/create/2d-survivor/prefabs/projectiles.prefab.js +56 -0
- package/templates/create/2d-survivor/scenes/boot.scene.js +12 -0
- package/templates/create/2d-survivor/scenes/gameplay.scene.js +314 -0
- package/templates/create/2d-survivor/scenes/menu.scene.js +9 -0
- package/templates/create/2d-survivor/src/main.js +5 -332
- package/templates/create/2d-survivor/src/runtime/app.js +49 -0
- package/templates/create/2d-survivor/src/runtime/capabilities.js +35 -0
- package/templates/create/2d-survivor/ui/hud.screen.js +45 -0
- package/templates/create/2d-survivor/ui/title.screen.js +13 -0
- package/templates/create/3d/assets/models/starter-avatar.gltf +184 -0
- package/templates/create/3d/config/gameplay/.gitkeep +1 -0
- package/templates/create/3d/content/gameplay/checkpoints.json +33 -0
- package/templates/create/3d/content/gameplay/course.js +40 -0
- package/templates/create/3d/content/registries/.gitkeep +1 -0
- package/templates/create/3d/docs/design/.gitkeep +1 -0
- package/templates/create/3d/docs/design/loop.md +5 -0
- package/templates/create/3d/prefabs/checkpoint.prefab.js +15 -0
- package/templates/create/3d/prefabs/player.prefab.js +204 -0
- package/templates/create/3d/prefabs/world.prefab.js +112 -0
- package/templates/create/3d/scenes/boot.scene.js +12 -0
- package/templates/create/3d/scenes/checkpoint.scene.js +9 -0
- package/templates/create/3d/scenes/gameplay.scene.js +292 -0
- package/templates/create/3d/src/main.js +6 -295
- package/templates/create/3d/src/runtime/app.js +49 -0
- package/templates/create/3d/src/runtime/capabilities.js +53 -0
- package/templates/create/3d/src/runtime/materials.js +34 -0
- package/templates/create/3d/src/runtime/state.js +39 -0
- package/templates/create/3d/ui/hud.screen.js +75 -0
- package/templates/create/3d/ui/pause.screen.js +166 -0
- package/templates/create/3d/ui/settings.screen.js +387 -0
- package/templates/create/3d-adventure/assets/models/starter-avatar.gltf +184 -0
- package/templates/create/3d-adventure/aura.config.json +28 -0
- package/templates/create/3d-adventure/config/gameplay/adventure.config.js +9 -0
- package/templates/create/3d-adventure/content/gameplay/course.js +62 -0
- package/templates/create/3d-adventure/content/registries/.gitkeep +1 -0
- package/templates/create/3d-adventure/docs/design/loop.md +5 -0
- package/templates/create/3d-adventure/prefabs/player.prefab.js +168 -0
- package/templates/create/3d-adventure/prefabs/relic.prefab.js +35 -0
- package/templates/create/3d-adventure/prefabs/world.prefab.js +119 -0
- package/templates/create/3d-adventure/scenes/gameplay.scene.js +358 -0
- package/templates/create/3d-adventure/src/runtime/capabilities.js +56 -0
- package/templates/create/3d-adventure/src/runtime/materials.js +39 -0
- package/templates/create/3d-adventure/src/runtime/state.js +31 -0
- package/templates/create/3d-adventure/ui/hud.screen.js +70 -0
- package/templates/create/3d-adventure/ui/pause.screen.js +437 -0
- package/templates/create/3d-collectathon/assets/models/starter-avatar.gltf +184 -0
- package/templates/create/3d-collectathon/config/gameplay/.gitkeep +1 -0
- package/templates/create/3d-collectathon/content/gameplay/collectibles.json +26 -0
- package/templates/create/3d-collectathon/content/gameplay/course.js +46 -0
- package/templates/create/3d-collectathon/content/registries/.gitkeep +1 -0
- package/templates/create/3d-collectathon/docs/design/.gitkeep +1 -0
- package/templates/create/3d-collectathon/docs/design/loop.md +5 -0
- package/templates/create/3d-collectathon/prefabs/collectible.prefab.js +15 -0
- package/templates/create/3d-collectathon/prefabs/player.prefab.js +207 -0
- package/templates/create/3d-collectathon/prefabs/world.prefab.js +112 -0
- package/templates/create/3d-collectathon/scenes/boot.scene.js +12 -0
- package/templates/create/3d-collectathon/scenes/checkpoint.scene.js +9 -0
- package/templates/create/3d-collectathon/scenes/gameplay.scene.js +200 -0
- package/templates/create/3d-collectathon/src/main.js +5 -355
- package/templates/create/3d-collectathon/src/runtime/app.js +49 -0
- package/templates/create/3d-collectathon/src/runtime/capabilities.js +53 -0
- package/templates/create/3d-collectathon/src/runtime/materials.js +34 -0
- package/templates/create/3d-collectathon/src/runtime/state.js +27 -0
- package/templates/create/3d-collectathon/ui/hud.screen.js +66 -0
- package/templates/create/3d-collectathon/ui/pause.screen.js +13 -0
- package/templates/create/blank/config/gameplay/.gitkeep +1 -0
- package/templates/create/blank/content/gameplay/.gitkeep +1 -0
- package/templates/create/blank/content/registries/.gitkeep +1 -0
- package/templates/create/blank/docs/design/.gitkeep +1 -0
- package/templates/create/blank/docs/design/loop.md +5 -0
- package/templates/create/blank/prefabs/.gitkeep +1 -0
- package/templates/create/blank/scenes/.gitkeep +1 -0
- package/templates/create/blank/src/runtime/.gitkeep +1 -0
- package/templates/create/blank/ui/.gitkeep +1 -0
- package/templates/create/deckbuilder-2d/assets/audio/.gitkeep +1 -0
- package/templates/create/deckbuilder-2d/assets/fonts/.gitkeep +1 -0
- package/templates/create/deckbuilder-2d/assets/sprites/.gitkeep +1 -0
- package/templates/create/deckbuilder-2d/assets/starter/README.md +11 -0
- package/templates/create/deckbuilder-2d/assets/ui/.gitkeep +1 -0
- package/templates/create/deckbuilder-2d/aura.config.json +28 -0
- package/templates/create/deckbuilder-2d/config/gameplay/deckbuilder.config.js +26 -0
- package/templates/create/deckbuilder-2d/content/cards/guard.card.js +19 -0
- package/templates/create/deckbuilder-2d/content/cards/spark.card.js +20 -0
- package/templates/create/deckbuilder-2d/content/cards/starter.deck.js +69 -0
- package/templates/create/deckbuilder-2d/content/cards/strike.card.js +19 -0
- package/templates/create/deckbuilder-2d/content/cards/survey.card.js +20 -0
- package/templates/create/deckbuilder-2d/content/encounters/training-battle.encounter.js +14 -0
- package/templates/create/deckbuilder-2d/content/encounters/training-battle.js +65 -0
- package/templates/create/deckbuilder-2d/content/enemies/training-automaton.enemy.js +48 -0
- package/templates/create/deckbuilder-2d/content/gameplay/.gitkeep +1 -0
- package/templates/create/deckbuilder-2d/content/registries/cards.registry.js +26 -0
- package/templates/create/deckbuilder-2d/content/registries/encounters.registry.js +20 -0
- package/templates/create/deckbuilder-2d/content/registries/enemies.registry.js +20 -0
- package/templates/create/deckbuilder-2d/content/registries/relics.registry.js +20 -0
- package/templates/create/deckbuilder-2d/content/relics/ember-charm.relic.js +18 -0
- package/templates/create/deckbuilder-2d/docs/design/loop.md +12 -0
- package/templates/create/deckbuilder-2d/prefabs/.gitkeep +1 -0
- package/templates/create/deckbuilder-2d/scenes/boot.scene.js +84 -0
- package/templates/create/deckbuilder-2d/scenes/gameplay.scene.js +641 -0
- package/templates/create/deckbuilder-2d/src/components/.gitkeep +1 -0
- package/templates/create/deckbuilder-2d/src/main.js +17 -0
- package/templates/create/deckbuilder-2d/src/runtime/capabilities.js +22 -0
- package/templates/create/deckbuilder-2d/src/shared/.gitkeep +1 -0
- package/templates/create/deckbuilder-2d/src/systems/.gitkeep +1 -0
- package/templates/create/deckbuilder-2d/tests/smoke/.gitkeep +1 -0
- package/templates/create/deckbuilder-2d/ui/hud.screen.js +80 -0
- package/templates/create/deckbuilder-2d/ui/pause.screen.js +146 -0
- package/templates/create/deckbuilder-2d/ui/settings.screen.js +342 -0
- package/templates/create/local-multiplayer/aura.config.json +40 -0
- package/templates/create/local-multiplayer/config/gameplay/local-multiplayer.config.js +26 -0
- package/templates/create/local-multiplayer/content/gameplay/room-layout.js +13 -0
- package/templates/create/local-multiplayer/content/registries/.gitkeep +1 -0
- package/templates/create/local-multiplayer/docs/design/loop.md +14 -0
- package/templates/create/local-multiplayer/prefabs/player.prefab.js +99 -0
- package/templates/create/local-multiplayer/scenes/boot.scene.js +12 -0
- package/templates/create/local-multiplayer/scenes/gameplay.scene.js +443 -0
- package/templates/create/local-multiplayer/src/main.js +17 -0
- package/templates/create/local-multiplayer/src/runtime/capabilities.js +28 -0
- package/templates/create/local-multiplayer/ui/hud.screen.js +60 -0
- package/templates/create/shared/src/runtime/project-inspector.js +105 -0
- package/templates/create/shared/src/runtime/scene-flow.js +290 -0
- package/templates/create/shared/src/runtime/screen-shell.js +222 -0
- package/templates/create/shared/src/runtime/ui-forms.js +209 -0
- package/templates/create/shared/src/runtime/ui-settings.js +237 -0
- package/templates/create/shared/src/runtime/ui-theme.js +352 -0
- package/templates/create/shared/src/starter-utils/adventure-objectives.js +102 -0
- package/templates/create/shared/src/starter-utils/animation-2d.js +337 -0
- package/templates/create/shared/src/starter-utils/avatar-3d.js +404 -0
- package/templates/create/shared/src/starter-utils/combat-feedback-2d.js +320 -0
- package/templates/create/shared/src/starter-utils/core.js +39 -3
- package/templates/create/shared/src/starter-utils/index.js +8 -2
- package/templates/create/shared/src/starter-utils/platformer-3d.js +34 -3
- package/templates/create/shared/src/starter-utils/triggers.js +662 -0
- package/templates/create/shared/src/starter-utils/tween-2d.js +615 -0
- package/templates/create/video-cutscene/assets/video/.gitkeep +0 -0
- package/templates/create/video-cutscene/aura.config.json +28 -0
- package/templates/create/video-cutscene/config/gameplay/.gitkeep +0 -0
- package/templates/create/video-cutscene/content/gameplay/.gitkeep +0 -0
- package/templates/create/video-cutscene/content/registries/.gitkeep +0 -0
- package/templates/create/video-cutscene/docs/design/loop.md +22 -0
- package/templates/create/video-cutscene/prefabs/.gitkeep +0 -0
- package/templates/create/video-cutscene/scenes/boot.scene.js +11 -0
- package/templates/create/video-cutscene/scenes/cutscene.scene.js +113 -0
- package/templates/create/video-cutscene/scenes/gameplay.scene.js +50 -0
- package/templates/create/video-cutscene/src/main.js +17 -0
- package/templates/create/video-cutscene/src/runtime/app.js +52 -0
- package/templates/create/video-cutscene/src/runtime/capabilities.js +35 -0
- package/templates/create/video-cutscene/src/runtime/state.js +13 -0
- package/templates/create/video-cutscene/ui/.gitkeep +0 -0
- package/templates/create-bin/play.js +1187 -0
- package/templates/make/README.md +46 -0
- package/templates/make/catalog.json +51 -0
- package/templates/make/component/files/{{MAKE_NAME}}.component.js +20 -0
- package/templates/make/component/manifest.json +9 -0
- package/templates/make/data/files/{{MAKE_NAME}}.json +14 -0
- package/templates/make/data/manifest.json +9 -0
- package/templates/make/material/files/{{MAKE_NAME}}.material.json +17 -0
- package/templates/make/material/manifest.json +9 -0
- package/templates/make/prefab/files/{{MAKE_NAME}}.prefab.js +20 -0
- package/templates/make/prefab/manifest.json +9 -0
- package/templates/make/scene/files/{{MAKE_NAME}}.scene.js +31 -0
- package/templates/make/scene/manifest.json +9 -0
- package/templates/make/shader/files/{{MAKE_NAME}}.shader.js +23 -0
- package/templates/make/shader/manifest.json +9 -0
- package/templates/make/system/files/{{MAKE_NAME}}.system.js +15 -0
- package/templates/make/system/manifest.json +9 -0
- package/templates/make/ui-screen/files/{{MAKE_NAME}}.screen.js +16 -0
- package/templates/make/ui-screen/files/{{MAKE_NAME}}.screen.json +23 -0
- package/templates/make/ui-screen/manifest.json +10 -0
- package/templates/make-starters/deckbuilder-2d/card/files/{{MAKE_NAME}}.card.js +22 -0
- package/templates/make-starters/deckbuilder-2d/card/manifest.json +9 -0
- package/templates/make-starters/deckbuilder-2d/catalog.json +34 -0
- package/templates/make-starters/deckbuilder-2d/encounter/files/{{MAKE_NAME}}.encounter.js +18 -0
- package/templates/make-starters/deckbuilder-2d/encounter/manifest.json +9 -0
- package/templates/make-starters/deckbuilder-2d/enemy/files/{{MAKE_NAME}}.enemy.js +28 -0
- package/templates/make-starters/deckbuilder-2d/enemy/manifest.json +9 -0
- package/templates/make-starters/deckbuilder-2d/relic/files/{{MAKE_NAME}}.relic.js +23 -0
- package/templates/make-starters/deckbuilder-2d/relic/manifest.json +9 -0
- package/templates/retro/platformer/README.md +10 -0
- package/templates/retro/platformer/assets/retro/assets.json +91 -0
- package/templates/retro/platformer/aura.config.json +7 -0
- package/templates/retro/platformer/package.json +5 -0
- package/templates/retro/platformer/src/main.js +40 -0
- package/templates/retro/puzzle-grid/README.md +10 -0
- package/templates/retro/puzzle-grid/assets/retro/assets.json +90 -0
- package/templates/retro/puzzle-grid/aura.config.json +7 -0
- package/templates/retro/puzzle-grid/package.json +5 -0
- package/templates/retro/puzzle-grid/src/main.js +29 -0
- package/templates/retro/tactics-grid/README.md +10 -0
- package/templates/retro/tactics-grid/assets/retro/assets.json +90 -0
- package/templates/retro/tactics-grid/aura.config.json +7 -0
- package/templates/retro/tactics-grid/package.json +5 -0
- package/templates/retro/tactics-grid/src/main.js +35 -0
- package/templates/retro/topdown-adventure/README.md +10 -0
- package/templates/retro/topdown-adventure/assets/retro/assets.json +95 -0
- package/templates/retro/topdown-adventure/aura.config.json +7 -0
- package/templates/retro/topdown-adventure/package.json +5 -0
- package/templates/retro/topdown-adventure/src/main.js +29 -0
- package/templates/skills/aurajs/SKILL.md +61 -5
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
import { clamp } from './core.js';
|
|
2
|
+
|
|
3
|
+
function finite(value, fallback = 0) {
|
|
4
|
+
const numeric = Number(value);
|
|
5
|
+
return Number.isFinite(numeric) ? numeric : fallback;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function normalizeVec3(value, fallback = {}) {
|
|
9
|
+
return {
|
|
10
|
+
x: finite(value?.x, finite(fallback?.x, 0)),
|
|
11
|
+
y: finite(value?.y, finite(fallback?.y, 0)),
|
|
12
|
+
z: finite(value?.z, finite(fallback?.z, 0)),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function normalizeScale(value, fallback = {}) {
|
|
17
|
+
return {
|
|
18
|
+
x: Math.max(0.001, finite(value?.x, Math.max(0.001, finite(fallback?.x, 1)))),
|
|
19
|
+
y: Math.max(0.001, finite(value?.y, Math.max(0.001, finite(fallback?.y, 1)))),
|
|
20
|
+
z: Math.max(0.001, finite(value?.z, Math.max(0.001, finite(fallback?.z, 1)))),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function normalizeClipMapEntry(entry) {
|
|
25
|
+
if (Number.isInteger(entry) && entry > 0) {
|
|
26
|
+
return { clipId: entry };
|
|
27
|
+
}
|
|
28
|
+
if (!entry || typeof entry !== 'object') {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
clipId: Number.isInteger(entry.clipId) && entry.clipId > 0 ? entry.clipId : null,
|
|
33
|
+
importId: Number.isInteger(entry.importId) && entry.importId > 0 ? entry.importId : null,
|
|
34
|
+
animation: typeof entry.animation === 'string' && entry.animation.trim().length > 0
|
|
35
|
+
? entry.animation.trim()
|
|
36
|
+
: null,
|
|
37
|
+
loop: typeof entry.loop === 'boolean' ? entry.loop : null,
|
|
38
|
+
speed: Number.isFinite(Number(entry.speed)) ? Number(entry.speed) : null,
|
|
39
|
+
transitionSeconds: Math.max(0, finite(entry.transitionSeconds, 0.16)),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function cloneState(avatar) {
|
|
44
|
+
return {
|
|
45
|
+
bodyId: avatar.bodyId,
|
|
46
|
+
locomotion: avatar.locomotion,
|
|
47
|
+
grounded: avatar.grounded,
|
|
48
|
+
onSlope: avatar.onSlope,
|
|
49
|
+
velocityY: avatar.velocityY,
|
|
50
|
+
facingYaw: avatar.facingYaw,
|
|
51
|
+
position: { ...avatar.position },
|
|
52
|
+
movement: { ...avatar.motion },
|
|
53
|
+
camera: {
|
|
54
|
+
position: { ...avatar.cameraState.position },
|
|
55
|
+
target: { ...avatar.cameraState.target },
|
|
56
|
+
},
|
|
57
|
+
visual: {
|
|
58
|
+
activeClipKey: avatar.visual.activeClipKey,
|
|
59
|
+
activeClipId: avatar.visual.activeClipId,
|
|
60
|
+
sceneNodeId: avatar.visual.sceneNodeId,
|
|
61
|
+
renderTransform: getAvatarRenderTransform3D(avatar),
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function clipCandidatesForLocomotion(locomotion) {
|
|
67
|
+
switch (locomotion) {
|
|
68
|
+
case 'run':
|
|
69
|
+
return ['run', 'walk', 'idle', 'default'];
|
|
70
|
+
case 'fall':
|
|
71
|
+
return ['fall', 'jump', 'idle', 'default'];
|
|
72
|
+
case 'jump':
|
|
73
|
+
return ['jump', 'fall', 'idle', 'default'];
|
|
74
|
+
case 'walk':
|
|
75
|
+
return ['walk', 'run', 'idle', 'default'];
|
|
76
|
+
default:
|
|
77
|
+
return [locomotion, 'idle', 'default'];
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function resolveAvatarClipEntry(avatar, locomotion) {
|
|
82
|
+
const clipMap = avatar.visual.clipMap || {};
|
|
83
|
+
for (const candidate of clipCandidatesForLocomotion(locomotion)) {
|
|
84
|
+
if (!Object.prototype.hasOwnProperty.call(clipMap, candidate)) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
return normalizeClipMapEntry(clipMap[candidate]);
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function ensureClipId(aura, avatar, locomotion) {
|
|
93
|
+
const entry = resolveAvatarClipEntry(avatar, locomotion);
|
|
94
|
+
if (!entry) return null;
|
|
95
|
+
if (Number.isInteger(entry.clipId) && entry.clipId > 0) {
|
|
96
|
+
return { ...entry, clipId: entry.clipId };
|
|
97
|
+
}
|
|
98
|
+
if (!entry.importId || !entry.animation || typeof aura?.scene3d?.playImportedAnimation !== 'function') {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const cacheKey = `${entry.importId}:${entry.animation}:${entry.loop === false ? '0' : '1'}:${entry.speed ?? 1}`;
|
|
103
|
+
const cached = avatar.visual.importedClipCache[cacheKey];
|
|
104
|
+
if (Number.isInteger(cached) && cached > 0) {
|
|
105
|
+
return { ...entry, clipId: cached };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const playback = aura.scene3d.playImportedAnimation(entry.importId, entry.animation, {
|
|
109
|
+
loop: entry.loop !== false,
|
|
110
|
+
speed: entry.speed ?? 1,
|
|
111
|
+
});
|
|
112
|
+
if (playback?.ok === true && Number.isInteger(playback.clipId) && playback.clipId > 0) {
|
|
113
|
+
avatar.visual.importedClipCache[cacheKey] = playback.clipId;
|
|
114
|
+
return { ...entry, clipId: playback.clipId };
|
|
115
|
+
}
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function applyClipState(aura, avatar, locomotion) {
|
|
120
|
+
if (!aura?.scene3d || typeof aura.scene3d !== 'object') return;
|
|
121
|
+
const entry = ensureClipId(aura, avatar, locomotion);
|
|
122
|
+
if (!entry || !Number.isInteger(entry.clipId) || entry.clipId <= 0) return;
|
|
123
|
+
|
|
124
|
+
const nextClipId = entry.clipId;
|
|
125
|
+
const previousClipId = avatar.visual.activeClipId;
|
|
126
|
+
const stateChanged = avatar.visual.activeClipKey !== locomotion || previousClipId !== nextClipId;
|
|
127
|
+
if (!stateChanged) return;
|
|
128
|
+
|
|
129
|
+
if (typeof entry.loop === 'boolean' && typeof aura.scene3d.setClipLoop === 'function') {
|
|
130
|
+
aura.scene3d.setClipLoop(nextClipId, entry.loop);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const transitionSeconds = Math.max(0, finite(entry.transitionSeconds, 0.16));
|
|
134
|
+
if (
|
|
135
|
+
Number.isInteger(previousClipId)
|
|
136
|
+
&& previousClipId > 0
|
|
137
|
+
&& previousClipId !== nextClipId
|
|
138
|
+
&& transitionSeconds > 0
|
|
139
|
+
&& typeof aura.scene3d.crossfadeClips === 'function'
|
|
140
|
+
) {
|
|
141
|
+
aura.scene3d.crossfadeClips(previousClipId, nextClipId, {
|
|
142
|
+
duration: transitionSeconds,
|
|
143
|
+
});
|
|
144
|
+
} else if (typeof aura.scene3d.playClip === 'function') {
|
|
145
|
+
aura.scene3d.playClip(nextClipId);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
avatar.visual.activeClipKey = locomotion;
|
|
149
|
+
avatar.visual.activeClipId = nextClipId;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function syncSceneNodeTransform(aura, avatar) {
|
|
153
|
+
if (!Number.isInteger(avatar.visual.sceneNodeId) || avatar.visual.sceneNodeId <= 0) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (typeof aura?.scene3d?.setLocalTransform !== 'function') {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
aura.scene3d.setLocalTransform(avatar.visual.sceneNodeId, getAvatarRenderTransform3D(avatar));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function syncCamera(aura, avatar) {
|
|
163
|
+
if (avatar.camera.enabled !== true) return;
|
|
164
|
+
if (typeof aura?.camera3d?.setPosition !== 'function' || typeof aura?.camera3d?.lookAt !== 'function') {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
let cameraOffset = avatar.camera.offset;
|
|
169
|
+
if (avatar.camera.rotateWithFacing === true) {
|
|
170
|
+
const cosine = Math.cos(avatar.facingYaw);
|
|
171
|
+
const sine = Math.sin(avatar.facingYaw);
|
|
172
|
+
cameraOffset = {
|
|
173
|
+
x: (avatar.camera.offset.x * cosine) - (avatar.camera.offset.z * sine),
|
|
174
|
+
y: avatar.camera.offset.y,
|
|
175
|
+
z: (avatar.camera.offset.x * sine) + (avatar.camera.offset.z * cosine),
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const target = {
|
|
180
|
+
x: avatar.position.x + avatar.camera.lookOffset.x,
|
|
181
|
+
y: avatar.position.y + avatar.camera.lookOffset.y,
|
|
182
|
+
z: avatar.position.z + avatar.camera.lookOffset.z,
|
|
183
|
+
};
|
|
184
|
+
const position = {
|
|
185
|
+
x: avatar.position.x + cameraOffset.x,
|
|
186
|
+
y: avatar.position.y + cameraOffset.y,
|
|
187
|
+
z: avatar.position.z + cameraOffset.z,
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
avatar.cameraState = { position, target };
|
|
191
|
+
aura.camera3d.setPosition(position.x, position.y, position.z);
|
|
192
|
+
aura.camera3d.lookAt(target.x, target.y, target.z);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function resolveLocomotion(avatar, magnitude) {
|
|
196
|
+
if (!avatar.grounded) {
|
|
197
|
+
return avatar.velocityY > 0.2 ? 'jump' : 'fall';
|
|
198
|
+
}
|
|
199
|
+
if (magnitude >= 0.85) return 'run';
|
|
200
|
+
if (magnitude >= 0.1) return 'walk';
|
|
201
|
+
return 'idle';
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export function createCharacterAvatar3D(options = {}) {
|
|
205
|
+
const radius = Math.max(0.1, finite(options.radius, 0.45));
|
|
206
|
+
const height = Math.max(radius * 2, finite(options.height, 1.1));
|
|
207
|
+
const visualScale = normalizeScale(options.visual?.scale, {
|
|
208
|
+
x: radius * 2,
|
|
209
|
+
y: height,
|
|
210
|
+
z: radius * 2,
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
return {
|
|
214
|
+
bodyId: null,
|
|
215
|
+
position: normalizeVec3(options.position, { x: 0, y: height * 0.5, z: 0 }),
|
|
216
|
+
grounded: false,
|
|
217
|
+
onSlope: false,
|
|
218
|
+
velocityY: 0,
|
|
219
|
+
facingYaw: finite(options.facingYaw, 0),
|
|
220
|
+
locomotion: 'idle',
|
|
221
|
+
motion: {
|
|
222
|
+
moveX: 0,
|
|
223
|
+
moveZ: 0,
|
|
224
|
+
magnitude: 0,
|
|
225
|
+
speed: 0,
|
|
226
|
+
},
|
|
227
|
+
input: {
|
|
228
|
+
moveX: 0,
|
|
229
|
+
moveZ: 0,
|
|
230
|
+
jump: false,
|
|
231
|
+
run: false,
|
|
232
|
+
},
|
|
233
|
+
movement: {
|
|
234
|
+
radius,
|
|
235
|
+
height,
|
|
236
|
+
stepHeight: Math.max(0.05, finite(options.stepHeight, 0.45)),
|
|
237
|
+
slopeLimit: Math.max(1, finite(options.slopeLimit, 48)),
|
|
238
|
+
gravity: Math.max(0, finite(options.gravity, 20)),
|
|
239
|
+
moveSpeed: Math.max(0, finite(options.moveSpeed, 5.3)),
|
|
240
|
+
runSpeed: Math.max(0, finite(options.runSpeed, Math.max(6.4, finite(options.moveSpeed, 5.3)))),
|
|
241
|
+
jumpSpeed: Math.max(0, finite(options.jumpSpeed, 8.2)),
|
|
242
|
+
},
|
|
243
|
+
visual: {
|
|
244
|
+
offset: normalizeVec3(options.visual?.offset),
|
|
245
|
+
scale: visualScale,
|
|
246
|
+
sceneNodeId: Number.isInteger(options.visual?.sceneNodeId) ? options.visual.sceneNodeId : null,
|
|
247
|
+
clipMap: options.visual?.clipMap && typeof options.visual.clipMap === 'object'
|
|
248
|
+
? { ...options.visual.clipMap }
|
|
249
|
+
: {},
|
|
250
|
+
importedClipCache: {},
|
|
251
|
+
activeClipKey: null,
|
|
252
|
+
activeClipId: null,
|
|
253
|
+
},
|
|
254
|
+
camera: {
|
|
255
|
+
enabled: options.camera?.enabled !== false,
|
|
256
|
+
offset: normalizeVec3(options.camera?.offset, { x: 7.4, y: 6.0, z: 8.8 }),
|
|
257
|
+
lookOffset: normalizeVec3(options.camera?.lookOffset, { x: 0, y: 0.2, z: 0 }),
|
|
258
|
+
rotateWithFacing: options.camera?.rotateWithFacing === true,
|
|
259
|
+
},
|
|
260
|
+
cameraState: {
|
|
261
|
+
position: normalizeVec3(options.position, { x: 0, y: height * 0.5, z: 0 }),
|
|
262
|
+
target: normalizeVec3(options.position, { x: 0, y: height * 0.5, z: 0 }),
|
|
263
|
+
},
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export function setAvatarInput3D(avatar, input = {}) {
|
|
268
|
+
avatar.input.moveX = clamp(finite(input.moveX, avatar.input.moveX), -1, 1);
|
|
269
|
+
avatar.input.moveZ = clamp(finite(input.moveZ, avatar.input.moveZ), -1, 1);
|
|
270
|
+
avatar.input.jump = input.jump === true;
|
|
271
|
+
avatar.input.run = input.run === true;
|
|
272
|
+
return avatar.input;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export function setAvatarVisual3D(avatar, options = {}) {
|
|
276
|
+
avatar.visual.offset = normalizeVec3(options.offset, avatar.visual.offset);
|
|
277
|
+
avatar.visual.scale = normalizeScale(options.scale, avatar.visual.scale);
|
|
278
|
+
if (Object.prototype.hasOwnProperty.call(options, 'sceneNodeId')) {
|
|
279
|
+
avatar.visual.sceneNodeId = Number.isInteger(options.sceneNodeId) ? options.sceneNodeId : null;
|
|
280
|
+
}
|
|
281
|
+
if (options.clipMap && typeof options.clipMap === 'object') {
|
|
282
|
+
avatar.visual.clipMap = { ...options.clipMap };
|
|
283
|
+
avatar.visual.activeClipKey = null;
|
|
284
|
+
avatar.visual.activeClipId = null;
|
|
285
|
+
avatar.visual.importedClipCache = {};
|
|
286
|
+
}
|
|
287
|
+
return avatar.visual;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export function spawnCharacterAvatar3D(aura, avatar, options = {}) {
|
|
291
|
+
const position = normalizeVec3(options.position, avatar.position);
|
|
292
|
+
avatar.position = position;
|
|
293
|
+
|
|
294
|
+
if (!Number.isInteger(avatar.bodyId) || avatar.bodyId <= 0) {
|
|
295
|
+
avatar.bodyId = aura.character3d.create({
|
|
296
|
+
x: position.x,
|
|
297
|
+
y: position.y,
|
|
298
|
+
z: position.z,
|
|
299
|
+
radius: avatar.movement.radius,
|
|
300
|
+
height: avatar.movement.height,
|
|
301
|
+
stepHeight: avatar.movement.stepHeight,
|
|
302
|
+
slopeLimit: avatar.movement.slopeLimit,
|
|
303
|
+
gravity: avatar.movement.gravity,
|
|
304
|
+
});
|
|
305
|
+
} else if (typeof aura?.character3d?.setPosition === 'function') {
|
|
306
|
+
aura.character3d.setPosition(avatar.bodyId, position.x, position.y, position.z);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const nextState = typeof aura?.character3d?.getState === 'function'
|
|
310
|
+
? aura.character3d.getState(avatar.bodyId)
|
|
311
|
+
: null;
|
|
312
|
+
if (nextState && typeof nextState === 'object') {
|
|
313
|
+
avatar.position = normalizeVec3(nextState, position);
|
|
314
|
+
avatar.grounded = nextState.grounded === true;
|
|
315
|
+
avatar.velocityY = finite(nextState.velocityY, 0);
|
|
316
|
+
avatar.onSlope = nextState.onSlope === true;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
syncSceneNodeTransform(aura, avatar);
|
|
320
|
+
syncCamera(aura, avatar);
|
|
321
|
+
return avatar.bodyId;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
export function tickCharacterAvatar3D(aura, avatar, dt) {
|
|
325
|
+
const frameDt = Math.max(0, finite(dt, 0));
|
|
326
|
+
if (!Number.isInteger(avatar.bodyId) || avatar.bodyId <= 0) {
|
|
327
|
+
spawnCharacterAvatar3D(aura, avatar);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const rawMoveX = clamp(finite(avatar.input.moveX, 0), -1, 1);
|
|
331
|
+
const rawMoveZ = clamp(finite(avatar.input.moveZ, 0), -1, 1);
|
|
332
|
+
let moveX = rawMoveX;
|
|
333
|
+
let moveZ = rawMoveZ;
|
|
334
|
+
const magnitude = Math.hypot(moveX, moveZ);
|
|
335
|
+
if (magnitude > 1e-6) {
|
|
336
|
+
moveX /= magnitude;
|
|
337
|
+
moveZ /= magnitude;
|
|
338
|
+
avatar.facingYaw = Math.atan2(moveX, moveZ);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
const speed = avatar.input.run === true ? avatar.movement.runSpeed : avatar.movement.moveSpeed;
|
|
342
|
+
if (typeof aura?.character3d?.move === 'function') {
|
|
343
|
+
aura.character3d.move(avatar.bodyId, {
|
|
344
|
+
x: moveX * speed * frameDt,
|
|
345
|
+
y: 0,
|
|
346
|
+
z: moveZ * speed * frameDt,
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
if (avatar.input.jump === true && typeof aura?.character3d?.jump === 'function') {
|
|
351
|
+
aura.character3d.jump(avatar.bodyId, avatar.movement.jumpSpeed);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
if (typeof aura?.character3d?.update === 'function') {
|
|
355
|
+
aura.character3d.update(frameDt);
|
|
356
|
+
}
|
|
357
|
+
const state = typeof aura?.character3d?.getState === 'function'
|
|
358
|
+
? aura.character3d.getState(avatar.bodyId)
|
|
359
|
+
: null;
|
|
360
|
+
if (state && typeof state === 'object') {
|
|
361
|
+
avatar.position = normalizeVec3(state, avatar.position);
|
|
362
|
+
avatar.grounded = state.grounded === true;
|
|
363
|
+
avatar.velocityY = finite(state.velocityY, 0);
|
|
364
|
+
avatar.onSlope = state.onSlope === true;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
avatar.motion = {
|
|
368
|
+
moveX,
|
|
369
|
+
moveZ,
|
|
370
|
+
magnitude,
|
|
371
|
+
speed: magnitude > 1e-6 ? speed : 0,
|
|
372
|
+
};
|
|
373
|
+
avatar.locomotion = resolveLocomotion(avatar, magnitude);
|
|
374
|
+
applyClipState(aura, avatar, avatar.locomotion);
|
|
375
|
+
|
|
376
|
+
if (typeof aura?.scene3d?.updateClips === 'function') {
|
|
377
|
+
aura.scene3d.updateClips(frameDt);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
syncSceneNodeTransform(aura, avatar);
|
|
381
|
+
syncCamera(aura, avatar);
|
|
382
|
+
avatar.input.jump = false;
|
|
383
|
+
return cloneState(avatar);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
export function getAvatarRenderTransform3D(avatar) {
|
|
387
|
+
return {
|
|
388
|
+
position: {
|
|
389
|
+
x: avatar.position.x + avatar.visual.offset.x,
|
|
390
|
+
y: avatar.position.y + avatar.visual.offset.y,
|
|
391
|
+
z: avatar.position.z + avatar.visual.offset.z,
|
|
392
|
+
},
|
|
393
|
+
rotation: {
|
|
394
|
+
x: 0,
|
|
395
|
+
y: avatar.facingYaw,
|
|
396
|
+
z: 0,
|
|
397
|
+
},
|
|
398
|
+
scale: { ...avatar.visual.scale },
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
export function getAvatarState3D(avatar) {
|
|
403
|
+
return cloneState(avatar);
|
|
404
|
+
}
|