@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
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Lod3D } from './helpers3D.js';
|
|
2
|
+
import { type Material3D } from './Material3D.js';
|
|
3
|
+
import { SdfShape3D, type SdfMeshOptions3D } from './Sdf3D.js';
|
|
4
|
+
/** How a model is made in levels: the mesh options, its material, and each level's triangles and distance. */
|
|
5
|
+
export interface SdfLodOptions3D extends SdfMeshOptions3D {
|
|
6
|
+
/**
|
|
7
|
+
* Each level as [triangles, distance]: shown once the camera is at least that far. The first is the full model and
|
|
8
|
+
* its distance is 0. Unless given: the model's `triangles` (8000) up close, a quarter of them beyond 12 times the
|
|
9
|
+
* model's size, and a sixteenth beyond 30 times.
|
|
10
|
+
*/
|
|
11
|
+
readonly levels?: readonly (readonly [triangles: number, distance: number])[];
|
|
12
|
+
/** The material of every level; a standard one with vertex colours unless given. */
|
|
13
|
+
readonly material?: Material3D;
|
|
14
|
+
}
|
|
15
|
+
/** The model in levels of detail, as a Lod3D whose children are the meshes of the levels, nearest first. */
|
|
16
|
+
export declare function createSdfLod3D(shape: SdfShape3D, options?: SdfLodOptions3D): Lod3D;
|
|
17
|
+
//# sourceMappingURL=SdfLod3D.d.ts.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// A model made from a distance field in a few levels of detail: the full mesh near the camera and simpler ones further
|
|
3
|
+
// off, each simplified from the one before, so a scene of many models draws far fewer triangles. The levels share
|
|
4
|
+
// one material and switch as the camera moves, through Lod3D.
|
|
5
|
+
import { World3DError } from './core3D.js';
|
|
6
|
+
import { Lod3D } from './helpers3D.js';
|
|
7
|
+
import { createStandardMaterial3D } from './Material3D.js';
|
|
8
|
+
import { Mesh3D } from './Mesh3D.js';
|
|
9
|
+
import { createSdfGeometry3D, SdfShape3D } from './Sdf3D.js';
|
|
10
|
+
import { simplifyGeometry3D } from './Simplify3D.js';
|
|
11
|
+
function invalid(what) {
|
|
12
|
+
return new World3DError('WORLD3D_INPUT_INVALID', what);
|
|
13
|
+
}
|
|
14
|
+
/** The model in levels of detail, as a Lod3D whose children are the meshes of the levels, nearest first. */
|
|
15
|
+
export function createSdfLod3D(shape, options = {}) {
|
|
16
|
+
if (!(shape instanceof SdfShape3D))
|
|
17
|
+
throw invalid('lod shape');
|
|
18
|
+
if (options === null || typeof options !== 'object')
|
|
19
|
+
throw invalid('lod options');
|
|
20
|
+
const b = shape.bounds, size = Math.max(b[3] - b[0], b[4] - b[1], b[5] - b[2]);
|
|
21
|
+
const top = options.triangles === undefined || options.triangles === 0 ? 8000 : options.triangles;
|
|
22
|
+
const levels = options.levels ??
|
|
23
|
+
[
|
|
24
|
+
[top, 0],
|
|
25
|
+
[Math.max(64, Math.round(top / 4)), size * 12],
|
|
26
|
+
[Math.max(32, Math.round(top / 16)), size * 30]
|
|
27
|
+
];
|
|
28
|
+
if (!Array.isArray(levels) || levels.length === 0 || levels.length > 8)
|
|
29
|
+
throw invalid('lod levels');
|
|
30
|
+
let last = Infinity, lastDistance = -1;
|
|
31
|
+
for (const level of levels) {
|
|
32
|
+
if (!Array.isArray(level) || level.length !== 2)
|
|
33
|
+
throw invalid('lod level');
|
|
34
|
+
const [triangles, distance] = level;
|
|
35
|
+
if (!Number.isInteger(triangles) || triangles <= 0 || triangles >= last)
|
|
36
|
+
throw invalid('lod level triangles');
|
|
37
|
+
if (typeof distance !== 'number' || !(distance > lastDistance) || !Number.isFinite(distance))
|
|
38
|
+
throw invalid('lod level distance');
|
|
39
|
+
last = triangles;
|
|
40
|
+
lastDistance = distance;
|
|
41
|
+
}
|
|
42
|
+
if (levels[0][1] !== 0)
|
|
43
|
+
throw invalid('lod level distance');
|
|
44
|
+
const material = options.material ?? createStandardMaterial3D({ vertexColors: true, roughness: 0.75 });
|
|
45
|
+
const lod = new Lod3D();
|
|
46
|
+
let geometry = createSdfGeometry3D(shape, { ...options, triangles: levels[0][0] });
|
|
47
|
+
levels.forEach(([triangles, distance], i) => {
|
|
48
|
+
if (i > 0)
|
|
49
|
+
geometry = simplifyGeometry3D(geometry, { triangles }).geometry;
|
|
50
|
+
const mesh = new Mesh3D(geometry, material);
|
|
51
|
+
mesh.name = 'lod' + i;
|
|
52
|
+
lod.addLevel(mesh, distance);
|
|
53
|
+
});
|
|
54
|
+
return lod;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=SdfLod3D.js.map
|
|
@@ -3,14 +3,18 @@ import { Geometry3D } from './Geometry3D.js';
|
|
|
3
3
|
import { Material3D } from './Material3D.js';
|
|
4
4
|
import { Object3D } from './Object3D.js';
|
|
5
5
|
import { Texture3D } from './Texture3D.js';
|
|
6
|
+
/** The format name of a saved scene document. */
|
|
6
7
|
export declare const SCENE_DOCUMENT_FORMAT_3D = "egret.world3d.scene";
|
|
8
|
+
/** The version of the scene document format. */
|
|
7
9
|
export declare const SCENE_DOCUMENT_VERSION_3D = 1;
|
|
10
|
+
/** The most nodes, embedded texture bytes and document bytes a scene document has. */
|
|
8
11
|
export declare const SERIALIZE3D_LIMITS: Readonly<{
|
|
9
12
|
readonly maxNodes: 65536;
|
|
10
13
|
readonly maxEmbeddedTextureBytes: 1048576;
|
|
11
14
|
readonly maxDocumentBytes: 268435456;
|
|
12
15
|
}>;
|
|
13
16
|
type Json = Record<string, any>;
|
|
17
|
+
/** A scene saved as JSON: its nodes, geometries, materials, textures and skeletons, and what was skipped. */
|
|
14
18
|
export interface SceneDocument3D {
|
|
15
19
|
readonly format: typeof SCENE_DOCUMENT_FORMAT_3D;
|
|
16
20
|
readonly version: number;
|
|
@@ -23,14 +27,27 @@ export interface SceneDocument3D {
|
|
|
23
27
|
/** Names of nodes that were written as plain objects because their type cannot be saved. */
|
|
24
28
|
readonly skipped: readonly string[];
|
|
25
29
|
}
|
|
30
|
+
/** How a scene is saved: the key each texture is saved by. */
|
|
26
31
|
export interface SerializeOptions3D {
|
|
27
32
|
/** Stable key for a texture that should be stored by reference, such as its asset id. */
|
|
28
33
|
readonly textureKey?: (texture: Texture3D) => string | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Stable key for a geometry the game can make again, such as the name of a model it builds in code: the geometry is
|
|
36
|
+
* then saved as that key alone, not as all its vertices. Undefined, or an empty string, saves it whole.
|
|
37
|
+
*/
|
|
38
|
+
readonly geometryKey?: (geometry: Geometry3D) => string | undefined;
|
|
29
39
|
}
|
|
40
|
+
/** How a scene is loaded back: how each texture key is turned into a texture. */
|
|
30
41
|
export interface DeserializeOptions3D {
|
|
31
42
|
/** Return the texture for a key written by `textureKey`. */
|
|
32
43
|
readonly resolveTexture?: (key: string) => Texture3D | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Return the geometry for a key written by `geometryKey`. It stays the game's: disposing the loaded scene leaves it.
|
|
46
|
+
* A key with no geometry gives an empty one, so the rest of the scene still loads.
|
|
47
|
+
*/
|
|
48
|
+
readonly resolveGeometry?: (key: string) => Geometry3D | undefined;
|
|
33
49
|
}
|
|
50
|
+
/** A scene loaded back: its root, cameras, geometries, materials and textures. */
|
|
34
51
|
export interface DeserializedScene3D {
|
|
35
52
|
readonly root: Object3D;
|
|
36
53
|
readonly cameras: readonly Camera3D[];
|
|
@@ -14,8 +14,11 @@ import { Bone3D, InstancedMesh3D, Mesh3D, Skeleton3D } from './Mesh3D.js';
|
|
|
14
14
|
import { Object3D, Scene3D } from './Object3D.js';
|
|
15
15
|
import { ParticleEmitter3D } from './Particles3D.js';
|
|
16
16
|
import { RenderTarget3D, Texture3D, isCompressedPixels3D, isTexturePixels3D } from './Texture3D.js';
|
|
17
|
+
/** The format name of a saved scene document. */
|
|
17
18
|
export const SCENE_DOCUMENT_FORMAT_3D = 'egret.world3d.scene';
|
|
19
|
+
/** The version of the scene document format. */
|
|
18
20
|
export const SCENE_DOCUMENT_VERSION_3D = 1;
|
|
21
|
+
/** The most nodes, embedded texture bytes and document bytes a scene document has. */
|
|
19
22
|
export const SERIALIZE3D_LIMITS = Object.freeze({
|
|
20
23
|
maxNodes: 65536,
|
|
21
24
|
maxEmbeddedTextureBytes: 1048576,
|
|
@@ -218,6 +221,12 @@ export function serializeScene3D(root, options = {}) {
|
|
|
218
221
|
const known = geometryIds.get(value);
|
|
219
222
|
if (known !== undefined)
|
|
220
223
|
return known;
|
|
224
|
+
const key = options.geometryKey?.(value);
|
|
225
|
+
if (typeof key === 'string' && key.length > 0) {
|
|
226
|
+
geometryIds.set(value, geometries.length);
|
|
227
|
+
geometries.push({ key });
|
|
228
|
+
return geometries.length - 1;
|
|
229
|
+
}
|
|
221
230
|
const attributes = {};
|
|
222
231
|
for (const [name, attribute] of value.attributes)
|
|
223
232
|
attributes[name] = {
|
|
@@ -435,6 +444,19 @@ export function deserializeScene3D(saved, options = {}) {
|
|
|
435
444
|
material[field] = textures[entry[field]];
|
|
436
445
|
}
|
|
437
446
|
for (const entry of doc['geometries']) {
|
|
447
|
+
if (typeof entry['key'] === 'string') {
|
|
448
|
+
const resolved = options.resolveGeometry?.(entry['key']);
|
|
449
|
+
if (resolved instanceof Geometry3D) {
|
|
450
|
+
geometries.push(resolved);
|
|
451
|
+
continue;
|
|
452
|
+
}
|
|
453
|
+
// A missing reference gives an empty geometry instead of failing the whole scene.
|
|
454
|
+
const empty = new Geometry3D();
|
|
455
|
+
empty.name = entry['key'];
|
|
456
|
+
created.push(empty);
|
|
457
|
+
geometries.push(empty);
|
|
458
|
+
continue;
|
|
459
|
+
}
|
|
438
460
|
const geometry = new Geometry3D();
|
|
439
461
|
created.push(geometry);
|
|
440
462
|
geometries.push(geometry);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Geometry3D } from './Geometry3D.js';
|
|
2
|
+
/** How far to simplify. */
|
|
3
|
+
export interface SimplifyOptions3D {
|
|
4
|
+
/** Stop at this many triangles or fewer. */
|
|
5
|
+
readonly triangles?: number;
|
|
6
|
+
/** Or keep this share of the triangles, from 0 to 1. Ignored when `triangles` is given. */
|
|
7
|
+
readonly ratio?: number;
|
|
8
|
+
/**
|
|
9
|
+
* Never move the surface further than this, in the model's units, even short of the target: the target is then
|
|
10
|
+
* not reached. No limit unless given.
|
|
11
|
+
*/
|
|
12
|
+
readonly maxError?: number;
|
|
13
|
+
}
|
|
14
|
+
/** How a simplification went. */
|
|
15
|
+
export interface SimplifyResult3D {
|
|
16
|
+
readonly geometry: Geometry3D;
|
|
17
|
+
/** Triangles before and after. */
|
|
18
|
+
readonly before: number;
|
|
19
|
+
readonly after: number;
|
|
20
|
+
/** The largest distance, in the model's units, a collapse moved the surface by. */
|
|
21
|
+
readonly error: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A copy of an indexed triangle geometry with fewer triangles; the geometry given is not changed. Groups (one material per range) are kept;
|
|
25
|
+
* geometries with morph targets are refused. Vertices that sit
|
|
26
|
+
* on an open edge (a hole, or a texture seam where vertices are split) are kept in place.
|
|
27
|
+
*/
|
|
28
|
+
export declare function simplifyGeometry3D(geometry: Geometry3D, options?: SimplifyOptions3D): SimplifyResult3D;
|
|
29
|
+
//# sourceMappingURL=Simplify3D.d.ts.map
|
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Fewer triangles for the same shape: a model made in code, a scanned or generated asset, a far version for a level
|
|
3
|
+
// of detail. Edges are collapsed one by one, cheapest first, where the cost of a collapse is how far the kept vertex
|
|
4
|
+
// lies from the planes of the triangles around both ends (the quadric error metric of Garland and Heckbert, 1997).
|
|
5
|
+
// A collapse that would turn a triangle over, pinch the surface or move an open edge is refused. With vertex colours
|
|
6
|
+
// the quadrics take in colour as well (Garland and Heckbert, 1998), so painted edges stay. Each kept vertex keeps its own normal, colour and texture
|
|
7
|
+
// coordinates, so seams and painted parts stay where they were.
|
|
8
|
+
import { World3DError } from './core3D.js';
|
|
9
|
+
import { Attribute3D, Geometry3D } from './Geometry3D.js';
|
|
10
|
+
function invalid(what) {
|
|
11
|
+
return new World3DError('WORLD3D_INPUT_INVALID', what);
|
|
12
|
+
}
|
|
13
|
+
class Heap {
|
|
14
|
+
cost = [];
|
|
15
|
+
a = [];
|
|
16
|
+
b = [];
|
|
17
|
+
stamp = [];
|
|
18
|
+
get size() {
|
|
19
|
+
return this.cost.length;
|
|
20
|
+
}
|
|
21
|
+
push(cost, a, b, stamp) {
|
|
22
|
+
let i = this.cost.length;
|
|
23
|
+
this.cost.push(cost);
|
|
24
|
+
this.a.push(a);
|
|
25
|
+
this.b.push(b);
|
|
26
|
+
this.stamp.push(stamp);
|
|
27
|
+
while (i > 0) {
|
|
28
|
+
const p = (i - 1) >> 1;
|
|
29
|
+
if (this.cost[p] <= cost)
|
|
30
|
+
break;
|
|
31
|
+
this.#swap(i, p);
|
|
32
|
+
i = p;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
pop() {
|
|
36
|
+
const top = [this.cost[0], this.a[0], this.b[0], this.stamp[0]];
|
|
37
|
+
const last = this.cost.length - 1;
|
|
38
|
+
this.#swap(0, last);
|
|
39
|
+
this.cost.pop();
|
|
40
|
+
this.a.pop();
|
|
41
|
+
this.b.pop();
|
|
42
|
+
this.stamp.pop();
|
|
43
|
+
let i = 0;
|
|
44
|
+
for (;;) {
|
|
45
|
+
const l = i * 2 + 1, r = l + 1;
|
|
46
|
+
let m = i;
|
|
47
|
+
if (l < this.cost.length && this.cost[l] < this.cost[m])
|
|
48
|
+
m = l;
|
|
49
|
+
if (r < this.cost.length && this.cost[r] < this.cost[m])
|
|
50
|
+
m = r;
|
|
51
|
+
if (m === i)
|
|
52
|
+
break;
|
|
53
|
+
this.#swap(i, m);
|
|
54
|
+
i = m;
|
|
55
|
+
}
|
|
56
|
+
return top;
|
|
57
|
+
}
|
|
58
|
+
#swap(i, j) {
|
|
59
|
+
for (const list of [this.cost, this.a, this.b, this.stamp]) {
|
|
60
|
+
const t = list[i];
|
|
61
|
+
list[i] = list[j];
|
|
62
|
+
list[j] = t;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* A copy of an indexed triangle geometry with fewer triangles; the geometry given is not changed. Groups (one material per range) are kept;
|
|
68
|
+
* geometries with morph targets are refused. Vertices that sit
|
|
69
|
+
* on an open edge (a hole, or a texture seam where vertices are split) are kept in place.
|
|
70
|
+
*/
|
|
71
|
+
export function simplifyGeometry3D(geometry, options = {}) {
|
|
72
|
+
if (!(geometry instanceof Geometry3D))
|
|
73
|
+
throw invalid('simplify geometry');
|
|
74
|
+
if (geometry.topology !== 'triangles')
|
|
75
|
+
throw invalid('simplify topology');
|
|
76
|
+
// Morph targets move vertices a collapse would join.
|
|
77
|
+
if (geometry.morphTargets.length > 0)
|
|
78
|
+
throw invalid('simplify morph targets');
|
|
79
|
+
if (options === null || typeof options !== 'object')
|
|
80
|
+
throw invalid('simplify options');
|
|
81
|
+
const position = geometry.getAttribute('position');
|
|
82
|
+
if (!position || position.itemSize !== 3)
|
|
83
|
+
throw invalid('simplify positions');
|
|
84
|
+
const P = position.data;
|
|
85
|
+
const n = P.length / 3;
|
|
86
|
+
const source = geometry.index ? Array.from(geometry.index.data) : Array.from({ length: n }, (_, i) => i);
|
|
87
|
+
if (source.length % 3 !== 0)
|
|
88
|
+
throw invalid('simplify indices');
|
|
89
|
+
const faces = source.length / 3;
|
|
90
|
+
let target;
|
|
91
|
+
if (options.triangles !== undefined) {
|
|
92
|
+
if (!Number.isInteger(options.triangles) || options.triangles < 0)
|
|
93
|
+
throw invalid('simplify triangles');
|
|
94
|
+
target = options.triangles;
|
|
95
|
+
}
|
|
96
|
+
else if (options.ratio !== undefined) {
|
|
97
|
+
if (typeof options.ratio !== 'number' || !(options.ratio >= 0 && options.ratio <= 1))
|
|
98
|
+
throw invalid('simplify ratio');
|
|
99
|
+
target = Math.floor(faces * options.ratio);
|
|
100
|
+
}
|
|
101
|
+
else
|
|
102
|
+
target = Math.floor(faces / 2);
|
|
103
|
+
let maxError = Infinity;
|
|
104
|
+
if (options.maxError !== undefined) {
|
|
105
|
+
if (typeof options.maxError !== 'number' || !(options.maxError >= 0))
|
|
106
|
+
throw invalid('simplify maxError');
|
|
107
|
+
maxError = options.maxError;
|
|
108
|
+
}
|
|
109
|
+
const F = Int32Array.from(source);
|
|
110
|
+
// The material of each triangle, from the groups: a collapse never changes it.
|
|
111
|
+
const groupOf = new Int32Array(faces).fill(-1);
|
|
112
|
+
for (const group of geometry.groups)
|
|
113
|
+
for (let i = Math.floor(group.start / 3); i < Math.min(faces, Math.floor((group.start + group.count) / 3)); i++)
|
|
114
|
+
groupOf[i] = group.materialIndex;
|
|
115
|
+
const alive = new Uint8Array(faces).fill(1);
|
|
116
|
+
const vertexFaces = Array.from({ length: n }, () => []);
|
|
117
|
+
for (let f = 0; f < faces; f++)
|
|
118
|
+
for (let c = 0; c < 3; c++)
|
|
119
|
+
vertexFaces[F[f * 3 + c]].push(f);
|
|
120
|
+
// Open edges: an edge used by one triangle only. Their vertices stay.
|
|
121
|
+
const edgeUse = new Map();
|
|
122
|
+
const key = (a, b) => (a < b ? a * n + b : b * n + a);
|
|
123
|
+
for (let f = 0; f < faces; f++)
|
|
124
|
+
for (let c = 0; c < 3; c++) {
|
|
125
|
+
const k = key(F[f * 3 + c], F[f * 3 + ((c + 1) % 3)]);
|
|
126
|
+
edgeUse.set(k, (edgeUse.get(k) ?? 0) + 1);
|
|
127
|
+
}
|
|
128
|
+
const locked = new Uint8Array(n);
|
|
129
|
+
for (let f = 0; f < faces; f++)
|
|
130
|
+
for (let c = 0; c < 3; c++) {
|
|
131
|
+
const a = F[f * 3 + c], b = F[f * 3 + ((c + 1) % 3)];
|
|
132
|
+
if (edgeUse.get(key(a, b)) !== 1)
|
|
133
|
+
continue;
|
|
134
|
+
locked[a] = 1;
|
|
135
|
+
locked[b] = 1;
|
|
136
|
+
}
|
|
137
|
+
// One quadric per vertex: the sum of the squared distances to the planes of its triangles, area-weighted.
|
|
138
|
+
const Q = new Float64Array(n * 10);
|
|
139
|
+
const addPlane = (v, a, b, c, d, w) => {
|
|
140
|
+
const q = v * 10;
|
|
141
|
+
Q[q] = Q[q] + w * a * a;
|
|
142
|
+
Q[q + 1] = Q[q + 1] + w * a * b;
|
|
143
|
+
Q[q + 2] = Q[q + 2] + w * a * c;
|
|
144
|
+
Q[q + 3] = Q[q + 3] + w * a * d;
|
|
145
|
+
Q[q + 4] = Q[q + 4] + w * b * b;
|
|
146
|
+
Q[q + 5] = Q[q + 5] + w * b * c;
|
|
147
|
+
Q[q + 6] = Q[q + 6] + w * b * d;
|
|
148
|
+
Q[q + 7] = Q[q + 7] + w * c * c;
|
|
149
|
+
Q[q + 8] = Q[q + 8] + w * c * d;
|
|
150
|
+
Q[q + 9] = Q[q + 9] + w * d * d;
|
|
151
|
+
};
|
|
152
|
+
const faceNormal = (i0, i1, i2) => {
|
|
153
|
+
const ux = P[i1 * 3] - P[i0 * 3], uy = P[i1 * 3 + 1] - P[i0 * 3 + 1], uz = P[i1 * 3 + 2] - P[i0 * 3 + 2];
|
|
154
|
+
const vx = P[i2 * 3] - P[i0 * 3], vy = P[i2 * 3 + 1] - P[i0 * 3 + 1], vz = P[i2 * 3 + 2] - P[i0 * 3 + 2];
|
|
155
|
+
const x = uy * vz - uz * vy, y = uz * vx - ux * vz, z = ux * vy - uy * vx;
|
|
156
|
+
const l = Math.hypot(x, y, z);
|
|
157
|
+
return l > 0 ? [x / l, y / l, z / l, l / 2] : [0, 0, 0, 0];
|
|
158
|
+
};
|
|
159
|
+
for (let f = 0; f < faces; f++) {
|
|
160
|
+
const i0 = F[f * 3], i1 = F[f * 3 + 1], i2 = F[f * 3 + 2];
|
|
161
|
+
const [a, b, c, area] = faceNormal(i0, i1, i2);
|
|
162
|
+
if (area === 0)
|
|
163
|
+
continue;
|
|
164
|
+
const d = -(a * P[i0 * 3] + b * P[i0 * 3 + 1] + c * P[i0 * 3 + 2]);
|
|
165
|
+
for (const v of [i0, i1, i2])
|
|
166
|
+
addPlane(v, a, b, c, d, area);
|
|
167
|
+
}
|
|
168
|
+
const errorAt = (q, r, v) => {
|
|
169
|
+
// The quadric of q plus that of r, at the position of v.
|
|
170
|
+
const x = P[v * 3], y = P[v * 3 + 1], z = P[v * 3 + 2];
|
|
171
|
+
const s = (i) => Q[q * 10 + i] + Q[r * 10 + i];
|
|
172
|
+
return Math.max(0, s(0) * x * x +
|
|
173
|
+
2 * s(1) * x * y +
|
|
174
|
+
2 * s(2) * x * z +
|
|
175
|
+
2 * s(3) * x +
|
|
176
|
+
s(4) * y * y +
|
|
177
|
+
2 * s(5) * y * z +
|
|
178
|
+
2 * s(6) * y +
|
|
179
|
+
s(7) * z * z +
|
|
180
|
+
2 * s(8) * z +
|
|
181
|
+
s(9));
|
|
182
|
+
};
|
|
183
|
+
const areaOf = new Float64Array(n);
|
|
184
|
+
for (let f = 0; f < faces; f++) {
|
|
185
|
+
const area = faceNormal(F[f * 3], F[f * 3 + 1], F[f * 3 + 2])[3];
|
|
186
|
+
for (let c = 0; c < 3; c++) {
|
|
187
|
+
const v = F[f * 3 + c];
|
|
188
|
+
areaOf[v] = areaOf[v] + area;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// The quadric error is an area-weighted squared distance; this turns it back into a distance.
|
|
192
|
+
const distanceOf = (cost, u, v) => Math.sqrt(cost / Math.max(areaOf[u] + areaOf[v], 1e-30));
|
|
193
|
+
const stamp = new Int32Array(n);
|
|
194
|
+
const heap = new Heap();
|
|
195
|
+
let colorCostOf;
|
|
196
|
+
// The cost of moving u onto v, Infinity when u may not move.
|
|
197
|
+
// Vertex colours count too, through a quadric over position and colour together (Garland and Heckbert, 1998): each
|
|
198
|
+
// triangle is a plane in six dimensions, and a collapse that drags a vertex of one colour across a stripe of
|
|
199
|
+
// another costs as much as moving the surface by a tenth of the model's size for a full change of colour. Painted
|
|
200
|
+
// edges then keep their line, and the triangles around them do not stretch across.
|
|
201
|
+
const colors = geometry.getAttribute('color');
|
|
202
|
+
const C = colors !== undefined && colors.itemSize >= 3 ? colors.data : undefined, cs = colors?.itemSize ?? 0;
|
|
203
|
+
const D = 6, W6 = D * D + D + 1;
|
|
204
|
+
const Q6 = C === undefined ? undefined : new Float64Array(n * W6);
|
|
205
|
+
if (C !== undefined && Q6 !== undefined) {
|
|
206
|
+
let x0 = Infinity, x1 = -Infinity, y0 = Infinity, y1 = -Infinity, z0 = Infinity, z1 = -Infinity;
|
|
207
|
+
for (let i = 0; i < n; i++) {
|
|
208
|
+
x0 = Math.min(x0, P[i * 3]);
|
|
209
|
+
x1 = Math.max(x1, P[i * 3]);
|
|
210
|
+
y0 = Math.min(y0, P[i * 3 + 1]);
|
|
211
|
+
y1 = Math.max(y1, P[i * 3 + 1]);
|
|
212
|
+
z0 = Math.min(z0, P[i * 3 + 2]);
|
|
213
|
+
z1 = Math.max(z1, P[i * 3 + 2]);
|
|
214
|
+
}
|
|
215
|
+
const scale = Math.hypot(x1 - x0, y1 - y0, z1 - z0) / 10;
|
|
216
|
+
const point = (v, out) => {
|
|
217
|
+
out[0] = P[v * 3];
|
|
218
|
+
out[1] = P[v * 3 + 1];
|
|
219
|
+
out[2] = P[v * 3 + 2];
|
|
220
|
+
for (let c = 0; c < 3; c++)
|
|
221
|
+
out[3 + c] = C[v * cs + c] * scale;
|
|
222
|
+
};
|
|
223
|
+
const p = new Float64Array(D), q = new Float64Array(D), r = new Float64Array(D), e1 = new Float64Array(D), e2 = new Float64Array(D);
|
|
224
|
+
const dot = (a, b) => {
|
|
225
|
+
let sum = 0;
|
|
226
|
+
for (let i = 0; i < D; i++)
|
|
227
|
+
sum += a[i] * b[i];
|
|
228
|
+
return sum;
|
|
229
|
+
};
|
|
230
|
+
for (let f = 0; f < faces; f++) {
|
|
231
|
+
const i0 = F[f * 3], i1 = F[f * 3 + 1], i2 = F[f * 3 + 2];
|
|
232
|
+
const area = faceNormal(i0, i1, i2)[3];
|
|
233
|
+
if (area === 0)
|
|
234
|
+
continue;
|
|
235
|
+
point(i0, p);
|
|
236
|
+
point(i1, q);
|
|
237
|
+
point(i2, r);
|
|
238
|
+
for (let i = 0; i < D; i++)
|
|
239
|
+
e1[i] = q[i] - p[i];
|
|
240
|
+
const l1 = Math.sqrt(dot(e1, e1));
|
|
241
|
+
if (l1 === 0)
|
|
242
|
+
continue;
|
|
243
|
+
for (let i = 0; i < D; i++)
|
|
244
|
+
e1[i] = e1[i] / l1;
|
|
245
|
+
for (let i = 0; i < D; i++)
|
|
246
|
+
e2[i] = r[i] - p[i];
|
|
247
|
+
const along = dot(e1, e2);
|
|
248
|
+
for (let i = 0; i < D; i++)
|
|
249
|
+
e2[i] = e2[i] - along * e1[i];
|
|
250
|
+
const l2 = Math.sqrt(dot(e2, e2));
|
|
251
|
+
if (l2 === 0)
|
|
252
|
+
continue;
|
|
253
|
+
for (let i = 0; i < D; i++)
|
|
254
|
+
e2[i] = e2[i] / l2;
|
|
255
|
+
const p1 = dot(p, e1), p2 = dot(p, e2);
|
|
256
|
+
for (const v of [i0, i1, i2]) {
|
|
257
|
+
const o = v * W6;
|
|
258
|
+
for (let i = 0; i < D; i++)
|
|
259
|
+
for (let j = 0; j < D; j++)
|
|
260
|
+
Q6[o + i * D + j] = Q6[o + i * D + j] + area * ((i === j ? 1 : 0) - e1[i] * e1[j] - e2[i] * e2[j]);
|
|
261
|
+
for (let i = 0; i < D; i++)
|
|
262
|
+
Q6[o + D * D + i] = Q6[o + D * D + i] + area * (p1 * e1[i] + p2 * e2[i] - p[i]);
|
|
263
|
+
Q6[o + D * D + D] = Q6[o + D * D + D] + area * (dot(p, p) - p1 * p1 - p2 * p2);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
// The point of a vertex is fixed now: keep it to price a collapse onto it.
|
|
267
|
+
const points6 = new Float64Array(n * D);
|
|
268
|
+
for (let v = 0; v < n; v++) {
|
|
269
|
+
point(v, p);
|
|
270
|
+
points6.set(p, v * D);
|
|
271
|
+
}
|
|
272
|
+
colorCostOf = (u, v) => {
|
|
273
|
+
let sum = 0;
|
|
274
|
+
const a = u * W6, b = v * W6, x = v * D;
|
|
275
|
+
for (let i = 0; i < D; i++) {
|
|
276
|
+
const xi = points6[x + i];
|
|
277
|
+
let row = 0;
|
|
278
|
+
for (let j = 0; j < D; j++)
|
|
279
|
+
row += (Q6[a + i * D + j] + Q6[b + i * D + j]) * points6[x + j];
|
|
280
|
+
sum += xi * row + 2 * (Q6[a + D * D + i] + Q6[b + D * D + i]) * xi;
|
|
281
|
+
}
|
|
282
|
+
return Math.max(0, sum + Q6[a + D * D + D] + Q6[b + D * D + D]);
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
const costOf = (u, v) => locked[u] ? Infinity : colorCostOf === undefined ? errorAt(u, v, v) : colorCostOf(u, v);
|
|
286
|
+
const offer = (a, b) => {
|
|
287
|
+
const ab = costOf(a, b), ba = costOf(b, a);
|
|
288
|
+
if (ab === Infinity && ba === Infinity)
|
|
289
|
+
return;
|
|
290
|
+
if (ab <= ba)
|
|
291
|
+
heap.push(ab, a, b, stamp[a] + stamp[b] * 65536);
|
|
292
|
+
else
|
|
293
|
+
heap.push(ba, b, a, stamp[a] + stamp[b] * 65536);
|
|
294
|
+
};
|
|
295
|
+
for (let f = 0; f < faces; f++)
|
|
296
|
+
for (let c = 0; c < 3; c++) {
|
|
297
|
+
const a = F[f * 3 + c], b = F[f * 3 + ((c + 1) % 3)];
|
|
298
|
+
if (a < b)
|
|
299
|
+
offer(a, b);
|
|
300
|
+
else if (edgeUse.get(key(a, b)) === 1)
|
|
301
|
+
offer(b, a);
|
|
302
|
+
}
|
|
303
|
+
const neighbours = (v) => {
|
|
304
|
+
const out = new Set();
|
|
305
|
+
for (const f of vertexFaces[v])
|
|
306
|
+
if (alive[f])
|
|
307
|
+
for (let c = 0; c < 3; c++)
|
|
308
|
+
out.add(F[f * 3 + c]);
|
|
309
|
+
out.delete(v);
|
|
310
|
+
return out;
|
|
311
|
+
};
|
|
312
|
+
let live = faces, worst = 0;
|
|
313
|
+
while (live > target && heap.size > 0) {
|
|
314
|
+
const [cost, u, v, s] = heap.pop();
|
|
315
|
+
const a = Math.min(u, v), b = Math.max(u, v);
|
|
316
|
+
if (s !== stamp[a] + stamp[b] * 65536)
|
|
317
|
+
continue;
|
|
318
|
+
if (cost === Infinity)
|
|
319
|
+
break;
|
|
320
|
+
// The heap orders by shape and colour together; the distance the surface moves is the shape's part alone.
|
|
321
|
+
const moved = distanceOf(errorAt(u, v, v), u, v);
|
|
322
|
+
if (moved > maxError)
|
|
323
|
+
break;
|
|
324
|
+
// The edge must still be there, and the two ends must share exactly the two vertices across the edge.
|
|
325
|
+
const nu = neighbours(u);
|
|
326
|
+
if (!nu.has(v))
|
|
327
|
+
continue;
|
|
328
|
+
const nv = neighbours(v);
|
|
329
|
+
let shared = 0;
|
|
330
|
+
for (const w of nu)
|
|
331
|
+
if (nv.has(w))
|
|
332
|
+
shared++;
|
|
333
|
+
if (shared !== 2)
|
|
334
|
+
continue;
|
|
335
|
+
// No triangle of u that stays may turn over or become a sliver.
|
|
336
|
+
let flips = false;
|
|
337
|
+
for (const f of vertexFaces[u]) {
|
|
338
|
+
if (!alive[f])
|
|
339
|
+
continue;
|
|
340
|
+
const i0 = F[f * 3], i1 = F[f * 3 + 1], i2 = F[f * 3 + 2];
|
|
341
|
+
if (i0 === v || i1 === v || i2 === v)
|
|
342
|
+
continue;
|
|
343
|
+
const before = faceNormal(i0, i1, i2);
|
|
344
|
+
const after = faceNormal(i0 === u ? v : i0, i1 === u ? v : i1, i2 === u ? v : i2);
|
|
345
|
+
if (after[3] === 0 || before[0] * after[0] + before[1] * after[1] + before[2] * after[2] < 0.3) {
|
|
346
|
+
flips = true;
|
|
347
|
+
break;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
if (flips)
|
|
351
|
+
continue;
|
|
352
|
+
for (const f of vertexFaces[u]) {
|
|
353
|
+
if (!alive[f])
|
|
354
|
+
continue;
|
|
355
|
+
let hasV = false;
|
|
356
|
+
for (let c = 0; c < 3; c++)
|
|
357
|
+
if (F[f * 3 + c] === v)
|
|
358
|
+
hasV = true;
|
|
359
|
+
if (hasV) {
|
|
360
|
+
alive[f] = 0;
|
|
361
|
+
live--;
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
for (let c = 0; c < 3; c++)
|
|
365
|
+
if (F[f * 3 + c] === u)
|
|
366
|
+
F[f * 3 + c] = v;
|
|
367
|
+
vertexFaces[v].push(f);
|
|
368
|
+
}
|
|
369
|
+
vertexFaces[u] = [];
|
|
370
|
+
for (let i = 0; i < 10; i++)
|
|
371
|
+
Q[v * 10 + i] = Q[v * 10 + i] + Q[u * 10 + i];
|
|
372
|
+
if (Q6 !== undefined)
|
|
373
|
+
for (let i = 0; i < W6; i++)
|
|
374
|
+
Q6[v * W6 + i] = Q6[v * W6 + i] + Q6[u * W6 + i];
|
|
375
|
+
areaOf[v] = areaOf[v] + areaOf[u];
|
|
376
|
+
if (moved > worst)
|
|
377
|
+
worst = moved;
|
|
378
|
+
stamp[v] = stamp[v] + 1;
|
|
379
|
+
stamp[u] = stamp[u] + 1;
|
|
380
|
+
vertexFaces[v] = vertexFaces[v].filter(f => alive[f]);
|
|
381
|
+
for (const w of neighbours(v))
|
|
382
|
+
offer(v, w);
|
|
383
|
+
}
|
|
384
|
+
// Keep the vertices still used, in their first order, with every attribute they had.
|
|
385
|
+
const remap = new Int32Array(n).fill(-1);
|
|
386
|
+
const order = [];
|
|
387
|
+
const indices = [];
|
|
388
|
+
const order3 = Array.from({ length: faces }, (_, f) => f).filter(f => alive[f] === 1);
|
|
389
|
+
if (geometry.groups.length > 0)
|
|
390
|
+
order3.sort((a, b) => groupOf[a] - groupOf[b] || a - b);
|
|
391
|
+
for (const f of order3) {
|
|
392
|
+
for (let c = 0; c < 3; c++) {
|
|
393
|
+
const v = F[f * 3 + c];
|
|
394
|
+
if (remap[v] === -1) {
|
|
395
|
+
remap[v] = order.length;
|
|
396
|
+
order.push(v);
|
|
397
|
+
}
|
|
398
|
+
indices.push(remap[v]);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
const out = new Geometry3D();
|
|
402
|
+
out.topology = 'triangles';
|
|
403
|
+
for (const [name, attribute] of geometry.attributes) {
|
|
404
|
+
const size = attribute.itemSize, data = attribute.data;
|
|
405
|
+
const copy = new data.constructor(order.length * size);
|
|
406
|
+
for (let i = 0; i < order.length; i++)
|
|
407
|
+
for (let c = 0; c < size; c++)
|
|
408
|
+
copy[i * size + c] = data[order[i] * size + c];
|
|
409
|
+
out.setAttribute(name, new Attribute3D(copy, size, attribute.normalized));
|
|
410
|
+
}
|
|
411
|
+
out.setIndex(order.length > 65535 ? Uint32Array.from(indices) : Uint16Array.from(indices));
|
|
412
|
+
if (geometry.groups.length > 0) {
|
|
413
|
+
let start = 0;
|
|
414
|
+
while (start < order3.length) {
|
|
415
|
+
let end = start;
|
|
416
|
+
while (end < order3.length && groupOf[order3[end]] === groupOf[order3[start]])
|
|
417
|
+
end++;
|
|
418
|
+
const material = groupOf[order3[start]];
|
|
419
|
+
if (material >= 0)
|
|
420
|
+
out.addGroup(start * 3, (end - start) * 3, material);
|
|
421
|
+
start = end;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
return { geometry: out, before: faces, after: live, error: worst };
|
|
425
|
+
}
|
|
426
|
+
//# sourceMappingURL=Simplify3D.js.map
|
|
@@ -1,23 +1,29 @@
|
|
|
1
1
|
import { AnimationMixer3D } from './Animation3D.js';
|
|
2
2
|
import type { AnimationClip3D } from './Animation3D.js';
|
|
3
|
+
/** The most states and transitions a state machine has, and how many transitions it takes in one update. */
|
|
3
4
|
export declare const STATE_MACHINE3D_LIMITS: Readonly<{
|
|
4
5
|
readonly maxStates: 256;
|
|
5
6
|
readonly maxTransitions: 2048;
|
|
6
7
|
readonly maxTransitionsPerUpdate: 8;
|
|
7
8
|
}>;
|
|
9
|
+
/** The value of a state machine parameter. */
|
|
8
10
|
export type StateParameter3D = number | boolean;
|
|
11
|
+
/** How a condition compares a parameter with its value. */
|
|
9
12
|
export type StateConditionOperator3D = '>' | '>=' | '<' | '<=' | '==' | '!=';
|
|
13
|
+
/** A condition of a transition: a parameter compared with a value. */
|
|
10
14
|
export interface StateCondition3D {
|
|
11
15
|
readonly parameter: string;
|
|
12
16
|
/** Comparison against `value`. Omit both to test a boolean or a trigger for true. */
|
|
13
17
|
readonly op?: StateConditionOperator3D;
|
|
14
18
|
readonly value?: StateParameter3D;
|
|
15
19
|
}
|
|
20
|
+
/** One clip of a blend state and the parameter value it shows at. */
|
|
16
21
|
export interface StateBlendEntry3D {
|
|
17
22
|
readonly clip: AnimationClip3D;
|
|
18
23
|
/** Parameter value at which this clip plays alone. */
|
|
19
24
|
readonly threshold: number;
|
|
20
25
|
}
|
|
26
|
+
/** A state to add: its clip or blend, whether it loops, its speed, and what it calls on entering and leaving. */
|
|
21
27
|
export interface StateOptions3D {
|
|
22
28
|
/** A single clip, or omit it and give `blend`. */
|
|
23
29
|
readonly clip?: AnimationClip3D;
|
|
@@ -32,6 +38,7 @@ export interface StateOptions3D {
|
|
|
32
38
|
readonly onEnter?: () => void;
|
|
33
39
|
readonly onExit?: () => void;
|
|
34
40
|
}
|
|
41
|
+
/** A transition to add: from and to which state, how long it fades, its conditions, its exit time and whether it can be interrupted. */
|
|
35
42
|
export interface TransitionOptions3D {
|
|
36
43
|
/** Source state, or '*' for any state. */
|
|
37
44
|
readonly from: string;
|
|
@@ -45,6 +52,7 @@ export interface TransitionOptions3D {
|
|
|
45
52
|
/** Allow this transition to start while another fade is still running. Defaults to true. */
|
|
46
53
|
readonly canInterrupt?: boolean;
|
|
47
54
|
}
|
|
55
|
+
/** Plays clips by state, moving between states when their conditions are met. */
|
|
48
56
|
export declare class AnimationStateMachine3D {
|
|
49
57
|
#private;
|
|
50
58
|
readonly mixer: AnimationMixer3D;
|
|
@@ -74,5 +82,6 @@ export declare class AnimationStateMachine3D {
|
|
|
74
82
|
/** Evaluate transitions, advance fades and drive the mixer by `deltaSeconds`. */
|
|
75
83
|
update(deltaSeconds: number): void;
|
|
76
84
|
}
|
|
85
|
+
/** Makes an animation state machine that drives a mixer. */
|
|
77
86
|
export declare function createAnimationStateMachine3D(mixer: AnimationMixer3D): AnimationStateMachine3D;
|
|
78
87
|
//# sourceMappingURL=StateMachine3D.d.ts.map
|