@haiyue/extensions 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/LICENSE +21 -0
- package/README.md +30 -0
- package/dist/animation/Animation2DComponent.d.ts +46 -0
- package/dist/animation/Animation2DExtensionRegistry.d.ts +27 -0
- package/dist/animation/Animation2DRenderSystem.d.ts +89 -0
- package/dist/animation/Animation2DRuntime.d.ts +99 -0
- package/dist/animation/Animation2DStateMachine.d.ts +13 -0
- package/dist/animation/Animation2DStateMachineComponent.d.ts +54 -0
- package/dist/animation/Animation2DStateMachineRuntime.d.ts +30 -0
- package/dist/animation/Animation2DStateMachineSystem.d.ts +14 -0
- package/dist/animation/Animation2DStateMachineVisualRuntime.d.ts +27 -0
- package/dist/animation/Animation2DSystem.d.ts +14 -0
- package/dist/animation/AnimationAssetLoader.d.ts +9 -0
- package/dist/animation/AnimationAudioClip.d.ts +26 -0
- package/dist/animation/AnimationPathTessellator.d.ts +52 -0
- package/dist/animation/AnimationTextRasterizer.d.ts +21 -0
- package/dist/animation/AnimationVisual2D.d.ts +68 -0
- package/dist/animation/HyaAnimation2DClipAdapter.d.ts +16 -0
- package/dist/animation/Particle2DDescriptorAdapter.d.ts +5 -0
- package/dist/animation/runtime/mixer/Action.d.ts +150 -0
- package/dist/animation/runtime/mixer/Mixer.d.ts +54 -0
- package/dist/animation/runtime/mixer/PoseBuffer.d.ts +23 -0
- package/dist/animation/runtime/mixer/Sampler.d.ts +17 -0
- package/dist/animation/runtime/mixer/Types.d.ts +101 -0
- package/dist/animation/runtime/mixer/index.d.ts +6 -0
- package/dist/animation-state-machine/AnimationStateMachine.d.ts +111 -0
- package/dist/animation-state-machine/AnimationStateMachineChannels.d.ts +23 -0
- package/dist/animation-state-machine/runtime/Animation2DStateMachineMixerAdapter.d.ts +51 -0
- package/dist/animation-state-machine/runtime/AnimationStateMachineBlendTreeWeights.d.ts +14 -0
- package/dist/animation-state-machine/runtime/AnimationStateMachineCompiler.d.ts +109 -0
- package/dist/animation-state-machine/runtime/AnimationStateMachineController.d.ts +103 -0
- package/dist/animation-state-machine/runtime/AnimationStateMachineMixerPort.d.ts +35 -0
- package/dist/animation-state-machine/runtime/index.d.ts +7 -0
- package/dist/animation.d.ts +15 -0
- package/dist/animation.js +1171 -0
- package/dist/animation3d/Animation3DAction.d.ts +46 -0
- package/dist/animation3d/Animation3DBinding.d.ts +85 -0
- package/dist/animation3d/Animation3DClip.d.ts +20 -0
- package/dist/animation3d/Animation3DError.d.ts +13 -0
- package/dist/animation3d/Animation3DMixer.d.ts +27 -0
- package/dist/animation3d/Animation3DPose.d.ts +40 -0
- package/dist/animation3d/Animation3DPoseBuffer.d.ts +24 -0
- package/dist/animation3d/Animation3DResource.d.ts +28 -0
- package/dist/animation3d/Animation3DStateMachine.d.ts +95 -0
- package/dist/animation3d/Animation3DStateMachineRuntime.d.ts +70 -0
- package/dist/animation3d/Animation3DTrack.d.ts +19 -0
- package/dist/animation3d/hya/HyaAnimation3DRuntime.d.ts +73 -0
- package/dist/animation3d/hya/HyaAnimation3DStateMachineRuntime.d.ts +65 -0
- package/dist/animation3d/hya/HyaAnimation3DTypes.d.ts +170 -0
- package/dist/animation3d/hya/index.d.ts +4 -0
- package/dist/animation3d/index.d.ts +14 -0
- package/dist/animation3d/runtime/integration/Animation3DStateMachineMixerAdapter.d.ts +81 -0
- package/dist/animation3d/runtime/integration/Animation3DStateMachineMixerIntegration.d.ts +39 -0
- package/dist/animation3d/runtime/integration/index.d.ts +2 -0
- package/dist/animation3d/runtime/mixer/Action.d.ts +150 -0
- package/dist/animation3d/runtime/mixer/Animation3DMixerRuntimeStore.d.ts +6 -0
- package/dist/animation3d/runtime/mixer/Mixer.d.ts +59 -0
- package/dist/animation3d/runtime/mixer/PoseBuffer.d.ts +1 -0
- package/dist/animation3d/runtime/mixer/TrackSampler.d.ts +24 -0
- package/dist/animation3d/runtime/mixer/index.d.ts +4 -0
- package/dist/animation3d/runtime/state-machine/Animation3DBlendTreeWeights.d.ts +1 -0
- package/dist/animation3d/runtime/state-machine/Animation3DStateMachineCompiler.d.ts +1 -0
- package/dist/animation3d/runtime/state-machine/Animation3DStateMachineController.d.ts +1 -0
- package/dist/animation3d/runtime/state-machine/Animation3DStateMachineMixerPort.d.ts +1 -0
- package/dist/animation3d/runtime/state-machine/index.d.ts +6 -0
- package/dist/animation3d.d.ts +5 -0
- package/dist/animation3d.js +1708 -0
- package/dist/benchmark.d.ts +30 -0
- package/dist/benchmark.js +119 -0
- package/dist/canvas-text/CanvasText2DRenderSystem.d.ts +24 -0
- package/dist/canvas-text/CanvasTextComponent.d.ts +18 -0
- package/dist/canvas-text.d.ts +4 -0
- package/dist/canvas-text.js +276 -0
- package/dist/chunks/2d-ui-animation-2d.generated-D4aHzFU2.js +4 -0
- package/dist/chunks/2d-ui-canvas-text-2d.generated-C0Eaej2m.js +4 -0
- package/dist/chunks/2d-ui-spine2d.generated-CUUi8xjl.js +4 -0
- package/dist/chunks/2d-ui-tilemap2d.generated-gebw4mX7.js +4 -0
- package/dist/chunks/Animation2DStateMachine-9IonguNa.js +3245 -0
- package/dist/chunks/AnimationStateMachineController-BIcAh-sT.js +1438 -0
- package/dist/chunks/GltfAnimation3DAdapter-Cu3rQQsW.js +2240 -0
- package/dist/chunks/GltfAnimationRuntime-CRHsLycN.js +631 -0
- package/dist/chunks/RenderSystem2DBase-DDT61dAu.js +227 -0
- package/dist/chunks/Spine2DRuntime-D9M9LAQR.js +3056 -0
- package/dist/chunks/SpineAssetParser-BSDmPge1.js +378 -0
- package/dist/chunks/gltfLoader-Dm22jLYB.js +2085 -0
- package/dist/chunks/pluginUtils-CvwroRMd.js +33 -0
- package/dist/experimental-gltf-worker.d.ts +4 -0
- package/dist/experimental-gltf-worker.js +138 -0
- package/dist/experimental-spine-worker.d.ts +4 -0
- package/dist/experimental-spine-worker.js +110 -0
- package/dist/gltf/GltfAccessorReader.d.ts +7 -0
- package/dist/gltf/GltfAnimation3DAdapter.d.ts +47 -0
- package/dist/gltf/GltfAnimationRuntime.d.ts +10 -0
- package/dist/gltf/GltfAssetWorkerClient.d.ts +20 -0
- package/dist/gltf/GltfCompatibilityReport.d.ts +70 -0
- package/dist/gltf/GltfConservativeBounds.d.ts +18 -0
- package/dist/gltf/GltfDracoDecoder.d.ts +4 -0
- package/dist/gltf/GltfExtensionAdapter.d.ts +54 -0
- package/dist/gltf/GltfLoaderContract.d.ts +249 -0
- package/dist/gltf/GltfLoaderErrors.d.ts +4 -0
- package/dist/gltf/GltfMaterialDescriptor.d.ts +23 -0
- package/dist/gltf/GltfMaterialEncoder.d.ts +20 -0
- package/dist/gltf/GltfMaterialLoader.d.ts +6 -0
- package/dist/gltf/GltfModelComponent.d.ts +72 -0
- package/dist/gltf/GltfModelSystem.d.ts +37 -0
- package/dist/gltf/GltfPlugin.d.ts +6 -0
- package/dist/gltf/GltfSchema.d.ts +225 -0
- package/dist/gltf/GltfUvSemanticPlanner.d.ts +33 -0
- package/dist/gltf/gltfLoader.d.ts +9 -0
- package/dist/gltf-animation3d.d.ts +3 -0
- package/dist/gltf-animation3d.js +8 -0
- package/dist/gltf-worker-runtime.d.ts +7 -0
- package/dist/gltf-worker-runtime.js +6981 -0
- package/dist/gltf.d.ts +12 -0
- package/dist/gltf.js +517 -0
- package/dist/grid/Grid2DComponent.d.ts +25 -0
- package/dist/grid.d.ts +2 -0
- package/dist/grid.js +56 -0
- package/dist/hya-state-machine.d.ts +7 -0
- package/dist/hya-state-machine.js +2934 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +7 -0
- package/dist/internal/2d-ui-shader-artifact.js +870 -0
- package/dist/plugins/pluginUtils.d.ts +20 -0
- package/dist/plugins.d.ts +6 -0
- package/dist/shaders/generated/2d-ui-artifact.generated.d.ts +658 -0
- package/dist/spine/Spine2DComponent.d.ts +116 -0
- package/dist/spine/Spine2DGpuRenderer.d.ts +65 -0
- package/dist/spine/Spine2DRenderSystem.d.ts +27 -0
- package/dist/spine/Spine2DRuntime.d.ts +103 -0
- package/dist/spine/SpineAnimationBoneTimelines.d.ts +8 -0
- package/dist/spine/SpineAssetParser.d.ts +18 -0
- package/dist/spine/SpineAssetWorkerClient.d.ts +19 -0
- package/dist/spine/SpineAssetWorkerContract.d.ts +6 -0
- package/dist/spine/SpineAtlasParser.d.ts +21 -0
- package/dist/spine/SpineFloatBuilder.d.ts +15 -0
- package/dist/spine/SpinePathConstraintSolver.d.ts +32 -0
- package/dist/spine/SpinePlugin.d.ts +8 -0
- package/dist/spine/SpineSkeletonRuntime.d.ts +185 -0
- package/dist/spine/SpineSlotAnimation.d.ts +17 -0
- package/dist/spine/SpineTimelineRuntime.d.ts +25 -0
- package/dist/spine/SpineVertexBuilder.d.ts +61 -0
- package/dist/spine.d.ts +7 -0
- package/dist/spine.js +578 -0
- package/dist/tilemap/Tilemap2DComponent.d.ts +110 -0
- package/dist/tilemap/Tilemap2DRenderSystem.d.ts +11 -0
- package/dist/tilemap/Tilemap2DRenderer.d.ts +24 -0
- package/dist/tilemap/TilemapPlugin.d.ts +8 -0
- package/dist/tilemap.d.ts +6 -0
- package/dist/tilemap.js +535 -0
- package/dist/tween/Tween2DComponent.d.ts +70 -0
- package/dist/tween/Tween2DSystem.d.ts +12 -0
- package/dist/tween.d.ts +4 -0
- package/dist/tween.js +138 -0
- package/dist/utils/RenderSystem2DBase.d.ts +42 -0
- package/dist/utils/arrayAccess.d.ts +4 -0
- package/dist/utils/camera2d.d.ts +12 -0
- package/dist/utils/render2dGpu.d.ts +32 -0
- package/package.json +124 -0
- package/src/animation/Animation2DComponent.ts +135 -0
- package/src/animation/Animation2DExtensionRegistry.ts +52 -0
- package/src/animation/Animation2DRenderSystem.ts +1026 -0
- package/src/animation/Animation2DRuntime.ts +1326 -0
- package/src/animation/Animation2DStateMachine.ts +39 -0
- package/src/animation/Animation2DStateMachineComponent.ts +228 -0
- package/src/animation/Animation2DStateMachineRuntime.ts +141 -0
- package/src/animation/Animation2DStateMachineSystem.ts +60 -0
- package/src/animation/Animation2DStateMachineVisualRuntime.ts +282 -0
- package/src/animation/Animation2DSystem.ts +72 -0
- package/src/animation/AnimationAssetLoader.ts +84 -0
- package/src/animation/AnimationAudioClip.ts +140 -0
- package/src/animation/AnimationPathTessellator.ts +691 -0
- package/src/animation/AnimationTextRasterizer.ts +340 -0
- package/src/animation/AnimationVisual2D.ts +153 -0
- package/src/animation/HyaAnimation2DClipAdapter.ts +845 -0
- package/src/animation/Particle2DDescriptorAdapter.ts +35 -0
- package/src/animation/runtime/mixer/Action.ts +876 -0
- package/src/animation/runtime/mixer/Mixer.ts +505 -0
- package/src/animation/runtime/mixer/PoseBuffer.ts +105 -0
- package/src/animation/runtime/mixer/Sampler.ts +252 -0
- package/src/animation/runtime/mixer/Types.ts +138 -0
- package/src/animation/runtime/mixer/index.ts +31 -0
- package/src/animation-state-machine/AnimationStateMachine.ts +146 -0
- package/src/animation-state-machine/AnimationStateMachineChannels.ts +116 -0
- package/src/animation-state-machine/runtime/Animation2DStateMachineMixerAdapter.ts +197 -0
- package/src/animation-state-machine/runtime/AnimationStateMachineBlendTreeWeights.ts +503 -0
- package/src/animation-state-machine/runtime/AnimationStateMachineCompiler.ts +763 -0
- package/src/animation-state-machine/runtime/AnimationStateMachineController.ts +987 -0
- package/src/animation-state-machine/runtime/AnimationStateMachineMixerPort.ts +54 -0
- package/src/animation-state-machine/runtime/index.ts +47 -0
- package/src/animation.ts +33 -0
- package/src/animation3d/Animation3DAction.ts +73 -0
- package/src/animation3d/Animation3DBinding.ts +116 -0
- package/src/animation3d/Animation3DClip.ts +22 -0
- package/src/animation3d/Animation3DError.ts +34 -0
- package/src/animation3d/Animation3DMixer.ts +82 -0
- package/src/animation3d/Animation3DPose.ts +100 -0
- package/src/animation3d/Animation3DPoseBuffer.ts +85 -0
- package/src/animation3d/Animation3DResource.ts +49 -0
- package/src/animation3d/Animation3DStateMachine.ts +126 -0
- package/src/animation3d/Animation3DStateMachineRuntime.ts +191 -0
- package/src/animation3d/Animation3DTrack.ts +29 -0
- package/src/animation3d/hya/HyaAnimation3DRuntime.ts +756 -0
- package/src/animation3d/hya/HyaAnimation3DStateMachineRuntime.ts +618 -0
- package/src/animation3d/hya/HyaAnimation3DTypes.ts +168 -0
- package/src/animation3d/hya/index.ts +10 -0
- package/src/animation3d/index.ts +76 -0
- package/src/animation3d/runtime/integration/Animation3DStateMachineMixerAdapter.ts +325 -0
- package/src/animation3d/runtime/integration/Animation3DStateMachineMixerIntegration.ts +158 -0
- package/src/animation3d/runtime/integration/index.ts +9 -0
- package/src/animation3d/runtime/mixer/Action.ts +833 -0
- package/src/animation3d/runtime/mixer/Animation3DMixerRuntimeStore.ts +26 -0
- package/src/animation3d/runtime/mixer/Mixer.ts +562 -0
- package/src/animation3d/runtime/mixer/PoseBuffer.ts +1 -0
- package/src/animation3d/runtime/mixer/TrackSampler.ts +399 -0
- package/src/animation3d/runtime/mixer/index.ts +8 -0
- package/src/animation3d/runtime/state-machine/Animation3DBlendTreeWeights.ts +4 -0
- package/src/animation3d/runtime/state-machine/Animation3DStateMachineCompiler.ts +1 -0
- package/src/animation3d/runtime/state-machine/Animation3DStateMachineController.ts +1 -0
- package/src/animation3d/runtime/state-machine/Animation3DStateMachineMixerPort.ts +1 -0
- package/src/animation3d/runtime/state-machine/index.ts +45 -0
- package/src/animation3d.ts +5 -0
- package/src/benchmark.ts +168 -0
- package/src/canvas-text/CanvasText2DRenderSystem.ts +292 -0
- package/src/canvas-text/CanvasTextComponent.ts +47 -0
- package/src/canvas-text.ts +4 -0
- package/src/experimental-gltf-worker.ts +18 -0
- package/src/experimental-spine-worker.ts +9 -0
- package/src/gltf/GltfAccessorReader.ts +271 -0
- package/src/gltf/GltfAnimation3DAdapter.ts +680 -0
- package/src/gltf/GltfAnimationRuntime.ts +392 -0
- package/src/gltf/GltfAssetWorkerClient.ts +136 -0
- package/src/gltf/GltfCompatibilityReport.ts +214 -0
- package/src/gltf/GltfConservativeBounds.ts +219 -0
- package/src/gltf/GltfDracoDecoder.ts +251 -0
- package/src/gltf/GltfExtensionAdapter.ts +340 -0
- package/src/gltf/GltfLoaderContract.ts +333 -0
- package/src/gltf/GltfLoaderErrors.ts +59 -0
- package/src/gltf/GltfMaterialDescriptor.ts +134 -0
- package/src/gltf/GltfMaterialEncoder.ts +173 -0
- package/src/gltf/GltfMaterialLoader.ts +293 -0
- package/src/gltf/GltfModelComponent.ts +115 -0
- package/src/gltf/GltfModelSystem.ts +208 -0
- package/src/gltf/GltfPlugin.ts +84 -0
- package/src/gltf/GltfSchema.ts +229 -0
- package/src/gltf/GltfUvSemanticPlanner.ts +166 -0
- package/src/gltf/gltfLoader.ts +910 -0
- package/src/gltf-animation3d.ts +10 -0
- package/src/gltf-worker-runtime.ts +10 -0
- package/src/gltf.ts +56 -0
- package/src/grid/Grid2DComponent.ts +69 -0
- package/src/grid.ts +2 -0
- package/src/hya-state-machine.ts +19 -0
- package/src/index.ts +2 -0
- package/src/plugins/pluginUtils.ts +50 -0
- package/src/plugins.ts +6 -0
- package/src/shaders/generated/2d-ui-animation-2d.generated.wgsl +242 -0
- package/src/shaders/generated/2d-ui-artifact.generated.ts +867 -0
- package/src/shaders/generated/2d-ui-canvas-text-2d.generated.wgsl +38 -0
- package/src/shaders/generated/2d-ui-spine2d.generated.wgsl +41 -0
- package/src/shaders/generated/2d-ui-tilemap2d.generated.wgsl +36 -0
- package/src/spine/Spine2DComponent.ts +168 -0
- package/src/spine/Spine2DGpuRenderer.ts +449 -0
- package/src/spine/Spine2DRenderSystem.ts +199 -0
- package/src/spine/Spine2DRuntime.ts +1529 -0
- package/src/spine/SpineAnimationBoneTimelines.ts +30 -0
- package/src/spine/SpineAssetParser.ts +20 -0
- package/src/spine/SpineAssetWorkerClient.ts +112 -0
- package/src/spine/SpineAssetWorkerContract.ts +4 -0
- package/src/spine/SpineAtlasParser.ts +127 -0
- package/src/spine/SpineFloatBuilder.ts +66 -0
- package/src/spine/SpinePathConstraintSolver.ts +582 -0
- package/src/spine/SpinePlugin.ts +76 -0
- package/src/spine/SpineSkeletonRuntime.ts +521 -0
- package/src/spine/SpineSlotAnimation.ts +195 -0
- package/src/spine/SpineTimelineRuntime.ts +453 -0
- package/src/spine/SpineVertexBuilder.ts +686 -0
- package/src/spine.ts +7 -0
- package/src/tilemap/Tilemap2DComponent.ts +232 -0
- package/src/tilemap/Tilemap2DRenderSystem.ts +58 -0
- package/src/tilemap/Tilemap2DRenderer.ts +289 -0
- package/src/tilemap/TilemapPlugin.ts +75 -0
- package/src/tilemap.ts +6 -0
- package/src/tween/Tween2DComponent.ts +83 -0
- package/src/tween/Tween2DSystem.ts +78 -0
- package/src/tween.ts +4 -0
- package/src/types/earcut.d.ts +7 -0
- package/src/types/wgsl.d.ts +4 -0
- package/src/utils/RenderSystem2DBase.ts +164 -0
- package/src/utils/arrayAccess.ts +17 -0
- package/src/utils/camera2d.ts +68 -0
- package/src/utils/render2dGpu.ts +132 -0
- package/test/fixtures/gltf/animation-characterization.gltf +344 -0
package/dist/gltf.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { GltfModelComponent } from './gltf/GltfModelComponent';
|
|
2
|
+
export type { GltfModelComponentOptions, GltfModelStatus } from './gltf/GltfModelComponent';
|
|
3
|
+
export { GltfModelSystem } from './gltf/GltfModelSystem';
|
|
4
|
+
export type { GltfModelSystemOptions } from './gltf/GltfModelSystem';
|
|
5
|
+
export { applyGltfAnimationClip, disposeGltfModel, GLTF_EXTENSION_CAPABILITIES, loadGltfModel, setGltfMaterialVariant } from './gltf/gltfLoader';
|
|
6
|
+
export { DEFAULT_GLTF_EXTENSION_ADAPTERS, collectGltfMaterialExtensionPatches, collectGltfMaterialVariantNames, collectGltfMaterialVariantReferences, resolveGltfExtensionAdapters, } from './gltf/GltfExtensionAdapter';
|
|
7
|
+
export { encodeGltfPbrMaterial } from './gltf/GltfMaterialEncoder';
|
|
8
|
+
export type { EncodedGltfPbrMaterial, EncodeGltfPbrMaterialOptions, } from './gltf/GltfMaterialEncoder';
|
|
9
|
+
export type { DracoDecoderConfig, DracoDecoderFactory, DracoDecoderModule, GltfAssetWorker, GltfAnimationClip, GltfAnimationInfo, GltfAnimationInterpolation, GltfAnimationPath, GltfAssetStats, GltfExtensionCapability, GltfExtensionAdapter, GltfExtensionReport, GltfExtensionReportEntry, GltfExtensionSupport, GltfLoadWarning, GltfCompatibilityExtensionEntry, GltfCompatibilityIssue, GltfCompatibilityPerformanceSummary, GltfCompatibilityReport, GltfCompatibilityStatus, GltfPrimitiveBoundsCompatibilityEntry, GltfPrimitiveBoundsSupport, GltfPrimitiveUvSemanticCompatibilityEntry, GltfTextureCompatibilityEntry, GltfTextureMipmapSource, LoadedGltfModel, LoadGltfOptions, } from './gltf/gltfLoader';
|
|
10
|
+
export type { GltfMaterialExtensionContext, GltfMaterialExtensionPatch, GltfMaterialStatePatch, GltfMaterialTextureBinding, GltfMaterialVariantReference, GltfPrimitiveExtensionContext, } from './gltf/GltfExtensionAdapter';
|
|
11
|
+
export { createGltfPlugin } from './gltf/GltfPlugin';
|
|
12
|
+
export type { GltfPluginOptions } from './gltf/GltfPlugin';
|
package/dist/gltf.js
ADDED
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
import { Component, System } from '@haiyue/engine';
|
|
2
|
+
import { UniqueCheckType } from '@haiyue/engine/ecs';
|
|
3
|
+
import { AssetJob } from '@haiyue/engine/assets';
|
|
4
|
+
import { a as loadGltfModel, d as disposeGltfModel } from './chunks/gltfLoader-Dm22jLYB.js';
|
|
5
|
+
export { D as DEFAULT_GLTF_EXTENSION_ADAPTERS, G as GLTF_EXTENSION_CAPABILITIES, c as collectGltfMaterialExtensionPatches, b as collectGltfMaterialVariantNames, e as collectGltfMaterialVariantReferences, r as resolveGltfExtensionAdapters, s as setGltfMaterialVariant } from './chunks/gltfLoader-Dm22jLYB.js';
|
|
6
|
+
import { E as EXTENSIONS_PLUGIN_VERSION, o as ownedEditorViewportSystem, r as removeSystem } from './chunks/pluginUtils-CvwroRMd.js';
|
|
7
|
+
export { a as applyGltfAnimationClip } from './chunks/GltfAnimationRuntime-CRHsLycN.js';
|
|
8
|
+
import '@haiyue/engine/components';
|
|
9
|
+
import '@haiyue/engine/experimental/async';
|
|
10
|
+
import 'wgpu-matrix';
|
|
11
|
+
import '@haiyue/engine/material';
|
|
12
|
+
import '@haiyue/engine/core';
|
|
13
|
+
|
|
14
|
+
class GltfModelComponent extends Component {
|
|
15
|
+
static UniqueCheckType = UniqueCheckType.SYMBOL | UniqueCheckType.REPLACE;
|
|
16
|
+
static UniqueSymbol = Symbol.for('GltfModelComponent');
|
|
17
|
+
static editor = {
|
|
18
|
+
fields: {
|
|
19
|
+
src: {
|
|
20
|
+
type: 'asset-ref',
|
|
21
|
+
label: 'Source',
|
|
22
|
+
assetType: 'gltf',
|
|
23
|
+
placeholder: 'glTF / GLB URL or asset key',
|
|
24
|
+
validate: (value) => String(value ?? '').trim() ? null : 'Source is required.',
|
|
25
|
+
},
|
|
26
|
+
scene: {
|
|
27
|
+
type: 'number',
|
|
28
|
+
label: 'Scene Index',
|
|
29
|
+
min: 0,
|
|
30
|
+
step: 1,
|
|
31
|
+
visibleWhen: (component) => String(component.src).trim().length > 0,
|
|
32
|
+
},
|
|
33
|
+
autoLoad: { type: 'boolean', label: 'Auto Load' },
|
|
34
|
+
clearPrevious: { type: 'boolean', label: 'Clear Previous' },
|
|
35
|
+
baseColorFactor: {
|
|
36
|
+
type: 'array',
|
|
37
|
+
label: 'Fallback Color',
|
|
38
|
+
rows: 2,
|
|
39
|
+
validate: (value) => Array.isArray(value) && value.length === 4 ? null : 'Fallback Color must be [r, g, b, a].',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
_src = '';
|
|
44
|
+
_scene = null;
|
|
45
|
+
_sourceKey = '|';
|
|
46
|
+
_sourceKeyDirty = false;
|
|
47
|
+
autoLoad;
|
|
48
|
+
clearPrevious;
|
|
49
|
+
baseColorFactor;
|
|
50
|
+
status = 'idle';
|
|
51
|
+
error = null;
|
|
52
|
+
/** Runtime root inserted by GltfModelSystem. Do not serialize. */
|
|
53
|
+
runtimeRoot = null;
|
|
54
|
+
runtimeAnimations = [];
|
|
55
|
+
runtimeAnimationClips = [];
|
|
56
|
+
runtimeAssetStats = null;
|
|
57
|
+
runtimeCompatibilityReport = null;
|
|
58
|
+
runtimeMaterialVariants = [];
|
|
59
|
+
runtimeSourceKey = '';
|
|
60
|
+
loadingSourceKey = '';
|
|
61
|
+
constructor(options = {}) {
|
|
62
|
+
super('GltfModelComponent');
|
|
63
|
+
this.src = options.src ?? '';
|
|
64
|
+
this.scene = options.scene ?? null;
|
|
65
|
+
this.autoLoad = options.autoLoad ?? true;
|
|
66
|
+
this.clearPrevious = options.clearPrevious ?? true;
|
|
67
|
+
this.baseColorFactor = options.baseColorFactor
|
|
68
|
+
? [...options.baseColorFactor]
|
|
69
|
+
: [1, 1, 1, 1];
|
|
70
|
+
}
|
|
71
|
+
get src() {
|
|
72
|
+
return this._src;
|
|
73
|
+
}
|
|
74
|
+
set src(value) {
|
|
75
|
+
if (this._src === value)
|
|
76
|
+
return;
|
|
77
|
+
this._src = value;
|
|
78
|
+
this._sourceKeyDirty = true;
|
|
79
|
+
}
|
|
80
|
+
get scene() {
|
|
81
|
+
return this._scene;
|
|
82
|
+
}
|
|
83
|
+
set scene(value) {
|
|
84
|
+
if (this._scene === value)
|
|
85
|
+
return;
|
|
86
|
+
this._scene = value;
|
|
87
|
+
this._sourceKeyDirty = true;
|
|
88
|
+
}
|
|
89
|
+
get sourceKey() {
|
|
90
|
+
if (this._sourceKeyDirty) {
|
|
91
|
+
this._sourceKey = `${this._src}|${this._scene ?? ''}`;
|
|
92
|
+
this._sourceKeyDirty = false;
|
|
93
|
+
}
|
|
94
|
+
return this._sourceKey;
|
|
95
|
+
}
|
|
96
|
+
clone() {
|
|
97
|
+
return new GltfModelComponent({
|
|
98
|
+
src: this.src,
|
|
99
|
+
...(this.scene === null ? {} : { scene: this.scene }),
|
|
100
|
+
autoLoad: this.autoLoad,
|
|
101
|
+
clearPrevious: this.clearPrevious,
|
|
102
|
+
baseColorFactor: this.baseColorFactor,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
class GltfModelSystem extends System {
|
|
108
|
+
dracoDecoder;
|
|
109
|
+
dracoDecoderConfig;
|
|
110
|
+
loadTimeoutMs;
|
|
111
|
+
assetManager;
|
|
112
|
+
assetWorker;
|
|
113
|
+
assetPriority;
|
|
114
|
+
componentModels = new Map();
|
|
115
|
+
pendingLoads = new Map();
|
|
116
|
+
failedLoads = new Map();
|
|
117
|
+
liveComponents = new Set();
|
|
118
|
+
constructor(options = {}) {
|
|
119
|
+
super({ all: [GltfModelComponent] });
|
|
120
|
+
this.name = 'GltfModelSystem';
|
|
121
|
+
if (options.priority !== undefined)
|
|
122
|
+
this.priority = options.priority;
|
|
123
|
+
this.dracoDecoder = options.dracoDecoder ?? null;
|
|
124
|
+
this.dracoDecoderConfig = options.dracoDecoderConfig;
|
|
125
|
+
this.loadTimeoutMs = Math.max(0, options.loadTimeoutMs ?? 30000);
|
|
126
|
+
this.assetManager = options.assetManager ?? null;
|
|
127
|
+
this.assetWorker = options.assetWorker ?? null;
|
|
128
|
+
this.assetPriority = options.assetPriority ?? 'normal';
|
|
129
|
+
}
|
|
130
|
+
update(world, _time, _delta) {
|
|
131
|
+
this.liveComponents.clear();
|
|
132
|
+
const entities = this.entitySet.get(world);
|
|
133
|
+
if (entities)
|
|
134
|
+
for (const entity of entities) {
|
|
135
|
+
const component = entity.getComponent(GltfModelComponent);
|
|
136
|
+
if (!component)
|
|
137
|
+
continue;
|
|
138
|
+
this.liveComponents.add(component);
|
|
139
|
+
if (!component.autoLoad || !component.src)
|
|
140
|
+
continue;
|
|
141
|
+
const key = component.sourceKey;
|
|
142
|
+
if (component.runtimeSourceKey === key
|
|
143
|
+
|| component.loadingSourceKey === key
|
|
144
|
+
|| this.failedLoads.get(component) === key)
|
|
145
|
+
continue;
|
|
146
|
+
this.loadIntoEntity(entity, component, key);
|
|
147
|
+
}
|
|
148
|
+
this.releaseModelsNotIn(this.liveComponents);
|
|
149
|
+
this.abortLoadsNotIn(this.liveComponents);
|
|
150
|
+
this.releaseFailuresNotIn(this.liveComponents);
|
|
151
|
+
return this;
|
|
152
|
+
}
|
|
153
|
+
destroy() {
|
|
154
|
+
for (const component of [...this.pendingLoads.keys()])
|
|
155
|
+
this.abortPendingLoad(component);
|
|
156
|
+
this.disposeAllModels();
|
|
157
|
+
this.failedLoads.clear();
|
|
158
|
+
return super.destroy();
|
|
159
|
+
}
|
|
160
|
+
async loadIntoEntity(entity, component, key) {
|
|
161
|
+
this.abortPendingLoad(component);
|
|
162
|
+
component.status = 'loading';
|
|
163
|
+
component.error = null;
|
|
164
|
+
component.loadingSourceKey = key;
|
|
165
|
+
this.failedLoads.delete(component);
|
|
166
|
+
component.runtimeAnimations = [];
|
|
167
|
+
component.runtimeAnimationClips = [];
|
|
168
|
+
component.runtimeAssetStats = null;
|
|
169
|
+
component.runtimeCompatibilityReport = null;
|
|
170
|
+
component.runtimeMaterialVariants = [];
|
|
171
|
+
const pending = this.createPendingLoad(component, key);
|
|
172
|
+
try {
|
|
173
|
+
const model = await pending.job.start(async (context) => {
|
|
174
|
+
context.setPhase('parsing');
|
|
175
|
+
return await loadGltfModel(component.src, {
|
|
176
|
+
scene: component.scene,
|
|
177
|
+
baseColorFactor: component.baseColorFactor,
|
|
178
|
+
dracoDecoder: this.dracoDecoder,
|
|
179
|
+
...(this.dracoDecoderConfig === undefined ? {} : { dracoDecoderConfig: this.dracoDecoderConfig }),
|
|
180
|
+
assetManager: this.assetManager,
|
|
181
|
+
assetWorker: this.assetWorker,
|
|
182
|
+
signal: context.signal,
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
if (component.loadingSourceKey !== key) {
|
|
186
|
+
disposeGltfModel(model);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
if (component.clearPrevious) {
|
|
190
|
+
if (component.runtimeRoot)
|
|
191
|
+
entity.removeChild(component.runtimeRoot);
|
|
192
|
+
this.disposeModelsForComponent(component);
|
|
193
|
+
}
|
|
194
|
+
model.root.name = `${entity.name || 'glTF'} Model`;
|
|
195
|
+
entity.addChild(model.root);
|
|
196
|
+
this.trackModel(component, model);
|
|
197
|
+
component.runtimeRoot = model.root;
|
|
198
|
+
component.runtimeAnimations = model.animations;
|
|
199
|
+
component.runtimeAnimationClips = model.animationClips;
|
|
200
|
+
component.runtimeAssetStats = model.assetStats;
|
|
201
|
+
component.runtimeCompatibilityReport = model.compatibilityReport;
|
|
202
|
+
component.runtimeMaterialVariants = model.materialVariants;
|
|
203
|
+
component.runtimeSourceKey = key;
|
|
204
|
+
this.failedLoads.delete(component);
|
|
205
|
+
component.status = 'loaded';
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
const timedOut = String(pending.job.controller.signal.reason ?? '').startsWith('timeout:');
|
|
209
|
+
if (component.loadingSourceKey !== key || (pending.job.controller.signal.aborted && !timedOut)) {
|
|
210
|
+
if (component.loadingSourceKey === key)
|
|
211
|
+
component.loadingSourceKey = '';
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
component.status = 'error';
|
|
215
|
+
this.failedLoads.set(component, key);
|
|
216
|
+
component.error = timedOut
|
|
217
|
+
? `glTF load timed out after ${this.loadTimeoutMs}ms.`
|
|
218
|
+
: error instanceof Error ? error.message : String(error);
|
|
219
|
+
console.warn(`[GltfModelSystem] ${component.error}`, error);
|
|
220
|
+
}
|
|
221
|
+
finally {
|
|
222
|
+
this.clearPendingLoad(component, pending);
|
|
223
|
+
if (component.loadingSourceKey === key)
|
|
224
|
+
component.loadingSourceKey = '';
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
createPendingLoad(component, key) {
|
|
228
|
+
const pending = {
|
|
229
|
+
key,
|
|
230
|
+
job: new AssetJob(`gltf:${key}`, {
|
|
231
|
+
timeoutMs: this.loadTimeoutMs,
|
|
232
|
+
priority: this.assetPriority,
|
|
233
|
+
disposeLateResult: disposeGltfModel,
|
|
234
|
+
}),
|
|
235
|
+
};
|
|
236
|
+
this.pendingLoads.set(component, pending);
|
|
237
|
+
return pending;
|
|
238
|
+
}
|
|
239
|
+
clearPendingLoad(component, pending) {
|
|
240
|
+
if (this.pendingLoads.get(component) === pending)
|
|
241
|
+
this.pendingLoads.delete(component);
|
|
242
|
+
}
|
|
243
|
+
abortPendingLoad(component) {
|
|
244
|
+
const pending = this.pendingLoads.get(component);
|
|
245
|
+
if (!pending)
|
|
246
|
+
return;
|
|
247
|
+
pending.job.abort('component-removed');
|
|
248
|
+
this.pendingLoads.delete(component);
|
|
249
|
+
if (component.loadingSourceKey === pending.key)
|
|
250
|
+
component.loadingSourceKey = '';
|
|
251
|
+
}
|
|
252
|
+
trackModel(component, model) {
|
|
253
|
+
let models = this.componentModels.get(component);
|
|
254
|
+
if (!models) {
|
|
255
|
+
models = new Set();
|
|
256
|
+
this.componentModels.set(component, models);
|
|
257
|
+
}
|
|
258
|
+
models.add(model);
|
|
259
|
+
}
|
|
260
|
+
disposeModelsForComponent(component) {
|
|
261
|
+
const models = this.componentModels.get(component);
|
|
262
|
+
if (!models)
|
|
263
|
+
return;
|
|
264
|
+
for (const model of models)
|
|
265
|
+
disposeGltfModel(model);
|
|
266
|
+
models.clear();
|
|
267
|
+
this.componentModels.delete(component);
|
|
268
|
+
}
|
|
269
|
+
releaseModelsNotIn(liveComponents) {
|
|
270
|
+
for (const component of [...this.componentModels.keys()]) {
|
|
271
|
+
if (!liveComponents.has(component)) {
|
|
272
|
+
this.disposeModelsForComponent(component);
|
|
273
|
+
component.runtimeRoot = null;
|
|
274
|
+
component.runtimeAnimations = [];
|
|
275
|
+
component.runtimeAnimationClips = [];
|
|
276
|
+
component.runtimeAssetStats = null;
|
|
277
|
+
component.runtimeCompatibilityReport = null;
|
|
278
|
+
component.runtimeMaterialVariants = [];
|
|
279
|
+
component.runtimeSourceKey = '';
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
abortLoadsNotIn(liveComponents) {
|
|
284
|
+
for (const component of [...this.pendingLoads.keys()]) {
|
|
285
|
+
if (!liveComponents.has(component))
|
|
286
|
+
this.abortPendingLoad(component);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
releaseFailuresNotIn(liveComponents) {
|
|
290
|
+
for (const component of this.failedLoads.keys()) {
|
|
291
|
+
if (!liveComponents.has(component))
|
|
292
|
+
this.failedLoads.delete(component);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
disposeAllModels() {
|
|
296
|
+
for (const component of [...this.componentModels.keys()])
|
|
297
|
+
this.disposeModelsForComponent(component);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Encodes the standard glTF material portion without taking ownership of image,
|
|
303
|
+
* sampler, or buffer allocation. Scene exporters can share this codec instead
|
|
304
|
+
* of duplicating KHR material semantics.
|
|
305
|
+
*/
|
|
306
|
+
function encodeGltfPbrMaterial(material, options) {
|
|
307
|
+
const extensionsUsed = new Set();
|
|
308
|
+
const texture = (slot, source) => {
|
|
309
|
+
if (!source)
|
|
310
|
+
return undefined;
|
|
311
|
+
const index = options.resolveTextureIndex(slot, source);
|
|
312
|
+
if (!Number.isSafeInteger(index) || index < 0) {
|
|
313
|
+
throw new RangeError(`glTF texture index for PBR slot "${slot}" must be a non-negative safe integer.`);
|
|
314
|
+
}
|
|
315
|
+
return encodeTextureInfo(material, slot, index, extensionsUsed);
|
|
316
|
+
};
|
|
317
|
+
const baseColor = new Float32Array(4);
|
|
318
|
+
material.baseColor.writeLinear(baseColor);
|
|
319
|
+
const baseColorTexture = texture('baseColor', material.baseColorTexture);
|
|
320
|
+
const metallicRoughnessTexture = texture('metallicRoughness', material.metallicRoughnessTexture);
|
|
321
|
+
const normalTexture = texture('normal', material.normalTexture);
|
|
322
|
+
const occlusionTexture = texture('occlusion', material.occlusionTexture);
|
|
323
|
+
const emissiveTexture = texture('emissive', material.emissiveTexture);
|
|
324
|
+
const clearcoatTexture = texture('clearcoat', material.clearcoatTexture);
|
|
325
|
+
const clearcoatRoughnessTexture = texture('clearcoatRoughness', material.clearcoatRoughnessTexture);
|
|
326
|
+
const clearcoatNormalTexture = texture('clearcoatNormal', material.clearcoatNormalTexture);
|
|
327
|
+
const specularTexture = texture('specular', material.specularTexture);
|
|
328
|
+
const specularColorTexture = texture('specularColor', material.specularColorTexture);
|
|
329
|
+
const sheenColorTexture = texture('sheenColor', material.sheenColorTexture);
|
|
330
|
+
const sheenRoughnessTexture = texture('sheenRoughness', material.sheenRoughnessTexture);
|
|
331
|
+
const transmissionTexture = texture('transmission', material.transmissionTexture);
|
|
332
|
+
const thicknessTexture = texture('thickness', material.thicknessTexture);
|
|
333
|
+
const extensions = {};
|
|
334
|
+
if (material.clearcoatFactor !== 0
|
|
335
|
+
|| material.clearcoatRoughnessFactor !== 0
|
|
336
|
+
|| clearcoatTexture
|
|
337
|
+
|| clearcoatRoughnessTexture
|
|
338
|
+
|| clearcoatNormalTexture) {
|
|
339
|
+
extensions.KHR_materials_clearcoat = {
|
|
340
|
+
clearcoatFactor: material.clearcoatFactor,
|
|
341
|
+
...(clearcoatTexture ? { clearcoatTexture } : {}),
|
|
342
|
+
clearcoatRoughnessFactor: material.clearcoatRoughnessFactor,
|
|
343
|
+
...(clearcoatRoughnessTexture ? { clearcoatRoughnessTexture } : {}),
|
|
344
|
+
...(clearcoatNormalTexture ? {
|
|
345
|
+
clearcoatNormalTexture: { ...clearcoatNormalTexture, scale: material.clearcoatNormalScale },
|
|
346
|
+
} : {}),
|
|
347
|
+
};
|
|
348
|
+
extensionsUsed.add('KHR_materials_clearcoat');
|
|
349
|
+
}
|
|
350
|
+
if (material.ior !== 1.5) {
|
|
351
|
+
extensions.KHR_materials_ior = { ior: material.ior };
|
|
352
|
+
extensionsUsed.add('KHR_materials_ior');
|
|
353
|
+
}
|
|
354
|
+
if (material.specularFactor !== 1
|
|
355
|
+
|| material.specularColorFactor.some(channel => channel !== 1)
|
|
356
|
+
|| specularTexture
|
|
357
|
+
|| specularColorTexture) {
|
|
358
|
+
extensions.KHR_materials_specular = {
|
|
359
|
+
specularFactor: material.specularFactor,
|
|
360
|
+
...(specularTexture ? { specularTexture } : {}),
|
|
361
|
+
specularColorFactor: [...material.specularColorFactor],
|
|
362
|
+
...(specularColorTexture ? { specularColorTexture } : {}),
|
|
363
|
+
};
|
|
364
|
+
extensionsUsed.add('KHR_materials_specular');
|
|
365
|
+
}
|
|
366
|
+
if (material.sheenColorFactor.some(channel => channel !== 0)
|
|
367
|
+
|| material.sheenRoughnessFactor !== 0
|
|
368
|
+
|| sheenColorTexture
|
|
369
|
+
|| sheenRoughnessTexture) {
|
|
370
|
+
extensions.KHR_materials_sheen = {
|
|
371
|
+
sheenColorFactor: [...material.sheenColorFactor],
|
|
372
|
+
...(sheenColorTexture ? { sheenColorTexture } : {}),
|
|
373
|
+
sheenRoughnessFactor: material.sheenRoughnessFactor,
|
|
374
|
+
...(sheenRoughnessTexture ? { sheenRoughnessTexture } : {}),
|
|
375
|
+
};
|
|
376
|
+
extensionsUsed.add('KHR_materials_sheen');
|
|
377
|
+
}
|
|
378
|
+
if (material.transmissionFactor !== 0 || transmissionTexture) {
|
|
379
|
+
extensions.KHR_materials_transmission = {
|
|
380
|
+
transmissionFactor: material.transmissionFactor,
|
|
381
|
+
...(transmissionTexture ? { transmissionTexture } : {}),
|
|
382
|
+
};
|
|
383
|
+
extensionsUsed.add('KHR_materials_transmission');
|
|
384
|
+
}
|
|
385
|
+
if (material.thicknessFactor !== 0
|
|
386
|
+
|| thicknessTexture
|
|
387
|
+
|| material.attenuationDistance !== Infinity
|
|
388
|
+
|| material.attenuationColor.some(channel => channel !== 1)) {
|
|
389
|
+
extensions.KHR_materials_volume = {
|
|
390
|
+
thicknessFactor: material.thicknessFactor,
|
|
391
|
+
...(thicknessTexture ? { thicknessTexture } : {}),
|
|
392
|
+
...(material.attenuationDistance === Infinity ? {} : { attenuationDistance: material.attenuationDistance }),
|
|
393
|
+
attenuationColor: [...material.attenuationColor],
|
|
394
|
+
};
|
|
395
|
+
extensionsUsed.add('KHR_materials_volume');
|
|
396
|
+
if (material.transmissionFactor === 0 && !transmissionTexture) {
|
|
397
|
+
extensions.KHR_materials_transmission = { transmissionFactor: 0 };
|
|
398
|
+
extensionsUsed.add('KHR_materials_transmission');
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
const gltfMaterial = {
|
|
402
|
+
...(options.name ? { name: options.name } : {}),
|
|
403
|
+
pbrMetallicRoughness: {
|
|
404
|
+
baseColorFactor: [baseColor[0], baseColor[1], baseColor[2], baseColor[3]],
|
|
405
|
+
...(baseColorTexture ? { baseColorTexture } : {}),
|
|
406
|
+
...(metallicRoughnessTexture ? { metallicRoughnessTexture } : {}),
|
|
407
|
+
metallicFactor: material.metallic,
|
|
408
|
+
roughnessFactor: material.roughness,
|
|
409
|
+
},
|
|
410
|
+
emissiveFactor: [...material.emissiveFactor],
|
|
411
|
+
...(emissiveTexture ? { emissiveTexture } : {}),
|
|
412
|
+
...(normalTexture ? { normalTexture: { ...normalTexture, scale: material.normalScale } } : {}),
|
|
413
|
+
...(occlusionTexture ? { occlusionTexture: { ...occlusionTexture, strength: material.occlusionStrength } } : {}),
|
|
414
|
+
alphaMode: material.alphaMode === 'blend' ? 'BLEND' : material.alphaMode === 'mask' ? 'MASK' : 'OPAQUE',
|
|
415
|
+
...(material.alphaMode === 'mask' ? { alphaCutoff: material.alphaCutoff } : {}),
|
|
416
|
+
doubleSided: material.doubleSided,
|
|
417
|
+
...(Object.keys(extensions).length > 0 ? { extensions } : {}),
|
|
418
|
+
};
|
|
419
|
+
return Object.freeze({
|
|
420
|
+
material: gltfMaterial,
|
|
421
|
+
extensionsUsed: Object.freeze([...extensionsUsed]),
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
function encodeTextureInfo(material, slot, index, extensionsUsed) {
|
|
425
|
+
const mapping = material.getTextureMapping(slot);
|
|
426
|
+
const transform = {};
|
|
427
|
+
if (mapping.offset[0] !== 0 || mapping.offset[1] !== 0)
|
|
428
|
+
transform.offset = [...mapping.offset];
|
|
429
|
+
if (mapping.rotation !== 0)
|
|
430
|
+
transform.rotation = mapping.rotation;
|
|
431
|
+
if (mapping.scale[0] !== 1 || mapping.scale[1] !== 1)
|
|
432
|
+
transform.scale = [...mapping.scale];
|
|
433
|
+
const transformed = Object.keys(transform).length > 0;
|
|
434
|
+
if (transformed)
|
|
435
|
+
extensionsUsed.add('KHR_texture_transform');
|
|
436
|
+
return {
|
|
437
|
+
index,
|
|
438
|
+
...(mapping.texCoord !== 0 ? { texCoord: mapping.texCoord } : {}),
|
|
439
|
+
...(transformed ? { extensions: { KHR_texture_transform: transform } } : {}),
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
function createGltfPlugin(options = {}) {
|
|
444
|
+
let system = null;
|
|
445
|
+
return {
|
|
446
|
+
name: '@haiyue/extensions/gltf',
|
|
447
|
+
version: EXTENSIONS_PLUGIN_VERSION,
|
|
448
|
+
installEngine(context) {
|
|
449
|
+
context.registerComponent({ type: 'GltfModelComponent', component: GltfModelComponent });
|
|
450
|
+
},
|
|
451
|
+
installScene(context) {
|
|
452
|
+
context.registerComponent({ type: 'GltfModelComponent', component: GltfModelComponent });
|
|
453
|
+
system = new GltfModelSystem({
|
|
454
|
+
...options.system,
|
|
455
|
+
assetManager: options.system?.assetManager ?? context.assetManager ?? null,
|
|
456
|
+
});
|
|
457
|
+
context.addSystem(system, false);
|
|
458
|
+
},
|
|
459
|
+
uninstallScene(context) {
|
|
460
|
+
removeSystem(context, system);
|
|
461
|
+
system = null;
|
|
462
|
+
},
|
|
463
|
+
installEditor(context) {
|
|
464
|
+
context.registerContribution({ components: [{
|
|
465
|
+
type: 'GltfModelComponent',
|
|
466
|
+
create: () => new GltfModelComponent({ src: '', autoLoad: true }),
|
|
467
|
+
inspector: GltfModelComponent.editor,
|
|
468
|
+
serialize(component) {
|
|
469
|
+
return {
|
|
470
|
+
type: 'GltfModelComponent',
|
|
471
|
+
src: component.src,
|
|
472
|
+
scene: component.scene,
|
|
473
|
+
autoLoad: component.autoLoad,
|
|
474
|
+
clearPrevious: component.clearPrevious,
|
|
475
|
+
baseColorFactor: [...component.baseColorFactor],
|
|
476
|
+
};
|
|
477
|
+
},
|
|
478
|
+
deserialize(data) {
|
|
479
|
+
const value = data;
|
|
480
|
+
if (value.type !== 'GltfModelComponent')
|
|
481
|
+
return null;
|
|
482
|
+
return new GltfModelComponent({ ...value, ...(typeof value.scene === 'number' ? { scene: value.scene } : {}) });
|
|
483
|
+
},
|
|
484
|
+
clone: (component) => component.clone(),
|
|
485
|
+
getIgnoredChildren: (component) => component.runtimeRoot ? [component.runtimeRoot] : [],
|
|
486
|
+
collectDependencies(component, dependencyContext) {
|
|
487
|
+
const dependency = dependencyContext.resolveModelBySrc(component.src);
|
|
488
|
+
return dependency ? [dependency] : [];
|
|
489
|
+
},
|
|
490
|
+
collectSerializedDependencies(data, dependencyContext) {
|
|
491
|
+
const value = data;
|
|
492
|
+
const dependency = value.type === 'GltfModelComponent' && typeof value.src === 'string'
|
|
493
|
+
? dependencyContext.resolveModelBySrc(value.src)
|
|
494
|
+
: null;
|
|
495
|
+
return dependency ? [dependency] : [];
|
|
496
|
+
},
|
|
497
|
+
installViewport(viewport) {
|
|
498
|
+
const existing = viewport.world.getSystem(GltfModelSystem);
|
|
499
|
+
const viewportSystem = existing ?? new GltfModelSystem({ priority: 0 });
|
|
500
|
+
if (!existing)
|
|
501
|
+
viewport.world.addSystem(viewportSystem);
|
|
502
|
+
return ownedEditorViewportSystem(viewport.world, viewportSystem, existing === null);
|
|
503
|
+
},
|
|
504
|
+
runtimeExport: {
|
|
505
|
+
imports: [{ from: '@haiyue/extensions/gltf', names: ['GltfModelComponent', 'GltfModelSystem'] }],
|
|
506
|
+
systems: ['GltfModelSystem'],
|
|
507
|
+
deserializeExpression: 'new GltfModelComponent(data)',
|
|
508
|
+
installSystems: ' if (hasComponentType(world, GltfModelComponent)) world.addSystem(new GltfModelSystem({ priority: 0 }));',
|
|
509
|
+
has3D: true,
|
|
510
|
+
},
|
|
511
|
+
}] });
|
|
512
|
+
},
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
export { GltfModelComponent, GltfModelSystem, createGltfPlugin, disposeGltfModel, encodeGltfPbrMaterial, loadGltfModel };
|
|
517
|
+
//# sourceMappingURL=gltf.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Component } from '@haiyue/engine';
|
|
2
|
+
export interface Grid2DComponentOptions {
|
|
3
|
+
columns?: number;
|
|
4
|
+
rows?: number;
|
|
5
|
+
cellWidth?: number;
|
|
6
|
+
cellHeight?: number;
|
|
7
|
+
originX?: number;
|
|
8
|
+
originY?: number;
|
|
9
|
+
}
|
|
10
|
+
export declare class Grid2DComponent extends Component {
|
|
11
|
+
static UniqueCheckType: number;
|
|
12
|
+
static UniqueSymbol: symbol;
|
|
13
|
+
columns: number;
|
|
14
|
+
rows: number;
|
|
15
|
+
cellWidth: number;
|
|
16
|
+
cellHeight: number;
|
|
17
|
+
originX: number;
|
|
18
|
+
originY: number;
|
|
19
|
+
constructor(options?: Grid2DComponentOptions);
|
|
20
|
+
gridToWorld(column: number, row: number): [number, number];
|
|
21
|
+
gridToWorldCenter(column: number, row: number): [number, number];
|
|
22
|
+
worldToGrid(x: number, y: number): [number, number];
|
|
23
|
+
contains(column: number, row: number): boolean;
|
|
24
|
+
clone(): Grid2DComponent;
|
|
25
|
+
}
|
package/dist/grid.d.ts
ADDED
package/dist/grid.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Component } from '@haiyue/engine';
|
|
2
|
+
import { UniqueCheckType } from '@haiyue/engine/ecs';
|
|
3
|
+
|
|
4
|
+
class Grid2DComponent extends Component {
|
|
5
|
+
static UniqueCheckType = UniqueCheckType.SYMBOL | UniqueCheckType.REPLACE;
|
|
6
|
+
static UniqueSymbol = Symbol.for('Grid2DComponent');
|
|
7
|
+
columns;
|
|
8
|
+
rows;
|
|
9
|
+
cellWidth;
|
|
10
|
+
cellHeight;
|
|
11
|
+
originX;
|
|
12
|
+
originY;
|
|
13
|
+
constructor(options = {}) {
|
|
14
|
+
super('Grid2DComponent');
|
|
15
|
+
this.columns = Math.max(1, Math.floor(options.columns ?? 10));
|
|
16
|
+
this.rows = Math.max(1, Math.floor(options.rows ?? 20));
|
|
17
|
+
this.cellWidth = options.cellWidth ?? 32;
|
|
18
|
+
this.cellHeight = options.cellHeight ?? 32;
|
|
19
|
+
this.originX = options.originX ?? 0;
|
|
20
|
+
this.originY = options.originY ?? 0;
|
|
21
|
+
}
|
|
22
|
+
gridToWorld(column, row) {
|
|
23
|
+
return [
|
|
24
|
+
this.originX + column * this.cellWidth,
|
|
25
|
+
this.originY + row * this.cellHeight,
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
gridToWorldCenter(column, row) {
|
|
29
|
+
return [
|
|
30
|
+
this.originX + (column + 0.5) * this.cellWidth,
|
|
31
|
+
this.originY + (row + 0.5) * this.cellHeight,
|
|
32
|
+
];
|
|
33
|
+
}
|
|
34
|
+
worldToGrid(x, y) {
|
|
35
|
+
return [
|
|
36
|
+
Math.floor((x - this.originX) / this.cellWidth),
|
|
37
|
+
Math.floor((y - this.originY) / this.cellHeight),
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
contains(column, row) {
|
|
41
|
+
return column >= 0 && row >= 0 && column < this.columns && row < this.rows;
|
|
42
|
+
}
|
|
43
|
+
clone() {
|
|
44
|
+
return new Grid2DComponent({
|
|
45
|
+
columns: this.columns,
|
|
46
|
+
rows: this.rows,
|
|
47
|
+
cellWidth: this.cellWidth,
|
|
48
|
+
cellHeight: this.cellHeight,
|
|
49
|
+
originX: this.originX,
|
|
50
|
+
originY: this.originY,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export { Grid2DComponent };
|
|
56
|
+
//# sourceMappingURL=grid.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { Animation2DStateMachineComponent } from './animation/Animation2DStateMachineComponent';
|
|
2
|
+
export type { Animation2DStateMachineComponentOptions } from './animation/Animation2DStateMachineComponent';
|
|
3
|
+
export { Animation2DStateMachineSystem } from './animation/Animation2DStateMachineSystem';
|
|
4
|
+
export type { Animation2DStateMachineSystemOptions } from './animation/Animation2DStateMachineSystem';
|
|
5
|
+
export { createHyaAnimation2DClips, getHyaStateMachineExtension, } from './animation/HyaAnimation2DClipAdapter';
|
|
6
|
+
export { AnimationStateMachineChannelError, assertAudioStateMachineCompatible, audioStateMachineCompatibilityDiagnostic, hyaStateMachineChannelCapability, HYA_STATE_MACHINE_CHANNEL_REGISTRY, } from './animation-state-machine/AnimationStateMachineChannels';
|
|
7
|
+
export type { AnimationStateMachineChannelDiagnostic, AnimationStateMachineChannelDiagnosticCode, } from './animation-state-machine/AnimationStateMachineChannels';
|