@pinkaphant/kolmo 0.2.3 → 0.4.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 +1 -1
- package/README.md +36 -36
- package/bin/kolmo.mjs +12 -6
- package/dist/engine/causewayBridge.d.ts +14 -0
- package/dist/engine/causewayBridge.js +166 -0
- package/dist/engine/causewayBridge.js.map +1 -0
- package/dist/engine/index.d.ts +6 -4
- package/dist/engine/index.js +19 -12
- package/dist/engine/index.js.map +1 -0
- package/dist/engine/islandSettlementMesh.d.ts +26 -0
- package/dist/engine/islandSettlementMesh.js +166 -0
- package/dist/engine/islandSettlementMesh.js.map +1 -0
- package/dist/engine/kolmoActions.d.ts +23 -0
- package/dist/engine/kolmoActions.js +164 -0
- package/dist/engine/kolmoActions.js.map +1 -0
- package/dist/engine/kolmoActor.js +242 -165
- package/dist/engine/kolmoActor.js.map +1 -0
- package/dist/engine/kolmoFloatingOrigin.d.ts +17 -0
- package/dist/engine/kolmoFloatingOrigin.js +98 -0
- package/dist/engine/kolmoFloatingOrigin.js.map +1 -0
- package/dist/engine/kolmoGame.d.ts +27 -0
- package/dist/engine/kolmoGame.js +80 -0
- package/dist/engine/kolmoGame.js.map +1 -0
- package/dist/engine/kolmoHud.d.ts +23 -0
- package/dist/engine/kolmoHud.js +195 -0
- package/dist/engine/kolmoHud.js.map +1 -0
- package/dist/engine/kolmoInput.d.ts +1 -1
- package/dist/engine/kolmoInput.js +57 -30
- package/dist/engine/kolmoInput.js.map +1 -0
- package/dist/engine/kolmoIsland.d.ts +5 -10
- package/dist/engine/kolmoIsland.js +182 -250
- package/dist/engine/kolmoIsland.js.map +1 -0
- package/dist/engine/kolmoLongDrive.d.ts +3 -4
- package/dist/engine/kolmoLongDrive.js +140 -205
- package/dist/engine/kolmoLongDrive.js.map +1 -0
- package/dist/engine/kolmoPilotMesh.d.ts +2 -0
- package/dist/engine/kolmoPilotMesh.js +64 -0
- package/dist/engine/kolmoPilotMesh.js.map +1 -0
- package/dist/engine/kolmoProcedural.d.ts +13 -0
- package/dist/engine/kolmoProcedural.js +101 -0
- package/dist/engine/kolmoProcedural.js.map +1 -0
- package/dist/engine/kolmoRigs.d.ts +1 -1
- package/dist/engine/kolmoRigs.js +88 -47
- package/dist/engine/kolmoRigs.js.map +1 -0
- package/dist/engine/kolmoStore.d.ts +3 -100
- package/dist/engine/kolmoSurface.d.ts +2 -2
- package/dist/engine/kolmoSurface.js +150 -134
- package/dist/engine/kolmoSurface.js.map +1 -0
- package/dist/engine/kolmoTraits.d.ts +128 -0
- package/dist/engine/kolmoTraits.js +140 -0
- package/dist/engine/kolmoTraits.js.map +1 -0
- package/dist/engine/kolmoVehicle.d.ts +3 -33
- package/dist/engine/kolmoVehicle.js +66 -240
- package/dist/engine/kolmoVehicle.js.map +1 -0
- package/dist/engine/kolmoVehicleConfig.d.ts +54 -0
- package/dist/engine/kolmoVehicleConfig.js +80 -0
- package/dist/engine/kolmoVehicleConfig.js.map +1 -0
- package/dist/engine/kolmoVehicleDriver.d.ts +4 -1
- package/dist/engine/kolmoVehicleDriver.js +116 -22
- package/dist/engine/kolmoVehicleDriver.js.map +1 -0
- package/dist/engine/kolmoVehicleInner.d.ts +7 -0
- package/dist/engine/kolmoVehicleInner.js +261 -0
- package/dist/engine/kolmoVehicleInner.js.map +1 -0
- package/dist/engine/kolmoWorld.d.ts +6 -4
- package/dist/engine/kolmoWorld.js +134 -116
- package/dist/engine/kolmoWorld.js.map +1 -0
- package/dist/engine/longDriveKit.d.ts +5 -12
- package/dist/engine/longDriveKit.js +121 -233
- package/dist/engine/longDriveKit.js.map +1 -0
- package/dist/engine/longDriveRoadside.d.ts +16 -0
- package/dist/engine/longDriveRoadside.js +171 -0
- package/dist/engine/longDriveRoadside.js.map +1 -0
- package/dist/engine/macroCellBuilder.d.ts +34 -0
- package/dist/engine/macroCellBuilder.js +145 -0
- package/dist/engine/macroCellBuilder.js.map +1 -0
- package/dist/engine/mainlandMacroCell.d.ts +2 -2
- package/dist/engine/mainlandMacroCell.js +77 -165
- package/dist/engine/mainlandMacroCell.js.map +1 -0
- package/dist/engine/shiftedFixedBody.d.ts +1 -1
- package/dist/engine/shiftedFixedBody.js +55 -28
- package/dist/engine/shiftedFixedBody.js.map +1 -0
- package/dist/importer/ChopShopPanel.d.ts +9 -1
- package/dist/importer/ChopShopPanel.js +303 -359
- package/dist/importer/ChopShopPanel.js.map +1 -0
- package/dist/importer/DomainWorkshopPanel.d.ts +2 -1
- package/dist/importer/DomainWorkshopPanel.js +172 -242
- package/dist/importer/DomainWorkshopPanel.js.map +1 -0
- package/dist/importer/GateHudBar.d.ts +8 -0
- package/dist/importer/GateHudBar.js +290 -279
- package/dist/importer/GateHudBar.js.map +1 -0
- package/dist/importer/GlbImportGate.d.ts +2 -1
- package/dist/importer/GlbImportGate.js +252 -225
- package/dist/importer/GlbImportGate.js.map +1 -0
- package/dist/importer/ImperativeVehicleRig.d.ts +2 -2
- package/dist/importer/ImperativeVehicleRig.js +223 -284
- package/dist/importer/ImperativeVehicleRig.js.map +1 -0
- package/dist/importer/LiveDrivePads.d.ts +20 -0
- package/dist/importer/LiveDrivePads.js +169 -0
- package/dist/importer/LiveDrivePads.js.map +1 -0
- package/dist/importer/PaperShellDebrisRig.d.ts +25 -0
- package/dist/importer/PaperShellDebrisRig.js +143 -0
- package/dist/importer/PaperShellDebrisRig.js.map +1 -0
- package/dist/importer/R2VaultDrawer.d.ts +12 -0
- package/dist/importer/R2VaultDrawer.js +90 -0
- package/dist/importer/R2VaultDrawer.js.map +1 -0
- package/dist/importer/Step1CalibrationPlinth.d.ts +23 -5
- package/dist/importer/Step1CalibrationPlinth.js +180 -251
- package/dist/importer/Step1CalibrationPlinth.js.map +1 -0
- package/dist/importer/Step1ExplodedIslands.d.ts +31 -0
- package/dist/importer/Step1ExplodedIslands.js +144 -0
- package/dist/importer/Step1ExplodedIslands.js.map +1 -0
- package/dist/importer/Step2UniversalPad.d.ts +7 -7
- package/dist/importer/Step2UniversalPad.js +49 -170
- package/dist/importer/Step2UniversalPad.js.map +1 -0
- package/dist/importer/VfxEmitterPool.js +59 -86
- package/dist/importer/VfxEmitterPool.js.map +1 -0
- package/dist/importer/WheelRingHandles3D.d.ts +11 -0
- package/dist/importer/WheelRingHandles3D.js +318 -0
- package/dist/importer/WheelRingHandles3D.js.map +1 -0
- package/dist/importer/archLinerGeom.d.ts +2 -0
- package/dist/importer/archLinerGeom.js +51 -0
- package/dist/importer/archLinerGeom.js.map +1 -0
- package/dist/importer/{vehiclePanelAnim.d.ts → chopHingeHelpers.d.ts} +0 -10
- package/dist/importer/chopHingeHelpers.js +193 -0
- package/dist/importer/chopHingeHelpers.js.map +1 -0
- package/dist/importer/chopShopActions.d.ts +20 -26
- package/dist/importer/chopShopActions.js +135 -210
- package/dist/importer/chopShopActions.js.map +1 -0
- package/dist/importer/chopShopHandlers.d.ts +26 -0
- package/dist/importer/chopShopHandlers.js +276 -0
- package/dist/importer/chopShopHandlers.js.map +1 -0
- package/dist/importer/chopShopIoActions.d.ts +15 -0
- package/dist/importer/chopShopIoActions.js +137 -0
- package/dist/importer/chopShopIoActions.js.map +1 -0
- package/dist/importer/chopShopMcpAction.d.ts +18 -0
- package/dist/importer/chopShopMcpAction.js +58 -0
- package/dist/importer/chopShopMcpAction.js.map +1 -0
- package/dist/importer/cylinderBooleanSlice.d.ts +14 -0
- package/dist/importer/cylinderBooleanSlice.js +110 -0
- package/dist/importer/cylinderBooleanSlice.js.map +1 -0
- package/dist/importer/cylinderSliceMath.d.ts +14 -0
- package/dist/importer/cylinderSliceMath.js +251 -0
- package/dist/importer/cylinderSliceMath.js.map +1 -0
- package/dist/importer/fusedWheelDetect.d.ts +4 -0
- package/dist/importer/fusedWheelDetect.js +175 -0
- package/dist/importer/fusedWheelDetect.js.map +1 -0
- package/dist/importer/fusedWheelFit.d.ts +13 -0
- package/dist/importer/fusedWheelFit.js +138 -0
- package/dist/importer/fusedWheelFit.js.map +1 -0
- package/dist/importer/gateStore.d.ts +1 -1
- package/dist/importer/gateStore.js +36 -27
- package/dist/importer/gateStore.js.map +1 -0
- package/dist/importer/glbNormalizer.js +118 -79
- package/dist/importer/glbNormalizer.js.map +1 -0
- package/dist/importer/importerWebMcp.d.ts +4 -3
- package/dist/importer/importerWebMcp.js +41 -336
- package/dist/importer/importerWebMcp.js.map +1 -0
- package/dist/importer/importerWebMcpTools.d.ts +2 -0
- package/dist/importer/importerWebMcpTools.js +340 -0
- package/dist/importer/importerWebMcpTools.js.map +1 -0
- package/dist/importer/index.d.ts +4 -0
- package/dist/importer/index.js +32 -22
- package/dist/importer/index.js.map +1 -0
- package/dist/importer/khrCarPlanHelpers.d.ts +28 -0
- package/dist/importer/khrCarPlanHelpers.js +221 -0
- package/dist/importer/khrCarPlanHelpers.js.map +1 -0
- package/dist/importer/khrCarPlanner.d.ts +7 -0
- package/dist/importer/khrCarPlanner.js +279 -0
- package/dist/importer/khrCarPlanner.js.map +1 -0
- package/dist/importer/khrCompiler.d.ts +4 -22
- package/dist/importer/khrCompiler.js +56 -424
- package/dist/importer/khrCompiler.js.map +1 -0
- package/dist/importer/khrCraftPropCompiler.d.ts +40 -0
- package/dist/importer/khrCraftPropCompiler.js +250 -0
- package/dist/importer/khrCraftPropCompiler.js.map +1 -0
- package/dist/importer/launcherBake.js +76 -35
- package/dist/importer/launcherBake.js.map +1 -0
- package/dist/importer/meshIslands.d.ts +4 -46
- package/dist/importer/meshIslands.js +84 -283
- package/dist/importer/meshIslands.js.map +1 -0
- package/dist/importer/meshSliceBuffers.d.ts +15 -0
- package/dist/importer/meshSliceBuffers.js +159 -0
- package/dist/importer/meshSliceBuffers.js.map +1 -0
- package/dist/importer/polygonEarClipYZ.d.ts +3 -0
- package/dist/importer/polygonEarClipYZ.js +67 -0
- package/dist/importer/polygonEarClipYZ.js.map +1 -0
- package/dist/importer/sceneSiNormalize.d.ts +19 -0
- package/dist/importer/sceneSiNormalize.js +138 -0
- package/dist/importer/sceneSiNormalize.js.map +1 -0
- package/dist/importer/starterScene.d.ts +3 -0
- package/dist/importer/starterScene.js +76 -0
- package/dist/importer/starterScene.js.map +1 -0
- package/dist/importer/surfaceCutter.d.ts +4 -15
- package/dist/importer/surfaceCutter.js +69 -240
- package/dist/importer/surfaceCutter.js.map +1 -0
- package/dist/importer/surfaceGeodesic.d.ts +7 -0
- package/dist/importer/surfaceGeodesic.js +130 -0
- package/dist/importer/surfaceGeodesic.js.map +1 -0
- package/dist/importer/surfaceLoopRefine.d.ts +6 -0
- package/dist/importer/surfaceLoopRefine.js +171 -0
- package/dist/importer/surfaceLoopRefine.js.map +1 -0
- package/dist/importer/surfacePeel.d.ts +11 -0
- package/dist/importer/surfacePeel.js +119 -0
- package/dist/importer/surfacePeel.js.map +1 -0
- package/dist/importer/surfaceTopology.d.ts +2 -6
- package/dist/importer/surfaceTopology.js +93 -133
- package/dist/importer/surfaceTopology.js.map +1 -0
- package/dist/importer/universalGateBake.d.ts +7 -3
- package/dist/importer/universalGateBake.js +104 -106
- package/dist/importer/universalGateBake.js.map +1 -0
- package/dist/importer/usdPhysicsSpecs.d.ts +3 -0
- package/dist/importer/usdPhysicsSpecs.js +245 -0
- package/dist/importer/usdPhysicsSpecs.js.map +1 -0
- package/dist/importer/usdTextParse.d.ts +12 -0
- package/dist/importer/usdTextParse.js +118 -0
- package/dist/importer/usdTextParse.js.map +1 -0
- package/dist/importer/usdToGlb.d.ts +3 -2
- package/dist/importer/usdToGlb.js +80 -280
- package/dist/importer/usdToGlb.js.map +1 -0
- package/dist/importer/useChopShopController.d.ts +50 -47
- package/dist/importer/useChopShopController.js +156 -338
- package/dist/importer/useChopShopController.js.map +1 -0
- package/dist/importer/useChopShopState.d.ts +103 -0
- package/dist/importer/useChopShopState.js +319 -0
- package/dist/importer/useChopShopState.js.map +1 -0
- package/dist/importer/useWasdKeyRef.d.ts +9 -0
- package/dist/importer/useWasdKeyRef.js +35 -0
- package/dist/importer/useWasdKeyRef.js.map +1 -0
- package/dist/importer/vehiclePartSplit.d.ts +33 -0
- package/dist/importer/vehiclePartSplit.js +178 -0
- package/dist/importer/vehiclePartSplit.js.map +1 -0
- package/dist/importer/wheelAxlePairing.js +106 -70
- package/dist/importer/wheelAxlePairing.js.map +1 -0
- package/dist/importer/wheelCutterHelpers.d.ts +42 -0
- package/dist/importer/wheelCutterHelpers.js +178 -0
- package/dist/importer/wheelCutterHelpers.js.map +1 -0
- package/dist/importer/wheelRingHandleMath.d.ts +20 -0
- package/dist/importer/wheelRingHandleMath.js +66 -0
- package/dist/importer/wheelRingHandleMath.js.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +90 -66
- package/dist/index.js.map +1 -0
- package/dist/junk/DestructibleTarget.d.ts +3 -3
- package/dist/junk/DestructibleTarget.js +177 -114
- package/dist/junk/DestructibleTarget.js.map +1 -0
- package/dist/junk/KolmoJunk.js +55 -44
- package/dist/junk/KolmoJunk.js.map +1 -0
- package/dist/junk/ShardPieces.d.ts +2 -1
- package/dist/junk/ShardPieces.js +80 -61
- package/dist/junk/ShardPieces.js.map +1 -0
- package/dist/junk/TargetDecals.d.ts +6 -15
- package/dist/junk/TargetDecals.js +66 -40
- package/dist/junk/TargetDecals.js.map +1 -0
- package/dist/junk/bvhShatter.d.ts +2 -6
- package/dist/junk/bvhShatter.js +89 -43
- package/dist/junk/bvhShatter.js.map +1 -0
- package/dist/junk/bvhTriCollector.d.ts +2 -6
- package/dist/junk/bvhTriCollector.js +111 -62
- package/dist/junk/bvhTriCollector.js.map +1 -0
- package/dist/junk/index.d.ts +2 -2
- package/dist/junk/index.js +11 -11
- package/dist/junk/index.js.map +1 -0
- package/dist/junk/junkGeometry.d.ts +5 -26
- package/dist/junk/junkGeometry.js +61 -43
- package/dist/junk/junkGeometry.js.map +1 -0
- package/dist/junk/junkImportSanitize.d.ts +4 -5
- package/dist/junk/junkImportSanitize.js +57 -37
- package/dist/junk/junkImportSanitize.js.map +1 -0
- package/dist/junk/junkImporter.d.ts +2 -13
- package/dist/junk/junkImporter.js +105 -76
- package/dist/junk/junkImporter.js.map +1 -0
- package/dist/junk/junkLabelCanvas.d.ts +1 -6
- package/dist/junk/junkLabelCanvas.js +147 -29
- package/dist/junk/junkLabelCanvas.js.map +1 -0
- package/dist/junk/junkLabels.d.ts +4 -26
- package/dist/junk/junkLabels.js +42 -28
- package/dist/junk/junkLabels.js.map +1 -0
- package/dist/junk/targetHelpers.d.ts +3 -4
- package/dist/junk/targetHelpers.js +121 -67
- package/dist/junk/targetHelpers.js.map +1 -0
- package/dist/junk/targetHitLogic.d.ts +8 -8
- package/dist/junk/targetHitLogic.js +131 -95
- package/dist/junk/targetHitLogic.js.map +1 -0
- package/dist/junk/useTargetAssets.d.ts +9 -14
- package/dist/junk/useTargetAssets.js +113 -85
- package/dist/junk/useTargetAssets.js.map +1 -0
- package/dist/physics/index.d.ts +1 -1
- package/dist/physics/index.js +79 -58
- package/dist/physics/index.js.map +1 -0
- package/dist/schema/kolmoSchema.d.ts +3 -64
- package/dist/schema/kolmoSchema.js +75 -149
- package/dist/schema/kolmoSchema.js.map +1 -0
- package/dist/schema/kolmoStamp.d.ts +6 -0
- package/dist/schema/kolmoStamp.js +71 -0
- package/dist/schema/kolmoStamp.js.map +1 -0
- package/dist/schema/kolmoTypes.d.ts +63 -0
- package/dist/schema/kolmoTypes.js +66 -0
- package/dist/schema/kolmoTypes.js.map +1 -0
- package/dist/shaders/celestialBackdrop.d.ts +2 -10
- package/dist/shaders/celestialBackdrop.js +128 -291
- package/dist/shaders/celestialBackdrop.js.map +1 -0
- package/dist/shaders/emitterShaders.d.ts +9 -0
- package/dist/shaders/emitterShaders.js +114 -0
- package/dist/shaders/emitterShaders.js.map +1 -0
- package/dist/shaders/index.d.ts +1 -1
- package/dist/shaders/index.js +12 -9
- package/dist/shaders/index.js.map +1 -0
- package/dist/shaders/plumeAndSparkle.d.ts +2 -4
- package/dist/shaders/plumeAndSparkle.js +152 -191
- package/dist/shaders/plumeAndSparkle.js.map +1 -0
- package/dist/shaders/ps2GlslShared.js +29 -2
- package/dist/shaders/ps2GlslShared.js.map +1 -0
- package/dist/shaders/ps2MaterialsTSL.js +132 -51
- package/dist/shaders/ps2MaterialsTSL.js.map +1 -0
- package/dist/shaders/ps2MaterialsWebGL.js +45 -28
- package/dist/shaders/ps2MaterialsWebGL.js.map +1 -0
- package/dist/shaders/ps2RoadWebGL.js +69 -32
- package/dist/shaders/ps2RoadWebGL.js.map +1 -0
- package/dist/shaders/ps2TerrainWebGL.js +107 -30
- package/dist/shaders/ps2TerrainWebGL.js.map +1 -0
- package/dist/shaders/ps2Textures.d.ts +1 -1
- package/dist/shaders/ps2Textures.js +116 -41
- package/dist/shaders/ps2Textures.js.map +1 -0
- package/dist/shaders/retroPalettes.d.ts +1 -1
- package/dist/shaders/retroPalettes.js +90 -57
- package/dist/shaders/retroPalettes.js.map +1 -0
- package/dist/shaders/retroShader.d.ts +2 -86
- package/dist/shaders/retroShader.js +65 -196
- package/dist/shaders/retroShader.js.map +1 -0
- package/dist/shaders/retroUniforms.d.ts +60 -0
- package/dist/shaders/retroUniforms.js +215 -0
- package/dist/shaders/retroUniforms.js.map +1 -0
- package/dist/shaders/skyboxShaders.d.ts +16 -0
- package/dist/shaders/skyboxShaders.js +266 -0
- package/dist/shaders/skyboxShaders.js.map +1 -0
- package/dist/shaders/tsl.d.ts +1 -1
- package/dist/shaders/tsl.js.map +1 -0
- package/dist/vite/index.js +39 -23
- package/dist/vite/index.js.map +1 -0
- package/dist/world/frontage.js +25 -21
- package/dist/world/frontage.js.map +1 -0
- package/dist/world/index.d.ts +4 -4
- package/dist/world/index.js +12 -11
- package/dist/world/index.js.map +1 -0
- package/dist/world/infiniteWorld2D.d.ts +0 -5
- package/dist/world/infiniteWorld2D.js +175 -200
- package/dist/world/infiniteWorld2D.js.map +1 -0
- package/dist/world/island.js +81 -166
- package/dist/world/island.js.map +1 -0
- package/dist/world/islandPathing.d.ts +6 -0
- package/dist/world/islandPathing.js +166 -0
- package/dist/world/islandPathing.js.map +1 -0
- package/dist/world/macroCellSchema.js +15 -8
- package/dist/world/macroCellSchema.js.map +1 -0
- package/dist/world/macroKnightAStar.js +140 -71
- package/dist/world/macroKnightAStar.js.map +1 -0
- package/dist/world/macroSettlementZones.d.ts +9 -0
- package/dist/world/macroSettlementZones.js +108 -0
- package/dist/world/macroSettlementZones.js.map +1 -0
- package/dist/world/random.js +50 -24
- package/dist/world/random.js.map +1 -0
- package/dist/world/road.js +152 -90
- package/dist/world/road.js.map +1 -0
- package/dist/world/roadRibbon.d.ts +4 -19
- package/dist/world/roadRibbon.js +129 -124
- package/dist/world/roadRibbon.js.map +1 -0
- package/dist/world/terrain.d.ts +1 -1
- package/dist/world/terrain.js +111 -65
- package/dist/world/terrain.js.map +1 -0
- package/dist/world/terrainGeometry.d.ts +14 -0
- package/dist/world/terrainGeometry.js +76 -0
- package/dist/world/terrainGeometry.js.map +1 -0
- package/dist/world/worldTypes.d.ts +3 -3
- package/dist/world/worldTypes.js +133 -67
- package/dist/world/worldTypes.js.map +1 -0
- package/docs/api-reference.md +187 -0
- package/package.json +58 -32
- package/dist/engine/kolmoStore.js +0 -211
- package/dist/importer/ImporterPlinthUikitTags.d.ts +0 -19
- package/dist/importer/ImporterPlinthUikitTags.js +0 -112
- package/dist/importer/vehiclePanelAnim.js +0 -214
|
@@ -1,78 +1,127 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { isMeshNode, isShaderMatNode } from "./junkImportSanitize.js";
|
|
2
|
+
import * as THREE from "three";
|
|
2
3
|
// src/junk/bvhTriCollector.ts
|
|
3
|
-
var
|
|
4
|
-
function
|
|
5
|
-
for (let
|
|
6
|
-
return
|
|
4
|
+
var MIN_AREA2 = 1e-10;
|
|
5
|
+
function allFinite(...vals) {
|
|
6
|
+
for (let i = 0; i < vals.length; i++) if (!Number.isFinite(vals[i])) return false;
|
|
7
|
+
return true;
|
|
7
8
|
}
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
function collectValidTris(root) {
|
|
10
|
+
root.updateMatrixWorld(true);
|
|
11
|
+
const invRoot = new THREE.Matrix4().copy(root.matrixWorld).invert();
|
|
12
|
+
const rel = new THREE.Matrix4();
|
|
13
|
+
const normalMat = new THREE.Matrix3();
|
|
14
|
+
const meshes = [];
|
|
15
|
+
root.traverse((obj) => {
|
|
16
|
+
if (!isMeshNode(obj)) return;
|
|
17
|
+
if (obj.userData.isDecal || obj.userData.isGizmo || isShaderMatNode(obj.material) || Array.isArray(obj.material) && obj.material.every((m) => isShaderMatNode(m)) || !obj.geometry?.attributes?.position) return;
|
|
18
|
+
meshes.push(obj);
|
|
13
19
|
});
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
const hasExplicitDestructible = meshes.some((m) => m.userData.destructible !== false);
|
|
21
|
+
const tris = [];
|
|
22
|
+
const v0 = new THREE.Vector3();
|
|
23
|
+
const v1 = new THREE.Vector3();
|
|
24
|
+
const v2 = new THREE.Vector3();
|
|
25
|
+
const e1 = new THREE.Vector3();
|
|
26
|
+
const e2 = new THREE.Vector3();
|
|
27
|
+
const fn = new THREE.Vector3();
|
|
28
|
+
const n0 = new THREE.Vector3();
|
|
29
|
+
const n1 = new THREE.Vector3();
|
|
30
|
+
const n2 = new THREE.Vector3();
|
|
31
|
+
for (const mesh of meshes) {
|
|
32
|
+
if (hasExplicitDestructible && mesh.userData.destructible === false) continue;
|
|
33
|
+
const srcGeo = mesh.geometry;
|
|
34
|
+
const indexed = srcGeo.index !== null;
|
|
35
|
+
const geo = indexed ? srcGeo.toNonIndexed() : srcGeo;
|
|
18
36
|
try {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
37
|
+
const pos = geo.attributes.position;
|
|
38
|
+
const norm = geo.attributes.normal;
|
|
39
|
+
const uv = geo.attributes.uv;
|
|
40
|
+
const triCount = Math.floor(pos.count / 3);
|
|
41
|
+
if (triCount <= 0) continue;
|
|
42
|
+
rel.multiplyMatrices(invRoot, mesh.matrixWorld);
|
|
43
|
+
normalMat.getNormalMatrix(rel);
|
|
44
|
+
for (let t = 0; t < triCount; t++) {
|
|
45
|
+
const i = t * 3;
|
|
46
|
+
v0.fromBufferAttribute(pos, i).applyMatrix4(rel);
|
|
47
|
+
v1.fromBufferAttribute(pos, i + 1).applyMatrix4(rel);
|
|
48
|
+
v2.fromBufferAttribute(pos, i + 2).applyMatrix4(rel);
|
|
49
|
+
if (!allFinite(v0.x, v0.y, v0.z, v1.x, v1.y, v1.z, v2.x, v2.y, v2.z)) continue;
|
|
50
|
+
e1.subVectors(v1, v0);
|
|
51
|
+
e2.subVectors(v2, v0);
|
|
52
|
+
fn.crossVectors(e1, e2);
|
|
53
|
+
const area2 = fn.length();
|
|
54
|
+
if (!Number.isFinite(area2) || area2 < MIN_AREA2) continue;
|
|
55
|
+
fn.divideScalar(area2);
|
|
56
|
+
if (norm) {
|
|
57
|
+
n0.fromBufferAttribute(norm, i).applyMatrix3(normalMat);
|
|
58
|
+
n1.fromBufferAttribute(norm, i + 1).applyMatrix3(normalMat);
|
|
59
|
+
n2.fromBufferAttribute(norm, i + 2).applyMatrix3(normalMat);
|
|
60
|
+
if (n0.lengthSq() > 1e-10) n0.normalize();
|
|
61
|
+
else n0.copy(fn);
|
|
62
|
+
if (n1.lengthSq() > 1e-10) n1.normalize();
|
|
63
|
+
else n1.copy(fn);
|
|
64
|
+
if (n2.lengthSq() > 1e-10) n2.normalize();
|
|
65
|
+
else n2.copy(fn);
|
|
66
|
+
} else {
|
|
67
|
+
n0.copy(fn);
|
|
68
|
+
n1.copy(fn);
|
|
69
|
+
n2.copy(fn);
|
|
70
|
+
}
|
|
71
|
+
const u0 = uv ? uv.getX(i) : 0;
|
|
72
|
+
const v0uv = uv ? uv.getY(i) : 0;
|
|
73
|
+
const u1 = uv ? uv.getX(i + 1) : 0;
|
|
74
|
+
const v1uv = uv ? uv.getY(i + 1) : 0;
|
|
75
|
+
const u2 = uv ? uv.getX(i + 2) : 0;
|
|
76
|
+
const v2uv = uv ? uv.getY(i + 2) : 0;
|
|
77
|
+
tris.push({
|
|
31
78
|
p: [
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
79
|
+
v0.x,
|
|
80
|
+
v0.y,
|
|
81
|
+
v0.z,
|
|
82
|
+
v1.x,
|
|
83
|
+
v1.y,
|
|
84
|
+
v1.z,
|
|
85
|
+
v2.x,
|
|
86
|
+
v2.y,
|
|
87
|
+
v2.z
|
|
41
88
|
],
|
|
42
89
|
n: [
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
90
|
+
n0.x,
|
|
91
|
+
n0.y,
|
|
92
|
+
n0.z,
|
|
93
|
+
n1.x,
|
|
94
|
+
n1.y,
|
|
95
|
+
n1.z,
|
|
96
|
+
n2.x,
|
|
97
|
+
n2.y,
|
|
98
|
+
n2.z
|
|
52
99
|
],
|
|
53
100
|
uv: [
|
|
54
|
-
Number.isFinite(
|
|
55
|
-
Number.isFinite(
|
|
56
|
-
Number.isFinite(
|
|
57
|
-
Number.isFinite(
|
|
58
|
-
Number.isFinite(
|
|
59
|
-
Number.isFinite(
|
|
101
|
+
Number.isFinite(u0) ? u0 : 0,
|
|
102
|
+
Number.isFinite(v0uv) ? v0uv : 0,
|
|
103
|
+
Number.isFinite(u1) ? u1 : 0,
|
|
104
|
+
Number.isFinite(v1uv) ? v1uv : 0,
|
|
105
|
+
Number.isFinite(u2) ? u2 : 0,
|
|
106
|
+
Number.isFinite(v2uv) ? v2uv : 0
|
|
60
107
|
],
|
|
61
|
-
cx: (
|
|
62
|
-
cy: (
|
|
63
|
-
cz: (
|
|
64
|
-
minX: Math.min(
|
|
65
|
-
minY: Math.min(
|
|
66
|
-
minZ: Math.min(
|
|
67
|
-
maxX: Math.max(
|
|
68
|
-
maxY: Math.max(
|
|
69
|
-
maxZ: Math.max(
|
|
108
|
+
cx: (v0.x + v1.x + v2.x) / 3,
|
|
109
|
+
cy: (v0.y + v1.y + v2.y) / 3,
|
|
110
|
+
cz: (v0.z + v1.z + v2.z) / 3,
|
|
111
|
+
minX: Math.min(v0.x, v1.x, v2.x),
|
|
112
|
+
minY: Math.min(v0.y, v1.y, v2.y),
|
|
113
|
+
minZ: Math.min(v0.z, v1.z, v2.z),
|
|
114
|
+
maxX: Math.max(v0.x, v1.x, v2.x),
|
|
115
|
+
maxY: Math.max(v0.y, v1.y, v2.y),
|
|
116
|
+
maxZ: Math.max(v0.z, v1.z, v2.z)
|
|
70
117
|
});
|
|
71
118
|
}
|
|
72
119
|
} finally {
|
|
73
|
-
|
|
120
|
+
if (indexed) geo.dispose();
|
|
74
121
|
}
|
|
75
122
|
}
|
|
76
|
-
return
|
|
123
|
+
return tris;
|
|
77
124
|
}
|
|
78
|
-
export {
|
|
125
|
+
export { collectValidTris };
|
|
126
|
+
|
|
127
|
+
//# sourceMappingURL=bvhTriCollector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bvhTriCollector.js","names":[],"sources":["../../src/junk/bvhTriCollector.ts"],"sourcesContent":["import * as THREE from \"three\";\nimport { isMeshNode, isShaderMatNode } from \"./junkImportSanitize.js\";\n\nexport interface ShardTri {\n p: [number, number, number, number, number, number, number, number, number];\n n: [number, number, number, number, number, number, number, number, number];\n uv: [number, number, number, number, number, number];\n cx: number;\n cy: number;\n cz: number;\n minX: number;\n minY: number;\n minZ: number;\n maxX: number;\n maxY: number;\n maxZ: number;\n}\n\nconst MIN_AREA2 = 1e-10;\n\nfunction allFinite(...vals: number[]): boolean {\n for (let i = 0; i < vals.length; i++) {\n if (!Number.isFinite(vals[i]))\n return false;\n }\n return true;\n}\n\nexport function collectValidTris(root: THREE.Object3D): ShardTri[] {\n root.updateMatrixWorld(true);\n const invRoot = new THREE.Matrix4().copy(root.matrixWorld).invert();\n const rel = new THREE.Matrix4();\n const normalMat = new THREE.Matrix3();\n const meshes: THREE.Mesh[] = [];\n\n root.traverse((obj) => {\n if (!isMeshNode(obj))\n return;\n if (\n obj.userData.isDecal ||\n obj.userData.isGizmo ||\n isShaderMatNode(obj.material) ||\n (Array.isArray(obj.material) && obj.material.every((m) => isShaderMatNode(m))) ||\n !obj.geometry?.attributes?.position\n ) {\n return;\n }\n meshes.push(obj);\n });\n\n const hasExplicitDestructible = meshes.some((m) => m.userData.destructible !== false);\n const tris: ShardTri[] = [];\n const v0 = new THREE.Vector3();\n const v1 = new THREE.Vector3();\n const v2 = new THREE.Vector3();\n const e1 = new THREE.Vector3();\n const e2 = new THREE.Vector3();\n const fn = new THREE.Vector3();\n const n0 = new THREE.Vector3();\n const n1 = new THREE.Vector3();\n const n2 = new THREE.Vector3();\n\n for (const mesh of meshes) {\n if (hasExplicitDestructible && mesh.userData.destructible === false)\n continue;\n const srcGeo = mesh.geometry;\n const indexed = srcGeo.index !== null;\n const geo = indexed ? srcGeo.toNonIndexed() : srcGeo;\n try {\n const pos = geo.attributes.position;\n const norm = geo.attributes.normal;\n const uv = geo.attributes.uv;\n const triCount = Math.floor(pos.count / 3);\n if (triCount <= 0)\n continue;\n rel.multiplyMatrices(invRoot, mesh.matrixWorld);\n normalMat.getNormalMatrix(rel);\n\n for (let t = 0; t < triCount; t++) {\n const i = t * 3;\n v0.fromBufferAttribute(pos, i).applyMatrix4(rel);\n v1.fromBufferAttribute(pos, i + 1).applyMatrix4(rel);\n v2.fromBufferAttribute(pos, i + 2).applyMatrix4(rel);\n if (!allFinite(v0.x, v0.y, v0.z, v1.x, v1.y, v1.z, v2.x, v2.y, v2.z))\n continue;\n e1.subVectors(v1, v0);\n e2.subVectors(v2, v0);\n fn.crossVectors(e1, e2);\n const area2 = fn.length();\n if (!Number.isFinite(area2) || area2 < MIN_AREA2)\n continue;\n fn.divideScalar(area2);\n\n if (norm) {\n n0.fromBufferAttribute(norm, i).applyMatrix3(normalMat);\n n1.fromBufferAttribute(norm, i + 1).applyMatrix3(normalMat);\n n2.fromBufferAttribute(norm, i + 2).applyMatrix3(normalMat);\n if (n0.lengthSq() > 1e-10) n0.normalize(); else n0.copy(fn);\n if (n1.lengthSq() > 1e-10) n1.normalize(); else n1.copy(fn);\n if (n2.lengthSq() > 1e-10) n2.normalize(); else n2.copy(fn);\n }\n else {\n n0.copy(fn);\n n1.copy(fn);\n n2.copy(fn);\n }\n\n const u0 = uv ? uv.getX(i) : 0;\n const v0uv = uv ? uv.getY(i) : 0;\n const u1 = uv ? uv.getX(i + 1) : 0;\n const v1uv = uv ? uv.getY(i + 1) : 0;\n const u2 = uv ? uv.getX(i + 2) : 0;\n const v2uv = uv ? uv.getY(i + 2) : 0;\n\n tris.push({\n p: [v0.x, v0.y, v0.z, v1.x, v1.y, v1.z, v2.x, v2.y, v2.z],\n n: [n0.x, n0.y, n0.z, n1.x, n1.y, n1.z, n2.x, n2.y, n2.z],\n uv: [\n Number.isFinite(u0) ? u0 : 0,\n Number.isFinite(v0uv) ? v0uv : 0,\n Number.isFinite(u1) ? u1 : 0,\n Number.isFinite(v1uv) ? v1uv : 0,\n Number.isFinite(u2) ? u2 : 0,\n Number.isFinite(v2uv) ? v2uv : 0,\n ],\n cx: (v0.x + v1.x + v2.x) / 3,\n cy: (v0.y + v1.y + v2.y) / 3,\n cz: (v0.z + v1.z + v2.z) / 3,\n minX: Math.min(v0.x, v1.x, v2.x),\n minY: Math.min(v0.y, v1.y, v2.y),\n minZ: Math.min(v0.z, v1.z, v2.z),\n maxX: Math.max(v0.x, v1.x, v2.x),\n maxY: Math.max(v0.y, v1.y, v2.y),\n maxZ: Math.max(v0.z, v1.z, v2.z),\n });\n }\n }\n finally {\n if (index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AM,KAAK,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;KAC/B,MAAM,KAAK,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;KAC/B,MAAM,KAAK,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;KAC/B,MAAM,KAAK,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;KAC/B,MAAM,KAAK,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;KAC/B,MAAM,KAAK,IAAI,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;IACnC,CAAC;GACL;EACJ,UACQ;GACJ,IAAI,SACA,IAAI,QAAQ;EACpB;CACJ;CACA,OAAO;AACX"}
|
package/dist/junk/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { DestructibleTarget, type DestructibleTargetHandle, type DestructibleTargetProps
|
|
1
|
+
export { DestructibleTarget, type DestructibleTargetHandle, type DestructibleTargetProps } from "./DestructibleTarget.js";
|
|
2
2
|
export { KolmoJunk, type KolmoJunkProps } from "./KolmoJunk.js";
|
|
3
3
|
export { ShardPieces } from "./ShardPieces.js";
|
|
4
4
|
export { TargetDecals, getBulletHoleTexture } from "./TargetDecals.js";
|
|
@@ -6,7 +6,7 @@ export { splitObjectIntoShards } from "./bvhShatter.js";
|
|
|
6
6
|
export { collectValidTris, type ShardTri } from "./bvhTriCollector.js";
|
|
7
7
|
export { BOTTLE_HEIGHT, CAN_LOD_THRESHOLD_M, TIN_CAN_HEIGHT, TIN_CAN_RADIUS, buildGlassBottleGeometry, buildTinCanGeometry, countGeometryTriangles, createGlassBottleMaterial, createTinCanMaterials, selectCanLod, type ResolvedCanLod, } from "./junkGeometry.js";
|
|
8
8
|
export { disposeImportedRoot, ensureMeshAttributes } from "./junkImportSanitize.js";
|
|
9
|
-
export { applySegmentsToImportedRoot, loadImportedGlbUrl, parseImportedGlbBuffer, type ImportedGlbAsset
|
|
9
|
+
export { applySegmentsToImportedRoot, loadImportedGlbUrl, parseImportedGlbBuffer, type ImportedGlbAsset } from "./junkImporter.js";
|
|
10
10
|
export { getProceduralLabelTexture, loadCustomLabelTexture } from "./junkLabels.js";
|
|
11
11
|
export type { DestructibleTargetSnapshot, SpawnedShardState } from "./targetHelpers.js";
|
|
12
12
|
export type { BallisticHitEvent, CanLodMode, DecalRecord, DestructibleTargetSpec, ImportedJunkSegment, JunkKind, ProceduralLabelId, ShardSpec, } from "./junkTypes.js";
|
package/dist/junk/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { DestructibleTarget
|
|
2
|
-
import { KolmoJunk
|
|
3
|
-
import { ShardPieces
|
|
4
|
-
import { TargetDecals
|
|
5
|
-
import { splitObjectIntoShards
|
|
6
|
-
import { collectValidTris
|
|
7
|
-
import { BOTTLE_HEIGHT
|
|
8
|
-
import { disposeImportedRoot
|
|
9
|
-
import { applySegmentsToImportedRoot
|
|
10
|
-
import { getProceduralLabelTexture
|
|
11
|
-
export {
|
|
1
|
+
import { DestructibleTarget } from "./DestructibleTarget.js";
|
|
2
|
+
import { KolmoJunk } from "./KolmoJunk.js";
|
|
3
|
+
import { ShardPieces } from "./ShardPieces.js";
|
|
4
|
+
import { TargetDecals, getBulletHoleTexture } from "./TargetDecals.js";
|
|
5
|
+
import { splitObjectIntoShards } from "./bvhShatter.js";
|
|
6
|
+
import { collectValidTris } from "./bvhTriCollector.js";
|
|
7
|
+
import { BOTTLE_HEIGHT, CAN_LOD_THRESHOLD_M, TIN_CAN_HEIGHT, TIN_CAN_RADIUS, buildGlassBottleGeometry, buildTinCanGeometry, countGeometryTriangles, createGlassBottleMaterial, createTinCanMaterials, selectCanLod } from "./junkGeometry.js";
|
|
8
|
+
import { disposeImportedRoot, ensureMeshAttributes } from "./junkImportSanitize.js";
|
|
9
|
+
import { applySegmentsToImportedRoot, loadImportedGlbUrl, parseImportedGlbBuffer } from "./junkImporter.js";
|
|
10
|
+
import { getProceduralLabelTexture, loadCustomLabelTexture } from "./junkLabels.js";
|
|
11
|
+
export { BOTTLE_HEIGHT, CAN_LOD_THRESHOLD_M, DestructibleTarget, KolmoJunk, ShardPieces, TIN_CAN_HEIGHT, TIN_CAN_RADIUS, TargetDecals, applySegmentsToImportedRoot, buildGlassBottleGeometry, buildTinCanGeometry, collectValidTris, countGeometryTriangles, createGlassBottleMaterial, createTinCanMaterials, disposeImportedRoot, ensureMeshAttributes, getBulletHoleTexture, getProceduralLabelTexture, loadCustomLabelTexture, loadImportedGlbUrl, parseImportedGlbBuffer, selectCanLod, splitObjectIntoShards };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/junk/index.ts"],"mappings":""}
|
|
@@ -1,34 +1,13 @@
|
|
|
1
|
-
import * as THREE from
|
|
1
|
+
import * as THREE from "three";
|
|
2
2
|
import type { CanLodMode } from "./junkTypes.js";
|
|
3
3
|
export declare const TIN_CAN_RADIUS = 0.085;
|
|
4
4
|
export declare const TIN_CAN_HEIGHT = 0.25;
|
|
5
5
|
export declare const BOTTLE_HEIGHT = 0.32;
|
|
6
6
|
export declare const CAN_LOD_THRESHOLD_M = 14;
|
|
7
|
-
export type ResolvedCanLod =
|
|
8
|
-
/**
|
|
9
|
-
* Selects concrete tin-can geometry LOD from camera distance and mode.
|
|
10
|
-
*/
|
|
7
|
+
export type ResolvedCanLod = "3-gon" | "12-gon";
|
|
11
8
|
export declare function selectCanLod(distanceM: number, mode: CanLodMode): ResolvedCanLod;
|
|
12
|
-
|
|
13
|
-
* Counts triangles for indexed or non-indexed BufferGeometry.
|
|
14
|
-
*/
|
|
15
|
-
export declare function countGeometryTriangles(geometry: THREE.BufferGeometry): number;
|
|
16
|
-
/**
|
|
17
|
-
* Builds procedural Tin Can geometry for '3-gon' (12 tris) or '12-gon' (72 tris).
|
|
18
|
-
* Uses thetaStart = Math.PI so the UV seam is at -Z and u = 0.5 faces +Z.
|
|
19
|
-
* Preserves multi-material groups: 0 = label sleeve, 1 = top cap, 2 = bottom cap.
|
|
20
|
-
*/
|
|
9
|
+
export declare function countGeometryTriangles(geo: THREE.BufferGeometry): number;
|
|
21
10
|
export declare function buildTinCanGeometry(lod: ResolvedCanLod): THREE.BufferGeometry;
|
|
22
|
-
|
|
23
|
-
* Builds procedural clearish glass bottle LatheGeometry ordered bottom-to-top
|
|
24
|
-
* with phiStart = Math.PI and height-normalized uv.y so labels wrap cleanly.
|
|
25
|
-
*/
|
|
26
|
-
export declare function buildGlassBottleGeometry(): THREE.BufferGeometry;
|
|
27
|
-
/**
|
|
28
|
-
* Creates Dreamcast-compatible clearish glass material.
|
|
29
|
-
*/
|
|
11
|
+
export declare function buildGlassBottleGeometry(): THREE.LatheGeometry;
|
|
30
12
|
export declare function createGlassBottleMaterial(): THREE.MeshStandardMaterial;
|
|
31
|
-
|
|
32
|
-
* Creates tin can multi-material array [label sleeve, top lid, bottom lid].
|
|
33
|
-
*/
|
|
34
|
-
export declare function createTinCanMaterials(labelTexture: THREE.Texture | null): [THREE.MeshStandardMaterial, THREE.MeshStandardMaterial, THREE.MeshStandardMaterial];
|
|
13
|
+
export declare function createTinCanMaterials(labelTex: THREE.Texture | null): THREE.MeshStandardMaterial[];
|
|
@@ -1,69 +1,87 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as THREE from "three";
|
|
2
2
|
// src/junk/junkGeometry.ts
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
var TIN_CAN_RADIUS = .085;
|
|
4
|
+
var TIN_CAN_HEIGHT = .25;
|
|
5
|
+
var BOTTLE_HEIGHT = .32;
|
|
6
|
+
var CAN_LOD_THRESHOLD_M = 14;
|
|
7
|
+
function selectCanLod(distanceM, mode) {
|
|
8
|
+
if (mode === "3-gon" || mode === "12-gon") return mode;
|
|
9
|
+
return distanceM > 14 ? "3-gon" : "12-gon";
|
|
6
10
|
}
|
|
7
|
-
function
|
|
8
|
-
if (
|
|
9
|
-
|
|
10
|
-
return
|
|
11
|
+
function countGeometryTriangles(geo) {
|
|
12
|
+
if (geo.index) return Math.floor(geo.index.count / 3);
|
|
13
|
+
const pos = geo.attributes.position;
|
|
14
|
+
return pos ? Math.floor(pos.count / 3) : 0;
|
|
11
15
|
}
|
|
12
|
-
function
|
|
13
|
-
if (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
function buildTinCanGeometry(lod) {
|
|
17
|
+
if (lod === "3-gon") {
|
|
18
|
+
const raw = new THREE.CylinderGeometry(TIN_CAN_RADIUS, TIN_CAN_RADIUS, TIN_CAN_HEIGHT, 3, 1, false, Math.PI, Math.PI * 2);
|
|
19
|
+
const geo = raw.toNonIndexed();
|
|
20
|
+
raw.dispose();
|
|
21
|
+
geo.computeVertexNormals();
|
|
22
|
+
geo.computeBoundingBox();
|
|
23
|
+
geo.computeBoundingSphere();
|
|
24
|
+
return geo;
|
|
16
25
|
}
|
|
17
|
-
|
|
18
|
-
|
|
26
|
+
const geo = new THREE.CylinderGeometry(TIN_CAN_RADIUS, TIN_CAN_RADIUS, TIN_CAN_HEIGHT, 12, 2, false, Math.PI, Math.PI * 2);
|
|
27
|
+
geo.computeBoundingBox();
|
|
28
|
+
geo.computeBoundingSphere();
|
|
29
|
+
return geo;
|
|
19
30
|
}
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
new
|
|
24
|
-
new
|
|
25
|
-
new
|
|
26
|
-
new
|
|
27
|
-
new
|
|
28
|
-
new
|
|
29
|
-
new
|
|
30
|
-
new
|
|
31
|
-
new
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
function buildGlassBottleGeometry() {
|
|
32
|
+
const halfH = BOTTLE_HEIGHT * .5;
|
|
33
|
+
const profile = [
|
|
34
|
+
new THREE.Vector2(1e-4, -.16),
|
|
35
|
+
new THREE.Vector2(.048, -.16),
|
|
36
|
+
new THREE.Vector2(.055, -.145),
|
|
37
|
+
new THREE.Vector2(.055, .01),
|
|
38
|
+
new THREE.Vector2(.046, .045),
|
|
39
|
+
new THREE.Vector2(.022, .085),
|
|
40
|
+
new THREE.Vector2(.02, .135),
|
|
41
|
+
new THREE.Vector2(.025, .148),
|
|
42
|
+
new THREE.Vector2(.024, halfH),
|
|
43
|
+
new THREE.Vector2(1e-4, halfH)
|
|
44
|
+
];
|
|
45
|
+
const geo = new THREE.LatheGeometry(profile, 12, Math.PI, Math.PI * 2);
|
|
46
|
+
const pos = geo.attributes.position;
|
|
47
|
+
const uv = geo.attributes.uv;
|
|
48
|
+
for (let i = 0; i < pos.count; i++) uv.setY(i, THREE.MathUtils.clamp((pos.getY(i) + halfH) / BOTTLE_HEIGHT, 0, 1));
|
|
49
|
+
uv.needsUpdate = true;
|
|
50
|
+
if (!geo.attributes.normal) geo.computeVertexNormals();
|
|
51
|
+
geo.computeBoundingBox();
|
|
52
|
+
geo.computeBoundingSphere();
|
|
53
|
+
return geo;
|
|
38
54
|
}
|
|
39
|
-
function
|
|
40
|
-
return new
|
|
55
|
+
function createGlassBottleMaterial() {
|
|
56
|
+
return new THREE.MeshStandardMaterial({
|
|
41
57
|
color: "#a7f3d0",
|
|
42
|
-
transparent:
|
|
58
|
+
transparent: true,
|
|
43
59
|
opacity: .42,
|
|
44
60
|
roughness: .12,
|
|
45
61
|
metalness: .1,
|
|
46
|
-
depthWrite:
|
|
62
|
+
depthWrite: false
|
|
47
63
|
});
|
|
48
64
|
}
|
|
49
|
-
function
|
|
65
|
+
function createTinCanMaterials(labelTex) {
|
|
50
66
|
return [
|
|
51
|
-
new
|
|
52
|
-
color:
|
|
53
|
-
map:
|
|
67
|
+
new THREE.MeshStandardMaterial({
|
|
68
|
+
color: labelTex ? "#ffffff" : "#e2e8f0",
|
|
69
|
+
map: labelTex ?? null,
|
|
54
70
|
roughness: .48,
|
|
55
71
|
metalness: .15
|
|
56
72
|
}),
|
|
57
|
-
new
|
|
73
|
+
new THREE.MeshStandardMaterial({
|
|
58
74
|
color: "#cbd5e1",
|
|
59
75
|
roughness: .34,
|
|
60
76
|
metalness: .78
|
|
61
77
|
}),
|
|
62
|
-
new
|
|
78
|
+
new THREE.MeshStandardMaterial({
|
|
63
79
|
color: "#94a3b8",
|
|
64
80
|
roughness: .38,
|
|
65
81
|
metalness: .78
|
|
66
82
|
})
|
|
67
83
|
];
|
|
68
84
|
}
|
|
69
|
-
export {
|
|
85
|
+
export { BOTTLE_HEIGHT, CAN_LOD_THRESHOLD_M, TIN_CAN_HEIGHT, TIN_CAN_RADIUS, buildGlassBottleGeometry, buildTinCanGeometry, countGeometryTriangles, createGlassBottleMaterial, createTinCanMaterials, selectCanLod };
|
|
86
|
+
|
|
87
|
+
//# sourceMappingURL=junkGeometry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"junkGeometry.js","names":[],"sources":["../../src/junk/junkGeometry.ts"],"sourcesContent":["import * as THREE from \"three\";\nimport type { CanLodMode } from \"./junkTypes.js\";\n\nexport const TIN_CAN_RADIUS = 0.085;\nexport const TIN_CAN_HEIGHT = 0.25;\nexport const BOTTLE_HEIGHT = 0.32;\nexport const CAN_LOD_THRESHOLD_M = 14;\n\nexport type ResolvedCanLod = \"3-gon\" | \"12-gon\";\n\nexport function selectCanLod(distanceM: number, mode: CanLodMode): ResolvedCanLod {\n if (mode === \"3-gon\" || mode === \"12-gon\")\n return mode;\n return distanceM > CAN_LOD_THRESHOLD_M ? \"3-gon\" : \"12-gon\";\n}\n\nexport function countGeometryTriangles(geo: THREE.BufferGeometry): number {\n if (geo.index)\n return Math.floor(geo.index.count / 3);\n const pos = geo.attributes.position;\n return pos ? Math.floor(pos.count / 3) : 0;\n}\n\nexport function buildTinCanGeometry(lod: ResolvedCanLod): THREE.BufferGeometry {\n if (lod === \"3-gon\") {\n const raw = new THREE.CylinderGeometry(TIN_CAN_RADIUS, TIN_CAN_RADIUS, TIN_CAN_HEIGHT, 3, 1, false, Math.PI, Math.PI * 2);\n const geo = raw.toNonIndexed();\n raw.dispose();\n geo.computeVertexNormals();\n geo.computeBoundingBox();\n geo.computeBoundingSphere();\n return geo;\n }\n const geo = new THREE.CylinderGeometry(TIN_CAN_RADIUS, TIN_CAN_RADIUS, TIN_CAN_HEIGHT, 12, 2, false, Math.PI, Math.PI * 2);\n geo.computeBoundingBox();\n geo.computeBoundingSphere();\n return geo;\n}\n\nexport function buildGlassBottleGeometry(): THREE.LatheGeometry {\n const halfH = BOTTLE_HEIGHT * 0.5;\n const profile = [\n new THREE.Vector2(1e-4, -0.16),\n new THREE.Vector2(0.048, -0.16),\n new THREE.Vector2(0.055, -0.145),\n new THREE.Vector2(0.055, 0.01),\n new THREE.Vector2(0.046, 0.045),\n new THREE.Vector2(0.022, 0.085),\n new THREE.Vector2(0.02, 0.135),\n new THREE.Vector2(0.025, 0.148),\n new THREE.Vector2(0.024, halfH),\n new THREE.Vector2(1e-4, halfH),\n ];\n const geo = new THREE.LatheGeometry(profile, 12, Math.PI, Math.PI * 2);\n const pos = geo.attributes.position;\n const uv = geo.attributes.uv;\n for (let i = 0; i < pos.count; i++) {\n uv.setY(i, THREE.MathUtils.clamp((pos.getY(i) + halfH) / BOTTLE_HEIGHT, 0, 1));\n }\n uv.needsUpdate = true;\n if (!geo.attributes.normal)\n geo.computeVertexNormals();\n geo.computeBoundingBox();\n geo.computeBoundingSphere();\n return geo;\n}\n\nexport function createGlassBottleMaterial(): THREE.MeshStandardMaterial {\n return new THREE.MeshStandardMaterial({\n color: \"#a7f3d0\",\n transparent: true,\n opacity: 0.42,\n roughness: 0.12,\n metalness: 0.1,\n depthWrite: false,\n });\n}\n\nexport function createTinCanMaterials(labelTex: THREE.Texture | null): THREE.MeshStandardMaterial[] {\n return [\n new THREE.MeshStandardMaterial({\n color: labelTex ? \"#ffffff\" : \"#e2e8f0\",\n map: labelTex ?? null,\n roughness: 0.48,\n metalness: 0.15,\n }),\n new THREE.MeshStandardMaterial({ color: \"#cbd5e1\", roughness: 0.34, metalness: 0.78 }),\n new THREE.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AC9B,IAAI,MAAM,QAAQ,KAAM,IAAK;EAC7B,IAAI,MAAM,QAAQ,MAAO,IAAK;EAC9B,IAAI,MAAM,QAAQ,MAAO,KAAK;EAC9B,IAAI,MAAM,QAAQ,MAAM,KAAK;CACjC;CACA,MAAM,MAAM,IAAI,MAAM,cAAc,SAAS,IAAI,KAAK,IAAI,KAAK,KAAK,CAAC;CACrE,MAAM,MAAM,IAAI,WAAW;CAC3B,MAAM,KAAK,IAAI,WAAW;CAC1B,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,OAAO,KAC3B,GAAG,KAAK,GAAG,MAAM,UAAU,OAAO,IAAI,KAAK,CAAC,IAAI,SAAS,eAAe,GAAG,CAAC,CAAC;CAEjF,GAAG,cAAc;CACjB,IAAI,CAAC,IAAI,WAAW,QAChB,IAAI,qBAAqB;CAC7B,IAAI,mBAAmB;CACvB,IAAI,sBAAsB;CAC1B,OAAO;AACX;AAEA,SAAgB,4BAAwD;CACpE,OAAO,IAAI,MAAM,qBAAqB;EAClC,OAAO;EACP,aAAa;EACb,SAAS;EACT,WAAW;EACX,WAAW;EACX,YAAY;CAChB,CAAC;AACL;AAEA,SAAgB,sBAAsB,UAA8D;CAChG,OAAO;EACH,IAAI,MAAM,qBAAqB;GAC3B,OAAO,WAAW,YAAY;GAC9B,KAAK,YAAY;GACjB,WAAW;GACX,WAAW;EACf,CAAC;EACD,IAAI,MAAM,qBAAqB;GAAE,OAAO;GAAW,WAAW;GAAM,WAAW;EAAK,CAAC;EACrF,IAAI,MAAM,qBAAqB;GAAE,OAAO;GAAW,WAAW;GAAM,WAAW;EAAK,CAAC;CACzF;AACJ"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import * as THREE from
|
|
2
|
-
export declare
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*/
|
|
1
|
+
import * as THREE from "three";
|
|
2
|
+
export declare const isMeshNode: (obj: unknown) => obj is THREE.Mesh;
|
|
3
|
+
export declare const isShaderMatNode: (mat: unknown) => boolean;
|
|
4
|
+
export declare function ensureMeshAttributes(mesh: THREE.Mesh, label: string): void;
|
|
6
5
|
export declare function disposeImportedRoot(root: THREE.Object3D): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as THREE from "three";
|
|
2
2
|
// src/junk/junkImportSanitize.ts
|
|
3
|
-
var
|
|
3
|
+
var TEX_FIELDS = [
|
|
4
4
|
"map",
|
|
5
5
|
"normalMap",
|
|
6
6
|
"roughnessMap",
|
|
@@ -9,46 +9,66 @@ var t = [
|
|
|
9
9
|
"aoMap",
|
|
10
10
|
"alphaMap"
|
|
11
11
|
];
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
var isMeshNode = (obj) => Boolean(obj?.isMesh);
|
|
13
|
+
var isShaderMatNode = (mat) => Boolean(mat?.isShaderMaterial);
|
|
14
|
+
var isTextureObj = (tex) => Boolean(tex?.isTexture);
|
|
15
|
+
function ensureMeshAttributes(mesh, label) {
|
|
16
|
+
const geo = mesh.geometry;
|
|
17
|
+
const pos = geo?.attributes?.position;
|
|
18
|
+
if (!pos) return;
|
|
19
|
+
for (let i = 0; i < pos.count; i++) if (!Number.isFinite(pos.getX(i)) || !Number.isFinite(pos.getY(i)) || !Number.isFinite(pos.getZ(i))) throw new Error(`GLB "${label}" contains non-finite vertex coordinates.`);
|
|
20
|
+
if (geo.index) {
|
|
21
|
+
const idx = geo.index;
|
|
22
|
+
for (let i = 0; i < idx.count; i++) {
|
|
23
|
+
const v = idx.getX(i);
|
|
24
|
+
if (!Number.isInteger(v) || v < 0 || v >= pos.count) throw new Error(`GLB "${label}" contains out-of-bounds triangle indices.`);
|
|
22
25
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
}
|
|
27
|
+
if (geo.attributes.normal) {
|
|
28
|
+
const norm = geo.attributes.normal;
|
|
29
|
+
let fixed = false;
|
|
30
|
+
for (let i = 0; i < norm.count; i++) if (!Number.isFinite(norm.getX(i)) || !Number.isFinite(norm.getY(i)) || !Number.isFinite(norm.getZ(i))) {
|
|
31
|
+
norm.setXYZ(i, 0, 1, 0);
|
|
32
|
+
fixed = true;
|
|
27
33
|
}
|
|
28
|
-
if (
|
|
29
|
-
let e = r.attributes.uv, t = !1;
|
|
30
|
-
for (let n = 0; n < e.count; n++) Number.isFinite(e.getX(n)) && Number.isFinite(e.getY(n)) || (e.setXY(n, 0, 0), t = !0);
|
|
31
|
-
t && (e.needsUpdate = !0);
|
|
32
|
-
} else r.setAttribute("uv", new e.Float32BufferAttribute(new Float32Array(i.count * 2), 2));
|
|
33
|
-
t.castShadow = !0, t.receiveShadow = !0;
|
|
34
|
+
if (fixed) norm.needsUpdate = true;
|
|
34
35
|
}
|
|
36
|
+
geo.computeBoundingBox();
|
|
37
|
+
if (!geo.attributes.normal) geo.computeVertexNormals();
|
|
38
|
+
if (geo.attributes.uv) {
|
|
39
|
+
const uv = geo.attributes.uv;
|
|
40
|
+
let fixed = false;
|
|
41
|
+
for (let i = 0; i < uv.count; i++) if (!Number.isFinite(uv.getX(i)) || !Number.isFinite(uv.getY(i))) {
|
|
42
|
+
uv.setXY(i, 0, 0);
|
|
43
|
+
fixed = true;
|
|
44
|
+
}
|
|
45
|
+
if (fixed) uv.needsUpdate = true;
|
|
46
|
+
} else geo.setAttribute("uv", new THREE.Float32BufferAttribute(new Float32Array(pos.count * 2), 2));
|
|
47
|
+
mesh.castShadow = true;
|
|
48
|
+
mesh.receiveShadow = true;
|
|
35
49
|
}
|
|
36
|
-
function
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
function disposeImportedRoot(root) {
|
|
51
|
+
const mats = /* @__PURE__ */ new Set();
|
|
52
|
+
const texs = /* @__PURE__ */ new Set();
|
|
53
|
+
root.traverse((obj) => {
|
|
54
|
+
if (!isMeshNode(obj)) return;
|
|
55
|
+
obj.geometry?.dispose();
|
|
56
|
+
const list = Array.isArray(obj.material) ? obj.material : [obj.material];
|
|
57
|
+
for (const mat of list) {
|
|
58
|
+
if (!mat || mats.has(mat)) continue;
|
|
59
|
+
mats.add(mat);
|
|
60
|
+
const rec = mat;
|
|
61
|
+
for (const f of TEX_FIELDS) {
|
|
62
|
+
const tex = rec[f];
|
|
63
|
+
if (isTextureObj(tex) && !texs.has(tex)) {
|
|
64
|
+
texs.add(tex);
|
|
65
|
+
tex.dispose();
|
|
66
|
+
}
|
|
49
67
|
}
|
|
50
|
-
|
|
68
|
+
mat.dispose();
|
|
51
69
|
}
|
|
52
70
|
});
|
|
53
71
|
}
|
|
54
|
-
export {
|
|
72
|
+
export { disposeImportedRoot, ensureMeshAttributes, isMeshNode, isShaderMatNode };
|
|
73
|
+
|
|
74
|
+
//# sourceMappingURL=junkImportSanitize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"junkImportSanitize.js","names":[],"sources":["../../src/junk/junkImportSanitize.ts"],"sourcesContent":["import * as THREE from \"three\";\n\nconst TEX_FIELDS = [\"map\", \"normalMap\", \"roughnessMap\", \"metalnessMap\", \"emissiveMap\", \"aoMap\", \"alphaMap\"] as const;\n\nexport const isMeshNode = (obj: unknown): obj is THREE.Mesh =>\n Boolean((obj as THREE.Mesh | null | undefined)?.isMesh);\n\nexport const isShaderMatNode = (mat: unknown): boolean =>\n Boolean((mat as THREE.ShaderMaterial | null | undefined)?.isShaderMaterial);\n\nconst isTextureObj = (tex: unknown): tex is THREE.Texture =>\n Boolean((tex as THREE.Texture | null | undefined)?.isTexture);\n\nexport function ensureMeshAttributes(mesh: THREE.Mesh, label: string): void {\n const geo = mesh.geometry;\n const pos = geo?.attributes?.position;\n if (!pos)\n return;\n for (let i = 0; i < pos.count; i++) {\n if (!Number.isFinite(pos.getX(i)) || !Number.isFinite(pos.getY(i)) || !Number.isFinite(pos.getZ(i))) {\n throw new Error(`GLB \"${label}\" contains non-finite vertex coordinates.`);\n }\n }\n if (geo.index) {\n const idx = geo.index;\n for (let i = 0; i < idx.count; i++) {\n const v = idx.getX(i);\n if (!Number.isInteger(v) || v < 0 || v >= pos.count) {\n throw new Error(`GLB \"${label}\" contains out-of-bounds triangle indices.`);\n }\n }\n }\n if (geo.attributes.normal) {\n const norm = geo.attributes.normal;\n let fixed = false;\n for (let i = 0; i < norm.count; i++) {\n if (!Number.isFinite(norm.getX(i)) || !Number.isFinite(norm.getY(i)) || !Number.isFinite(norm.getZ(i))) {\n norm.setXYZ(i, 0, 1, 0);\n fixed = true;\n }\n }\n if (fixed)\n norm.needsUpdate = true;\n }\n geo.computeBoundingBox();\n if (!geo.attributes.normal)\n geo.computeVertexNormals();\n if (geo.attributes.uv) {\n const uv = geo.attributes.uv;\n let fixed = false;\n for (let i = 0; i < uv.count; i++) {\n if (!Number.isFinite(uv.getX(i)) || !Number.isFinite(uv.getY(i))) {\n uv.setXY(i, 0, 0);\n fixed = true;\n }\n }\n if (fixed)\n uv.needsUpdate = true;\n }\n else {\n geo.setAttribute(\"uv\", new THREE.Float32BufferAttribute(new Float32Array(pos.count * 2), 2));\n }\n mesh.castShadow = true;\n mesh.receiveShadow = true;\n}\n\nexport function disposeImportedRoot(root: THREE.Object3D): void {\n const mats = new Set<THREE.Material>();\n const texs = new Set<THREE.Texture>();\n root.traverse((obj) => {\n if (!isMeshNode(obj))\n return;\n obj.geometry?.dispose();\n const list = Array.isArray(obj.material) ? obj.material : [obj.material];\n for (const mat of list) {\n if (!mat || mats.has(mat))\n continue;\n mats.add(mat);\n const rec = mat as unknown as Record<string, unknown>;\n for (const f of TEX_FIELDS) {\n const tex = rec[f];\n if (isTextureObj(tex) && !texs.has(tex)) {\n texs.add(tex);\n tex.dispose();\n }\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from "three";
|
|
2
2
|
import type { ImportedJunkSegment } from "./junkTypes.js";
|
|
3
|
-
export { disposeImportedRoot } from "./junkImportSanitize.js";
|
|
4
3
|
export interface ImportedGlbAsset {
|
|
5
4
|
root: THREE.Group;
|
|
6
5
|
fileName: string;
|
|
@@ -10,16 +9,6 @@ export interface ImportedGlbAsset {
|
|
|
10
9
|
halfExtents: [number, number, number];
|
|
11
10
|
dispose: () => void;
|
|
12
11
|
}
|
|
13
|
-
|
|
14
|
-
* Applies segment destructibility and customName metadata onto an imported root's meshes.
|
|
15
|
-
*/
|
|
16
|
-
export declare function applySegmentsToImportedRoot(root: THREE.Object3D, segments: ImportedJunkSegment[]): void;
|
|
17
|
-
/**
|
|
18
|
-
* Parses an ArrayBuffer containing a .glb/.gltf asset, normalizes scale/origin,
|
|
19
|
-
* guarantees normals/UVs, and enumerates ImportedJunkSegment descriptors.
|
|
20
|
-
*/
|
|
12
|
+
export declare function applySegmentsToImportedRoot(root: THREE.Object3D, segments: readonly ImportedJunkSegment[]): void;
|
|
21
13
|
export declare function parseImportedGlbBuffer(buffer: ArrayBuffer, fileName?: string): Promise<ImportedGlbAsset>;
|
|
22
|
-
/**
|
|
23
|
-
* Fetches a .glb/.gltf URL (blob:, data:, or HTTP path) and parses it as an ImportedGlbAsset.
|
|
24
|
-
*/
|
|
25
14
|
export declare function loadImportedGlbUrl(url: string, fileName?: string): Promise<ImportedGlbAsset>;
|