@playcanvas/splat-transform 1.9.1 → 1.9.2

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.
@@ -34,6 +34,8 @@ export { writeLod } from './writers/write-lod';
34
34
  export { writeGlb } from './writers/write-glb';
35
35
  export { writeVoxel } from './writers/write-voxel';
36
36
  export type { WriteVoxelOptions, VoxelMetadata } from './writers/write-voxel';
37
+ export { marchingCubes } from './voxel/marching-cubes';
38
+ export type { MarchingCubesMesh } from './voxel/marching-cubes';
37
39
  export type { Options, Param } from './types';
38
40
  export { logger } from './utils/logger';
39
41
  export type { Logger, ProgressNode } from './utils/logger';
@@ -34,6 +34,8 @@ export { writeLod } from './writers/write-lod';
34
34
  export { writeGlb } from './writers/write-glb';
35
35
  export { writeVoxel } from './writers/write-voxel';
36
36
  export type { WriteVoxelOptions, VoxelMetadata } from './writers/write-voxel';
37
+ export { marchingCubes } from './voxel/marching-cubes';
38
+ export type { MarchingCubesMesh } from './voxel/marching-cubes';
37
39
  export type { Options, Param } from './types';
38
40
  export { logger } from './utils/logger';
39
41
  export type { Logger, ProgressNode } from './utils/logger';
@@ -18,6 +18,10 @@ type Options = {
18
18
  voxelResolution?: number;
19
19
  /** Opacity threshold for solid voxels - voxels below this are considered empty. Default: 0.5 */
20
20
  opacityCutoff?: number;
21
+ /** Whether to generate a collision mesh (.collision.glb) alongside voxel output. Default: false */
22
+ collisionMesh?: boolean;
23
+ /** Ratio of triangles to keep when simplifying the collision mesh (0-1). Default: 0.25 */
24
+ meshSimplify?: number;
21
25
  };
22
26
  /**
23
27
  * Parameter passed to MJS generator scripts.
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Build a minimal GLB (glTF 2.0 binary) file containing a single triangle mesh.
3
+ *
4
+ * The output contains only positions and triangle indices — no normals,
5
+ * UVs, or materials — suitable for collision meshes.
6
+ *
7
+ * @param positions - Vertex positions (3 floats per vertex)
8
+ * @param indices - Triangle indices (3 per triangle, unsigned 32-bit)
9
+ * @returns GLB file as a Uint8Array
10
+ */
11
+ declare function buildCollisionGlb(positions: Float32Array, indices: Uint32Array): Uint8Array;
12
+ export { buildCollisionGlb };
@@ -4,3 +4,5 @@ export { GpuVoxelization } from './gpu-voxelization.js';
4
4
  export type { BatchSpec, MultiBatchResult } from './gpu-voxelization.js';
5
5
  export { buildSparseOctree, alignGridBounds } from './sparse-octree.js';
6
6
  export type { SparseOctree, Bounds } from './sparse-octree.js';
7
+ export { marchingCubes } from './marching-cubes.js';
8
+ export type { MarchingCubesMesh } from './marching-cubes.js';
@@ -0,0 +1,25 @@
1
+ import { BlockAccumulator, type Bounds } from './sparse-octree';
2
+ /**
3
+ * Result of marching cubes surface extraction.
4
+ */
5
+ interface MarchingCubesMesh {
6
+ /** Vertex positions (3 floats per vertex) */
7
+ positions: Float32Array;
8
+ /** Triangle indices (3 indices per triangle) */
9
+ indices: Uint32Array;
10
+ }
11
+ /**
12
+ * Extract a triangle mesh from a BlockAccumulator using marching cubes.
13
+ *
14
+ * Each voxel is treated as a cell in the marching cubes grid. Corner values
15
+ * are binary (0 = empty, 1 = occupied) with a 0.5 threshold. Vertices are
16
+ * placed at edge midpoints, producing a mesh that follows voxel boundaries.
17
+ *
18
+ * @param accumulator - Voxel block data after filtering
19
+ * @param gridBounds - Grid bounds aligned to block boundaries
20
+ * @param voxelResolution - Size of each voxel in world units
21
+ * @returns Mesh with positions and indices
22
+ */
23
+ declare function marchingCubes(accumulator: BlockAccumulator, gridBounds: Bounds, voxelResolution: number): MarchingCubesMesh;
24
+ export { marchingCubes };
25
+ export type { MarchingCubesMesh };
@@ -15,6 +15,10 @@ type WriteVoxelOptions = {
15
15
  opacityCutoff?: number;
16
16
  /** Optional function to create a GPU device for voxelization */
17
17
  createDevice?: DeviceCreator;
18
+ /** Whether to generate a collision mesh (.collision.glb) alongside the voxel data. Default: false */
19
+ collisionMesh?: boolean;
20
+ /** Ratio of triangles to keep when simplifying the collision mesh (0-1). Default: 0.25 */
21
+ meshSimplify?: number;
18
22
  };
19
23
  /**
20
24
  * Metadata for a voxel octree file.
@@ -51,9 +55,10 @@ interface VoxelMetadata {
51
55
  * Voxelizes Gaussian splat data and writes the result as a sparse voxel octree.
52
56
  *
53
57
  * This function performs GPU-accelerated voxelization of Gaussian splat data
54
- * and outputs two files:
58
+ * and outputs two or three files:
55
59
  * - `filename` (.voxel.json) - JSON metadata including bounds, resolution, and array sizes
56
60
  * - Corresponding .voxel.bin - Binary octree data (nodes + leafData as Uint32 arrays)
61
+ * - Corresponding .collision.glb - Triangle mesh extracted via marching cubes (GLB format, optional)
57
62
  *
58
63
  * The binary file layout is:
59
64
  * - Bytes 0 to (nodeCount * 4 - 1): nodes array (Uint32, little-endian)
@@ -72,6 +77,7 @@ interface VoxelMetadata {
72
77
  * dataTable: myDataTable,
73
78
  * voxelResolution: 0.05,
74
79
  * opacityCutoff: 0.5,
80
+ * collisionMesh: true,
75
81
  * createDevice: async () => myGraphicsDevice
76
82
  * }, fs);
77
83
  * ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playcanvas/splat-transform",
3
- "version": "1.9.1",
3
+ "version": "1.9.2",
4
4
  "author": "PlayCanvas<support@playcanvas.com>",
5
5
  "homepage": "https://playcanvas.com",
6
6
  "description": "Library and CLI tool for 3D Gaussian splat format conversion and transformation",
@@ -45,6 +45,7 @@
45
45
  "lib/"
46
46
  ],
47
47
  "dependencies": {
48
+ "meshoptimizer": "^1.0.1",
48
49
  "webgpu": "^0.3.8"
49
50
  },
50
51
  "devDependencies": {