@null3d/splats 0.0.0-stage → 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/LICENSE-APACHE +176 -0
- package/LICENSE-MIT +21 -0
- package/README.md +55 -2
- package/THIRD-PARTY-NOTICES.txt +63 -0
- package/dist/splats.wasm +0 -0
- package/lib/chunks.d.ts +74 -0
- package/lib/chunks.js +170 -0
- package/lib/coverage.d.ts +18 -0
- package/lib/coverage.js +208 -0
- package/lib/feature.d.ts +10 -0
- package/lib/feature.js +39 -0
- package/lib/format.d.ts +35 -0
- package/lib/format.js +53 -0
- package/lib/gltf.d.ts +9 -0
- package/lib/gltf.js +174 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +10 -0
- package/lib/pack.d.ts +34 -0
- package/lib/pack.js +60 -0
- package/lib/select-reference.d.ts +12 -0
- package/lib/select-reference.js +103 -0
- package/lib/select-task.d.ts +65 -0
- package/lib/select-task.js +200 -0
- package/lib/select.d.ts +41 -0
- package/lib/select.js +145 -0
- package/lib/splats-mesh.wgsl-material-glsl-0-01097b38ab28a3d5.js +24 -0
- package/lib/splats-mesh.wgsl-material-glsl-1-3f27ff0f14b7cdd2.js +24 -0
- package/lib/splats-mesh.wgsl-material-glsl-2-d471bfaf3a580318.js +24 -0
- package/lib/splats-mesh.wgsl-material-glsl-3-e048b0d077060953.js +24 -0
- package/lib/splats-mesh.wgsl-material-wgsl-0-c529a49353714424.js +24 -0
- package/lib/splats-mesh.wgsl-material-wgsl-2-ec594872c7d3fbf6.js +24 -0
- package/lib/splats-mesh.wgsl.d.ts +6 -0
- package/lib/splats-mesh.wgsl.js +36 -0
- package/lib/splats.wgsl-material-glsl-0-32dc5311875620e4.js +24 -0
- package/lib/splats.wgsl-material-glsl-1-da80dc94627cf770.js +24 -0
- package/lib/splats.wgsl-material-glsl-2-fb7895ef8b78d665.js +24 -0
- package/lib/splats.wgsl-material-glsl-3-b8800106bf9b5770.js +24 -0
- package/lib/splats.wgsl-material-glsl-64-9f7d0841d0ac147d.js +24 -0
- package/lib/splats.wgsl-material-glsl-65-fbc638499588c846.js +24 -0
- package/lib/splats.wgsl-material-glsl-66-3c49fd84ca72bada.js +24 -0
- package/lib/splats.wgsl-material-glsl-67-5aabadfe22c2f13c.js +24 -0
- package/lib/splats.wgsl-material-wgsl-0-eef591a67552ad7e.js +24 -0
- package/lib/splats.wgsl-material-wgsl-2-15569422a33203f4.js +24 -0
- package/lib/splats.wgsl-material-wgsl-64-769cd6ac619835c2.js +24 -0
- package/lib/splats.wgsl-material-wgsl-66-f1515cd808e3a573.js +24 -0
- package/lib/splats.wgsl.d.ts +14 -0
- package/lib/splats.wgsl.js +42 -0
- package/lib/spz-write.d.ts +9 -0
- package/lib/spz-write.js +133 -0
- package/lib/spz.d.ts +9 -0
- package/lib/spz.js +240 -0
- package/lib/stream.d.ts +126 -0
- package/lib/stream.js +304 -0
- package/lib/system.d.ts +110 -0
- package/lib/system.js +498 -0
- package/lib/version.d.ts +1 -0
- package/lib/version.js +3 -0
- package/package.json +56 -5
package/LICENSE-APACHE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
package/LICENSE-MIT
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ramesh Nair
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,56 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Gaussian splats for null3D
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@null3d/splats` draws Gaussian splats in a null3D sketch: clouds of soft, colored ellipsoids from
|
|
4
|
+
a scan or a training run. It reads SPZ files, splat streams and glTF models that carry
|
|
5
|
+
`KHR_gaussian_splatting`. A large cloud gets detail levels and a budget that follows the quality
|
|
6
|
+
preset and the GPU path, and the splats mix with the scene's meshes by depth. A stream downloads
|
|
7
|
+
only the chunks that the view needs, so a large cloud draws before its whole file has arrived.
|
|
8
|
+
|
|
9
|
+
## Use
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { defineSketch } from '@null3d/engine';
|
|
13
|
+
import { createSplats } from '@null3d/splats';
|
|
14
|
+
|
|
15
|
+
export default defineSketch(async (ctx) => {
|
|
16
|
+
const camera = ctx.scene.createPerspectiveCamera({ position: [0, 1.5, 4], target: [0, 0, 0] });
|
|
17
|
+
ctx.scene.setActiveCamera(camera);
|
|
18
|
+
const splats = await createSplats(ctx, { url: '/scans/garden.spz' });
|
|
19
|
+
await splats.ready;
|
|
20
|
+
const eye = [0, 0, 0];
|
|
21
|
+
return {
|
|
22
|
+
onUpdate() {
|
|
23
|
+
camera.getPosition(eye);
|
|
24
|
+
splats.update(eye);
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Importing the package also registers the glTF reader, so
|
|
31
|
+
`assets.loadGltf('/scans/room.glb')` loads a `KHR_gaussian_splatting` model with no other call.
|
|
32
|
+
|
|
33
|
+
## Costs and limits
|
|
34
|
+
|
|
35
|
+
- One draw for the whole cloud. The engine culls the rows and sorts them back to front on its job
|
|
36
|
+
workers, on WebGPU and WebGL2. The splats draw unlit: each pixel is a fade and a blend, with no
|
|
37
|
+
lights, shadows or reflections.
|
|
38
|
+
- A chunk far from the camera draws a prefix of its splats, and the prefix grows the splats it
|
|
39
|
+
keeps by the share of the chunk's surface that it leaves uncovered, which the add-on measures as
|
|
40
|
+
it cuts the chunk. A scan's colors are its photographs', so show one
|
|
41
|
+
with `post.set({ toneMapping: 'none' })`.
|
|
42
|
+
- A splat stream is an index of chunk files: read the index first, then fetch the chunks that the
|
|
43
|
+
view asks for. `chunkSplats` and `encodeSpz` make the files, and `parseStreamIndex` reads an
|
|
44
|
+
index without a sketch.
|
|
45
|
+
- The batch holds the budget's rows, 56 bytes each. The preset draws up to 100,000 splats on Low and
|
|
46
|
+
800,000 on Ultra, half those counts on WebGL2, and the frame-budget governor lowers them again.
|
|
47
|
+
- The color is the first spherical-harmonic band's. Higher bands, which change a color with the
|
|
48
|
+
view, are ignored, which the glTF extension allows.
|
|
49
|
+
- A glTF model draws its splats in the file's order inside each part; use an SPZ file for a large
|
|
50
|
+
cloud, whose splats the engine sorts one by one.
|
|
51
|
+
- Splats cast no shadow and receive none.
|
|
52
|
+
|
|
53
|
+
## Licence
|
|
54
|
+
|
|
55
|
+
MIT OR Apache-2.0, the engine's licences. See `LICENSE-MIT` and `LICENSE-APACHE` at the repository
|
|
56
|
+
root.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
Third-party code in @null3d/splats
|
|
2
|
+
|
|
3
|
+
The @null3d/splats package ships code from the projects below. Each section names the files
|
|
4
|
+
that hold the code, its licence, and the notices that the licence asks a copy to carry.
|
|
5
|
+
|
|
6
|
+
A build with the null3D Vite plugin writes this text into null3d-third-party-notices.txt beside
|
|
7
|
+
the page, after the engine's own notices. Keep that file with the build when you publish it, or
|
|
8
|
+
show its text in your game's credits.
|
|
9
|
+
|
|
10
|
+
==============================================================================
|
|
11
|
+
Rust crates in the splat selection (dist/splats.wasm)
|
|
12
|
+
==============================================================================
|
|
13
|
+
|
|
14
|
+
The splat selection is compiled from Rust with these crates. The Rust core library is offered under
|
|
15
|
+
the MIT License or the Apache License 2.0, and libm under the MIT License. null3D takes both
|
|
16
|
+
under the MIT License.
|
|
17
|
+
|
|
18
|
+
- The Rust core library: Copyright (c) The Rust Project Contributors
|
|
19
|
+
- libm 0.2.16, the float functions that the core library leaves out: Copyright (c) 2018
|
|
20
|
+
Jorge Aparicio
|
|
21
|
+
|
|
22
|
+
Portions of libm are derived from third-party works licensed under terms compatible with the
|
|
23
|
+
MIT License:
|
|
24
|
+
|
|
25
|
+
* musl libc https://www.musl-libc.org/. This library contains the following copyright:
|
|
26
|
+
|
|
27
|
+
Copyright © 2005-2020 Rich Felker, et al.
|
|
28
|
+
|
|
29
|
+
* The CORE-MATH project https://core-math.gitlabpages.inria.fr/. CORE-MATH routines are
|
|
30
|
+
available under the MIT license on a per-file basis.
|
|
31
|
+
|
|
32
|
+
The musl libc COPYRIGHT file also includes the following notice relevant to math portions of
|
|
33
|
+
the library:
|
|
34
|
+
|
|
35
|
+
Much of the math library code (src/math/* and src/complex/*) is
|
|
36
|
+
Copyright © 1993,2004 Sun Microsystems or
|
|
37
|
+
Copyright © 2003-2011 David Schultz or
|
|
38
|
+
Copyright © 2003-2009 Steven G. Kargl or
|
|
39
|
+
Copyright © 2003-2009 Bruce D. Evans or
|
|
40
|
+
Copyright © 2008 Stephen L. Moshier or
|
|
41
|
+
Copyright © 2017-2018 Arm Limited
|
|
42
|
+
and labelled as such in comments in the individual source files. All
|
|
43
|
+
have been licensed under extremely permissive terms.
|
|
44
|
+
|
|
45
|
+
The MIT License
|
|
46
|
+
|
|
47
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
48
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
49
|
+
in the Software without restriction, including without limitation the rights
|
|
50
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
51
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
52
|
+
furnished to do so, subject to the following conditions:
|
|
53
|
+
|
|
54
|
+
The above copyright notice and this permission notice shall be included in
|
|
55
|
+
all copies or substantial portions of the Software.
|
|
56
|
+
|
|
57
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
58
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
59
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
60
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
61
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
62
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
63
|
+
THE SOFTWARE.
|
package/dist/splats.wasm
ADDED
|
Binary file
|
package/lib/chunks.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { SplatData } from './format.js';
|
|
2
|
+
/**
|
|
3
|
+
* One chunk of a cloud, with its splats in the order that a coarser level keeps.
|
|
4
|
+
*
|
|
5
|
+
* @category api/splats
|
|
6
|
+
*/
|
|
7
|
+
export interface SplatChunk {
|
|
8
|
+
/** The center of the splats' bounds, in meters. */
|
|
9
|
+
readonly center: readonly [number, number, number];
|
|
10
|
+
/** The distance from the center to the farthest splat, in meters. */
|
|
11
|
+
readonly radius: number;
|
|
12
|
+
/** The number of splats. */
|
|
13
|
+
readonly count: number;
|
|
14
|
+
/** The centers, 3 floats each, most important first. */
|
|
15
|
+
readonly positions: Float32Array;
|
|
16
|
+
/** The rotations as unit quaternions, 4 floats each. */
|
|
17
|
+
readonly rotations: Float32Array;
|
|
18
|
+
/** The principal standard deviations, 3 floats each. */
|
|
19
|
+
readonly scales: Float32Array;
|
|
20
|
+
/** Linear RGBA colors, 4 floats each. */
|
|
21
|
+
readonly colors: Float32Array;
|
|
22
|
+
/**
|
|
23
|
+
* The share of the chunk's surface that its first splats cover: index 0 is the whole chunk,
|
|
24
|
+
* and each next index keeps a prefix the square root of two times shorter. A coarse level grows
|
|
25
|
+
* its splats by what its prefix leaves uncovered.
|
|
26
|
+
*/
|
|
27
|
+
readonly coverage: Float32Array;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A cloud cut into chunks, and the splits that its levels take.
|
|
31
|
+
*
|
|
32
|
+
* @category api/splats
|
|
33
|
+
*/
|
|
34
|
+
export interface SplatChunks {
|
|
35
|
+
/** The chunks that the cut made. */
|
|
36
|
+
readonly chunks: readonly SplatChunk[];
|
|
37
|
+
/** The number of splats, which the chunks together hold. */
|
|
38
|
+
readonly total: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Hands the thread back between chunks, so a large cloud never holds up a frame.
|
|
42
|
+
*
|
|
43
|
+
* @category api/splats
|
|
44
|
+
*/
|
|
45
|
+
export type Yielder = () => Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* How a cloud is cut, and what the caller sees as it is.
|
|
48
|
+
*
|
|
49
|
+
* @category api/splats
|
|
50
|
+
*/
|
|
51
|
+
export interface ChunkOptions {
|
|
52
|
+
/** Runs between chunks, which lets the caller hand the thread back. */
|
|
53
|
+
readonly yieldTo?: Yielder;
|
|
54
|
+
/** Sees each chunk as it is ready, so a draw can take the cloud one chunk at a time. */
|
|
55
|
+
readonly onChunk?: (chunk: SplatChunk) => void;
|
|
56
|
+
/** The splats that a chunk holds, at about. The default is 25,000. */
|
|
57
|
+
readonly splatsPerChunk?: number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Cuts a cloud into chunks of nearby splats, each ordered so that its first splats cover the most
|
|
61
|
+
* surface. `yieldTo` runs between chunks, and `onChunk` sees each chunk as it is ready: a draw that
|
|
62
|
+
* takes them one by one appears coarse to fine, and a large cloud never holds up a frame.
|
|
63
|
+
*
|
|
64
|
+
* @category api/splats
|
|
65
|
+
*/
|
|
66
|
+
export declare function chunkSplats(data: SplatData, options?: ChunkOptions): Promise<SplatChunks>;
|
|
67
|
+
/**
|
|
68
|
+
* One cloud's splats, most important first, around the bounds that its reader gives. A streamed
|
|
69
|
+
* chunk arrives as a cloud of its own, whose chunk keeps the bounds that the stream's index names,
|
|
70
|
+
* so the selection can place it before any of its splats have loaded.
|
|
71
|
+
*
|
|
72
|
+
* @category api/splats
|
|
73
|
+
*/
|
|
74
|
+
export declare function chunkFrom(data: SplatData, center: readonly [number, number, number], radius: number): SplatChunk;
|
package/lib/chunks.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// A cloud cut into chunks, each of them in the order that a coarser level keeps: a chunk's first
|
|
2
|
+
// splats cover the most surface, so a prefix of the list stands in for the whole chunk from farther
|
|
3
|
+
// away. The draw chooses a prefix for each chunk by its distance, and the engine then sorts and
|
|
4
|
+
// culls the rows that the prefixes fill.
|
|
5
|
+
//
|
|
6
|
+
// The cut follows a grid in space, so a chunk holds nearby splats. That keeps a chunk's depth
|
|
7
|
+
// spread small, which is what makes one distance stand for all of its splats, and it gives the
|
|
8
|
+
// budget a set of independent pieces to leave out when a scene has more splats than draw.
|
|
9
|
+
import { coverageShares } from './coverage.js';
|
|
10
|
+
/**
|
|
11
|
+
* The splats that a chunk aims to hold. A cloud that fills only part of its bounds gives fewer,
|
|
12
|
+
* larger chunks, because its cells hold the splats that fall in them.
|
|
13
|
+
*/
|
|
14
|
+
const CHUNK_SPLATS = 25_000;
|
|
15
|
+
/** The grid cells that one axis may have, so a scene far out never makes tiny cells. */
|
|
16
|
+
const MOST_CELLS_PER_AXIS = 16;
|
|
17
|
+
/**
|
|
18
|
+
* Cuts a cloud into chunks of nearby splats, each ordered so that its first splats cover the most
|
|
19
|
+
* surface. `yieldTo` runs between chunks, and `onChunk` sees each chunk as it is ready: a draw that
|
|
20
|
+
* takes them one by one appears coarse to fine, and a large cloud never holds up a frame.
|
|
21
|
+
*
|
|
22
|
+
* @category api/splats
|
|
23
|
+
*/
|
|
24
|
+
export async function chunkSplats(data, options = {}) {
|
|
25
|
+
const { count } = data;
|
|
26
|
+
if (count === 0)
|
|
27
|
+
return { chunks: [], total: 0 };
|
|
28
|
+
const { yieldTo, onChunk } = options;
|
|
29
|
+
const bounds = boundsOf(data);
|
|
30
|
+
const cellSplats = Math.min(count, options.splatsPerChunk ?? CHUNK_SPLATS);
|
|
31
|
+
// Enough cells on a side that the cells of the bounds hold about one chunk's load each. The
|
|
32
|
+
// cube root follows the cloud's size and that load, so a bigger cloud makes smaller chunks
|
|
33
|
+
// rather than one chunk of the whole.
|
|
34
|
+
const perAxis = Math.max(1, Math.min(MOST_CELLS_PER_AXIS, Math.ceil((count / cellSplats) ** (1 / 3))));
|
|
35
|
+
const cells = perAxis ** 3;
|
|
36
|
+
const extent = [0, 1, 2].map((k) => bounds.max[k] - bounds.min[k]);
|
|
37
|
+
// Each axis is cut into `perAxis` equal widths across the bounds, so a splat's cell follows its
|
|
38
|
+
// place in the cloud and nothing else.
|
|
39
|
+
const scale = [0, 1, 2].map((k) => (perAxis / Math.max(extent[k], 1e-9)));
|
|
40
|
+
const cellOf = (i) => {
|
|
41
|
+
const position = data.positions;
|
|
42
|
+
const x = Math.min(perAxis - 1, Math.floor((position[i * 3] - bounds.min[0]) * scale[0]));
|
|
43
|
+
const y = Math.min(perAxis - 1, Math.floor((position[i * 3 + 1] - bounds.min[1]) * scale[1]));
|
|
44
|
+
const z = Math.min(perAxis - 1, Math.floor((position[i * 3 + 2] - bounds.min[2]) * scale[2]));
|
|
45
|
+
return x + perAxis * (y + perAxis * z);
|
|
46
|
+
};
|
|
47
|
+
// A counting sort puts each splat in its cell, so the cut costs one pass over the cloud.
|
|
48
|
+
const totals = new Uint32Array(cells + 1);
|
|
49
|
+
for (let i = 0; i < count; i++) {
|
|
50
|
+
const cell = cellOf(i) + 1;
|
|
51
|
+
totals[cell] = totals[cell] + 1;
|
|
52
|
+
}
|
|
53
|
+
for (let c = 0; c < cells; c++)
|
|
54
|
+
totals[c + 1] = totals[c + 1] + totals[c];
|
|
55
|
+
const starts = totals.slice();
|
|
56
|
+
const place = new Uint32Array(count);
|
|
57
|
+
for (let i = 0; i < count; i++) {
|
|
58
|
+
const cell = cellOf(i);
|
|
59
|
+
const at = starts[cell];
|
|
60
|
+
place[at] = i;
|
|
61
|
+
starts[cell] = at + 1;
|
|
62
|
+
}
|
|
63
|
+
const chunks = [];
|
|
64
|
+
for (let c = 0; c < cells; c++) {
|
|
65
|
+
const first = totals[c];
|
|
66
|
+
const last = totals[c + 1];
|
|
67
|
+
if (last === first)
|
|
68
|
+
continue;
|
|
69
|
+
const chunk = chunkOf(data, place.subarray(first, last));
|
|
70
|
+
chunks.push(chunk);
|
|
71
|
+
onChunk?.(chunk);
|
|
72
|
+
await yieldTo?.();
|
|
73
|
+
}
|
|
74
|
+
// A level's prefix is more useful the more of a chunk it keeps, so the biggest chunks draw
|
|
75
|
+
// first when the budget cannot hold them all.
|
|
76
|
+
return { chunks, total: count };
|
|
77
|
+
}
|
|
78
|
+
/** The cloud's bounds, and the center that the cut works with. */
|
|
79
|
+
function boundsOf(data) {
|
|
80
|
+
const min = [Infinity, Infinity, Infinity];
|
|
81
|
+
const max = [-Infinity, -Infinity, -Infinity];
|
|
82
|
+
const { positions, count } = data;
|
|
83
|
+
for (let i = 0; i < count; i++)
|
|
84
|
+
for (let k = 0; k < 3; k++) {
|
|
85
|
+
const value = positions[i * 3 + k];
|
|
86
|
+
if (value < min[k])
|
|
87
|
+
min[k] = value;
|
|
88
|
+
if (value > max[k])
|
|
89
|
+
max[k] = value;
|
|
90
|
+
}
|
|
91
|
+
return { min, max };
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* One cloud's splats, most important first, around the bounds that its reader gives. A streamed
|
|
95
|
+
* chunk arrives as a cloud of its own, whose chunk keeps the bounds that the stream's index names,
|
|
96
|
+
* so the selection can place it before any of its splats have loaded.
|
|
97
|
+
*
|
|
98
|
+
* @category api/splats
|
|
99
|
+
*/
|
|
100
|
+
export function chunkFrom(data, center, radius) {
|
|
101
|
+
const which = new Uint32Array(data.count);
|
|
102
|
+
for (let i = 0; i < data.count; i++)
|
|
103
|
+
which[i] = i;
|
|
104
|
+
return buildChunk(data, which, center, radius);
|
|
105
|
+
}
|
|
106
|
+
/** One chunk's splats, most important first, and the bounds that its splats make. */
|
|
107
|
+
function chunkOf(data, which) {
|
|
108
|
+
const min = [Infinity, Infinity, Infinity];
|
|
109
|
+
const max = [-Infinity, -Infinity, -Infinity];
|
|
110
|
+
for (let k = 0; k < which.length; k++) {
|
|
111
|
+
const i = which[k];
|
|
112
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
113
|
+
const value = data.positions[i * 3 + axis];
|
|
114
|
+
if (value < min[axis])
|
|
115
|
+
min[axis] = value;
|
|
116
|
+
if (value > max[axis])
|
|
117
|
+
max[axis] = value;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const center = [
|
|
121
|
+
(min[0] + max[0]) / 2,
|
|
122
|
+
(min[1] + max[1]) / 2,
|
|
123
|
+
(min[2] + max[2]) / 2,
|
|
124
|
+
];
|
|
125
|
+
let radius = 0;
|
|
126
|
+
for (let k = 0; k < which.length; k++) {
|
|
127
|
+
const i = which[k];
|
|
128
|
+
const dx = data.positions[i * 3] - center[0];
|
|
129
|
+
const dy = data.positions[i * 3 + 1] - center[1];
|
|
130
|
+
const dz = data.positions[i * 3 + 2] - center[2];
|
|
131
|
+
radius = Math.max(radius, Math.sqrt(dx * dx + dy * dy + dz * dz));
|
|
132
|
+
}
|
|
133
|
+
return buildChunk(data, which, center, radius);
|
|
134
|
+
}
|
|
135
|
+
/** The splats that `which` names, copied in importance order around the bounds that the caller gives. */
|
|
136
|
+
function buildChunk(data, which, center, radius) {
|
|
137
|
+
const count = which.length;
|
|
138
|
+
// A splat's importance is the surface that it covers. A scan's splats are mostly flat discs
|
|
139
|
+
// whose thickness says nothing of the surface, so their volume would rank them almost at random.
|
|
140
|
+
const weight = new Float32Array(count);
|
|
141
|
+
for (let k = 0; k < count; k++)
|
|
142
|
+
weight[k] = coverOf(data.scales, data.colors, which[k]);
|
|
143
|
+
const order = new Uint32Array(count);
|
|
144
|
+
for (let k = 0; k < count; k++)
|
|
145
|
+
order[k] = k;
|
|
146
|
+
order.sort((a, b) => weight[b] - weight[a]);
|
|
147
|
+
const positions = new Float32Array(count * 3);
|
|
148
|
+
const rotations = new Float32Array(count * 4);
|
|
149
|
+
const scales = new Float32Array(count * 3);
|
|
150
|
+
const colors = new Float32Array(count * 4);
|
|
151
|
+
for (let k = 0; k < count; k++) {
|
|
152
|
+
const i = which[order[k]];
|
|
153
|
+
positions.set(data.positions.subarray(i * 3, i * 3 + 3), k * 3);
|
|
154
|
+
rotations.set(data.rotations.subarray(i * 4, i * 4 + 4), k * 4);
|
|
155
|
+
scales.set(data.scales.subarray(i * 3, i * 3 + 3), k * 3);
|
|
156
|
+
colors.set(data.colors.subarray(i * 4, i * 4 + 4), k * 4);
|
|
157
|
+
}
|
|
158
|
+
const coverage = coverageShares(positions, rotations, scales, colors, count, center, radius);
|
|
159
|
+
return { center, radius, count, positions, rotations, scales, colors, coverage };
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* The surface that splat `i` covers: its opacity times the area of its largest cross-section, the
|
|
163
|
+
* product of its two largest spreads.
|
|
164
|
+
*/
|
|
165
|
+
function coverOf(scales, colors, i) {
|
|
166
|
+
const a = scales[i * 3];
|
|
167
|
+
const b = scales[i * 3 + 1];
|
|
168
|
+
const c = scales[i * 3 + 2];
|
|
169
|
+
return Math.max(a * b, b * c, a * c) * Math.max(colors[i * 4 + 3], 0);
|
|
170
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The share of the chunk's covered cells that its first splats cover, at the prefix lengths that
|
|
3
|
+
* `coveragePrefix` names: index 0 is the whole chunk, whose share is 1, and each next index keeps
|
|
4
|
+
* a prefix the square root of two times shorter. The arrays hold the chunk's splats in order.
|
|
5
|
+
*
|
|
6
|
+
* The chunk is seen from three directions, along each axis. In each view, a splat hides the cells
|
|
7
|
+
* under its projected ellipse by its own Gaussian, so a flat splat seen face on covers its disc and
|
|
8
|
+
* one seen edge on a line. A splat narrower than a cell along an axis takes the share of the cell
|
|
9
|
+
* that it covers along that axis, so a crowd of tiny splats covers a cell as their areas add up.
|
|
10
|
+
*/
|
|
11
|
+
export declare function coverageShares(positions: Float32Array, rotations: Float32Array, scales: Float32Array, colors: Float32Array, count: number, center: readonly [number, number, number], radius: number): Float32Array;
|
|
12
|
+
/** The length of the prefix that index `k` of a chunk's coverage shares measures. */
|
|
13
|
+
export declare function coveragePrefix(count: number, k: number): number;
|
|
14
|
+
/**
|
|
15
|
+
* The share of the chunk's covered cells that its first `kept` splats cover, read between the
|
|
16
|
+
* recorded prefix lengths along the halving of the prefix.
|
|
17
|
+
*/
|
|
18
|
+
export declare function coverageAt(shares: Float32Array, count: number, kept: number): number;
|