@egret/engine 7.0.1-rc.3 → 7.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Engine.js +7 -2
- package/dist/animation/sequenceResetTypes.d.ts +6 -0
- package/dist/animation/types.d.ts +6 -0
- package/dist/assetBundle.d.ts +2 -0
- package/dist/assetGroupTypes.d.ts +2 -0
- package/dist/audioCues.d.ts +4 -0
- package/dist/audioTypes.d.ts +13 -0
- package/dist/bitmapButtonTypes.d.ts +2 -0
- package/dist/bitmapFontTypes.d.ts +3 -0
- package/dist/bitmapResourceSlot.d.ts +1 -0
- package/dist/camera2d.js +10 -2
- package/dist/cameraTypes.d.ts +12 -0
- package/dist/contentTypes.d.ts +2 -0
- package/dist/createEngineForProfile.js +8 -5
- package/dist/fontContentTypes.d.ts +5 -0
- package/dist/gameClockTypes.d.ts +6 -0
- package/dist/gameRun.d.ts +3 -0
- package/dist/gamepadTypes.d.ts +8 -0
- package/dist/hoverInputTypes.d.ts +10 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +2 -1
- package/dist/inputActions.d.ts +5 -0
- package/dist/internal/uiFactoryState.d.ts +4 -0
- package/dist/internal/uiFactoryState.js +18 -2
- package/dist/keyboardInput.d.ts +1 -0
- package/dist/keyboardInput.js +1 -0
- package/dist/keyboardInputTypes.d.ts +12 -0
- package/dist/kit.d.ts +3 -1
- package/dist/kit.js +2 -1
- package/dist/manifestResourceState.d.ts +1 -0
- package/dist/manifestResourceState.js +1 -0
- package/dist/manifestResourceTypes.d.ts +1 -0
- package/dist/motion.d.ts +2 -0
- package/dist/mouseInputTypes.d.ts +4 -0
- package/dist/particleEmitter.js +8 -0
- package/dist/particleTypes.d.ts +8 -0
- package/dist/physics2d.d.ts +2 -2
- package/dist/physics2d.js +1 -1
- package/dist/physics2dTypes.d.ts +55 -1
- package/dist/physics2dWorld.js +209 -9
- package/dist/pointerInput.d.ts +1 -0
- package/dist/pointerInput.js +1 -0
- package/dist/pointerInputTypes.d.ts +3 -0
- package/dist/random.d.ts +1 -0
- package/dist/rendering/packSharedDraws2D.js +53 -5
- package/dist/rendering/prepareSharedDraws2D.d.ts +2 -0
- package/dist/rendering/prepareSharedDraws2D.js +17 -6
- package/dist/rendering/sharedColor2D.d.ts +35 -1
- package/dist/rendering/sharedColor2D.js +131 -8
- package/dist/rendering/sharedEffects2D.js +16 -8
- package/dist/rendering/world3d/Animation3D.d.ts +9 -0
- package/dist/rendering/world3d/Animation3D.js +4 -0
- package/dist/rendering/world3d/AnimationTexture3D.d.ts +6 -0
- package/dist/rendering/world3d/AnimationTexture3D.js +2 -0
- package/dist/rendering/world3d/Batch3D.d.ts +4 -0
- package/dist/rendering/world3d/Batch3D.js +3 -0
- package/dist/rendering/world3d/Camera3D.d.ts +5 -0
- package/dist/rendering/world3d/Camera3D.js +3 -0
- package/dist/rendering/world3d/Character3D.d.ts +4 -0
- package/dist/rendering/world3d/Character3D.js +2 -0
- package/dist/rendering/world3d/Cloth3D.d.ts +18 -3
- package/dist/rendering/world3d/Cloth3D.js +6 -1
- package/dist/rendering/world3d/Compression3D.d.ts +1 -0
- package/dist/rendering/world3d/Compression3D.js +1 -0
- package/dist/rendering/world3d/Curves3D.d.ts +8 -0
- package/dist/rendering/world3d/Curves3D.js +5 -0
- package/dist/rendering/world3d/Decal3D.d.ts +2 -0
- package/dist/rendering/world3d/Decal3D.js +1 -0
- package/dist/rendering/world3d/Export3D.d.ts +13 -0
- package/dist/rendering/world3d/Export3D.js +263 -0
- package/dist/rendering/world3d/Geometry3D.d.ts +11 -1
- package/dist/rendering/world3d/Geometry3D.js +10 -1
- package/dist/rendering/world3d/GeometryBuilder3D.d.ts +2 -0
- package/dist/rendering/world3d/Gizmo3D.d.ts +5 -0
- package/dist/rendering/world3d/Gizmo3D.js +2 -0
- package/dist/rendering/world3d/Gltf3D.d.ts +6 -0
- package/dist/rendering/world3d/Gltf3D.js +25 -5
- package/dist/rendering/world3d/GpuParticles3D.d.ts +2 -0
- package/dist/rendering/world3d/GpuParticles3D.js +1 -0
- package/dist/rendering/world3d/Hdr3D.d.ts +2 -0
- package/dist/rendering/world3d/Hdr3D.js +1 -0
- package/dist/rendering/world3d/Jelly3D.d.ts +2 -0
- package/dist/rendering/world3d/Jelly3D.js +1 -0
- package/dist/rendering/world3d/Ktx23D.d.ts +3 -0
- package/dist/rendering/world3d/Light3D.d.ts +9 -0
- package/dist/rendering/world3d/Light3D.js +4 -0
- package/dist/rendering/world3d/Material3D.d.ts +10 -0
- package/dist/rendering/world3d/Material3D.js +2 -0
- package/dist/rendering/world3d/Mesh3D.d.ts +4 -0
- package/dist/rendering/world3d/Mesh3D.js +16 -2
- package/dist/rendering/world3d/Meshopt3D.d.ts +3 -0
- package/dist/rendering/world3d/Meshopt3D.js +1 -0
- package/dist/rendering/world3d/Navigation3D.d.ts +41 -1
- package/dist/rendering/world3d/Navigation3D.js +74 -2
- package/dist/rendering/world3d/Object3D.d.ts +11 -0
- package/dist/rendering/world3d/Object3D.js +10 -0
- package/dist/rendering/world3d/Particles3D.d.ts +5 -0
- package/dist/rendering/world3d/Particles3D.js +3 -0
- package/dist/rendering/world3d/Physics3D.d.ts +14 -0
- package/dist/rendering/world3d/Physics3D.js +5 -0
- package/dist/rendering/world3d/PhysicsHull3D.d.ts +2 -0
- package/dist/rendering/world3d/PhysicsHull3D.js +2 -0
- package/dist/rendering/world3d/PhysicsMesh3D.d.ts +2 -0
- package/dist/rendering/world3d/PhysicsMesh3D.js +2 -0
- package/dist/rendering/world3d/PhysicsRemote3D.d.ts +5 -0
- package/dist/rendering/world3d/PhysicsRemote3D.js +2 -0
- package/dist/rendering/world3d/Ragdoll3D.d.ts +5 -0
- package/dist/rendering/world3d/Ragdoll3D.js +2 -0
- package/dist/rendering/world3d/Raycast3D.d.ts +3 -0
- package/dist/rendering/world3d/Raycast3D.js +1 -0
- package/dist/rendering/world3d/RenderList3D.d.ts +3 -0
- package/dist/rendering/world3d/RenderList3D.js +12 -0
- package/dist/rendering/world3d/Retarget3D.d.ts +1 -0
- package/dist/rendering/world3d/Rig3D.d.ts +57 -0
- package/dist/rendering/world3d/Rig3D.js +219 -0
- package/dist/rendering/world3d/Sdf3D.d.ts +181 -0
- package/dist/rendering/world3d/Sdf3D.js +1136 -0
- package/dist/rendering/world3d/SdfLod3D.d.ts +17 -0
- package/dist/rendering/world3d/SdfLod3D.js +56 -0
- package/dist/rendering/world3d/Serialize3D.d.ts +17 -0
- package/dist/rendering/world3d/Serialize3D.js +22 -0
- package/dist/rendering/world3d/Simplify3D.d.ts +29 -0
- package/dist/rendering/world3d/Simplify3D.js +426 -0
- package/dist/rendering/world3d/StateMachine3D.d.ts +9 -0
- package/dist/rendering/world3d/StateMachine3D.js +3 -0
- package/dist/rendering/world3d/SurfaceMaterial3D.d.ts +26 -0
- package/dist/rendering/world3d/SurfaceMaterial3D.js +138 -0
- package/dist/rendering/world3d/Terrain3D.d.ts +21 -0
- package/dist/rendering/world3d/Terrain3D.js +25 -1
- package/dist/rendering/world3d/Text3D.d.ts +5 -0
- package/dist/rendering/world3d/Text3D.js +2 -0
- package/dist/rendering/world3d/Texture3D.d.ts +16 -1
- package/dist/rendering/world3d/Texture3D.js +19 -1
- package/dist/rendering/world3d/Trail3D.d.ts +3 -0
- package/dist/rendering/world3d/Trail3D.js +2 -0
- package/dist/rendering/world3d/Vehicle3D.d.ts +5 -0
- package/dist/rendering/world3d/Vehicle3D.js +2 -0
- package/dist/rendering/world3d/VolumetricFog3D.d.ts +2 -0
- package/dist/rendering/world3d/VolumetricFog3D.js +1 -0
- package/dist/rendering/world3d/Water3D.d.ts +2 -0
- package/dist/rendering/world3d/Water3D.js +1 -0
- package/dist/rendering/world3d/core3D.d.ts +2 -0
- package/dist/rendering/world3d/debug3D.d.ts +5 -0
- package/dist/rendering/world3d/debug3D.js +5 -0
- package/dist/rendering/world3d/geometries3D.d.ts +12 -0
- package/dist/rendering/world3d/geometries3D.js +5 -0
- package/dist/rendering/world3d/helpers3D.d.ts +2 -0
- package/dist/rendering/world3d/helpers3D.js +1 -0
- package/dist/rendering/world3d/index.d.ts +12 -0
- package/dist/rendering/world3d/index.js +6 -0
- package/dist/rendering/world3d/math3D.d.ts +36 -0
- package/dist/rendering/world3d/math3D.js +35 -0
- package/dist/rendering/world3d/primitives3D.d.ts +7 -0
- package/dist/rendering/world3d/primitives3D.js +1 -0
- package/dist/saveStore.d.ts +18 -3
- package/dist/saveStore.js +23 -4
- package/dist/semanticList.d.ts +4 -0
- package/dist/semanticList.js +1 -0
- package/dist/semanticTree.js +11 -4
- package/dist/semanticTypes.d.ts +8 -0
- package/dist/sequencePlaybackTypes.d.ts +3 -0
- package/dist/text.d.ts +1 -0
- package/dist/textTable.d.ts +41 -0
- package/dist/textTable.js +114 -0
- package/dist/tilemapTypes.d.ts +13 -0
- package/dist/timer.d.ts +34 -0
- package/dist/timer.js +119 -0
- package/dist/tweenTypes.d.ts +4 -0
- package/dist/ui/controlKeys.d.ts +4 -0
- package/dist/ui/controlKeys.js +1 -0
- package/dist/ui/controls.d.ts +6 -0
- package/dist/ui/controls.js +2 -0
- package/dist/ui/layerTypes.d.ts +7 -0
- package/dist/ui/rangeControl.d.ts +3 -0
- package/dist/ui/rangeControl.js +1 -0
- package/dist/ui/scrollControl.d.ts +12 -0
- package/dist/ui/scrollControl.js +5 -1
- package/dist/ui/stateControls.d.ts +8 -0
- package/dist/ui/stateControls.js +3 -0
- package/dist/ui/textEditor.d.ts +1 -0
- package/dist/ui/textEditor.js +1 -0
- package/dist/ui/textEditorTypes.d.ts +7 -0
- package/dist/ui/textFieldControl.d.ts +4 -0
- package/dist/ui/textFieldControl.js +1 -0
- package/dist/ui/theme.d.ts +5 -0
- package/dist/ui/theme.js +1 -0
- package/dist/ui/types.d.ts +20 -0
- package/dist/ui/uiRoot.js +38 -9
- package/dist/ui/uiRootModel.d.ts +3 -1
- package/dist/ui/uiRootModel.js +8 -2
- package/dist/videoTypes.d.ts +3 -0
- package/dist/web/BrowserAssetBundle.d.ts +2 -0
- package/dist/web/BrowserAudio.d.ts +34 -1
- package/dist/web/BrowserAudio.js +69 -39
- package/dist/web/BrowserFrameLoop.d.ts +4 -0
- package/dist/web/BrowserGame.d.ts +64 -2
- package/dist/web/BrowserGame.js +129 -8
- package/dist/web/BrowserGamepadInput.d.ts +3 -0
- package/dist/web/BrowserHoverInput.d.ts +1 -0
- package/dist/web/BrowserImageTextures.d.ts +6 -0
- package/dist/web/BrowserInputActions.d.ts +10 -0
- package/dist/web/BrowserInputActions.js +4 -1
- package/dist/web/BrowserPlay.d.ts +130 -2
- package/dist/web/BrowserPlay.js +366 -19
- package/dist/web/BrowserPreferences.d.ts +10 -0
- package/dist/web/BrowserPreferences.js +39 -0
- package/dist/web/BrowserSemantics.d.ts +2 -0
- package/dist/web/BrowserStatsPanel.d.ts +10 -0
- package/dist/web/BrowserStatsPanel.js +9 -3
- package/dist/web/BrowserStorage.d.ts +2 -0
- package/dist/web/BrowserTextEditor.d.ts +3 -0
- package/dist/web/BrowserTextInput.d.ts +6 -0
- package/dist/web/BrowserTextureProvider.d.ts +6 -0
- package/dist/web/BrowserVideo.d.ts +13 -1
- package/dist/web/BrowserVideo.js +28 -2
- package/dist/web/CanvasKitFontSetProvider.d.ts +3 -0
- package/dist/web/CanvasKitParagraphProvider.d.ts +4 -0
- package/dist/web/CanvasKitParagraphProvider.js +1 -0
- package/dist/web/ManifestByteSource.d.ts +4 -0
- package/dist/web/ManifestByteSource.js +1 -0
- package/dist/web/ManifestFontContentLoader.d.ts +1 -0
- package/dist/web/WebGL2Host.js +64 -25
- package/dist/web/WebGPUHost.d.ts +13 -0
- package/dist/web/WebGPUHost.js +117 -36
- package/dist/web/audio.d.ts +2 -2
- package/dist/web/audio.js +1 -1
- package/dist/web/editorFonts.d.ts +4 -0
- package/dist/web/game.d.ts +1 -1
- package/dist/web/imageProjections2D.d.ts +2 -0
- package/dist/web/kit.d.ts +1 -0
- package/dist/web/kit.js +1 -0
- package/dist/web/play.d.ts +6 -1
- package/dist/web/play.js +4 -1
- package/dist/web/playMusic.d.ts +33 -0
- package/dist/web/playMusic.js +194 -0
- package/dist/web/playTouch.d.ts +45 -0
- package/dist/web/playTouch.js +141 -0
- package/dist/web/playWidgets.d.ts +71 -0
- package/dist/web/playWidgets.js +431 -0
- package/dist/web/prepareSharedSubmission2D.js +9 -3
- package/dist/web/resources.d.ts +2 -0
- package/dist/web/sharedEffectShaders.d.ts +6 -2
- package/dist/web/sharedEffectShaders.js +23 -7
- package/dist/web/sharedSubmissionStorage2D.js +1 -1
- package/dist/web/sharedWebGL2Options.d.ts +3 -0
- package/dist/web/sharedWebGL2Options.js +8 -2
- package/dist/web/sharedWebGL2Shaders.d.ts +15 -2
- package/dist/web/sharedWebGL2Shaders.js +108 -14
- package/dist/web/sharedWebGPUOptions.d.ts +5 -1
- package/dist/web/sharedWebGPUOptions.js +6 -2
- package/dist/web/video.d.ts +1 -1
- package/dist/web/webgl2Native.d.ts +3 -1
- package/dist/web/webgl2Native.js +9 -5
- package/dist/web/webgl2Types.d.ts +18 -0
- package/dist/web/webgpuImageResidency.d.ts +5 -2
- package/dist/web/webgpuImageResidency.js +7 -3
- package/dist/web/webgpuRetentionPool.d.ts +2 -2
- package/dist/web/webgpuRetentionPool.js +2 -1
- package/dist/web/webgpuSharedPass.d.ts +1 -1
- package/dist/web/webgpuSharedPass.js +87 -5
- package/dist/web/webgpuSharedResolvePass.d.ts +1 -1
- package/dist/web/webgpuSharedResolvePass.js +9 -4
- package/dist/web/world3d/Audio3D.d.ts +18 -1
- package/dist/web/world3d/Audio3D.js +62 -3
- package/dist/web/world3d/BrowserPlay3D.d.ts +115 -2
- package/dist/web/world3d/BrowserPlay3D.js +448 -43
- package/dist/web/world3d/FlyControls3D.d.ts +4 -0
- package/dist/web/world3d/FlyControls3D.js +2 -0
- package/dist/web/world3d/FollowControls3D.d.ts +3 -0
- package/dist/web/world3d/FollowControls3D.js +2 -0
- package/dist/web/world3d/OrbitControls3D.d.ts +3 -0
- package/dist/web/world3d/OrbitControls3D.js +2 -0
- package/dist/web/world3d/TransformControls3D.d.ts +5 -2
- package/dist/web/world3d/TransformControls3D.js +7 -4
- package/dist/web/world3d/WebGL2Renderer3D.d.ts +3 -0
- package/dist/web/world3d/WebGL2Renderer3D.js +2 -0
- package/dist/web/world3d/WebGPURenderer3D.d.ts +2 -0
- package/dist/web/world3d/WebGPURenderer3D.js +1 -0
- package/dist/web/world3d/World3DView.d.ts +3 -0
- package/dist/web/world3d/World3DView.js +2 -0
- package/dist/web/world3d/app3D.d.ts +7 -0
- package/dist/web/world3d/app3D.js +1 -0
- package/dist/web/world3d/assets3D.d.ts +1 -0
- package/dist/web/world3d/atmosphere3D.d.ts +9 -0
- package/dist/web/world3d/atmosphere3D.js +19 -4
- package/dist/web/world3d/canvasFont3D.d.ts +21 -0
- package/dist/web/world3d/canvasFont3D.js +165 -0
- package/dist/web/world3d/frame3D.d.ts +2 -0
- package/dist/web/world3d/host3D.d.ts +1 -0
- package/dist/web/world3d/index.d.ts +4 -2
- package/dist/web/world3d/index.js +2 -1
- package/dist/web/world3d/loaders3D.d.ts +1 -0
- package/dist/web/world3d/markers3D.d.ts +4 -0
- package/dist/web/world3d/overlay3D.d.ts +19 -0
- package/dist/web/world3d/overlay3D.js +21 -4
- package/dist/web/world3d/post3D.d.ts +4 -0
- package/dist/web/world3d/post3D.js +3 -0
- package/dist/web/world3d/probe3D.d.ts +1 -0
- package/dist/web/world3d/stats3D.d.ts +3 -0
- package/dist/web/world3d/stats3D.js +1 -0
- package/dist/web/world3d/webGL2FrameMetrics3D.d.ts +5 -0
- package/dist/web/world3d/webgpu.d.ts +2 -0
- package/dist/web/world3d/webgpu.js +1 -0
- package/package.json +3 -3
|
@@ -3,12 +3,14 @@ import type { Camera3D } from '../../rendering/world3d/Camera3D.js';
|
|
|
3
3
|
import { FollowCamera3D } from '../../rendering/world3d/Character3D.js';
|
|
4
4
|
import type { FollowCameraOptions3D } from '../../rendering/world3d/Character3D.js';
|
|
5
5
|
import type { Object3D } from '../../rendering/world3d/Object3D.js';
|
|
6
|
+
/** Follow controls to make: how fast they turn and zoom. */
|
|
6
7
|
export interface FollowControlsOptions3D extends FollowCameraOptions3D {
|
|
7
8
|
/** Radians turned per pixel dragged. Defaults to 0.005. */
|
|
8
9
|
readonly rotateSpeed?: number;
|
|
9
10
|
/** Share of the distance changed per wheel notch. Defaults to 0.1. */
|
|
10
11
|
readonly zoomSpeed?: number;
|
|
11
12
|
}
|
|
13
|
+
/** Turns and zooms a follow camera with the mouse and touch. */
|
|
12
14
|
export declare class FollowControls3D implements Disposable {
|
|
13
15
|
#private;
|
|
14
16
|
readonly element: HTMLElement;
|
|
@@ -24,5 +26,6 @@ export declare class FollowControls3D implements Disposable {
|
|
|
24
26
|
private forgetPointer;
|
|
25
27
|
private releaseCapture;
|
|
26
28
|
}
|
|
29
|
+
/** Makes follow controls for a follow camera on an element. */
|
|
27
30
|
export declare function createFollowControls3D(camera: Camera3D, element: HTMLElement, target: Object3D | ArrayLike<number>, options?: FollowControlsOptions3D): FollowControls3D;
|
|
28
31
|
//# sourceMappingURL=FollowControls3D.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { FollowCamera3D } from '../../rendering/world3d/Character3D.js';
|
|
2
2
|
import { World3DError } from '../../rendering/world3d/core3D.js';
|
|
3
|
+
/** Turns and zooms a follow camera with the mouse and touch. */
|
|
3
4
|
export class FollowControls3D {
|
|
4
5
|
element;
|
|
5
6
|
/** The camera rig; read `follow.yaw` or call `follow.moveDirection()` to steer a character relative to the view. */
|
|
@@ -111,6 +112,7 @@ export class FollowControls3D {
|
|
|
111
112
|
this.element.releasePointerCapture(id);
|
|
112
113
|
}
|
|
113
114
|
}
|
|
115
|
+
/** Makes follow controls for a follow camera on an element. */
|
|
114
116
|
export function createFollowControls3D(camera, element, target, options = {}) {
|
|
115
117
|
return new FollowControls3D(camera, element, target, options);
|
|
116
118
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Disposable } from '@egret/contracts';
|
|
2
2
|
import type { Camera3D } from '../../rendering/world3d/Camera3D.js';
|
|
3
|
+
/** Orbit controls to make: their target, distances and angles, how fast they turn, pan and zoom, and which of these are on. */
|
|
3
4
|
export interface OrbitControlsOptions3D {
|
|
4
5
|
readonly target?: readonly [number, number, number];
|
|
5
6
|
readonly minDistance?: number;
|
|
@@ -18,6 +19,7 @@ export interface OrbitControlsOptions3D {
|
|
|
18
19
|
/** Radians per second of automatic rotation about the Y axis. */
|
|
19
20
|
readonly autoRotateSpeed?: number;
|
|
20
21
|
}
|
|
22
|
+
/** Turns a camera around a target, pans and zooms it, with the mouse and touch. */
|
|
21
23
|
export declare class OrbitControls3D implements Disposable {
|
|
22
24
|
#private;
|
|
23
25
|
readonly camera: Camera3D;
|
|
@@ -51,5 +53,6 @@ export declare class OrbitControls3D implements Disposable {
|
|
|
51
53
|
/** Detach every listener. Idempotent. */
|
|
52
54
|
dispose(): void;
|
|
53
55
|
}
|
|
56
|
+
/** Makes orbit controls for a camera on an element. */
|
|
54
57
|
export declare function createOrbitControls3D(camera: Camera3D, element: HTMLElement, options?: OrbitControlsOptions3D): OrbitControls3D;
|
|
55
58
|
//# sourceMappingURL=OrbitControls3D.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { World3DError } from '../../rendering/world3d/core3D.js';
|
|
2
2
|
const EPSILON = 1e-4;
|
|
3
|
+
/** Turns a camera around a target, pans and zooms it, with the mouse and touch. */
|
|
3
4
|
export class OrbitControls3D {
|
|
4
5
|
camera;
|
|
5
6
|
element;
|
|
@@ -181,6 +182,7 @@ export class OrbitControls3D {
|
|
|
181
182
|
this.#pointers.clear();
|
|
182
183
|
}
|
|
183
184
|
}
|
|
185
|
+
/** Makes orbit controls for a camera on an element. */
|
|
184
186
|
export function createOrbitControls3D(camera, element, options = {}) {
|
|
185
187
|
return new OrbitControls3D(camera, element, options);
|
|
186
188
|
}
|
|
@@ -3,6 +3,7 @@ import type { Camera3D } from '../../rendering/world3d/Camera3D.js';
|
|
|
3
3
|
import { TransformGizmo3D } from '../../rendering/world3d/Gizmo3D.js';
|
|
4
4
|
import type { GizmoMode3D, GizmoSpace3D, TransformGizmoOptions3D } from '../../rendering/world3d/Gizmo3D.js';
|
|
5
5
|
import type { Object3D } from '../../rendering/world3d/Object3D.js';
|
|
6
|
+
/** Drags a transform gizmo with the mouse and touch to move, turn or scale an object. */
|
|
6
7
|
export declare class TransformControls3D implements Disposable {
|
|
7
8
|
#private;
|
|
8
9
|
readonly camera: Camera3D;
|
|
@@ -10,8 +11,9 @@ export declare class TransformControls3D implements Disposable {
|
|
|
10
11
|
/** The handles; add this to the scene that holds the edited object. */
|
|
11
12
|
readonly gizmo: TransformGizmo3D;
|
|
12
13
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
14
|
+
* A press that lands on a handle is kept from orbit, fly and follow controls
|
|
15
|
+
* on the same element, made before or after these: the handles listen in the
|
|
16
|
+
* capture phase, which runs first. A press anywhere else reaches them.
|
|
15
17
|
*/
|
|
16
18
|
constructor(camera: Camera3D, element: HTMLElement, options?: TransformGizmoOptions3D);
|
|
17
19
|
get mode(): GizmoMode3D;
|
|
@@ -30,5 +32,6 @@ export declare class TransformControls3D implements Disposable {
|
|
|
30
32
|
update(): void;
|
|
31
33
|
dispose(): void;
|
|
32
34
|
}
|
|
35
|
+
/** Makes transform controls for a camera on an element. */
|
|
33
36
|
export declare function createTransformControls3D(camera: Camera3D, element: HTMLElement, options?: TransformGizmoOptions3D): TransformControls3D;
|
|
34
37
|
//# sourceMappingURL=TransformControls3D.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { World3DError } from '../../rendering/world3d/core3D.js';
|
|
2
2
|
import { TransformGizmo3D } from '../../rendering/world3d/Gizmo3D.js';
|
|
3
|
+
/** Drags a transform gizmo with the mouse and touch to move, turn or scale an object. */
|
|
3
4
|
export class TransformControls3D {
|
|
4
5
|
camera;
|
|
5
6
|
element;
|
|
@@ -11,8 +12,9 @@ export class TransformControls3D {
|
|
|
11
12
|
#pointer = -1;
|
|
12
13
|
#disposed = false;
|
|
13
14
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
15
|
+
* A press that lands on a handle is kept from orbit, fly and follow controls
|
|
16
|
+
* on the same element, made before or after these: the handles listen in the
|
|
17
|
+
* capture phase, which runs first. A press anywhere else reaches them.
|
|
16
18
|
*/
|
|
17
19
|
constructor(camera, element, options = {}) {
|
|
18
20
|
if (!camera || !element || typeof element.addEventListener !== 'function')
|
|
@@ -59,7 +61,7 @@ export class TransformControls3D {
|
|
|
59
61
|
['pointercancel', up]
|
|
60
62
|
];
|
|
61
63
|
for (const [type, listener] of this.#listeners)
|
|
62
|
-
element.addEventListener(type, listener);
|
|
64
|
+
element.addEventListener(type, listener, { capture: true });
|
|
63
65
|
}
|
|
64
66
|
get mode() {
|
|
65
67
|
return this.gizmo.mode;
|
|
@@ -115,10 +117,11 @@ export class TransformControls3D {
|
|
|
115
117
|
return;
|
|
116
118
|
this.#disposed = true;
|
|
117
119
|
for (const [type, listener] of this.#listeners)
|
|
118
|
-
this.element.removeEventListener(type, listener);
|
|
120
|
+
this.element.removeEventListener(type, listener, { capture: true });
|
|
119
121
|
this.gizmo.dispose();
|
|
120
122
|
}
|
|
121
123
|
}
|
|
124
|
+
/** Makes transform controls for a camera on an element. */
|
|
122
125
|
export function createTransformControls3D(camera, element, options = {}) {
|
|
123
126
|
return new TransformControls3D(camera, element, options);
|
|
124
127
|
}
|
|
@@ -8,6 +8,7 @@ import type { CompressedFormat3D } from '../../rendering/world3d/Texture3D.js';
|
|
|
8
8
|
import type { PostProcessSettings3D } from './post3D.js';
|
|
9
9
|
import type { Renderer3D, Renderer3DInfo, ToneMapping3D } from './frame3D.js';
|
|
10
10
|
import type { World3DFrameMetrics } from './webGL2FrameMetrics3D.js';
|
|
11
|
+
/** A WebGL2 renderer to make: its canvas and context, its tone mapping and exposure, its shadows, and what is called when the context is lost and restored. */
|
|
11
12
|
export interface WebGL2Renderer3DOptions {
|
|
12
13
|
readonly canvas: HTMLCanvasElement | OffscreenCanvas;
|
|
13
14
|
readonly antialias?: boolean;
|
|
@@ -38,6 +39,7 @@ export interface WebGL2ProgramVariant3D {
|
|
|
38
39
|
readonly softDepth?: boolean;
|
|
39
40
|
readonly transmission?: boolean;
|
|
40
41
|
}
|
|
42
|
+
/** Draws 3D scenes with WebGL2: set its size, render a scene from a camera, and read what it drew. */
|
|
41
43
|
export declare class WebGL2Renderer3D implements Renderer3D {
|
|
42
44
|
#private;
|
|
43
45
|
readonly canvas: HTMLCanvasElement | OffscreenCanvas;
|
|
@@ -129,5 +131,6 @@ export declare class WebGL2Renderer3D implements Renderer3D {
|
|
|
129
131
|
/** Release every GPU object and detach from the canvas. Idempotent. */
|
|
130
132
|
dispose(): void;
|
|
131
133
|
}
|
|
134
|
+
/** Makes a renderer that draws 3D scenes with WebGL2. */
|
|
132
135
|
export declare function createWebGL2Renderer3D(options: WebGL2Renderer3DOptions): WebGL2Renderer3D;
|
|
133
136
|
//# sourceMappingURL=WebGL2Renderer3D.d.ts.map
|
|
@@ -26,6 +26,7 @@ function colorProgramFlags(fog, toneMapping, environment, linear) {
|
|
|
26
26
|
(environment ? V.environment : 0) |
|
|
27
27
|
(linear ? V.linearOutput : 0));
|
|
28
28
|
}
|
|
29
|
+
/** Draws 3D scenes with WebGL2: set its size, render a scene from a camera, and read what it drew. */
|
|
29
30
|
export class WebGL2Renderer3D {
|
|
30
31
|
canvas;
|
|
31
32
|
toneMapping;
|
|
@@ -1167,6 +1168,7 @@ export class WebGL2Renderer3D {
|
|
|
1167
1168
|
}
|
|
1168
1169
|
}
|
|
1169
1170
|
}
|
|
1171
|
+
/** Makes a renderer that draws 3D scenes with WebGL2. */
|
|
1170
1172
|
export function createWebGL2Renderer3D(options) {
|
|
1171
1173
|
return new WebGL2Renderer3D(options);
|
|
1172
1174
|
}
|
|
@@ -5,6 +5,7 @@ import { RenderTarget3D } from '../../rendering/world3d/Texture3D.js';
|
|
|
5
5
|
import type { CompressedFormat3D } from '../../rendering/world3d/Texture3D.js';
|
|
6
6
|
import type { PostProcessSettings3D } from './post3D.js';
|
|
7
7
|
import type { Renderer3D, Renderer3DInfo, ToneMapping3D } from './frame3D.js';
|
|
8
|
+
/** A WebGPU renderer to make: its canvas and device, its tone mapping and exposure, its shadows, and what is called when the device is lost. */
|
|
8
9
|
export interface WebGPURenderer3DOptions {
|
|
9
10
|
readonly canvas: HTMLCanvasElement | OffscreenCanvas;
|
|
10
11
|
/** Four-sample multisampling of the canvas pass. Defaults to true. */
|
|
@@ -22,6 +23,7 @@ export interface WebGPURenderer3DOptions {
|
|
|
22
23
|
/** Called once when the device is lost. Create a new renderer to continue. */
|
|
23
24
|
readonly onDeviceLost?: (message: string) => void;
|
|
24
25
|
}
|
|
26
|
+
/** Draws 3D scenes with WebGPU: set its size, render a scene from a camera, and read what it drew. */
|
|
25
27
|
export declare class WebGPURenderer3D implements Renderer3D {
|
|
26
28
|
#private;
|
|
27
29
|
readonly canvas: HTMLCanvasElement | OffscreenCanvas;
|
|
@@ -14,6 +14,7 @@ export interface World3DClockSource {
|
|
|
14
14
|
}) => undefined): Disposable;
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
+
/** A 3D view to make: its renderer, scene and camera, its mixers and controls, its update, and how it resizes. */
|
|
17
18
|
export interface World3DViewOptions {
|
|
18
19
|
readonly renderer: Renderer3D;
|
|
19
20
|
readonly scene: Scene3D;
|
|
@@ -31,6 +32,7 @@ export interface World3DViewOptions {
|
|
|
31
32
|
/** Receives failures thrown while updating or drawing; the view keeps ticking. */
|
|
32
33
|
readonly onError?: (cause: unknown) => void;
|
|
33
34
|
}
|
|
35
|
+
/** Draws a scene from a camera on each tick of the Engine, updating its mixers and controls. */
|
|
34
36
|
export declare class World3DView implements Disposable {
|
|
35
37
|
#private;
|
|
36
38
|
readonly renderer: Renderer3D;
|
|
@@ -47,5 +49,6 @@ export declare class World3DView implements Disposable {
|
|
|
47
49
|
/** Stop ticking. The renderer, scene and controls stay owned by their creator. */
|
|
48
50
|
dispose(): void;
|
|
49
51
|
}
|
|
52
|
+
/** Makes a view that draws a scene on each tick of the Engine's clock. */
|
|
50
53
|
export declare function createWorld3DView(engine: World3DClockSource, scope: Scope, options: World3DViewOptions): World3DView;
|
|
51
54
|
//# sourceMappingURL=World3DView.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { World3DError } from '../../rendering/world3d/core3D.js';
|
|
2
2
|
import { ParticleEmitter3D } from '../../rendering/world3d/Particles3D.js';
|
|
3
|
+
/** Draws a scene from a camera on each tick of the Engine, updating its mixers and controls. */
|
|
3
4
|
export class World3DView {
|
|
4
5
|
renderer;
|
|
5
6
|
scene;
|
|
@@ -71,6 +72,7 @@ export class World3DView {
|
|
|
71
72
|
this.#subscription.dispose();
|
|
72
73
|
}
|
|
73
74
|
}
|
|
75
|
+
/** Makes a view that draws a scene on each tick of the Engine's clock. */
|
|
74
76
|
export function createWorld3DView(engine, scope, options) {
|
|
75
77
|
return new World3DView(engine, scope, options);
|
|
76
78
|
}
|
|
@@ -7,7 +7,9 @@ import type { AnimationMixer3D } from '../../rendering/world3d/Animation3D.js';
|
|
|
7
7
|
import type { Renderer3D, ToneMapping3D } from './frame3D.js';
|
|
8
8
|
import { World3DView } from './World3DView.js';
|
|
9
9
|
import type { OrbitControls3D } from './OrbitControls3D.js';
|
|
10
|
+
/** Which GPU interface a 3D app draws with. */
|
|
10
11
|
export type World3DBackend = 'webgl2' | 'webgpu';
|
|
12
|
+
/** How much a 3D app draws: low, medium or high quality. */
|
|
11
13
|
export type World3DQuality = 'low' | 'medium' | 'high';
|
|
12
14
|
/** What one picture quality turns on. */
|
|
13
15
|
export interface World3DQualityPreset {
|
|
@@ -53,6 +55,7 @@ export declare function pickWorld3DQuality(hints?: World3DDeviceHints): World3DQ
|
|
|
53
55
|
export declare function isSoftwareRendered3D(document?: Document): boolean;
|
|
54
56
|
/** The backend asked for by the address (`backend=webgpu`), or `fallback`. */
|
|
55
57
|
export declare function pickWorld3DBackend(query?: string | URLSearchParams, fallback?: World3DBackend): World3DBackend;
|
|
58
|
+
/** How dynamic resolution moves: its least and greatest scale, its step, and the frame rates and times that move it. */
|
|
56
59
|
export interface DynamicResolutionOptions3D {
|
|
57
60
|
/** Smallest share of the quality's pixel ratio drawn at. Defaults to 0.6. */
|
|
58
61
|
readonly min?: number;
|
|
@@ -80,7 +83,9 @@ export interface DynamicResolution3D {
|
|
|
80
83
|
/** Back to the largest share, as after a change of scene. */
|
|
81
84
|
reset(): void;
|
|
82
85
|
}
|
|
86
|
+
/** Makes a resolution scale that drops when frames are slow and rises when they are fast. */
|
|
83
87
|
export declare function createDynamicResolution3D(options?: DynamicResolutionOptions3D): DynamicResolution3D;
|
|
88
|
+
/** A 3D app to make: its backend and quality, its dynamic resolution, its tone mapping, and what is called on an error or a lost device. */
|
|
84
89
|
export interface World3DAppOptions {
|
|
85
90
|
/** `webgl2` or `webgpu`. Defaults to what the address asks (`backend=`), else WebGL2. */
|
|
86
91
|
readonly backend?: World3DBackend;
|
|
@@ -100,12 +105,14 @@ export interface World3DAppOptions {
|
|
|
100
105
|
/** Told once when the graphics device is lost. */
|
|
101
106
|
readonly onDeviceLost?: (message: string) => void;
|
|
102
107
|
}
|
|
108
|
+
/** What a 3D app shows: its update, mixers and controls. */
|
|
103
109
|
export interface World3DShowOptions {
|
|
104
110
|
/** Called every frame before animation and drawing. */
|
|
105
111
|
readonly onUpdate?: (deltaSeconds: number, elapsedSeconds: number) => void;
|
|
106
112
|
readonly mixers?: readonly AnimationMixer3D[];
|
|
107
113
|
readonly controls?: OrbitControls3D;
|
|
108
114
|
}
|
|
115
|
+
/** A 3D app: its Engine, renderer and view, its quality and resolution, and calls that show a scene and start and stop it. */
|
|
109
116
|
export interface World3DApp extends Disposable {
|
|
110
117
|
readonly engine: Engine;
|
|
111
118
|
/** The Engine scope the app's view and renderer belong to. */
|
|
@@ -95,6 +95,7 @@ export function pickWorld3DBackend(query, fallback = 'webgl2') {
|
|
|
95
95
|
const asked = params(query)?.get('backend');
|
|
96
96
|
return asked === 'webgpu' || asked === 'webgl2' ? asked : fallback;
|
|
97
97
|
}
|
|
98
|
+
/** Makes a resolution scale that drops when frames are slow and rises when they are fast. */
|
|
98
99
|
export function createDynamicResolution3D(options = {}) {
|
|
99
100
|
const min = options.min ?? 0.6, max = options.max ?? 1, step = options.step ?? 0.15, lowFps = options.lowFps ?? 45, highFps = options.highFps ?? 57, downAfter = options.downAfter ?? 1.5, upAfter = options.upAfter ?? 6;
|
|
100
101
|
const numbers = [min, max, step, lowFps, highFps, downAfter, upAfter];
|
|
@@ -15,6 +15,7 @@ export declare const TEXTURE_ASSET_3D: AssetType<Texture3D>;
|
|
|
15
15
|
export declare const CUBE_TEXTURE_ASSET_3D: AssetType<CubeTexture3D>;
|
|
16
16
|
/** A scene document written by serializeScene3D. The reference id is the JSON file URL. */
|
|
17
17
|
export declare const SCENE_ASSET_3D: AssetType<DeserializedScene3D>;
|
|
18
|
+
/** How a 3D app loads assets: how URLs are resolved, how many bytes, and how textures and compressed data are decoded. */
|
|
18
19
|
export interface World3DAssetOptions {
|
|
19
20
|
/** Map a reference id to the URL to download. Defaults to using the id as the URL. */
|
|
20
21
|
readonly resolveUrl?: (id: string) => string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Camera3D } from '../../rendering/world3d/Camera3D.js';
|
|
2
2
|
import { type CustomPost3D } from './post3D.js';
|
|
3
|
+
/** An atmosphere to make: its fog's color, density and height, and its light shafts. */
|
|
3
4
|
export interface AtmosphereOptions3D {
|
|
4
5
|
/** Fog color, 0xRRGGBB. Default a pale blue-grey. */
|
|
5
6
|
readonly fogColor?: number;
|
|
@@ -9,6 +10,11 @@ export interface AtmosphereOptions3D {
|
|
|
9
10
|
readonly fogHeight?: number;
|
|
10
11
|
/** How quickly the fog thins with height, per world unit; 0 gives uniform fog. Default 0.08. */
|
|
11
12
|
readonly fogFalloff?: number;
|
|
13
|
+
/**
|
|
14
|
+
* How much of the fog lies over the sky itself, from 0 (a clear sky, fog only on what stands before it) to 1 (the
|
|
15
|
+
* sky fogged as if it were the far plane, which greys the horizon). Default 1, as before. Fixed when made.
|
|
16
|
+
*/
|
|
17
|
+
readonly skyFog?: number;
|
|
12
18
|
/** Brightness of the light shafts; 0 turns them off. Default 0.6. */
|
|
13
19
|
readonly shaftIntensity?: number;
|
|
14
20
|
/** How far the shafts reach across the screen, 0 to 1. Default 0.6. */
|
|
@@ -22,6 +28,8 @@ export interface AtmosphereOptions3D {
|
|
|
22
28
|
export declare class Atmosphere3D {
|
|
23
29
|
#private;
|
|
24
30
|
readonly post: CustomPost3D;
|
|
31
|
+
/** How much of the fog lies over the sky, as given when it was made. */
|
|
32
|
+
readonly skyFog: number;
|
|
25
33
|
constructor(options?: AtmosphereOptions3D);
|
|
26
34
|
get fogDensity(): number;
|
|
27
35
|
set fogDensity(value: number);
|
|
@@ -43,5 +51,6 @@ export declare class Atmosphere3D {
|
|
|
43
51
|
update(camera: Camera3D, sunDirection?: ArrayLike<number>): void;
|
|
44
52
|
private amount;
|
|
45
53
|
}
|
|
54
|
+
/** Makes height fog and light shafts for a scene. */
|
|
46
55
|
export declare function createAtmosphere3D(options?: AtmosphereOptions3D): Atmosphere3D;
|
|
47
56
|
//# sourceMappingURL=atmosphere3D.d.ts.map
|
|
@@ -3,7 +3,7 @@ import { colorFromHex } from '../../rendering/world3d/math3D.js';
|
|
|
3
3
|
import { createCustomPost3D } from './post3D.js';
|
|
4
4
|
// uniforms: [0] fog rgb, density; [1] falloff, base height, sky distance, shaft intensity;
|
|
5
5
|
// [2] sun uv, sun visibility, shaft length; [3] the camera's world Y axis in view space, camera height.
|
|
6
|
-
const GLSL = /* glsl */ `
|
|
6
|
+
const GLSL = (skyFog) => /* glsl */ `
|
|
7
7
|
vec3 customPost(vec3 color, vec2 uv) {
|
|
8
8
|
vec4 fog = uPostCustom[0], shape = uPostCustom[1], sun = uPostCustom[2], up = uPostCustom[3];
|
|
9
9
|
vec3 view = unprojectDepth(uv, rawDepth(uv));
|
|
@@ -13,6 +13,8 @@ vec3 customPost(vec3 color, vec2 uv) {
|
|
|
13
13
|
float rise = dot(up.xyz, view), slope = shape.x * rise;
|
|
14
14
|
float thin = abs(slope) > 0.0001 ? (1.0 - exp(-slope)) / slope : 1.0;
|
|
15
15
|
float depth = fog.a * exp(-shape.x * (up.w - shape.y)) * reach * thin;
|
|
16
|
+
// The sky lies on the far plane: it takes its own share of the fog.
|
|
17
|
+
depth *= mix(1.0, ${skyFog}, step(shape.z, reach));
|
|
16
18
|
color = mix(fog.rgb, color, exp(-max(depth, 0.0)));
|
|
17
19
|
}
|
|
18
20
|
if (shape.w > 0.0 && sun.z > 0.0) {
|
|
@@ -35,7 +37,7 @@ vec3 customPost(vec3 color, vec2 uv) {
|
|
|
35
37
|
return color;
|
|
36
38
|
}
|
|
37
39
|
`;
|
|
38
|
-
const WGSL = /* wgsl */ `
|
|
40
|
+
const WGSL = (skyFog) => /* wgsl */ `
|
|
39
41
|
fn customPost(color: vec3f, uv: vec2f) -> vec3f {
|
|
40
42
|
let fog = params.custom[0];
|
|
41
43
|
let shape = params.custom[1];
|
|
@@ -51,7 +53,7 @@ fn customPost(color: vec3f, uv: vec2f) -> vec3f {
|
|
|
51
53
|
let slope = shape.x * rise;
|
|
52
54
|
var thin = 1.0;
|
|
53
55
|
if (abs(slope) > 0.0001) { thin = (1.0 - exp(-slope)) / slope; }
|
|
54
|
-
let depth = fog.a * exp(-shape.x * (up.w - shape.y)) * reach * thin;
|
|
56
|
+
let depth = fog.a * exp(-shape.x * (up.w - shape.y)) * reach * thin * mix(1.0, ${skyFog}, step(shape.z, reach));
|
|
55
57
|
result = mix(fog.rgb, result, exp(-max(depth, 0.0)));
|
|
56
58
|
}
|
|
57
59
|
if (shape.w > 0.0 && sun.z > 0.0) {
|
|
@@ -81,9 +83,21 @@ fn customPost(color: vec3f, uv: vec2f) -> vec3f {
|
|
|
81
83
|
*/
|
|
82
84
|
export class Atmosphere3D {
|
|
83
85
|
post;
|
|
86
|
+
/** How much of the fog lies over the sky, as given when it was made. */
|
|
87
|
+
skyFog;
|
|
84
88
|
#scratch = [0, 0, 0];
|
|
85
89
|
constructor(options = {}) {
|
|
86
|
-
|
|
90
|
+
const sky = options.skyFog ?? 1;
|
|
91
|
+
if (typeof sky !== 'number' || !(sky >= 0 && sky <= 1))
|
|
92
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'skyFog');
|
|
93
|
+
// A clear sky is a constant of the program: the sixteen numbers of the hook are all in use.
|
|
94
|
+
const constant = sky.toFixed(4);
|
|
95
|
+
this.skyFog = Number(constant);
|
|
96
|
+
this.post = createCustomPost3D({
|
|
97
|
+
key: sky === 1 ? 'world3d-atmosphere' : 'world3d-atmosphere-sky' + constant,
|
|
98
|
+
glsl: GLSL(constant),
|
|
99
|
+
wgsl: WGSL(constant)
|
|
100
|
+
});
|
|
87
101
|
colorFromHex(this.post.uniforms, options.fogColor ?? 0xb4c4d4);
|
|
88
102
|
this.fogDensity = options.fogDensity ?? 0.01;
|
|
89
103
|
this.fogHeight = options.fogHeight ?? 0;
|
|
@@ -172,6 +186,7 @@ export class Atmosphere3D {
|
|
|
172
186
|
return value;
|
|
173
187
|
}
|
|
174
188
|
}
|
|
189
|
+
/** Makes height fog and light shafts for a scene. */
|
|
175
190
|
export function createAtmosphere3D(options = {}) {
|
|
176
191
|
return new Atmosphere3D(options);
|
|
177
192
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Font3D } from '../../rendering/world3d/Text3D.js';
|
|
2
|
+
/** A canvas font to make: the page's font family, weight and style, how finely it is traced, and how much it is smoothed. */
|
|
3
|
+
export interface CanvasFontOptions3D {
|
|
4
|
+
/** A CSS font family the page has loaded. Defaults to `sans-serif`. */
|
|
5
|
+
readonly family?: string;
|
|
6
|
+
/** A CSS font weight, such as `bold` or `700`. Defaults to `normal`. */
|
|
7
|
+
readonly weight?: string | number;
|
|
8
|
+
readonly style?: 'normal' | 'italic';
|
|
9
|
+
/** Canvas pixels to one em when a character is traced, 16 to 512. Defaults to 128; more is finer and slower. */
|
|
10
|
+
readonly resolution?: number;
|
|
11
|
+
/** How far, in traced pixels, a smoothed outline may stray from the pixel edge. Defaults to 0.75. */
|
|
12
|
+
readonly tolerance?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A `Font3D` whose glyphs are traced from the page's own fonts, for 3D text in any script the page can draw, such as
|
|
16
|
+
* the Chinese of a road sign, without a font file. Each character is drawn and traced once, when first used. The
|
|
17
|
+
* outlines are straight segments following the drawn edge, so curves are as smooth as `resolution` allows. Where the
|
|
18
|
+
* page has neither `OffscreenCanvas` nor a document, it throws `WORLD3D_CONTEXT_UNAVAILABLE`.
|
|
19
|
+
*/
|
|
20
|
+
export declare function createCanvasFont3D(options?: CanvasFontOptions3D): Font3D;
|
|
21
|
+
//# sourceMappingURL=canvasFont3D.d.ts.map
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// A font for 3D text read from the page's own fonts: each character is drawn
|
|
3
|
+
// once onto a small canvas, its edge traced into outlines and smoothed, and
|
|
4
|
+
// handed to Font3D as straight segments. For a few dozen signs in any script,
|
|
5
|
+
// Chinese included, without shipping a font file.
|
|
6
|
+
import { Font3D } from '../../rendering/world3d/Text3D.js';
|
|
7
|
+
import { World3DError } from '../../rendering/world3d/core3D.js';
|
|
8
|
+
function canvasOf(size) {
|
|
9
|
+
const Offscreen = globalThis.OffscreenCanvas;
|
|
10
|
+
if (typeof Offscreen === 'function')
|
|
11
|
+
return new Offscreen(size, size).getContext('2d', { willReadFrequently: true }) ?? undefined;
|
|
12
|
+
const doc = globalThis.document;
|
|
13
|
+
if (doc === undefined)
|
|
14
|
+
return undefined;
|
|
15
|
+
const canvas = doc.createElement('canvas');
|
|
16
|
+
canvas.width = canvas.height = size;
|
|
17
|
+
return canvas.getContext('2d', { willReadFrequently: true }) ?? undefined;
|
|
18
|
+
}
|
|
19
|
+
/** The loops of pixel edges around the filled pixels of a mask, each a list of corner points. */
|
|
20
|
+
function traceEdges(filled, width, height) {
|
|
21
|
+
const at = (x, y) => x >= 0 && y >= 0 && x < width && y < height && filled[y * width + x] === 1;
|
|
22
|
+
// Directed edges with the filled pixel on their left, keyed by their start corner.
|
|
23
|
+
const next = new Map();
|
|
24
|
+
const key = (x, y) => y * (width + 1) + x;
|
|
25
|
+
const edge = (x0, y0, x1, y1) => {
|
|
26
|
+
const from = key(x0, y0), list = next.get(from);
|
|
27
|
+
if (list)
|
|
28
|
+
list.push(key(x1, y1));
|
|
29
|
+
else
|
|
30
|
+
next.set(from, [key(x1, y1)]);
|
|
31
|
+
};
|
|
32
|
+
for (let y = 0; y < height; y++)
|
|
33
|
+
for (let x = 0; x < width; x++) {
|
|
34
|
+
if (!at(x, y))
|
|
35
|
+
continue;
|
|
36
|
+
// Rows run down: going round a pixel with it on the left is anticlockwise on screen.
|
|
37
|
+
if (!at(x, y - 1))
|
|
38
|
+
edge(x + 1, y, x, y);
|
|
39
|
+
if (!at(x - 1, y))
|
|
40
|
+
edge(x, y, x, y + 1);
|
|
41
|
+
if (!at(x, y + 1))
|
|
42
|
+
edge(x, y + 1, x + 1, y + 1);
|
|
43
|
+
if (!at(x + 1, y))
|
|
44
|
+
edge(x + 1, y + 1, x + 1, y);
|
|
45
|
+
}
|
|
46
|
+
const loops = [];
|
|
47
|
+
for (const [start, ends] of next) {
|
|
48
|
+
while (ends.length > 0) {
|
|
49
|
+
const loop = [];
|
|
50
|
+
let from = start, to = ends.pop();
|
|
51
|
+
loop.push(from % (width + 1), Math.floor(from / (width + 1)));
|
|
52
|
+
while (to !== start) {
|
|
53
|
+
loop.push(to % (width + 1), Math.floor(to / (width + 1)));
|
|
54
|
+
const onward = next.get(to);
|
|
55
|
+
if (!onward || onward.length === 0)
|
|
56
|
+
break;
|
|
57
|
+
from = to;
|
|
58
|
+
to = onward.pop();
|
|
59
|
+
}
|
|
60
|
+
if (loop.length >= 6)
|
|
61
|
+
loops.push(loop);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return loops;
|
|
65
|
+
}
|
|
66
|
+
/** Fewer points along a closed loop, each removed one within `tolerance` of the line that replaces it. */
|
|
67
|
+
function simplify(loop, tolerance) {
|
|
68
|
+
const count = loop.length / 2;
|
|
69
|
+
if (count <= 4)
|
|
70
|
+
return loop;
|
|
71
|
+
const keep = new Uint8Array(count);
|
|
72
|
+
// Split the loop at its first point and the point farthest from it, and simplify each half.
|
|
73
|
+
let far = 0, best = -1;
|
|
74
|
+
for (let i = 1; i < count; i++) {
|
|
75
|
+
const d = (loop[i * 2] - loop[0]) ** 2 + (loop[i * 2 + 1] - loop[1]) ** 2;
|
|
76
|
+
if (d > best) {
|
|
77
|
+
best = d;
|
|
78
|
+
far = i;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
keep[0] = keep[far] = 1;
|
|
82
|
+
const stack = [
|
|
83
|
+
[0, far],
|
|
84
|
+
[far, count]
|
|
85
|
+
];
|
|
86
|
+
while (stack.length > 0) {
|
|
87
|
+
const [a, b] = stack.pop();
|
|
88
|
+
const ax = loop[a * 2], ay = loop[a * 2 + 1], bx = loop[(b % count) * 2], by = loop[(b % count) * 2 + 1], length = Math.hypot(bx - ax, by - ay) || 1;
|
|
89
|
+
let worst = -1, distance = tolerance;
|
|
90
|
+
for (let i = a + 1; i < b; i++) {
|
|
91
|
+
const d = Math.abs((bx - ax) * (ay - loop[i * 2 + 1]) - (ax - loop[i * 2]) * (by - ay)) / length;
|
|
92
|
+
if (d > distance) {
|
|
93
|
+
distance = d;
|
|
94
|
+
worst = i;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (worst >= 0) {
|
|
98
|
+
keep[worst] = 1;
|
|
99
|
+
stack.push([a, worst], [worst, b]);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const out = [];
|
|
103
|
+
for (let i = 0; i < count; i++)
|
|
104
|
+
if (keep[i])
|
|
105
|
+
out.push(loop[i * 2], loop[i * 2 + 1]);
|
|
106
|
+
return out.length >= 6 ? out : loop;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* A `Font3D` whose glyphs are traced from the page's own fonts, for 3D text in any script the page can draw, such as
|
|
110
|
+
* the Chinese of a road sign, without a font file. Each character is drawn and traced once, when first used. The
|
|
111
|
+
* outlines are straight segments following the drawn edge, so curves are as smooth as `resolution` allows. Where the
|
|
112
|
+
* page has neither `OffscreenCanvas` nor a document, it throws `WORLD3D_CONTEXT_UNAVAILABLE`.
|
|
113
|
+
*/
|
|
114
|
+
export function createCanvasFont3D(options = {}) {
|
|
115
|
+
if (options === null || typeof options !== 'object')
|
|
116
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'canvas font');
|
|
117
|
+
const family = options.family ?? 'sans-serif', weight = options.weight ?? 'normal', style = options.style ?? 'normal', em = options.resolution ?? 128, tolerance = options.tolerance ?? 0.75;
|
|
118
|
+
if (typeof family !== 'string' ||
|
|
119
|
+
family.length === 0 ||
|
|
120
|
+
/[;{}]/.test(family) ||
|
|
121
|
+
(typeof weight !== 'string' && typeof weight !== 'number') ||
|
|
122
|
+
(style !== 'normal' && style !== 'italic') ||
|
|
123
|
+
!Number.isInteger(em) ||
|
|
124
|
+
em < 16 ||
|
|
125
|
+
em > 512 ||
|
|
126
|
+
!(tolerance >= 0 && tolerance <= 8))
|
|
127
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'canvas font');
|
|
128
|
+
// Room for strokes that reach past the em box on every side.
|
|
129
|
+
const size = em * 2, left = Math.round(em / 2), baseline = Math.round(em * 1.4);
|
|
130
|
+
const context = canvasOf(size);
|
|
131
|
+
if (context === undefined)
|
|
132
|
+
throw new World3DError('WORLD3D_CONTEXT_UNAVAILABLE', 'canvas font');
|
|
133
|
+
context.font = `${style} ${weight} ${em}px ${family}`;
|
|
134
|
+
context.textBaseline = 'alphabetic';
|
|
135
|
+
context.fillStyle = '#fff';
|
|
136
|
+
const metrics = context.measureText('Hg中');
|
|
137
|
+
const ascender = metrics.fontBoundingBoxAscent > 0 ? metrics.fontBoundingBoxAscent : em * 0.88, descender = metrics.fontBoundingBoxDescent > 0 ? -metrics.fontBoundingBoxDescent : -em * 0.12;
|
|
138
|
+
const filled = new Uint8Array(size * size);
|
|
139
|
+
return new Font3D({
|
|
140
|
+
unitsPerEm: em,
|
|
141
|
+
ascender,
|
|
142
|
+
descender,
|
|
143
|
+
lineHeight: Math.max(em * 1.2, ascender - descender),
|
|
144
|
+
familyName: family,
|
|
145
|
+
glyph(codePoint) {
|
|
146
|
+
if (!Number.isInteger(codePoint) || codePoint < 0 || codePoint > 0x10ffff)
|
|
147
|
+
return undefined;
|
|
148
|
+
const text = String.fromCodePoint(codePoint), advance = context.measureText(text).width;
|
|
149
|
+
context.clearRect(0, 0, size, size);
|
|
150
|
+
context.fillText(text, left, baseline);
|
|
151
|
+
const pixels = context.getImageData(0, 0, size, size).data;
|
|
152
|
+
for (let i = 0; i < filled.length; i++)
|
|
153
|
+
filled[i] = pixels[i * 4 + 3] >= 128 ? 1 : 0;
|
|
154
|
+
const commands = [];
|
|
155
|
+
for (const loop of traceEdges(filled, size, size)) {
|
|
156
|
+
const points = simplify(loop, tolerance);
|
|
157
|
+
// Font units run up from the baseline; canvas rows run down.
|
|
158
|
+
for (let i = 0; i < points.length; i += 2)
|
|
159
|
+
commands.push(i === 0 ? 0 : 1, points[i] - left, baseline - points[i + 1]);
|
|
160
|
+
}
|
|
161
|
+
return { advance, commands };
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=canvasFont3D.js.map
|
|
@@ -6,9 +6,11 @@ import type { Scene3D } from '../../rendering/world3d/Object3D.js';
|
|
|
6
6
|
import type { RenderList3D } from '../../rendering/world3d/RenderList3D.js';
|
|
7
7
|
import type { PostProcessSettings3D } from './post3D.js';
|
|
8
8
|
import type { CompressedFormat3D, RenderTarget3D } from '../../rendering/world3d/Texture3D.js';
|
|
9
|
+
/** How a renderer maps bright colors into the screen's range. */
|
|
9
10
|
export type ToneMapping3D = 'none' | 'reinhard' | 'aces';
|
|
10
11
|
/** Half-float targets keep scene-referred light until composition. */
|
|
11
12
|
export declare function outputToneMapping3D(toneMapping: ToneMapping3D, target?: RenderTarget3D): ToneMapping3D;
|
|
13
|
+
/** What a renderer drew in its last frame: draws, triangles, culled nodes, lights, shadow maps and resources. */
|
|
12
14
|
export interface Renderer3DInfo {
|
|
13
15
|
frame: number;
|
|
14
16
|
drawCalls: number;
|
|
@@ -4,6 +4,7 @@ import type { Disposable, HostAdapter } from '@egret/contracts';
|
|
|
4
4
|
* owns the WebGL context, so this host has no device to start or close.
|
|
5
5
|
*/
|
|
6
6
|
export declare function createWorld3DHost(canvas: HTMLCanvasElement | OffscreenCanvas): HostAdapter;
|
|
7
|
+
/** What drives a 3D view: an Engine's clock and the call that advances it. */
|
|
7
8
|
export interface World3DLoopSource {
|
|
8
9
|
advanceTime(sourceSeconds: number): unknown;
|
|
9
10
|
readonly clock: {
|
|
@@ -25,6 +25,8 @@ export { FollowControls3D, createFollowControls3D } from './FollowControls3D.js'
|
|
|
25
25
|
export type { FollowControlsOptions3D } from './FollowControls3D.js';
|
|
26
26
|
export { Atmosphere3D, createAtmosphere3D } from './atmosphere3D.js';
|
|
27
27
|
export type { AtmosphereOptions3D } from './atmosphere3D.js';
|
|
28
|
+
export { createCanvasFont3D } from './canvasFont3D.js';
|
|
29
|
+
export type { CanvasFontOptions3D } from './canvasFont3D.js';
|
|
28
30
|
export { WORLD3D_QUALITY_PRESETS, createDynamicResolution3D, createWorld3DApp, pickWorld3DBackend, pickWorld3DQuality, isSoftwareRendered3D } from './app3D.js';
|
|
29
31
|
export type { DynamicResolution3D, DynamicResolutionOptions3D, World3DApp, World3DAppOptions, World3DBackend, World3DDeviceHints, World3DQuality, World3DQualityPreset, World3DShowOptions } from './app3D.js';
|
|
30
32
|
export { createScreenMarkers3D } from './markers3D.js';
|
|
@@ -33,6 +35,6 @@ export { createWorld3DStats } from './stats3D.js';
|
|
|
33
35
|
export type { World3DStats, World3DStatsOptions } from './stats3D.js';
|
|
34
36
|
export { createWorld3DOverlay } from './overlay3D.js';
|
|
35
37
|
export type { World3DOverlay, World3DOverlayOptions } from './overlay3D.js';
|
|
36
|
-
export { play3d, PlayThing3D } from './BrowserPlay3D.js';
|
|
37
|
-
export type { Play3DGame, Play3DOptions, PlayBurst3D, PlayCamera3D, PlayFollow3D, PlayPlace3D } from './BrowserPlay3D.js';
|
|
38
|
+
export { play3d, PlayThing3D, PlayLamp3D, PLAY_LOOKS_3D } from './BrowserPlay3D.js';
|
|
39
|
+
export type { Play3DGame, Play3DOptions, PlayBurst3D, PlayCamera3D, PlayFollow3D, PlayLampOptions3D, PlayLook3D, PlayLookName3D, PlayPlace3D, PlayWeather3D, PlayWeatherOptions3D } from './BrowserPlay3D.js';
|
|
38
40
|
//# sourceMappingURL=index.d.ts.map
|