@pinkaphant/kolmo 0.4.2 → 0.4.5
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/README.md +60 -6
- package/bin/kolmo.mjs +455 -15
- package/dist/engine/index.d.ts +3 -0
- package/dist/engine/index.js +8 -5
- package/dist/engine/kolmoActions.js +24 -9
- package/dist/engine/kolmoActions.js.map +1 -1
- package/dist/engine/kolmoActor.js +19 -31
- package/dist/engine/kolmoActor.js.map +1 -1
- package/dist/engine/kolmoActorHelpers.d.ts +24 -0
- package/dist/engine/kolmoActorHelpers.js +64 -0
- package/dist/engine/kolmoActorHelpers.js.map +1 -0
- package/dist/engine/kolmoGame.js +4 -1
- package/dist/engine/kolmoGame.js.map +1 -1
- package/dist/engine/kolmoHud.js +34 -15
- package/dist/engine/kolmoHud.js.map +1 -1
- package/dist/engine/kolmoInput.d.ts +3 -1
- package/dist/engine/kolmoInput.js +18 -12
- package/dist/engine/kolmoInput.js.map +1 -1
- package/dist/engine/kolmoLongDrive.d.ts +1 -1
- package/dist/engine/kolmoLongDrive.js +10 -8
- package/dist/engine/kolmoLongDrive.js.map +1 -1
- package/dist/engine/kolmoPilotMesh.js +189 -48
- package/dist/engine/kolmoPilotMesh.js.map +1 -1
- package/dist/engine/kolmoStore.js +4 -0
- package/dist/engine/kolmoStore.js.map +1 -0
- package/dist/engine/kolmoTouchOverlay.d.ts +21 -0
- package/dist/engine/kolmoTouchOverlay.js +326 -0
- package/dist/engine/kolmoTouchOverlay.js.map +1 -0
- package/dist/engine/kolmoTouchState.d.ts +50 -0
- package/dist/engine/kolmoTouchState.js +210 -0
- package/dist/engine/kolmoTouchState.js.map +1 -0
- package/dist/engine/kolmoVehicle.js +30 -27
- package/dist/engine/kolmoVehicle.js.map +1 -1
- package/dist/engine/kolmoVehicleAutoCompile.d.ts +10 -0
- package/dist/engine/kolmoVehicleAutoCompile.js +78 -0
- package/dist/engine/kolmoVehicleAutoCompile.js.map +1 -0
- package/dist/engine/kolmoVehicleConfig.d.ts +2 -0
- package/dist/engine/kolmoVehicleConfig.js +8 -4
- package/dist/engine/kolmoVehicleConfig.js.map +1 -1
- package/dist/engine/kolmoVehicleDriver.d.ts +5 -0
- package/dist/engine/kolmoVehicleDriver.js +18 -11
- package/dist/engine/kolmoVehicleDriver.js.map +1 -1
- package/dist/engine/kolmoVehicleInner.js +49 -19
- package/dist/engine/kolmoVehicleInner.js.map +1 -1
- package/dist/engine/kolmoWorld.js +6 -2
- package/dist/engine/kolmoWorld.js.map +1 -1
- package/dist/engine/longDriveKit.d.ts +6 -1
- package/dist/engine/longDriveKit.js +8 -5
- package/dist/engine/longDriveKit.js.map +1 -1
- package/dist/engine/macroCellBuilder.d.ts +10 -0
- package/dist/engine/macroCellBuilder.js +101 -18
- package/dist/engine/macroCellBuilder.js.map +1 -1
- package/dist/engine/mainlandMacroCell.js +18 -9
- package/dist/engine/mainlandMacroCell.js.map +1 -1
- package/dist/importer/DomainWorkshopPanel.d.ts +3 -3
- package/dist/importer/DomainWorkshopPanel.js +148 -44
- package/dist/importer/DomainWorkshopPanel.js.map +1 -1
- package/dist/importer/GateHudBar.d.ts +2 -0
- package/dist/importer/GateHudBar.js +113 -35
- package/dist/importer/GateHudBar.js.map +1 -1
- package/dist/importer/GlbImportGate.js +16 -3
- package/dist/importer/GlbImportGate.js.map +1 -1
- package/dist/importer/LiveDrivePads.js +5 -3
- package/dist/importer/LiveDrivePads.js.map +1 -1
- package/dist/importer/Step1CalibrationPlinth.js +3 -3
- package/dist/importer/WheelRingHandles3D.js +2 -1
- package/dist/importer/WheelRingHandles3D.js.map +1 -1
- package/dist/importer/chopShopActions.js +22 -18
- package/dist/importer/chopShopActions.js.map +1 -1
- package/dist/importer/chopShopHandlers.js +17 -10
- package/dist/importer/chopShopHandlers.js.map +1 -1
- package/dist/importer/chopShopIoActions.d.ts +2 -0
- package/dist/importer/chopShopIoActions.js +33 -2
- package/dist/importer/chopShopIoActions.js.map +1 -1
- package/dist/importer/cylinderBooleanSlice.js.map +1 -1
- package/dist/importer/fusedWheelDetect.d.ts +2 -2
- package/dist/importer/fusedWheelDetect.js +227 -106
- package/dist/importer/fusedWheelDetect.js.map +1 -1
- package/dist/importer/fusedWheelFit.d.ts +6 -0
- package/dist/importer/fusedWheelFit.js +82 -1
- package/dist/importer/fusedWheelFit.js.map +1 -1
- package/dist/importer/gateStore.d.ts +2 -2
- package/dist/importer/gateStore.js +4 -3
- package/dist/importer/gateStore.js.map +1 -1
- package/dist/importer/glbNormalizer.js +5 -0
- package/dist/importer/glbNormalizer.js.map +1 -1
- package/dist/importer/importerWebMcpTools.js +3 -2
- package/dist/importer/importerWebMcpTools.js.map +1 -1
- package/dist/importer/index.d.ts +4 -2
- package/dist/importer/index.js +16 -12
- package/dist/importer/khrCarGeometryMass.d.ts +20 -0
- package/dist/importer/khrCarGeometryMass.js +125 -0
- package/dist/importer/khrCarGeometryMass.js.map +1 -0
- package/dist/importer/khrCarPlanHelpers.js +13 -23
- package/dist/importer/khrCarPlanHelpers.js.map +1 -1
- package/dist/importer/khrCarPlanner.js +52 -85
- package/dist/importer/khrCarPlanner.js.map +1 -1
- package/dist/importer/khrCompiler.js +1 -1
- package/dist/importer/launcherBake.js +4 -2
- package/dist/importer/launcherBake.js.map +1 -1
- package/dist/importer/launcherCadGeometry.d.ts +22 -0
- package/dist/importer/launcherCadGeometry.js +185 -0
- package/dist/importer/launcherCadGeometry.js.map +1 -0
- package/dist/importer/proceduralC12AndCraft.d.ts +18 -0
- package/dist/importer/proceduralC12AndCraft.js +302 -0
- package/dist/importer/proceduralC12AndCraft.js.map +1 -0
- package/dist/importer/proceduralDomainBuilders.d.ts +10 -0
- package/dist/importer/proceduralDomainBuilders.js +346 -0
- package/dist/importer/proceduralDomainBuilders.js.map +1 -0
- package/dist/importer/proceduralPersonAndProp.d.ts +8 -0
- package/dist/importer/proceduralPersonAndProp.js +303 -0
- package/dist/importer/proceduralPersonAndProp.js.map +1 -0
- package/dist/importer/starterScene.d.ts +3 -1
- package/dist/importer/starterScene.js +76 -13
- package/dist/importer/starterScene.js.map +1 -1
- package/dist/importer/universalGateBake.js +43 -11
- package/dist/importer/universalGateBake.js.map +1 -1
- package/dist/importer/useChopShopController.d.ts +3 -1
- package/dist/importer/useChopShopController.js +33 -18
- package/dist/importer/useChopShopController.js.map +1 -1
- package/dist/importer/useChopShopState.d.ts +1 -1
- package/dist/importer/useChopShopState.js +35 -9
- package/dist/importer/useChopShopState.js.map +1 -1
- package/dist/importer/wheelCutterHelpers.d.ts +7 -4
- package/dist/importer/wheelCutterHelpers.js +58 -28
- package/dist/importer/wheelCutterHelpers.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +34 -20
- package/dist/junk/DestructibleTarget.js +9 -3
- package/dist/junk/DestructibleTarget.js.map +1 -1
- package/dist/junk/ShardPieces.js +10 -2
- package/dist/junk/ShardPieces.js.map +1 -1
- package/dist/junk/index.d.ts +1 -0
- package/dist/junk/index.js +2 -1
- package/dist/junk/junkProceduralScenes.d.ts +12 -0
- package/dist/junk/junkProceduralScenes.js +220 -0
- package/dist/junk/junkProceduralScenes.js.map +1 -0
- package/dist/junk/junkTypes.js +0 -0
- package/dist/junk/junkTypes.js.map +1 -0
- package/dist/sand3d/KolmoSand3D.d.ts +19 -0
- package/dist/sand3d/KolmoSand3D.js +92 -0
- package/dist/sand3d/KolmoSand3D.js.map +1 -0
- package/dist/sand3d/Sand3dWorkshopSection.d.ts +8 -0
- package/dist/sand3d/Sand3dWorkshopSection.js +117 -0
- package/dist/sand3d/Sand3dWorkshopSection.js.map +1 -0
- package/dist/sand3d/gateBakeHelpers.d.ts +21 -0
- package/dist/sand3d/gateBakeHelpers.js +225 -0
- package/dist/sand3d/gateBakeHelpers.js.map +1 -0
- package/dist/sand3d/gateDoorwayBake.d.ts +12 -0
- package/dist/sand3d/gateDoorwayBake.js +203 -0
- package/dist/sand3d/gateDoorwayBake.js.map +1 -0
- package/dist/sand3d/index.d.ts +3 -0
- package/dist/sand3d/index.js +4 -0
- package/dist/sand3d/index.js.map +1 -0
- package/dist/sand3d/sand3dAssetLoader.d.ts +28 -0
- package/dist/sand3d/sand3dAssetLoader.js +177 -0
- package/dist/sand3d/sand3dAssetLoader.js.map +1 -0
- package/dist/suika/KolmoSuikaOrb.d.ts +33 -0
- package/dist/suika/KolmoSuikaOrb.js +375 -0
- package/dist/suika/KolmoSuikaOrb.js.map +1 -0
- package/dist/suika/index.d.ts +4 -0
- package/dist/suika/index.js +5 -0
- package/dist/suika/index.js.map +1 -0
- package/dist/suika/suikaArbiter.d.ts +60 -0
- package/dist/suika/suikaArbiter.js +265 -0
- package/dist/suika/suikaArbiter.js.map +1 -0
- package/dist/suika/suikaGeometry.d.ts +10 -0
- package/dist/suika/suikaGeometry.js +251 -0
- package/dist/suika/suikaGeometry.js.map +1 -0
- package/dist/suika/suikaTypes.d.ts +74 -0
- package/dist/suika/suikaTypes.js +196 -0
- package/dist/suika/suikaTypes.js.map +1 -0
- package/dist/world/index.d.ts +1 -1
- package/dist/world/index.js +2 -2
- package/dist/world/worldTypes.d.ts +4 -0
- package/dist/world/worldTypes.js +21 -1
- package/dist/world/worldTypes.js.map +1 -1
- package/docs/api-reference.md +82 -124
- package/package.json +16 -7
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/sand3d/index.ts"],"mappings":""}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as THREE from "three";
|
|
2
|
+
import { type KhrAssetBundle } from "@khr3/core";
|
|
3
|
+
import { SAND3D_RECIPES, SAND3D_RECIPE_MAP, buildSand3dRecipe, compileSand3dAssembly, exportSand3dGlb, isSand3dFileName, loadSand3dBundle, parseSand3dSource, s3d, type CompiledSand3dAssembly, type Sand3dAssembly, type Sand3dRecipe, type Sand3dRecipeId } from "@khr3/core/sand3d";
|
|
4
|
+
import { type KolmoAuthoredNodePatch } from "../schema/kolmoSchema.js";
|
|
5
|
+
export { SAND3D_RECIPES, SAND3D_RECIPE_MAP, buildSand3dRecipe, compileSand3dAssembly, exportSand3dGlb, isSand3dFileName, loadSand3dBundle, parseSand3dSource, s3d, type CompiledSand3dAssembly, type Sand3dAssembly, type Sand3dRecipe, type Sand3dRecipeId, };
|
|
6
|
+
export interface IngestedSand3dAsset {
|
|
7
|
+
readonly name: string;
|
|
8
|
+
readonly format: "sand3d" | "usd" | "glb";
|
|
9
|
+
readonly glbBytes: Uint8Array;
|
|
10
|
+
readonly bundle: KhrAssetBundle;
|
|
11
|
+
readonly worldKind: "vehicle" | "prop";
|
|
12
|
+
}
|
|
13
|
+
export declare function isSupportedCadImportFileName(fileName: string): boolean;
|
|
14
|
+
export declare function detectSand3dBytes(bytes: ArrayBuffer | Uint8Array, fileName?: string): boolean;
|
|
15
|
+
export declare function findSand3dRecipe(idOrSlug: string): Sand3dRecipe | undefined;
|
|
16
|
+
export declare function resolveSand3dAssembly(programOrRecipe: string | Sand3dAssembly): Sand3dAssembly;
|
|
17
|
+
export declare function measureNaturalSceneSpanM(scene: THREE.Object3D): {
|
|
18
|
+
maxSpanM: number;
|
|
19
|
+
lengthZM: number;
|
|
20
|
+
size: [number, number, number];
|
|
21
|
+
};
|
|
22
|
+
export declare function exportCompiledSand3dWithKolmo(compiled: CompiledSand3dAssembly, patches?: readonly KolmoAuthoredNodePatch[]): Promise<{
|
|
23
|
+
glbBytes: Uint8Array;
|
|
24
|
+
bundle: KhrAssetBundle;
|
|
25
|
+
worldKind: "vehicle" | "prop";
|
|
26
|
+
}>;
|
|
27
|
+
export declare function compileSand3dRecipeGlb(programOrRecipe: string | Sand3dAssembly): Promise<IngestedSand3dAsset>;
|
|
28
|
+
export declare function ingestSand3dOrGlb(input: File | Blob | ArrayBuffer | Uint8Array | string, fileNameHint?: string): Promise<IngestedSand3dAsset>;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { loadOrAutoCompileVehicleGlb } from "../engine/kolmoVehicleAutoCompile.js";
|
|
2
|
+
import { convertUsdToGlb, isUsdFileName } from "../importer/usdToGlb.js";
|
|
3
|
+
import { stampKolmoNodesIntoGlb } from "../schema/kolmoStamp.js";
|
|
4
|
+
import * as THREE from "three";
|
|
5
|
+
import { exportKhrGlb, loadKhrGlb } from "@khr3/core";
|
|
6
|
+
import { SAND3D_RECIPES, SAND3D_RECIPE_MAP, buildSand3dRecipe, compileSand3dAssembly, exportSand3dGlb, isSand3dFileName, loadSand3dBundle, parseSand3dSource, s3d } from "@khr3/core/sand3d";
|
|
7
|
+
// src/sand3d/sand3dAssetLoader.ts
|
|
8
|
+
var GLTF_MAGIC = 1179937895;
|
|
9
|
+
var ZIP_MAGIC = 67324752;
|
|
10
|
+
function isSupportedCadImportFileName(fileName) {
|
|
11
|
+
const lower = fileName.trim().toLowerCase();
|
|
12
|
+
if (isUsdFileName(lower) || isSand3dFileName(lower)) return true;
|
|
13
|
+
return /\.(?:glb|gltf|py|json)$/.test(lower);
|
|
14
|
+
}
|
|
15
|
+
function detectSand3dBytes(bytes, fileName) {
|
|
16
|
+
const cleanName = (fileName ?? "").trim().toLowerCase();
|
|
17
|
+
if (cleanName.endsWith(".glb") || isUsdFileName(cleanName)) return false;
|
|
18
|
+
if (cleanName && (cleanName.endsWith(".sand3d") || cleanName.endsWith(".s3d") || cleanName.endsWith(".py"))) return true;
|
|
19
|
+
const u8 = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);
|
|
20
|
+
if (u8.byteLength >= 4) {
|
|
21
|
+
const magic = new DataView(u8.buffer, u8.byteOffset, u8.byteLength).getUint32(0, true);
|
|
22
|
+
if (magic === GLTF_MAGIC || magic === ZIP_MAGIC) return false;
|
|
23
|
+
}
|
|
24
|
+
if (u8.byteLength >= 8) {
|
|
25
|
+
if (new TextDecoder().decode(u8.subarray(0, 8)) === "PXR-USDC") return false;
|
|
26
|
+
}
|
|
27
|
+
const sample = new TextDecoder().decode(u8.subarray(0, Math.min(u8.byteLength, 2048))).trim();
|
|
28
|
+
if (!sample) return false;
|
|
29
|
+
if (cleanName.endsWith(".gltf") || sample.startsWith("{") && /"asset"\s*:\s*\{[\s\S]*?"version"\s*:\s*"2\./.test(sample)) return false;
|
|
30
|
+
if (isSand3dFileName(cleanName)) return true;
|
|
31
|
+
return sample.includes("import sand3d") || /\bs3d\s*\./.test(sample) || /"kind"\s*:\s*"assembly"/.test(sample) || /"units"\s*:/.test(sample) && /"parts"\s*:/.test(sample);
|
|
32
|
+
}
|
|
33
|
+
function findSand3dRecipe(idOrSlug) {
|
|
34
|
+
const clean = idOrSlug.trim().toLowerCase();
|
|
35
|
+
return SAND3D_RECIPES.find((r) => r.id === clean || r.label.toLowerCase().replace(/\s+/g, "_") === clean);
|
|
36
|
+
}
|
|
37
|
+
function resolveSand3dAssembly(programOrRecipe) {
|
|
38
|
+
if (typeof programOrRecipe !== "string") return programOrRecipe;
|
|
39
|
+
const recipe = findSand3dRecipe(programOrRecipe);
|
|
40
|
+
if (recipe) return recipe.build();
|
|
41
|
+
return parseSand3dSource(programOrRecipe);
|
|
42
|
+
}
|
|
43
|
+
function measureNaturalSceneSpanM(scene) {
|
|
44
|
+
scene.updateMatrixWorld(true);
|
|
45
|
+
const box = new THREE.Box3().setFromObject(scene);
|
|
46
|
+
if (box.isEmpty()) return {
|
|
47
|
+
maxSpanM: 1,
|
|
48
|
+
lengthZM: 1,
|
|
49
|
+
size: [
|
|
50
|
+
1,
|
|
51
|
+
1,
|
|
52
|
+
1
|
|
53
|
+
]
|
|
54
|
+
};
|
|
55
|
+
const sz = box.getSize(new THREE.Vector3());
|
|
56
|
+
return {
|
|
57
|
+
maxSpanM: Math.max(.008, sz.x, sz.y, sz.z),
|
|
58
|
+
lengthZM: Math.max(.008, sz.z),
|
|
59
|
+
size: [
|
|
60
|
+
sz.x,
|
|
61
|
+
sz.y,
|
|
62
|
+
sz.z
|
|
63
|
+
]
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
async function exportCompiledSand3dWithKolmo(compiled, patches = []) {
|
|
67
|
+
const rawBuf = await exportKhrGlb(compiled.scene, compiled.specs, {
|
|
68
|
+
gateDomain: "sand3d",
|
|
69
|
+
...compiled.sceneExtras
|
|
70
|
+
});
|
|
71
|
+
const autoPatches = [];
|
|
72
|
+
for (const thr of compiled.assembly.thrusters) {
|
|
73
|
+
const obj = compiled.scene.getObjectByName(thr.name);
|
|
74
|
+
if (obj) {
|
|
75
|
+
const wp = obj.getWorldPosition(new THREE.Vector3());
|
|
76
|
+
autoPatches.push({
|
|
77
|
+
nodeName: `Kolmo_Plume_${thr.name}`,
|
|
78
|
+
translation: [
|
|
79
|
+
Number(wp.x.toFixed(4)),
|
|
80
|
+
Number(wp.y.toFixed(4)),
|
|
81
|
+
Number(wp.z.toFixed(4))
|
|
82
|
+
],
|
|
83
|
+
extension: {
|
|
84
|
+
kind: "plume",
|
|
85
|
+
drive: "throttle",
|
|
86
|
+
size: .9
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const merged = stampKolmoNodesIntoGlb(new Uint8Array(rawBuf), [...autoPatches, ...patches], void 0, { preserveExistingNodes: true });
|
|
92
|
+
const glbBytes = new Uint8Array(merged);
|
|
93
|
+
const bundle = await loadKhrGlb(glbBytes.buffer.slice(glbBytes.byteOffset, glbBytes.byteOffset + glbBytes.byteLength));
|
|
94
|
+
return {
|
|
95
|
+
glbBytes,
|
|
96
|
+
bundle,
|
|
97
|
+
worldKind: bundle.wheels.length > 0 || bundle.propellers.length > 0 ? "vehicle" : "prop"
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
async function compileSand3dRecipeGlb(programOrRecipe) {
|
|
101
|
+
const asm = resolveSand3dAssembly(programOrRecipe);
|
|
102
|
+
const { glbBytes, bundle, worldKind } = await exportCompiledSand3dWithKolmo(compileSand3dAssembly(asm));
|
|
103
|
+
return {
|
|
104
|
+
name: asm.name || "sand3d_asset",
|
|
105
|
+
format: "sand3d",
|
|
106
|
+
glbBytes,
|
|
107
|
+
bundle,
|
|
108
|
+
worldKind
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
async function ingestSand3dOrGlb(input, fileNameHint) {
|
|
112
|
+
if (typeof input === "string") {
|
|
113
|
+
const trimmed = input.trim();
|
|
114
|
+
if (/^(?:https?:\/\/|\/|\.\.?\/|blob:|data:)/i.test(trimmed)) {
|
|
115
|
+
const res = await fetch(trimmed);
|
|
116
|
+
if (!res.ok) throw new Error(`Asset fetch returned status ${res.status} for ${trimmed}`);
|
|
117
|
+
const urlName = trimmed.split("?")[0].split("/").pop() || "remote_asset.glb";
|
|
118
|
+
return ingestSand3dOrGlb(await res.arrayBuffer(), fileNameHint ?? urlName);
|
|
119
|
+
}
|
|
120
|
+
return compileSand3dRecipeGlb(trimmed);
|
|
121
|
+
}
|
|
122
|
+
if (!(input instanceof Uint8Array) && !(input instanceof ArrayBuffer)) {
|
|
123
|
+
const inferredName = "name" in input && typeof input.name === "string" ? input.name : "imported_asset.glb";
|
|
124
|
+
return ingestSand3dOrGlb(await input.arrayBuffer(), fileNameHint ?? inferredName);
|
|
125
|
+
}
|
|
126
|
+
const u8 = input instanceof Uint8Array ? input : new Uint8Array(input);
|
|
127
|
+
const rawName = (fileNameHint ?? "imported_asset").replace(/\.[^.]+$/, "") || "imported_asset";
|
|
128
|
+
if (fileNameHint && isUsdFileName(fileNameHint)) {
|
|
129
|
+
const ab = u8.buffer.slice(u8.byteOffset, u8.byteOffset + u8.byteLength);
|
|
130
|
+
const usd = await convertUsdToGlb(ab);
|
|
131
|
+
const glbBytes = new Uint8Array(usd.glb);
|
|
132
|
+
const bundle = await loadKhrGlb(usd.glb);
|
|
133
|
+
return {
|
|
134
|
+
name: rawName,
|
|
135
|
+
format: "usd",
|
|
136
|
+
glbBytes,
|
|
137
|
+
bundle,
|
|
138
|
+
worldKind: bundle.wheels.length > 0 || bundle.propellers.length > 0 ? "vehicle" : "prop"
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
if (detectSand3dBytes(u8, fileNameHint)) {
|
|
142
|
+
const source = new TextDecoder().decode(u8);
|
|
143
|
+
const asm = parseSand3dSource(source);
|
|
144
|
+
const { glbBytes, bundle, worldKind } = await exportCompiledSand3dWithKolmo(compileSand3dAssembly(asm));
|
|
145
|
+
return {
|
|
146
|
+
name: asm.name || rawName,
|
|
147
|
+
format: "sand3d",
|
|
148
|
+
glbBytes,
|
|
149
|
+
bundle,
|
|
150
|
+
worldKind
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
const copyBuf = u8.buffer.slice(u8.byteOffset, u8.byteOffset + u8.byteLength);
|
|
154
|
+
const initial = await loadKhrGlb(copyBuf);
|
|
155
|
+
if (initial.bodies.length > 0 || initial.wheels.length > 0 || initial.propellers.length > 0) {
|
|
156
|
+
const worldKind = initial.wheels.length > 0 || initial.propellers.length > 0 ? "vehicle" : "prop";
|
|
157
|
+
return {
|
|
158
|
+
name: rawName,
|
|
159
|
+
format: "glb",
|
|
160
|
+
glbBytes: new Uint8Array(copyBuf),
|
|
161
|
+
bundle: initial,
|
|
162
|
+
worldKind
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
const autoCompiled = await loadOrAutoCompileVehicleGlb(new Uint8Array(copyBuf));
|
|
166
|
+
const worldKind = autoCompiled.bundle.wheels.length > 0 || autoCompiled.bundle.propellers.length > 0 ? "vehicle" : "prop";
|
|
167
|
+
return {
|
|
168
|
+
name: rawName,
|
|
169
|
+
format: "glb",
|
|
170
|
+
glbBytes: new Uint8Array(autoCompiled.bytes),
|
|
171
|
+
bundle: autoCompiled.bundle,
|
|
172
|
+
worldKind
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
export { SAND3D_RECIPES, SAND3D_RECIPE_MAP, buildSand3dRecipe, compileSand3dAssembly, compileSand3dRecipeGlb, detectSand3dBytes, exportCompiledSand3dWithKolmo, exportSand3dGlb, findSand3dRecipe, ingestSand3dOrGlb, isSand3dFileName, isSupportedCadImportFileName, loadSand3dBundle, measureNaturalSceneSpanM, parseSand3dSource, resolveSand3dAssembly, s3d };
|
|
176
|
+
|
|
177
|
+
//# sourceMappingURL=sand3dAssetLoader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sand3dAssetLoader.js","names":[],"sources":["../../src/sand3d/sand3dAssetLoader.ts"],"sourcesContent":["import * as THREE from \"three\";\nimport { exportKhrGlb, loadKhrGlb, type KhrAssetBundle } from \"@khr3/core\";\nimport {\n SAND3D_RECIPES,\n SAND3D_RECIPE_MAP,\n buildSand3dRecipe,\n compileSand3dAssembly,\n exportSand3dGlb,\n isSand3dFileName,\n loadSand3dBundle,\n parseSand3dSource,\n s3d,\n type CompiledSand3dAssembly,\n type Sand3dAssembly,\n type Sand3dRecipe,\n type Sand3dRecipeId,\n} from \"@khr3/core/sand3d\";\nimport { loadOrAutoCompileVehicleGlb } from \"../engine/kolmoVehicleAutoCompile.js\";\nimport { convertUsdToGlb, isUsdFileName } from \"../importer/usdToGlb.js\";\nimport { stampKolmoNodesIntoGlb, type KolmoAuthoredNodePatch } from \"../schema/kolmoSchema.js\";\n\nexport {\n SAND3D_RECIPES,\n SAND3D_RECIPE_MAP,\n buildSand3dRecipe,\n compileSand3dAssembly,\n exportSand3dGlb,\n isSand3dFileName,\n loadSand3dBundle,\n parseSand3dSource,\n s3d,\n type CompiledSand3dAssembly,\n type Sand3dAssembly,\n type Sand3dRecipe,\n type Sand3dRecipeId,\n};\n\nexport interface IngestedSand3dAsset {\n readonly name: string;\n readonly format: \"sand3d\" | \"usd\" | \"glb\";\n readonly glbBytes: Uint8Array;\n readonly bundle: KhrAssetBundle;\n readonly worldKind: \"vehicle\" | \"prop\";\n}\n\nconst GLTF_MAGIC = 0x46546c67;\nconst ZIP_MAGIC = 0x04034b50;\n\nexport function isSupportedCadImportFileName(fileName: string): boolean {\n const lower = fileName.trim().toLowerCase();\n if (isUsdFileName(lower) || isSand3dFileName(lower)) return true;\n return /\\.(?:glb|gltf|py|json)$/.test(lower);\n}\n\nexport function detectSand3dBytes(bytes: ArrayBuffer | Uint8Array, fileName?: string): boolean {\n const cleanName = (fileName ?? \"\").trim().toLowerCase();\n if (cleanName.endsWith(\".glb\") || isUsdFileName(cleanName)) return false;\n if (cleanName && (cleanName.endsWith(\".sand3d\") || cleanName.endsWith(\".s3d\") || cleanName.endsWith(\".py\"))) {\n return true;\n }\n const u8 = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes);\n if (u8.byteLength >= 4) {\n const view = new DataView(u8.buffer, u8.byteOffset, u8.byteLength);\n const magic = view.getUint32(0, true);\n if (magic === GLTF_MAGIC || magic === ZIP_MAGIC) return false;\n }\n if (u8.byteLength >= 8) {\n const head8 = new TextDecoder().decode(u8.subarray(0, 8));\n if (head8 === \"PXR-USDC\") return false;\n }\n const sample = new TextDecoder().decode(u8.subarray(0, Math.min(u8.byteLength, 2048))).trim();\n if (!sample) return false;\n if (cleanName.endsWith(\".gltf\") || (sample.startsWith(\"{\") && /\"asset\"\\s*:\\s*\\{[\\s\\S]*?\"version\"\\s*:\\s*\"2\\./.test(sample))) {\n return false;\n }\n if (isSand3dFileName(cleanName)) return true;\n return (\n sample.includes(\"import sand3d\") ||\n /\\bs3d\\s*\\./.test(sample) ||\n /\"kind\"\\s*:\\s*\"assembly\"/.test(sample) ||\n (/\"units\"\\s*:/.test(sample) && /\"parts\"\\s*:/.test(sample))\n );\n}\n\nexport function findSand3dRecipe(idOrSlug: string): Sand3dRecipe | undefined {\n const clean = idOrSlug.trim().toLowerCase();\n return SAND3D_RECIPES.find((r) => r.id === clean || r.label.toLowerCase().replace(/\\s+/g, \"_\") === clean);\n}\n\nexport function resolveSand3dAssembly(programOrRecipe: string | Sand3dAssembly): Sand3dAssembly {\n if (typeof programOrRecipe !== \"string\") return programOrRecipe;\n const recipe = findSand3dRecipe(programOrRecipe);\n if (recipe) return recipe.build();\n return parseSand3dSource(programOrRecipe);\n}\n\nexport function measureNaturalSceneSpanM(scene: THREE.Object3D): {\n maxSpanM: number;\n lengthZM: number;\n size: [number, number, number];\n} {\n scene.updateMatrixWorld(true);\n const box = new THREE.Box3().setFromObject(scene);\n if (box.isEmpty()) return { maxSpanM: 1, lengthZM: 1, size: [1, 1, 1] };\n const sz = box.getSize(new THREE.Vector3());\n return {\n maxSpanM: Math.max(0.008, sz.x, sz.y, sz.z),\n lengthZM: Math.max(0.008, sz.z),\n size: [sz.x, sz.y, sz.z],\n };\n}\n\nexport async function exportCompiledSand3dWithKolmo(\n compiled: CompiledSand3dAssembly,\n patches: readonly KolmoAuthoredNodePatch[] = [],\n): Promise<{ glbBytes: Uint8Array; bundle: KhrAssetBundle; worldKind: \"vehicle\" | \"prop\" }> {\n const rawBuf = await exportKhrGlb(compiled.scene, compiled.specs, {\n gateDomain: \"sand3d\",\n ...compiled.sceneExtras,\n });\n const autoPatches: KolmoAuthoredNodePatch[] = [];\n for (const thr of compiled.assembly.thrusters) {\n const obj = compiled.scene.getObjectByName(thr.name);\n if (obj) {\n const wp = obj.getWorldPosition(new THREE.Vector3());\n autoPatches.push({\n nodeName: `Kolmo_Plume_${thr.name}`,\n translation: [Number(wp.x.toFixed(4)), Number(wp.y.toFixed(4)), Number(wp.z.toFixed(4))],\n extension: { kind: \"plume\", drive: \"throttle\", size: 0.9 },\n });\n }\n }\n const merged = stampKolmoNodesIntoGlb(new Uint8Array(rawBuf), [...autoPatches, ...patches], undefined, {\n preserveExistingNodes: true,\n });\n const glbBytes = new Uint8Array(merged);\n const bundle = await loadKhrGlb(glbBytes.buffer.slice(glbBytes.byteOffset, glbBytes.byteOffset + glbBytes.byteLength));\n const worldKind: \"vehicle\" | \"prop\" =\n bundle.wheels.length > 0 || bundle.propellers.length > 0 ? \"vehicle\" : \"prop\";\n return { glbBytes, bundle, worldKind };\n}\n\nexport async function compileSand3dRecipeGlb(\n programOrRecipe: string | Sand3dAssembly,\n): Promise<IngestedSand3dAsset> {\n const asm = resolveSand3dAssembly(programOrRecipe);\n const compiled = compileSand3dAssembly(asm);\n const { glbBytes, bundle, worldKind } = await exportCompiledSand3dWithKolmo(compiled);\n return { name: asm.name || \"sand3d_asset\", format: \"sand3d\", glbBytes, bundle, worldKind };\n}\n\nexport async function ingestSand3dOrGlb(\n input: File | Blob | ArrayBuffer | Uint8Array | string,\n fileNameHint?: string,\n): Promise<IngestedSand3dAsset> {\n if (typeof input === \"string\") {\n const trimmed = input.trim();\n if (/^(?:https?:\\/\\/|\\/|\\.\\.?\\/|blob:|data:)/i.test(trimmed)) {\n const res = await fetch(trimmed);\n if (!res.ok) throw new Error(`Asset fetch returned status ${res.status} for ${trimmed}`);\n const urlName = trimmed.split(\"?\")[0].split(\"/\").pop() || \"remote_asset.glb\";\n return ingestSand3dOrGlb(await res.arrayBuffer(), fileNameHint ?? urlName);\n }\n return compileSand3dRecipeGlb(trimmed);\n }\n if (!(input instanceof Uint8Array) && !(input instanceof ArrayBuffer)) {\n const inferredName = \"name\" in input && typeof input.name === \"string\" ? input.name : \"imported_asset.glb\";\n return ingestSand3dOrGlb(await input.arrayBuffer(), fileNameHint ?? inferredName);\n }\n\n const u8 = input instanceof Uint8Array ? input : new Uint8Array(input);\n const rawName = (fileNameHint ?? \"imported_asset\").replace(/\\.[^.]+$/, \"\") || \"imported_asset\";\n\n if (fileNameHint && isUsdFileName(fileNameHint)) {\n const ab = u8.buffer.slice(u8.byteOffset, u8.byteOffset + u8.byteLength) as ArrayBuffer;\n const usd = await convertUsdToGlb(ab);\n const glbBytes = new Uint8Array(usd.glb);\n const bundle = await loadKhrGlb(usd.glb);\n const worldKind = bundle.wheels.length > 0 || bundle.propellers.length > 0 ? \"vehicle\" : \"prop\";\n return { name: rawName, format: \"usd\", glbBytes, bundle, worldKind };\n }\n\n if (detectSand3dBytes(u8, fileNameHint)) {\n const source = new TextDecoder().decode(u8);\n const asm = parseSand3dSource(source);\n const compiled = compileSand3dAssembly(asm);\n const { glbBytes, bundle, worldKind } = await exportCompiledSand3dWithKolmo(compiled);\n return { name: asm.name || rawName, format: \"sand3d\", glbBytes, bundle, worldKind };\n }\n\n const copyBuf = u8.buffer.slice(u8.byteOffset, u8.byteOffset + u8.byteLength) as ArrayBuffer;\n const initial = await loadKhrGlb(copyBuf);\n if (initial.bodies.length > 0 || initial.wheels.length > 0 || initial.propellers.length > 0) {\n const worldKind = initial.wheels.length > 0 || initial.propellers.length > 0 ? \"vehicle\" : \"prop\";\n return { name: rawName, format: \"glb\", glbBytes: new Uint8Array(copyBuf), bundle: initial, worldKind };\n }\n\n const autoCompiled = await loadOrAutoCompileVehicleGlb(new Uint8Array(copyBuf));\n const worldKind = autoCompiled.bundle.wheels.length > 0 || autoCompiled.bundle.propellers.length > 0 ? \"vehicle\" : \"prop\";\n return { name: rawName, format: \"glb\", glbBytes: new Uint8Array(autoCompiled.bytes), bundle: autoCompiled.bundle, worldKind };\n}\n"],"mappings":";;;;;;;AA6CA,IAAM,aAAa;AACnB,IAAM,YAAY;AAElB,SAAgB,6BAA6B,UAA2B;CACpE,MAAM,QAAQ,SAAS,KAAK,CAAC,CAAC,YAAY;CAC1C,IAAI,cAAc,KAAK,KAAK,iBAAiB,KAAK,GAAG,OAAO;CAC5D,OAAO,0BAA0B,KAAK,KAAK;AAC/C;AAEA,SAAgB,kBAAkB,OAAiC,UAA4B;CAC3F,MAAM,aAAa,YAAY,GAAA,CAAI,KAAK,CAAC,CAAC,YAAY;CACtD,IAAI,UAAU,SAAS,MAAM,KAAK,cAAc,SAAS,GAAG,OAAO;CACnE,IAAI,cAAc,UAAU,SAAS,SAAS,KAAK,UAAU,SAAS,MAAM,KAAK,UAAU,SAAS,KAAK,IACrG,OAAO;CAEX,MAAM,KAAK,iBAAiB,aAAa,QAAQ,IAAI,WAAW,KAAK;CACrE,IAAI,GAAG,cAAc,GAAG;EAEpB,MAAM,QAAQ,IADG,SAAS,GAAG,QAAQ,GAAG,YAAY,GAAG,UACzC,CAAA,CAAK,UAAU,GAAG,IAAI;EACpC,IAAI,UAAU,cAAc,UAAU,WAAW,OAAO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EA,IAAI,kBAAkB,IAAI,YAAY,GAAG;EACrC,MAAM,SAAS,IAAI,YAAY,CAAC,CAAC,OAAO,EAAE;EAC1C,MAAM,MAAM,kBAAkB,MAAM;EAEpC,MAAM,EAAE,UAAU,QAAQ,cAAc,MAAM,8BAD7B,sBAAsB,GACqC,CAAQ;EACpF,OAAO;GAAE,MAAM,IAAI,QAAQ;GAAS,QAAQ;GAAU;GAAU;GAAQ;EAAU;CACtF;CAEA,MAAM,UAAU,GAAG,OAAO,MAAM,GAAG,YAAY,GAAG,aAAa,GAAG,UAAU;CAC5E,MAAM,UAAU,MAAM,WAAW,OAAO;CACxC,IAAI,QAAQ,OAAO,SAAS,KAAK,QAAQ,OAAO,SAAS,KAAK,QAAQ,WAAW,SAAS,GAAG;EACzF,MAAM,YAAY,QAAQ,OAAO,SAAS,KAAK,QAAQ,WAAW,SAAS,IAAI,YAAY;EAC3F,OAAO;GAAE,MAAM;GAAS,QAAQ;GAAO,UAAU,IAAI,WAAW,OAAO;GAAG,QAAQ;GAAS;EAAU;CACzG;CAEA,MAAM,eAAe,MAAM,4BAA4B,IAAI,WAAW,OAAO,CAAC;CAC9E,MAAM,YAAY,aAAa,OAAO,OAAO,SAAS,KAAK,aAAa,OAAO,WAAW,SAAS,IAAI,YAAY;CACnH,OAAO;EAAE,MAAM;EAAS,QAAQ;EAAO,UAAU,IAAI,WAAW,aAAa,KAAK;EAAG,QAAQ,aAAa;EAAQ;CAAU;AAChI"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { SuikaMergeArbiter } from "./suikaArbiter.js";
|
|
3
|
+
import { type OrbShape, type SuikaBurstEffect, type SuikaMergeEvent, type SuikaSpawnInput } from "./suikaTypes.js";
|
|
4
|
+
export interface OrbShapeGeometryProps {
|
|
5
|
+
readonly shape: OrbShape;
|
|
6
|
+
readonly radius: number;
|
|
7
|
+
readonly sphereSegments?: number;
|
|
8
|
+
}
|
|
9
|
+
export declare function OrbShapeGeometry({ shape, radius, sphereSegments }: OrbShapeGeometryProps): React.JSX.Element;
|
|
10
|
+
export declare function SuikaBurstMesh({ burst }: {
|
|
11
|
+
readonly burst: SuikaBurstEffect;
|
|
12
|
+
}): React.JSX.Element;
|
|
13
|
+
export interface KolmoSuikaOrbProps {
|
|
14
|
+
readonly id?: string;
|
|
15
|
+
readonly tier?: number;
|
|
16
|
+
readonly position?: [number, number, number];
|
|
17
|
+
readonly velocity?: [number, number, number];
|
|
18
|
+
readonly linearDamping?: number;
|
|
19
|
+
readonly angularDamping?: number;
|
|
20
|
+
readonly importedUrl?: string | null;
|
|
21
|
+
readonly arbiter?: SuikaMergeArbiter | null;
|
|
22
|
+
readonly managedBySystem?: boolean;
|
|
23
|
+
readonly minCoreRadius?: number;
|
|
24
|
+
}
|
|
25
|
+
export declare function KolmoSuikaOrb({ id, tier, position, velocity, linearDamping, angularDamping, importedUrl, arbiter, managedBySystem, minCoreRadius, }: KolmoSuikaOrbProps): React.JSX.Element;
|
|
26
|
+
export interface KolmoSuikaSystemProps {
|
|
27
|
+
readonly arbiter?: SuikaMergeArbiter;
|
|
28
|
+
readonly initialOrbs?: readonly SuikaSpawnInput[];
|
|
29
|
+
readonly minCoreRadius?: number;
|
|
30
|
+
readonly showBursts?: boolean;
|
|
31
|
+
readonly onMerge?: (event: SuikaMergeEvent) => void;
|
|
32
|
+
}
|
|
33
|
+
export declare function KolmoSuikaSystem({ arbiter, initialOrbs, minCoreRadius, showBursts, onMerge, }: KolmoSuikaSystemProps): React.JSX.Element;
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
import { useIsKolmoCustomGravity } from "../physics/index.js";
|
|
2
|
+
import { computeSuikaMergeMidpoint, defaultSuikaArbiter, useSuikaStore } from "./suikaArbiter.js";
|
|
3
|
+
import { getConvexHullVertices, loadImportedSuikaGlbUrl } from "./suikaGeometry.js";
|
|
4
|
+
import { getSuikaTier } from "./suikaTypes.js";
|
|
5
|
+
import { useEffect, useId, useMemo, useRef, useState } from "react";
|
|
6
|
+
import * as THREE from "three";
|
|
7
|
+
import { useFrame } from "@react-three/fiber";
|
|
8
|
+
import { useCustomGravity } from "@pinkaphant/ecctrl/gravity";
|
|
9
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
import { BallCollider, ConvexHullCollider, CuboidCollider, RigidBody, useRapier } from "@react-three/rapier";
|
|
11
|
+
import { easing } from "maath";
|
|
12
|
+
// src/suika/KolmoSuikaOrb.tsx
|
|
13
|
+
var _upVec = new THREE.Vector3();
|
|
14
|
+
function OrbShapeGeometry({ shape, radius, sphereSegments = 28 }) {
|
|
15
|
+
switch (shape) {
|
|
16
|
+
case "pyramid": return /* @__PURE__ */ jsx("coneGeometry", { args: [
|
|
17
|
+
radius,
|
|
18
|
+
radius * 2,
|
|
19
|
+
4
|
|
20
|
+
] });
|
|
21
|
+
case "cube": return /* @__PURE__ */ jsx("boxGeometry", { args: [
|
|
22
|
+
radius * 2,
|
|
23
|
+
radius * 2,
|
|
24
|
+
radius * 2
|
|
25
|
+
] });
|
|
26
|
+
case "dodecahedron": return /* @__PURE__ */ jsx("dodecahedronGeometry", { args: [radius, 0] });
|
|
27
|
+
case "octahedron": return /* @__PURE__ */ jsx("octahedronGeometry", { args: [radius, 0] });
|
|
28
|
+
case "icosahedron": return /* @__PURE__ */ jsx("icosahedronGeometry", { args: [radius, 0] });
|
|
29
|
+
case "geodesic1": return /* @__PURE__ */ jsx("icosahedronGeometry", { args: [radius, 1] });
|
|
30
|
+
case "geodesic2": return /* @__PURE__ */ jsx("icosahedronGeometry", { args: [radius, 2] });
|
|
31
|
+
default: return /* @__PURE__ */ jsx("sphereGeometry", { args: [
|
|
32
|
+
radius,
|
|
33
|
+
sphereSegments,
|
|
34
|
+
sphereSegments
|
|
35
|
+
] });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function SuikaBurstMesh({ burst }) {
|
|
39
|
+
const meshRef = useRef(null);
|
|
40
|
+
const matRef = useRef(null);
|
|
41
|
+
useFrame(() => {
|
|
42
|
+
const progress = Math.min(1, (Date.now() - burst.createdAt) / 800);
|
|
43
|
+
meshRef.current?.scale.setScalar(burst.radius * (.2 + progress * 1.8));
|
|
44
|
+
if (matRef.current) matRef.current.opacity = Math.max(0, 1 - progress) * .75;
|
|
45
|
+
});
|
|
46
|
+
return /* @__PURE__ */ jsxs("mesh", {
|
|
47
|
+
ref: meshRef,
|
|
48
|
+
position: burst.position,
|
|
49
|
+
children: [/* @__PURE__ */ jsx("sphereGeometry", { args: [
|
|
50
|
+
1,
|
|
51
|
+
16,
|
|
52
|
+
16
|
|
53
|
+
] }), /* @__PURE__ */ jsx("meshBasicMaterial", {
|
|
54
|
+
ref: matRef,
|
|
55
|
+
color: burst.color,
|
|
56
|
+
transparent: true,
|
|
57
|
+
opacity: .75,
|
|
58
|
+
wireframe: true
|
|
59
|
+
})]
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function KolmoSuikaOrb({ id, tier = 0, position = [
|
|
63
|
+
0,
|
|
64
|
+
1.5,
|
|
65
|
+
0
|
|
66
|
+
], velocity, linearDamping, angularDamping = .4, importedUrl = null, arbiter = defaultSuikaArbiter, managedBySystem = false, minCoreRadius = 0 }) {
|
|
67
|
+
const reactId = useId();
|
|
68
|
+
const orbId = id ?? `suika_${reactId.replace(/:/g, "")}`;
|
|
69
|
+
const tierDef = getSuikaTier(tier);
|
|
70
|
+
const bodyRef = useRef(null);
|
|
71
|
+
const groupRef = useRef(null);
|
|
72
|
+
const scaleRef = useRef(.1);
|
|
73
|
+
const initVelRef = useRef(false);
|
|
74
|
+
const { world } = useRapier();
|
|
75
|
+
const isCustomGravity = useIsKolmoCustomGravity();
|
|
76
|
+
const applyGravityField = useCustomGravity((s) => s.applyGravityField);
|
|
77
|
+
const [importedSkin, setImportedSkin] = useState(null);
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
if (!importedUrl) {
|
|
80
|
+
setImportedSkin(null);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
let alive = true, loadedAsset = null;
|
|
84
|
+
loadImportedSuikaGlbUrl(importedUrl, tierDef).then((asset) => {
|
|
85
|
+
if (!alive) {
|
|
86
|
+
asset.dispose();
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
loadedAsset = asset;
|
|
90
|
+
setImportedSkin(asset);
|
|
91
|
+
}).catch(() => {});
|
|
92
|
+
return () => {
|
|
93
|
+
alive = false;
|
|
94
|
+
loadedAsset?.dispose();
|
|
95
|
+
};
|
|
96
|
+
}, [importedUrl, tierDef]);
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
if (!arbiter || managedBySystem) return;
|
|
99
|
+
if (!arbiter.getEntity(orbId)) arbiter.spawn({
|
|
100
|
+
id: orbId,
|
|
101
|
+
tier: tierDef.id,
|
|
102
|
+
position,
|
|
103
|
+
velocity,
|
|
104
|
+
linearDamping,
|
|
105
|
+
importedUrl
|
|
106
|
+
});
|
|
107
|
+
return () => {
|
|
108
|
+
arbiter.remove(orbId);
|
|
109
|
+
};
|
|
110
|
+
}, [
|
|
111
|
+
arbiter,
|
|
112
|
+
managedBySystem,
|
|
113
|
+
orbId,
|
|
114
|
+
tierDef.id
|
|
115
|
+
]);
|
|
116
|
+
useFrame((_, delta) => {
|
|
117
|
+
const body = bodyRef.current;
|
|
118
|
+
if (!body) return;
|
|
119
|
+
if (!initVelRef.current && velocity) {
|
|
120
|
+
body.setLinvel({
|
|
121
|
+
x: velocity[0],
|
|
122
|
+
y: velocity[1],
|
|
123
|
+
z: velocity[2]
|
|
124
|
+
}, true);
|
|
125
|
+
initVelRef.current = true;
|
|
126
|
+
}
|
|
127
|
+
if (scaleRef.current < .999) {
|
|
128
|
+
easing.damp(scaleRef, "current", 1, .08, delta);
|
|
129
|
+
groupRef.current?.scale.setScalar(scaleRef.current);
|
|
130
|
+
}
|
|
131
|
+
if (isCustomGravity) applyGravityField(body, world.timestep);
|
|
132
|
+
const t = body.translation(), lv = body.linvel();
|
|
133
|
+
arbiter?.updateOrbKinematics(orbId, [
|
|
134
|
+
t.x,
|
|
135
|
+
t.y,
|
|
136
|
+
t.z
|
|
137
|
+
], [
|
|
138
|
+
lv.x,
|
|
139
|
+
lv.y,
|
|
140
|
+
lv.z
|
|
141
|
+
]);
|
|
142
|
+
if (minCoreRadius > 0) {
|
|
143
|
+
const r = Math.hypot(t.x, t.y, t.z);
|
|
144
|
+
if (r > .001 && r < minCoreRadius + tierDef.radius * .5) {
|
|
145
|
+
_upVec.set(t.x / r, t.y / r, t.z / r);
|
|
146
|
+
const targetR = minCoreRadius + tierDef.radius + .25;
|
|
147
|
+
body.setTranslation({
|
|
148
|
+
x: _upVec.x * targetR,
|
|
149
|
+
y: _upVec.y * targetR,
|
|
150
|
+
z: _upVec.z * targetR
|
|
151
|
+
}, true);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
const hullVertices = useMemo(() => {
|
|
156
|
+
if (importedSkin && importedSkin.hullVertices.length >= 12) return importedSkin.hullVertices;
|
|
157
|
+
return tierDef.shape !== "sphere" && tierDef.shape !== "cube" ? getConvexHullVertices(tierDef.shape, tierDef.radius) : null;
|
|
158
|
+
}, [
|
|
159
|
+
importedSkin,
|
|
160
|
+
tierDef.shape,
|
|
161
|
+
tierDef.radius
|
|
162
|
+
]);
|
|
163
|
+
const effDamping = linearDamping ?? (isCustomGravity || arbiter?.isInSpace ? 0 : .05);
|
|
164
|
+
return /* @__PURE__ */ jsxs(RigidBody, {
|
|
165
|
+
ref: bodyRef,
|
|
166
|
+
position,
|
|
167
|
+
type: "dynamic",
|
|
168
|
+
colliders: false,
|
|
169
|
+
ccd: true,
|
|
170
|
+
linearDamping: effDamping,
|
|
171
|
+
angularDamping,
|
|
172
|
+
mass: tierDef.mass,
|
|
173
|
+
userData: {
|
|
174
|
+
orbId,
|
|
175
|
+
tier: tierDef.id,
|
|
176
|
+
suikaId: orbId,
|
|
177
|
+
suikaTier: tierDef.id,
|
|
178
|
+
ecctrl: {
|
|
179
|
+
excludeRay: true,
|
|
180
|
+
excludeCharacterRay: true,
|
|
181
|
+
excludeVehicleRay: true
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
onCollisionEnter: (payload) => {
|
|
185
|
+
if (!arbiter) return;
|
|
186
|
+
const otherData = payload.other.rigidBodyObject?.userData;
|
|
187
|
+
const otherId = otherData?.orbId ?? otherData?.suikaId;
|
|
188
|
+
const otherTier = otherData?.tier ?? otherData?.suikaTier;
|
|
189
|
+
if (otherId && otherTier === tierDef.id && bodyRef.current && payload.other.rigidBody) {
|
|
190
|
+
const mid = computeSuikaMergeMidpoint(bodyRef.current.translation(), payload.other.rigidBody.translation(), tierDef.id, {
|
|
191
|
+
radialPointGravity: isCustomGravity,
|
|
192
|
+
minCoreRadius
|
|
193
|
+
});
|
|
194
|
+
arbiter.requestMerge(orbId, otherId, mid);
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
children: [tierDef.shape === "cube" && !importedSkin ? /* @__PURE__ */ jsx(CuboidCollider, {
|
|
198
|
+
args: [
|
|
199
|
+
tierDef.radius,
|
|
200
|
+
tierDef.radius,
|
|
201
|
+
tierDef.radius
|
|
202
|
+
],
|
|
203
|
+
restitution: .32,
|
|
204
|
+
friction: .75
|
|
205
|
+
}) : hullVertices && hullVertices.length >= 12 ? /* @__PURE__ */ jsx(ConvexHullCollider, {
|
|
206
|
+
args: [hullVertices],
|
|
207
|
+
restitution: .32,
|
|
208
|
+
friction: .75
|
|
209
|
+
}) : /* @__PURE__ */ jsx(BallCollider, {
|
|
210
|
+
args: [tierDef.radius],
|
|
211
|
+
restitution: .32,
|
|
212
|
+
friction: .75
|
|
213
|
+
}), /* @__PURE__ */ jsxs("group", {
|
|
214
|
+
ref: groupRef,
|
|
215
|
+
scale: .1,
|
|
216
|
+
children: [
|
|
217
|
+
importedSkin ? /* @__PURE__ */ jsx("primitive", { object: importedSkin.root }) : /* @__PURE__ */ jsxs("mesh", {
|
|
218
|
+
castShadow: true,
|
|
219
|
+
receiveShadow: true,
|
|
220
|
+
children: [/* @__PURE__ */ jsx(OrbShapeGeometry, {
|
|
221
|
+
shape: tierDef.shape,
|
|
222
|
+
radius: tierDef.radius,
|
|
223
|
+
sphereSegments: 32
|
|
224
|
+
}), /* @__PURE__ */ jsx("meshStandardMaterial", {
|
|
225
|
+
color: tierDef.color,
|
|
226
|
+
emissive: tierDef.emissive,
|
|
227
|
+
emissiveIntensity: tierDef.emissiveIntensity,
|
|
228
|
+
roughness: tierDef.roughness,
|
|
229
|
+
metalness: tierDef.metalness,
|
|
230
|
+
flatShading: true
|
|
231
|
+
})]
|
|
232
|
+
}),
|
|
233
|
+
/* @__PURE__ */ jsxs("mesh", { children: [/* @__PURE__ */ jsx(OrbShapeGeometry, {
|
|
234
|
+
shape: tierDef.shape,
|
|
235
|
+
radius: tierDef.radius * .65,
|
|
236
|
+
sphereSegments: 16
|
|
237
|
+
}), /* @__PURE__ */ jsx("meshBasicMaterial", {
|
|
238
|
+
color: tierDef.emissive,
|
|
239
|
+
transparent: true,
|
|
240
|
+
opacity: .6
|
|
241
|
+
})] }),
|
|
242
|
+
tierDef.id === 7 && /* @__PURE__ */ jsxs("mesh", {
|
|
243
|
+
rotation: [
|
|
244
|
+
.5,
|
|
245
|
+
.5,
|
|
246
|
+
0
|
|
247
|
+
],
|
|
248
|
+
children: [/* @__PURE__ */ jsx("torusGeometry", { args: [
|
|
249
|
+
tierDef.radius * 1.25,
|
|
250
|
+
.12,
|
|
251
|
+
12,
|
|
252
|
+
32
|
|
253
|
+
] }), /* @__PURE__ */ jsx("meshStandardMaterial", {
|
|
254
|
+
color: "#ff00aa",
|
|
255
|
+
emissive: "#ff00aa",
|
|
256
|
+
emissiveIntensity: 3
|
|
257
|
+
})]
|
|
258
|
+
}),
|
|
259
|
+
tierDef.id === 8 && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("mesh", {
|
|
260
|
+
rotation: [
|
|
261
|
+
1,
|
|
262
|
+
.4,
|
|
263
|
+
0
|
|
264
|
+
],
|
|
265
|
+
children: [/* @__PURE__ */ jsx("torusGeometry", { args: [
|
|
266
|
+
tierDef.radius * 1.35,
|
|
267
|
+
.18,
|
|
268
|
+
12,
|
|
269
|
+
36
|
|
270
|
+
] }), /* @__PURE__ */ jsx("meshStandardMaterial", {
|
|
271
|
+
color: "#ffaa00",
|
|
272
|
+
emissive: "#ffd700",
|
|
273
|
+
emissiveIntensity: 3
|
|
274
|
+
})]
|
|
275
|
+
}), /* @__PURE__ */ jsx("pointLight", {
|
|
276
|
+
color: "#ffaa00",
|
|
277
|
+
intensity: 4,
|
|
278
|
+
distance: tierDef.radius * 3
|
|
279
|
+
})] }),
|
|
280
|
+
tierDef.id === 9 && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("mesh", {
|
|
281
|
+
rotation: [
|
|
282
|
+
Math.PI / 2,
|
|
283
|
+
0,
|
|
284
|
+
0
|
|
285
|
+
],
|
|
286
|
+
children: [/* @__PURE__ */ jsx("ringGeometry", { args: [
|
|
287
|
+
tierDef.radius * 1.15,
|
|
288
|
+
tierDef.radius * 1.85,
|
|
289
|
+
48
|
|
290
|
+
] }), /* @__PURE__ */ jsx("meshStandardMaterial", {
|
|
291
|
+
color: "#7c4dff",
|
|
292
|
+
emissive: "#aa00ff",
|
|
293
|
+
emissiveIntensity: 4,
|
|
294
|
+
side: THREE.DoubleSide
|
|
295
|
+
})]
|
|
296
|
+
}), /* @__PURE__ */ jsx("pointLight", {
|
|
297
|
+
color: "#7c4dff",
|
|
298
|
+
intensity: 6,
|
|
299
|
+
distance: tierDef.radius * 4
|
|
300
|
+
})] }),
|
|
301
|
+
tierDef.id === 10 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
302
|
+
/* @__PURE__ */ jsxs("mesh", {
|
|
303
|
+
rotation: [
|
|
304
|
+
.4,
|
|
305
|
+
.8,
|
|
306
|
+
0
|
|
307
|
+
],
|
|
308
|
+
children: [/* @__PURE__ */ jsx("sphereGeometry", { args: [
|
|
309
|
+
tierDef.radius * 1.002,
|
|
310
|
+
36,
|
|
311
|
+
36
|
|
312
|
+
] }), /* @__PURE__ */ jsx("meshStandardMaterial", {
|
|
313
|
+
color: "#cfd8dc",
|
|
314
|
+
roughness: .9,
|
|
315
|
+
metalness: .1
|
|
316
|
+
})]
|
|
317
|
+
}),
|
|
318
|
+
/* @__PURE__ */ jsxs("mesh", {
|
|
319
|
+
rotation: [
|
|
320
|
+
.3,
|
|
321
|
+
.5,
|
|
322
|
+
0
|
|
323
|
+
],
|
|
324
|
+
children: [/* @__PURE__ */ jsx("ringGeometry", { args: [
|
|
325
|
+
tierDef.radius * 1.3,
|
|
326
|
+
tierDef.radius * 1.7,
|
|
327
|
+
48
|
|
328
|
+
] }), /* @__PURE__ */ jsx("meshBasicMaterial", {
|
|
329
|
+
color: "#80deea",
|
|
330
|
+
transparent: true,
|
|
331
|
+
opacity: .65,
|
|
332
|
+
side: THREE.DoubleSide
|
|
333
|
+
})]
|
|
334
|
+
}),
|
|
335
|
+
/* @__PURE__ */ jsx("pointLight", {
|
|
336
|
+
color: "#e0f7fa",
|
|
337
|
+
intensity: 8,
|
|
338
|
+
distance: tierDef.radius * 5
|
|
339
|
+
})
|
|
340
|
+
] })
|
|
341
|
+
]
|
|
342
|
+
})]
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
function KolmoSuikaSystem({ arbiter = defaultSuikaArbiter, initialOrbs, minCoreRadius = 0, showBursts = true, onMerge }) {
|
|
346
|
+
const snap = useSuikaStore(arbiter);
|
|
347
|
+
const cleanupAccumRef = useRef(0);
|
|
348
|
+
useEffect(() => {
|
|
349
|
+
if (!initialOrbs || initialOrbs.length === 0) return;
|
|
350
|
+
for (const item of initialOrbs) if (!item.id || !arbiter.getEntity(item.id)) arbiter.spawn(item);
|
|
351
|
+
}, [arbiter, initialOrbs]);
|
|
352
|
+
useFrame((_, delta) => {
|
|
353
|
+
const events = arbiter.resolveStep();
|
|
354
|
+
if (onMerge) for (const ev of events) onMerge(ev);
|
|
355
|
+
cleanupAccumRef.current += delta;
|
|
356
|
+
if (cleanupAccumRef.current >= .25) {
|
|
357
|
+
cleanupAccumRef.current = 0;
|
|
358
|
+
arbiter.cleanUpEffects();
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [snap.orbs.map((orb) => /* @__PURE__ */ jsx(KolmoSuikaOrb, {
|
|
362
|
+
id: orb.id,
|
|
363
|
+
tier: orb.tier,
|
|
364
|
+
position: orb.position,
|
|
365
|
+
velocity: orb.velocity,
|
|
366
|
+
linearDamping: orb.linearDamping,
|
|
367
|
+
importedUrl: orb.importedUrl,
|
|
368
|
+
arbiter,
|
|
369
|
+
managedBySystem: true,
|
|
370
|
+
minCoreRadius
|
|
371
|
+
}, orb.id)), showBursts && snap.particleBursts.map((b) => /* @__PURE__ */ jsx(SuikaBurstMesh, { burst: b }, b.id))] });
|
|
372
|
+
}
|
|
373
|
+
export { KolmoSuikaOrb, KolmoSuikaSystem, OrbShapeGeometry, SuikaBurstMesh };
|
|
374
|
+
|
|
375
|
+
//# sourceMappingURL=KolmoSuikaOrb.js.map
|