@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,865 @@
|
|
|
1
|
+
import { Box2, BufferGeometry, Float32BufferAttribute, Vector2, Vector3 } from 'three';
|
|
2
|
+
import { remapAttribute } from './BufferGeometryUtils.js';
|
|
3
|
+
import { potpack } from '../libs/potpack.module.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Generates a unique UV atlas for the meshes in a hierarchy, measured in world space.
|
|
7
|
+
* Each mesh receives a new geometry. Skinned and morphed meshes are unwrapped in
|
|
8
|
+
* their current pose. InstancedMesh and BatchedMesh are skipped with a warning.
|
|
9
|
+
* Excluded faces collapse onto the UV of a neighboring chart vertex, or (0, 0) if
|
|
10
|
+
* isolated, and get a faceCharts entry of -1.
|
|
11
|
+
*
|
|
12
|
+
* @three_import import { unwrapUVs } from 'three/addons/utils/unwrapUVs.js';
|
|
13
|
+
*
|
|
14
|
+
* @param {Object3D} root - A mesh or hierarchy to unwrap.
|
|
15
|
+
* @param {Object} [options] - Atlas and chart options.
|
|
16
|
+
* @param {string} [options.attribute='uv1'] - Output attribute: uv, uv1, uv2, uv3.
|
|
17
|
+
* @param {string} [options.mode='lightmap'] - 'lightmap' or 'normal'. Normal tries LSCM.
|
|
18
|
+
* @param {number} [options.resolution=1024] - Square atlas size in pixels, integer >= 4.
|
|
19
|
+
* @param {number} [options.padding=4] - Nonnegative gutter in pixels; 2 * padding + 1 must be less than resolution.
|
|
20
|
+
* @param {number} [options.texelsPerUnit=0] - Common world density; zero fits the atlas. Must be nonnegative.
|
|
21
|
+
* @param {boolean} [options.respectUVSeams] - Cut discontinuities in existing uv (normal default).
|
|
22
|
+
* @param {boolean} [options.useInputUVs=false] - Preserve valid authored UV charts before trying LSCM.
|
|
23
|
+
* @return {?Object} Atlas size, density, chart bounds, mesh vertex/face mappings and warning
|
|
24
|
+
* counts (excluded faces, tiny faces under 0.01 atlas pixels squared and single-triangle
|
|
25
|
+
* charts, which signal fragmentation), or null if the charts do not fit. Meshes are left
|
|
26
|
+
* unchanged in that case. Charts that fail Float32 validation are split and repacked;
|
|
27
|
+
* single faces that still fail are excluded.
|
|
28
|
+
*/
|
|
29
|
+
function unwrapUVs( root, options = {} ) {
|
|
30
|
+
|
|
31
|
+
const settings = {
|
|
32
|
+
attribute: 'uv1', mode: 'lightmap', resolution: 1024, padding: 4,
|
|
33
|
+
texelsPerUnit: 0,
|
|
34
|
+
useInputUVs: false,
|
|
35
|
+
...options, maxAreaRatio: 2
|
|
36
|
+
};
|
|
37
|
+
settings.maxStretch = settings.mode === 'normal' ? 2 : 1.5;
|
|
38
|
+
settings.respectUVSeams ??= settings.mode === 'normal';
|
|
39
|
+
root.updateWorldMatrix( true, true );
|
|
40
|
+
|
|
41
|
+
const records = [];
|
|
42
|
+
root.traverse( mesh => {
|
|
43
|
+
|
|
44
|
+
if ( ! mesh.isMesh ) return;
|
|
45
|
+
if ( mesh.isInstancedMesh || mesh.isBatchedMesh ) {
|
|
46
|
+
|
|
47
|
+
console.warn( 'THREE.unwrapUVs(): InstancedMesh and BatchedMesh are not supported. Skipping mesh.', mesh );
|
|
48
|
+
return;
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
records.push( readMesh( mesh, settings ) );
|
|
53
|
+
|
|
54
|
+
} );
|
|
55
|
+
|
|
56
|
+
const charts = [];
|
|
57
|
+
for ( const record of records ) {
|
|
58
|
+
|
|
59
|
+
for ( const faces of growCharts( record, settings ) ) {
|
|
60
|
+
|
|
61
|
+
parameterize( record, faces, settings, charts );
|
|
62
|
+
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
let density;
|
|
68
|
+
for ( ; ; ) {
|
|
69
|
+
|
|
70
|
+
density = packCharts( charts, settings );
|
|
71
|
+
if ( density === null ) return null;
|
|
72
|
+
|
|
73
|
+
const failed = [];
|
|
74
|
+
for ( let i = charts.length - 1; i >= 0; i -- ) {
|
|
75
|
+
|
|
76
|
+
if ( validateFloat32Chart( charts[ i ], settings, density ) === null ) failed.push( ...charts.splice( i, 1 ) );
|
|
77
|
+
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if ( failed.length === 0 ) break;
|
|
81
|
+
|
|
82
|
+
// Float32 rounding broke these charts at this density; split them and repack.
|
|
83
|
+
for ( const chart of failed ) splitFaces( chart.record, chart.faces, settings, charts );
|
|
84
|
+
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
for ( let i = charts.length - 1; i >= 0; i -- ) {
|
|
88
|
+
|
|
89
|
+
if ( charts[ i ].dropped.size === charts[ i ].faces.length ) charts.splice( i, 1 );
|
|
90
|
+
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
for ( let i = 0; i < charts.length; i ++ ) {
|
|
94
|
+
|
|
95
|
+
charts[ i ].faces.forEach( ( face, t ) => {
|
|
96
|
+
|
|
97
|
+
if ( ! charts[ i ].dropped.has( t ) ) charts[ i ].record.faceCharts[ face ] = i;
|
|
98
|
+
|
|
99
|
+
} );
|
|
100
|
+
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
for ( const record of records ) record.mesh.geometry = rebuildGeometry( record, charts, settings );
|
|
104
|
+
|
|
105
|
+
let tinyFaces = 0;
|
|
106
|
+
for ( const chart of charts ) {
|
|
107
|
+
|
|
108
|
+
for ( const [ t, triangle ] of chart.triangles.entries() ) {
|
|
109
|
+
|
|
110
|
+
if ( ! chart.dropped.has( t ) && Math.abs( cross2( ...triangle.map( i => chart.outputUV[ i ] ) ) ) * settings.resolution ** 2 / 2 < 0.01 ) tinyFaces ++;
|
|
111
|
+
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const excludedFaces = records.reduce( ( sum, record ) => sum + record.faceCharts.filter( chart => chart === - 1 ).length, 0 );
|
|
117
|
+
const singleTriangleCharts = charts.filter( chart => chart.faces.length === 1 ).length;
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
attribute: settings.attribute, resolution: settings.resolution, padding: settings.padding,
|
|
121
|
+
texelsPerUnit: density,
|
|
122
|
+
charts: charts.map( chart => ( { x: chart.box.x, y: chart.box.y, width: chart.box.w, height: chart.box.h } ) ),
|
|
123
|
+
meshes: records.map( record => ( { mesh: record.mesh, sourceVertices: record.sourceVertices, faceCharts: record.faceCharts } ) ),
|
|
124
|
+
warnings: { excludedFaces, tinyFaces, singleTriangleCharts }
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function readMesh( mesh, settings ) {
|
|
130
|
+
|
|
131
|
+
mesh.updateMatrixWorld( true ); // Also refresh SkinnedMesh.bindMatrixInverse.
|
|
132
|
+
if ( mesh.isSkinnedMesh ) {
|
|
133
|
+
|
|
134
|
+
for ( const bone of mesh.skeleton.bones ) bone.updateWorldMatrix( true, false );
|
|
135
|
+
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const geometry = mesh.geometry, position = geometry.getAttribute( 'position' );
|
|
139
|
+
const index = geometry.index;
|
|
140
|
+
const count = index ? index.count : position.count;
|
|
141
|
+
const points = [], welds = [], unique = new Map();
|
|
142
|
+
for ( let i = 0; i < position.count; i ++ ) {
|
|
143
|
+
|
|
144
|
+
// Exact positional welding only, for topology; output attributes keep original identity.
|
|
145
|
+
const key = `${ position.getX( i ) },${ position.getY( i ) },${ position.getZ( i ) }`;
|
|
146
|
+
if ( ! unique.has( key ) ) unique.set( key, unique.size );
|
|
147
|
+
welds.push( unique.get( key ) );
|
|
148
|
+
points.push( mesh.getVertexPosition( i, new Vector3() ).applyMatrix4( mesh.matrixWorld ) );
|
|
149
|
+
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const materials = new Int32Array( count / 3 );
|
|
153
|
+
for ( const group of geometry.groups ) {
|
|
154
|
+
|
|
155
|
+
materials.fill( group.materialIndex, group.start / 3, ( group.start + group.count ) / 3 );
|
|
156
|
+
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const faces = [], edges = new Map();
|
|
160
|
+
for ( let offset = 0; offset < count; offset += 3 ) {
|
|
161
|
+
|
|
162
|
+
const vertices = [ 0, 1, 2 ].map( j => index ? index.getX( offset + j ) : offset + j );
|
|
163
|
+
const normal = new Vector3().subVectors( points[ vertices[ 1 ] ], points[ vertices[ 0 ] ] );
|
|
164
|
+
normal.cross( new Vector3().subVectors( points[ vertices[ 2 ] ], points[ vertices[ 0 ] ] ) );
|
|
165
|
+
const area = normal.length() * 0.5;
|
|
166
|
+
const longest = Math.max( ...[ 0, 1, 2 ].map( j => points[ vertices[ j ] ].distanceToSquared( points[ vertices[ ( j + 1 ) % 3 ] ] ) ) );
|
|
167
|
+
// slivers beyond Float32 precision are excluded from the atlas
|
|
168
|
+
const ignored = ! ( area > longest * 1e-6 );
|
|
169
|
+
const face = { vertices, welds: vertices.map( v => welds[ v ] ), normal: normal.normalize(), area, ignored, neighbors: [] };
|
|
170
|
+
const f = faces.length;
|
|
171
|
+
faces.push( face );
|
|
172
|
+
if ( face.ignored ) continue;
|
|
173
|
+
|
|
174
|
+
for ( let j = 0; j < 3; j ++ ) {
|
|
175
|
+
|
|
176
|
+
const a = face.welds[ j ], b = face.welds[ ( j + 1 ) % 3 ];
|
|
177
|
+
const key = a < b ? `${ a },${ b }` : `${ b },${ a }`;
|
|
178
|
+
if ( ! edges.has( key ) ) edges.set( key, [] );
|
|
179
|
+
edges.get( key ).push( { f, j, a, b } );
|
|
180
|
+
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const uv = geometry.getAttribute( 'uv' );
|
|
186
|
+
for ( const edge of edges.values() ) {
|
|
187
|
+
|
|
188
|
+
// Pair opposite half-edges by closest normal, so duplicated double-sided shells
|
|
189
|
+
// (four faces per edge) join each side separately instead of becoming all seams.
|
|
190
|
+
const pairs = [], used = new Set();
|
|
191
|
+
for ( const x of edge ) {
|
|
192
|
+
|
|
193
|
+
let best = null, bestDot = - Infinity;
|
|
194
|
+
for ( const y of edge ) {
|
|
195
|
+
|
|
196
|
+
if ( used.has( x ) || used.has( y ) || y.a !== x.b || y.b !== x.a || materials[ x.f ] !== materials[ y.f ] ) continue;
|
|
197
|
+
const dot = faces[ x.f ].normal.dot( faces[ y.f ].normal );
|
|
198
|
+
if ( dot > bestDot ) {
|
|
199
|
+
|
|
200
|
+
best = y; bestDot = dot;
|
|
201
|
+
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if ( best ) {
|
|
207
|
+
|
|
208
|
+
pairs.push( [ x, best ] );
|
|
209
|
+
used.add( x ).add( best );
|
|
210
|
+
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
for ( const [ a, b ] of pairs ) {
|
|
216
|
+
|
|
217
|
+
if ( ( settings.respectUVSeams || settings.useInputUVs ) && uv ) {
|
|
218
|
+
|
|
219
|
+
const av = faces[ a.f ].vertices, bv = faces[ b.f ].vertices;
|
|
220
|
+
if ( ! equalUV( uv, av[ a.j ], bv[ ( b.j + 1 ) % 3 ] ) || ! equalUV( uv, av[ ( a.j + 1 ) % 3 ], bv[ b.j ] ) ) continue;
|
|
221
|
+
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
faces[ a.f ].neighbors.push( b.f );
|
|
225
|
+
faces[ b.f ].neighbors.push( a.f );
|
|
226
|
+
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// UV discontinuities can be cuts inside a connected chart (e.g. a slit
|
|
232
|
+
// cylinder). Keep the two coincident seam endpoints distinct in the solver.
|
|
233
|
+
const vertexKeys = welds.map( ( weld, i ) => uv && ( settings.respectUVSeams || settings.useInputUVs ) ? `${ weld },${ uv.getX( i ) },${ uv.getY( i ) }` : weld );
|
|
234
|
+
return { mesh, original: geometry, points, faces, vertexKeys, faceCharts: new Int32Array( faces.length ).fill( - 1 ) };
|
|
235
|
+
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function equalUV( uv, a, b ) {
|
|
239
|
+
|
|
240
|
+
return uv.getX( a ) === uv.getX( b ) && uv.getY( a ) === uv.getY( b );
|
|
241
|
+
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function growCharts( record, settings ) {
|
|
245
|
+
|
|
246
|
+
const assigned = new Uint8Array( record.faces.length ), charts = [];
|
|
247
|
+
// Lightmap charts use planar projection; keep the costlier LSCM charts smaller.
|
|
248
|
+
const limit = settings.mode === 'lightmap' ? 8192 : 2048;
|
|
249
|
+
// Wider normal cones in normal mode give LSCM useful curved patches to solve.
|
|
250
|
+
const cosine = settings.useInputUVs && record.original.attributes.uv ? - 1 : settings.mode === 'normal' ? 0.35 : 1 / settings.maxStretch;
|
|
251
|
+
for ( let seed = 0; seed < assigned.length; seed ++ ) {
|
|
252
|
+
|
|
253
|
+
if ( assigned[ seed ] || record.faces[ seed ].ignored ) continue;
|
|
254
|
+
const faces = [ seed ], normal = record.faces[ seed ].normal;
|
|
255
|
+
assigned[ seed ] = 1;
|
|
256
|
+
for ( let i = 0; i < faces.length && faces.length < limit; i ++ ) {
|
|
257
|
+
|
|
258
|
+
for ( const neighbor of record.faces[ faces[ i ] ].neighbors ) {
|
|
259
|
+
|
|
260
|
+
if ( assigned[ neighbor ] || record.faces[ neighbor ].normal.dot( normal ) < cosine ) continue;
|
|
261
|
+
assigned[ neighbor ] = 1;
|
|
262
|
+
faces.push( neighbor );
|
|
263
|
+
if ( faces.length === limit ) break;
|
|
264
|
+
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
charts.push( faces );
|
|
270
|
+
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
return charts;
|
|
274
|
+
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function parameterize( record, faces, settings, charts ) {
|
|
278
|
+
|
|
279
|
+
const normal = new Vector3();
|
|
280
|
+
for ( const f of faces ) normal.addScaledVector( record.faces[ f ].normal, record.faces[ f ].area );
|
|
281
|
+
normal.normalize();
|
|
282
|
+
const axis = Math.abs( normal.x ) < 0.8 ? new Vector3( 1, 0, 0 ) : new Vector3( 0, 1, 0 );
|
|
283
|
+
const u = axis.cross( normal ).normalize(), v = new Vector3().crossVectors( normal, u );
|
|
284
|
+
const vertexMap = new Map(), positions = [], uv = [], triangles = [];
|
|
285
|
+
const useInput = settings.useInputUVs && record.original.attributes.uv;
|
|
286
|
+
const origin = record.points[ record.faces[ faces[ 0 ] ].vertices[ 0 ] ];
|
|
287
|
+
let worldArea = 0;
|
|
288
|
+
for ( const f of faces ) {
|
|
289
|
+
|
|
290
|
+
const face = record.faces[ f ];
|
|
291
|
+
worldArea += face.area;
|
|
292
|
+
triangles.push( face.vertices.map( vertex => {
|
|
293
|
+
|
|
294
|
+
const key = record.vertexKeys[ vertex ];
|
|
295
|
+
if ( ! vertexMap.has( key ) ) {
|
|
296
|
+
|
|
297
|
+
vertexMap.set( key, positions.length );
|
|
298
|
+
const p = record.points[ vertex ].clone().sub( origin );
|
|
299
|
+
positions.push( p );
|
|
300
|
+
uv.push( useInput ? [ useInput.getX( vertex ), useInput.getY( vertex ) ] : [ p.dot( u ), p.dot( v ) ] );
|
|
301
|
+
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return vertexMap.get( key );
|
|
305
|
+
|
|
306
|
+
} ) );
|
|
307
|
+
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
if ( useInput && triangles.reduce( ( sum, tri ) => sum + cross2( ...tri.map( i => uv[ i ] ) ), 0 ) < 0 ) {
|
|
311
|
+
|
|
312
|
+
for ( const p of uv ) p[ 1 ] = - p[ 1 ];
|
|
313
|
+
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
let candidate = uv;
|
|
317
|
+
const initialQuality = checkChart( positions, triangles, uv, worldArea, settings );
|
|
318
|
+
let quality = initialQuality;
|
|
319
|
+
if ( settings.mode === 'normal' && faces.length > 1 && ! ( initialQuality && ( useInput || initialQuality.maxStretch < 1.000001 ) ) ) {
|
|
320
|
+
|
|
321
|
+
const conformal = solveLSCM( positions, triangles, uv );
|
|
322
|
+
const conformalQuality = conformal && checkChart( positions, triangles, conformal, worldArea, settings );
|
|
323
|
+
if ( conformalQuality ) {
|
|
324
|
+
|
|
325
|
+
candidate = conformal;
|
|
326
|
+
quality = conformalQuality;
|
|
327
|
+
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if ( ! quality ) {
|
|
333
|
+
|
|
334
|
+
if ( useInput && ( settings.mode === 'lightmap' || faces.length === 1 ) ) {
|
|
335
|
+
|
|
336
|
+
// Reproject a rejected lightmap island before splitting its authored UVs
|
|
337
|
+
// into one chart per triangle. Normal mode already tries LSCM above.
|
|
338
|
+
parameterize( record, faces, { ...settings, useInputUVs: false }, charts );
|
|
339
|
+
return;
|
|
340
|
+
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
if ( faces.length === 1 ) {
|
|
344
|
+
|
|
345
|
+
record.faces[ faces[ 0 ] ].ignored = true;
|
|
346
|
+
return;
|
|
347
|
+
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
splitFaces( record, faces, settings, charts );
|
|
351
|
+
return;
|
|
352
|
+
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
const scale = Math.sqrt( worldArea / quality.area );
|
|
356
|
+
for ( const p of candidate ) {
|
|
357
|
+
|
|
358
|
+
p[ 0 ] *= scale; p[ 1 ] *= scale;
|
|
359
|
+
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// Principal-axis alignment reduces rectangle waste without reflection.
|
|
363
|
+
alignChart( candidate );
|
|
364
|
+
const bounds = getBounds( candidate );
|
|
365
|
+
for ( const p of candidate ) {
|
|
366
|
+
|
|
367
|
+
p[ 0 ] -= bounds.min.x; p[ 1 ] -= bounds.min.y;
|
|
368
|
+
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
charts.push( {
|
|
372
|
+
record, faces, vertexMap, uv: candidate, worldArea,
|
|
373
|
+
width: bounds.max.x - bounds.min.x, height: bounds.max.y - bounds.min.y,
|
|
374
|
+
positions, triangles
|
|
375
|
+
} );
|
|
376
|
+
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
function splitFaces( record, faces, settings, charts ) {
|
|
380
|
+
|
|
381
|
+
const half = Math.floor( faces.length / 2 );
|
|
382
|
+
for ( const subset of [ faces.slice( 0, half ), faces.slice( half ) ] ) {
|
|
383
|
+
|
|
384
|
+
for ( const component of connectedComponents( record, subset ) ) parameterize( record, component, settings, charts );
|
|
385
|
+
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function connectedComponents( record, faces ) {
|
|
391
|
+
|
|
392
|
+
const remaining = new Set( faces ), components = [];
|
|
393
|
+
for ( const seed of faces ) {
|
|
394
|
+
|
|
395
|
+
if ( ! remaining.delete( seed ) ) continue;
|
|
396
|
+
const component = [ seed ];
|
|
397
|
+
for ( let i = 0; i < component.length; i ++ ) {
|
|
398
|
+
|
|
399
|
+
for ( const neighbor of record.faces[ component[ i ] ].neighbors ) {
|
|
400
|
+
|
|
401
|
+
if ( remaining.delete( neighbor ) ) component.push( neighbor );
|
|
402
|
+
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
components.push( component );
|
|
408
|
+
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
return components;
|
|
412
|
+
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function checkChart( positions, triangles, uv, worldArea, settings ) {
|
|
416
|
+
|
|
417
|
+
if ( uv.some( p => ! Number.isFinite( p[ 0 ] + p[ 1 ] ) ) ) return null;
|
|
418
|
+
let area = 0, maxStretch = 1, minRatio = Infinity, maxRatio = 0;
|
|
419
|
+
for ( const tri of triangles ) {
|
|
420
|
+
|
|
421
|
+
const { length, x, y, cross } = triangleFrame( positions, tri );
|
|
422
|
+
const [ p, q, r ] = tri.map( i => uv[ i ] );
|
|
423
|
+
const determinant = cross2( p, q, r );
|
|
424
|
+
if ( ! ( determinant > 0 ) ) return null;
|
|
425
|
+
area += determinant * 0.5;
|
|
426
|
+
const ux = ( q[ 0 ] - p[ 0 ] ) / length, vx = ( q[ 1 ] - p[ 1 ] ) / length;
|
|
427
|
+
const uy = ( r[ 0 ] - p[ 0 ] - ux * x ) / y, vy = ( r[ 1 ] - p[ 1 ] - vx * x ) / y;
|
|
428
|
+
const aa = ux * ux + vx * vx, bb = uy * uy + vy * vy, cc = ux * uy + vx * vy;
|
|
429
|
+
const trace = aa + bb, difference = aa - bb, delta = Math.sqrt( difference * difference + 4 * cc * cc );
|
|
430
|
+
// Use determinant for the small eigenvalue to avoid subtractive cancellation.
|
|
431
|
+
const largest = ( trace + delta ) * 0.5;
|
|
432
|
+
const jacobianDet = determinant / cross;
|
|
433
|
+
const stretch = largest / jacobianDet;
|
|
434
|
+
if ( ! Number.isFinite( stretch ) || stretch > settings.maxStretch * ( 1 + 1e-8 ) ) return null;
|
|
435
|
+
maxStretch = Math.max( maxStretch, stretch );
|
|
436
|
+
minRatio = Math.min( minRatio, jacobianDet );
|
|
437
|
+
maxRatio = Math.max( maxRatio, jacobianDet );
|
|
438
|
+
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
const mean = area / worldArea;
|
|
442
|
+
if ( minRatio / mean < 1 / settings.maxAreaRatio - 1e-8 || maxRatio / mean > settings.maxAreaRatio + 1e-8 ) return null;
|
|
443
|
+
if ( hasOverlap( uv, triangles ) ) return null;
|
|
444
|
+
return { area, maxStretch };
|
|
445
|
+
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function cross2( a, b, c ) {
|
|
449
|
+
|
|
450
|
+
return ( b[ 0 ] - a[ 0 ] ) * ( c[ 1 ] - a[ 1 ] ) - ( b[ 1 ] - a[ 1 ] ) * ( c[ 0 ] - a[ 0 ] );
|
|
451
|
+
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
function getBounds( points ) {
|
|
455
|
+
|
|
456
|
+
const bounds = new Box2(), point = new Vector2();
|
|
457
|
+
for ( const p of points ) bounds.expandByPoint( point.set( p[ 0 ], p[ 1 ] ) );
|
|
458
|
+
return bounds;
|
|
459
|
+
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
function hasOverlap( uv, triangles ) {
|
|
463
|
+
|
|
464
|
+
const bounds = getBounds( uv );
|
|
465
|
+
const extent = Math.max( bounds.max.x - bounds.min.x, bounds.max.y - bounds.min.y );
|
|
466
|
+
const cellSize = extent / Math.max( 1, Math.sqrt( triangles.length ) );
|
|
467
|
+
const epsilon = extent * 1e-10, cells = new Map();
|
|
468
|
+
for ( let i = 0; i < triangles.length; i ++ ) {
|
|
469
|
+
|
|
470
|
+
const points = triangles[ i ].map( v => uv[ v ] ), box = getBounds( points ), seen = new Set();
|
|
471
|
+
for ( let x = Math.floor( ( box.min.x - bounds.min.x ) / cellSize ); x <= Math.floor( ( box.max.x - bounds.min.x ) / cellSize ); x ++ ) {
|
|
472
|
+
|
|
473
|
+
for ( let y = Math.floor( ( box.min.y - bounds.min.y ) / cellSize ); y <= Math.floor( ( box.max.y - bounds.min.y ) / cellSize ); y ++ ) {
|
|
474
|
+
|
|
475
|
+
const key = `${ x },${ y }`;
|
|
476
|
+
if ( ! cells.has( key ) ) cells.set( key, [] );
|
|
477
|
+
const cell = cells.get( key );
|
|
478
|
+
for ( const other of cell ) {
|
|
479
|
+
|
|
480
|
+
if ( seen.has( other ) ) continue;
|
|
481
|
+
seen.add( other );
|
|
482
|
+
if ( overlapSAT( points, triangles[ other ].map( v => uv[ v ] ), epsilon ) ) return true;
|
|
483
|
+
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
cell.push( i );
|
|
487
|
+
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
return false;
|
|
495
|
+
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
// Strict interior intersection: shared edges and vertices are allowed.
|
|
499
|
+
function overlapSAT( a, b, epsilon ) {
|
|
500
|
+
|
|
501
|
+
for ( const tri of [ a, b ] ) {
|
|
502
|
+
|
|
503
|
+
for ( let j = 0; j < 3; j ++ ) {
|
|
504
|
+
|
|
505
|
+
const p = tri[ j ], q = tri[ ( j + 1 ) % 3 ];
|
|
506
|
+
const nx = p[ 1 ] - q[ 1 ], ny = q[ 0 ] - p[ 0 ];
|
|
507
|
+
let minA = Infinity, maxA = - Infinity, minB = Infinity, maxB = - Infinity;
|
|
508
|
+
for ( let k = 0; k < 3; k ++ ) {
|
|
509
|
+
|
|
510
|
+
const da = a[ k ][ 0 ] * nx + a[ k ][ 1 ] * ny, db = b[ k ][ 0 ] * nx + b[ k ][ 1 ] * ny;
|
|
511
|
+
minA = Math.min( minA, da ); maxA = Math.max( maxA, da );
|
|
512
|
+
minB = Math.min( minB, db ); maxB = Math.max( maxB, db );
|
|
513
|
+
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
if ( Math.min( maxA, maxB ) - Math.max( minA, minB ) <= epsilon * Math.sqrt( nx * nx + ny * ny ) ) return false;
|
|
517
|
+
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
return true;
|
|
523
|
+
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
function alignChart( uv ) {
|
|
527
|
+
|
|
528
|
+
let x = 0, y = 0, xx = 0, yy = 0, xy = 0;
|
|
529
|
+
for ( const p of uv ) {
|
|
530
|
+
|
|
531
|
+
x += p[ 0 ]; y += p[ 1 ];
|
|
532
|
+
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
x /= uv.length; y /= uv.length;
|
|
536
|
+
for ( const p of uv ) {
|
|
537
|
+
|
|
538
|
+
xx += ( p[ 0 ] - x ) ** 2; yy += ( p[ 1 ] - y ) ** 2; xy += ( p[ 0 ] - x ) * ( p[ 1 ] - y );
|
|
539
|
+
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
const angle = 0.5 * Math.atan2( 2 * xy, xx - yy ), cosine = Math.cos( angle ), sine = Math.sin( angle );
|
|
543
|
+
const rotated = uv.map( p => [ cosine * p[ 0 ] + sine * p[ 1 ], - sine * p[ 0 ] + cosine * p[ 1 ] ] );
|
|
544
|
+
const a = getBounds( uv ), b = getBounds( rotated );
|
|
545
|
+
if ( ( b.max.x - b.min.x ) * ( b.max.y - b.min.y ) < ( a.max.x - a.min.x ) * ( a.max.y - a.min.y ) ) {
|
|
546
|
+
|
|
547
|
+
for ( let i = 0; i < uv.length; i ++ ) uv[ i ] = rotated[ i ];
|
|
548
|
+
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
function packCharts( charts, settings ) {
|
|
554
|
+
|
|
555
|
+
if ( charts.length === 0 ) return 0;
|
|
556
|
+
// Half a pixel beyond the requested gutter protects the texel-center boundary.
|
|
557
|
+
const border = settings.padding + 0.5;
|
|
558
|
+
function pack( density ) {
|
|
559
|
+
|
|
560
|
+
const boxes = charts.map( chart => ( {
|
|
561
|
+
chart, w: Math.max( 1, Math.ceil( chart.width * density + border * 2 ) ),
|
|
562
|
+
h: Math.max( 1, Math.ceil( chart.height * density + border * 2 ) )
|
|
563
|
+
} ) );
|
|
564
|
+
const result = potpack( boxes );
|
|
565
|
+
if ( result.w > settings.resolution || result.h > settings.resolution ) return packShelves( boxes, settings.resolution );
|
|
566
|
+
return boxes;
|
|
567
|
+
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
let density = settings.texelsPerUnit, boxes = density > 0 ? pack( density ) : null;
|
|
571
|
+
if ( density > 0 && ! boxes ) console.warn( 'THREE.unwrapUVs(): Charts do not fit at the requested texelsPerUnit. Fitting the atlas instead.' );
|
|
572
|
+
|
|
573
|
+
if ( ! boxes ) {
|
|
574
|
+
|
|
575
|
+
const area = charts.reduce( ( sum, chart ) => sum + chart.width * chart.height, 0 );
|
|
576
|
+
let low = 0, high = settings.resolution / Math.sqrt( area );
|
|
577
|
+
for ( let iteration = 0; iteration < 24; iteration ++ ) {
|
|
578
|
+
|
|
579
|
+
const middle = ( low + high ) * 0.5, trial = pack( middle );
|
|
580
|
+
if ( trial ) {
|
|
581
|
+
|
|
582
|
+
low = middle; boxes = trial;
|
|
583
|
+
|
|
584
|
+
} else {
|
|
585
|
+
|
|
586
|
+
high = middle;
|
|
587
|
+
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
density = low;
|
|
593
|
+
if ( ! boxes ) {
|
|
594
|
+
|
|
595
|
+
console.error( 'THREE.unwrapUVs(): Charts do not fit the atlas. Increase the resolution, reduce the padding or partition the hierarchy.' );
|
|
596
|
+
return null;
|
|
597
|
+
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
for ( const box of boxes ) box.chart.box = { x: box.x, y: box.y, w: box.w, h: box.h };
|
|
603
|
+
return density;
|
|
604
|
+
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
// A fixed-width fallback avoids potpack's unconstrained container-width heuristic.
|
|
608
|
+
function packShelves( boxes, resolution ) {
|
|
609
|
+
|
|
610
|
+
const shelves = [];
|
|
611
|
+
let height = 0;
|
|
612
|
+
for ( const box of boxes ) {
|
|
613
|
+
|
|
614
|
+
if ( box.w > resolution || box.h > resolution ) return null;
|
|
615
|
+
let best = null;
|
|
616
|
+
for ( const shelf of shelves ) {
|
|
617
|
+
|
|
618
|
+
if ( shelf.h >= box.h && shelf.x + box.w <= resolution && ( best === null || shelf.x > best.x ) ) best = shelf;
|
|
619
|
+
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
if ( best === null ) {
|
|
623
|
+
|
|
624
|
+
if ( height + box.h > resolution ) return null;
|
|
625
|
+
best = { x: 0, y: height, h: box.h };
|
|
626
|
+
shelves.push( best );
|
|
627
|
+
height += box.h;
|
|
628
|
+
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
box.x = best.x;
|
|
632
|
+
box.y = best.y;
|
|
633
|
+
best.x += box.w;
|
|
634
|
+
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
return boxes;
|
|
638
|
+
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
function validateFloat32Chart( chart, settings, density ) {
|
|
642
|
+
|
|
643
|
+
const border = settings.padding + 0.5;
|
|
644
|
+
chart.outputUV = chart.uv.map( p => [
|
|
645
|
+
Math.fround( ( chart.box.x + border + p[ 0 ] * density ) / settings.resolution ),
|
|
646
|
+
Math.fround( ( chart.box.y + border + p[ 1 ] * density ) / settings.resolution )
|
|
647
|
+
] );
|
|
648
|
+
// Validate the coordinates the GPU actually receives, not just the solver's
|
|
649
|
+
// doubles. Slivers can collapse or reverse after atlas translation/rounding.
|
|
650
|
+
const limits = { ...settings, maxStretch: settings.maxStretch * ( 1 + 5e-4 ), maxAreaRatio: settings.maxAreaRatio * ( 1 + 5e-4 ) };
|
|
651
|
+
// Drops are recomputed on every pass, so a repack at another density can restore them.
|
|
652
|
+
chart.dropped = new Set();
|
|
653
|
+
if ( checkChart( chart.positions, chart.triangles, chart.outputUV, chart.worldArea, limits ) ) return true;
|
|
654
|
+
|
|
655
|
+
// Drop failing single faces and subtexel faces; anything else needs a split.
|
|
656
|
+
const triangles = [];
|
|
657
|
+
let worldArea = chart.worldArea;
|
|
658
|
+
for ( let i = 0; i < chart.triangles.length; i ++ ) {
|
|
659
|
+
|
|
660
|
+
const triangle = chart.triangles[ i ], face = chart.record.faces[ chart.faces[ i ] ];
|
|
661
|
+
if ( chart.triangles.length === 1 || face.area * density * density < 1 && ! checkChart( chart.positions, [ triangle ], chart.outputUV, face.area, limits ) ) {
|
|
662
|
+
|
|
663
|
+
chart.dropped.add( i );
|
|
664
|
+
worldArea -= face.area;
|
|
665
|
+
|
|
666
|
+
} else {
|
|
667
|
+
|
|
668
|
+
triangles.push( triangle );
|
|
669
|
+
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
return triangles.length === 0 || checkChart( chart.positions, triangles, chart.outputUV, worldArea, limits ) ? true : null;
|
|
675
|
+
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
function rebuildGeometry( record, charts, settings ) {
|
|
679
|
+
|
|
680
|
+
const original = record.original, lookup = new Map(), source = [], values = [], indices = [];
|
|
681
|
+
const chartUV = ( chart, vertex ) => chart.outputUV[ chart.vertexMap.get( record.vertexKeys[ vertex ] ) ];
|
|
682
|
+
|
|
683
|
+
// Excluded faces collapse onto a welded neighbor's UV so they sample adjacent lighting
|
|
684
|
+
// rather than the gutter of whichever chart sits at (0, 0). Isolated ones keep (0, 0).
|
|
685
|
+
const weldUVs = new Map();
|
|
686
|
+
for ( let f = 0; f < record.faces.length; f ++ ) {
|
|
687
|
+
|
|
688
|
+
const chart = charts[ record.faceCharts[ f ] ], face = record.faces[ f ];
|
|
689
|
+
if ( chart ) for ( let j = 0; j < 3; j ++ ) weldUVs.set( face.welds[ j ], chartUV( chart, face.vertices[ j ] ) );
|
|
690
|
+
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
for ( let f = 0; f < record.faces.length; f ++ ) {
|
|
694
|
+
|
|
695
|
+
const chartIndex = record.faceCharts[ f ], chart = charts[ chartIndex ], face = record.faces[ f ];
|
|
696
|
+
const fallback = chart ? null : face.welds.map( weld => weldUVs.get( weld ) ).find( Boolean ) ?? [ 0, 0 ];
|
|
697
|
+
for ( let j = 0; j < 3; j ++ ) {
|
|
698
|
+
|
|
699
|
+
const vertex = face.vertices[ j ], key = chart ? `${ vertex },${ chartIndex }` : `${ vertex },${ fallback }`;
|
|
700
|
+
if ( ! lookup.has( key ) ) {
|
|
701
|
+
|
|
702
|
+
lookup.set( key, source.length );
|
|
703
|
+
source.push( vertex );
|
|
704
|
+
const p = chart ? chartUV( chart, vertex ) : fallback;
|
|
705
|
+
values.push( p[ 0 ], p[ 1 ] );
|
|
706
|
+
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
indices.push( lookup.get( key ) );
|
|
710
|
+
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
const geometry = new BufferGeometry(), buffers = new Map();
|
|
716
|
+
geometry.name = original.name;
|
|
717
|
+
geometry.morphTargetsRelative = original.morphTargetsRelative;
|
|
718
|
+
geometry.userData = original.userData;
|
|
719
|
+
geometry.setDrawRange( original.drawRange.start, original.drawRange.count );
|
|
720
|
+
for ( const group of original.groups ) geometry.addGroup( group.start, group.count, group.materialIndex );
|
|
721
|
+
|
|
722
|
+
for ( const name of Object.keys( original.attributes ) ) geometry.setAttribute( name, remapAttribute( original.attributes[ name ], source, buffers ) );
|
|
723
|
+
for ( const name of Object.keys( original.morphAttributes ) ) {
|
|
724
|
+
|
|
725
|
+
geometry.morphAttributes[ name ] = original.morphAttributes[ name ].map( attribute => remapAttribute( attribute, source, buffers ) );
|
|
726
|
+
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
geometry.setIndex( indices );
|
|
730
|
+
geometry.setAttribute( settings.attribute, new Float32BufferAttribute( values, 2 ) );
|
|
731
|
+
if ( settings.attribute === 'uv' ) geometry.deleteAttribute( 'tangent' );
|
|
732
|
+
record.sourceVertices = Uint32Array.from( source );
|
|
733
|
+
return geometry;
|
|
734
|
+
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
function triangleFrame( positions, triangle ) {
|
|
738
|
+
|
|
739
|
+
const [ a, b, c ] = triangle.map( i => positions[ i ] );
|
|
740
|
+
const ab = new Vector3().subVectors( b, a ), ac = new Vector3().subVectors( c, a );
|
|
741
|
+
const length = ab.length(), cross = new Vector3().crossVectors( ab, ac ).length();
|
|
742
|
+
return { length, x: ac.dot( ab ) / length, y: cross / length, cross };
|
|
743
|
+
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
// Least squares conformal maps, solved with Jacobi-preconditioned conjugate gradients.
|
|
747
|
+
// Two pinned vertices remove the similarity null modes. Returns null on failure.
|
|
748
|
+
function solveLSCM( positions, triangles, initial ) {
|
|
749
|
+
|
|
750
|
+
let pinA = 0, pinB = 0, distance = 0;
|
|
751
|
+
for ( let i = 1; i < initial.length; i ++ ) {
|
|
752
|
+
|
|
753
|
+
if ( initial[ i ][ 0 ] < initial[ pinA ][ 0 ] ) pinA = i;
|
|
754
|
+
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
for ( let i = 0; i < initial.length; i ++ ) {
|
|
758
|
+
|
|
759
|
+
const d = ( initial[ i ][ 0 ] - initial[ pinA ][ 0 ] ) ** 2 + ( initial[ i ][ 1 ] - initial[ pinA ][ 1 ] ) ** 2;
|
|
760
|
+
if ( d > distance ) {
|
|
761
|
+
|
|
762
|
+
distance = d; pinB = i;
|
|
763
|
+
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
if ( distance === 0 ) return null;
|
|
769
|
+
const n = positions.length * 2, fixed = new Uint8Array( n );
|
|
770
|
+
for ( const pin of [ pinA, pinB ] ) {
|
|
771
|
+
|
|
772
|
+
fixed[ pin * 2 ] = 1; fixed[ pin * 2 + 1 ] = 1;
|
|
773
|
+
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
const rows = [];
|
|
777
|
+
for ( const tri of triangles ) {
|
|
778
|
+
|
|
779
|
+
const { length, x, y } = triangleFrame( positions, tri );
|
|
780
|
+
if ( ! ( y > 0 && length > 0 ) ) return null;
|
|
781
|
+
const weight = Math.sqrt( length * y * 0.5 );
|
|
782
|
+
const gx = [ - 1 / length, 1 / length, 0 ], gy = [ ( x - length ) / ( length * y ), - x / ( length * y ), 1 / y ];
|
|
783
|
+
const indices = tri.flatMap( i => [ i * 2, i * 2 + 1 ] );
|
|
784
|
+
rows.push( { indices, values: gx.flatMap( ( value, i ) => [ value * weight, - gy[ i ] * weight ] ) } );
|
|
785
|
+
rows.push( { indices, values: gy.flatMap( ( value, i ) => [ value * weight, gx[ i ] * weight ] ) } );
|
|
786
|
+
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
const diagonal = new Float64Array( n ), rhs = new Float64Array( n );
|
|
790
|
+
for ( const row of rows ) {
|
|
791
|
+
|
|
792
|
+
let offset = 0;
|
|
793
|
+
for ( let j = 0; j < 6; j ++ ) {
|
|
794
|
+
|
|
795
|
+
const i = row.indices[ j ];
|
|
796
|
+
if ( fixed[ i ] ) offset += row.values[ j ] * initial[ i >> 1 ][ i % 2 ];
|
|
797
|
+
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
for ( let j = 0; j < 6; j ++ ) {
|
|
801
|
+
|
|
802
|
+
const i = row.indices[ j ];
|
|
803
|
+
if ( ! fixed[ i ] ) {
|
|
804
|
+
|
|
805
|
+
diagonal[ i ] += row.values[ j ] ** 2; rhs[ i ] -= row.values[ j ] * offset;
|
|
806
|
+
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
function multiply( input, output ) {
|
|
814
|
+
|
|
815
|
+
output.fill( 0 );
|
|
816
|
+
for ( const row of rows ) {
|
|
817
|
+
|
|
818
|
+
let sum = 0;
|
|
819
|
+
for ( let j = 0; j < 6; j ++ ) if ( ! fixed[ row.indices[ j ] ] ) sum += row.values[ j ] * input[ row.indices[ j ] ];
|
|
820
|
+
for ( let j = 0; j < 6; j ++ ) if ( ! fixed[ row.indices[ j ] ] ) output[ row.indices[ j ] ] += row.values[ j ] * sum;
|
|
821
|
+
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
const solution = new Float64Array( n ), residual = new Float64Array( n ), direction = new Float64Array( n ), product = new Float64Array( n );
|
|
827
|
+
for ( let i = 0; i < n; i ++ ) if ( ! fixed[ i ] ) solution[ i ] = initial[ i >> 1 ][ i % 2 ];
|
|
828
|
+
multiply( solution, product );
|
|
829
|
+
let rz = 0;
|
|
830
|
+
for ( let i = 0; i < n; i ++ ) {
|
|
831
|
+
|
|
832
|
+
residual[ i ] = rhs[ i ] - product[ i ];
|
|
833
|
+
direction[ i ] = diagonal[ i ] > 0 ? residual[ i ] / diagonal[ i ] : 0;
|
|
834
|
+
rz += residual[ i ] * direction[ i ];
|
|
835
|
+
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
const tolerance = rz * 1e-12;
|
|
839
|
+
for ( let iteration = 0; iteration < Math.min( n, 300 ) && rz > tolerance && rz > 1e-24; iteration ++ ) {
|
|
840
|
+
|
|
841
|
+
multiply( direction, product );
|
|
842
|
+
let denominator = 0;
|
|
843
|
+
for ( let i = 0; i < n; i ++ ) denominator += direction[ i ] * product[ i ];
|
|
844
|
+
if ( ! ( denominator > 0 ) ) return null;
|
|
845
|
+
const alpha = rz / denominator;
|
|
846
|
+
let next = 0;
|
|
847
|
+
for ( let i = 0; i < n; i ++ ) {
|
|
848
|
+
|
|
849
|
+
solution[ i ] += alpha * direction[ i ];
|
|
850
|
+
residual[ i ] -= alpha * product[ i ];
|
|
851
|
+
if ( diagonal[ i ] > 0 ) next += residual[ i ] ** 2 / diagonal[ i ];
|
|
852
|
+
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
const beta = next / rz;
|
|
856
|
+
for ( let i = 0; i < n; i ++ ) direction[ i ] = ( diagonal[ i ] > 0 ? residual[ i ] / diagonal[ i ] : 0 ) + beta * direction[ i ];
|
|
857
|
+
rz = next;
|
|
858
|
+
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
return initial.map( ( p, i ) => fixed[ i * 2 ] ? p.slice() : [ solution[ i * 2 ], solution[ i * 2 + 1 ] ] );
|
|
862
|
+
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
export { unwrapUVs };
|