@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,102 +1,130 @@
|
|
|
1
|
-
import { buildGlassBottleGeometry
|
|
2
|
-
import { applySegmentsToImportedRoot
|
|
3
|
-
import { getProceduralLabelTexture
|
|
4
|
-
import { useEffect
|
|
1
|
+
import { buildGlassBottleGeometry, buildTinCanGeometry, countGeometryTriangles, createGlassBottleMaterial, createTinCanMaterials } from "./junkGeometry.js";
|
|
2
|
+
import { applySegmentsToImportedRoot, loadImportedGlbUrl } from "./junkImporter.js";
|
|
3
|
+
import { getProceduralLabelTexture, loadCustomLabelTexture } from "./junkLabels.js";
|
|
4
|
+
import { useEffect, useMemo, useState } from "react";
|
|
5
|
+
import "three";
|
|
5
6
|
// src/junk/useTargetAssets.ts
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
v(null);
|
|
7
|
+
function useTargetAssets(spec, importedAsset) {
|
|
8
|
+
const [customTex, setCustomTex] = useState(null);
|
|
9
|
+
const [fetchedAsset, setFetchedAsset] = useState(null);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (spec.labelId !== "custom" || !spec.customAlbedoUrl) {
|
|
12
|
+
setCustomTex(null);
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
|
-
let
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
let cancelled = false;
|
|
16
|
+
let disposeTex = null;
|
|
17
|
+
loadCustomLabelTexture(spec.customAlbedoUrl).then((loaded) => {
|
|
18
|
+
if (cancelled) loaded.dispose();
|
|
19
|
+
else {
|
|
20
|
+
disposeTex = loaded.dispose;
|
|
21
|
+
setCustomTex(loaded.texture);
|
|
22
|
+
}
|
|
18
23
|
}).catch(() => {
|
|
19
|
-
|
|
20
|
-
})
|
|
21
|
-
|
|
24
|
+
if (!cancelled) setCustomTex(null);
|
|
25
|
+
});
|
|
26
|
+
return () => {
|
|
27
|
+
cancelled = true;
|
|
28
|
+
disposeTex?.();
|
|
22
29
|
};
|
|
23
|
-
}, [
|
|
24
|
-
|
|
25
|
-
|
|
30
|
+
}, [spec.labelId, spec.customAlbedoUrl]);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (spec.kind !== "imported-glb" || importedAsset || !spec.importedUrl) {
|
|
33
|
+
setFetchedAsset(null);
|
|
26
34
|
return;
|
|
27
35
|
}
|
|
28
|
-
let
|
|
29
|
-
|
|
30
|
-
|
|
36
|
+
let cancelled = false;
|
|
37
|
+
let owned = null;
|
|
38
|
+
loadImportedGlbUrl(spec.importedUrl, spec.id).then((asset) => {
|
|
39
|
+
if (cancelled) asset.dispose();
|
|
40
|
+
else {
|
|
41
|
+
owned = asset;
|
|
42
|
+
setFetchedAsset(asset);
|
|
43
|
+
}
|
|
31
44
|
}).catch(() => {
|
|
32
|
-
|
|
33
|
-
})
|
|
34
|
-
|
|
45
|
+
if (!cancelled) setFetchedAsset(null);
|
|
46
|
+
});
|
|
47
|
+
return () => {
|
|
48
|
+
cancelled = true;
|
|
49
|
+
owned?.dispose();
|
|
35
50
|
};
|
|
36
51
|
}, [
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
52
|
+
spec.kind,
|
|
53
|
+
spec.importedUrl,
|
|
54
|
+
spec.id,
|
|
55
|
+
importedAsset
|
|
41
56
|
]);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
57
|
+
const sourceAsset = importedAsset ?? fetchedAsset;
|
|
58
|
+
const importedRoot = useMemo(() => {
|
|
59
|
+
if (!sourceAsset) return null;
|
|
60
|
+
return importedAsset ? sourceAsset.root.clone(true) : sourceAsset.root;
|
|
61
|
+
}, [sourceAsset, importedAsset]);
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (importedRoot && spec.segments) applySegmentsToImportedRoot(importedRoot, spec.segments);
|
|
64
|
+
}, [importedRoot, spec.segments]);
|
|
65
|
+
const can3Geo = useMemo(() => spec.kind === "tin-can" ? buildTinCanGeometry("3-gon") : null, [spec.kind]);
|
|
66
|
+
const can12Geo = useMemo(() => spec.kind === "tin-can" ? buildTinCanGeometry("12-gon") : null, [spec.kind]);
|
|
67
|
+
const bottleGeo = useMemo(() => spec.kind === "glass-bottle" ? buildGlassBottleGeometry() : null, [spec.kind]);
|
|
68
|
+
const bottleMat = useMemo(() => spec.kind === "glass-bottle" ? createGlassBottleMaterial() : null, [spec.kind]);
|
|
69
|
+
useEffect(() => () => {
|
|
70
|
+
can3Geo?.dispose();
|
|
71
|
+
can12Geo?.dispose();
|
|
72
|
+
bottleGeo?.dispose();
|
|
73
|
+
bottleMat?.dispose();
|
|
49
74
|
}, [
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
75
|
+
can3Geo,
|
|
76
|
+
can12Geo,
|
|
77
|
+
bottleGeo,
|
|
78
|
+
bottleMat
|
|
54
79
|
]);
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return
|
|
80
|
+
const activeLabelTex = useMemo(() => spec.labelId === "custom" && customTex ? customTex : getProceduralLabelTexture(spec.labelId), [spec.labelId, customTex]);
|
|
81
|
+
const canMats = useMemo(() => spec.kind === "tin-can" ? createTinCanMaterials(activeLabelTex) : null, [spec.kind, activeLabelTex]);
|
|
82
|
+
useEffect(() => () => {
|
|
83
|
+
canMats?.forEach((m) => m.dispose());
|
|
84
|
+
}, [canMats]);
|
|
85
|
+
const can3TriCount = useMemo(() => can3Geo ? countGeometryTriangles(can3Geo) : 0, [can3Geo]);
|
|
86
|
+
const can12TriCount = useMemo(() => can12Geo ? countGeometryTriangles(can12Geo) : 0, [can12Geo]);
|
|
87
|
+
const baseTriCount = useMemo(() => {
|
|
88
|
+
if (spec.kind === "glass-bottle") return bottleGeo ? countGeometryTriangles(bottleGeo) : 0;
|
|
89
|
+
return sourceAsset ? sourceAsset.segments.reduce((s, seg) => s + seg.triCount, 0) : 0;
|
|
65
90
|
}, [
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
91
|
+
spec.kind,
|
|
92
|
+
bottleGeo,
|
|
93
|
+
sourceAsset
|
|
94
|
+
]);
|
|
95
|
+
const customLabelLoaded = Boolean(spec.labelId === "custom" && spec.customAlbedoUrl && customTex);
|
|
96
|
+
const importedHalfExtents = sourceAsset?.halfExtents ?? null;
|
|
97
|
+
const importedKey = sourceAsset?.fileName ?? "glb";
|
|
98
|
+
return useMemo(() => ({
|
|
99
|
+
can3Geo,
|
|
100
|
+
can12Geo,
|
|
101
|
+
can3TriCount,
|
|
102
|
+
can12TriCount,
|
|
103
|
+
baseTriCount,
|
|
104
|
+
canMats,
|
|
105
|
+
bottleGeo,
|
|
106
|
+
bottleMat,
|
|
107
|
+
activeLabelTex,
|
|
108
|
+
customLabelLoaded,
|
|
109
|
+
importedRoot,
|
|
110
|
+
importedHalfExtents,
|
|
111
|
+
importedKey
|
|
87
112
|
}), [
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
113
|
+
can3Geo,
|
|
114
|
+
can12Geo,
|
|
115
|
+
can3TriCount,
|
|
116
|
+
can12TriCount,
|
|
117
|
+
baseTriCount,
|
|
118
|
+
canMats,
|
|
119
|
+
bottleGeo,
|
|
120
|
+
bottleMat,
|
|
121
|
+
activeLabelTex,
|
|
122
|
+
customLabelLoaded,
|
|
123
|
+
importedRoot,
|
|
124
|
+
importedHalfExtents,
|
|
125
|
+
importedKey
|
|
100
126
|
]);
|
|
101
127
|
}
|
|
102
|
-
export {
|
|
128
|
+
export { useTargetAssets };
|
|
129
|
+
|
|
130
|
+
//# sourceMappingURL=useTargetAssets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTargetAssets.js","names":[],"sources":["../../src/junk/useTargetAssets.ts"],"sourcesContent":["import { useEffect, useMemo, useState } from \"react\";\nimport * as THREE from \"three\";\nimport {\n buildGlassBottleGeometry,\n buildTinCanGeometry,\n countGeometryTriangles,\n createGlassBottleMaterial,\n createTinCanMaterials,\n} from \"./junkGeometry.js\";\nimport { applySegmentsToImportedRoot, loadImportedGlbUrl, type ImportedGlbAsset } from \"./junkImporter.js\";\nimport { getProceduralLabelTexture, loadCustomLabelTexture } from \"./junkLabels.js\";\nimport type { DestructibleTargetSpec } from \"./junkTypes.js\";\n\nexport interface TargetAssetBundle {\n can3Geo: THREE.BufferGeometry | null;\n can12Geo: THREE.BufferGeometry | null;\n can3TriCount: number;\n can12TriCount: number;\n baseTriCount: number;\n canMats: THREE.MeshStandardMaterial[] | null;\n bottleGeo: THREE.LatheGeometry | null;\n bottleMat: THREE.MeshStandardMaterial | null;\n activeLabelTex: THREE.Texture | null;\n customLabelLoaded: boolean;\n importedRoot: THREE.Group | null;\n importedHalfExtents: [number, number, number] | null;\n importedKey: string;\n}\n\nexport function useTargetAssets(\n spec: DestructibleTargetSpec,\n importedAsset?: ImportedGlbAsset | null,\n): TargetAssetBundle {\n const [customTex, setCustomTex] = useState<THREE.Texture | null>(null);\n const [fetchedAsset, setFetchedAsset] = useState<ImportedGlbAsset | null>(null);\n\n useEffect(() => {\n if (spec.labelId !== \"custom\" || !spec.customAlbedoUrl) {\n setCustomTex(null);\n return;\n }\n let cancelled = false;\n let disposeTex: (() => void) | null = null;\n void loadCustomLabelTexture(spec.customAlbedoUrl)\n .then((loaded) => {\n if (cancelled)\n loaded.dispose();\n else {\n disposeTex = loaded.dispose;\n setCustomTex(loaded.texture);\n }\n })\n .catch(() => {\n if (!cancelled)\n setCustomTex(null);\n });\n return () => {\n cancelled = true;\n disposeTex?.();\n };\n }, [spec.labelId, spec.customAlbedoUrl]);\n\n useEffect(() => {\n if (spec.kind !== \"imported-glb\" || importedAsset || !spec.importedUrl) {\n setFetchedAsset(null);\n return;\n }\n let cancelled = false;\n let owned: ImportedGlbAsset | null = null;\n void loadImportedGlbUrl(spec.importedUrl, spec.id)\n .then((asset) => {\n if (cancelled)\n asset.dispose();\n else {\n owned = asset;\n setFetchedAsset(asset);\n }\n })\n .catch(() => {\n if (!cancelled)\n setFetchedAsset(null);\n });\n return () => {\n cancelled = true;\n owned?.dispose();\n };\n }, [spec.kind, spec.importedUrl, spec.id, importedAsset]);\n\n const sourceAsset = importedAsset ?? fetchedAsset;\n const importedRoot = useMemo(() => {\n if (!sourceAsset)\n return null;\n return importedAsset ? sourceAsset.root.clone(true) : sourceAsset.root;\n }, [sourceAsset, importedAsset]);\n\n useEffect(() => {\n if (importedRoot && spec.segments)\n applySegmentsToImportedRoot(importedRoot, spec.segments);\n }, [importedRoot, spec.segments]);\n\n const can3Geo = useMemo(() => (spec.kind === \"tin-can\" ? buildTinCanGeometry(\"3-gon\") : null), [spec.kind]);\n const can12Geo = useMemo(() => (spec.kind === \"tin-can\" ? buildTinCanGeometry(\"12-gon\") : null), [spec.kind]);\n const bottleGeo = useMemo(() => (spec.kind === \"glass-bottle\" ? buildGlassBottleGeometry() : null), [spec.kind]);\n const bottleMat = useMemo(() => (spec.kind === \"glass-bottle\" ? createGlassBottleMaterial() : null), [spec.kind]);\n\n useEffect(\n () => () => {\n can3Geo?.dispose();\n can12Geo?.dispose();\n bottleGeo?.dispose();\n bottleMat?.dispose();\n },\n [can3Geo, can12Geo, bottleGeo, bottleMat],\n );\n\n const activeLabelTex = useMemo<THREE.Texture | null>(\n () => (spec.labelId === \"custom\" && customTex ? customTex : getProceduralLabelTexture(spec.labelId)),\n [spec.labelId, customTex],\n );\n const canMats = useMemo(() => (spec.kind === \"tin-can\" ? createTinCanMaterials(activeLabelTex) : null), [spec.kind, activeLabelTex]);\n\n useEffect(\n () => () => {\n canMats?.forEach((m) => m.dispose());\n },\n [canMats],\n );\n\n const can3TriCount = useMemo(() => (can3Geo ? countGeometryTriangles(can3Geo) : 0), [can3Geo]);\n const can12TriCount = useMemo(() => (can12Geo ? countGeometryTriangles(can12Geo) : 0), [can12Geo]);\n const baseTriCount = useMemo(() => {\n if (spec.kind === \"glass-bottle\")\n return bottleGeo ? countGeometryTriangles(bottleGeo) : 0;\n return sourceAsset ? sourceAsset.segments.reduce((s, seg) => s + seg.triCount, 0) : 0;\n }, [spec.kind, bottleGeo, sourceAsset]);\n\n const customLabelLoaded = Boolean(spec.labelId === \"custom\" && spec.customAlbedoUrl && customTex);\n const importedHalfExtents = sourceAsset?.halfExtents ?? null;\n const importedKey = sourceAsset?.fileName ?? \"glb\";\n\n return useMemo(\n () => ({\n can3Geo,\n can12Geo,\n can3TriCount,\n can12TriCount,\n baseTriCount,\n canMats,\n bottleGeo,\n bottleMat,\n activeLabelTex,\n customLabelLoaded,\n importedRoot,\n importedHalfExtents,\n importedKey,\n }),\n [\n can3Geo,\n can12Geo,\n can3TriCount,\n can12TriCount,\n baseTriCount,\n canMats,\n bottleGeo,\n bottleMat,\n activeLabelTex,\n customLabelLoaded,\n importedRoot,\n importedHalfExtents,\n importedKey,\n ],\n );\n}\n"],"mappings":"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"}
|
package/dist/physics/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { type ReactNode, type RefObject } from "react";
|
|
2
2
|
import * as THREE from "three";
|
|
3
3
|
import { type PhysicsWorldProps } from "@khr3/core";
|
|
4
|
-
import type
|
|
4
|
+
import { type World } from "koota";
|
|
5
5
|
export type KolmoTimeControlValue = number | RefObject<number>;
|
|
6
6
|
export type KolmoPointGravity = {
|
|
7
7
|
readonly kind: "point";
|
package/dist/physics/index.js
CHANGED
|
@@ -1,30 +1,48 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { kolmoWorld } from "../engine/kolmoTraits.js";
|
|
2
|
+
import { Suspense, createContext, useContext, useLayoutEffect, useMemo } from "react";
|
|
3
|
+
import * as THREE from "three";
|
|
4
|
+
import "koota";
|
|
5
|
+
import { WorldProvider, useWorld } from "koota/react";
|
|
6
|
+
import { PhysicsWorld } from "@khr3/core";
|
|
7
|
+
import { useCustomGravity } from "@pinkaphant/ecctrl/gravity";
|
|
8
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
9
|
// src/physics/index.tsx
|
|
8
|
-
var
|
|
9
|
-
function
|
|
10
|
+
var KolmoGravityContext = createContext(false);
|
|
11
|
+
function useOptionalKootaWorld() {
|
|
10
12
|
try {
|
|
11
|
-
return
|
|
13
|
+
return useWorld();
|
|
12
14
|
} catch {
|
|
13
15
|
return null;
|
|
14
16
|
}
|
|
15
17
|
}
|
|
16
|
-
function
|
|
17
|
-
return Array.isArray(
|
|
18
|
+
function isGravityTuple(g) {
|
|
19
|
+
return Array.isArray(g);
|
|
18
20
|
}
|
|
19
|
-
function
|
|
20
|
-
return typeof
|
|
21
|
+
function isPointGravity(g) {
|
|
22
|
+
return typeof g === "object" && !Array.isArray(g) && "kind" in g && g.kind === "point";
|
|
21
23
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
var _gravTmp = new THREE.Vector3();
|
|
25
|
+
function KolmoPhysics({ gravity = "planar", paused = false, timeScale = 1, maxDelta, physicsDebug = false, world = null, children, ...physicsProps }) {
|
|
26
|
+
const outerWorld = useOptionalKootaWorld();
|
|
27
|
+
const resolvedWorld = world ?? outerWorld ?? kolmoWorld;
|
|
28
|
+
const isCallback = typeof gravity === "function";
|
|
29
|
+
const isTuple = isGravityTuple(gravity);
|
|
30
|
+
const isCustomLiteral = gravity === "custom";
|
|
31
|
+
const isPoint = isPointGravity(gravity);
|
|
32
|
+
const isCustomGravity = isCallback || isPoint || isCustomLiteral;
|
|
33
|
+
const gx = isTuple ? gravity[0] : 0;
|
|
34
|
+
const gy = isTuple ? gravity[1] : -9.81;
|
|
35
|
+
const gz = isTuple ? gravity[2] : 0;
|
|
36
|
+
const cx = isPoint ? gravity.center[0] : 0;
|
|
37
|
+
const cy = isPoint ? gravity.center[1] : 0;
|
|
38
|
+
const cz = isPoint ? gravity.center[2] : 0;
|
|
39
|
+
const surfaceG = isPoint ? gravity.surfaceG : gravity === "zero" ? 0 : 9.81;
|
|
40
|
+
const gravityFn = isCallback ? gravity : null;
|
|
41
|
+
const rapierGravity = useMemo(() => isTuple ? [
|
|
42
|
+
gx,
|
|
43
|
+
gy,
|
|
44
|
+
gz
|
|
45
|
+
] : isCustomGravity || gravity === "zero" ? [
|
|
28
46
|
0,
|
|
29
47
|
0,
|
|
30
48
|
0
|
|
@@ -33,52 +51,55 @@ function g({ gravity: t = "planar", paused: n = !1, timeScale: a = 1, maxDelta:
|
|
|
33
51
|
-9.81,
|
|
34
52
|
0
|
|
35
53
|
], [
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
54
|
+
isTuple,
|
|
55
|
+
gx,
|
|
56
|
+
gy,
|
|
57
|
+
gz,
|
|
58
|
+
isCustomGravity,
|
|
59
|
+
gravity === "zero"
|
|
42
60
|
]);
|
|
43
|
-
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
61
|
+
useLayoutEffect(() => {
|
|
62
|
+
if (isCustomLiteral || !isCallback && !isPoint) return;
|
|
63
|
+
const setField = useCustomGravity.getState().setGravityField;
|
|
64
|
+
if (gravityFn) setField((pos) => gravityFn(pos, _gravTmp));
|
|
65
|
+
else if (isPoint) setField((pos) => {
|
|
66
|
+
_gravTmp.set(pos.x - cx, pos.y - cy, pos.z - cz);
|
|
67
|
+
const lenSq = _gravTmp.lengthSq();
|
|
68
|
+
return lenSq < 1e-8 ? _gravTmp.set(0, -surfaceG, 0) : _gravTmp.multiplyScalar(-surfaceG / Math.sqrt(lenSq));
|
|
50
69
|
});
|
|
51
70
|
}, [
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
71
|
+
isCustomLiteral,
|
|
72
|
+
isCallback,
|
|
73
|
+
isPoint,
|
|
74
|
+
gravityFn,
|
|
75
|
+
cx,
|
|
76
|
+
cy,
|
|
77
|
+
cz,
|
|
78
|
+
surfaceG
|
|
60
79
|
]);
|
|
61
|
-
|
|
62
|
-
value:
|
|
63
|
-
children: /* @__PURE__ */
|
|
64
|
-
...
|
|
65
|
-
paused
|
|
66
|
-
timeScale
|
|
67
|
-
...
|
|
68
|
-
gravity:
|
|
69
|
-
debug:
|
|
70
|
-
children: /* @__PURE__ */
|
|
80
|
+
const content = /* @__PURE__ */ jsx(KolmoGravityContext.Provider, {
|
|
81
|
+
value: isCustomGravity,
|
|
82
|
+
children: /* @__PURE__ */ jsx(PhysicsWorld, {
|
|
83
|
+
...physicsProps,
|
|
84
|
+
paused,
|
|
85
|
+
timeScale,
|
|
86
|
+
...maxDelta === void 0 ? {} : { maxDelta },
|
|
87
|
+
gravity: rapierGravity,
|
|
88
|
+
debug: physicsDebug,
|
|
89
|
+
children: /* @__PURE__ */ jsx(Suspense, {
|
|
71
90
|
fallback: null,
|
|
72
|
-
children
|
|
91
|
+
children
|
|
73
92
|
})
|
|
74
93
|
})
|
|
75
94
|
});
|
|
76
|
-
return
|
|
77
|
-
world:
|
|
78
|
-
children:
|
|
79
|
-
}) :
|
|
95
|
+
return resolvedWorld !== outerWorld ? /* @__PURE__ */ jsx(WorldProvider, {
|
|
96
|
+
world: resolvedWorld,
|
|
97
|
+
children: content
|
|
98
|
+
}) : content;
|
|
80
99
|
}
|
|
81
|
-
function
|
|
82
|
-
return
|
|
100
|
+
function useIsKolmoCustomGravity() {
|
|
101
|
+
return useContext(KolmoGravityContext);
|
|
83
102
|
}
|
|
84
|
-
export {
|
|
103
|
+
export { KolmoGravityContext, KolmoPhysics, useIsKolmoCustomGravity, useOptionalKootaWorld };
|
|
104
|
+
|
|
105
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/physics/index.tsx"],"sourcesContent":["import React, { Suspense, createContext, useContext, useLayoutEffect, useMemo, type ReactNode, type RefObject } from \"react\";\nimport * as THREE from \"three\";\nimport { PhysicsWorld, type PhysicsWorldProps } from \"@khr3/core\";\nimport { useCustomGravity } from \"@pinkaphant/ecctrl/gravity\";\nimport { type World } from \"koota\";\nimport { WorldProvider, useWorld } from \"koota/react\";\nimport { kolmoWorld } from \"../engine/kolmoTraits.js\";\n\nexport type KolmoTimeControlValue = number | RefObject<number>;\n\nexport type KolmoPointGravity = {\n readonly kind: \"point\";\n readonly center: readonly [number, number, number];\n readonly surfaceG: number;\n readonly radius: number;\n};\n\nexport type KolmoGravityCallback = (pos: THREE.Vector3, out: THREE.Vector3) => THREE.Vector3;\n\nexport type KolmoGravitySpec =\n | \"planar\"\n | \"zero\"\n | \"custom\"\n | readonly [number, number, number]\n | KolmoPointGravity\n | KolmoGravityCallback;\n\nexport const KolmoGravityContext = createContext<boolean>(false);\n\nexport function useOptionalKootaWorld(): World | null {\n try {\n return useWorld();\n }\n catch {\n return null;\n }\n}\n\nfunction isGravityTuple(g: KolmoGravitySpec): g is readonly [number, number, number] {\n return Array.isArray(g);\n}\n\nfunction isPointGravity(g: KolmoGravitySpec): g is KolmoPointGravity {\n return typeof g === \"object\" && !Array.isArray(g) && \"kind\" in g && g.kind === \"point\";\n}\n\nconst _gravTmp = new THREE.Vector3();\n\nexport interface KolmoPhysicsProps extends Omit<PhysicsWorldProps, \"gravity\" | \"debug\" | \"timeScale\" | \"maxDelta\" | \"children\"> {\n readonly gravity?: KolmoGravitySpec;\n readonly paused?: boolean;\n readonly timeScale?: KolmoTimeControlValue;\n readonly maxDelta?: KolmoTimeControlValue;\n readonly physicsDebug?: boolean;\n readonly world?: World | null;\n readonly children: ReactNode;\n}\n\nexport function KolmoPhysics({\n gravity = \"planar\",\n paused = false,\n timeScale = 1,\n maxDelta,\n physicsDebug = false,\n world = null,\n children,\n ...physicsProps\n}: KolmoPhysicsProps): React.JSX.Element {\n const outerWorld = useOptionalKootaWorld();\n const resolvedWorld = world ?? outerWorld ?? kolmoWorld;\n const isCallback = typeof gravity === \"function\";\n const isTuple = isGravityTuple(gravity);\n const isCustomLiteral = gravity === \"custom\";\n const isPoint = isPointGravity(gravity);\n const isCustomGravity = isCallback || isPoint || isCustomLiteral;\n\n const gx = isTuple ? gravity[0] : 0;\n const gy = isTuple ? gravity[1] : -9.81;\n const gz = isTuple ? gravity[2] : 0;\n const cx = isPoint ? gravity.center[0] : 0;\n const cy = isPoint ? gravity.center[1] : 0;\n const cz = isPoint ? gravity.center[2] : 0;\n const surfaceG = isPoint ? gravity.surfaceG : gravity === \"zero\" ? 0 : 9.81;\n const gravityFn = isCallback ? gravity : null;\n\n const rapierGravity = useMemo<[number, number, number]>(\n () => (isTuple ? [gx, gy, gz] : isCustomGravity || gravity === \"zero\" ? [0, 0, 0] : [0, -9.81, 0]),\n [isTuple, gx, gy, gz, isCustomGravity, gravity === \"zero\"],\n );\n\n useLayoutEffect(() => {\n if (isCustomLiteral || (!isCallback && !isPoint))\n return;\n const setField = useCustomGravity.getState().setGravityField;\n if (gravityFn) {\n setField((pos) => gravityFn(pos, _gravTmp));\n }\n else if (isPoint) {\n setField((pos) => {\n _gravTmp.set(pos.x - cx, pos.y - cy, pos.z - cz);\n const lenSq = _gravTmp.lengthSq();\n return lenSq < 1e-8 ? _gravTmp.set(0, -surfaceG, 0) : _gravTmp.multiplyScalar(-surfaceG / Math.sqrt(lenSq));\n });\n }\n }, [isCustomLiteral, isCallback, isPoint, gravityFn, cx, cy, cz, surfaceG]);\n\n const content = (\n <KolmoGravityContext.Provider value={isCustomGravity}>\n <PhysicsWorld\n {...physicsProps}\n paused={paused}\n timeScale={timeScale}\n {...(maxDelta === undefined ? {} : { maxDelta })}\n gravity={rapierGravity}\n debug={physicsDebug}\n >\n <Suspense fallback={null}>{children}</Suspense>\n </PhysicsWorld>\n </KolmoGravityContext.Provider>\n );\n\n return resolvedWorld !== outerWorld ? <WorldProvider world={resolvedWorld}>{content}</WorldProvider> : content;\n}\n\nexport function useIsKolmoCustomGravity(): boolean {\n return useContext(KolmoGravityContext);\n}\n"],"mappings":";;;;;;;;;AA2BA,IAAa,sBAAsB,cAAuB,KAAK;AAE/D,SAAgB,wBAAsC;CAClD,IAAI;EACA,OAAO,SAAS;CACpB,QACM;EACF,OAAO;CACX;AACJ;AAEA,SAAS,eAAe,GAA6D;CACjF,OAAO,MAAM,QAAQ,CAAC;AAC1B;AAEA,SAAS,eAAe,GAA6C;CACjE,OAAO,OAAO,MAAM,YAAY,CAAC,MAAM,QAAQ,CAAC,KAAK,UAAU,KAAK,EAAE,SAAS;AACnF;AAEA,IAAM,WAAW,IAAI,MAAM,QAAQ;AAYnC,SAAgB,aAAa,EACzB,UAAU,UACV,SAAS,OACT,YAAY,GACZ,UACA,eAAe,OACf,QAAQ,MACR,UACA,GAAG,gBACkC;CACrC,MAAM,aAAa,sBAAsB;CACzC,MAAM,gBAAgB,SAAS,cAAc;CAC7C,MAAM,aAAa,OAAO,YAAY;CACtC,MAAM,UAAU,eAAe,OAAO;CACtC,MAAM,kBAAkB,YAAY;CACpC,MAAM,UAAU,eAAe,OAAO;CACtC,MAAM,kBAAkB,cAAc,WAAW;CAEjD,MAAM,KAAK,UAAU,QAAQ,KAAK;CAClC,MAAM,KAAK,UAAU,QAAQ,KAAK;CAClC,MAAM,KAAK,UAAU,QAAQ,KAAK;CAClC,MAAM,KAAK,UAAU,QAAQ,OAAO,KAAK;CACzC,MAAM,KAAK,UAAU,QAAQ,OAAO,KAAK;CACzC,MAAM,KAAK,UAAU,QAAQ,OAAO,KAAK;CACzC,MAAM,WAAW,UAAU,QAAQ,WAAW,YAAY,SAAS,IAAI;CACvE,MAAM,YAAY,aAAa,UAAU;CAEzC,MAAM,gBAAgB,cACX,UAAU;EAAC;EAAI;EAAI;CAAE,IAAI,mBAAmB,YAAY,SAAS;EAAC;EAAG;EAAG;CAAC,IAAI;EAAC;EAAG;EAAO;CAAC,GAChG;EAAC;EAAS;EAAI;EAAI;EAAI;EAAiB,YAAY;CAAM,CAC7D;CAEA,sBAAsB;EAClB,IAAI,mBAAoB,CAAC,cAAc,CAAC,SACpC;EACJ,MAAM,WAAW,iBAAiB,SAAS,CAAC,CAAC;EAC7C,IAAI,WACA,UAAU,QAAQ,UAAU,KAAK,QAAQ,CAAC;OAEzC,IAAI,SACL,UAAU,QAAQ;GACd,SAAS,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,EAAE;GAC/C,MAAM,QAAQ,SAAS,SAAS;GAChC,OAAO,QAAQ,OAAO,SAAS,IAAI,GAAG,CAAC,UAAU,CAAC,IAAI,SAAS,eAAe,CAAC,WAAW,KAAK,KAAK,KAAK,CAAC;EAC9G,CAAC;CAET,GAAG;EAAC;EAAiB;EAAY;EAAS;EAAW;EAAI;EAAI;EAAI;CAAQ,CAAC;CAE1E,MAAM,UACF,oBAAC,oBAAoB,UAArB;EAA8B,OAAO;EACjC,UAAA,oBAAC,cAAD;GACI,GAAI;GACI;GACG;GACX,GAAK,aAAa,KAAA,IAAY,CAAC,IAAI,EAAE,SAAS;GAC9C,SAAS;GACT,OAAO;GAEP,UAAA,oBAAC,UAAD;IAAU,UAAU;IAAO;GAAmB,CAAA;EACpC,CAAA;CACY,CAAA;CAGlC,OAAO,kBAAkB,aAAa,oBAAC,eAAD;EAAe,OAAO;EAAgB,UAAA;CAAuB,CAAA,IAAI;AAC3G;AAEA,SAAgB,0BAAmC;CAC/C,OAAO,WAAW,mBAAmB;AACzC"}
|
|
@@ -1,70 +1,9 @@
|
|
|
1
1
|
import * as THREE from "three";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
export type KolmoSocketRole = "seat" | "exit" | "grip_primary" | "grip_secondary" | "optic" | "muzzle" | "eject" | "hinge" | "mount" | "contact";
|
|
6
|
-
export interface KolmoNodeExtension {
|
|
7
|
-
kind?: KolmoEmitterKind;
|
|
8
|
-
drive?: KolmoDriveChannel;
|
|
9
|
-
color?: [number, number, number];
|
|
10
|
-
size?: number;
|
|
11
|
-
socket?: KolmoSocketRole;
|
|
12
|
-
}
|
|
13
|
-
export interface DecodedKolmoEmitter {
|
|
14
|
-
nodeName: string;
|
|
15
|
-
object: THREE.Object3D;
|
|
16
|
-
localPosition: [number, number, number];
|
|
17
|
-
localQuaternion: [number, number, number, number];
|
|
18
|
-
kind: KolmoEmitterKind;
|
|
19
|
-
drive: KolmoDriveChannel;
|
|
20
|
-
color: [number, number, number];
|
|
21
|
-
size: number;
|
|
22
|
-
}
|
|
23
|
-
export interface DecodedKolmoSocket {
|
|
24
|
-
nodeName: string;
|
|
25
|
-
role: KolmoSocketRole;
|
|
26
|
-
localPosition: [number, number, number];
|
|
27
|
-
localQuaternion: [number, number, number, number];
|
|
28
|
-
}
|
|
29
|
-
export interface KolmoRigMetadata {
|
|
30
|
-
emitters: DecodedKolmoEmitter[];
|
|
31
|
-
sockets: DecodedKolmoSocket[];
|
|
32
|
-
}
|
|
33
|
-
export interface KolmoSignalState {
|
|
34
|
-
throttle: number;
|
|
35
|
-
boost: number;
|
|
36
|
-
brake: number;
|
|
37
|
-
slip: number;
|
|
38
|
-
reverse: number;
|
|
39
|
-
turn_l: number;
|
|
40
|
-
turn_r: number;
|
|
41
|
-
headlight: number;
|
|
42
|
-
fire: number;
|
|
43
|
-
damage: number;
|
|
44
|
-
always: number;
|
|
45
|
-
}
|
|
46
|
-
export declare function createDefaultSignals(): KolmoSignalState;
|
|
47
|
-
export declare function inferKolmoSocketRole(nodeName: string, explicitRole?: KolmoSocketRole): KolmoSocketRole;
|
|
2
|
+
import { stampKolmoNodesIntoGlb } from "./kolmoStamp.js";
|
|
3
|
+
import { KOLMO_EXTENSION_NAME, createDefaultSignals, inferKolmoSocketRole, type DecodedKolmoEmitter, type DecodedKolmoSocket, type KolmoAuthoredNodePatch, type KolmoDriveChannel, type KolmoEmitterKind, type KolmoNodeExtension, type KolmoRigMetadata, type KolmoSignalState, type KolmoSocketRole } from "./kolmoTypes.js";
|
|
4
|
+
export { KOLMO_EXTENSION_NAME, createDefaultSignals, inferKolmoSocketRole, stampKolmoNodesIntoGlb, type DecodedKolmoEmitter, type DecodedKolmoSocket, type KolmoAuthoredNodePatch, type KolmoDriveChannel, type KolmoEmitterKind, type KolmoNodeExtension, type KolmoRigMetadata, type KolmoSignalState, type KolmoSocketRole, };
|
|
48
5
|
/**
|
|
49
6
|
* Extracts `KOLMO_emitter` directional VFX emitters (-Z nozzle convention) and sockets
|
|
50
7
|
* from raw `.glb` JSON + live `THREE.Group` scene graph (or cloned `userData.kolmoExtension`).
|
|
51
8
|
*/
|
|
52
9
|
export declare function decodeKolmoRig(scene: THREE.Group, glbBytes?: ArrayBuffer | Uint8Array): KolmoRigMetadata;
|
|
53
|
-
export interface KolmoAuthoredNodePatch {
|
|
54
|
-
nodeName: string;
|
|
55
|
-
translation: [number, number, number];
|
|
56
|
-
rotation?: [number, number, number, number];
|
|
57
|
-
extension: KolmoNodeExtension;
|
|
58
|
-
spotLight?: {
|
|
59
|
-
color: [number, number, number];
|
|
60
|
-
intensity: number;
|
|
61
|
-
range?: number;
|
|
62
|
-
innerConeAngle?: number;
|
|
63
|
-
outerConeAngle?: number;
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Stamps `KOLMO_emitter` nodes and optional official `KHR_lights_punctual` spotlights
|
|
68
|
-
* directly into a `.glb` binary's JSON chunk (`extensionsUsed`, never `extensionsRequired`).
|
|
69
|
-
*/
|
|
70
|
-
export declare function stampKolmoNodesIntoGlb(glbBytes: Uint8Array, patches: readonly KolmoAuthoredNodePatch[], extraSceneTune?: Record<string, unknown>): Uint8Array;
|