@egret/engine 0.0.0-stage → 7.0.1-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/NOTICE +21 -0
- package/README.md +101 -2
- package/README.zh-CN.md +102 -0
- package/dist/Engine.d.ts +77 -0
- package/dist/Engine.js +464 -0
- package/dist/animation/index.d.ts +6 -0
- package/dist/animation/index.js +5 -0
- package/dist/animation/sequenceController.d.ts +22 -0
- package/dist/animation/sequenceController.js +618 -0
- package/dist/animation/sequenceCoordinator.d.ts +26 -0
- package/dist/animation/sequenceCoordinator.js +161 -0
- package/dist/animation/sequenceInput.d.ts +25 -0
- package/dist/animation/sequenceInput.js +108 -0
- package/dist/animation/sequenceMath.d.ts +35 -0
- package/dist/animation/sequenceMath.js +164 -0
- package/dist/animation/sequenceResetSlot.d.ts +7 -0
- package/dist/animation/sequenceResetSlot.js +367 -0
- package/dist/animation/sequenceResetTypes.d.ts +42 -0
- package/dist/animation/sequenceResetTypes.js +2 -0
- package/dist/animation/types.d.ts +69 -0
- package/dist/animation/types.js +2 -0
- package/dist/assetBundle.d.ts +52 -0
- package/dist/assetBundle.js +173 -0
- package/dist/assetGroup.d.ts +17 -0
- package/dist/assetGroup.js +332 -0
- package/dist/assetGroupTypes.d.ts +15 -0
- package/dist/assetGroupTypes.js +2 -0
- package/dist/audio.d.ts +4 -0
- package/dist/audio.js +4 -0
- package/dist/audioCues.d.ts +43 -0
- package/dist/audioCues.js +127 -0
- package/dist/audioMixer.d.ts +7 -0
- package/dist/audioMixer.js +785 -0
- package/dist/audioTypes.d.ts +233 -0
- package/dist/audioTypes.js +3 -0
- package/dist/bitmapBindingTicket.d.ts +24 -0
- package/dist/bitmapBindingTicket.js +215 -0
- package/dist/bitmapButton.d.ts +4 -0
- package/dist/bitmapButton.js +407 -0
- package/dist/bitmapButtonTypes.d.ts +29 -0
- package/dist/bitmapButtonTypes.js +2 -0
- package/dist/bitmapFontParse.d.ts +10 -0
- package/dist/bitmapFontParse.js +246 -0
- package/dist/bitmapFontTypes.d.ts +109 -0
- package/dist/bitmapFontTypes.js +2 -0
- package/dist/bitmapResourceSlot.d.ts +25 -0
- package/dist/bitmapResourceSlot.js +340 -0
- package/dist/bitmapText.d.ts +6 -0
- package/dist/bitmapText.js +320 -0
- package/dist/bitmapfont.d.ts +5 -0
- package/dist/bitmapfont.js +5 -0
- package/dist/camera.d.ts +4 -0
- package/dist/camera.js +4 -0
- package/dist/camera2d.d.ts +7 -0
- package/dist/camera2d.js +411 -0
- package/dist/cameraTypes.d.ts +114 -0
- package/dist/cameraTypes.js +2 -0
- package/dist/closeHost.d.ts +4 -0
- package/dist/closeHost.js +66 -0
- package/dist/contentArtifacts.d.ts +12 -0
- package/dist/contentArtifacts.js +153 -0
- package/dist/contentAtlasPages.d.ts +13 -0
- package/dist/contentAtlasPages.js +117 -0
- package/dist/contentLoader.d.ts +6 -0
- package/dist/contentLoader.js +327 -0
- package/dist/contentTypes.d.ts +33 -0
- package/dist/contentTypes.js +2 -0
- package/dist/createEngine.d.ts +7 -0
- package/dist/createEngine.js +25 -0
- package/dist/createEngineForProfile.d.ts +5 -0
- package/dist/createEngineForProfile.js +42 -0
- package/dist/displaySubtreeTicket.d.ts +25 -0
- package/dist/displaySubtreeTicket.js +76 -0
- package/dist/fontContentLoader.d.ts +6 -0
- package/dist/fontContentLoader.js +298 -0
- package/dist/fontContentTypes.d.ts +34 -0
- package/dist/fontContentTypes.js +2 -0
- package/dist/gameClock.d.ts +24 -0
- package/dist/gameClock.js +246 -0
- package/dist/gameClockTypes.d.ts +31 -0
- package/dist/gameClockTypes.js +2 -0
- package/dist/gameRun.d.ts +50 -0
- package/dist/gameRun.js +97 -0
- package/dist/gamepad.d.ts +5 -0
- package/dist/gamepad.js +5 -0
- package/dist/gamepadInput.d.ts +4 -0
- package/dist/gamepadInput.js +281 -0
- package/dist/gamepadKeys.d.ts +4 -0
- package/dist/gamepadKeys.js +205 -0
- package/dist/gamepadTypes.d.ts +134 -0
- package/dist/gamepadTypes.js +3 -0
- package/dist/hover.d.ts +4 -0
- package/dist/hover.js +4 -0
- package/dist/hoverInput.d.ts +8 -0
- package/dist/hoverInput.js +503 -0
- package/dist/hoverInputTypes.d.ts +119 -0
- package/dist/hoverInputTypes.js +2 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.js +20 -0
- package/dist/input.d.ts +6 -0
- package/dist/input.js +5 -0
- package/dist/inputActions.d.ts +81 -0
- package/dist/inputActions.js +330 -0
- package/dist/internal/contentFactoryState.d.ts +19 -0
- package/dist/internal/contentFactoryState.js +42 -0
- package/dist/internal/mouseInputFactoryState.d.ts +57 -0
- package/dist/internal/mouseInputFactoryState.js +125 -0
- package/dist/internal/sequenceControllerFactoryState.d.ts +42 -0
- package/dist/internal/sequenceControllerFactoryState.js +98 -0
- package/dist/internal/textFieldFactoryState.d.ts +11 -0
- package/dist/internal/textFieldFactoryState.js +32 -0
- package/dist/internal/texturedFrameState.d.ts +4 -0
- package/dist/internal/texturedFrameState.js +12 -0
- package/dist/internal/uiFactoryState.d.ts +64 -0
- package/dist/internal/uiFactoryState.js +157 -0
- package/dist/internal/uiRootState.d.ts +67 -0
- package/dist/internal/uiRootState.js +103 -0
- package/dist/keyboardInput.d.ts +12 -0
- package/dist/keyboardInput.js +578 -0
- package/dist/keyboardInputTypes.d.ts +81 -0
- package/dist/keyboardInputTypes.js +2 -0
- package/dist/kit.d.ts +14 -0
- package/dist/kit.js +9 -0
- package/dist/layout.d.ts +5 -0
- package/dist/layout.js +132 -0
- package/dist/layoutTypes.d.ts +28 -0
- package/dist/layoutTypes.js +2 -0
- package/dist/manifestAssetGroup.d.ts +10 -0
- package/dist/manifestAssetGroup.js +477 -0
- package/dist/manifestResourceState.d.ts +16 -0
- package/dist/manifestResourceState.js +57 -0
- package/dist/manifestResourceTypes.d.ts +25 -0
- package/dist/manifestResourceTypes.js +2 -0
- package/dist/motion.d.ts +33 -0
- package/dist/motion.js +206 -0
- package/dist/mouseInput.d.ts +102 -0
- package/dist/mouseInput.js +562 -0
- package/dist/mouseInputTypes.d.ts +37 -0
- package/dist/mouseInputTypes.js +2 -0
- package/dist/paragraph.d.ts +8 -0
- package/dist/paragraph.js +7 -0
- package/dist/particleEmitter.d.ts +4 -0
- package/dist/particleEmitter.js +292 -0
- package/dist/particleTypes.d.ts +107 -0
- package/dist/particleTypes.js +2 -0
- package/dist/particles.d.ts +4 -0
- package/dist/particles.js +4 -0
- package/dist/physics2d.d.ts +4 -0
- package/dist/physics2d.js +4 -0
- package/dist/physics2dGeometry.d.ts +39 -0
- package/dist/physics2dGeometry.js +230 -0
- package/dist/physics2dTypes.d.ts +167 -0
- package/dist/physics2dTypes.js +2 -0
- package/dist/physics2dWorld.d.ts +4 -0
- package/dist/physics2dWorld.js +623 -0
- package/dist/pointerInput.d.ts +11 -0
- package/dist/pointerInput.js +299 -0
- package/dist/pointerInputTypes.d.ts +38 -0
- package/dist/pointerInputTypes.js +2 -0
- package/dist/random.d.ts +29 -0
- package/dist/random.js +131 -0
- package/dist/rendering/ownedPreparationFailure2D.d.ts +5 -0
- package/dist/rendering/ownedPreparationFailure2D.js +33 -0
- package/dist/rendering/packSharedDraws2D.d.ts +50 -0
- package/dist/rendering/packSharedDraws2D.js +331 -0
- package/dist/rendering/packedOrientation.d.ts +4 -0
- package/dist/rendering/packedOrientation.js +7 -0
- package/dist/rendering/prepareRectangles2D.d.ts +92 -0
- package/dist/rendering/prepareRectangles2D.js +481 -0
- package/dist/rendering/prepareSharedDraws2D.d.ts +88 -0
- package/dist/rendering/prepareSharedDraws2D.js +652 -0
- package/dist/rendering/preparedBatches2D.d.ts +17 -0
- package/dist/rendering/preparedBatches2D.js +30 -0
- package/dist/rendering/preparedSharedBatches2D.d.ts +44 -0
- package/dist/rendering/preparedSharedBatches2D.js +247 -0
- package/dist/rendering/sharedColor2D.d.ts +18 -0
- package/dist/rendering/sharedColor2D.js +68 -0
- package/dist/rendering/sharedEffects2D.d.ts +23 -0
- package/dist/rendering/sharedEffects2D.js +118 -0
- package/dist/rendering/sharedPreparationRetention2D.d.ts +120 -0
- package/dist/rendering/sharedPreparationRetention2D.js +357 -0
- package/dist/rendering/srgbBytes.d.ts +3 -0
- package/dist/rendering/srgbBytes.js +64 -0
- package/dist/rendering/texturedPreparationBudget2D.d.ts +31 -0
- package/dist/rendering/texturedPreparationBudget2D.js +81 -0
- package/dist/rendering/world3d/Animation3D.d.ts +95 -0
- package/dist/rendering/world3d/Animation3D.js +380 -0
- package/dist/rendering/world3d/AnimationTexture3D.d.ts +157 -0
- package/dist/rendering/world3d/AnimationTexture3D.js +601 -0
- package/dist/rendering/world3d/Batch3D.d.ts +71 -0
- package/dist/rendering/world3d/Batch3D.js +329 -0
- package/dist/rendering/world3d/Camera3D.d.ts +57 -0
- package/dist/rendering/world3d/Camera3D.js +129 -0
- package/dist/rendering/world3d/Character3D.d.ts +123 -0
- package/dist/rendering/world3d/Character3D.js +303 -0
- package/dist/rendering/world3d/Cloth3D.d.ts +115 -0
- package/dist/rendering/world3d/Cloth3D.js +498 -0
- package/dist/rendering/world3d/Compression3D.d.ts +21 -0
- package/dist/rendering/world3d/Compression3D.js +702 -0
- package/dist/rendering/world3d/Curves3D.d.ts +111 -0
- package/dist/rendering/world3d/Curves3D.js +455 -0
- package/dist/rendering/world3d/Decal3D.d.ts +41 -0
- package/dist/rendering/world3d/Decal3D.js +241 -0
- package/dist/rendering/world3d/Geometry3D.d.ts +85 -0
- package/dist/rendering/world3d/Geometry3D.js +326 -0
- package/dist/rendering/world3d/GeometryBuilder3D.d.ts +51 -0
- package/dist/rendering/world3d/GeometryBuilder3D.js +196 -0
- package/dist/rendering/world3d/Gizmo3D.d.ts +75 -0
- package/dist/rendering/world3d/Gizmo3D.js +512 -0
- package/dist/rendering/world3d/Gltf3D.d.ts +67 -0
- package/dist/rendering/world3d/Gltf3D.js +976 -0
- package/dist/rendering/world3d/GpuParticles3D.d.ts +107 -0
- package/dist/rendering/world3d/GpuParticles3D.js +400 -0
- package/dist/rendering/world3d/Hdr3D.d.ts +33 -0
- package/dist/rendering/world3d/Hdr3D.js +190 -0
- package/dist/rendering/world3d/Jelly3D.d.ts +75 -0
- package/dist/rendering/world3d/Jelly3D.js +266 -0
- package/dist/rendering/world3d/Ktx23D.d.ts +27 -0
- package/dist/rendering/world3d/Ktx23D.js +112 -0
- package/dist/rendering/world3d/Light3D.d.ts +75 -0
- package/dist/rendering/world3d/Light3D.js +93 -0
- package/dist/rendering/world3d/Material3D.d.ts +243 -0
- package/dist/rendering/world3d/Material3D.js +267 -0
- package/dist/rendering/world3d/Mesh3D.d.ts +108 -0
- package/dist/rendering/world3d/Mesh3D.js +323 -0
- package/dist/rendering/world3d/Meshopt3D.d.ts +12 -0
- package/dist/rendering/world3d/Meshopt3D.js +275 -0
- package/dist/rendering/world3d/Navigation3D.d.ts +173 -0
- package/dist/rendering/world3d/Navigation3D.js +971 -0
- package/dist/rendering/world3d/Object3D.d.ts +107 -0
- package/dist/rendering/world3d/Object3D.js +305 -0
- package/dist/rendering/world3d/Particles3D.d.ts +85 -0
- package/dist/rendering/world3d/Particles3D.js +274 -0
- package/dist/rendering/world3d/Physics3D.d.ts +416 -0
- package/dist/rendering/world3d/Physics3D.js +2835 -0
- package/dist/rendering/world3d/PhysicsHull3D.d.ts +35 -0
- package/dist/rendering/world3d/PhysicsHull3D.js +227 -0
- package/dist/rendering/world3d/PhysicsMesh3D.d.ts +39 -0
- package/dist/rendering/world3d/PhysicsMesh3D.js +338 -0
- package/dist/rendering/world3d/PhysicsQueries3D.d.ts +24 -0
- package/dist/rendering/world3d/PhysicsQueries3D.js +323 -0
- package/dist/rendering/world3d/PhysicsRemote3D.d.ts +174 -0
- package/dist/rendering/world3d/PhysicsRemote3D.js +534 -0
- package/dist/rendering/world3d/Ragdoll3D.d.ts +69 -0
- package/dist/rendering/world3d/Ragdoll3D.js +200 -0
- package/dist/rendering/world3d/Raycast3D.d.ts +37 -0
- package/dist/rendering/world3d/Raycast3D.js +246 -0
- package/dist/rendering/world3d/RenderList3D.d.ts +88 -0
- package/dist/rendering/world3d/RenderList3D.js +490 -0
- package/dist/rendering/world3d/Retarget3D.d.ts +20 -0
- package/dist/rendering/world3d/Retarget3D.js +185 -0
- package/dist/rendering/world3d/Serialize3D.d.ts +49 -0
- package/dist/rendering/world3d/Serialize3D.js +607 -0
- package/dist/rendering/world3d/StateMachine3D.d.ts +78 -0
- package/dist/rendering/world3d/StateMachine3D.js +277 -0
- package/dist/rendering/world3d/Terrain3D.d.ts +227 -0
- package/dist/rendering/world3d/Terrain3D.js +803 -0
- package/dist/rendering/world3d/Text3D.d.ts +90 -0
- package/dist/rendering/world3d/Text3D.js +558 -0
- package/dist/rendering/world3d/Texture3D.d.ts +133 -0
- package/dist/rendering/world3d/Texture3D.js +252 -0
- package/dist/rendering/world3d/Trail3D.d.ts +59 -0
- package/dist/rendering/world3d/Trail3D.js +193 -0
- package/dist/rendering/world3d/Vehicle3D.d.ts +97 -0
- package/dist/rendering/world3d/Vehicle3D.js +226 -0
- package/dist/rendering/world3d/VolumetricFog3D.d.ts +55 -0
- package/dist/rendering/world3d/VolumetricFog3D.js +229 -0
- package/dist/rendering/world3d/Water3D.d.ts +163 -0
- package/dist/rendering/world3d/Water3D.js +606 -0
- package/dist/rendering/world3d/core3D.d.ts +34 -0
- package/dist/rendering/world3d/core3D.js +99 -0
- package/dist/rendering/world3d/debug3D.d.ts +64 -0
- package/dist/rendering/world3d/debug3D.js +257 -0
- package/dist/rendering/world3d/decoders3D.d.ts +42 -0
- package/dist/rendering/world3d/decoders3D.js +133 -0
- package/dist/rendering/world3d/geometries3D.d.ts +99 -0
- package/dist/rendering/world3d/geometries3D.js +605 -0
- package/dist/rendering/world3d/helpers3D.d.ts +65 -0
- package/dist/rendering/world3d/helpers3D.js +177 -0
- package/dist/rendering/world3d/index.d.ts +91 -0
- package/dist/rendering/world3d/index.js +56 -0
- package/dist/rendering/world3d/math3D.d.ts +78 -0
- package/dist/rendering/world3d/math3D.js +640 -0
- package/dist/rendering/world3d/primitives3D.d.ts +60 -0
- package/dist/rendering/world3d/primitives3D.js +196 -0
- package/dist/resources.d.ts +8 -0
- package/dist/resources.js +6 -0
- package/dist/saveStore.d.ts +56 -0
- package/dist/saveStore.js +163 -0
- package/dist/semanticList.d.ts +122 -0
- package/dist/semanticList.js +174 -0
- package/dist/semanticTree.d.ts +10 -0
- package/dist/semanticTree.js +532 -0
- package/dist/semanticTypes.d.ts +167 -0
- package/dist/semanticTypes.js +2 -0
- package/dist/semantics.d.ts +6 -0
- package/dist/semantics.js +5 -0
- package/dist/sequencePlayback.d.ts +19 -0
- package/dist/sequencePlayback.js +391 -0
- package/dist/sequencePlaybackTypes.d.ts +21 -0
- package/dist/sequencePlaybackTypes.js +2 -0
- package/dist/sequenceTargetClaims.d.ts +10 -0
- package/dist/sequenceTargetClaims.js +31 -0
- package/dist/srgbBytes.d.ts +3 -0
- package/dist/srgbBytes.js +64 -0
- package/dist/startEngine.d.ts +5 -0
- package/dist/startEngine.js +31 -0
- package/dist/surfaceOwnership.d.ts +3 -0
- package/dist/surfaceOwnership.js +15 -0
- package/dist/text.d.ts +23 -0
- package/dist/text.js +4 -0
- package/dist/textField.d.ts +6 -0
- package/dist/textField.js +6 -0
- package/dist/tileMapDraw.d.ts +7 -0
- package/dist/tileMapDraw.js +310 -0
- package/dist/tiledImport.d.ts +9 -0
- package/dist/tiledImport.js +357 -0
- package/dist/tilemap.d.ts +5 -0
- package/dist/tilemap.js +5 -0
- package/dist/tilemapTypes.d.ts +169 -0
- package/dist/tilemapTypes.js +2 -0
- package/dist/tween.d.ts +15 -0
- package/dist/tween.js +329 -0
- package/dist/tweenTypes.d.ts +27 -0
- package/dist/tweenTypes.js +2 -0
- package/dist/ui/controlKeys.d.ts +109 -0
- package/dist/ui/controlKeys.js +249 -0
- package/dist/ui/controls.d.ts +52 -0
- package/dist/ui/controls.js +288 -0
- package/dist/ui/editing.d.ts +3 -0
- package/dist/ui/editing.js +3 -0
- package/dist/ui/index.d.ts +19 -0
- package/dist/ui/index.js +11 -0
- package/dist/ui/keyboardFocus.d.ts +32 -0
- package/dist/ui/keyboardFocus.js +146 -0
- package/dist/ui/layerTypes.d.ts +91 -0
- package/dist/ui/layerTypes.js +2 -0
- package/dist/ui/layers.d.ts +4 -0
- package/dist/ui/layers.js +586 -0
- package/dist/ui/leafContent.d.ts +21 -0
- package/dist/ui/leafContent.js +136 -0
- package/dist/ui/rangeControl.d.ts +50 -0
- package/dist/ui/rangeControl.js +167 -0
- package/dist/ui/scrollControl.d.ts +72 -0
- package/dist/ui/scrollControl.js +218 -0
- package/dist/ui/stateControls.d.ts +82 -0
- package/dist/ui/stateControls.js +328 -0
- package/dist/ui/textEditor.d.ts +53 -0
- package/dist/ui/textEditor.js +370 -0
- package/dist/ui/textEditorTypes.d.ts +78 -0
- package/dist/ui/textEditorTypes.js +2 -0
- package/dist/ui/textFieldControl.d.ts +96 -0
- package/dist/ui/textFieldControl.js +259 -0
- package/dist/ui/theme.d.ts +59 -0
- package/dist/ui/theme.js +165 -0
- package/dist/ui/types.d.ts +265 -0
- package/dist/ui/types.js +2 -0
- package/dist/ui/uiRoot.d.ts +4 -0
- package/dist/ui/uiRoot.js +1497 -0
- package/dist/ui/uiRootDisplay.d.ts +46 -0
- package/dist/ui/uiRootDisplay.js +148 -0
- package/dist/ui/uiRootModel.d.ts +112 -0
- package/dist/ui/uiRootModel.js +60 -0
- package/dist/ui/virtualList.d.ts +20 -0
- package/dist/ui/virtualList.js +105 -0
- package/dist/video.d.ts +4 -0
- package/dist/video.js +4 -0
- package/dist/videoPlayer.d.ts +4 -0
- package/dist/videoPlayer.js +215 -0
- package/dist/videoTypes.d.ts +74 -0
- package/dist/videoTypes.js +2 -0
- package/dist/web/BrowserAssetBundle.d.ts +39 -0
- package/dist/web/BrowserAssetBundle.js +136 -0
- package/dist/web/BrowserAudio.d.ts +41 -0
- package/dist/web/BrowserAudio.js +473 -0
- package/dist/web/BrowserFrameLoop.d.ts +65 -0
- package/dist/web/BrowserFrameLoop.js +125 -0
- package/dist/web/BrowserGame.d.ts +112 -0
- package/dist/web/BrowserGame.js +352 -0
- package/dist/web/BrowserGamepadInput.d.ts +35 -0
- package/dist/web/BrowserGamepadInput.js +134 -0
- package/dist/web/BrowserHoverInput.d.ts +24 -0
- package/dist/web/BrowserHoverInput.js +266 -0
- package/dist/web/BrowserImageTextures.d.ts +66 -0
- package/dist/web/BrowserImageTextures.js +169 -0
- package/dist/web/BrowserInputActions.d.ts +53 -0
- package/dist/web/BrowserInputActions.js +342 -0
- package/dist/web/BrowserKeyboardInput.d.ts +4 -0
- package/dist/web/BrowserKeyboardInput.js +223 -0
- package/dist/web/BrowserPlay.d.ts +289 -0
- package/dist/web/BrowserPlay.js +1301 -0
- package/dist/web/BrowserPointerInput.d.ts +4 -0
- package/dist/web/BrowserPointerInput.js +511 -0
- package/dist/web/BrowserSemantics.d.ts +34 -0
- package/dist/web/BrowserSemantics.js +418 -0
- package/dist/web/BrowserStatsPanel.d.ts +46 -0
- package/dist/web/BrowserStatsPanel.js +137 -0
- package/dist/web/BrowserStorage.d.ts +33 -0
- package/dist/web/BrowserStorage.js +132 -0
- package/dist/web/BrowserTextEditor.d.ts +49 -0
- package/dist/web/BrowserTextEditor.js +839 -0
- package/dist/web/BrowserTextInput.d.ts +83 -0
- package/dist/web/BrowserTextInput.js +524 -0
- package/dist/web/BrowserTextureProvider.d.ts +52 -0
- package/dist/web/BrowserTextureProvider.js +935 -0
- package/dist/web/BrowserVideo.d.ts +28 -0
- package/dist/web/BrowserVideo.js +211 -0
- package/dist/web/CanvasKitFontSetProvider.d.ts +29 -0
- package/dist/web/CanvasKitFontSetProvider.js +215 -0
- package/dist/web/CanvasKitParagraphProvider.d.ts +169 -0
- package/dist/web/CanvasKitParagraphProvider.js +691 -0
- package/dist/web/CanvasTextRasterProvider.d.ts +4 -0
- package/dist/web/CanvasTextRasterProvider.js +312 -0
- package/dist/web/ManifestByteSource.d.ts +147 -0
- package/dist/web/ManifestByteSource.js +974 -0
- package/dist/web/ManifestFontContentLoader.d.ts +12 -0
- package/dist/web/ManifestFontContentLoader.js +30 -0
- package/dist/web/MouseInput.d.ts +4 -0
- package/dist/web/MouseInput.js +218 -0
- package/dist/web/WebGL2Host.d.ts +5 -0
- package/dist/web/WebGL2Host.js +2672 -0
- package/dist/web/WebGPUHost.d.ts +87 -0
- package/dist/web/WebGPUHost.js +3349 -0
- package/dist/web/audio.d.ts +3 -0
- package/dist/web/audio.js +4 -0
- package/dist/web/canvasKitParagraphGeometry.d.ts +27 -0
- package/dist/web/canvasKitParagraphGeometry.js +83 -0
- package/dist/web/editing.d.ts +5 -0
- package/dist/web/editing.js +4 -0
- package/dist/web/editorFonts.d.ts +50 -0
- package/dist/web/editorFonts.js +297 -0
- package/dist/web/game.d.ts +5 -0
- package/dist/web/game.js +6 -0
- package/dist/web/gamepad.d.ts +3 -0
- package/dist/web/gamepad.js +4 -0
- package/dist/web/hover.d.ts +3 -0
- package/dist/web/hover.js +4 -0
- package/dist/web/image.d.ts +4 -0
- package/dist/web/image.js +4 -0
- package/dist/web/imageProjections2D.d.ts +14 -0
- package/dist/web/imageProjections2D.js +2 -0
- package/dist/web/input.d.ts +6 -0
- package/dist/web/input.js +4 -0
- package/dist/web/keyboard.d.ts +3 -0
- package/dist/web/keyboard.js +3 -0
- package/dist/web/kit.d.ts +10 -0
- package/dist/web/kit.js +7 -0
- package/dist/web/loop.d.ts +3 -0
- package/dist/web/loop.js +4 -0
- package/dist/web/paragraph.d.ts +6 -0
- package/dist/web/paragraph.js +4 -0
- package/dist/web/play.d.ts +5 -0
- package/dist/web/play.js +6 -0
- package/dist/web/playSfx.d.ts +36 -0
- package/dist/web/playSfx.js +112 -0
- package/dist/web/pointer.d.ts +3 -0
- package/dist/web/pointer.js +3 -0
- package/dist/web/prepareSharedSubmission2D.d.ts +27 -0
- package/dist/web/prepareSharedSubmission2D.js +57 -0
- package/dist/web/resources.d.ts +27 -0
- package/dist/web/resources.js +96 -0
- package/dist/web/semantics.d.ts +3 -0
- package/dist/web/semantics.js +4 -0
- package/dist/web/sharedDeviceSession.d.ts +64 -0
- package/dist/web/sharedDeviceSession.js +2 -0
- package/dist/web/sharedEffectShaders.d.ts +9 -0
- package/dist/web/sharedEffectShaders.js +165 -0
- package/dist/web/sharedFrameUpload.d.ts +25 -0
- package/dist/web/sharedFrameUpload.js +2 -0
- package/dist/web/sharedHostDeferred.d.ts +7 -0
- package/dist/web/sharedHostDeferred.js +12 -0
- package/dist/web/sharedRetentionLedger.d.ts +85 -0
- package/dist/web/sharedRetentionLedger.js +391 -0
- package/dist/web/sharedSubmissionStorage2D.d.ts +56 -0
- package/dist/web/sharedSubmissionStorage2D.js +73 -0
- package/dist/web/sharedWebGL2Arena.d.ts +40 -0
- package/dist/web/sharedWebGL2Arena.js +77 -0
- package/dist/web/sharedWebGL2Options.d.ts +30 -0
- package/dist/web/sharedWebGL2Options.js +96 -0
- package/dist/web/sharedWebGL2Shaders.d.ts +20 -0
- package/dist/web/sharedWebGL2Shaders.js +314 -0
- package/dist/web/sharedWebGPUOptions.d.ts +37 -0
- package/dist/web/sharedWebGPUOptions.js +126 -0
- package/dist/web/text.d.ts +3 -0
- package/dist/web/text.js +3 -0
- package/dist/web/textInput.d.ts +3 -0
- package/dist/web/textInput.js +3 -0
- package/dist/web/video.d.ts +3 -0
- package/dist/web/video.js +4 -0
- package/dist/web/webgl2.d.ts +7 -0
- package/dist/web/webgl2.js +4 -0
- package/dist/web/webgl2LayerState.d.ts +50 -0
- package/dist/web/webgl2LayerState.js +102 -0
- package/dist/web/webgl2Native.d.ts +70 -0
- package/dist/web/webgl2Native.js +568 -0
- package/dist/web/webgl2Types.d.ts +132 -0
- package/dist/web/webgl2Types.js +2 -0
- package/dist/web/webgpu.d.ts +6 -0
- package/dist/web/webgpu.js +2 -0
- package/dist/web/webgpuBindingCache.d.ts +26 -0
- package/dist/web/webgpuBindingCache.js +223 -0
- package/dist/web/webgpuBufferPool.d.ts +51 -0
- package/dist/web/webgpuBufferPool.js +58 -0
- package/dist/web/webgpuImageResidency.d.ts +53 -0
- package/dist/web/webgpuImageResidency.js +61 -0
- package/dist/web/webgpuLifetime.d.ts +45 -0
- package/dist/web/webgpuLifetime.js +64 -0
- package/dist/web/webgpuRetentionPool.d.ts +66 -0
- package/dist/web/webgpuRetentionPool.js +84 -0
- package/dist/web/webgpuSharedPass.d.ts +7 -0
- package/dist/web/webgpuSharedPass.js +211 -0
- package/dist/web/webgpuSharedResolvePass.d.ts +3 -0
- package/dist/web/webgpuSharedResolvePass.js +29 -0
- package/dist/web/world3d/Audio3D.d.ts +68 -0
- package/dist/web/world3d/Audio3D.js +212 -0
- package/dist/web/world3d/BrowserPlay3D.d.ts +182 -0
- package/dist/web/world3d/BrowserPlay3D.js +851 -0
- package/dist/web/world3d/FlyControls3D.d.ts +55 -0
- package/dist/web/world3d/FlyControls3D.js +160 -0
- package/dist/web/world3d/FollowControls3D.d.ts +28 -0
- package/dist/web/world3d/FollowControls3D.js +117 -0
- package/dist/web/world3d/OrbitControls3D.d.ts +55 -0
- package/dist/web/world3d/OrbitControls3D.js +187 -0
- package/dist/web/world3d/TransformControls3D.d.ts +34 -0
- package/dist/web/world3d/TransformControls3D.js +125 -0
- package/dist/web/world3d/WebGL2Renderer3D.d.ts +133 -0
- package/dist/web/world3d/WebGL2Renderer3D.js +1173 -0
- package/dist/web/world3d/WebGPURenderer3D.d.ts +110 -0
- package/dist/web/world3d/WebGPURenderer3D.js +1915 -0
- package/dist/web/world3d/World3DView.d.ts +51 -0
- package/dist/web/world3d/World3DView.js +77 -0
- package/dist/web/world3d/app3D.d.ts +136 -0
- package/dist/web/world3d/app3D.js +304 -0
- package/dist/web/world3d/assets3D.d.ts +38 -0
- package/dist/web/world3d/assets3D.js +112 -0
- package/dist/web/world3d/atmosphere3D.d.ts +47 -0
- package/dist/web/world3d/atmosphere3D.js +178 -0
- package/dist/web/world3d/frame3D.d.ts +142 -0
- package/dist/web/world3d/frame3D.js +388 -0
- package/dist/web/world3d/gpuResources3D.d.ts +98 -0
- package/dist/web/world3d/gpuResources3D.js +901 -0
- package/dist/web/world3d/host3D.d.ts +23 -0
- package/dist/web/world3d/host3D.js +61 -0
- package/dist/web/world3d/index.d.ts +38 -0
- package/dist/web/world3d/index.js +23 -0
- package/dist/web/world3d/loaders3D.d.ts +26 -0
- package/dist/web/world3d/loaders3D.js +138 -0
- package/dist/web/world3d/markers3D.d.ts +49 -0
- package/dist/web/world3d/markers3D.js +130 -0
- package/dist/web/world3d/materialWebGL23D.d.ts +34 -0
- package/dist/web/world3d/materialWebGL23D.js +218 -0
- package/dist/web/world3d/overlay3D.d.ts +28 -0
- package/dist/web/world3d/overlay3D.js +170 -0
- package/dist/web/world3d/post3D.d.ts +112 -0
- package/dist/web/world3d/post3D.js +459 -0
- package/dist/web/world3d/postWebGL23D.d.ts +24 -0
- package/dist/web/world3d/postWebGL23D.js +237 -0
- package/dist/web/world3d/postWebGPU3D.d.ts +23 -0
- package/dist/web/world3d/postWebGPU3D.js +255 -0
- package/dist/web/world3d/probe3D.d.ts +14 -0
- package/dist/web/world3d/probe3D.js +66 -0
- package/dist/web/world3d/shaders3D.d.ts +43 -0
- package/dist/web/world3d/shaders3D.js +851 -0
- package/dist/web/world3d/stats3D.d.ts +31 -0
- package/dist/web/world3d/stats3D.js +80 -0
- package/dist/web/world3d/webGL2FrameMetrics3D.d.ts +66 -0
- package/dist/web/world3d/webGL2FrameMetrics3D.js +185 -0
- package/dist/web/world3d/webgpu.d.ts +35 -0
- package/dist/web/world3d/webgpu.js +22 -0
- package/dist/web/world3d/webgpuPacking3D.d.ts +13 -0
- package/dist/web/world3d/webgpuPacking3D.js +85 -0
- package/dist/web/world3d/wgsl3D.d.ts +68 -0
- package/dist/web/world3d/wgsl3D.js +781 -0
- package/package.json +220 -4
|
@@ -0,0 +1,605 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Further procedural geometries (discs, knots, polyhedra, lathes, tubes,
|
|
3
|
+
// flat and extruded outlines) and geometry utilities (edges, wireframe,
|
|
4
|
+
// merging, welding, baking a transform). Triangles are counter-clockwise
|
|
5
|
+
// with outward normals, like the basic primitives.
|
|
6
|
+
import { World3DError, requireCount3D, requireFinite3D, requirePositive3D } from './core3D.js';
|
|
7
|
+
import { Curve3D, Shape3D, signedArea2D, triangulateShape3D } from './Curves3D.js';
|
|
8
|
+
import { Attribute3D, Geometry3D, createGeometry3D } from './Geometry3D.js';
|
|
9
|
+
import { mat3NormalFromMat4 } from './math3D.js';
|
|
10
|
+
const MAX_SEGMENTS = 2048;
|
|
11
|
+
function count(value, fallback, min, field) {
|
|
12
|
+
const n = requireCount3D(value ?? fallback, field, MAX_SEGMENTS);
|
|
13
|
+
if (n < min)
|
|
14
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', field);
|
|
15
|
+
return n;
|
|
16
|
+
}
|
|
17
|
+
const lists = () => ({ positions: [], normals: [], uvs: [], indices: [] });
|
|
18
|
+
const build = (l) => createGeometry3D({ positions: l.positions, normals: l.normals, uvs: l.uvs, indices: l.indices });
|
|
19
|
+
/** Index a (columns + 1) x (rows + 1) vertex grid. */
|
|
20
|
+
function grid(l, base, columns, rows) {
|
|
21
|
+
const stride = columns + 1;
|
|
22
|
+
for (let row = 0; row < rows; row++)
|
|
23
|
+
for (let column = 0; column < columns; column++) {
|
|
24
|
+
const a = base + row * stride + column, b = a + stride;
|
|
25
|
+
l.indices.push(a, b, a + 1, b, b + 1, a + 1);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** Flat disc or sector in the XY plane, facing +Z. */
|
|
29
|
+
export function createCircleGeometry3D(options = {}) {
|
|
30
|
+
return createRingGeometry3D({
|
|
31
|
+
innerRadius: 0,
|
|
32
|
+
outerRadius: options.radius ?? 0.5,
|
|
33
|
+
thetaSegments: options.segments ?? 32,
|
|
34
|
+
phiSegments: 1,
|
|
35
|
+
...(options.thetaStart === undefined ? {} : { thetaStart: options.thetaStart }),
|
|
36
|
+
...(options.thetaLength === undefined ? {} : { thetaLength: options.thetaLength })
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/** Flat ring in the XY plane, facing +Z. An inner radius of 0 gives a disc. */
|
|
40
|
+
export function createRingGeometry3D(options = {}) {
|
|
41
|
+
const inner = Math.max(requireFinite3D(options.innerRadius ?? 0.25, 'innerRadius'), 0), outer = requirePositive3D(options.outerRadius ?? 0.5, 'outerRadius');
|
|
42
|
+
if (inner >= outer)
|
|
43
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'innerRadius');
|
|
44
|
+
const ts = count(options.thetaSegments, 32, 3, 'thetaSegments'), ps = count(options.phiSegments, 1, 1, 'phiSegments');
|
|
45
|
+
const start = options.thetaStart ?? 0, length = options.thetaLength ?? Math.PI * 2, l = lists();
|
|
46
|
+
for (let j = 0; j <= ps; j++) {
|
|
47
|
+
const radius = inner + ((outer - inner) * j) / ps;
|
|
48
|
+
for (let i = 0; i <= ts; i++) {
|
|
49
|
+
const angle = start + (length * i) / ts, x = Math.cos(angle) * radius, y = Math.sin(angle) * radius;
|
|
50
|
+
l.positions.push(x, y, 0);
|
|
51
|
+
l.normals.push(0, 0, 1);
|
|
52
|
+
l.uvs.push((x / outer) * 0.5 + 0.5, (y / outer) * 0.5 + 0.5);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const stride = ts + 1;
|
|
56
|
+
for (let j = 0; j < ps; j++)
|
|
57
|
+
for (let i = 0; i < ts; i++) {
|
|
58
|
+
const a = j * stride + i, b = a + stride;
|
|
59
|
+
l.indices.push(a, b, a + 1, b, b + 1, a + 1);
|
|
60
|
+
}
|
|
61
|
+
return build(l);
|
|
62
|
+
}
|
|
63
|
+
export function createTorusKnotGeometry3D(options = {}) {
|
|
64
|
+
const radius = requirePositive3D(options.radius ?? 0.5, 'radius'), tube = requirePositive3D(options.tube ?? 0.15, 'tube');
|
|
65
|
+
const ts = count(options.tubularSegments, 96, 3, 'tubularSegments'), rs = count(options.radialSegments, 12, 3, 'radialSegments');
|
|
66
|
+
const p = options.p ?? 2, q = options.q ?? 3, l = lists();
|
|
67
|
+
const at = (u) => {
|
|
68
|
+
const cu = Math.cos(u), su = Math.sin(u), quOverP = (q / p) * u, cs = Math.cos(quOverP);
|
|
69
|
+
return [radius * (2 + cs) * 0.5 * cu, radius * (2 + cs) * su * 0.5, radius * Math.sin(quOverP) * 0.5];
|
|
70
|
+
};
|
|
71
|
+
for (let i = 0; i <= ts; i++) {
|
|
72
|
+
const u = (i / ts) * p * Math.PI * 2, p1 = at(u), p2 = at(u + 0.01);
|
|
73
|
+
const t = [p2[0] - p1[0], p2[1] - p1[1], p2[2] - p1[2]], n0 = [p2[0] + p1[0], p2[1] + p1[1], p2[2] + p1[2]];
|
|
74
|
+
const b = unit(cross(t, n0)), n = unit(cross(b, t));
|
|
75
|
+
for (let j = 0; j <= rs; j++) {
|
|
76
|
+
const v = (j / rs) * Math.PI * 2, cx = -tube * Math.cos(v), cy = tube * Math.sin(v);
|
|
77
|
+
const x = p1[0] + cx * n[0] + cy * b[0], y = p1[1] + cx * n[1] + cy * b[1], z = p1[2] + cx * n[2] + cy * b[2];
|
|
78
|
+
const normal = unit([x - p1[0], y - p1[1], z - p1[2]]);
|
|
79
|
+
l.positions.push(x, y, z);
|
|
80
|
+
l.normals.push(...normal);
|
|
81
|
+
l.uvs.push(i / ts, j / rs);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
grid(l, 0, rs, ts);
|
|
85
|
+
return build(l);
|
|
86
|
+
}
|
|
87
|
+
function cross(a, b) {
|
|
88
|
+
return [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
|
|
89
|
+
}
|
|
90
|
+
function unit(a) {
|
|
91
|
+
const length = Math.hypot(a[0], a[1], a[2]) || 1;
|
|
92
|
+
return [a[0] / length, a[1] / length, a[2] / length];
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Project a convex solid's triangles onto a sphere, subdividing each `detail`
|
|
96
|
+
* times. Vertices are not shared, so the result is faceted unless
|
|
97
|
+
* `smooth` is set, which uses the sphere normal.
|
|
98
|
+
*/
|
|
99
|
+
export function createPolyhedronGeometry3D(vertices, indices, options = {}) {
|
|
100
|
+
const radius = requirePositive3D(options.radius ?? 0.5, 'radius'), detail = requireCount3D(options.detail ?? 0, 'detail', 6), smooth = options.smooth ?? detail > 0;
|
|
101
|
+
if (!vertices || vertices.length % 3 !== 0 || !indices || indices.length % 3 !== 0)
|
|
102
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'polyhedron');
|
|
103
|
+
const l = lists(), divisions = detail + 1;
|
|
104
|
+
const corner = (i) => unit([vertices[i * 3], vertices[i * 3 + 1], vertices[i * 3 + 2]]);
|
|
105
|
+
const emit = (a, b, c) => {
|
|
106
|
+
const flat = unit(cross([b[0] - a[0], b[1] - a[1], b[2] - a[2]], [c[0] - a[0], c[1] - a[1], c[2] - a[2]]));
|
|
107
|
+
for (const p of [a, b, c]) {
|
|
108
|
+
l.positions.push(p[0] * radius, p[1] * radius, p[2] * radius);
|
|
109
|
+
l.normals.push(...(smooth ? p : flat));
|
|
110
|
+
l.uvs.push(Math.atan2(p[2], -p[0]) / (Math.PI * 2) + 0.5, Math.asin(Math.min(Math.max(p[1], -1), 1)) / Math.PI + 0.5);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
for (let f = 0; f < indices.length; f += 3) {
|
|
114
|
+
const a = corner(indices[f]), b = corner(indices[f + 1]), c = corner(indices[f + 2]);
|
|
115
|
+
// Barycentric rows of points, pushed out to the unit sphere.
|
|
116
|
+
const rows = [];
|
|
117
|
+
for (let i = 0; i <= divisions; i++) {
|
|
118
|
+
const row = [], left = mix(a, c, i / divisions), right = mix(b, c, i / divisions), steps = divisions - i;
|
|
119
|
+
for (let j = 0; j <= steps; j++)
|
|
120
|
+
row.push(unit(steps === 0 ? left : mix(left, right, j / steps)));
|
|
121
|
+
rows.push(row);
|
|
122
|
+
}
|
|
123
|
+
for (let i = 0; i < divisions; i++)
|
|
124
|
+
for (let j = 0; j < divisions - i; j++) {
|
|
125
|
+
emit(rows[i][j], rows[i][j + 1], rows[i + 1][j]);
|
|
126
|
+
if (j < divisions - i - 1)
|
|
127
|
+
emit(rows[i][j + 1], rows[i + 1][j + 1], rows[i + 1][j]);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return createGeometry3D({ positions: l.positions, normals: l.normals, uvs: l.uvs });
|
|
131
|
+
}
|
|
132
|
+
function mix(a, b, t) {
|
|
133
|
+
return [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t];
|
|
134
|
+
}
|
|
135
|
+
const PHI = (1 + Math.sqrt(5)) / 2, INVERSE_PHI = 1 / PHI;
|
|
136
|
+
export function createTetrahedronGeometry3D(options = {}) {
|
|
137
|
+
return createPolyhedronGeometry3D([1, 1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1], [2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1], options);
|
|
138
|
+
}
|
|
139
|
+
export function createOctahedronGeometry3D(options = {}) {
|
|
140
|
+
return createPolyhedronGeometry3D([1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 1, 0, 0, -1], [0, 2, 4, 0, 4, 3, 0, 3, 5, 0, 5, 2, 1, 2, 5, 1, 5, 3, 1, 3, 4, 1, 4, 2], options);
|
|
141
|
+
}
|
|
142
|
+
export function createIcosahedronGeometry3D(options = {}) {
|
|
143
|
+
return createPolyhedronGeometry3D([
|
|
144
|
+
-1,
|
|
145
|
+
PHI,
|
|
146
|
+
0,
|
|
147
|
+
1,
|
|
148
|
+
PHI,
|
|
149
|
+
0,
|
|
150
|
+
-1,
|
|
151
|
+
-PHI,
|
|
152
|
+
0,
|
|
153
|
+
1,
|
|
154
|
+
-PHI,
|
|
155
|
+
0,
|
|
156
|
+
0,
|
|
157
|
+
-1,
|
|
158
|
+
PHI,
|
|
159
|
+
0,
|
|
160
|
+
1,
|
|
161
|
+
PHI,
|
|
162
|
+
0,
|
|
163
|
+
-1,
|
|
164
|
+
-PHI,
|
|
165
|
+
0,
|
|
166
|
+
1,
|
|
167
|
+
-PHI,
|
|
168
|
+
PHI,
|
|
169
|
+
0,
|
|
170
|
+
-1,
|
|
171
|
+
PHI,
|
|
172
|
+
0,
|
|
173
|
+
1,
|
|
174
|
+
-PHI,
|
|
175
|
+
0,
|
|
176
|
+
-1,
|
|
177
|
+
-PHI,
|
|
178
|
+
0,
|
|
179
|
+
1
|
|
180
|
+
], [
|
|
181
|
+
0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11, 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8, 3, 9, 4, 3, 4,
|
|
182
|
+
2, 3, 2, 6, 3, 6, 8, 3, 8, 9, 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
|
|
183
|
+
], options);
|
|
184
|
+
}
|
|
185
|
+
export function createDodecahedronGeometry3D(options = {}) {
|
|
186
|
+
const r = INVERSE_PHI, t = PHI;
|
|
187
|
+
return createPolyhedronGeometry3D([
|
|
188
|
+
-1,
|
|
189
|
+
-1,
|
|
190
|
+
-1,
|
|
191
|
+
-1,
|
|
192
|
+
-1,
|
|
193
|
+
1,
|
|
194
|
+
-1,
|
|
195
|
+
1,
|
|
196
|
+
-1,
|
|
197
|
+
-1,
|
|
198
|
+
1,
|
|
199
|
+
1,
|
|
200
|
+
1,
|
|
201
|
+
-1,
|
|
202
|
+
-1,
|
|
203
|
+
1,
|
|
204
|
+
-1,
|
|
205
|
+
1,
|
|
206
|
+
1,
|
|
207
|
+
1,
|
|
208
|
+
-1,
|
|
209
|
+
1,
|
|
210
|
+
1,
|
|
211
|
+
1,
|
|
212
|
+
0,
|
|
213
|
+
-r,
|
|
214
|
+
-t,
|
|
215
|
+
0,
|
|
216
|
+
-r,
|
|
217
|
+
t,
|
|
218
|
+
0,
|
|
219
|
+
r,
|
|
220
|
+
-t,
|
|
221
|
+
0,
|
|
222
|
+
r,
|
|
223
|
+
t,
|
|
224
|
+
-r,
|
|
225
|
+
-t,
|
|
226
|
+
0,
|
|
227
|
+
-r,
|
|
228
|
+
t,
|
|
229
|
+
0,
|
|
230
|
+
r,
|
|
231
|
+
-t,
|
|
232
|
+
0,
|
|
233
|
+
r,
|
|
234
|
+
t,
|
|
235
|
+
0,
|
|
236
|
+
-t,
|
|
237
|
+
0,
|
|
238
|
+
-r,
|
|
239
|
+
t,
|
|
240
|
+
0,
|
|
241
|
+
-r,
|
|
242
|
+
-t,
|
|
243
|
+
0,
|
|
244
|
+
r,
|
|
245
|
+
t,
|
|
246
|
+
0,
|
|
247
|
+
r
|
|
248
|
+
], [
|
|
249
|
+
3, 11, 7, 3, 7, 15, 3, 15, 13, 7, 19, 17, 7, 17, 6, 7, 6, 15, 17, 4, 8, 17, 8, 10, 17, 10, 6, 8, 0, 16, 8, 16, 2,
|
|
250
|
+
8, 2, 10, 0, 12, 1, 0, 1, 18, 0, 18, 16, 6, 10, 2, 6, 2, 13, 6, 13, 15, 2, 16, 18, 2, 18, 3, 2, 3, 13, 18, 1, 9,
|
|
251
|
+
18, 9, 11, 18, 11, 3, 4, 14, 12, 4, 12, 0, 4, 0, 8, 11, 9, 5, 11, 5, 19, 11, 19, 7, 19, 5, 14, 19, 14, 4, 19, 4,
|
|
252
|
+
17, 1, 12, 14, 1, 14, 5, 1, 5, 9
|
|
253
|
+
], options);
|
|
254
|
+
}
|
|
255
|
+
/** Revolve a profile of [x, y] points (x is the distance from the Y axis) around Y. */
|
|
256
|
+
export function createLatheGeometry3D(profile, options = {}) {
|
|
257
|
+
if (!Array.isArray(profile) || profile.length < 2)
|
|
258
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'lathe profile');
|
|
259
|
+
const segments = count(options.segments, 24, 3, 'segments'), start = options.phiStart ?? 0, length = options.phiLength ?? Math.PI * 2, l = lists(), rows = profile.length;
|
|
260
|
+
// Profile normals: perpendicular to the neighbouring edges, pointing away from the axis.
|
|
261
|
+
const profileNormals = profile.map((_, i) => {
|
|
262
|
+
const a = profile[Math.max(i - 1, 0)], b = profile[Math.min(i + 1, rows - 1)], dx = b[0] - a[0], dy = b[1] - a[1], size = Math.hypot(dx, dy) || 1;
|
|
263
|
+
return [dy / size, -dx / size];
|
|
264
|
+
});
|
|
265
|
+
for (let i = 0; i <= segments; i++) {
|
|
266
|
+
const phi = start + (length * i) / segments, sin = Math.sin(phi), cos = Math.cos(phi);
|
|
267
|
+
for (let j = 0; j < rows; j++) {
|
|
268
|
+
const [x, y] = profile[j], [nx, ny] = profileNormals[j];
|
|
269
|
+
l.positions.push(x * sin, y, x * cos);
|
|
270
|
+
l.normals.push(nx * sin, ny, nx * cos);
|
|
271
|
+
l.uvs.push(i / segments, j / (rows - 1));
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
grid(l, 0, rows - 1, segments);
|
|
275
|
+
return build(l);
|
|
276
|
+
}
|
|
277
|
+
/** Sweep a circle along a curve, using twist-free frames. */
|
|
278
|
+
export function createTubeGeometry3D(curve, options = {}) {
|
|
279
|
+
if (!(curve instanceof Curve3D))
|
|
280
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'curve');
|
|
281
|
+
const ts = count(options.tubularSegments, 64, 1, 'tubularSegments'), rs = count(options.radialSegments, 8, 3, 'radialSegments');
|
|
282
|
+
const radius = requirePositive3D(options.radius ?? 0.1, 'radius'), closed = options.closed ?? false, frames = curve.computeFrames(ts, closed), l = lists();
|
|
283
|
+
for (let i = 0; i <= ts; i++) {
|
|
284
|
+
const center = curve.getPointAt(i / ts), n = frames.normals[i], b = frames.binormals[i];
|
|
285
|
+
for (let j = 0; j <= rs; j++) {
|
|
286
|
+
const v = (j / rs) * Math.PI * 2, sin = Math.sin(v), cos = -Math.cos(v), nx = cos * n[0] + sin * b[0], ny = cos * n[1] + sin * b[1], nz = cos * n[2] + sin * b[2];
|
|
287
|
+
l.positions.push(center[0] + radius * nx, center[1] + radius * ny, center[2] + radius * nz);
|
|
288
|
+
l.normals.push(nx, ny, nz);
|
|
289
|
+
l.uvs.push(i / ts, j / rs);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
grid(l, 0, rs, ts);
|
|
293
|
+
return build(l);
|
|
294
|
+
}
|
|
295
|
+
function shapeList(shapes) {
|
|
296
|
+
const list = shapes instanceof Shape3D ? [shapes] : shapes;
|
|
297
|
+
if (!Array.isArray(list) || list.length === 0 || !list.every(shape => shape instanceof Shape3D))
|
|
298
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'shapes');
|
|
299
|
+
return list;
|
|
300
|
+
}
|
|
301
|
+
/** Fill one or more outlines in the XY plane, facing +Z. UVs equal the XY coordinates. */
|
|
302
|
+
export function createShapeGeometry3D(shapes) {
|
|
303
|
+
const l = lists();
|
|
304
|
+
for (const shape of shapeList(shapes)) {
|
|
305
|
+
const base = l.positions.length / 3, { vertices, indices } = triangulateShape3D(shape.contour(), shape.holes.map(hole => hole.contour()));
|
|
306
|
+
for (const [x, y] of vertices) {
|
|
307
|
+
l.positions.push(x, y, 0);
|
|
308
|
+
l.normals.push(0, 0, 1);
|
|
309
|
+
l.uvs.push(x, y);
|
|
310
|
+
}
|
|
311
|
+
for (const index of indices)
|
|
312
|
+
l.indices.push(base + index);
|
|
313
|
+
}
|
|
314
|
+
return build(l);
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Give an outline thickness. The result has two material groups: 0 for the
|
|
318
|
+
* front and back caps, 1 for the side walls. Edges are sharp; bevels are not
|
|
319
|
+
* generated.
|
|
320
|
+
*/
|
|
321
|
+
export function createExtrudeGeometry3D(shapes, options = {}) {
|
|
322
|
+
const steps = count(options.steps, options.path ? 32 : 1, 1, 'steps'), depth = requireFinite3D(options.depth ?? 1, 'depth'), path = options.path;
|
|
323
|
+
const caps = lists(), sides = lists(), frames = path?.computeFrames(steps, false);
|
|
324
|
+
// Map an outline point at step `s` into 3D.
|
|
325
|
+
const place = (x, y, s) => {
|
|
326
|
+
if (!path || !frames)
|
|
327
|
+
return [x, y, (depth * s) / steps];
|
|
328
|
+
const center = path.getPointAt(s / steps), n = frames.normals[s], b = frames.binormals[s];
|
|
329
|
+
return [center[0] + n[0] * x + b[0] * y, center[1] + n[1] * x + b[1] * y, center[2] + n[2] * x + b[2] * y];
|
|
330
|
+
};
|
|
331
|
+
for (const shape of shapeList(shapes)) {
|
|
332
|
+
const contour = shape.contour(), holes = shape.holes.map(hole => hole.contour());
|
|
333
|
+
if (signedArea2D(contour) < 0)
|
|
334
|
+
contour.reverse();
|
|
335
|
+
for (const hole of holes)
|
|
336
|
+
if (signedArea2D(hole) > 0)
|
|
337
|
+
hole.reverse();
|
|
338
|
+
const { vertices, indices } = triangulateShape3D(contour, holes);
|
|
339
|
+
for (const front of [false, true]) {
|
|
340
|
+
const base = caps.positions.length / 3, s = front ? steps : 0;
|
|
341
|
+
const a = place(0, 0, s), ex = place(1, 0, s), ey = place(0, 1, s);
|
|
342
|
+
const facing = unit(cross([ex[0] - a[0], ex[1] - a[1], ex[2] - a[2]], [ey[0] - a[0], ey[1] - a[1], ey[2] - a[2]])), sign = front ? 1 : -1;
|
|
343
|
+
for (const [x, y] of vertices) {
|
|
344
|
+
caps.positions.push(...place(x, y, s));
|
|
345
|
+
caps.normals.push(facing[0] * sign, facing[1] * sign, facing[2] * sign);
|
|
346
|
+
caps.uvs.push(x, y);
|
|
347
|
+
}
|
|
348
|
+
for (let i = 0; i < indices.length; i += 3) {
|
|
349
|
+
if (front)
|
|
350
|
+
caps.indices.push(base + indices[i], base + indices[i + 1], base + indices[i + 2]);
|
|
351
|
+
else
|
|
352
|
+
caps.indices.push(base + indices[i], base + indices[i + 2], base + indices[i + 1]);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
for (const ring of [contour, ...holes]) {
|
|
356
|
+
let travelled = 0;
|
|
357
|
+
for (let i = 0; i < ring.length; i++) {
|
|
358
|
+
const p = ring[i], q = ring[(i + 1) % ring.length], edge = Math.hypot(q[0] - p[0], q[1] - p[1]);
|
|
359
|
+
// Each wall quad strip has its own vertices so corners stay sharp.
|
|
360
|
+
const base = sides.positions.length / 3;
|
|
361
|
+
for (let s = 0; s <= steps; s++) {
|
|
362
|
+
const a = place(p[0], p[1], s), b = place(q[0], q[1], s), next = place(p[0], p[1], Math.min(s + 1, steps)), previous = place(p[0], p[1], Math.max(s - 1, 0));
|
|
363
|
+
const normal = unit(cross([b[0] - a[0], b[1] - a[1], b[2] - a[2]], [next[0] - previous[0], next[1] - previous[1], next[2] - previous[2]]));
|
|
364
|
+
sides.positions.push(...a, ...b);
|
|
365
|
+
sides.normals.push(...normal, ...normal);
|
|
366
|
+
sides.uvs.push(travelled, s / steps, travelled + edge, s / steps);
|
|
367
|
+
}
|
|
368
|
+
for (let s = 0; s < steps; s++) {
|
|
369
|
+
const a = base + s * 2;
|
|
370
|
+
sides.indices.push(a, a + 1, a + 2, a + 1, a + 3, a + 2);
|
|
371
|
+
}
|
|
372
|
+
travelled += edge;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
const capVertices = caps.positions.length / 3;
|
|
377
|
+
const geometry = createGeometry3D({
|
|
378
|
+
positions: [...caps.positions, ...sides.positions],
|
|
379
|
+
normals: [...caps.normals, ...sides.normals],
|
|
380
|
+
uvs: [...caps.uvs, ...sides.uvs],
|
|
381
|
+
indices: [...caps.indices, ...sides.indices.map(index => index + capVertices)]
|
|
382
|
+
});
|
|
383
|
+
geometry.addGroup(0, caps.indices.length, 0);
|
|
384
|
+
geometry.addGroup(caps.indices.length, sides.indices.length, 1);
|
|
385
|
+
return geometry;
|
|
386
|
+
}
|
|
387
|
+
// ---- utilities ------------------------------------------------------------------
|
|
388
|
+
function triangleIndices(geometry) {
|
|
389
|
+
if (!(geometry instanceof Geometry3D) || geometry.topology !== 'triangles')
|
|
390
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'triangle geometry');
|
|
391
|
+
const position = geometry.getAttribute('position');
|
|
392
|
+
if (!position)
|
|
393
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'geometry positions');
|
|
394
|
+
return geometry.index ? geometry.index.data : Array.from({ length: position.count }, (_, i) => i);
|
|
395
|
+
}
|
|
396
|
+
const lineGeometry = (positions) => createGeometry3D({ positions, topology: 'lines' });
|
|
397
|
+
/** Line segments for every triangle edge, each drawn once. */
|
|
398
|
+
export function createWireframeGeometry3D(geometry) {
|
|
399
|
+
const indices = triangleIndices(geometry), p = geometry.getAttribute('position').data, seen = new Set(), positions = [], total = p.length / 3;
|
|
400
|
+
for (let i = 0; i < indices.length; i += 3)
|
|
401
|
+
for (let e = 0; e < 3; e++) {
|
|
402
|
+
const a = indices[i + e], b = indices[i + ((e + 1) % 3)], key = Math.min(a, b) * total + Math.max(a, b);
|
|
403
|
+
if (seen.has(key))
|
|
404
|
+
continue;
|
|
405
|
+
seen.add(key);
|
|
406
|
+
positions.push(p[a * 3], p[a * 3 + 1], p[a * 3 + 2], p[b * 3], p[b * 3 + 1], p[b * 3 + 2]);
|
|
407
|
+
}
|
|
408
|
+
return lineGeometry(positions);
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Line segments for outline and crease edges only: edges with one face, or
|
|
412
|
+
* whose two faces meet at more than `thresholdAngle` radians.
|
|
413
|
+
*/
|
|
414
|
+
export function createEdgesGeometry3D(geometry, thresholdAngle = Math.PI / 180) {
|
|
415
|
+
const indices = triangleIndices(geometry), p = geometry.getAttribute('position').data, limit = Math.cos(thresholdAngle), positions = [];
|
|
416
|
+
// Weld by position so faces that only share coordinates still count as neighbours.
|
|
417
|
+
const ids = new Map(), welded = [];
|
|
418
|
+
for (let i = 0; i < p.length / 3; i++) {
|
|
419
|
+
const key = Math.round(p[i * 3] * 1e4) + ',' + Math.round(p[i * 3 + 1] * 1e4) + ',' + Math.round(p[i * 3 + 2] * 1e4);
|
|
420
|
+
let id = ids.get(key);
|
|
421
|
+
if (id === undefined)
|
|
422
|
+
ids.set(key, (id = ids.size));
|
|
423
|
+
welded.push(id);
|
|
424
|
+
}
|
|
425
|
+
const edges = new Map();
|
|
426
|
+
for (let i = 0; i < indices.length; i += 3) {
|
|
427
|
+
const ia = indices[i], ib = indices[i + 1], ic = indices[i + 2];
|
|
428
|
+
const normal = unit(cross([p[ib * 3] - p[ia * 3], p[ib * 3 + 1] - p[ia * 3 + 1], p[ib * 3 + 2] - p[ia * 3 + 2]], [p[ic * 3] - p[ia * 3], p[ic * 3 + 1] - p[ia * 3 + 1], p[ic * 3 + 2] - p[ia * 3 + 2]]));
|
|
429
|
+
for (const [a, b] of [
|
|
430
|
+
[ia, ib],
|
|
431
|
+
[ib, ic],
|
|
432
|
+
[ic, ia]
|
|
433
|
+
]) {
|
|
434
|
+
const wa = welded[a], wb = welded[b];
|
|
435
|
+
if (wa === wb)
|
|
436
|
+
continue;
|
|
437
|
+
const key = wa < wb ? wa + '_' + wb : wb + '_' + wa, existing = edges.get(key);
|
|
438
|
+
if (!existing)
|
|
439
|
+
edges.set(key, { a, b, normal, shared: false, sharp: false });
|
|
440
|
+
else {
|
|
441
|
+
existing.shared = true;
|
|
442
|
+
if (existing.normal[0] * normal[0] + existing.normal[1] * normal[1] + existing.normal[2] * normal[2] <= limit)
|
|
443
|
+
existing.sharp = true;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
for (const edge of edges.values()) {
|
|
448
|
+
if (edge.shared && !edge.sharp)
|
|
449
|
+
continue;
|
|
450
|
+
positions.push(p[edge.a * 3], p[edge.a * 3 + 1], p[edge.a * 3 + 2], p[edge.b * 3], p[edge.b * 3 + 1], p[edge.b * 3 + 2]);
|
|
451
|
+
}
|
|
452
|
+
return lineGeometry(positions);
|
|
453
|
+
}
|
|
454
|
+
function cloneArray(data, length) {
|
|
455
|
+
return new data.constructor(length);
|
|
456
|
+
}
|
|
457
|
+
/** Copy with every triangle owning its vertices, as needed for per-face data. */
|
|
458
|
+
export function toNonIndexedGeometry3D(geometry) {
|
|
459
|
+
if (!(geometry instanceof Geometry3D))
|
|
460
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'geometry');
|
|
461
|
+
const index = geometry.index?.data, out = new Geometry3D();
|
|
462
|
+
out.topology = geometry.topology;
|
|
463
|
+
out.name = geometry.name;
|
|
464
|
+
for (const [name, attribute] of geometry.attributes) {
|
|
465
|
+
if (!index) {
|
|
466
|
+
out.setAttribute(name, new Attribute3D(attribute.data.slice(), attribute.itemSize, attribute.normalized));
|
|
467
|
+
continue;
|
|
468
|
+
}
|
|
469
|
+
const size = attribute.itemSize, data = cloneArray(attribute.data, index.length * size);
|
|
470
|
+
for (let i = 0; i < index.length; i++)
|
|
471
|
+
for (let k = 0; k < size; k++)
|
|
472
|
+
data[i * size + k] = attribute.data[index[i] * size + k];
|
|
473
|
+
out.setAttribute(name, new Attribute3D(data, size, attribute.normalized));
|
|
474
|
+
}
|
|
475
|
+
for (const group of geometry.groups)
|
|
476
|
+
out.addGroup(group.start, group.count, group.materialIndex);
|
|
477
|
+
return out;
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Join geometries that share the same attribute set into one. With
|
|
481
|
+
* `useGroups`, each input becomes a material group in order.
|
|
482
|
+
*/
|
|
483
|
+
export function mergeGeometries3D(geometries, useGroups = false) {
|
|
484
|
+
if (!Array.isArray(geometries) || geometries.length === 0)
|
|
485
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'geometries');
|
|
486
|
+
const first = geometries[0], names = [...first.attributes.keys()], out = new Geometry3D();
|
|
487
|
+
out.topology = first.topology;
|
|
488
|
+
let vertexTotal = 0, indexTotal = 0;
|
|
489
|
+
for (const geometry of geometries) {
|
|
490
|
+
if (geometry.topology !== first.topology ||
|
|
491
|
+
geometry.attributes.size !== names.length ||
|
|
492
|
+
(geometry.index === undefined) !== (first.index === undefined))
|
|
493
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'geometries differ in layout');
|
|
494
|
+
for (const name of names) {
|
|
495
|
+
const a = geometry.getAttribute(name), b = first.getAttribute(name);
|
|
496
|
+
if (!a || a.itemSize !== b.itemSize || a.data.constructor !== b.data.constructor)
|
|
497
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'attribute ' + name);
|
|
498
|
+
}
|
|
499
|
+
vertexTotal += geometry.getAttribute('position').count;
|
|
500
|
+
indexTotal += geometry.index?.data.length ?? 0;
|
|
501
|
+
}
|
|
502
|
+
for (const name of names) {
|
|
503
|
+
const model = first.getAttribute(name), data = cloneArray(model.data, vertexTotal * model.itemSize);
|
|
504
|
+
let offset = 0;
|
|
505
|
+
for (const geometry of geometries) {
|
|
506
|
+
const source = geometry.getAttribute(name).data;
|
|
507
|
+
data.set(source, offset);
|
|
508
|
+
offset += source.length;
|
|
509
|
+
}
|
|
510
|
+
out.setAttribute(name, new Attribute3D(data, model.itemSize, model.normalized));
|
|
511
|
+
}
|
|
512
|
+
let vertexOffset = 0, drawOffset = 0;
|
|
513
|
+
const index = first.index
|
|
514
|
+
? vertexTotal > 65535
|
|
515
|
+
? new Uint32Array(indexTotal)
|
|
516
|
+
: new Uint16Array(indexTotal)
|
|
517
|
+
: undefined;
|
|
518
|
+
for (const geometry of geometries) {
|
|
519
|
+
const vertices = geometry.getAttribute('position').count, source = geometry.index?.data, drawCount = source ? source.length : vertices;
|
|
520
|
+
if (index && source)
|
|
521
|
+
for (let i = 0; i < source.length; i++)
|
|
522
|
+
index[drawOffset + i] = source[i] + vertexOffset;
|
|
523
|
+
if (useGroups)
|
|
524
|
+
out.addGroup(drawOffset, drawCount, geometries.indexOf(geometry));
|
|
525
|
+
vertexOffset += vertices;
|
|
526
|
+
drawOffset += drawCount;
|
|
527
|
+
}
|
|
528
|
+
if (index)
|
|
529
|
+
out.setIndex(index);
|
|
530
|
+
return out;
|
|
531
|
+
}
|
|
532
|
+
/** Weld vertices whose every attribute matches within `tolerance`, producing an indexed geometry. */
|
|
533
|
+
export function mergeVertices3D(geometry, tolerance = 1e-4) {
|
|
534
|
+
if (!(geometry instanceof Geometry3D) || !(tolerance > 0))
|
|
535
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'geometry');
|
|
536
|
+
const position = geometry.getAttribute('position');
|
|
537
|
+
if (!position)
|
|
538
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'geometry positions');
|
|
539
|
+
const attributes = [...geometry.attributes], source = geometry.index?.data, total = source ? source.length : position.count;
|
|
540
|
+
const ids = new Map(), remap = [], kept = [], scale = 1 / tolerance;
|
|
541
|
+
for (let i = 0; i < position.count; i++) {
|
|
542
|
+
let key = '';
|
|
543
|
+
for (const [, attribute] of attributes)
|
|
544
|
+
for (let k = 0; k < attribute.itemSize; k++)
|
|
545
|
+
key += Math.round(attribute.data[i * attribute.itemSize + k] * scale) + ',';
|
|
546
|
+
let id = ids.get(key);
|
|
547
|
+
if (id === undefined) {
|
|
548
|
+
ids.set(key, (id = kept.length));
|
|
549
|
+
kept.push(i);
|
|
550
|
+
}
|
|
551
|
+
remap.push(id);
|
|
552
|
+
}
|
|
553
|
+
const out = new Geometry3D();
|
|
554
|
+
out.topology = geometry.topology;
|
|
555
|
+
out.name = geometry.name;
|
|
556
|
+
for (const [name, attribute] of attributes) {
|
|
557
|
+
const size = attribute.itemSize, data = cloneArray(attribute.data, kept.length * size);
|
|
558
|
+
kept.forEach((from, to) => {
|
|
559
|
+
for (let k = 0; k < size; k++)
|
|
560
|
+
data[to * size + k] = attribute.data[from * size + k];
|
|
561
|
+
});
|
|
562
|
+
out.setAttribute(name, new Attribute3D(data, size, attribute.normalized));
|
|
563
|
+
}
|
|
564
|
+
const index = kept.length > 65535 ? new Uint32Array(total) : new Uint16Array(total);
|
|
565
|
+
for (let i = 0; i < total; i++)
|
|
566
|
+
index[i] = remap[source ? source[i] : i];
|
|
567
|
+
out.setIndex(index);
|
|
568
|
+
for (const group of geometry.groups)
|
|
569
|
+
out.addGroup(group.start, group.count, group.materialIndex);
|
|
570
|
+
return out;
|
|
571
|
+
}
|
|
572
|
+
/** Bake a 4x4 transform into positions, normals and tangents, in place. */
|
|
573
|
+
export function transformGeometry3D(geometry, matrix) {
|
|
574
|
+
if (!(geometry instanceof Geometry3D) || !matrix || matrix.length !== 16)
|
|
575
|
+
throw new World3DError('WORLD3D_INPUT_INVALID', 'transform');
|
|
576
|
+
const m = matrix, position = geometry.getAttribute('position');
|
|
577
|
+
if (position) {
|
|
578
|
+
const d = position.data;
|
|
579
|
+
for (let i = 0; i < d.length; i += 3) {
|
|
580
|
+
const x = d[i], y = d[i + 1], z = d[i + 2];
|
|
581
|
+
d[i] = m[0] * x + m[4] * y + m[8] * z + m[12];
|
|
582
|
+
d[i + 1] = m[1] * x + m[5] * y + m[9] * z + m[13];
|
|
583
|
+
d[i + 2] = m[2] * x + m[6] * y + m[10] * z + m[14];
|
|
584
|
+
}
|
|
585
|
+
position.touch();
|
|
586
|
+
}
|
|
587
|
+
const n = mat3NormalFromMat4(new Float32Array(9), m);
|
|
588
|
+
for (const name of ['normal', 'tangent']) {
|
|
589
|
+
const attribute = geometry.getAttribute(name);
|
|
590
|
+
if (!attribute)
|
|
591
|
+
continue;
|
|
592
|
+
// Normals use the inverse transpose; tangents follow the surface, so they use the matrix itself.
|
|
593
|
+
const d = attribute.data, size = attribute.itemSize, k = name === 'normal' ? n : [m[0], m[1], m[2], m[4], m[5], m[6], m[8], m[9], m[10]];
|
|
594
|
+
for (let i = 0; i < d.length; i += size) {
|
|
595
|
+
const x = d[i], y = d[i + 1], z = d[i + 2], nx = k[0] * x + k[3] * y + k[6] * z, ny = k[1] * x + k[4] * y + k[7] * z, nz = k[2] * x + k[5] * y + k[8] * z, length = Math.hypot(nx, ny, nz) || 1;
|
|
596
|
+
d[i] = nx / length;
|
|
597
|
+
d[i + 1] = ny / length;
|
|
598
|
+
d[i + 2] = nz / length;
|
|
599
|
+
}
|
|
600
|
+
attribute.touch();
|
|
601
|
+
}
|
|
602
|
+
geometry.invalidateBounds();
|
|
603
|
+
return geometry;
|
|
604
|
+
}
|
|
605
|
+
//# sourceMappingURL=geometries3D.js.map
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Geometry3D } from './Geometry3D.js';
|
|
2
|
+
import { Material3D } from './Material3D.js';
|
|
3
|
+
import type { ColorInput3D } from './Material3D.js';
|
|
4
|
+
import { Mesh3D } from './Mesh3D.js';
|
|
5
|
+
import { Texture3D } from './Texture3D.js';
|
|
6
|
+
import type { TextureSource3D } from './Texture3D.js';
|
|
7
|
+
import { Object3D } from './Object3D.js';
|
|
8
|
+
/** Square grid of lines on the XZ plane, centered at the origin. */
|
|
9
|
+
export declare function createGridGeometry3D(size?: number, divisions?: number): Geometry3D;
|
|
10
|
+
/** Three colored segments from the origin along +X (red), +Y (green) and +Z (blue). */
|
|
11
|
+
export declare function createAxesGeometry3D(length?: number): Geometry3D;
|
|
12
|
+
/** The twelve edges of an axis-aligned box given as [minX, minY, minZ, maxX, maxY, maxZ]. */
|
|
13
|
+
export declare function createBoxEdgesGeometry3D(box: ArrayLike<number>): Geometry3D;
|
|
14
|
+
/** Unlit line or point material; pair it with a 'lines', 'line-strip' or 'points' geometry. */
|
|
15
|
+
export declare function createLineMaterial3D(color?: ColorInput3D, vertexColors?: boolean): Material3D;
|
|
16
|
+
/** Ready-made grid node for editors and debug views. */
|
|
17
|
+
export declare function createGridHelper3D(size?: number, divisions?: number, color?: ColorInput3D): Mesh3D;
|
|
18
|
+
/** Ready-made axes node colored X red, Y green, Z blue. */
|
|
19
|
+
export declare function createAxesHelper3D(length?: number): Mesh3D;
|
|
20
|
+
/**
|
|
21
|
+
* Shows exactly one child depending on the distance to the camera. Levels are
|
|
22
|
+
* kept sorted by distance; the render list calls select() once per frame.
|
|
23
|
+
*/
|
|
24
|
+
export declare class Lod3D extends Object3D {
|
|
25
|
+
#private;
|
|
26
|
+
/** Index of the level shown by the last select(), or -1 before the first. */
|
|
27
|
+
currentLevel: number;
|
|
28
|
+
constructor();
|
|
29
|
+
get levels(): readonly {
|
|
30
|
+
readonly object: Object3D;
|
|
31
|
+
readonly distance: number;
|
|
32
|
+
}[];
|
|
33
|
+
/** Show `object` once the camera is at least `distance` world units away. */
|
|
34
|
+
addLevel(object: Object3D, distance?: number): this;
|
|
35
|
+
/** Pick the level for a camera at world position (x, y, z). */
|
|
36
|
+
select(x: number, y: number, z: number): void;
|
|
37
|
+
clone(): this;
|
|
38
|
+
}
|
|
39
|
+
export interface ScreenLayerOptions3D {
|
|
40
|
+
/** 'overlay' draws after the scene with blending; 'underlay' draws first and is covered by it. */
|
|
41
|
+
readonly order?: 'overlay' | 'underlay';
|
|
42
|
+
/** Multiplies the layer's alpha. */
|
|
43
|
+
readonly opacity?: number;
|
|
44
|
+
/** Re-upload the source every frame. Disable for layers that change rarely and call refreshSource() instead. */
|
|
45
|
+
readonly autoUpdate?: boolean;
|
|
46
|
+
/** Source rows start at the top, as canvases and images do. Defaults to true. */
|
|
47
|
+
readonly topRowFirst?: boolean;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Full-screen image drawn in the same pass as the 3D scene, typically the
|
|
51
|
+
* canvas of a 2D stage. An overlay is composited above the scene and an
|
|
52
|
+
* underlay beneath it, so interface, scene and backdrop share one surface.
|
|
53
|
+
*/
|
|
54
|
+
export declare class ScreenLayer3D extends Mesh3D {
|
|
55
|
+
readonly texture: Texture3D;
|
|
56
|
+
autoUpdate: boolean;
|
|
57
|
+
constructor(source: TextureSource3D, options?: ScreenLayerOptions3D);
|
|
58
|
+
/** Schedule a new upload of the source pixels. */
|
|
59
|
+
refreshSource(): void;
|
|
60
|
+
/** Release the layer's texture and material. The shared quad geometry stays alive. */
|
|
61
|
+
dispose(): void;
|
|
62
|
+
clone(): this;
|
|
63
|
+
}
|
|
64
|
+
export declare function createScreenLayer3D(source: TextureSource3D, options?: ScreenLayerOptions3D): ScreenLayer3D;
|
|
65
|
+
//# sourceMappingURL=helpers3D.d.ts.map
|