@speridlabs/visus 0.1.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/README.md ADDED
@@ -0,0 +1,155 @@
1
+ # Visus - Gaussian Splatting for Three.js
2
+
3
+ Visus is a high-performance WebGL library designed to seamlessly integrate real-time 3D Gaussian Splatting (3DGS) rendering into [Three.js](https://threejs.org/) applications. It focuses on speed and optimization to deliver smooth rendering experiences directly within your existing Three.js scenes.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ # Using npm
9
+ npm install visus
10
+
11
+ # Using yarn
12
+ yarn add visus
13
+
14
+ # Using pnpm
15
+ pnpm add visus
16
+ ```
17
+
18
+ ## Key Features
19
+
20
+ - **Three.js Integration:** Designed as a `THREE.Mesh`-like object (`SplatMesh`) for easy addition to Three.js scenes.
21
+ - **Customizable Material:** Offers options for controlling rendering appearance.
22
+ - **Optimized Performance:** Leverages several techniques for speed:
23
+ - **GPU Sorting:** Performs view-dependent sorting in a Web Worker to avoid blocking the main thread, ensuring correct transparency.
24
+ - **Instanced Rendering:** Draws multiple splats per draw call using GPU instancing.
25
+ - **Efficient Texture Packing:** Packs rotation and scale data tightly into GPU textures.
26
+ - **Optimized Shaders:** Includes early discards and efficient math operations in GLSL shaders.
27
+
28
+ ## Basic Usage
29
+
30
+ ```typescript
31
+ // main.ts
32
+ import * as THREE from 'three';
33
+ import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
34
+ import { PlyLoader, SplatMesh, SplatData } from 'visus'; // Import from visus
35
+
36
+ // 1. Basic Three.js Scene Setup
37
+ const scene = new THREE.Scene();
38
+ const camera = new THREE.PerspectiveCamera(
39
+ 75,
40
+ window.innerWidth / window.innerHeight,
41
+ 0.1,
42
+ 1000,
43
+ );
44
+ camera.position.set(0, 1, 3);
45
+
46
+ const renderer = new THREE.WebGLRenderer({ antialias: true });
47
+ renderer.setSize(window.innerWidth, window.innerHeight);
48
+ renderer.setAnimationLoop(animate);
49
+ document.body.appendChild(renderer.domElement);
50
+
51
+ const controls = new OrbitControls(camera, renderer.domElement);
52
+ controls.enableDamping = true;
53
+
54
+ // 2. Load the Splat File
55
+ // IMPORTANT: Place your PLY file (e.g., sample.ply) in your project's `public/` directory
56
+ // or serve it from a location accessible by the browser.
57
+ const loader = new PlyLoader();
58
+ const plyUrl = '/sample.ply'; // Adjust path as needed
59
+
60
+ async function loadAndDisplaySplat() {
61
+ try {
62
+ console.log(`Loading splat from ${plyUrl}...`);
63
+ const splatData: SplatData = await loader.loadAsync(plyUrl);
64
+ console.log(`Loaded ${splatData.numSplats} splats.`);
65
+
66
+ // 3. Create the SplatMesh
67
+ // autoSort: true enables automatic sorting based on camera view (recommended)
68
+ const splatMesh = new SplatMesh(splatData, { autoSort: true });
69
+
70
+ // Optional: Apply transformations if needed (e.g., correct orientation)
71
+ // splatMesh.rotation.set(0, 0, Math.PI);
72
+
73
+ // 4. Add to Scene
74
+ scene.add(splatMesh);
75
+ console.log('SplatMesh added to scene.');
76
+
77
+ // Optional: Focus camera on the splat
78
+ if (splatMesh.geometry.boundingBox) {
79
+ const center = new THREE.Vector3();
80
+ splatMesh.geometry.boundingBox.getCenter(center);
81
+ controls.target.copy(center);
82
+
83
+ const sphere = new THREE.Sphere();
84
+ splatMesh.geometry.boundingBox.getBoundingSphere(sphere);
85
+ camera.position
86
+ .copy(center)
87
+ .add(new THREE.Vector3(0, 0, sphere.radius * 2));
88
+ camera.lookAt(center);
89
+ controls.update();
90
+ }
91
+ } catch (error) {
92
+ console.error('Error loading splat:', error);
93
+ // Display error to user
94
+ }
95
+ }
96
+
97
+ loadAndDisplaySplat(); // Start loading
98
+
99
+ // 5. Animation Loop
100
+ function animate() {
101
+ controls.update(); // Required if damping is enabled
102
+ renderer.render(scene, camera);
103
+ }
104
+
105
+ // Handle window resize
106
+ window.addEventListener('resize', () => {
107
+ camera.aspect = window.innerWidth / window.innerHeight;
108
+ camera.updateProjectionMatrix();
109
+ renderer.setSize(window.innerWidth, window.innerHeight);
110
+ });
111
+ ```
112
+
113
+ _(See `examples/main.ts` for a more complete example setup)_
114
+
115
+ ## API Overview
116
+
117
+ - **`PlyLoader`**: Loads `.ply` files containing Gaussian Splat data. Use `loadAsync` for Promise-based loading.
118
+ - **`SplatData`**: Internal representation holding the raw data (positions, rotations, scales, colors, opacities) for all splats.
119
+ - **`SplatMesh`**: The main renderable object. Add this to your `THREE.Scene`. It manages the geometry, material, and sorting. Takes `SplatData` and optional `SplatMeshOptions` in its constructor.
120
+ - `options.autoSort` (default `true`): Automatically triggers sorting based on camera movement.
121
+ - **`SplatMaterial`**: The `THREE.ShaderMaterial` used internally by `SplatMesh`. Handles the actual splat rendering logic. Can be customized via `SplatMaterialOptions`.
122
+ - **`SplatSorter`**: Manages the Web Worker responsible for view-dependent sorting. Generally used internally by `SplatMesh`.
123
+ - **`TextureManager`**: Handles packing splat data into GPU textures. Used internally.
124
+
125
+ ## Performance Optimizations
126
+
127
+ Visus employs several techniques documented in `Optimizations.md` to achieve real-time performance:
128
+
129
+ - **GPU Sorting via Web Worker:** Sorts splats by depth off the main thread using a distance-based counting sort, preventing stutter and ensuring correct alpha blending.
130
+ - **Instanced Rendering:** Renders many splats (typically 128) in a single draw call, reducing CPU overhead.
131
+ - **Packed Data Textures:** Stores rotation and scale data efficiently in textures, minimizing GPU memory bandwidth. Rotation quaternions are packed, reconstructing the `w` component in the shader. Scale is stored logarithmically.
132
+ - **Shader Optimizations:** Uses early checks in vertex and fragment shaders to discard splats/fragments that won't be visible (behind near plane, too small, fully transparent, outside ellipse), reducing GPU workload.
133
+ - **Premultiplied Alpha Blending:** Uses standard premultiplied alpha for correct transparency compositing.
134
+
135
+ ## Future Development / Roadmap
136
+
137
+ Based on the analysis in `Optimizations.md`, potential future enhancements include:
138
+
139
+ - Support for Spherical Harmonics (SH) for view-dependent color effects.
140
+ - Implementing spatial data reordering (e.g., Morton order) before GPU upload for improved cache coherency.
141
+ - Exploring more advanced texture compression or lower-precision formats (like half-floats or uint8) for attributes like color and scale to further reduce GPU memory usage.
142
+ - Adding streamed loading capabilities to handle very large `.ply` files more efficiently in terms of RAM.
143
+ - Investigating multi-chunk based sorting optimizations for better key distribution with non-uniform datasets.
144
+ - Adding optional dithering techniques as an alternative to alpha blending.
145
+ - Implementing more sophisticated culling methods.
146
+
147
+ ## Contributing
148
+
149
+ Contributions are welcome! If you find a bug or have a feature request, please open an issue on the GitHub repository.
150
+
151
+ For pull requests, please ensure your code adheres to the project's linting (`pnpm lint`) and formatting (`pnpm format`) standards.
152
+
153
+ ## License
154
+
155
+ Visus is licensed under the [Apache License 2.0](LICENSE).
@@ -0,0 +1,12 @@
1
+ /**
2
+ * visus - Gaussian Splat Rendering for Three.js
3
+ */
4
+ export { SplatData } from './core/data';
5
+ export { SplatSorter } from './core/sorter';
6
+ export { SplatMesh, type SplatMeshOptions } from './core/mesh';
7
+ export { PlyLoader } from './loaders/ply';
8
+ export { SplatMaterial, type SplatMaterialOptions } from './materials';
9
+ export { BoundingBox } from './utils/bounding';
10
+ export { TextureManager } from './materials/texture';
11
+ export declare const VERSION = "0.1.0";
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,12 @@
1
+ import { B as r, P as s, S as o, c as S, b as l, a as p, T as n } from "./ply-CQ9dyX1o.mjs";
2
+ const a = "0.1.0";
3
+ export {
4
+ r as BoundingBox,
5
+ s as PlyLoader,
6
+ o as SplatData,
7
+ S as SplatMaterial,
8
+ l as SplatMesh,
9
+ p as SplatSorter,
10
+ n as TextureManager,
11
+ a as VERSION
12
+ };