@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
|
@@ -2,13 +2,16 @@
|
|
|
2
2
|
// A whole small 3D game from one call. The picture is a World3D app; everything else is `play`, drawn clear over
|
|
3
3
|
// it on a canvas of its own: the keys, the pointer, sound, timers, tweens, text and buttons. What is added here is
|
|
4
4
|
// what a 3D game makes its world of: boxes, balls and a ground that are placed by plain numbers, a camera that
|
|
5
|
-
// follows, a sun, tests of distance and overlap, and pieces thrown out by a hit
|
|
5
|
+
// follows, a sun, tests of distance and overlap, and pieces thrown out by a hit; things grouped to move as one,
|
|
6
|
+
// things that glow, lamps, and snow or rain.
|
|
6
7
|
import { EgretError } from '@egret/runtime';
|
|
7
8
|
import { play } from '../play.js';
|
|
8
9
|
import { Object3D, Scene3D } from '../../rendering/world3d/Object3D.js';
|
|
9
10
|
import { Mesh3D } from '../../rendering/world3d/Mesh3D.js';
|
|
10
11
|
import { createPerspectiveCamera3D } from '../../rendering/world3d/Camera3D.js';
|
|
11
|
-
import { createDirectionalLight3D, createHemisphereLight3D } from '../../rendering/world3d/Light3D.js';
|
|
12
|
+
import { createDirectionalLight3D, createHemisphereLight3D, createPointLight3D } from '../../rendering/world3d/Light3D.js';
|
|
13
|
+
import { GpuParticles3D } from '../../rendering/world3d/GpuParticles3D.js';
|
|
14
|
+
import { Texture3D } from '../../rendering/world3d/Texture3D.js';
|
|
12
15
|
import { createStandardMaterial3D, setColor3D } from '../../rendering/world3d/Material3D.js';
|
|
13
16
|
import { createBoxGeometry3D, createCylinderGeometry3D, createSphereGeometry3D } from '../../rendering/world3d/primitives3D.js';
|
|
14
17
|
import { linearColor3D } from '../../rendering/world3d/GeometryBuilder3D.js';
|
|
@@ -60,6 +63,8 @@ export class PlayThing3D {
|
|
|
60
63
|
middleZ;
|
|
61
64
|
#material;
|
|
62
65
|
#color;
|
|
66
|
+
#glow = 0;
|
|
67
|
+
#shadow;
|
|
63
68
|
#turn = [0, 0, 0];
|
|
64
69
|
#removed = false;
|
|
65
70
|
/**
|
|
@@ -185,6 +190,61 @@ export class PlayThing3D {
|
|
|
185
190
|
return;
|
|
186
191
|
this.#color = value;
|
|
187
192
|
setColor3D(this.#material.color, value);
|
|
193
|
+
if (this.#glow > 0)
|
|
194
|
+
setColor3D(this.#material.emissive, value);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* How much it shines with its own colour, lit or not: 0 (the default) not at all, 1 as bright as its colour,
|
|
198
|
+
* more for a lamp or a screen. A thing that glows is not hidden by fog. A model keeps the materials it has.
|
|
199
|
+
*/
|
|
200
|
+
get glow() {
|
|
201
|
+
return this.#glow;
|
|
202
|
+
}
|
|
203
|
+
set glow(value) {
|
|
204
|
+
if (!finite(value) || value < 0 || this.#material === undefined)
|
|
205
|
+
return;
|
|
206
|
+
this.#glow = value;
|
|
207
|
+
setColor3D(this.#material.emissive, value > 0 ? this.#color : 0);
|
|
208
|
+
this.#material.emissiveIntensity = value;
|
|
209
|
+
// What glows is seen through the fog and the snow, as a lighthouse or a lantern is at night.
|
|
210
|
+
this.#material.fog = value === 0;
|
|
211
|
+
this.#blend();
|
|
212
|
+
}
|
|
213
|
+
/** A see-through thing that glows adds its light to what is behind it, as a beam does; any other mixes over it. */
|
|
214
|
+
#blend() {
|
|
215
|
+
if (this.#material === undefined)
|
|
216
|
+
return;
|
|
217
|
+
this.#material.blending = this.#glow > 0 && this.#material.opacity < 1 ? 'additive' : 'normal';
|
|
218
|
+
// Fog, blending and the alpha mode choose the shader, so a change of them is told to the material.
|
|
219
|
+
this.#material.touch();
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* How much of it is seen, 0 to 1: 1 (the default) is solid, less lets what is behind it show through, as glass, a
|
|
223
|
+
* ghost or, with `glow`, a beam of light, whose light is added to what is behind it. A see-through thing casts no
|
|
224
|
+
* shadow. A model keeps the materials it has.
|
|
225
|
+
*/
|
|
226
|
+
get opacity() {
|
|
227
|
+
return this.#material?.opacity ?? 1;
|
|
228
|
+
}
|
|
229
|
+
set opacity(value) {
|
|
230
|
+
if (!finite(value) || this.#material === undefined)
|
|
231
|
+
return;
|
|
232
|
+
const opacity = Math.min(1, Math.max(0, value)), solid = opacity >= 1;
|
|
233
|
+
this.#material.opacity = opacity;
|
|
234
|
+
this.#material.alphaMode = solid ? 'opaque' : 'blend';
|
|
235
|
+
this.#material.depthWrite = solid;
|
|
236
|
+
this.#blend();
|
|
237
|
+
if (this.node instanceof Mesh3D) {
|
|
238
|
+
// It keeps the shadow it had when it is made solid again.
|
|
239
|
+
if (!solid && this.#shadow === undefined) {
|
|
240
|
+
this.#shadow = this.node.castShadow;
|
|
241
|
+
this.node.castShadow = false;
|
|
242
|
+
}
|
|
243
|
+
else if (solid && this.#shadow !== undefined) {
|
|
244
|
+
this.node.castShadow = this.#shadow;
|
|
245
|
+
this.#shadow = undefined;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
188
248
|
}
|
|
189
249
|
/** Whether `game.remove` has taken it out of the world. Setting it afterwards does nothing that is seen. */
|
|
190
250
|
get removed() {
|
|
@@ -200,6 +260,133 @@ export class PlayThing3D {
|
|
|
200
260
|
cleanUp([() => this.node.removeFromParent(), () => geometry?.dispose(), () => this.#material?.dispose()]);
|
|
201
261
|
}
|
|
202
262
|
}
|
|
263
|
+
/**
|
|
264
|
+
* A lamp: light from a point of the world that fades out by `range`. It is placed and changed by plain numbers, and
|
|
265
|
+
* `game.remove` puts it out. Up to eight are lit fully; more are lit by a coarser way.
|
|
266
|
+
*/
|
|
267
|
+
export class PlayLamp3D {
|
|
268
|
+
node;
|
|
269
|
+
#color;
|
|
270
|
+
#removed = false;
|
|
271
|
+
constructor(color, intensity, range) {
|
|
272
|
+
this.#color = color;
|
|
273
|
+
this.node = createPointLight3D({ color, intensity, range });
|
|
274
|
+
}
|
|
275
|
+
get x() {
|
|
276
|
+
return this.node.position[0];
|
|
277
|
+
}
|
|
278
|
+
set x(value) {
|
|
279
|
+
if (finite(value))
|
|
280
|
+
this.node.setPosition(value, this.node.position[1], this.node.position[2]);
|
|
281
|
+
}
|
|
282
|
+
get y() {
|
|
283
|
+
return this.node.position[1];
|
|
284
|
+
}
|
|
285
|
+
set y(value) {
|
|
286
|
+
if (finite(value))
|
|
287
|
+
this.node.setPosition(this.node.position[0], value, this.node.position[2]);
|
|
288
|
+
}
|
|
289
|
+
get z() {
|
|
290
|
+
return this.node.position[2];
|
|
291
|
+
}
|
|
292
|
+
set z(value) {
|
|
293
|
+
if (finite(value))
|
|
294
|
+
this.node.setPosition(this.node.position[0], this.node.position[1], value);
|
|
295
|
+
}
|
|
296
|
+
get color() {
|
|
297
|
+
return this.#color;
|
|
298
|
+
}
|
|
299
|
+
set color(value) {
|
|
300
|
+
if (!colour(value))
|
|
301
|
+
return;
|
|
302
|
+
this.#color = value;
|
|
303
|
+
setColor3D(this.node.color, value);
|
|
304
|
+
}
|
|
305
|
+
/** How bright it is; 0 is dark. */
|
|
306
|
+
get intensity() {
|
|
307
|
+
return this.node.intensity;
|
|
308
|
+
}
|
|
309
|
+
set intensity(value) {
|
|
310
|
+
if (finite(value) && value >= 0)
|
|
311
|
+
this.node.intensity = value;
|
|
312
|
+
}
|
|
313
|
+
/** How far it reaches before it has faded out, in units of the world. */
|
|
314
|
+
get range() {
|
|
315
|
+
return this.node.range;
|
|
316
|
+
}
|
|
317
|
+
set range(value) {
|
|
318
|
+
if (above(value))
|
|
319
|
+
this.node.range = value;
|
|
320
|
+
}
|
|
321
|
+
get visible() {
|
|
322
|
+
return this.node.visible;
|
|
323
|
+
}
|
|
324
|
+
set visible(value) {
|
|
325
|
+
this.node.visible = value === true;
|
|
326
|
+
}
|
|
327
|
+
get removed() {
|
|
328
|
+
return this.#removed;
|
|
329
|
+
}
|
|
330
|
+
leave() {
|
|
331
|
+
if (this.#removed)
|
|
332
|
+
return;
|
|
333
|
+
this.#removed = true;
|
|
334
|
+
this.node.removeFromParent();
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
/** The looks every game is given, by name. */
|
|
338
|
+
export const PLAY_LOOKS_3D = Object.freeze({
|
|
339
|
+
day: {
|
|
340
|
+
background: 0x8ec5ff,
|
|
341
|
+
sky: 0xcfe3ff,
|
|
342
|
+
ground: 0x4a5a3a,
|
|
343
|
+
light: 0.9,
|
|
344
|
+
sun: 0xfff4e0,
|
|
345
|
+
sunIntensity: 2.4,
|
|
346
|
+
sunFrom: [8, 16, 10],
|
|
347
|
+
fog: 0.006
|
|
348
|
+
},
|
|
349
|
+
dusk: {
|
|
350
|
+
background: 0xd98a62,
|
|
351
|
+
sky: 0xffc18a,
|
|
352
|
+
ground: 0x2b2238,
|
|
353
|
+
light: 0.7,
|
|
354
|
+
sun: 0xff9a5a,
|
|
355
|
+
sunIntensity: 2,
|
|
356
|
+
sunFrom: [16, 5, 6],
|
|
357
|
+
fog: 0.018
|
|
358
|
+
},
|
|
359
|
+
night: {
|
|
360
|
+
background: 0x0b1020,
|
|
361
|
+
sky: 0x3a4a78,
|
|
362
|
+
ground: 0x08080c,
|
|
363
|
+
light: 0.22,
|
|
364
|
+
sun: 0x9fb8ff,
|
|
365
|
+
sunIntensity: 0.35,
|
|
366
|
+
sunFrom: [-6, 14, 8],
|
|
367
|
+
fog: 0.015
|
|
368
|
+
},
|
|
369
|
+
fog: {
|
|
370
|
+
background: 0xb8c0c8,
|
|
371
|
+
sky: 0xdfe5ea,
|
|
372
|
+
ground: 0x6b7076,
|
|
373
|
+
light: 0.9,
|
|
374
|
+
sun: 0xffffff,
|
|
375
|
+
sunIntensity: 1,
|
|
376
|
+
sunFrom: [8, 16, 10],
|
|
377
|
+
fog: 0.06
|
|
378
|
+
},
|
|
379
|
+
snow: {
|
|
380
|
+
background: 0xdfe8f2,
|
|
381
|
+
sky: 0xe6eef8,
|
|
382
|
+
ground: 0x8a96a6,
|
|
383
|
+
light: 0.7,
|
|
384
|
+
sun: 0xfff8f0,
|
|
385
|
+
sunIntensity: 1.4,
|
|
386
|
+
sunFrom: [8, 14, 12],
|
|
387
|
+
fog: 0.025
|
|
388
|
+
}
|
|
389
|
+
});
|
|
203
390
|
const PIECES = 96;
|
|
204
391
|
/** How deep a ground is under its top. */
|
|
205
392
|
const GROUND_DEPTH = 8;
|
|
@@ -273,8 +460,62 @@ export function pushOut3D(a, b) {
|
|
|
273
460
|
return { x: p[0] >= q[0] ? x : -x, y: 0, z: 0 };
|
|
274
461
|
return { x: 0, y: 0, z: p[2] >= q[2] ? z : -z };
|
|
275
462
|
}
|
|
463
|
+
function browserSurface(given, options) {
|
|
464
|
+
// The picture goes on a canvas of its own, under the game's, in the same place whatever the page does.
|
|
465
|
+
const over = given.canvas, holder = over.parentElement;
|
|
466
|
+
if (holder === null)
|
|
467
|
+
throw invalid('play3d needs its canvas in the page');
|
|
468
|
+
const page = over.ownerDocument, win = page.defaultView ?? globalThis;
|
|
469
|
+
const under = page.createElement('canvas');
|
|
470
|
+
under.style.cssText = 'position:absolute;left:0;top:0;width:0;height:0;display:block';
|
|
471
|
+
const initialPosition = over.style.position;
|
|
472
|
+
let observer;
|
|
473
|
+
const place = () => {
|
|
474
|
+
const outer = holder.getBoundingClientRect(), box = over.getBoundingClientRect();
|
|
475
|
+
under.style.left = box.left - outer.left + holder.scrollLeft + 'px';
|
|
476
|
+
under.style.top = box.top - outer.top + holder.scrollTop + 'px';
|
|
477
|
+
under.style.width = box.width + 'px';
|
|
478
|
+
under.style.height = box.height + 'px';
|
|
479
|
+
};
|
|
480
|
+
const unplace = () => cleanUp([() => win.removeEventListener('resize', place), () => observer?.disconnect()]);
|
|
481
|
+
try {
|
|
482
|
+
over.style.position = 'relative';
|
|
483
|
+
holder.insertBefore(under, over);
|
|
484
|
+
place();
|
|
485
|
+
const Resize = globalThis.ResizeObserver;
|
|
486
|
+
observer = Resize ? new Resize(place) : undefined;
|
|
487
|
+
observer?.observe(over);
|
|
488
|
+
win.addEventListener('resize', place);
|
|
489
|
+
const ready = createWorld3DApp(under, {
|
|
490
|
+
backend: options.backend === 'webgpu' ? 'webgpu' : 'webgl2',
|
|
491
|
+
...(options.onError === undefined ? {} : { onError: options.onError })
|
|
492
|
+
});
|
|
493
|
+
return { ready, unplace, remove: () => under.remove() };
|
|
494
|
+
}
|
|
495
|
+
catch (cause) {
|
|
496
|
+
// The caller can only retire a surface after we return it. Restore the DOM
|
|
497
|
+
// here even if a host listener or observer throws during registration.
|
|
498
|
+
try {
|
|
499
|
+
cleanUp([
|
|
500
|
+
unplace,
|
|
501
|
+
() => under.remove(),
|
|
502
|
+
() => {
|
|
503
|
+
over.style.position = initialPosition;
|
|
504
|
+
}
|
|
505
|
+
]);
|
|
506
|
+
}
|
|
507
|
+
catch (cleanup) {
|
|
508
|
+
throw new AggregateError([cause, cleanup], 'Play3D surface mount and rollback failed', { cause });
|
|
509
|
+
}
|
|
510
|
+
throw cause;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
276
513
|
/** Starts a 3D game in the page. See the guide `play3d.md`. */
|
|
277
|
-
export
|
|
514
|
+
export function play3d(options) {
|
|
515
|
+
return createPlay3DSession(options, play, browserSurface);
|
|
516
|
+
}
|
|
517
|
+
/** Internal host entry. The flat session owns input and UI; the surface presents the original scene. */
|
|
518
|
+
export async function createPlay3DSession(options, startFlat, attach) {
|
|
278
519
|
if (options === null || typeof options !== 'object')
|
|
279
520
|
throw invalid('play3d takes an object of options');
|
|
280
521
|
const { setup, update, background = 0x0b1020 } = options;
|
|
@@ -286,7 +527,7 @@ export async function play3d(options) {
|
|
|
286
527
|
throw invalid('update is a function');
|
|
287
528
|
if (options.canvas !== undefined)
|
|
288
529
|
throw invalid('play3d makes its own canvases');
|
|
289
|
-
let game, app, creatingApp,
|
|
530
|
+
let game, app, creatingApp, surface;
|
|
290
531
|
let clearing = false, closing = false, generation = 0;
|
|
291
532
|
let disposal;
|
|
292
533
|
const admit = () => {
|
|
@@ -307,14 +548,126 @@ export async function play3d(options) {
|
|
|
307
548
|
sun.shadow.extent = 24;
|
|
308
549
|
sun.shadow.far = 120;
|
|
309
550
|
const things = new Set();
|
|
551
|
+
// The parts of each group, which leave with it; and the lamps that are lit.
|
|
552
|
+
const groups = new WeakMap(), grouped = new WeakSet();
|
|
553
|
+
const lamps = new Set();
|
|
554
|
+
// What falls, made when first asked for and kept over what the camera looks at.
|
|
555
|
+
// A soft round dot that every flake and drop is drawn with, made when first needed.
|
|
556
|
+
let dot, streak;
|
|
557
|
+
const dotTexture = () => {
|
|
558
|
+
if (dot !== undefined)
|
|
559
|
+
return dot;
|
|
560
|
+
const size = 16, data = new Uint8Array(4 * size * size);
|
|
561
|
+
for (let y = 0; y < size; y++)
|
|
562
|
+
for (let x = 0; x < size; x++) {
|
|
563
|
+
const d = Math.hypot(x + 0.5 - size / 2, y + 0.5 - size / 2) / (size / 2);
|
|
564
|
+
data.set([255, 255, 255, Math.round(255 * Math.max(0, Math.min(1, (1 - d) * 2.5)))], 4 * (y * size + x));
|
|
565
|
+
}
|
|
566
|
+
return (dot = new Texture3D({ width: size, height: size, data }, { wrapS: 'clamp', wrapT: 'clamp' }));
|
|
567
|
+
};
|
|
568
|
+
// A drop of rain is seen as a streak: a thin upright line, brightest in its middle and fading to its ends.
|
|
569
|
+
const streakTexture = () => {
|
|
570
|
+
if (streak !== undefined)
|
|
571
|
+
return streak;
|
|
572
|
+
const width = 8, height = 32, data = new Uint8Array(4 * width * height);
|
|
573
|
+
for (let y = 0; y < height; y++)
|
|
574
|
+
for (let x = 0; x < width; x++) {
|
|
575
|
+
const across = Math.max(0, 1 - Math.abs(x + 0.5 - width / 2) / 1.5), along = Math.sin((Math.PI * (y + 0.5)) / height);
|
|
576
|
+
data.set([255, 255, 255, Math.round(255 * Math.min(1, across) * along)], 4 * (y * width + x));
|
|
577
|
+
}
|
|
578
|
+
return (streak = new Texture3D({ width, height, data }, { wrapS: 'clamp', wrapT: 'clamp' }));
|
|
579
|
+
};
|
|
580
|
+
let falling, fallingKind = 'none', fallingAmount = 1;
|
|
581
|
+
const fall = (kind, amount) => {
|
|
582
|
+
if (kind === fallingKind && amount === fallingAmount)
|
|
583
|
+
return;
|
|
584
|
+
falling?.removeFromParent();
|
|
585
|
+
falling?.dispose();
|
|
586
|
+
falling = undefined;
|
|
587
|
+
fallingKind = kind;
|
|
588
|
+
fallingAmount = amount;
|
|
589
|
+
if (kind === 'none' || amount === 0)
|
|
590
|
+
return;
|
|
591
|
+
const snow = kind === 'snow';
|
|
592
|
+
// A box of sky over what is looked at; flakes are left where they fall as the camera moves.
|
|
593
|
+
falling = new GpuParticles3D({
|
|
594
|
+
count: Math.max(1, Math.round((snow ? 1600 : 2400) * amount)),
|
|
595
|
+
lifetime: snow ? [5, 7] : [0.9, 1.1],
|
|
596
|
+
speed: snow ? [0.4, 0.9] : [16, 20],
|
|
597
|
+
direction: [snow ? 0.15 : 0.05, -1, 0],
|
|
598
|
+
spread: snow ? 0.5 : 0.04,
|
|
599
|
+
gravity: [0, snow ? -0.4 : -6, 0],
|
|
600
|
+
startSize: snow ? [0.12, 0.22] : [0.3, 0.42],
|
|
601
|
+
startColor: snow ? 0xffffff : 0xa8bcd8,
|
|
602
|
+
startOpacity: snow ? 0.95 : 0.55,
|
|
603
|
+
endOpacity: snow ? 0.9 : 0.5,
|
|
604
|
+
fadeIn: 0.05,
|
|
605
|
+
fadeOut: 0.15,
|
|
606
|
+
shape: 'box',
|
|
607
|
+
extents: [22, 0.5, 22],
|
|
608
|
+
loop: true,
|
|
609
|
+
space: 'world',
|
|
610
|
+
seed: 7,
|
|
611
|
+
map: snow ? dotTexture() : streakTexture()
|
|
612
|
+
});
|
|
613
|
+
falling.castShadow = false;
|
|
614
|
+
falling.receiveShadow = false;
|
|
615
|
+
falling.setPosition(aim[0], aim[1] + (snow ? 9 : 16), aim[2]);
|
|
616
|
+
scene.addChild(falling);
|
|
617
|
+
};
|
|
310
618
|
// The camera: where the game put it, what it looks at, and how far a shake has it out of place.
|
|
311
619
|
const base = [0, 6, 12], aim = [0, 0, 0], shaken = [0, 0, 0];
|
|
312
|
-
let followed, turning = false, offset = [0, 4, 8], smooth = 6, shakeAmount = 0, shakeLeft = 0, shakeSpan = 1;
|
|
620
|
+
let followed, turning = false, lookAbove = 0, offset = [0, 4, 8], smooth = 6, shakeAmount = 0, shakeLeft = 0, shakeSpan = 1;
|
|
621
|
+
// The side the sun shines from; a look changes it.
|
|
622
|
+
const sunFrom = [8, 16, 10];
|
|
623
|
+
const look = (given) => {
|
|
624
|
+
const chosen = typeof given === 'string' ? PLAY_LOOKS_3D[given] : given;
|
|
625
|
+
if (chosen === undefined || chosen === null || typeof chosen !== 'object')
|
|
626
|
+
throw invalid("look is 'day', 'dusk', 'night', 'fog' or 'snow', or { background, sky, ground, sun, fog }");
|
|
627
|
+
const hex = (value) => Number.isInteger(value) && value >= 0 && value <= 0xffffff;
|
|
628
|
+
// A strength given a colour, as 0x2a3550 for `light`, would light the world white: it is refused instead.
|
|
629
|
+
for (const key of ['light', 'sunIntensity'])
|
|
630
|
+
if (chosen[key] !== undefined && !(finite(chosen[key]) && chosen[key] >= 0 && chosen[key] <= 16))
|
|
631
|
+
throw invalid(key +
|
|
632
|
+
' is how strong the light is, 0 to 16 (night 0.22, day 0.9); its colour is ' +
|
|
633
|
+
(key === 'light' ? 'sky' : 'sun'));
|
|
634
|
+
if (hex(chosen.background)) {
|
|
635
|
+
scene.background = linearColor3D(chosen.background);
|
|
636
|
+
if (scene.fog !== undefined)
|
|
637
|
+
scene.fog = { ...scene.fog, color: linearColor3D(chosen.background) };
|
|
638
|
+
}
|
|
639
|
+
if (hex(chosen.sky))
|
|
640
|
+
setColor3D(sky.color, chosen.sky);
|
|
641
|
+
if (hex(chosen.ground))
|
|
642
|
+
setColor3D(sky.groundColor, chosen.ground);
|
|
643
|
+
if (finite(chosen.light) && chosen.light >= 0)
|
|
644
|
+
sky.intensity = chosen.light;
|
|
645
|
+
if (hex(chosen.sun))
|
|
646
|
+
setColor3D(sun.color, chosen.sun);
|
|
647
|
+
if (finite(chosen.sunIntensity) && chosen.sunIntensity >= 0)
|
|
648
|
+
sun.intensity = chosen.sunIntensity;
|
|
649
|
+
const from = chosen.sunFrom;
|
|
650
|
+
if (Array.isArray(from) && from.length === 3 && from.every(finite) && from[1] > 0) {
|
|
651
|
+
sunFrom[0] = from[0];
|
|
652
|
+
sunFrom[1] = from[1];
|
|
653
|
+
sunFrom[2] = from[2];
|
|
654
|
+
}
|
|
655
|
+
if (finite(chosen.fog) && chosen.fog >= 0) {
|
|
656
|
+
const color = Array.isArray(scene.background)
|
|
657
|
+
? scene.background
|
|
658
|
+
: linearColor3D(background);
|
|
659
|
+
scene.fog =
|
|
660
|
+
chosen.fog === 0
|
|
661
|
+
? undefined
|
|
662
|
+
: { kind: 'exponential', color: [...color], density: chosen.fog };
|
|
663
|
+
}
|
|
664
|
+
settle();
|
|
665
|
+
};
|
|
313
666
|
const settle = () => {
|
|
314
667
|
eye.setPosition(base[0] + shaken[0], base[1] + shaken[1], base[2] + shaken[2]);
|
|
315
668
|
eye.lookAt(aim[0], aim[1], aim[2]);
|
|
316
669
|
// The sun keeps its direction and stays over what is looked at, so its shadows are there.
|
|
317
|
-
sun.setPosition(aim[0] +
|
|
670
|
+
sun.setPosition(aim[0] + sunFrom[0], aim[1] + sunFrom[1], aim[2] + sunFrom[2]);
|
|
318
671
|
sun.lookAt(aim[0], aim[1], aim[2]);
|
|
319
672
|
};
|
|
320
673
|
const camera = {
|
|
@@ -424,8 +777,9 @@ export async function play3d(options) {
|
|
|
424
777
|
clearing = true;
|
|
425
778
|
generation++;
|
|
426
779
|
try {
|
|
427
|
-
const leaving = [...things];
|
|
780
|
+
const leaving = [...things], unlit = [...lamps];
|
|
428
781
|
things.clear();
|
|
782
|
+
lamps.clear();
|
|
429
783
|
taps.clear();
|
|
430
784
|
tapErrors = {};
|
|
431
785
|
for (const piece of pieces) {
|
|
@@ -439,7 +793,7 @@ export async function play3d(options) {
|
|
|
439
793
|
aim[0] = aim[1] = aim[2] = 0;
|
|
440
794
|
shakeLeft = 0;
|
|
441
795
|
shaken[0] = shaken[1] = shaken[2] = 0;
|
|
442
|
-
cleanUp(leaving.map(thing => () => thing.leave()));
|
|
796
|
+
cleanUp([...leaving.map(thing => () => thing.leave()), ...unlit.map(lamp => () => lamp.leave())]);
|
|
443
797
|
}
|
|
444
798
|
finally {
|
|
445
799
|
clearing = false;
|
|
@@ -462,9 +816,12 @@ export async function play3d(options) {
|
|
|
462
816
|
clear,
|
|
463
817
|
...pieces.map(piece => () => piece.thing.leave()),
|
|
464
818
|
() => pieceShape.dispose(),
|
|
465
|
-
() =>
|
|
819
|
+
() => fall('none', 0),
|
|
820
|
+
() => dot?.dispose(),
|
|
821
|
+
() => streak?.dispose(),
|
|
822
|
+
() => surface?.unplace?.(),
|
|
466
823
|
() => app?.dispose(),
|
|
467
|
-
() =>
|
|
824
|
+
() => surface?.remove?.()
|
|
468
825
|
]);
|
|
469
826
|
}
|
|
470
827
|
catch (cause) {
|
|
@@ -495,7 +852,7 @@ export async function play3d(options) {
|
|
|
495
852
|
base[1] = base[1] + (y - base[1]) * share;
|
|
496
853
|
base[2] = base[2] + (z - base[2]) * share;
|
|
497
854
|
aim[0] = followed.x;
|
|
498
|
-
aim[1] = followed.y;
|
|
855
|
+
aim[1] = followed.y + lookAbove;
|
|
499
856
|
aim[2] = followed.z;
|
|
500
857
|
}
|
|
501
858
|
if (shakeLeft > 0) {
|
|
@@ -504,6 +861,10 @@ export async function play3d(options) {
|
|
|
504
861
|
for (let i = 0; i < 3; i++)
|
|
505
862
|
shaken[i] = (Math.random() * 2 - 1) * reach;
|
|
506
863
|
}
|
|
864
|
+
if (falling !== undefined) {
|
|
865
|
+
falling.setPosition(aim[0], aim[1] + (fallingKind === 'snow' ? 9 : 16), aim[2]);
|
|
866
|
+
falling.update(seconds);
|
|
867
|
+
}
|
|
507
868
|
for (const piece of pieces) {
|
|
508
869
|
if (piece.life <= 0)
|
|
509
870
|
continue;
|
|
@@ -522,6 +883,7 @@ export async function play3d(options) {
|
|
|
522
883
|
};
|
|
523
884
|
const extend = (flat) => {
|
|
524
885
|
const added = {
|
|
886
|
+
look,
|
|
525
887
|
box(width, height, depth, color, at = {}) {
|
|
526
888
|
admit();
|
|
527
889
|
if (!above(width) || !above(height) || !above(depth))
|
|
@@ -590,16 +952,83 @@ export async function play3d(options) {
|
|
|
590
952
|
taps.set(target, callback);
|
|
591
953
|
},
|
|
592
954
|
remove(body) {
|
|
593
|
-
if (
|
|
955
|
+
if (body instanceof PlayLamp3D) {
|
|
956
|
+
lamps.delete(body);
|
|
957
|
+
body.leave();
|
|
958
|
+
}
|
|
959
|
+
else if (isThing(body)) {
|
|
594
960
|
things.delete(body);
|
|
595
961
|
taps.delete(body);
|
|
596
962
|
if (followed === body)
|
|
597
963
|
followed = undefined;
|
|
598
964
|
body.leave();
|
|
965
|
+
for (const part of groups.get(body) ?? [])
|
|
966
|
+
whole.remove(part);
|
|
599
967
|
}
|
|
600
968
|
else
|
|
601
969
|
flat.remove(body);
|
|
602
970
|
},
|
|
971
|
+
group(parts, at = {}) {
|
|
972
|
+
admit();
|
|
973
|
+
if (!Array.isArray(parts) || parts.length === 0 || !parts.every(isThing))
|
|
974
|
+
throw invalid('group takes a list of things');
|
|
975
|
+
if (parts.some(part => part.removed || !things.has(part) || grouped.has(part)) ||
|
|
976
|
+
new Set(parts).size !== parts.length)
|
|
977
|
+
throw invalid('a group is made of things of the world not in a group, each once');
|
|
978
|
+
if (at === null || typeof at !== 'object')
|
|
979
|
+
throw invalid('a place is an object with x, y and z');
|
|
980
|
+
const { x, y, z } = at;
|
|
981
|
+
admit();
|
|
982
|
+
// The box of the parts where they are, as the group's own.
|
|
983
|
+
const low = [Infinity, Infinity, Infinity], high = [-Infinity, -Infinity, -Infinity];
|
|
984
|
+
for (const part of parts) {
|
|
985
|
+
const box = boxOf(part);
|
|
986
|
+
for (let k = 0; k < 3; k++) {
|
|
987
|
+
low[k] = Math.min(low[k], box[k] - box[k + 3]);
|
|
988
|
+
high[k] = Math.max(high[k], box[k] + box[k + 3]);
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
const node = new Object3D();
|
|
992
|
+
for (const part of parts) {
|
|
993
|
+
part.node.removeFromParent();
|
|
994
|
+
node.addChild(part.node);
|
|
995
|
+
}
|
|
996
|
+
const thing = new PlayThing3D(node, 0xffffff, [0, 1, 2].map(k => (high[k] - low[k]) / 2), [0, 1, 2].map(k => (high[k] + low[k]) / 2));
|
|
997
|
+
node.setPosition(finite(x) ? x : 0, finite(y) ? y : 0, finite(z) ? z : 0);
|
|
998
|
+
scene.addChild(node);
|
|
999
|
+
things.add(thing);
|
|
1000
|
+
groups.set(thing, [...parts]);
|
|
1001
|
+
for (const part of parts)
|
|
1002
|
+
grouped.add(part);
|
|
1003
|
+
return thing;
|
|
1004
|
+
},
|
|
1005
|
+
lamp(color, at = {}, o = {}) {
|
|
1006
|
+
admit();
|
|
1007
|
+
if (!colour(color))
|
|
1008
|
+
throw invalid('a colour is a number from 0 to 0xffffff');
|
|
1009
|
+
if (at === null || typeof at !== 'object')
|
|
1010
|
+
throw invalid('a place is an object with x, y and z');
|
|
1011
|
+
if (o === null || typeof o !== 'object')
|
|
1012
|
+
throw invalid('a lamp takes { intensity, range }');
|
|
1013
|
+
const { x, y, z } = at;
|
|
1014
|
+
const intensity = finite(o.intensity) && o.intensity >= 0 ? o.intensity : 4, range = above(o.range) ? o.range : 8;
|
|
1015
|
+
admit();
|
|
1016
|
+
const lamp = new PlayLamp3D(color, intensity, range);
|
|
1017
|
+
lamp.node.setPosition(finite(x) ? x : 0, finite(y) ? y : 0, finite(z) ? z : 0);
|
|
1018
|
+
scene.addChild(lamp.node);
|
|
1019
|
+
lamps.add(lamp);
|
|
1020
|
+
return lamp;
|
|
1021
|
+
},
|
|
1022
|
+
weather(kind, o = {}) {
|
|
1023
|
+
admit();
|
|
1024
|
+
if (kind !== 'snow' && kind !== 'rain' && kind !== 'none')
|
|
1025
|
+
throw invalid("weather is 'snow', 'rain' or 'none'");
|
|
1026
|
+
if (o === null || typeof o !== 'object')
|
|
1027
|
+
throw invalid('weather takes { amount }');
|
|
1028
|
+
const amount = finite(o.amount) ? Math.max(0, Math.min(3, o.amount)) : 1;
|
|
1029
|
+
admit();
|
|
1030
|
+
fall(kind, amount);
|
|
1031
|
+
},
|
|
603
1032
|
near(a, b, distance) {
|
|
604
1033
|
if (!isThing(a) || !isThing(b))
|
|
605
1034
|
return !isThing(a) && !isThing(b) && flat.near(a, b, distance ?? 0);
|
|
@@ -642,10 +1071,11 @@ export async function play3d(options) {
|
|
|
642
1071
|
offset = [finite(where.x) ? where.x : 0, finite(where.y) ? where.y : 4, finite(where.z) ? where.z : 8];
|
|
643
1072
|
smooth = finite(where.smooth) && where.smooth >= 0 ? where.smooth : 6;
|
|
644
1073
|
turning = where.turn === true;
|
|
1074
|
+
lookAbove = finite(where.lookY) ? where.lookY : 0;
|
|
645
1075
|
// It starts where it will stay, and does not fly in from where the camera was.
|
|
646
1076
|
[base[0], base[1], base[2]] = placeBy(thing);
|
|
647
1077
|
aim[0] = thing.x;
|
|
648
|
-
aim[1] = thing.y;
|
|
1078
|
+
aim[1] = thing.y + lookAbove;
|
|
649
1079
|
aim[2] = thing.z;
|
|
650
1080
|
},
|
|
651
1081
|
hitStop(seconds = 0.06) {
|
|
@@ -734,7 +1164,7 @@ export async function play3d(options) {
|
|
|
734
1164
|
});
|
|
735
1165
|
return whole;
|
|
736
1166
|
};
|
|
737
|
-
const flat = await
|
|
1167
|
+
const flat = await startFlat({
|
|
738
1168
|
...options,
|
|
739
1169
|
// The interface is drawn by WebGL2 unless WebGPU is asked for, as the overlay of a World3D app is.
|
|
740
1170
|
backend: options.backend ?? 'webgl2',
|
|
@@ -742,34 +1172,8 @@ export async function play3d(options) {
|
|
|
742
1172
|
async setup(given) {
|
|
743
1173
|
admit();
|
|
744
1174
|
if (game === undefined) {
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
if (holder === null)
|
|
748
|
-
throw invalid('play3d needs its canvas in the page');
|
|
749
|
-
const page = over.ownerDocument, win = page.defaultView ?? globalThis;
|
|
750
|
-
const under = (deep = page.createElement('canvas'));
|
|
751
|
-
under.style.cssText = 'position:absolute;left:0;top:0;width:0;height:0;display:block';
|
|
752
|
-
over.style.position = 'relative';
|
|
753
|
-
holder.insertBefore(under, over);
|
|
754
|
-
const place = () => {
|
|
755
|
-
const outer = holder.getBoundingClientRect(), box = over.getBoundingClientRect();
|
|
756
|
-
under.style.left = box.left - outer.left + holder.scrollLeft + 'px';
|
|
757
|
-
under.style.top = box.top - outer.top + holder.scrollTop + 'px';
|
|
758
|
-
under.style.width = box.width + 'px';
|
|
759
|
-
under.style.height = box.height + 'px';
|
|
760
|
-
};
|
|
761
|
-
place();
|
|
762
|
-
const Resize = globalThis.ResizeObserver, observer = Resize ? new Resize(place) : undefined;
|
|
763
|
-
observer?.observe(over);
|
|
764
|
-
win.addEventListener('resize', place);
|
|
765
|
-
unplace = () => {
|
|
766
|
-
observer?.disconnect();
|
|
767
|
-
win.removeEventListener('resize', place);
|
|
768
|
-
};
|
|
769
|
-
creatingApp = createWorld3DApp(under, {
|
|
770
|
-
backend: options.backend === 'webgpu' ? 'webgpu' : 'webgl2',
|
|
771
|
-
...(options.onError === undefined ? {} : { onError: options.onError })
|
|
772
|
-
});
|
|
1175
|
+
surface = attach(given, options);
|
|
1176
|
+
creatingApp = surface.ready;
|
|
773
1177
|
try {
|
|
774
1178
|
app = await creatingApp;
|
|
775
1179
|
}
|
|
@@ -782,7 +1186,8 @@ export async function play3d(options) {
|
|
|
782
1186
|
scene.addChild(sky);
|
|
783
1187
|
scene.addChild(sun);
|
|
784
1188
|
settle();
|
|
785
|
-
app
|
|
1189
|
+
app?.show(scene, eye);
|
|
1190
|
+
surface.show?.(scene, eye);
|
|
786
1191
|
game = extend(given);
|
|
787
1192
|
}
|
|
788
1193
|
else
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Disposable } from '@egret/contracts';
|
|
2
2
|
import type { Camera3D } from '../../rendering/world3d/Camera3D.js';
|
|
3
|
+
/** Fly controls to make: how fast they move and look, whether they fly, use pointer lock or damp, and their keys. */
|
|
3
4
|
export interface FlyControlsOptions3D {
|
|
4
5
|
/** Units per second. */
|
|
5
6
|
readonly moveSpeed?: number;
|
|
@@ -16,6 +17,7 @@ export interface FlyControlsOptions3D {
|
|
|
16
17
|
/** Key codes (KeyboardEvent.code) for each action. */
|
|
17
18
|
readonly keys?: Partial<FlyControlsKeys3D>;
|
|
18
19
|
}
|
|
20
|
+
/** The keys of fly controls: forward, back, left, right, up, down and sprint. */
|
|
19
21
|
export interface FlyControlsKeys3D {
|
|
20
22
|
readonly forward: readonly string[];
|
|
21
23
|
readonly back: readonly string[];
|
|
@@ -25,6 +27,7 @@ export interface FlyControlsKeys3D {
|
|
|
25
27
|
readonly down: readonly string[];
|
|
26
28
|
readonly sprint: readonly string[];
|
|
27
29
|
}
|
|
30
|
+
/** Moves a camera with the keyboard and mouse, walking or flying. */
|
|
28
31
|
export declare class FlyControls3D implements Disposable {
|
|
29
32
|
#private;
|
|
30
33
|
readonly camera: Camera3D;
|
|
@@ -51,5 +54,6 @@ export declare class FlyControls3D implements Disposable {
|
|
|
51
54
|
update(deltaSeconds: number): void;
|
|
52
55
|
dispose(): void;
|
|
53
56
|
}
|
|
57
|
+
/** Makes fly controls for a camera on an element. */
|
|
54
58
|
export declare function createFlyControls3D(camera: Camera3D, element: HTMLElement, options?: FlyControlsOptions3D): FlyControls3D;
|
|
55
59
|
//# sourceMappingURL=FlyControls3D.d.ts.map
|
|
@@ -9,6 +9,7 @@ const DEFAULT_KEYS = Object.freeze({
|
|
|
9
9
|
sprint: ['ShiftLeft', 'ShiftRight']
|
|
10
10
|
});
|
|
11
11
|
const LIMIT = Math.PI / 2 - 0.001;
|
|
12
|
+
/** Moves a camera with the keyboard and mouse, walking or flying. */
|
|
12
13
|
export class FlyControls3D {
|
|
13
14
|
camera;
|
|
14
15
|
element;
|
|
@@ -154,6 +155,7 @@ export class FlyControls3D {
|
|
|
154
155
|
this.#down.clear();
|
|
155
156
|
}
|
|
156
157
|
}
|
|
158
|
+
/** Makes fly controls for a camera on an element. */
|
|
157
159
|
export function createFlyControls3D(camera, element, options = {}) {
|
|
158
160
|
return new FlyControls3D(camera, element, options);
|
|
159
161
|
}
|