@speridlabs/visus 0.2.0 → 0.3.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.
Files changed (2) hide show
  1. package/README.md +85 -117
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,155 +1,123 @@
1
- # Visus - Gaussian Splatting for Three.js
1
+ # Visus
2
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.
3
+ ![Visus Demo](./public/demo.png)
4
4
 
5
- ## Installation
5
+ **High‑performance Gaussian Splatting** (3DGS) for [Three.js](https://threejs.org/) and React‑Three‑Fiber.
6
+ Drop in a `SplatMesh` or `<Splat>` component, feed it a `.ply`, and render millions of splats with correct transparency and minimal overhead.
7
+
8
+ ---
9
+
10
+ ## 🚀 Installation
6
11
 
7
12
  ```bash
8
- # Using npm
9
- npm install visus
13
+ # npm
14
+ npm install @speridlabs/visus three
10
15
 
11
- # Using yarn
12
- yarn add visus
16
+ # yarn
17
+ yarn add @speridlabs/visus three
18
+
19
+ # pnpm
20
+ pnpm add @speridlabs/visus three
13
21
 
14
- # Using pnpm
15
- pnpm add visus
16
22
  ```
17
23
 
18
- ## Key Features
24
+ > Visus treats Three.js as a peer dependency—make sure it's installed alongside.
25
+
26
+ ---
19
27
 
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.
28
+ ## 🔑 Key Features
27
29
 
28
- ## Basic Usage
30
+ * **Mesh‑like API**: `new SplatMesh(data, options)` behaves like a `THREE.Mesh`.
31
+ * **React wrapper**: `<Splat plyUrl="..." splatOptions={{…}} />` for R3F apps.
32
+ * **Web Worker sorting**: non‑blocking depth sort for correct transparency.
33
+ * **GPU instancing**: draw hundreds of splats in a single call.
34
+ * **Packed textures**: compact quaternion & scale storage.
35
+ * **Shader culling**: early discards, premultiplied alpha.
29
36
 
30
- ```typescript
31
- // main.ts
37
+ ---
38
+
39
+ ## 🎯 Quickstart
40
+
41
+ ### Plain Three.js
42
+
43
+ ```js
32
44
  import * as THREE from 'three';
33
45
  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
- );
46
+ import { PlyLoader, SplatMesh } from '@speridlabs/visus';
47
+
48
+ const scene = new THREE.Scene();
49
+ const camera = new THREE.PerspectiveCamera(75, window.innerWidth/window.innerHeight, 0.1, 100);
44
50
  camera.position.set(0, 1, 3);
45
51
 
46
52
  const renderer = new THREE.WebGLRenderer({ antialias: true });
47
53
  renderer.setSize(window.innerWidth, window.innerHeight);
48
- renderer.setAnimationLoop(animate);
49
54
  document.body.appendChild(renderer.domElement);
50
55
 
51
56
  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
57
 
99
- // 5. Animation Loop
100
- function animate() {
101
- controls.update(); // Required if damping is enabled
102
- renderer.render(scene, camera);
103
- }
58
+ (async () => {
59
+ const data = await new PlyLoader().loadAsync('/sample.ply');
60
+ const mesh = new SplatMesh(data, { autoSort: true });
61
+ scene.add(mesh);
62
+ })();
104
63
 
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);
64
+ renderer.setAnimationLoop(() => {
65
+ controls.update();
66
+ renderer.render(scene, camera);
110
67
  });
111
68
  ```
112
69
 
113
- _(See `examples/main.ts` for a more complete example setup)_
70
+ ### React‑Three‑Fiber (R3F)
71
+
72
+ ```tsx
73
+ import React from 'react';
74
+ import { Canvas } from '@react-three/fiber';
75
+ import { Splat } from '@speridlabs/visus/react';
76
+
77
+ export default function App() {
78
+ return (
79
+ <Canvas camera={{ position: [0, 1, 3] }}>
80
+ <ambientLight />
81
+ <Splat plyUrl="/sample.ply" splatOptions={{ autoSort: true }} />
82
+ </Canvas>
83
+ );
84
+ }
85
+ ```
114
86
 
115
- ## API Overview
87
+ ---
116
88
 
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.
89
+ ## 📦 API Overview
124
90
 
125
- ## Performance Optimizations
91
+ | Export | Description |
92
+ | -------------- | -------------------------------------------------------------- |
93
+ | `PlyLoader` | `.loadAsync(url): Promise<SplatData>` |
94
+ | `SplatData` | Raw buffers of positions, rotations, scales, colors, opacities |
95
+ | `SplatMesh` | `new SplatMesh(data, options?)` → a `THREE.Mesh` |
96
+ | `SplatOptions` | `{ autoSort?: boolean; /* … */ }` |
97
+ | `Splat` | React component wrapping `SplatMesh` |
98
+ | `VERSION` | Library version string |
126
99
 
127
- Visus employs several techniques documented in `Optimizations.md` to achieve real-time performance:
100
+ ---
128
101
 
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.
102
+ ## 🔧 Performance Highlights
134
103
 
135
- ## Future Development / Roadmap
104
+ * **Off‑thread sorting** via Web Worker
105
+ * **Instanced draw calls** for minimal CPU overhead
106
+ * **Packed data textures** reduce memory bandwidth
107
+ * **Shader‑level early exit** for invisible splats
136
108
 
137
- Based on the analysis in `Optimizations.md`, potential future enhancements include:
109
+ ---
138
110
 
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.
111
+ ## 🤝 Contributing
146
112
 
147
- ## Contributing
113
+ 1. Fork & clone
114
+ 2. `pnpm install`
115
+ 3. `pnpm lint && pnpm build`
116
+ 4. Open a PR!
148
117
 
149
- Contributions are welcome! If you find a bug or have a feature request, please open an issue on the GitHub repository.
118
+ ---
150
119
 
151
- For pull requests, please ensure your code adheres to the project's linting (`pnpm lint`) and formatting (`pnpm format`) standards.
120
+ ## 📄 License
152
121
 
153
- ## License
122
+ Apache 2.0 © Sperid Labs
154
123
 
155
- Visus is licensed under the [Apache License 2.0](LICENSE).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@speridlabs/visus",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "A web package for threejs that enables real time rendering of optimized 3DGS (Gaussian Splatting)",
5
5
  "types": "dist/main.d.ts",
6
6
  "main": "dist/main.umd.js",