@multitapio/multitap 0.0.14 → 0.0.15
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/dist/lib.d.ts +1 -0
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +61 -0
- package/dist/mesh-utils.d.ts +58 -0
- package/dist/mesh-utils.d.ts.map +1 -0
- package/dist/types/lib.d.ts +1 -0
- package/dist/types/lib.d.ts.map +1 -1
- package/dist/types/mesh-utils.d.ts +58 -0
- package/dist/types/mesh-utils.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/lib.d.ts
CHANGED
package/dist/lib.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../src/lib.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC;AACxB,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../src/lib.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC;AACxB,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
|
package/dist/lib.js
CHANGED
|
@@ -8741,6 +8741,65 @@ var TestSession = class _TestSession {
|
|
|
8741
8741
|
}
|
|
8742
8742
|
};
|
|
8743
8743
|
|
|
8744
|
+
// src/mesh-utils.ts
|
|
8745
|
+
function extractMeshFromGeometry(geometry, scale = 1, offset = [0, 0, 0]) {
|
|
8746
|
+
const posAttr = geometry.attributes.position;
|
|
8747
|
+
if (!posAttr) {
|
|
8748
|
+
throw new Error("Geometry has no position attribute");
|
|
8749
|
+
}
|
|
8750
|
+
const vertexCount = posAttr.count;
|
|
8751
|
+
const vertices = new Float32Array(vertexCount * 3);
|
|
8752
|
+
for (let i = 0; i < vertexCount; i++) {
|
|
8753
|
+
const srcIdx = i * posAttr.itemSize;
|
|
8754
|
+
const dstIdx = i * 3;
|
|
8755
|
+
const x = posAttr.array[srcIdx];
|
|
8756
|
+
const y = posAttr.array[srcIdx + 1];
|
|
8757
|
+
const z = posAttr.array[srcIdx + 2];
|
|
8758
|
+
vertices[dstIdx] = x * scale + offset[0];
|
|
8759
|
+
vertices[dstIdx + 1] = y * scale + offset[1];
|
|
8760
|
+
vertices[dstIdx + 2] = z * scale + offset[2];
|
|
8761
|
+
}
|
|
8762
|
+
let indices;
|
|
8763
|
+
if (geometry.index) {
|
|
8764
|
+
const indexCount = geometry.index.count;
|
|
8765
|
+
indices = new Uint32Array(indexCount);
|
|
8766
|
+
for (let i = 0; i < indexCount; i++) {
|
|
8767
|
+
indices[i] = geometry.index.array[i];
|
|
8768
|
+
}
|
|
8769
|
+
} else {
|
|
8770
|
+
const indexCount = vertexCount;
|
|
8771
|
+
indices = new Uint32Array(indexCount);
|
|
8772
|
+
for (let i = 0; i < indexCount; i++) {
|
|
8773
|
+
indices[i] = i;
|
|
8774
|
+
}
|
|
8775
|
+
}
|
|
8776
|
+
return { vertices, indices };
|
|
8777
|
+
}
|
|
8778
|
+
function encodeTriMeshBlob(mesh) {
|
|
8779
|
+
const vertexCount = mesh.vertices.length / 3;
|
|
8780
|
+
const triangleCount = mesh.indices.length / 3;
|
|
8781
|
+
const headerSize = 8;
|
|
8782
|
+
const verticesSize = vertexCount * 12;
|
|
8783
|
+
const indicesSize = triangleCount * 12;
|
|
8784
|
+
const totalSize = headerSize + verticesSize + indicesSize;
|
|
8785
|
+
const buffer2 = new ArrayBuffer(totalSize);
|
|
8786
|
+
const view = new DataView(buffer2);
|
|
8787
|
+
let offset = 0;
|
|
8788
|
+
view.setUint32(offset, vertexCount, true);
|
|
8789
|
+
offset += 4;
|
|
8790
|
+
view.setUint32(offset, triangleCount, true);
|
|
8791
|
+
offset += 4;
|
|
8792
|
+
for (let i = 0; i < mesh.vertices.length; i++) {
|
|
8793
|
+
view.setFloat32(offset, mesh.vertices[i], true);
|
|
8794
|
+
offset += 4;
|
|
8795
|
+
}
|
|
8796
|
+
for (let i = 0; i < mesh.indices.length; i++) {
|
|
8797
|
+
view.setUint32(offset, mesh.indices[i], true);
|
|
8798
|
+
offset += 4;
|
|
8799
|
+
}
|
|
8800
|
+
return new Uint8Array(buffer2);
|
|
8801
|
+
}
|
|
8802
|
+
|
|
8744
8803
|
// src/react/providers/SessionProvider.tsx
|
|
8745
8804
|
import { createContext, useContext, useEffect, useState, useRef, useMemo, useCallback } from "react";
|
|
8746
8805
|
import { useFrame as useFiberFrame } from "@react-three/fiber";
|
|
@@ -10716,8 +10775,10 @@ export {
|
|
|
10716
10775
|
createState,
|
|
10717
10776
|
createStoreApi,
|
|
10718
10777
|
despawn,
|
|
10778
|
+
encodeTriMeshBlob,
|
|
10719
10779
|
ensureCompiled,
|
|
10720
10780
|
ensureCompiledStateSchema,
|
|
10781
|
+
extractMeshFromGeometry,
|
|
10721
10782
|
generateKeyPair,
|
|
10722
10783
|
genesisHashFromString,
|
|
10723
10784
|
genesisHashToString,
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mesh extraction utilities for trimesh colliders.
|
|
3
|
+
*
|
|
4
|
+
* Extracts triangle mesh data from Three.js BufferGeometry and encodes it
|
|
5
|
+
* as a binary blob for passing to the physics simulation.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Extracted mesh data ready for encoding.
|
|
9
|
+
*/
|
|
10
|
+
export interface ExtractedMesh {
|
|
11
|
+
/** Flat array of vertex positions (xyz triples) */
|
|
12
|
+
vertices: Float32Array;
|
|
13
|
+
/** Triangle indices (3 indices per triangle) */
|
|
14
|
+
indices: Uint32Array;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Minimal interface for BufferGeometry to avoid Three.js dependency.
|
|
18
|
+
* Compatible with THREE.BufferGeometry.
|
|
19
|
+
*/
|
|
20
|
+
export interface BufferGeometryLike {
|
|
21
|
+
attributes: {
|
|
22
|
+
position?: {
|
|
23
|
+
array: ArrayLike<number>;
|
|
24
|
+
count: number;
|
|
25
|
+
itemSize: number;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
index?: {
|
|
29
|
+
array: ArrayLike<number>;
|
|
30
|
+
count: number;
|
|
31
|
+
} | null;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Extract trimesh data from a BufferGeometry-like object.
|
|
35
|
+
*
|
|
36
|
+
* @param geometry - The geometry to extract from
|
|
37
|
+
* @param scale - Scale factor to apply to vertices (default: 1)
|
|
38
|
+
* @param offset - XYZ offset to add to each vertex (default: [0, 0, 0])
|
|
39
|
+
* @returns Extracted mesh with vertices and indices
|
|
40
|
+
*/
|
|
41
|
+
export declare function extractMeshFromGeometry(geometry: BufferGeometryLike, scale?: number, offset?: [number, number, number]): ExtractedMesh;
|
|
42
|
+
/**
|
|
43
|
+
* Encode extracted mesh data as a binary blob for the physics plugin.
|
|
44
|
+
*
|
|
45
|
+
* Binary format:
|
|
46
|
+
* - Header (8 bytes):
|
|
47
|
+
* - vertex_count: u32 (LE)
|
|
48
|
+
* - triangle_count: u32 (LE)
|
|
49
|
+
* - Vertices (vertex_count * 12 bytes):
|
|
50
|
+
* - x: f32, y: f32, z: f32 (LE each)
|
|
51
|
+
* - Indices (triangle_count * 12 bytes):
|
|
52
|
+
* - i0: u32, i1: u32, i2: u32 (LE each)
|
|
53
|
+
*
|
|
54
|
+
* @param mesh - Extracted mesh data
|
|
55
|
+
* @returns Binary blob ready for init data
|
|
56
|
+
*/
|
|
57
|
+
export declare function encodeTriMeshBlob(mesh: ExtractedMesh): Uint8Array;
|
|
58
|
+
//# sourceMappingURL=mesh-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mesh-utils.d.ts","sourceRoot":"","sources":["../../src/mesh-utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,mDAAmD;IACnD,QAAQ,EAAE,YAAY,CAAC;IACvB,gDAAgD;IAChD,OAAO,EAAE,WAAW,CAAC;CACtB;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE;QACV,QAAQ,CAAC,EAAE;YACT,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;YACzB,KAAK,EAAE,MAAM,CAAC;YACd,QAAQ,EAAE,MAAM,CAAC;SAClB,CAAC;KACH,CAAC;IACF,KAAK,CAAC,EAAE;QACN,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;QACzB,KAAK,EAAE,MAAM,CAAC;KACf,GAAG,IAAI,CAAC;CACV;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,kBAAkB,EAC5B,KAAK,GAAE,MAAU,EACjB,MAAM,GAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAa,GAC3C,aAAa,CAyCf;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,aAAa,GAAG,UAAU,CAiCjE"}
|
package/dist/types/lib.d.ts
CHANGED
package/dist/types/lib.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../src/lib.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC;AACxB,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../src/lib.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,SAAS,CAAC;AACxB,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mesh extraction utilities for trimesh colliders.
|
|
3
|
+
*
|
|
4
|
+
* Extracts triangle mesh data from Three.js BufferGeometry and encodes it
|
|
5
|
+
* as a binary blob for passing to the physics simulation.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Extracted mesh data ready for encoding.
|
|
9
|
+
*/
|
|
10
|
+
export interface ExtractedMesh {
|
|
11
|
+
/** Flat array of vertex positions (xyz triples) */
|
|
12
|
+
vertices: Float32Array;
|
|
13
|
+
/** Triangle indices (3 indices per triangle) */
|
|
14
|
+
indices: Uint32Array;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Minimal interface for BufferGeometry to avoid Three.js dependency.
|
|
18
|
+
* Compatible with THREE.BufferGeometry.
|
|
19
|
+
*/
|
|
20
|
+
export interface BufferGeometryLike {
|
|
21
|
+
attributes: {
|
|
22
|
+
position?: {
|
|
23
|
+
array: ArrayLike<number>;
|
|
24
|
+
count: number;
|
|
25
|
+
itemSize: number;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
index?: {
|
|
29
|
+
array: ArrayLike<number>;
|
|
30
|
+
count: number;
|
|
31
|
+
} | null;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Extract trimesh data from a BufferGeometry-like object.
|
|
35
|
+
*
|
|
36
|
+
* @param geometry - The geometry to extract from
|
|
37
|
+
* @param scale - Scale factor to apply to vertices (default: 1)
|
|
38
|
+
* @param offset - XYZ offset to add to each vertex (default: [0, 0, 0])
|
|
39
|
+
* @returns Extracted mesh with vertices and indices
|
|
40
|
+
*/
|
|
41
|
+
export declare function extractMeshFromGeometry(geometry: BufferGeometryLike, scale?: number, offset?: [number, number, number]): ExtractedMesh;
|
|
42
|
+
/**
|
|
43
|
+
* Encode extracted mesh data as a binary blob for the physics plugin.
|
|
44
|
+
*
|
|
45
|
+
* Binary format:
|
|
46
|
+
* - Header (8 bytes):
|
|
47
|
+
* - vertex_count: u32 (LE)
|
|
48
|
+
* - triangle_count: u32 (LE)
|
|
49
|
+
* - Vertices (vertex_count * 12 bytes):
|
|
50
|
+
* - x: f32, y: f32, z: f32 (LE each)
|
|
51
|
+
* - Indices (triangle_count * 12 bytes):
|
|
52
|
+
* - i0: u32, i1: u32, i2: u32 (LE each)
|
|
53
|
+
*
|
|
54
|
+
* @param mesh - Extracted mesh data
|
|
55
|
+
* @returns Binary blob ready for init data
|
|
56
|
+
*/
|
|
57
|
+
export declare function encodeTriMeshBlob(mesh: ExtractedMesh): Uint8Array;
|
|
58
|
+
//# sourceMappingURL=mesh-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mesh-utils.d.ts","sourceRoot":"","sources":["../../src/mesh-utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,mDAAmD;IACnD,QAAQ,EAAE,YAAY,CAAC;IACvB,gDAAgD;IAChD,OAAO,EAAE,WAAW,CAAC;CACtB;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE;QACV,QAAQ,CAAC,EAAE;YACT,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;YACzB,KAAK,EAAE,MAAM,CAAC;YACd,QAAQ,EAAE,MAAM,CAAC;SAClB,CAAC;KACH,CAAC;IACF,KAAK,CAAC,EAAE;QACN,KAAK,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;QACzB,KAAK,EAAE,MAAM,CAAC;KACf,GAAG,IAAI,CAAC;CACV;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,kBAAkB,EAC5B,KAAK,GAAE,MAAU,EACjB,MAAM,GAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAa,GAC3C,aAAa,CAyCf;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,aAAa,GAAG,UAAU,CAiCjE"}
|