@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.
- package/README.md +85 -117
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,155 +1,123 @@
|
|
|
1
|
-
# Visus
|
|
1
|
+
# Visus
|
|
2
2
|
|
|
3
|
-
Visus
|
|
3
|
+

|
|
4
4
|
|
|
5
|
-
|
|
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
|
-
#
|
|
9
|
-
npm install visus
|
|
13
|
+
# npm
|
|
14
|
+
npm install @speridlabs/visus three
|
|
10
15
|
|
|
11
|
-
#
|
|
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
|
-
|
|
24
|
+
> Visus treats Three.js as a peer dependency—make sure it's installed alongside.
|
|
25
|
+
|
|
26
|
+
---
|
|
19
27
|
|
|
20
|
-
|
|
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
|
-
|
|
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
|
-
|
|
31
|
-
|
|
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
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
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
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
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
|
-
|
|
87
|
+
---
|
|
116
88
|
|
|
117
|
-
|
|
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
|
-
|
|
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
|
-
|
|
100
|
+
---
|
|
128
101
|
|
|
129
|
-
|
|
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
|
-
|
|
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
|
-
|
|
109
|
+
---
|
|
138
110
|
|
|
139
|
-
|
|
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
|
-
|
|
113
|
+
1. Fork & clone
|
|
114
|
+
2. `pnpm install`
|
|
115
|
+
3. `pnpm lint && pnpm build`
|
|
116
|
+
4. Open a PR!
|
|
148
117
|
|
|
149
|
-
|
|
118
|
+
---
|
|
150
119
|
|
|
151
|
-
|
|
120
|
+
## 📄 License
|
|
152
121
|
|
|
153
|
-
|
|
122
|
+
Apache 2.0 © Sperid Labs
|
|
154
123
|
|
|
155
|
-
Visus is licensed under the [Apache License 2.0](LICENSE).
|
package/package.json
CHANGED