@lampdotdev/lamp 0.0.0-stage → 0.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +357 -2
- package/Resources/Devices/roku.json +410 -0
- package/Resources/Devices/xbox-one.json +367 -0
- package/Resources/GameKit/NOTICE.md +63 -0
- package/Resources/GameKit/apple/LampPage.swift +1646 -0
- package/Resources/GameKit/apple/LampPlayer.swift +46 -0
- package/Resources/GameKit/apple/LampWebApp.swift +63 -0
- package/Resources/GameKit/apple/LampWebGame.swift +87 -0
- package/Resources/GameKit/apple/Native.swift +12 -0
- package/Resources/GameKit/build.sh +55 -0
- package/Resources/GameKit/lamp_game.h +116 -0
- package/Resources/GameKit/lamp_host.h +19 -0
- package/Resources/GameKit/lamp_kit.cpp +61 -0
- package/Resources/GameKit/lamp_sound.cpp +455 -0
- package/Resources/GameKit/lamp_xbox.cpp +374 -0
- package/Resources/GameKit/libraries/HandmadeMath.h +3940 -0
- package/Resources/GameKit/libraries/cgltf.h +7240 -0
- package/Resources/GameKit/libraries/dr_mp3.h +5430 -0
- package/Resources/GameKit/libraries/dr_wav.h +9209 -0
- package/Resources/GameKit/libraries/sokol_debugtext.h +4754 -0
- package/Resources/GameKit/libraries/sokol_gfx.h +29558 -0
- package/Resources/GameKit/libraries/sokol_gl.h +4538 -0
- package/Resources/GameKit/libraries/sokol_log.h +335 -0
- package/Resources/GameKit/libraries/sokol_shape.h +1531 -0
- package/Resources/GameKit/libraries/stb_image.h +7988 -0
- package/Resources/GameKit/libraries/stb_vorbis.c +5584 -0
- package/Resources/GameKit/scaffold/Game/game.cpp +142 -0
- package/Resources/GameKit/scaffold/Game/scene.glsl +49 -0
- package/Resources/GameKit/scaffold-web/Web/game.js +31 -0
- package/Resources/GameKit/scaffold-web/Web/index.html +13 -0
- package/Resources/GameKit/scaffold-web/Web/making.js +33 -0
- package/Resources/GameKit/scaffold-web/Web/world.js +33 -0
- package/Resources/GameKit/web/lamp-game.js +3036 -0
- package/Resources/GameKit/web/lamp-phaser.js +128 -0
- package/Resources/WebHost/App.exe +0 -0
- package/Resources/WebHost/Microsoft.Web.WebView2.Core.dll +0 -0
- package/Resources/WebHost/WebView2-LICENSE.txt +27 -0
- package/Resources/WebHost/lamp_controllers.h +1506 -0
- package/Resources/WebHost/lamp_web_host.cpp +1173 -0
- package/Resources/WebLibraries/earlier.txt +318 -0
- package/Resources/WebLibraries/phaser/LICENSE.md +20 -0
- package/Resources/WebLibraries/phaser/NOTICE.md +2 -0
- package/Resources/WebLibraries/phaser/phaser.esm.min.js +1 -0
- package/Resources/WebLibraries/qrcode/LICENSE +21 -0
- package/Resources/WebLibraries/qrcode/NOTICE.md +4 -0
- package/Resources/WebLibraries/qrcode/qrcode.js +2297 -0
- package/Resources/WebLibraries/rapier/LICENSE +201 -0
- package/Resources/WebLibraries/rapier/NOTICE.md +3 -0
- package/Resources/WebLibraries/rapier/rapier.js +2 -0
- package/Resources/WebLibraries/three/LICENSE +21 -0
- package/Resources/WebLibraries/three/NOTICE.md +4 -0
- package/Resources/WebLibraries/three/addons/animation/AnimationClipCreator.js +168 -0
- package/Resources/WebLibraries/three/addons/animation/CCDIKSolver.js +607 -0
- package/Resources/WebLibraries/three/addons/controls/ArcballControls.js +3543 -0
- package/Resources/WebLibraries/three/addons/controls/DragControls.js +452 -0
- package/Resources/WebLibraries/three/addons/controls/FirstPersonControls.js +512 -0
- package/Resources/WebLibraries/three/addons/controls/FlyControls.js +384 -0
- package/Resources/WebLibraries/three/addons/controls/MapControls.js +116 -0
- package/Resources/WebLibraries/three/addons/controls/OrbitControls.js +1985 -0
- package/Resources/WebLibraries/three/addons/controls/PointerLockControls.js +264 -0
- package/Resources/WebLibraries/three/addons/controls/TrackballControls.js +1106 -0
- package/Resources/WebLibraries/three/addons/controls/TransformControls.js +2003 -0
- package/Resources/WebLibraries/three/addons/curves/CurveExtras.js +694 -0
- package/Resources/WebLibraries/three/addons/curves/NURBSCurve.js +169 -0
- package/Resources/WebLibraries/three/addons/curves/NURBSSurface.js +98 -0
- package/Resources/WebLibraries/three/addons/curves/NURBSUtils.js +532 -0
- package/Resources/WebLibraries/three/addons/curves/NURBSVolume.js +82 -0
- package/Resources/WebLibraries/three/addons/effects/AnaglyphEffect.js +274 -0
- package/Resources/WebLibraries/three/addons/effects/AsciiEffect.js +323 -0
- package/Resources/WebLibraries/three/addons/effects/OutlineEffect.js +489 -0
- package/Resources/WebLibraries/three/addons/effects/ParallaxBarrierEffect.js +155 -0
- package/Resources/WebLibraries/three/addons/effects/StereoEffect.js +91 -0
- package/Resources/WebLibraries/three/addons/environments/ColorEnvironment.js +59 -0
- package/Resources/WebLibraries/three/addons/environments/DebugEnvironment.js +102 -0
- package/Resources/WebLibraries/three/addons/environments/RoomEnvironment.js +185 -0
- package/Resources/WebLibraries/three/addons/geometries/BoxLineGeometry.js +92 -0
- package/Resources/WebLibraries/three/addons/geometries/ConvexGeometry.js +72 -0
- package/Resources/WebLibraries/three/addons/geometries/DecalGeometry.js +420 -0
- package/Resources/WebLibraries/three/addons/geometries/LoftGeometry.js +355 -0
- package/Resources/WebLibraries/three/addons/geometries/ParametricFunctions.js +100 -0
- package/Resources/WebLibraries/three/addons/geometries/ParametricGeometry.js +172 -0
- package/Resources/WebLibraries/three/addons/geometries/RoundedBoxGeometry.js +216 -0
- package/Resources/WebLibraries/three/addons/geometries/TeapotGeometry.js +689 -0
- package/Resources/WebLibraries/three/addons/geometries/TextGeometry.js +102 -0
- package/Resources/WebLibraries/three/addons/helpers/AnimationPathHelper.js +302 -0
- package/Resources/WebLibraries/three/addons/helpers/LightProbeGridHelper.js +166 -0
- package/Resources/WebLibraries/three/addons/helpers/LightProbeGridHelperWebGL.js +221 -0
- package/Resources/WebLibraries/three/addons/helpers/LightProbeHelper.js +166 -0
- package/Resources/WebLibraries/three/addons/helpers/LightProbeHelperGPU.js +102 -0
- package/Resources/WebLibraries/three/addons/helpers/OctreeHelper.js +109 -0
- package/Resources/WebLibraries/three/addons/helpers/PositionalAudioHelper.js +169 -0
- package/Resources/WebLibraries/three/addons/helpers/RapierHelper.js +59 -0
- package/Resources/WebLibraries/three/addons/helpers/RectAreaLightHelper.js +118 -0
- package/Resources/WebLibraries/three/addons/helpers/TextureHelper.js +265 -0
- package/Resources/WebLibraries/three/addons/helpers/TextureHelperGPU.js +214 -0
- package/Resources/WebLibraries/three/addons/helpers/VertexNormalsHelper.js +155 -0
- package/Resources/WebLibraries/three/addons/helpers/VertexTangentsHelper.js +133 -0
- package/Resources/WebLibraries/three/addons/helpers/ViewHelper.js +529 -0
- package/Resources/WebLibraries/three/addons/interactive/HTMLMesh.js +617 -0
- package/Resources/WebLibraries/three/addons/interactive/InteractiveGroup.js +224 -0
- package/Resources/WebLibraries/three/addons/interactive/SelectionBox.js +324 -0
- package/Resources/WebLibraries/three/addons/interactive/SelectionHelper.js +150 -0
- package/Resources/WebLibraries/three/addons/libs/fflate.module.js +2699 -0
- package/Resources/WebLibraries/three/addons/libs/lil-gui.module.min.js +8 -0
- package/Resources/WebLibraries/three/addons/libs/meshopt_decoder.module.js +196 -0
- package/Resources/WebLibraries/three/addons/libs/potpack.module.js +125 -0
- package/Resources/WebLibraries/three/addons/libs/stats.module.js +167 -0
- package/Resources/WebLibraries/three/addons/libs/tween.module.js +876 -0
- package/Resources/WebLibraries/three/addons/lighting/ClusteredLighting.js +153 -0
- package/Resources/WebLibraries/three/addons/lighting/DynamicLighting.js +82 -0
- package/Resources/WebLibraries/three/addons/lighting/LightMapper.js +295 -0
- package/Resources/WebLibraries/three/addons/lighting/LightProbeGrid.js +923 -0
- package/Resources/WebLibraries/three/addons/lighting/LightProbeGridUtils.js +107 -0
- package/Resources/WebLibraries/three/addons/lighting/LightProbeGridWebGL.js +846 -0
- package/Resources/WebLibraries/three/addons/lighting/vxgi/VXGIConeTracer.js +243 -0
- package/Resources/WebLibraries/three/addons/lighting/vxgi/VXGIIrradiance.js +43 -0
- package/Resources/WebLibraries/three/addons/lighting/vxgi/VXGINode.js +617 -0
- package/Resources/WebLibraries/three/addons/lighting/vxgi/VXGISceneCollector.js +793 -0
- package/Resources/WebLibraries/three/addons/lighting/vxgi/VXGIVolume.js +1440 -0
- package/Resources/WebLibraries/three/addons/lights/LightProbeGenerator.js +337 -0
- package/Resources/WebLibraries/three/addons/lights/RectAreaLightTexturesLib.js +127 -0
- package/Resources/WebLibraries/three/addons/lights/RectAreaLightUniformsLib.js +40 -0
- package/Resources/WebLibraries/three/addons/lights/SunLight.js +100 -0
- package/Resources/WebLibraries/three/addons/lights/SunLightNode.js +56 -0
- package/Resources/WebLibraries/three/addons/lights/SunLightShadow.js +319 -0
- package/Resources/WebLibraries/three/addons/lights/SunShadowNode.js +312 -0
- package/Resources/WebLibraries/three/addons/lines/Line2.js +56 -0
- package/Resources/WebLibraries/three/addons/lines/LineGeometry.js +157 -0
- package/Resources/WebLibraries/three/addons/lines/LineMaterial.js +742 -0
- package/Resources/WebLibraries/three/addons/lines/LineSegments2.js +434 -0
- package/Resources/WebLibraries/three/addons/lines/LineSegmentsGeometry.js +298 -0
- package/Resources/WebLibraries/three/addons/lines/Wireframe.js +108 -0
- package/Resources/WebLibraries/three/addons/lines/WireframeGeometry2.js +49 -0
- package/Resources/WebLibraries/three/addons/lines/webgpu/Line2.js +46 -0
- package/Resources/WebLibraries/three/addons/lines/webgpu/LineSegments2.js +419 -0
- package/Resources/WebLibraries/three/addons/lines/webgpu/Wireframe.js +86 -0
- package/Resources/WebLibraries/three/addons/loaders/EXRLoader.js +3411 -0
- package/Resources/WebLibraries/three/addons/loaders/FBXLoader.js +4660 -0
- package/Resources/WebLibraries/three/addons/loaders/FontLoader.js +262 -0
- package/Resources/WebLibraries/three/addons/loaders/GLTFLoader.js +5006 -0
- package/Resources/WebLibraries/three/addons/loaders/HDRLoader.js +463 -0
- package/Resources/WebLibraries/three/addons/loaders/MTLLoader.js +601 -0
- package/Resources/WebLibraries/three/addons/loaders/OBJLoader.js +961 -0
- package/Resources/WebLibraries/three/addons/loaders/PLYLoader.js +992 -0
- package/Resources/WebLibraries/three/addons/loaders/RGBELoader.js +18 -0
- package/Resources/WebLibraries/three/addons/loaders/STLLoader.js +423 -0
- package/Resources/WebLibraries/three/addons/loaders/SVGLoader.js +3297 -0
- package/Resources/WebLibraries/three/addons/loaders/TGALoader.js +539 -0
- package/Resources/WebLibraries/three/addons/loaders/UltraHDRLoader.js +757 -0
- package/Resources/WebLibraries/three/addons/math/Capsule.js +159 -0
- package/Resources/WebLibraries/three/addons/math/ColorConverter.js +62 -0
- package/Resources/WebLibraries/three/addons/math/ColorSpaces.js +147 -0
- package/Resources/WebLibraries/three/addons/math/ConvexHull.js +1695 -0
- package/Resources/WebLibraries/three/addons/math/ImprovedNoise.js +88 -0
- package/Resources/WebLibraries/three/addons/math/Lut.js +317 -0
- package/Resources/WebLibraries/three/addons/math/MeshSurfaceSampler.js +315 -0
- package/Resources/WebLibraries/three/addons/math/OBB.js +535 -0
- package/Resources/WebLibraries/three/addons/math/Octree.js +825 -0
- package/Resources/WebLibraries/three/addons/math/SimplexNoise.js +470 -0
- package/Resources/WebLibraries/three/addons/misc/ConvexObjectBreaker.js +539 -0
- package/Resources/WebLibraries/three/addons/misc/GPUComputationRenderer.js +508 -0
- package/Resources/WebLibraries/three/addons/misc/Gyroscope.js +78 -0
- package/Resources/WebLibraries/three/addons/misc/MorphAnimMesh.js +119 -0
- package/Resources/WebLibraries/three/addons/misc/MorphBlendMesh.js +425 -0
- package/Resources/WebLibraries/three/addons/misc/ProgressiveLightMap.js +370 -0
- package/Resources/WebLibraries/three/addons/misc/ProgressiveLightMapGPU.js +322 -0
- package/Resources/WebLibraries/three/addons/misc/RollerCoaster.js +661 -0
- package/Resources/WebLibraries/three/addons/misc/Sculptor.js +1679 -0
- package/Resources/WebLibraries/three/addons/misc/SculptorMesh.js +1504 -0
- package/Resources/WebLibraries/three/addons/misc/SculptorTools.js +1180 -0
- package/Resources/WebLibraries/three/addons/misc/SculptorUtils.js +345 -0
- package/Resources/WebLibraries/three/addons/misc/TileCreasedNormalsPlugin.js +270 -0
- package/Resources/WebLibraries/three/addons/misc/TubePainter.js +611 -0
- package/Resources/WebLibraries/three/addons/misc/Volume.js +520 -0
- package/Resources/WebLibraries/three/addons/misc/VolumeSlice.js +275 -0
- package/Resources/WebLibraries/three/addons/modifiers/CurveModifier.js +374 -0
- package/Resources/WebLibraries/three/addons/modifiers/CurveModifierGPU.js +256 -0
- package/Resources/WebLibraries/three/addons/modifiers/EdgeSplitModifier.js +299 -0
- package/Resources/WebLibraries/three/addons/modifiers/TessellateModifier.js +340 -0
- package/Resources/WebLibraries/three/addons/objects/GroundedSkybox.js +69 -0
- package/Resources/WebLibraries/three/addons/objects/Lensflare.js +489 -0
- package/Resources/WebLibraries/three/addons/objects/LensflareMesh.js +376 -0
- package/Resources/WebLibraries/three/addons/objects/MarchingCubes.js +1261 -0
- package/Resources/WebLibraries/three/addons/objects/Reflector.js +390 -0
- package/Resources/WebLibraries/three/addons/objects/ReflectorForSSRPass.js +393 -0
- package/Resources/WebLibraries/three/addons/objects/Refractor.js +389 -0
- package/Resources/WebLibraries/three/addons/objects/ShadowMesh.js +130 -0
- package/Resources/WebLibraries/three/addons/objects/Sky.js +342 -0
- package/Resources/WebLibraries/three/addons/objects/SkyMesh.js +403 -0
- package/Resources/WebLibraries/three/addons/objects/Water.js +374 -0
- package/Resources/WebLibraries/three/addons/objects/Water2.js +403 -0
- package/Resources/WebLibraries/three/addons/objects/Water2Mesh.js +199 -0
- package/Resources/WebLibraries/three/addons/objects/WaterMesh.js +194 -0
- package/Resources/WebLibraries/three/addons/postprocessing/AfterimagePass.js +187 -0
- package/Resources/WebLibraries/three/addons/postprocessing/BloomPass.js +274 -0
- package/Resources/WebLibraries/three/addons/postprocessing/BokehPass.js +218 -0
- package/Resources/WebLibraries/three/addons/postprocessing/ClearPass.js +97 -0
- package/Resources/WebLibraries/three/addons/postprocessing/CubeTexturePass.js +146 -0
- package/Resources/WebLibraries/three/addons/postprocessing/DotScreenPass.js +114 -0
- package/Resources/WebLibraries/three/addons/postprocessing/EffectComposer.js +365 -0
- package/Resources/WebLibraries/three/addons/postprocessing/FXAAPass.js +40 -0
- package/Resources/WebLibraries/three/addons/postprocessing/FilmPass.js +113 -0
- package/Resources/WebLibraries/three/addons/postprocessing/GTAOPass.js +735 -0
- package/Resources/WebLibraries/three/addons/postprocessing/GlitchPass.js +177 -0
- package/Resources/WebLibraries/three/addons/postprocessing/HalftonePass.js +134 -0
- package/Resources/WebLibraries/three/addons/postprocessing/LUTPass.js +138 -0
- package/Resources/WebLibraries/three/addons/postprocessing/MaskPass.js +195 -0
- package/Resources/WebLibraries/three/addons/postprocessing/OutlinePass.js +776 -0
- package/Resources/WebLibraries/three/addons/postprocessing/OutputPass.js +148 -0
- package/Resources/WebLibraries/three/addons/postprocessing/Pass.js +191 -0
- package/Resources/WebLibraries/three/addons/postprocessing/RenderPass.js +193 -0
- package/Resources/WebLibraries/three/addons/postprocessing/RenderPixelatedPass.js +314 -0
- package/Resources/WebLibraries/three/addons/postprocessing/RenderTransitionPass.js +267 -0
- package/Resources/WebLibraries/three/addons/postprocessing/SAOPass.js +407 -0
- package/Resources/WebLibraries/three/addons/postprocessing/SMAAPass.js +230 -0
- package/Resources/WebLibraries/three/addons/postprocessing/SSAARenderPass.js +313 -0
- package/Resources/WebLibraries/three/addons/postprocessing/SSAOPass.js +527 -0
- package/Resources/WebLibraries/three/addons/postprocessing/SSRPass.js +858 -0
- package/Resources/WebLibraries/three/addons/postprocessing/SavePass.js +132 -0
- package/Resources/WebLibraries/three/addons/postprocessing/ShaderPass.js +135 -0
- package/Resources/WebLibraries/three/addons/postprocessing/TAARenderPass.js +243 -0
- package/Resources/WebLibraries/three/addons/postprocessing/TexturePass.js +131 -0
- package/Resources/WebLibraries/three/addons/postprocessing/UnrealBloomPass.js +541 -0
- package/Resources/WebLibraries/three/addons/shaders/ACESFilmicToneMappingShader.js +96 -0
- package/Resources/WebLibraries/three/addons/shaders/AfterimageShader.js +63 -0
- package/Resources/WebLibraries/three/addons/shaders/BasicShader.js +36 -0
- package/Resources/WebLibraries/three/addons/shaders/BleachBypassShader.js +68 -0
- package/Resources/WebLibraries/three/addons/shaders/BlendShader.js +56 -0
- package/Resources/WebLibraries/three/addons/shaders/BokehShader.js +151 -0
- package/Resources/WebLibraries/three/addons/shaders/BokehShader2.js +404 -0
- package/Resources/WebLibraries/three/addons/shaders/BrightnessContrastShader.js +62 -0
- package/Resources/WebLibraries/three/addons/shaders/ColorCorrectionShader.js +59 -0
- package/Resources/WebLibraries/three/addons/shaders/ColorifyShader.js +57 -0
- package/Resources/WebLibraries/three/addons/shaders/ConvolutionShader.js +74 -0
- package/Resources/WebLibraries/three/addons/shaders/CopyShader.js +52 -0
- package/Resources/WebLibraries/three/addons/shaders/DOFMipMapShader.js +63 -0
- package/Resources/WebLibraries/three/addons/shaders/DepthLimitedBlurShader.js +183 -0
- package/Resources/WebLibraries/three/addons/shaders/DigitalGlitch.js +104 -0
- package/Resources/WebLibraries/three/addons/shaders/DotScreenShader.js +75 -0
- package/Resources/WebLibraries/three/addons/shaders/ExposureShader.js +51 -0
- package/Resources/WebLibraries/three/addons/shaders/FXAAShader.js +298 -0
- package/Resources/WebLibraries/three/addons/shaders/FilmShader.js +73 -0
- package/Resources/WebLibraries/three/addons/shaders/FocusShader.js +94 -0
- package/Resources/WebLibraries/three/addons/shaders/FreiChenShader.js +103 -0
- package/Resources/WebLibraries/three/addons/shaders/GTAOShader.js +437 -0
- package/Resources/WebLibraries/three/addons/shaders/GammaCorrectionShader.js +52 -0
- package/Resources/WebLibraries/three/addons/shaders/HalftoneShader.js +332 -0
- package/Resources/WebLibraries/three/addons/shaders/HorizontalBlurShader.js +68 -0
- package/Resources/WebLibraries/three/addons/shaders/HorizontalTiltShiftShader.js +70 -0
- package/Resources/WebLibraries/three/addons/shaders/HueSaturationShader.js +74 -0
- package/Resources/WebLibraries/three/addons/shaders/KaleidoShader.js +65 -0
- package/Resources/WebLibraries/three/addons/shaders/LuminosityHighPassShader.js +68 -0
- package/Resources/WebLibraries/three/addons/shaders/LuminosityShader.js +54 -0
- package/Resources/WebLibraries/three/addons/shaders/MirrorShader.js +62 -0
- package/Resources/WebLibraries/three/addons/shaders/NormalMapShader.js +60 -0
- package/Resources/WebLibraries/three/addons/shaders/OutputShader.js +103 -0
- package/Resources/WebLibraries/three/addons/shaders/PoissonDenoiseShader.js +230 -0
- package/Resources/WebLibraries/three/addons/shaders/RGBShiftShader.js +61 -0
- package/Resources/WebLibraries/three/addons/shaders/SAOShader.js +201 -0
- package/Resources/WebLibraries/three/addons/shaders/SMAAShader.js +489 -0
- package/Resources/WebLibraries/three/addons/shaders/SSAOShader.js +331 -0
- package/Resources/WebLibraries/three/addons/shaders/SSRShader.js +396 -0
- package/Resources/WebLibraries/three/addons/shaders/SepiaShader.js +57 -0
- package/Resources/WebLibraries/three/addons/shaders/SobelOperatorShader.js +98 -0
- package/Resources/WebLibraries/three/addons/shaders/SubsurfaceScatteringShader.js +95 -0
- package/Resources/WebLibraries/three/addons/shaders/TechnicolorShader.js +51 -0
- package/Resources/WebLibraries/three/addons/shaders/ToonShader.js +349 -0
- package/Resources/WebLibraries/three/addons/shaders/TriangleBlurShader.js +79 -0
- package/Resources/WebLibraries/three/addons/shaders/UnpackDepthRGBAShader.js +60 -0
- package/Resources/WebLibraries/three/addons/shaders/VelocityShader.js +137 -0
- package/Resources/WebLibraries/three/addons/shaders/VerticalBlurShader.js +66 -0
- package/Resources/WebLibraries/three/addons/shaders/VerticalTiltShiftShader.js +70 -0
- package/Resources/WebLibraries/three/addons/shaders/VignetteShader.js +56 -0
- package/Resources/WebLibraries/three/addons/shaders/VolumeShader.js +285 -0
- package/Resources/WebLibraries/three/addons/shaders/WaterRefractionShader.js +106 -0
- package/Resources/WebLibraries/three/addons/textures/FlakesTexture.js +54 -0
- package/Resources/WebLibraries/three/addons/tsl/WebGLNodesHandler.js +607 -0
- package/Resources/WebLibraries/three/addons/tsl/display/AfterImageNode.js +256 -0
- package/Resources/WebLibraries/three/addons/tsl/display/AnaglyphPassNode.js +550 -0
- package/Resources/WebLibraries/three/addons/tsl/display/BilateralBlurNode.js +377 -0
- package/Resources/WebLibraries/three/addons/tsl/display/BleachBypass.js +33 -0
- package/Resources/WebLibraries/three/addons/tsl/display/BloomNode.js +599 -0
- package/Resources/WebLibraries/three/addons/tsl/display/CRT.js +150 -0
- package/Resources/WebLibraries/three/addons/tsl/display/ChromaticAberrationNode.js +163 -0
- package/Resources/WebLibraries/three/addons/tsl/display/DenoiseNode.js +354 -0
- package/Resources/WebLibraries/three/addons/tsl/display/DepthOfFieldNode.js +572 -0
- package/Resources/WebLibraries/three/addons/tsl/display/DotScreenNode.js +104 -0
- package/Resources/WebLibraries/three/addons/tsl/display/FSR1Node.js +481 -0
- package/Resources/WebLibraries/three/addons/tsl/display/FXAANode.js +357 -0
- package/Resources/WebLibraries/three/addons/tsl/display/FilmNode.js +101 -0
- package/Resources/WebLibraries/three/addons/tsl/display/GTAONode.js +727 -0
- package/Resources/WebLibraries/three/addons/tsl/display/GaussianBlurNode.js +412 -0
- package/Resources/WebLibraries/three/addons/tsl/display/GodraysNode.js +604 -0
- package/Resources/WebLibraries/three/addons/tsl/display/ImportanceSampledEnvironment.js +564 -0
- package/Resources/WebLibraries/three/addons/tsl/display/LensflareNode.js +282 -0
- package/Resources/WebLibraries/three/addons/tsl/display/Lut3DNode.js +109 -0
- package/Resources/WebLibraries/three/addons/tsl/display/MotionBlur.js +33 -0
- package/Resources/WebLibraries/three/addons/tsl/display/OITPassNode.js +341 -0
- package/Resources/WebLibraries/three/addons/tsl/display/OutlineNode.js +916 -0
- package/Resources/WebLibraries/three/addons/tsl/display/ParallaxBarrierPassNode.js +90 -0
- package/Resources/WebLibraries/three/addons/tsl/display/PixelationPassNode.js +227 -0
- package/Resources/WebLibraries/three/addons/tsl/display/RGBShiftNode.js +96 -0
- package/Resources/WebLibraries/three/addons/tsl/display/RecurrentDenoiseNode.js +812 -0
- package/Resources/WebLibraries/three/addons/tsl/display/RetroPassNode.js +263 -0
- package/Resources/WebLibraries/three/addons/tsl/display/SMAANode.js +729 -0
- package/Resources/WebLibraries/three/addons/tsl/display/SSAAPassNode.js +344 -0
- package/Resources/WebLibraries/three/addons/tsl/display/SSAONode.js +422 -0
- package/Resources/WebLibraries/three/addons/tsl/display/SSGINode.js +698 -0
- package/Resources/WebLibraries/three/addons/tsl/display/SSRNode.js +1430 -0
- package/Resources/WebLibraries/three/addons/tsl/display/SSSNode.js +479 -0
- package/Resources/WebLibraries/three/addons/tsl/display/Sepia.js +24 -0
- package/Resources/WebLibraries/three/addons/tsl/display/Shape.js +29 -0
- package/Resources/WebLibraries/three/addons/tsl/display/SharpenNode.js +284 -0
- package/Resources/WebLibraries/three/addons/tsl/display/SobelOperatorNode.js +168 -0
- package/Resources/WebLibraries/three/addons/tsl/display/StereoCompositePassNode.js +190 -0
- package/Resources/WebLibraries/three/addons/tsl/display/StereoPassNode.js +117 -0
- package/Resources/WebLibraries/three/addons/tsl/display/TAAUNode.js +700 -0
- package/Resources/WebLibraries/three/addons/tsl/display/TRAANode.js +609 -0
- package/Resources/WebLibraries/three/addons/tsl/display/TemporalReprojectNode.js +1024 -0
- package/Resources/WebLibraries/three/addons/tsl/display/TransitionNode.js +141 -0
- package/Resources/WebLibraries/three/addons/tsl/display/boxBlur.js +65 -0
- package/Resources/WebLibraries/three/addons/tsl/display/depthAwareBlend.js +80 -0
- package/Resources/WebLibraries/three/addons/tsl/display/depthAwareBlur.js +63 -0
- package/Resources/WebLibraries/three/addons/tsl/display/hashBlur.js +55 -0
- package/Resources/WebLibraries/three/addons/tsl/display/lensDirt.js +30 -0
- package/Resources/WebLibraries/three/addons/tsl/display/radialBlur.js +68 -0
- package/Resources/WebLibraries/three/addons/tsl/lighting/ClusteredLightsNode.js +994 -0
- package/Resources/WebLibraries/three/addons/tsl/lighting/DynamicLightsNode.js +201 -0
- package/Resources/WebLibraries/three/addons/tsl/lighting/LightProbeGridNode.js +183 -0
- package/Resources/WebLibraries/three/addons/tsl/lighting/data/AmbientLightDataNode.js +67 -0
- package/Resources/WebLibraries/three/addons/tsl/lighting/data/DirectionalLightDataNode.js +117 -0
- package/Resources/WebLibraries/three/addons/tsl/lighting/data/HemisphereLightDataNode.js +105 -0
- package/Resources/WebLibraries/three/addons/tsl/lighting/data/PointLightDataNode.js +140 -0
- package/Resources/WebLibraries/three/addons/tsl/lighting/data/SpotLightDataNode.js +167 -0
- package/Resources/WebLibraries/three/addons/tsl/math/Bayer.js +84 -0
- package/Resources/WebLibraries/three/addons/tsl/math/curlNoise.js +107 -0
- package/Resources/WebLibraries/three/addons/tsl/math/voronoiNoise.js +112 -0
- package/Resources/WebLibraries/three/addons/tsl/shadows/TileShadowNode.js +542 -0
- package/Resources/WebLibraries/three/addons/tsl/shadows/TileShadowNodeHelper.js +212 -0
- package/Resources/WebLibraries/three/addons/tsl/utils/GroundedSkybox.js +62 -0
- package/Resources/WebLibraries/three/addons/tsl/utils/RNoise.js +51 -0
- package/Resources/WebLibraries/three/addons/tsl/utils/Raymarching.js +70 -0
- package/Resources/WebLibraries/three/addons/tsl/utils/SoftParticles.js +53 -0
- package/Resources/WebLibraries/three/addons/tsl/utils/SpecularHelpers.js +302 -0
- package/Resources/WebLibraries/three/addons/tsl/utils/TAAUtils.js +184 -0
- package/Resources/WebLibraries/three/addons/utils/BufferGeometryUtils.js +1523 -0
- package/Resources/WebLibraries/three/addons/utils/CameraUtils.js +82 -0
- package/Resources/WebLibraries/three/addons/utils/ColorUtils.js +76 -0
- package/Resources/WebLibraries/three/addons/utils/GaussianSplatUtils.js +229 -0
- package/Resources/WebLibraries/three/addons/utils/GeometryCompressionUtils.js +547 -0
- package/Resources/WebLibraries/three/addons/utils/GeometryUtils.js +226 -0
- package/Resources/WebLibraries/three/addons/utils/LDrawUtils.js +211 -0
- package/Resources/WebLibraries/three/addons/utils/SceneOptimizer.js +459 -0
- package/Resources/WebLibraries/three/addons/utils/SceneUtils.js +363 -0
- package/Resources/WebLibraries/three/addons/utils/ShadowMapViewer.js +244 -0
- package/Resources/WebLibraries/three/addons/utils/ShadowMapViewerGPU.js +233 -0
- package/Resources/WebLibraries/three/addons/utils/SkeletonUtils.js +496 -0
- package/Resources/WebLibraries/three/addons/utils/SortUtils.js +175 -0
- package/Resources/WebLibraries/three/addons/utils/UVsDebug.js +173 -0
- package/Resources/WebLibraries/three/addons/utils/WebGLTextureUtils.js +115 -0
- package/Resources/WebLibraries/three/addons/utils/WebGPUTextureUtils.js +81 -0
- package/Resources/WebLibraries/three/addons/utils/WorkerPool.js +167 -0
- package/Resources/WebLibraries/three/addons/utils/unwrapUVs.js +865 -0
- package/Resources/WebLibraries/three/three.core.js +61162 -0
- package/Resources/WebLibraries/three/three.module.js +19537 -0
- package/Resources/WebLibraries/three/three.tsl.js +41903 -0
- package/Resources/WebLibraries/three/three.webgpu.js +53714 -0
- package/Resources/skills/2d-game/SKILL.md +305 -0
- package/Resources/skills/3d-game/SKILL.md +274 -0
- package/Resources/skills/accounts/SKILL.md +41 -0
- package/Resources/skills/android-design/SKILL.md +159 -0
- package/Resources/skills/app-ai/SKILL.md +154 -0
- package/Resources/skills/app-intents/SKILL.md +31 -0
- package/Resources/skills/app-kinds/SKILL.md +122 -0
- package/Resources/skills/apple-watch/SKILL.md +43 -0
- package/Resources/skills/assets/SKILL.md +183 -0
- package/Resources/skills/building-blocks/SKILL.md +97 -0
- package/Resources/skills/device-control/SKILL.md +56 -0
- package/Resources/skills/device-integrations/SKILL.md +278 -0
- package/Resources/skills/finder-files/SKILL.md +19 -0
- package/Resources/skills/game/SKILL.md +414 -0
- package/Resources/skills/game-3d/SKILL.md +12 -0
- package/Resources/skills/game-art/SKILL.md +11 -0
- package/Resources/skills/game-feel/SKILL.md +13 -0
- package/Resources/skills/game-levels/SKILL.md +12 -0
- package/Resources/skills/game-live/SKILL.md +12 -0
- package/Resources/skills/game-physics/SKILL.md +13 -0
- package/Resources/skills/game-playtest/SKILL.md +26 -0
- package/Resources/skills/game-ui/SKILL.md +278 -0
- package/Resources/skills/github-projects/SKILL.md +59 -0
- package/Resources/skills/icloud-sync/SKILL.md +30 -0
- package/Resources/skills/iphone-hardware/SKILL.md +57 -0
- package/Resources/skills/iphone-widgets/SKILL.md +53 -0
- package/Resources/skills/lg-developer-mode/SKILL.md +152 -0
- package/Resources/skills/mac-widgets/SKILL.md +60 -0
- package/Resources/skills/maps/SKILL.md +8 -0
- package/Resources/skills/menu-bar/SKILL.md +36 -0
- package/Resources/skills/more-apps/SKILL.md +53 -0
- package/Resources/skills/phone-controllers/SKILL.md +79 -0
- package/Resources/skills/phone-pages/SKILL.md +173 -0
- package/Resources/skills/roku-developer-mode/SKILL.md +106 -0
- package/Resources/skills/scene-3d/SKILL.md +27 -0
- package/Resources/skills/scripting/SKILL.md +17 -0
- package/Resources/skills/share-extension/SKILL.md +22 -0
- package/Resources/skills/tv-design/SKILL.md +72 -0
- package/Resources/skills/web-app/SKILL.md +136 -0
- package/Resources/skills/web-game/SKILL.md +95 -0
- package/Resources/skills/web-or-native/SKILL.md +103 -0
- package/Resources/skills/wish-links/SKILL.md +156 -0
- package/THIRD_PARTY_NOTICES.md +170 -0
- package/cli/android.mjs +941 -0
- package/cli/browser.mjs +268 -0
- package/cli/calls.mjs +390 -0
- package/cli/dev.mjs +773 -0
- package/cli/devices.mjs +984 -0
- package/cli/lamp.mjs +1016 -0
- package/cli/lampapp.mjs +332 -0
- package/cli/lamps/android-host/LampPageGateway.kt +345 -0
- package/cli/lamps/android-host/app/build.gradle.kts +40 -0
- package/cli/lamps/android-host/build.gradle.kts +4 -0
- package/cli/lamps/android-host/game/AndroidManifest.xml +33 -0
- package/cli/lamps/android-host/game/MainActivity.kt +173 -0
- package/cli/lamps/android-host/gradle/libs.versions.toml +39 -0
- package/cli/lamps/android-host/gradle.properties +8 -0
- package/cli/lamps/android-host/page/AndroidManifest.xml +35 -0
- package/cli/lamps/android-host/page/MainActivity.kt +193 -0
- package/cli/lamps/android-host/settings.gradle.kts +30 -0
- package/cli/lamps/android-host/tools.json +43 -0
- package/cli/lamps/lamp-controllers.js +2 -0
- package/cli/lamps/lamp-for-games.js +6863 -0
- package/cli/lamps/lamp.js +7023 -0
- package/cli/lamps/mac-starter/.lamp/meta.json +1 -0
- package/cli/lamps/mac-starter/APP.md +12 -0
- package/cli/lamps/mac-starter/Package.swift +8 -0
- package/cli/lamps/mac-starter/Sources/App.swift +11 -0
- package/cli/lamps/mac-starter/Sources/ContentView.swift +17 -0
- package/cli/lamps/mac-starter/Sources/LampSupport.swift +18097 -0
- package/cli/lamps/mac-starter/build.sh +336 -0
- package/cli/lamps/mac-starter/gitignore +3 -0
- package/cli/lamps/mac-starter/lamp-starter.json +6 -0
- package/cli/lamps/web-starter/APP.md +8 -0
- package/cli/lamps/web-starter/app.js +1 -0
- package/cli/lamps/web-starter/index.html +17 -0
- package/cli/lamps/web-starter/lamp-starter.json +5 -0
- package/cli/lamps/web-starter/lamp.js +7023 -0
- package/cli/lamps/web-starter/style.css +25 -0
- package/cli/link.mjs +138 -0
- package/cli/mac.mjs +621 -0
- package/cli/mdns.mjs +205 -0
- package/cli/msix.mjs +413 -0
- package/cli/network.mjs +209 -0
- package/cli/outside.mjs +140 -0
- package/cli/page.js +165 -0
- package/cli/place.mjs +298 -0
- package/cli/png.mjs +184 -0
- package/cli/share.mjs +202 -0
- package/cli/skill/SKILL.md +255 -0
- package/cli/skills.mjs +71 -0
- package/cli/state.mjs +173 -0
- package/cli/update.mjs +57 -0
- package/package.json +20 -4
- package/site/lib/quota.js +59 -0
- package/site/lib/shared-wishes.js +996 -0
|
@@ -0,0 +1,1504 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Portions adapted from SculptGL by Stéphane Ginier.
|
|
3
|
+
* Copyright (c) 2019 Stéphane GINIER
|
|
4
|
+
* Licensed under the MIT License; see ./SculptGL.LICENSE.txt.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
TRI_INDEX,
|
|
9
|
+
MAX_FLAG,
|
|
10
|
+
getMemory
|
|
11
|
+
} from './SculptorUtils.js';
|
|
12
|
+
|
|
13
|
+
const OCTREE_MAX_DEPTH = 8;
|
|
14
|
+
const OCTREE_MAX_FACES = 100;
|
|
15
|
+
// A depth-first walk retains at most seven siblings for each level.
|
|
16
|
+
const OCTREE_STACK = new Array( 1 + 7 * OCTREE_MAX_DEPTH ).fill( null );
|
|
17
|
+
const RELATIVE_WELD_TOLERANCE = 1e-7;
|
|
18
|
+
|
|
19
|
+
function queueLeaf( leaves, leaf ) {
|
|
20
|
+
|
|
21
|
+
if ( leaves === undefined || leaf._queuedForUpdate ) return;
|
|
22
|
+
leaf._queuedForUpdate = true;
|
|
23
|
+
leaves.push( leaf );
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function hashPosition( x, y, z ) {
|
|
28
|
+
|
|
29
|
+
let hash = Math.imul( x, 0x85ebca6b );
|
|
30
|
+
hash = Math.imul( hash ^ ( hash >>> 13 ) ^ y, 0xc2b2ae35 );
|
|
31
|
+
hash = Math.imul( hash ^ ( hash >>> 16 ) ^ z, 0x27d4eb2d );
|
|
32
|
+
return ( hash ^ ( hash >>> 15 ) ) >>> 0;
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function resetTagFlags( flags, activeCount ) {
|
|
37
|
+
|
|
38
|
+
for ( let i = 0; i < activeCount; i ++ ) {
|
|
39
|
+
|
|
40
|
+
if ( flags[ i ] >= 0 ) flags[ i ] = 0;
|
|
41
|
+
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
flags.fill( 0, activeCount );
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function readSourceElements( index, sourceVertexCount ) {
|
|
49
|
+
|
|
50
|
+
const elementCount = index ? index.count : sourceVertexCount;
|
|
51
|
+
|
|
52
|
+
if ( index && ( index.itemSize !== 1 || index.normalized ) ) {
|
|
53
|
+
|
|
54
|
+
throw new Error( 'SculptorMesh: The index must be a non-normalized scalar attribute.' );
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if ( index && typeof index.getX !== 'function' ) {
|
|
59
|
+
|
|
60
|
+
throw new Error( 'SculptorMesh: The index attribute must be CPU-accessible.' );
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if ( elementCount === 0 || elementCount % 3 !== 0 ) {
|
|
65
|
+
|
|
66
|
+
throw new Error( 'SculptorMesh: The geometry must contain triangles with a complete, non-empty element list.' );
|
|
67
|
+
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if ( index === null ) {
|
|
71
|
+
|
|
72
|
+
return { elementCount, sourceIndices: null, referencedVertices: null };
|
|
73
|
+
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const sourceIndices = new Uint32Array( elementCount );
|
|
77
|
+
const referencedVertices = new Uint8Array( sourceVertexCount );
|
|
78
|
+
|
|
79
|
+
for ( let i = 0; i < elementCount; i ++ ) {
|
|
80
|
+
|
|
81
|
+
const sourceIndex = index.getX( i );
|
|
82
|
+
|
|
83
|
+
if ( Number.isInteger( sourceIndex ) === false || sourceIndex < 0 || sourceIndex >= sourceVertexCount ) {
|
|
84
|
+
|
|
85
|
+
throw new Error( 'SculptorMesh: Triangle indices must reference valid positions.' );
|
|
86
|
+
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
sourceIndices[ i ] = sourceIndex;
|
|
90
|
+
referencedVertices[ sourceIndex ] = 1;
|
|
91
|
+
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return { elementCount, sourceIndices, referencedVertices };
|
|
95
|
+
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function readSourcePositions( position, referencedVertices ) {
|
|
99
|
+
|
|
100
|
+
const sourceVertexCount = position.count;
|
|
101
|
+
const positions = new Float32Array( sourceVertexCount * 3 );
|
|
102
|
+
let minX = Infinity, minY = Infinity, minZ = Infinity;
|
|
103
|
+
let maxX = - Infinity, maxY = - Infinity, maxZ = - Infinity;
|
|
104
|
+
|
|
105
|
+
for ( let i = 0; i < sourceVertexCount; i ++ ) {
|
|
106
|
+
|
|
107
|
+
if ( referencedVertices !== null && referencedVertices[ i ] === 0 ) continue;
|
|
108
|
+
|
|
109
|
+
const sourceX = position.getX( i );
|
|
110
|
+
const sourceY = position.getY( i );
|
|
111
|
+
const sourceZ = position.getZ( i );
|
|
112
|
+
|
|
113
|
+
if ( Number.isFinite( sourceX ) === false || Number.isFinite( sourceY ) === false || Number.isFinite( sourceZ ) === false ) {
|
|
114
|
+
|
|
115
|
+
throw new Error( 'SculptorMesh: Position values must be finite.' );
|
|
116
|
+
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const x = Math.fround( sourceX );
|
|
120
|
+
const y = Math.fround( sourceY );
|
|
121
|
+
const z = Math.fround( sourceZ );
|
|
122
|
+
|
|
123
|
+
if ( Number.isFinite( x ) === false || Number.isFinite( y ) === false || Number.isFinite( z ) === false ) {
|
|
124
|
+
|
|
125
|
+
throw new Error( 'SculptorMesh: Position values must fit in Float32 storage.' );
|
|
126
|
+
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const offset = i * 3;
|
|
130
|
+
positions[ offset ] = x;
|
|
131
|
+
positions[ offset + 1 ] = y;
|
|
132
|
+
positions[ offset + 2 ] = z;
|
|
133
|
+
|
|
134
|
+
if ( x < minX ) minX = x;
|
|
135
|
+
if ( y < minY ) minY = y;
|
|
136
|
+
if ( z < minZ ) minZ = z;
|
|
137
|
+
if ( x > maxX ) maxX = x;
|
|
138
|
+
if ( y > maxY ) maxY = y;
|
|
139
|
+
if ( z > maxZ ) maxZ = z;
|
|
140
|
+
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return { positions, bounds: [ minX, minY, minZ, maxX, maxY, maxZ ] };
|
|
144
|
+
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function weldPositions( sourcePositions, referencedVertices, bounds ) {
|
|
148
|
+
|
|
149
|
+
const sourceVertexCount = sourcePositions.length / 3;
|
|
150
|
+
const extent = Math.max( bounds[ 3 ] - bounds[ 0 ], bounds[ 4 ] - bounds[ 1 ], bounds[ 5 ] - bounds[ 2 ] );
|
|
151
|
+
const tolerance = extent * RELATIVE_WELD_TOLERANCE;
|
|
152
|
+
const toleranceSquared = tolerance * tolerance;
|
|
153
|
+
|
|
154
|
+
// Cells twice the weld radius only need the current and nearest neighboring
|
|
155
|
+
// cell in each dimension. Exact distances resolve spatial-hash collisions.
|
|
156
|
+
const inverseCellSize = tolerance > 0 ? 0.5 / tolerance : 0;
|
|
157
|
+
const cellHeads = new Map();
|
|
158
|
+
const nextHashEntry = [];
|
|
159
|
+
const mergedPositions = [];
|
|
160
|
+
const vertexMap = new Uint32Array( sourceVertexCount );
|
|
161
|
+
const searchCellCount = inverseCellSize > 0 ? 2 : 1;
|
|
162
|
+
|
|
163
|
+
for ( let i = 0; i < sourceVertexCount; i ++ ) {
|
|
164
|
+
|
|
165
|
+
if ( referencedVertices !== null && referencedVertices[ i ] === 0 ) continue;
|
|
166
|
+
|
|
167
|
+
const offset = i * 3;
|
|
168
|
+
const x = sourcePositions[ offset ];
|
|
169
|
+
const y = sourcePositions[ offset + 1 ];
|
|
170
|
+
const z = sourcePositions[ offset + 2 ];
|
|
171
|
+
const gridX = ( x - bounds[ 0 ] ) * inverseCellSize;
|
|
172
|
+
const gridY = ( y - bounds[ 1 ] ) * inverseCellSize;
|
|
173
|
+
const gridZ = ( z - bounds[ 2 ] ) * inverseCellSize;
|
|
174
|
+
const cellX = Math.floor( gridX );
|
|
175
|
+
const cellY = Math.floor( gridY );
|
|
176
|
+
const cellZ = Math.floor( gridZ );
|
|
177
|
+
const neighborX = cellX + ( gridX - cellX < 0.5 ? - 1 : 1 );
|
|
178
|
+
const neighborY = cellY + ( gridY - cellY < 0.5 ? - 1 : 1 );
|
|
179
|
+
const neighborZ = cellZ + ( gridZ - cellZ < 0.5 ? - 1 : 1 );
|
|
180
|
+
let mergedIndex;
|
|
181
|
+
let closestDistanceSquared = Infinity;
|
|
182
|
+
|
|
183
|
+
searchCells: for ( let iz = 0; iz < searchCellCount; iz ++ ) {
|
|
184
|
+
|
|
185
|
+
const searchZ = iz === 0 ? cellZ : neighborZ;
|
|
186
|
+
|
|
187
|
+
for ( let iy = 0; iy < searchCellCount; iy ++ ) {
|
|
188
|
+
|
|
189
|
+
const searchY = iy === 0 ? cellY : neighborY;
|
|
190
|
+
|
|
191
|
+
for ( let ix = 0; ix < searchCellCount; ix ++ ) {
|
|
192
|
+
|
|
193
|
+
const searchX = ix === 0 ? cellX : neighborX;
|
|
194
|
+
let candidate = cellHeads.get( hashPosition( searchX, searchY, searchZ ) );
|
|
195
|
+
|
|
196
|
+
while ( candidate !== undefined ) {
|
|
197
|
+
|
|
198
|
+
const candidateOffset = candidate * 3;
|
|
199
|
+
const dx = mergedPositions[ candidateOffset ] - x;
|
|
200
|
+
const dy = mergedPositions[ candidateOffset + 1 ] - y;
|
|
201
|
+
const dz = mergedPositions[ candidateOffset + 2 ] - z;
|
|
202
|
+
const distanceSquared = dx * dx + dy * dy + dz * dz;
|
|
203
|
+
|
|
204
|
+
if ( distanceSquared === 0 ) {
|
|
205
|
+
|
|
206
|
+
mergedIndex = candidate;
|
|
207
|
+
break searchCells;
|
|
208
|
+
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if ( distanceSquared <= toleranceSquared && distanceSquared < closestDistanceSquared ) {
|
|
212
|
+
|
|
213
|
+
mergedIndex = candidate;
|
|
214
|
+
closestDistanceSquared = distanceSquared;
|
|
215
|
+
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
candidate = nextHashEntry[ candidate ];
|
|
219
|
+
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if ( mergedIndex === undefined ) {
|
|
229
|
+
|
|
230
|
+
mergedIndex = mergedPositions.length / 3;
|
|
231
|
+
const hash = hashPosition( cellX, cellY, cellZ );
|
|
232
|
+
nextHashEntry[ mergedIndex ] = cellHeads.get( hash );
|
|
233
|
+
cellHeads.set( hash, mergedIndex );
|
|
234
|
+
mergedPositions.push( x, y, z );
|
|
235
|
+
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
vertexMap[ i ] = mergedIndex;
|
|
239
|
+
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return { positions: mergedPositions, vertexMap };
|
|
243
|
+
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function buildTriangleBuffers( elementCount, sourceIndices, vertexMap, positions ) {
|
|
247
|
+
|
|
248
|
+
const triangleCount = elementCount / 3;
|
|
249
|
+
const faces = new Uint32Array( triangleCount * 4 );
|
|
250
|
+
const triangles = new Uint32Array( elementCount );
|
|
251
|
+
|
|
252
|
+
for ( let i = 0; i < triangleCount; i ++ ) {
|
|
253
|
+
|
|
254
|
+
const triangleOffset = i * 3;
|
|
255
|
+
let a, b, c;
|
|
256
|
+
|
|
257
|
+
if ( sourceIndices === null ) {
|
|
258
|
+
|
|
259
|
+
a = vertexMap[ triangleOffset ];
|
|
260
|
+
b = vertexMap[ triangleOffset + 1 ];
|
|
261
|
+
c = vertexMap[ triangleOffset + 2 ];
|
|
262
|
+
|
|
263
|
+
} else {
|
|
264
|
+
|
|
265
|
+
a = vertexMap[ sourceIndices[ triangleOffset ] ];
|
|
266
|
+
b = vertexMap[ sourceIndices[ triangleOffset + 1 ] ];
|
|
267
|
+
c = vertexMap[ sourceIndices[ triangleOffset + 2 ] ];
|
|
268
|
+
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if ( a === b || b === c || c === a ) {
|
|
272
|
+
|
|
273
|
+
throw new Error( 'SculptorMesh: Welding produced a degenerate triangle.' );
|
|
274
|
+
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const a3 = a * 3;
|
|
278
|
+
const b3 = b * 3;
|
|
279
|
+
const c3 = c * 3;
|
|
280
|
+
const abx = positions[ b3 ] - positions[ a3 ];
|
|
281
|
+
const aby = positions[ b3 + 1 ] - positions[ a3 + 1 ];
|
|
282
|
+
const abz = positions[ b3 + 2 ] - positions[ a3 + 2 ];
|
|
283
|
+
const acx = positions[ c3 ] - positions[ a3 ];
|
|
284
|
+
const acy = positions[ c3 + 1 ] - positions[ a3 + 1 ];
|
|
285
|
+
const acz = positions[ c3 + 2 ] - positions[ a3 + 2 ];
|
|
286
|
+
const normalX = Math.fround( aby * acz - abz * acy );
|
|
287
|
+
const normalY = Math.fround( abz * acx - abx * acz );
|
|
288
|
+
const normalZ = Math.fround( abx * acy - aby * acx );
|
|
289
|
+
|
|
290
|
+
if ( Number.isFinite( normalX ) === false || Number.isFinite( normalY ) === false || Number.isFinite( normalZ ) === false ) {
|
|
291
|
+
|
|
292
|
+
throw new Error( 'SculptorMesh: Triangle normals must fit in Float32 storage.' );
|
|
293
|
+
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if ( normalX === 0 && normalY === 0 && normalZ === 0 ) {
|
|
297
|
+
|
|
298
|
+
throw new Error( 'SculptorMesh: The geometry contains a zero-area triangle at Float32 precision after welding.' );
|
|
299
|
+
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const faceOffset = i * 4;
|
|
303
|
+
faces[ faceOffset ] = a;
|
|
304
|
+
faces[ faceOffset + 1 ] = b;
|
|
305
|
+
faces[ faceOffset + 2 ] = c;
|
|
306
|
+
faces[ faceOffset + 3 ] = TRI_INDEX;
|
|
307
|
+
triangles[ triangleOffset ] = a;
|
|
308
|
+
triangles[ triangleOffset + 1 ] = b;
|
|
309
|
+
triangles[ triangleOffset + 2 ] = c;
|
|
310
|
+
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
return { faces, triangles };
|
|
314
|
+
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// Octree
|
|
318
|
+
|
|
319
|
+
class OctreeCell {
|
|
320
|
+
|
|
321
|
+
constructor( parent ) {
|
|
322
|
+
|
|
323
|
+
this._parent = parent ?? null;
|
|
324
|
+
this._depth = parent ? parent._depth + 1 : 0;
|
|
325
|
+
this._children = [];
|
|
326
|
+
this._aabbLoose = [ Infinity, Infinity, Infinity, - Infinity, - Infinity, - Infinity ];
|
|
327
|
+
this._aabbSplit = [ Infinity, Infinity, Infinity, - Infinity, - Infinity, - Infinity ];
|
|
328
|
+
this._iFaces = [];
|
|
329
|
+
this._queuedForUpdate = false;
|
|
330
|
+
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
resetNbFaces( nbFaces ) {
|
|
334
|
+
|
|
335
|
+
const f = this._iFaces;
|
|
336
|
+
f.length = nbFaces;
|
|
337
|
+
for ( let i = 0; i < nbFaces; ++ i ) f[ i ] = i;
|
|
338
|
+
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
build( mesh ) {
|
|
342
|
+
|
|
343
|
+
const stack = OCTREE_STACK;
|
|
344
|
+
stack[ 0 ] = this;
|
|
345
|
+
let curStack = 1;
|
|
346
|
+
const leaves = [];
|
|
347
|
+
while ( curStack > 0 ) {
|
|
348
|
+
|
|
349
|
+
const cell = stack[ -- curStack ];
|
|
350
|
+
const nbFaces = cell._iFaces.length;
|
|
351
|
+
if ( nbFaces > OCTREE_MAX_FACES && cell._depth < OCTREE_MAX_DEPTH ) {
|
|
352
|
+
|
|
353
|
+
cell._constructChildren( mesh );
|
|
354
|
+
const children = cell._children;
|
|
355
|
+
for ( let i = 0; i < 8; ++ i ) stack[ curStack + i ] = children[ i ];
|
|
356
|
+
curStack += 8;
|
|
357
|
+
|
|
358
|
+
} else if ( nbFaces > 0 ) {
|
|
359
|
+
|
|
360
|
+
leaves.push( cell );
|
|
361
|
+
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
for ( let i = 0, l = leaves.length; i < l; ++ i ) leaves[ i ]._constructLeaf( mesh );
|
|
367
|
+
stack.fill( null );
|
|
368
|
+
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
_constructLeaf( mesh ) {
|
|
372
|
+
|
|
373
|
+
const iFaces = this._iFaces;
|
|
374
|
+
const nbFaces = iFaces.length;
|
|
375
|
+
let bxmin = Infinity, bymin = Infinity, bzmin = Infinity;
|
|
376
|
+
let bxmax = - Infinity, bymax = - Infinity, bzmax = - Infinity;
|
|
377
|
+
const faceBoxes = mesh._faceBoxes;
|
|
378
|
+
const facePosInLeaf = mesh._facePosInLeaf;
|
|
379
|
+
const faceLeaf = mesh._faceLeaf;
|
|
380
|
+
for ( let i = 0; i < nbFaces; ++ i ) {
|
|
381
|
+
|
|
382
|
+
const id = iFaces[ i ];
|
|
383
|
+
faceLeaf[ id ] = this;
|
|
384
|
+
facePosInLeaf[ id ] = i;
|
|
385
|
+
const id6 = id * 6;
|
|
386
|
+
if ( faceBoxes[ id6 ] < bxmin ) bxmin = faceBoxes[ id6 ];
|
|
387
|
+
if ( faceBoxes[ id6 + 1 ] < bymin ) bymin = faceBoxes[ id6 + 1 ];
|
|
388
|
+
if ( faceBoxes[ id6 + 2 ] < bzmin ) bzmin = faceBoxes[ id6 + 2 ];
|
|
389
|
+
if ( faceBoxes[ id6 + 3 ] > bxmax ) bxmax = faceBoxes[ id6 + 3 ];
|
|
390
|
+
if ( faceBoxes[ id6 + 4 ] > bymax ) bymax = faceBoxes[ id6 + 4 ];
|
|
391
|
+
if ( faceBoxes[ id6 + 5 ] > bzmax ) bzmax = faceBoxes[ id6 + 5 ];
|
|
392
|
+
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
this._expandAabbLoose( bxmin, bymin, bzmin, bxmax, bymax, bzmax );
|
|
396
|
+
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
_constructChildren( mesh ) {
|
|
400
|
+
|
|
401
|
+
const split = this._aabbSplit;
|
|
402
|
+
const xmin = split[ 0 ], ymin = split[ 1 ], zmin = split[ 2 ];
|
|
403
|
+
const xmax = split[ 3 ], ymax = split[ 4 ], zmax = split[ 5 ];
|
|
404
|
+
const xcen = ( xmax + xmin ) * 0.5, ycen = ( ymax + ymin ) * 0.5, zcen = ( zmax + zmin ) * 0.5;
|
|
405
|
+
|
|
406
|
+
const children = new Array( 8 );
|
|
407
|
+
for ( let i = 0; i < 8; i ++ ) children[ i ] = new OctreeCell( this );
|
|
408
|
+
|
|
409
|
+
const faceCenters = mesh._faceCenters;
|
|
410
|
+
const iFaces = this._iFaces;
|
|
411
|
+
for ( let i = 0, l = iFaces.length; i < l; ++ i ) {
|
|
412
|
+
|
|
413
|
+
const iFace = iFaces[ i ];
|
|
414
|
+
const id = iFace * 3;
|
|
415
|
+
const cx = faceCenters[ id ], cy = faceCenters[ id + 1 ], cz = faceCenters[ id + 2 ];
|
|
416
|
+
if ( cx > xcen ) {
|
|
417
|
+
|
|
418
|
+
if ( cy > ycen ) children[ cz > zcen ? 6 : 5 ]._iFaces.push( iFace );
|
|
419
|
+
else children[ cz > zcen ? 2 : 1 ]._iFaces.push( iFace );
|
|
420
|
+
|
|
421
|
+
} else {
|
|
422
|
+
|
|
423
|
+
if ( cy > ycen ) children[ cz > zcen ? 7 : 4 ]._iFaces.push( iFace );
|
|
424
|
+
else children[ cz > zcen ? 3 : 0 ]._iFaces.push( iFace );
|
|
425
|
+
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
children[ 0 ]._setAabbSplit( xmin, ymin, zmin, xcen, ycen, zcen );
|
|
431
|
+
children[ 1 ]._setAabbSplit( xcen, ymin, zmin, xmax, ycen, zcen );
|
|
432
|
+
children[ 2 ]._setAabbSplit( xcen, ymin, zcen, xmax, ycen, zmax );
|
|
433
|
+
children[ 3 ]._setAabbSplit( xmin, ymin, zcen, xcen, ycen, zmax );
|
|
434
|
+
children[ 4 ]._setAabbSplit( xmin, ycen, zmin, xcen, ymax, zcen );
|
|
435
|
+
children[ 5 ]._setAabbSplit( xcen, ycen, zmin, xmax, ymax, zcen );
|
|
436
|
+
children[ 6 ]._setAabbSplit( xcen, ycen, zcen, xmax, ymax, zmax );
|
|
437
|
+
children[ 7 ]._setAabbSplit( xmin, ycen, zcen, xcen, ymax, zmax );
|
|
438
|
+
|
|
439
|
+
this._children = children;
|
|
440
|
+
this._iFaces.length = 0;
|
|
441
|
+
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
_setAabbSplit( xmin, ymin, zmin, xmax, ymax, zmax ) {
|
|
445
|
+
|
|
446
|
+
const a = this._aabbSplit;
|
|
447
|
+
a[ 0 ] = xmin; a[ 1 ] = ymin; a[ 2 ] = zmin;
|
|
448
|
+
a[ 3 ] = xmax; a[ 4 ] = ymax; a[ 5 ] = zmax;
|
|
449
|
+
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
_setAabbLoose( xmin, ymin, zmin, xmax, ymax, zmax ) {
|
|
453
|
+
|
|
454
|
+
const a = this._aabbLoose;
|
|
455
|
+
a[ 0 ] = xmin; a[ 1 ] = ymin; a[ 2 ] = zmin;
|
|
456
|
+
a[ 3 ] = xmax; a[ 4 ] = ymax; a[ 5 ] = zmax;
|
|
457
|
+
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
collectIntersectRay( vNear, eyeDir, collectFaces, leavesHit ) {
|
|
461
|
+
|
|
462
|
+
const vx = vNear[ 0 ], vy = vNear[ 1 ], vz = vNear[ 2 ];
|
|
463
|
+
const irx = 1.0 / eyeDir[ 0 ], iry = 1.0 / eyeDir[ 1 ], irz = 1.0 / eyeDir[ 2 ];
|
|
464
|
+
let acc = 0;
|
|
465
|
+
const stack = OCTREE_STACK;
|
|
466
|
+
stack[ 0 ] = this;
|
|
467
|
+
let curStack = 1;
|
|
468
|
+
while ( curStack > 0 ) {
|
|
469
|
+
|
|
470
|
+
const cell = stack[ -- curStack ];
|
|
471
|
+
const loose = cell._aabbLoose;
|
|
472
|
+
const t1 = ( loose[ 0 ] - vx ) * irx, t2 = ( loose[ 3 ] - vx ) * irx;
|
|
473
|
+
const t3 = ( loose[ 1 ] - vy ) * iry, t4 = ( loose[ 4 ] - vy ) * iry;
|
|
474
|
+
const t5 = ( loose[ 2 ] - vz ) * irz, t6 = ( loose[ 5 ] - vz ) * irz;
|
|
475
|
+
const tmin = Math.max( Math.min( t1, t2 ), Math.min( t3, t4 ), Math.min( t5, t6 ) );
|
|
476
|
+
const tmax = Math.min( Math.max( t1, t2 ), Math.max( t3, t4 ), Math.max( t5, t6 ) );
|
|
477
|
+
if ( tmax < 0 || tmin > tmax ) continue;
|
|
478
|
+
const children = cell._children;
|
|
479
|
+
if ( children.length === 8 ) {
|
|
480
|
+
|
|
481
|
+
for ( let i = 0; i < 8; ++ i ) stack[ curStack + i ] = children[ i ];
|
|
482
|
+
curStack += 8;
|
|
483
|
+
|
|
484
|
+
} else {
|
|
485
|
+
|
|
486
|
+
queueLeaf( leavesHit, cell );
|
|
487
|
+
const iFaces = cell._iFaces;
|
|
488
|
+
collectFaces.set( iFaces, acc );
|
|
489
|
+
acc += iFaces.length;
|
|
490
|
+
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
stack.fill( null );
|
|
496
|
+
return collectFaces.slice( 0, acc );
|
|
497
|
+
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
collectIntersectSphere( vert, radiusSquared, collectFaces, leavesHit ) {
|
|
501
|
+
|
|
502
|
+
const vx = vert[ 0 ], vy = vert[ 1 ], vz = vert[ 2 ];
|
|
503
|
+
let acc = 0;
|
|
504
|
+
const stack = OCTREE_STACK;
|
|
505
|
+
stack[ 0 ] = this;
|
|
506
|
+
let curStack = 1;
|
|
507
|
+
while ( curStack > 0 ) {
|
|
508
|
+
|
|
509
|
+
const cell = stack[ -- curStack ];
|
|
510
|
+
const loose = cell._aabbLoose;
|
|
511
|
+
let dx = 0, dy = 0, dz = 0;
|
|
512
|
+
if ( loose[ 0 ] > vx ) dx = loose[ 0 ] - vx;
|
|
513
|
+
else if ( loose[ 3 ] < vx ) dx = loose[ 3 ] - vx;
|
|
514
|
+
if ( loose[ 1 ] > vy ) dy = loose[ 1 ] - vy;
|
|
515
|
+
else if ( loose[ 4 ] < vy ) dy = loose[ 4 ] - vy;
|
|
516
|
+
if ( loose[ 2 ] > vz ) dz = loose[ 2 ] - vz;
|
|
517
|
+
else if ( loose[ 5 ] < vz ) dz = loose[ 5 ] - vz;
|
|
518
|
+
if ( dx * dx + dy * dy + dz * dz > radiusSquared ) continue;
|
|
519
|
+
const children = cell._children;
|
|
520
|
+
if ( children.length === 8 ) {
|
|
521
|
+
|
|
522
|
+
for ( let i = 0; i < 8; ++ i ) stack[ curStack + i ] = children[ i ];
|
|
523
|
+
curStack += 8;
|
|
524
|
+
|
|
525
|
+
} else {
|
|
526
|
+
|
|
527
|
+
queueLeaf( leavesHit, cell );
|
|
528
|
+
const iFaces = cell._iFaces;
|
|
529
|
+
collectFaces.set( iFaces, acc );
|
|
530
|
+
acc += iFaces.length;
|
|
531
|
+
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
stack.fill( null );
|
|
537
|
+
return collectFaces.slice( 0, acc );
|
|
538
|
+
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
addFace( faceId, bxmin, bymin, bzmin, bxmax, bymax, bzmax, cx, cy, cz ) {
|
|
542
|
+
|
|
543
|
+
const stack = OCTREE_STACK;
|
|
544
|
+
stack[ 0 ] = this;
|
|
545
|
+
let curStack = 1;
|
|
546
|
+
while ( curStack > 0 ) {
|
|
547
|
+
|
|
548
|
+
const cell = stack[ -- curStack ];
|
|
549
|
+
const s = cell._aabbSplit;
|
|
550
|
+
if ( cx <= s[ 0 ] || cy <= s[ 1 ] || cz <= s[ 2 ] || cx > s[ 3 ] || cy > s[ 4 ] || cz > s[ 5 ] ) continue;
|
|
551
|
+
const loose = cell._aabbLoose;
|
|
552
|
+
if ( bxmin < loose[ 0 ] ) loose[ 0 ] = bxmin;
|
|
553
|
+
if ( bymin < loose[ 1 ] ) loose[ 1 ] = bymin;
|
|
554
|
+
if ( bzmin < loose[ 2 ] ) loose[ 2 ] = bzmin;
|
|
555
|
+
if ( bxmax > loose[ 3 ] ) loose[ 3 ] = bxmax;
|
|
556
|
+
if ( bymax > loose[ 4 ] ) loose[ 4 ] = bymax;
|
|
557
|
+
if ( bzmax > loose[ 5 ] ) loose[ 5 ] = bzmax;
|
|
558
|
+
const children = cell._children;
|
|
559
|
+
if ( children.length === 8 ) {
|
|
560
|
+
|
|
561
|
+
for ( let i = 0; i < 8; ++ i ) stack[ curStack + i ] = children[ i ];
|
|
562
|
+
curStack += 8;
|
|
563
|
+
|
|
564
|
+
} else {
|
|
565
|
+
|
|
566
|
+
cell._iFaces.push( faceId );
|
|
567
|
+
stack.fill( null );
|
|
568
|
+
return cell;
|
|
569
|
+
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
stack.fill( null );
|
|
575
|
+
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
_expandAabbLoose( bxmin, bymin, bzmin, bxmax, bymax, bzmax ) {
|
|
579
|
+
|
|
580
|
+
let parent = this;
|
|
581
|
+
while ( parent ) {
|
|
582
|
+
|
|
583
|
+
const p = parent._aabbLoose;
|
|
584
|
+
let proceed = false;
|
|
585
|
+
if ( bxmin < p[ 0 ] ) {
|
|
586
|
+
|
|
587
|
+
p[ 0 ] = bxmin; proceed = true;
|
|
588
|
+
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
if ( bymin < p[ 1 ] ) {
|
|
592
|
+
|
|
593
|
+
p[ 1 ] = bymin; proceed = true;
|
|
594
|
+
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
if ( bzmin < p[ 2 ] ) {
|
|
598
|
+
|
|
599
|
+
p[ 2 ] = bzmin; proceed = true;
|
|
600
|
+
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
if ( bxmax > p[ 3 ] ) {
|
|
604
|
+
|
|
605
|
+
p[ 3 ] = bxmax; proceed = true;
|
|
606
|
+
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
if ( bymax > p[ 4 ] ) {
|
|
610
|
+
|
|
611
|
+
p[ 4 ] = bymax; proceed = true;
|
|
612
|
+
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
if ( bzmax > p[ 5 ] ) {
|
|
616
|
+
|
|
617
|
+
p[ 5 ] = bzmax; proceed = true;
|
|
618
|
+
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
parent = proceed ? parent._parent : null;
|
|
622
|
+
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
pruneIfPossible() {
|
|
628
|
+
|
|
629
|
+
let cell = this;
|
|
630
|
+
while ( cell._parent ) {
|
|
631
|
+
|
|
632
|
+
const parent = cell._parent;
|
|
633
|
+
const children = parent._children;
|
|
634
|
+
if ( children.length === 0 ) return;
|
|
635
|
+
for ( let i = 0; i < 8; ++ i ) {
|
|
636
|
+
|
|
637
|
+
if ( children[ i ]._iFaces.length > 0 || children[ i ]._children.length === 8 ) return;
|
|
638
|
+
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
children.length = 0;
|
|
642
|
+
cell = parent;
|
|
643
|
+
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
// Mesh topology and spatial queries
|
|
651
|
+
|
|
652
|
+
class SculptorMesh {
|
|
653
|
+
|
|
654
|
+
constructor() {
|
|
655
|
+
|
|
656
|
+
this._nbVertices = 0;
|
|
657
|
+
this._nbFaces = 0;
|
|
658
|
+
|
|
659
|
+
this._verticesXYZ = null;
|
|
660
|
+
this._normalsXYZ = null;
|
|
661
|
+
this._renderNormalsXYZ = null;
|
|
662
|
+
|
|
663
|
+
this._facesABCD = null;
|
|
664
|
+
this._trianglesABC = null;
|
|
665
|
+
|
|
666
|
+
this._vertRingVert = [];
|
|
667
|
+
this._vertRingFace = [];
|
|
668
|
+
this._vertOnEdge = null;
|
|
669
|
+
|
|
670
|
+
this._faceNormals = null;
|
|
671
|
+
this._faceBoxes = null;
|
|
672
|
+
this._faceCenters = null;
|
|
673
|
+
this._facePosInLeaf = null;
|
|
674
|
+
this._faceLeaf = [];
|
|
675
|
+
|
|
676
|
+
this._vertTagFlags = null;
|
|
677
|
+
this._vertSculptFlags = null;
|
|
678
|
+
this._facesTagFlags = null;
|
|
679
|
+
|
|
680
|
+
this._octree = null;
|
|
681
|
+
this._leavesToUpdate = [];
|
|
682
|
+
this._topologyVersion = 0;
|
|
683
|
+
this._tagFlag = 1;
|
|
684
|
+
this._sculptFlag = 1;
|
|
685
|
+
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
getNbVertices() {
|
|
689
|
+
|
|
690
|
+
return this._nbVertices;
|
|
691
|
+
|
|
692
|
+
}
|
|
693
|
+
getNbFaces() {
|
|
694
|
+
|
|
695
|
+
return this._nbFaces;
|
|
696
|
+
|
|
697
|
+
}
|
|
698
|
+
getNbTriangles() {
|
|
699
|
+
|
|
700
|
+
return this._nbFaces;
|
|
701
|
+
|
|
702
|
+
}
|
|
703
|
+
getVertices() {
|
|
704
|
+
|
|
705
|
+
return this._verticesXYZ;
|
|
706
|
+
|
|
707
|
+
}
|
|
708
|
+
getNormals() {
|
|
709
|
+
|
|
710
|
+
return this._normalsXYZ;
|
|
711
|
+
|
|
712
|
+
}
|
|
713
|
+
getRenderNormals() {
|
|
714
|
+
|
|
715
|
+
return this._renderNormalsXYZ;
|
|
716
|
+
|
|
717
|
+
}
|
|
718
|
+
getFaces() {
|
|
719
|
+
|
|
720
|
+
return this._facesABCD;
|
|
721
|
+
|
|
722
|
+
}
|
|
723
|
+
getTriangles() {
|
|
724
|
+
|
|
725
|
+
return this._trianglesABC;
|
|
726
|
+
|
|
727
|
+
}
|
|
728
|
+
getVerticesRingVert() {
|
|
729
|
+
|
|
730
|
+
return this._vertRingVert;
|
|
731
|
+
|
|
732
|
+
}
|
|
733
|
+
getVerticesRingFace() {
|
|
734
|
+
|
|
735
|
+
return this._vertRingFace;
|
|
736
|
+
|
|
737
|
+
}
|
|
738
|
+
getVerticesOnEdge() {
|
|
739
|
+
|
|
740
|
+
return this._vertOnEdge;
|
|
741
|
+
|
|
742
|
+
}
|
|
743
|
+
getVerticesTagFlags() {
|
|
744
|
+
|
|
745
|
+
return this._vertTagFlags;
|
|
746
|
+
|
|
747
|
+
}
|
|
748
|
+
getVerticesSculptFlags() {
|
|
749
|
+
|
|
750
|
+
return this._vertSculptFlags;
|
|
751
|
+
|
|
752
|
+
}
|
|
753
|
+
getFaceNormals() {
|
|
754
|
+
|
|
755
|
+
return this._faceNormals;
|
|
756
|
+
|
|
757
|
+
}
|
|
758
|
+
getFaceBoxes() {
|
|
759
|
+
|
|
760
|
+
return this._faceBoxes;
|
|
761
|
+
|
|
762
|
+
}
|
|
763
|
+
getFaceCenters() {
|
|
764
|
+
|
|
765
|
+
return this._faceCenters;
|
|
766
|
+
|
|
767
|
+
}
|
|
768
|
+
getFacePosInLeaf() {
|
|
769
|
+
|
|
770
|
+
return this._facePosInLeaf;
|
|
771
|
+
|
|
772
|
+
}
|
|
773
|
+
getFaceLeaf() {
|
|
774
|
+
|
|
775
|
+
return this._faceLeaf;
|
|
776
|
+
|
|
777
|
+
}
|
|
778
|
+
getFacesTagFlags() {
|
|
779
|
+
|
|
780
|
+
return this._facesTagFlags;
|
|
781
|
+
|
|
782
|
+
}
|
|
783
|
+
getTopologyVersion() {
|
|
784
|
+
|
|
785
|
+
return this._topologyVersion;
|
|
786
|
+
|
|
787
|
+
}
|
|
788
|
+
getSculptFlag() {
|
|
789
|
+
|
|
790
|
+
return this._sculptFlag;
|
|
791
|
+
|
|
792
|
+
}
|
|
793
|
+
nextTagFlag() {
|
|
794
|
+
|
|
795
|
+
if ( this._tagFlag >= MAX_FLAG ) {
|
|
796
|
+
|
|
797
|
+
// Preserve pending deletion sentinels across tag rollover.
|
|
798
|
+
resetTagFlags( this._vertTagFlags, this._nbVertices );
|
|
799
|
+
resetTagFlags( this._facesTagFlags, this._nbFaces );
|
|
800
|
+
this._tagFlag = 1;
|
|
801
|
+
|
|
802
|
+
} else {
|
|
803
|
+
|
|
804
|
+
this._tagFlag ++;
|
|
805
|
+
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
return this._tagFlag;
|
|
809
|
+
|
|
810
|
+
}
|
|
811
|
+
nextSculptFlag() {
|
|
812
|
+
|
|
813
|
+
if ( this._sculptFlag >= MAX_FLAG ) {
|
|
814
|
+
|
|
815
|
+
this._vertSculptFlags.fill( 0 );
|
|
816
|
+
this._sculptFlag = 1;
|
|
817
|
+
|
|
818
|
+
} else {
|
|
819
|
+
|
|
820
|
+
this._sculptFlag ++;
|
|
821
|
+
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
return this._sculptFlag;
|
|
825
|
+
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
addNbVertice( nb ) {
|
|
829
|
+
|
|
830
|
+
this._nbVertices += nb;
|
|
831
|
+
|
|
832
|
+
}
|
|
833
|
+
addNbFace( nb ) {
|
|
834
|
+
|
|
835
|
+
this._nbFaces += nb;
|
|
836
|
+
this._topologyVersion ++;
|
|
837
|
+
|
|
838
|
+
}
|
|
839
|
+
markTopologyChanged() {
|
|
840
|
+
|
|
841
|
+
this._topologyVersion ++;
|
|
842
|
+
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
initFromGeometry( geometry ) {
|
|
846
|
+
|
|
847
|
+
this._tagFlag = 1;
|
|
848
|
+
this._sculptFlag = 1;
|
|
849
|
+
|
|
850
|
+
const posAttr = geometry.getAttribute( 'position' );
|
|
851
|
+
|
|
852
|
+
if ( posAttr === undefined || posAttr.itemSize !== 3 || posAttr.count === 0 ) {
|
|
853
|
+
|
|
854
|
+
throw new Error( 'SculptorMesh: A non-empty position attribute with itemSize 3 is required.' );
|
|
855
|
+
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
if ( typeof posAttr.getX !== 'function' || typeof posAttr.getY !== 'function' || typeof posAttr.getZ !== 'function' ) {
|
|
859
|
+
|
|
860
|
+
throw new Error( 'SculptorMesh: The position attribute must be CPU-accessible.' );
|
|
861
|
+
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
const index = geometry.getIndex();
|
|
865
|
+
const sourceVertexCount = posAttr.count;
|
|
866
|
+
const { elementCount, sourceIndices, referencedVertices } = readSourceElements( index, sourceVertexCount );
|
|
867
|
+
const { positions: sourcePositions, bounds } = readSourcePositions( posAttr, referencedVertices );
|
|
868
|
+
const { positions: weldedPositions, vertexMap } = weldPositions( sourcePositions, referencedVertices, bounds );
|
|
869
|
+
const { faces, triangles } = buildTriangleBuffers( elementCount, sourceIndices, vertexMap, weldedPositions );
|
|
870
|
+
const vertexCount = weldedPositions.length / 3;
|
|
871
|
+
const triangleCount = elementCount / 3;
|
|
872
|
+
const vertexDataLength = vertexCount * 3;
|
|
873
|
+
|
|
874
|
+
this._nbVertices = vertexCount;
|
|
875
|
+
this._nbFaces = triangleCount;
|
|
876
|
+
this._topologyVersion = 0;
|
|
877
|
+
this._leavesToUpdate.length = 0;
|
|
878
|
+
|
|
879
|
+
this._verticesXYZ = new Float32Array( weldedPositions );
|
|
880
|
+
this._normalsXYZ = new Float32Array( vertexDataLength );
|
|
881
|
+
this._renderNormalsXYZ = new Float32Array( vertexDataLength );
|
|
882
|
+
|
|
883
|
+
this._facesABCD = faces;
|
|
884
|
+
this._trianglesABC = triangles;
|
|
885
|
+
this._vertOnEdge = new Uint8Array( vertexCount );
|
|
886
|
+
this._vertTagFlags = new Int32Array( vertexCount );
|
|
887
|
+
this._vertSculptFlags = new Int32Array( vertexCount );
|
|
888
|
+
this._facesTagFlags = new Int32Array( triangleCount );
|
|
889
|
+
this._faceBoxes = new Float32Array( triangleCount * 6 );
|
|
890
|
+
this._faceNormals = new Float32Array( triangleCount * 3 );
|
|
891
|
+
this._faceCenters = new Float32Array( triangleCount * 3 );
|
|
892
|
+
this._facePosInLeaf = new Uint32Array( triangleCount );
|
|
893
|
+
this._faceLeaf = new Array( triangleCount ).fill( null );
|
|
894
|
+
|
|
895
|
+
this._initTopology();
|
|
896
|
+
this._updateGeometry();
|
|
897
|
+
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
_initTopology() {
|
|
901
|
+
|
|
902
|
+
const vrings = this._vertRingVert;
|
|
903
|
+
const frings = this._vertRingFace;
|
|
904
|
+
const nbVertices = this._nbVertices;
|
|
905
|
+
vrings.length = frings.length = nbVertices;
|
|
906
|
+
for ( let i = 0; i < nbVertices; ++ i ) {
|
|
907
|
+
|
|
908
|
+
vrings[ i ] = [];
|
|
909
|
+
frings[ i ] = [];
|
|
910
|
+
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
const nbTriangles = this._nbFaces;
|
|
914
|
+
const tAr = this._trianglesABC;
|
|
915
|
+
for ( let i = 0; i < nbTriangles; ++ i ) {
|
|
916
|
+
|
|
917
|
+
const j = i * 3;
|
|
918
|
+
frings[ tAr[ j ] ].push( i );
|
|
919
|
+
frings[ tAr[ j + 1 ] ].push( i );
|
|
920
|
+
frings[ tAr[ j + 2 ] ].push( i );
|
|
921
|
+
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
const vOnEdge = this._vertOnEdge;
|
|
925
|
+
for ( let i = 0; i < nbVertices; ++ i ) {
|
|
926
|
+
|
|
927
|
+
this._computeRingVertices( i );
|
|
928
|
+
vOnEdge[ i ] = frings[ i ].length !== vrings[ i ].length ? 1 : 0;
|
|
929
|
+
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
_computeRingVertices( iVert ) {
|
|
935
|
+
|
|
936
|
+
const tagFlag = this.nextTagFlag();
|
|
937
|
+
const fAr = this._facesABCD;
|
|
938
|
+
const vflags = this._vertTagFlags;
|
|
939
|
+
const vring = this._vertRingVert[ iVert ];
|
|
940
|
+
const fring = this._vertRingFace[ iVert ];
|
|
941
|
+
vring.length = 0;
|
|
942
|
+
for ( let i = 0, l = fring.length; i < l; ++ i ) {
|
|
943
|
+
|
|
944
|
+
const ind = fring[ i ] * 4;
|
|
945
|
+
let iVer1 = fAr[ ind ];
|
|
946
|
+
let iVer2 = fAr[ ind + 1 ];
|
|
947
|
+
if ( iVer1 === iVert ) iVer1 = fAr[ ind + 2 ];
|
|
948
|
+
else if ( iVer2 === iVert ) iVer2 = fAr[ ind + 2 ];
|
|
949
|
+
if ( vflags[ iVer1 ] !== tagFlag ) {
|
|
950
|
+
|
|
951
|
+
vflags[ iVer1 ] = tagFlag; vring.push( iVer1 );
|
|
952
|
+
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
if ( vflags[ iVer2 ] !== tagFlag ) {
|
|
956
|
+
|
|
957
|
+
vflags[ iVer2 ] = tagFlag; vring.push( iVer2 );
|
|
958
|
+
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
_updateGeometry( iFaces, iVerts ) {
|
|
966
|
+
|
|
967
|
+
if ( iVerts === undefined && iFaces !== undefined ) iVerts = this.getVerticesFromFaces( iFaces );
|
|
968
|
+
|
|
969
|
+
this._updateFacesAabbAndNormal( iFaces );
|
|
970
|
+
this._updateVerticesNormal( iVerts );
|
|
971
|
+
this._updateOctree( iFaces );
|
|
972
|
+
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
_updateFacesAabbAndNormal( iFaces ) {
|
|
976
|
+
|
|
977
|
+
const faceNormals = this._faceNormals;
|
|
978
|
+
const faceBoxes = this._faceBoxes;
|
|
979
|
+
const faceCenters = this._faceCenters;
|
|
980
|
+
const vAr = this._verticesXYZ;
|
|
981
|
+
const fAr = this._facesABCD;
|
|
982
|
+
const full = iFaces === undefined;
|
|
983
|
+
const nbFaces = full ? this._nbFaces : iFaces.length;
|
|
984
|
+
|
|
985
|
+
for ( let i = 0; i < nbFaces; ++ i ) {
|
|
986
|
+
|
|
987
|
+
const ind = full ? i : iFaces[ i ];
|
|
988
|
+
const idTri = ind * 3;
|
|
989
|
+
const idFace = ind * 4;
|
|
990
|
+
const idBox = ind * 6;
|
|
991
|
+
const ind1 = fAr[ idFace ] * 3;
|
|
992
|
+
const ind2 = fAr[ idFace + 1 ] * 3;
|
|
993
|
+
const ind3 = fAr[ idFace + 2 ] * 3;
|
|
994
|
+
|
|
995
|
+
const v1x = vAr[ ind1 ], v1y = vAr[ ind1 + 1 ], v1z = vAr[ ind1 + 2 ];
|
|
996
|
+
const v2x = vAr[ ind2 ], v2y = vAr[ ind2 + 1 ], v2z = vAr[ ind2 + 2 ];
|
|
997
|
+
const v3x = vAr[ ind3 ], v3y = vAr[ ind3 + 1 ], v3z = vAr[ ind3 + 2 ];
|
|
998
|
+
|
|
999
|
+
const ax = v2x - v1x, ay = v2y - v1y, az = v2z - v1z;
|
|
1000
|
+
const bx = v3x - v1x, by = v3y - v1y, bz = v3z - v1z;
|
|
1001
|
+
faceNormals[ idTri ] = ay * bz - az * by;
|
|
1002
|
+
faceNormals[ idTri + 1 ] = az * bx - ax * bz;
|
|
1003
|
+
faceNormals[ idTri + 2 ] = ax * by - ay * bx;
|
|
1004
|
+
|
|
1005
|
+
const xmin = v1x < v2x ? ( v1x < v3x ? v1x : v3x ) : ( v2x < v3x ? v2x : v3x );
|
|
1006
|
+
const xmax = v1x > v2x ? ( v1x > v3x ? v1x : v3x ) : ( v2x > v3x ? v2x : v3x );
|
|
1007
|
+
const ymin = v1y < v2y ? ( v1y < v3y ? v1y : v3y ) : ( v2y < v3y ? v2y : v3y );
|
|
1008
|
+
const ymax = v1y > v2y ? ( v1y > v3y ? v1y : v3y ) : ( v2y > v3y ? v2y : v3y );
|
|
1009
|
+
const zmin = v1z < v2z ? ( v1z < v3z ? v1z : v3z ) : ( v2z < v3z ? v2z : v3z );
|
|
1010
|
+
const zmax = v1z > v2z ? ( v1z > v3z ? v1z : v3z ) : ( v2z > v3z ? v2z : v3z );
|
|
1011
|
+
|
|
1012
|
+
faceBoxes[ idBox ] = xmin; faceBoxes[ idBox + 1 ] = ymin; faceBoxes[ idBox + 2 ] = zmin;
|
|
1013
|
+
faceBoxes[ idBox + 3 ] = xmax; faceBoxes[ idBox + 4 ] = ymax; faceBoxes[ idBox + 5 ] = zmax;
|
|
1014
|
+
faceCenters[ idTri ] = ( xmin + xmax ) * 0.5;
|
|
1015
|
+
faceCenters[ idTri + 1 ] = ( ymin + ymax ) * 0.5;
|
|
1016
|
+
faceCenters[ idTri + 2 ] = ( zmin + zmax ) * 0.5;
|
|
1017
|
+
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
_updateVerticesNormal( iVerts ) {
|
|
1023
|
+
|
|
1024
|
+
const nAr = this._normalsXYZ;
|
|
1025
|
+
const renderNAr = this._renderNormalsXYZ;
|
|
1026
|
+
const faceNormals = this._faceNormals;
|
|
1027
|
+
const ringFaces = this._vertRingFace;
|
|
1028
|
+
const full = iVerts === undefined;
|
|
1029
|
+
const nbVerts = full ? this._nbVertices : iVerts.length;
|
|
1030
|
+
|
|
1031
|
+
for ( let i = 0; i < nbVerts; ++ i ) {
|
|
1032
|
+
|
|
1033
|
+
const ind = full ? i : iVerts[ i ];
|
|
1034
|
+
const vrf = ringFaces[ ind ];
|
|
1035
|
+
let nx = 0, ny = 0, nz = 0;
|
|
1036
|
+
for ( let j = 0, l = vrf.length; j < l; ++ j ) {
|
|
1037
|
+
|
|
1038
|
+
const id = vrf[ j ] * 3;
|
|
1039
|
+
nx += faceNormals[ id ];
|
|
1040
|
+
ny += faceNormals[ id + 1 ];
|
|
1041
|
+
nz += faceNormals[ id + 2 ];
|
|
1042
|
+
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
const inverseCount = vrf.length > 0 ? 1.0 / vrf.length : 0;
|
|
1046
|
+
const ind3 = ind * 3;
|
|
1047
|
+
nx *= inverseCount;
|
|
1048
|
+
ny *= inverseCount;
|
|
1049
|
+
nz *= inverseCount;
|
|
1050
|
+
nAr[ ind3 ] = nx;
|
|
1051
|
+
nAr[ ind3 + 1 ] = ny;
|
|
1052
|
+
nAr[ ind3 + 2 ] = nz;
|
|
1053
|
+
|
|
1054
|
+
const length = Math.sqrt( nx * nx + ny * ny + nz * nz );
|
|
1055
|
+
const invLength = length > 0 ? 1.0 / length : 0;
|
|
1056
|
+
renderNAr[ ind3 ] = nx * invLength;
|
|
1057
|
+
renderNAr[ ind3 + 1 ] = ny * invLength;
|
|
1058
|
+
renderNAr[ ind3 + 2 ] = nz * invLength;
|
|
1059
|
+
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
_updateOctree( iFaces ) {
|
|
1065
|
+
|
|
1066
|
+
if ( iFaces === undefined ) {
|
|
1067
|
+
|
|
1068
|
+
this._computeOctree();
|
|
1069
|
+
|
|
1070
|
+
} else {
|
|
1071
|
+
|
|
1072
|
+
this._updateOctreeAdd( this._updateOctreeRemove( iFaces ) );
|
|
1073
|
+
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
_computeOctree() {
|
|
1079
|
+
|
|
1080
|
+
const vAr = this._verticesXYZ;
|
|
1081
|
+
let xmin = Infinity, ymin = Infinity, zmin = Infinity;
|
|
1082
|
+
let xmax = - Infinity, ymax = - Infinity, zmax = - Infinity;
|
|
1083
|
+
|
|
1084
|
+
for ( let i = 0, l = this._nbVertices * 3; i < l; i += 3 ) {
|
|
1085
|
+
|
|
1086
|
+
if ( vAr[ i ] < xmin ) xmin = vAr[ i ];
|
|
1087
|
+
if ( vAr[ i ] > xmax ) xmax = vAr[ i ];
|
|
1088
|
+
if ( vAr[ i + 1 ] < ymin ) ymin = vAr[ i + 1 ];
|
|
1089
|
+
if ( vAr[ i + 1 ] > ymax ) ymax = vAr[ i + 1 ];
|
|
1090
|
+
if ( vAr[ i + 2 ] < zmin ) zmin = vAr[ i + 2 ];
|
|
1091
|
+
if ( vAr[ i + 2 ] > zmax ) zmax = vAr[ i + 2 ];
|
|
1092
|
+
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
const dx = xmax - xmin;
|
|
1096
|
+
const dy = ymax - ymin;
|
|
1097
|
+
const dz = zmax - zmin;
|
|
1098
|
+
const thickness = Math.hypot( dx, dy, dz ) * 0.2;
|
|
1099
|
+
|
|
1100
|
+
if ( dx === 0 ) {
|
|
1101
|
+
|
|
1102
|
+
xmin -= thickness;
|
|
1103
|
+
xmax += thickness;
|
|
1104
|
+
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
if ( dy === 0 ) {
|
|
1108
|
+
|
|
1109
|
+
ymin -= thickness;
|
|
1110
|
+
ymax += thickness;
|
|
1111
|
+
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
if ( dz === 0 ) {
|
|
1115
|
+
|
|
1116
|
+
zmin -= thickness;
|
|
1117
|
+
zmax += thickness;
|
|
1118
|
+
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
const octree = new OctreeCell();
|
|
1122
|
+
octree.resetNbFaces( this._nbFaces );
|
|
1123
|
+
octree._setAabbLoose( xmin, ymin, zmin, xmax, ymax, zmax );
|
|
1124
|
+
octree._setAabbSplit(
|
|
1125
|
+
xmin - dx * 0.3, ymin - dy * 0.3, zmin - dz * 0.3,
|
|
1126
|
+
xmax + dx * 0.3, ymax + dy * 0.3, zmax + dz * 0.3
|
|
1127
|
+
);
|
|
1128
|
+
octree.build( this );
|
|
1129
|
+
|
|
1130
|
+
this._octree = octree;
|
|
1131
|
+
for ( let i = 0, l = this._leavesToUpdate.length; i < l; i ++ ) this._leavesToUpdate[ i ]._queuedForUpdate = false;
|
|
1132
|
+
this._leavesToUpdate.length = 0;
|
|
1133
|
+
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
_updateOctreeRemove( iFaces ) {
|
|
1137
|
+
|
|
1138
|
+
const faceBoxes = this._faceBoxes;
|
|
1139
|
+
const faceCenters = this._faceCenters;
|
|
1140
|
+
const faceLeaf = this._faceLeaf;
|
|
1141
|
+
const facePosInLeaf = this._facePosInLeaf;
|
|
1142
|
+
const facesToMove = new Uint32Array( getMemory( iFaces.length * 4 ), 0, iFaces.length );
|
|
1143
|
+
let count = 0;
|
|
1144
|
+
|
|
1145
|
+
for ( let i = 0, l = iFaces.length; i < l; ++ i ) {
|
|
1146
|
+
|
|
1147
|
+
const iFace = iFaces[ i ];
|
|
1148
|
+
const leaf = faceLeaf[ iFace ];
|
|
1149
|
+
const idCenter = iFace * 3;
|
|
1150
|
+
|
|
1151
|
+
if ( leaf === undefined || leaf === null ) {
|
|
1152
|
+
|
|
1153
|
+
facesToMove[ count ++ ] = iFace;
|
|
1154
|
+
continue;
|
|
1155
|
+
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
const split = leaf._aabbSplit;
|
|
1159
|
+
const x = faceCenters[ idCenter ];
|
|
1160
|
+
const y = faceCenters[ idCenter + 1 ];
|
|
1161
|
+
const z = faceCenters[ idCenter + 2 ];
|
|
1162
|
+
|
|
1163
|
+
if ( x <= split[ 0 ] || y <= split[ 1 ] || z <= split[ 2 ] || x > split[ 3 ] || y > split[ 4 ] || z > split[ 5 ] ) {
|
|
1164
|
+
|
|
1165
|
+
facesToMove[ count ++ ] = iFace;
|
|
1166
|
+
const facesInLeaf = leaf._iFaces;
|
|
1167
|
+
const position = facePosInLeaf[ iFace ];
|
|
1168
|
+
const lastFace = facesInLeaf[ facesInLeaf.length - 1 ];
|
|
1169
|
+
|
|
1170
|
+
facesInLeaf[ position ] = lastFace;
|
|
1171
|
+
facePosInLeaf[ lastFace ] = position;
|
|
1172
|
+
facesInLeaf.pop();
|
|
1173
|
+
queueLeaf( this._leavesToUpdate, leaf );
|
|
1174
|
+
|
|
1175
|
+
} else {
|
|
1176
|
+
|
|
1177
|
+
const idBox = iFace * 6;
|
|
1178
|
+
leaf._expandAabbLoose(
|
|
1179
|
+
faceBoxes[ idBox ], faceBoxes[ idBox + 1 ], faceBoxes[ idBox + 2 ],
|
|
1180
|
+
faceBoxes[ idBox + 3 ], faceBoxes[ idBox + 4 ], faceBoxes[ idBox + 5 ]
|
|
1181
|
+
);
|
|
1182
|
+
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
return facesToMove.subarray( 0, count );
|
|
1188
|
+
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
_updateOctreeAdd( iFaces ) {
|
|
1192
|
+
|
|
1193
|
+
const faceBoxes = this._faceBoxes;
|
|
1194
|
+
const faceCenters = this._faceCenters;
|
|
1195
|
+
const faceLeaf = this._faceLeaf;
|
|
1196
|
+
const facePosInLeaf = this._facePosInLeaf;
|
|
1197
|
+
|
|
1198
|
+
for ( let i = 0, l = iFaces.length; i < l; ++ i ) {
|
|
1199
|
+
|
|
1200
|
+
const iFace = iFaces[ i ];
|
|
1201
|
+
const idBox = iFace * 6;
|
|
1202
|
+
const idCenter = iFace * 3;
|
|
1203
|
+
const newLeaf = this._octree.addFace(
|
|
1204
|
+
iFace,
|
|
1205
|
+
faceBoxes[ idBox ], faceBoxes[ idBox + 1 ], faceBoxes[ idBox + 2 ],
|
|
1206
|
+
faceBoxes[ idBox + 3 ], faceBoxes[ idBox + 4 ], faceBoxes[ idBox + 5 ],
|
|
1207
|
+
faceCenters[ idCenter ], faceCenters[ idCenter + 1 ], faceCenters[ idCenter + 2 ]
|
|
1208
|
+
);
|
|
1209
|
+
|
|
1210
|
+
if ( newLeaf === undefined ) {
|
|
1211
|
+
|
|
1212
|
+
this._computeOctree();
|
|
1213
|
+
return;
|
|
1214
|
+
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1217
|
+
faceLeaf[ iFace ] = newLeaf;
|
|
1218
|
+
facePosInLeaf[ iFace ] = newLeaf._iFaces.length - 1;
|
|
1219
|
+
queueLeaf( this._leavesToUpdate, newLeaf );
|
|
1220
|
+
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
// Mesh queries
|
|
1226
|
+
|
|
1227
|
+
intersectRay( vNear, eyeDir ) {
|
|
1228
|
+
|
|
1229
|
+
const nbFaces = this._nbFaces;
|
|
1230
|
+
const collectBuffer = new Uint32Array( getMemory( nbFaces * 4 ), 0, nbFaces );
|
|
1231
|
+
return this._octree.collectIntersectRay( vNear, eyeDir, collectBuffer );
|
|
1232
|
+
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
intersectSphere( center, radiusSq, collectLeaves = false ) {
|
|
1236
|
+
|
|
1237
|
+
const nbFaces = this._nbFaces;
|
|
1238
|
+
const collectBuffer = new Uint32Array( getMemory( nbFaces * 4 ), 0, nbFaces );
|
|
1239
|
+
return this._octree.collectIntersectSphere( center, radiusSq, collectBuffer, collectLeaves ? this._leavesToUpdate : undefined );
|
|
1240
|
+
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
getVerticesFromFaces( iFaces ) {
|
|
1244
|
+
|
|
1245
|
+
const tagFlag = this.nextTagFlag();
|
|
1246
|
+
const nbFaces = iFaces.length;
|
|
1247
|
+
const vtf = this._vertTagFlags;
|
|
1248
|
+
const fAr = this._facesABCD;
|
|
1249
|
+
let acc = 0;
|
|
1250
|
+
const verts = new Uint32Array( getMemory( 3 * nbFaces * 4 ), 0, nbFaces * 3 );
|
|
1251
|
+
for ( let i = 0; i < nbFaces; ++ i ) {
|
|
1252
|
+
|
|
1253
|
+
const ind = iFaces[ i ] * 4;
|
|
1254
|
+
const iv1 = fAr[ ind ], iv2 = fAr[ ind + 1 ], iv3 = fAr[ ind + 2 ];
|
|
1255
|
+
if ( vtf[ iv1 ] !== tagFlag ) {
|
|
1256
|
+
|
|
1257
|
+
vtf[ iv1 ] = tagFlag; verts[ acc ++ ] = iv1;
|
|
1258
|
+
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1261
|
+
if ( vtf[ iv2 ] !== tagFlag ) {
|
|
1262
|
+
|
|
1263
|
+
vtf[ iv2 ] = tagFlag; verts[ acc ++ ] = iv2;
|
|
1264
|
+
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
if ( vtf[ iv3 ] !== tagFlag ) {
|
|
1268
|
+
|
|
1269
|
+
vtf[ iv3 ] = tagFlag; verts[ acc ++ ] = iv3;
|
|
1270
|
+
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
return verts.slice( 0, acc );
|
|
1276
|
+
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
getFacesFromVertices( iVerts ) {
|
|
1280
|
+
|
|
1281
|
+
const tagFlag = this.nextTagFlag();
|
|
1282
|
+
const ftf = this._facesTagFlags;
|
|
1283
|
+
const frings = this._vertRingFace;
|
|
1284
|
+
const nbVerts = iVerts.length;
|
|
1285
|
+
const faces = new Uint32Array( getMemory( 4 * this._nbFaces ), 0, this._nbFaces );
|
|
1286
|
+
let acc = 0;
|
|
1287
|
+
for ( let i = 0; i < nbVerts; ++ i ) {
|
|
1288
|
+
|
|
1289
|
+
const fring = frings[ iVerts[ i ] ];
|
|
1290
|
+
for ( let j = 0, l = fring.length; j < l; ++ j ) {
|
|
1291
|
+
|
|
1292
|
+
const iFace = fring[ j ];
|
|
1293
|
+
if ( ftf[ iFace ] !== tagFlag ) {
|
|
1294
|
+
|
|
1295
|
+
ftf[ iFace ] = tagFlag;
|
|
1296
|
+
faces[ acc ++ ] = iFace;
|
|
1297
|
+
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
return faces.slice( 0, acc );
|
|
1305
|
+
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
expandsFaces( iFaces, nRing ) {
|
|
1309
|
+
|
|
1310
|
+
const tagFlag = this.nextTagFlag();
|
|
1311
|
+
let nbFaces = iFaces.length;
|
|
1312
|
+
const ftf = this._facesTagFlags;
|
|
1313
|
+
const fAr = this._facesABCD;
|
|
1314
|
+
const ringFaces = this._vertRingFace;
|
|
1315
|
+
let acc = nbFaces;
|
|
1316
|
+
const iFacesExpanded = new Uint32Array( getMemory( 4 * this._nbFaces ), 0, this._nbFaces );
|
|
1317
|
+
iFacesExpanded.set( iFaces );
|
|
1318
|
+
for ( let i = 0; i < nbFaces; ++ i ) ftf[ iFacesExpanded[ i ] ] = tagFlag;
|
|
1319
|
+
let iBegin = 0;
|
|
1320
|
+
while ( nRing ) {
|
|
1321
|
+
|
|
1322
|
+
-- nRing;
|
|
1323
|
+
for ( let i = iBegin; i < nbFaces; ++ i ) {
|
|
1324
|
+
|
|
1325
|
+
const ind = iFacesExpanded[ i ] * 4;
|
|
1326
|
+
for ( let j = 0; j < 3; ++ j ) {
|
|
1327
|
+
|
|
1328
|
+
const idv = fAr[ ind + j ];
|
|
1329
|
+
const vrf = ringFaces[ idv ];
|
|
1330
|
+
for ( let k = 0, l = vrf.length; k < l; ++ k ) {
|
|
1331
|
+
|
|
1332
|
+
const id = vrf[ k ];
|
|
1333
|
+
if ( ftf[ id ] === tagFlag ) continue;
|
|
1334
|
+
ftf[ id ] = tagFlag;
|
|
1335
|
+
iFacesExpanded[ acc ++ ] = id;
|
|
1336
|
+
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
iBegin = nbFaces;
|
|
1344
|
+
nbFaces = acc;
|
|
1345
|
+
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
return iFacesExpanded.slice( 0, acc );
|
|
1349
|
+
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
expandsVertices( iVerts, nRing ) {
|
|
1353
|
+
|
|
1354
|
+
const tagFlag = this.nextTagFlag();
|
|
1355
|
+
let nbVerts = iVerts.length;
|
|
1356
|
+
const vrings = this._vertRingVert;
|
|
1357
|
+
const vtf = this._vertTagFlags;
|
|
1358
|
+
let acc = nbVerts;
|
|
1359
|
+
const nbVertices = this._nbVertices;
|
|
1360
|
+
const iVertsExpanded = new Uint32Array( getMemory( 4 * nbVertices ), 0, nbVertices );
|
|
1361
|
+
iVertsExpanded.set( iVerts );
|
|
1362
|
+
for ( let i = 0; i < nbVerts; ++ i ) vtf[ iVertsExpanded[ i ] ] = tagFlag;
|
|
1363
|
+
let iBegin = 0;
|
|
1364
|
+
while ( nRing ) {
|
|
1365
|
+
|
|
1366
|
+
-- nRing;
|
|
1367
|
+
for ( let i = iBegin; i < nbVerts; ++ i ) {
|
|
1368
|
+
|
|
1369
|
+
const ring = vrings[ iVertsExpanded[ i ] ];
|
|
1370
|
+
for ( let j = 0, l = ring.length; j < l; ++ j ) {
|
|
1371
|
+
|
|
1372
|
+
const id = ring[ j ];
|
|
1373
|
+
if ( vtf[ id ] === tagFlag ) continue;
|
|
1374
|
+
vtf[ id ] = tagFlag;
|
|
1375
|
+
iVertsExpanded[ acc ++ ] = id;
|
|
1376
|
+
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
iBegin = nbVerts;
|
|
1382
|
+
nbVerts = acc;
|
|
1383
|
+
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
return iVertsExpanded.slice( 0, acc );
|
|
1387
|
+
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
// Dynamic topology
|
|
1391
|
+
|
|
1392
|
+
updateRenderTriangles( iFaces ) {
|
|
1393
|
+
|
|
1394
|
+
const tAr = this._trianglesABC;
|
|
1395
|
+
const fAr = this._facesABCD;
|
|
1396
|
+
const full = iFaces === undefined;
|
|
1397
|
+
const nbFaces = full ? this._nbFaces : iFaces.length;
|
|
1398
|
+
for ( let i = 0; i < nbFaces; ++ i ) {
|
|
1399
|
+
|
|
1400
|
+
const id = full ? i : iFaces[ i ];
|
|
1401
|
+
const idt = id * 3;
|
|
1402
|
+
const idf = id * 4;
|
|
1403
|
+
tAr[ idt ] = fAr[ idf ];
|
|
1404
|
+
tAr[ idt + 1 ] = fAr[ idf + 1 ];
|
|
1405
|
+
tAr[ idt + 2 ] = fAr[ idf + 2 ];
|
|
1406
|
+
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
updateVerticesOnEdge( iVerts ) {
|
|
1412
|
+
|
|
1413
|
+
const vOnEdge = this._vertOnEdge;
|
|
1414
|
+
const vrings = this._vertRingVert;
|
|
1415
|
+
const frings = this._vertRingFace;
|
|
1416
|
+
const full = iVerts === undefined;
|
|
1417
|
+
const nbVerts = full ? this._nbVertices : iVerts.length;
|
|
1418
|
+
for ( let i = 0; i < nbVerts; ++ i ) {
|
|
1419
|
+
|
|
1420
|
+
const id = full ? i : iVerts[ i ];
|
|
1421
|
+
vOnEdge[ id ] = vrings[ id ].length !== frings[ id ].length ? 1 : 0;
|
|
1422
|
+
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
updateTopology( iFaces, iVerts ) {
|
|
1428
|
+
|
|
1429
|
+
this.updateRenderTriangles( iFaces );
|
|
1430
|
+
this.updateVerticesOnEdge( iVerts );
|
|
1431
|
+
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
_resizeArray( array, requiredLength ) {
|
|
1435
|
+
|
|
1436
|
+
if ( array === null ) return null;
|
|
1437
|
+
|
|
1438
|
+
const resized = new array.constructor( requiredLength * 2 );
|
|
1439
|
+
resized.set( array.subarray( 0, Math.min( array.length, resized.length ) ) );
|
|
1440
|
+
return resized;
|
|
1441
|
+
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
reAllocateArrays( nbAddElements ) {
|
|
1445
|
+
|
|
1446
|
+
let capacity = this._facesABCD.length / 4;
|
|
1447
|
+
let requiredCount = this._nbFaces + nbAddElements;
|
|
1448
|
+
|
|
1449
|
+
if ( capacity < requiredCount || capacity > requiredCount * 4 ) {
|
|
1450
|
+
|
|
1451
|
+
this._facesABCD = this._resizeArray( this._facesABCD, requiredCount * 4 );
|
|
1452
|
+
this._trianglesABC = this._resizeArray( this._trianglesABC, requiredCount * 3 );
|
|
1453
|
+
this._faceBoxes = this._resizeArray( this._faceBoxes, requiredCount * 6 );
|
|
1454
|
+
this._faceNormals = this._resizeArray( this._faceNormals, requiredCount * 3 );
|
|
1455
|
+
this._faceCenters = this._resizeArray( this._faceCenters, requiredCount * 3 );
|
|
1456
|
+
this._facesTagFlags = this._resizeArray( this._facesTagFlags, requiredCount );
|
|
1457
|
+
this._facePosInLeaf = this._resizeArray( this._facePosInLeaf, requiredCount );
|
|
1458
|
+
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
capacity = this._verticesXYZ.length / 3;
|
|
1462
|
+
requiredCount = this._nbVertices + nbAddElements;
|
|
1463
|
+
|
|
1464
|
+
if ( capacity < requiredCount || capacity > requiredCount * 4 ) {
|
|
1465
|
+
|
|
1466
|
+
this._verticesXYZ = this._resizeArray( this._verticesXYZ, requiredCount * 3 );
|
|
1467
|
+
this._normalsXYZ = this._resizeArray( this._normalsXYZ, requiredCount * 3 );
|
|
1468
|
+
this._renderNormalsXYZ = this._resizeArray( this._renderNormalsXYZ, requiredCount * 3 );
|
|
1469
|
+
this._vertOnEdge = this._resizeArray( this._vertOnEdge, requiredCount );
|
|
1470
|
+
this._vertTagFlags = this._resizeArray( this._vertTagFlags, requiredCount );
|
|
1471
|
+
this._vertSculptFlags = this._resizeArray( this._vertSculptFlags, requiredCount );
|
|
1472
|
+
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
balanceOctree() {
|
|
1478
|
+
|
|
1479
|
+
const leaves = this._leavesToUpdate;
|
|
1480
|
+
|
|
1481
|
+
for ( let i = 0, l = leaves.length; i < l; ++ i ) {
|
|
1482
|
+
|
|
1483
|
+
const leaf = leaves[ i ];
|
|
1484
|
+
leaf._queuedForUpdate = false;
|
|
1485
|
+
|
|
1486
|
+
if ( leaf._iFaces.length === 0 ) {
|
|
1487
|
+
|
|
1488
|
+
leaf.pruneIfPossible();
|
|
1489
|
+
|
|
1490
|
+
} else if ( leaf._iFaces.length > OCTREE_MAX_FACES && leaf._depth < OCTREE_MAX_DEPTH ) {
|
|
1491
|
+
|
|
1492
|
+
leaf.build( this );
|
|
1493
|
+
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
leaves.length = 0;
|
|
1499
|
+
|
|
1500
|
+
}
|
|
1501
|
+
|
|
1502
|
+
}
|
|
1503
|
+
|
|
1504
|
+
export { SculptorMesh };
|