@viggle/splat-engine-three 0.4.0 → 0.5.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/CHANGELOG.md +9 -0
- package/README.md +7 -3
- package/dist/chunks/{chunk-SASRTGRD.js → chunk-NNGE5LDC.js} +340 -39
- package/dist/chunks/{chunk-SASRTGRD.js.map → chunk-NNGE5LDC.js.map} +4 -4
- package/dist/index.js +3 -1
- package/dist/types/environment.d.ts +3 -2
- package/dist/types/index.d.ts +1 -0
- package/dist/types/loader/environment/compressed-ply.d.ts +40 -0
- package/dist/types/loader/environment/ply.d.ts +3 -0
- package/dist/types/loader/shared/asset-loader.d.ts +3 -2
- package/dist/types/loader/shared/sog.d.ts +5 -0
- package/dist/types/three/loaders.d.ts +4 -2
- package/dist/types/three/sog-loader.d.ts +50 -0
- package/dist/webgpu.js +3 -1
- package/dist/webgpu.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
Splat-scene loading level with `@viggle/splat-engine` 0.3.2. Additions only; nothing an existing app calls changes behaviour.
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- **`.compressed.ply`** - PlayCanvas's quantised PLY, as SuperSplat and splat-transform write it - reads everywhere a `.ply` does: `SplatPLYLoader`, `Environment.load`, `loadSplatAsset`, `loadSplatSource`, `decodeSplatFile` and `parseGaussianPly`. The layout is told by the header, so a renamed file reads too. Decoded with the arithmetic of PlayCanvas's `GSplatCompressedData.decompress`, and bit-identical to it on 12- and 18-float chunk layouts, with and without an `sh` element (which is skipped, as `f_rest_*` is for the float PLY).
|
|
10
|
+
- **`SplatSOGLoader`**, a `THREE.Loader` for SOG scenes: a `.sog` bundle, or an unbundled `meta.json` whose images it fetches from beside it. Every file goes through a `FileLoader`, so the `LoadingManager`, `setPath`, request headers and credentials mode apply to the images too. Same splats as `loadSplatSource`.
|
|
11
|
+
|
|
3
12
|
## 0.4.0
|
|
4
13
|
|
|
5
14
|
Splat objects can hide one another where they overlap. The setting is off by default; with it off, every frame draws exactly as in 0.3.0.
|
package/README.md
CHANGED
|
@@ -56,13 +56,17 @@ Get character `.vsplat` files and animation `.glb` files from https://viggle.ai/
|
|
|
56
56
|
|
|
57
57
|
### Loaders
|
|
58
58
|
|
|
59
|
-
All
|
|
59
|
+
All of them extend `THREE.Loader`, so `load` / `loadAsync`, `setPath`, `setRequestHeader`, `setWithCredentials` and a `LoadingManager` work as usual. Each also has `parseAsync(arrayBuffer)` for bytes you already hold.
|
|
60
60
|
|
|
61
61
|
| Loader | Reads | Gives you |
|
|
62
62
|
|---|---|---|
|
|
63
63
|
| `VSplatLoader` | `.vsplat` character bundles | `SplatCharacter` |
|
|
64
64
|
| `SplatClipLoader` | MetaHuman-rig `.glb` animations | `SplatClip` |
|
|
65
|
-
| `SplatPLYLoader` |
|
|
65
|
+
| `SplatPLYLoader` | 3D Gaussian Splatting `.ply`, uncompressed or PlayCanvas's `.compressed.ply` | `SplatMesh` |
|
|
66
|
+
| `SplatSPZLoader` | `.spz` (versions 1-4) | `SplatMesh` |
|
|
67
|
+
| `SplatSOGLoader` | SOG: a `.sog` bundle, or an unbundled `meta.json` (its images are fetched from beside it) | `SplatMesh` |
|
|
68
|
+
|
|
69
|
+
Streamed LOD bundles (`lod-meta.json`) pick their detail level from the engine's camera every frame, so they load through [`Environment.loadLodBundle`](#the-game-engine-layer) rather than a loader.
|
|
66
70
|
|
|
67
71
|
### `SplatCharacter`
|
|
68
72
|
|
|
@@ -180,7 +184,7 @@ Ported, and checked against the PlayCanvas build by the A/B suite (see [Verifica
|
|
|
180
184
|
- Characters - loading `.vsplat` bundles, position / rotation / scale, tint (mix and multiply), colour grade, opacity, the feet-to-head reveal, cut pieces, colour hooks
|
|
181
185
|
- Animation - GLB clips, crossfade, layers with bone masks, root motion
|
|
182
186
|
- Rig - pose evaluation, bone-length scaling (`setBoneStretch`, stretching and shrinking)
|
|
183
|
-
- Splat scenes - `.ply
|
|
187
|
+
- Splat scenes - `.ply` (uncompressed and `.compressed.ply`), `.spz` (versions 1-4), SOG, and streamed LOD bundles (`Environment.loadLodBundle`)
|
|
184
188
|
- `SunLight`, `SkyLight`, `PointLight` (against the version this port started from; the current PlayCanvas build has removed them)
|
|
185
189
|
- `SplatRelight` - characters and environments lit through voxel proxies, with sun shadows and point lights
|
|
186
190
|
- `Scene`, `CameraFrame` (tone mapping, bloom, grading, vignette), `PostFX` and `BaseCapturingPass`, `PixelartEffect`, `OutlineEffect`
|
|
@@ -8749,6 +8749,214 @@ var _band = new Float32Array(4);
|
|
|
8749
8749
|
var _sketch = new Float32Array(4);
|
|
8750
8750
|
var _tint = new Float32Array(4);
|
|
8751
8751
|
|
|
8752
|
+
// src/loader/environment/compressed-ply.ts
|
|
8753
|
+
var SH_C02 = 0.28209479177387814;
|
|
8754
|
+
var CHUNK_SPLATS = 256;
|
|
8755
|
+
var CHUNK_RANGE = [
|
|
8756
|
+
"min_x",
|
|
8757
|
+
"min_y",
|
|
8758
|
+
"min_z",
|
|
8759
|
+
"max_x",
|
|
8760
|
+
"max_y",
|
|
8761
|
+
"max_z",
|
|
8762
|
+
"min_scale_x",
|
|
8763
|
+
"min_scale_y",
|
|
8764
|
+
"min_scale_z",
|
|
8765
|
+
"max_scale_x",
|
|
8766
|
+
"max_scale_y",
|
|
8767
|
+
"max_scale_z"
|
|
8768
|
+
];
|
|
8769
|
+
var CHUNK_COLOR = ["min_r", "min_g", "min_b", "max_r", "max_g", "max_b"];
|
|
8770
|
+
var PACKED = ["packed_position", "packed_rotation", "packed_scale", "packed_color"];
|
|
8771
|
+
var TYPE_SIZE = {
|
|
8772
|
+
char: 1,
|
|
8773
|
+
int8: 1,
|
|
8774
|
+
uchar: 1,
|
|
8775
|
+
uint8: 1,
|
|
8776
|
+
short: 2,
|
|
8777
|
+
int16: 2,
|
|
8778
|
+
ushort: 2,
|
|
8779
|
+
uint16: 2,
|
|
8780
|
+
int: 4,
|
|
8781
|
+
int32: 4,
|
|
8782
|
+
uint: 4,
|
|
8783
|
+
uint32: 4,
|
|
8784
|
+
float: 4,
|
|
8785
|
+
float32: 4,
|
|
8786
|
+
double: 8,
|
|
8787
|
+
float64: 8
|
|
8788
|
+
};
|
|
8789
|
+
function parseElements(headerLines) {
|
|
8790
|
+
const elements = [];
|
|
8791
|
+
for (const raw of headerLines) {
|
|
8792
|
+
const tokens = raw.trim().split(/\s+/);
|
|
8793
|
+
if (tokens[0] === "element") {
|
|
8794
|
+
elements.push({ name: tokens[1], count: Number.parseInt(tokens[2], 10), props: [], stride: 0 });
|
|
8795
|
+
} else if (tokens[0] === "property") {
|
|
8796
|
+
const el = elements[elements.length - 1];
|
|
8797
|
+
if (!el) throw new Error("[parseCompressedPly] property declared before any element");
|
|
8798
|
+
if (tokens[1] === "list") throw new Error("[parseCompressedPly] list properties are not supported");
|
|
8799
|
+
const size = TYPE_SIZE[tokens[1]];
|
|
8800
|
+
if (!size) throw new Error(`[parseCompressedPly] unknown property type '${tokens[1]}'`);
|
|
8801
|
+
el.props.push({ name: tokens[2], type: tokens[1], offset: el.stride });
|
|
8802
|
+
el.stride += size;
|
|
8803
|
+
}
|
|
8804
|
+
}
|
|
8805
|
+
return elements;
|
|
8806
|
+
}
|
|
8807
|
+
function isCompressedPlyHeader(header) {
|
|
8808
|
+
const elements = parseElementsSafe(header.split("\n"));
|
|
8809
|
+
if (!elements) return false;
|
|
8810
|
+
const vertex = elements.find((e) => e.name === "vertex");
|
|
8811
|
+
return elements.some((e) => e.name === "chunk") && !!vertex && PACKED.every((n) => vertex.props.some((p) => p.name === n));
|
|
8812
|
+
}
|
|
8813
|
+
function parseElementsSafe(lines) {
|
|
8814
|
+
try {
|
|
8815
|
+
return parseElements(lines);
|
|
8816
|
+
} catch {
|
|
8817
|
+
return null;
|
|
8818
|
+
}
|
|
8819
|
+
}
|
|
8820
|
+
var unorm = (value, bits) => {
|
|
8821
|
+
const t = (1 << bits) - 1;
|
|
8822
|
+
return (value & t) / t;
|
|
8823
|
+
};
|
|
8824
|
+
var lerp = (a, b, t) => a * (1 - t) + b * t;
|
|
8825
|
+
function parseCompressedPly(file, headerText, dataStart) {
|
|
8826
|
+
const lines = headerText.split("\n");
|
|
8827
|
+
const format = lines.map((l) => l.trim().split(/\s+/)).find((t) => t[0] === "format");
|
|
8828
|
+
if (!format || format[1] !== "binary_little_endian") {
|
|
8829
|
+
throw new Error(`[parseCompressedPly] unsupported PLY format '${format?.[1]}'; expected binary_little_endian`);
|
|
8830
|
+
}
|
|
8831
|
+
const elements = parseElements(lines);
|
|
8832
|
+
const offsets = /* @__PURE__ */ new Map();
|
|
8833
|
+
let at = dataStart;
|
|
8834
|
+
for (const el of elements) {
|
|
8835
|
+
if (!Number.isFinite(el.count) || el.count < 0) {
|
|
8836
|
+
throw new Error(`[parseCompressedPly] element '${el.name}' count is not a non-negative integer`);
|
|
8837
|
+
}
|
|
8838
|
+
offsets.set(el.name, at);
|
|
8839
|
+
at += el.count * el.stride;
|
|
8840
|
+
}
|
|
8841
|
+
if (at > file.byteLength) {
|
|
8842
|
+
throw new Error(
|
|
8843
|
+
`[parseCompressedPly] truncated: header declares ${at - dataStart} B of data, but only ${file.byteLength - dataStart} B follow it`
|
|
8844
|
+
);
|
|
8845
|
+
}
|
|
8846
|
+
const chunk = elements.find((e) => e.name === "chunk");
|
|
8847
|
+
const vertex = elements.find((e) => e.name === "vertex");
|
|
8848
|
+
const numSplats = vertex.count;
|
|
8849
|
+
if (chunk.count < Math.ceil(numSplats / CHUNK_SPLATS)) {
|
|
8850
|
+
throw new Error(
|
|
8851
|
+
`[parseCompressedPly] ${numSplats} splats need ${Math.ceil(numSplats / CHUNK_SPLATS)} chunks, but the file has ${chunk.count}`
|
|
8852
|
+
);
|
|
8853
|
+
}
|
|
8854
|
+
const column = (el, name, type, required) => {
|
|
8855
|
+
const p = el.props.find((q) => q.name === name);
|
|
8856
|
+
if (!p) {
|
|
8857
|
+
if (required) throw new Error(`[parseCompressedPly] PLY is missing the required ${el.name} property '${name}'`);
|
|
8858
|
+
return -1;
|
|
8859
|
+
}
|
|
8860
|
+
const ok = type === "float" ? p.type === "float" || p.type === "float32" : p.type === "uint" || p.type === "uint32";
|
|
8861
|
+
if (!ok) throw new Error(`[parseCompressedPly] ${el.name} property '${name}' is ${p.type}; expected ${type}`);
|
|
8862
|
+
return p.offset;
|
|
8863
|
+
};
|
|
8864
|
+
const view = new DataView(file);
|
|
8865
|
+
const rangeCols = CHUNK_RANGE.map((n) => column(chunk, n, "float", true));
|
|
8866
|
+
const colorCols = CHUNK_COLOR.map((n) => column(chunk, n, "float", false));
|
|
8867
|
+
const hasColorRange = colorCols.every((c) => c >= 0);
|
|
8868
|
+
const chunkCols = hasColorRange ? [...rangeCols, ...colorCols] : rangeCols;
|
|
8869
|
+
const chunkSize = chunkCols.length;
|
|
8870
|
+
const chunkData = new Float32Array(chunk.count * chunkSize);
|
|
8871
|
+
const chunkBase = offsets.get("chunk");
|
|
8872
|
+
for (let c = 0; c < chunk.count; c++) {
|
|
8873
|
+
const row = chunkBase + c * chunk.stride;
|
|
8874
|
+
for (let k = 0; k < chunkSize; k++) chunkData[c * chunkSize + k] = view.getFloat32(row + chunkCols[k], true);
|
|
8875
|
+
}
|
|
8876
|
+
const [posCol, rotCol, scaleCol, colorCol] = PACKED.map((n) => column(vertex, n, "uint", true));
|
|
8877
|
+
const vertexBase = offsets.get("vertex");
|
|
8878
|
+
const out = {
|
|
8879
|
+
x: new Float32Array(numSplats),
|
|
8880
|
+
y: new Float32Array(numSplats),
|
|
8881
|
+
z: new Float32Array(numSplats),
|
|
8882
|
+
scale_0: new Float32Array(numSplats),
|
|
8883
|
+
scale_1: new Float32Array(numSplats),
|
|
8884
|
+
scale_2: new Float32Array(numSplats),
|
|
8885
|
+
rot_0: new Float32Array(numSplats),
|
|
8886
|
+
rot_1: new Float32Array(numSplats),
|
|
8887
|
+
rot_2: new Float32Array(numSplats),
|
|
8888
|
+
rot_3: new Float32Array(numSplats),
|
|
8889
|
+
f_dc_0: new Float32Array(numSplats),
|
|
8890
|
+
f_dc_1: new Float32Array(numSplats),
|
|
8891
|
+
f_dc_2: new Float32Array(numSplats),
|
|
8892
|
+
opacity: new Float32Array(numSplats)
|
|
8893
|
+
};
|
|
8894
|
+
const SQRT2 = Math.SQRT2;
|
|
8895
|
+
for (let i = 0; i < numSplats; i++) {
|
|
8896
|
+
const row = vertexBase + i * vertex.stride;
|
|
8897
|
+
const ci = Math.floor(i / CHUNK_SPLATS) * chunkSize;
|
|
8898
|
+
const pos = view.getUint32(row + posCol, true);
|
|
8899
|
+
out.x[i] = lerp(chunkData[ci], chunkData[ci + 3], unorm(pos >>> 21, 11));
|
|
8900
|
+
out.y[i] = lerp(chunkData[ci + 1], chunkData[ci + 4], unorm(pos >>> 11, 10));
|
|
8901
|
+
out.z[i] = lerp(chunkData[ci + 2], chunkData[ci + 5], unorm(pos, 11));
|
|
8902
|
+
const rot = view.getUint32(row + rotCol, true);
|
|
8903
|
+
const a = (unorm(rot >>> 20, 10) - 0.5) * SQRT2;
|
|
8904
|
+
const b = (unorm(rot >>> 10, 10) - 0.5) * SQRT2;
|
|
8905
|
+
const c = (unorm(rot, 10) - 0.5) * SQRT2;
|
|
8906
|
+
const m = Math.sqrt(Math.max(0, 1 - (a * a + b * b + c * c)));
|
|
8907
|
+
let qw, qx, qy, qz;
|
|
8908
|
+
switch (rot >>> 30) {
|
|
8909
|
+
case 0:
|
|
8910
|
+
qw = m;
|
|
8911
|
+
qx = a;
|
|
8912
|
+
qy = b;
|
|
8913
|
+
qz = c;
|
|
8914
|
+
break;
|
|
8915
|
+
case 1:
|
|
8916
|
+
qw = a;
|
|
8917
|
+
qx = m;
|
|
8918
|
+
qy = b;
|
|
8919
|
+
qz = c;
|
|
8920
|
+
break;
|
|
8921
|
+
case 2:
|
|
8922
|
+
qw = a;
|
|
8923
|
+
qx = b;
|
|
8924
|
+
qy = m;
|
|
8925
|
+
qz = c;
|
|
8926
|
+
break;
|
|
8927
|
+
default:
|
|
8928
|
+
qw = a;
|
|
8929
|
+
qx = b;
|
|
8930
|
+
qy = c;
|
|
8931
|
+
qz = m;
|
|
8932
|
+
break;
|
|
8933
|
+
}
|
|
8934
|
+
out.rot_0[i] = qw;
|
|
8935
|
+
out.rot_1[i] = qx;
|
|
8936
|
+
out.rot_2[i] = qy;
|
|
8937
|
+
out.rot_3[i] = qz;
|
|
8938
|
+
const scale = view.getUint32(row + scaleCol, true);
|
|
8939
|
+
out.scale_0[i] = lerp(chunkData[ci + 6], chunkData[ci + 9], unorm(scale >>> 21, 11));
|
|
8940
|
+
out.scale_1[i] = lerp(chunkData[ci + 7], chunkData[ci + 10], unorm(scale >>> 11, 10));
|
|
8941
|
+
out.scale_2[i] = lerp(chunkData[ci + 8], chunkData[ci + 11], unorm(scale, 11));
|
|
8942
|
+
const col = view.getUint32(row + colorCol, true);
|
|
8943
|
+
let r = unorm(col >>> 24, 8);
|
|
8944
|
+
let g = unorm(col >>> 16, 8);
|
|
8945
|
+
let bl = unorm(col >>> 8, 8);
|
|
8946
|
+
const alpha = unorm(col, 8);
|
|
8947
|
+
if (hasColorRange) {
|
|
8948
|
+
r = lerp(chunkData[ci + 12], chunkData[ci + 15], r);
|
|
8949
|
+
g = lerp(chunkData[ci + 13], chunkData[ci + 16], g);
|
|
8950
|
+
bl = lerp(chunkData[ci + 14], chunkData[ci + 17], bl);
|
|
8951
|
+
}
|
|
8952
|
+
out.f_dc_0[i] = (r - 0.5) / SH_C02;
|
|
8953
|
+
out.f_dc_1[i] = (g - 0.5) / SH_C02;
|
|
8954
|
+
out.f_dc_2[i] = (bl - 0.5) / SH_C02;
|
|
8955
|
+
out.opacity[i] = alpha <= 0 ? -40 : alpha >= 1 ? 40 : -Math.log(1 / alpha - 1);
|
|
8956
|
+
}
|
|
8957
|
+
return { numSplats, splats: out };
|
|
8958
|
+
}
|
|
8959
|
+
|
|
8752
8960
|
// src/loader/environment/ply.ts
|
|
8753
8961
|
var HEADER_END = "end_header\n";
|
|
8754
8962
|
var MAX_HEADER_BYTES = 64 * 1024;
|
|
@@ -8794,6 +9002,9 @@ function parseGaussianPly(file) {
|
|
|
8794
9002
|
throw new Error('[parseGaussianPly] not a PLY file: missing "ply" magic or "end_header"');
|
|
8795
9003
|
}
|
|
8796
9004
|
const dataStart = end + HEADER_END.length;
|
|
9005
|
+
if (isCompressedPlyHeader(headerText.slice(0, end))) {
|
|
9006
|
+
return parseCompressedPly(file, headerText.slice(0, end), dataStart);
|
|
9007
|
+
}
|
|
8797
9008
|
let numSplats = 0;
|
|
8798
9009
|
let stride = 0;
|
|
8799
9010
|
let inVertex = false;
|
|
@@ -9179,7 +9390,7 @@ function packSplatsInWorker(numSplats, s) {
|
|
|
9179
9390
|
const e = f >> 23 & 511;
|
|
9180
9391
|
return baseTable[e] + ((f & 8388607) >> shiftTable[e]);
|
|
9181
9392
|
};
|
|
9182
|
-
const
|
|
9393
|
+
const SH_C06 = 0.28209479177387814;
|
|
9183
9394
|
const width2 = Math.max(1, Math.ceil(Math.sqrt(numSplats)));
|
|
9184
9395
|
const height = Math.max(1, Math.ceil(numSplats / width2));
|
|
9185
9396
|
const texels = width2 * height;
|
|
@@ -9192,9 +9403,9 @@ function packSplatsInWorker(numSplats, s) {
|
|
|
9192
9403
|
let maxX = -Infinity, maxY = -Infinity, maxZ = -Infinity;
|
|
9193
9404
|
for (let i = 0; i < numSplats; i++) {
|
|
9194
9405
|
const o = i * 4;
|
|
9195
|
-
color[o] = toHalf(s.f_dc_0[i] *
|
|
9196
|
-
color[o + 1] = toHalf(s.f_dc_1[i] *
|
|
9197
|
-
color[o + 2] = toHalf(s.f_dc_2[i] *
|
|
9406
|
+
color[o] = toHalf(s.f_dc_0[i] * SH_C06 + 0.5);
|
|
9407
|
+
color[o + 1] = toHalf(s.f_dc_1[i] * SH_C06 + 0.5);
|
|
9408
|
+
color[o + 2] = toHalf(s.f_dc_2[i] * SH_C06 + 0.5);
|
|
9198
9409
|
color[o + 3] = toHalf(1 / (1 + Math.exp(-s.opacity[i])));
|
|
9199
9410
|
const x = s.x[i], y = s.y[i], z = s.z[i];
|
|
9200
9411
|
transformAFloat[o] = x;
|
|
@@ -9283,7 +9494,7 @@ async function readImagePixels(files) {
|
|
|
9283
9494
|
function decodeSogPixels(meta, px) {
|
|
9284
9495
|
const n = sogCount(meta);
|
|
9285
9496
|
const v2 = meta.version === 2;
|
|
9286
|
-
const
|
|
9497
|
+
const lerp2 = (a, b, t) => a * (1 - t) + b * t;
|
|
9287
9498
|
const book = (codebook) => {
|
|
9288
9499
|
const out2 = (codebook ?? []).slice();
|
|
9289
9500
|
if (codebook?.[0] === null) out2[0] = out2[1] + (out2[1] - out2[255]) / 255;
|
|
@@ -9291,12 +9502,12 @@ function decodeSogPixels(meta, px) {
|
|
|
9291
9502
|
};
|
|
9292
9503
|
const scaleBook = book(meta.scales.codebook);
|
|
9293
9504
|
const colorBook = book(meta.sh0.codebook);
|
|
9294
|
-
const
|
|
9505
|
+
const SH_C06 = 0.28209479177387814;
|
|
9295
9506
|
const positionTable = (axis) => {
|
|
9296
9507
|
const out2 = new Float32Array(65536);
|
|
9297
9508
|
const min = meta.means.mins[axis], max = meta.means.maxs[axis];
|
|
9298
9509
|
for (let v = 0; v < 65536; v++) {
|
|
9299
|
-
const t =
|
|
9510
|
+
const t = lerp2(min, max, v / 65535);
|
|
9300
9511
|
out2[v] = Math.sign(t) * (Math.exp(Math.abs(t)) - 1);
|
|
9301
9512
|
}
|
|
9302
9513
|
return out2;
|
|
@@ -9306,14 +9517,14 @@ function decodeSogPixels(meta, px) {
|
|
|
9306
9517
|
const colorOf = new Float32Array(768);
|
|
9307
9518
|
for (let c = 0; c < 3; c++) {
|
|
9308
9519
|
for (let b = 0; b < 256; b++) {
|
|
9309
|
-
scaleOf[c * 256 + b] = v2 ? scaleBook[b] :
|
|
9310
|
-
const color = 0.5 + (v2 ? colorBook[b] :
|
|
9311
|
-
colorOf[c * 256 + b] = (color - 0.5) /
|
|
9520
|
+
scaleOf[c * 256 + b] = v2 ? scaleBook[b] : lerp2(meta.scales.mins[c], meta.scales.maxs[c], b / 255);
|
|
9521
|
+
const color = 0.5 + (v2 ? colorBook[b] : lerp2(meta.sh0.mins[c], meta.sh0.maxs[c], b / 255)) * SH_C06;
|
|
9522
|
+
colorOf[c * 256 + b] = (color - 0.5) / SH_C06;
|
|
9312
9523
|
}
|
|
9313
9524
|
}
|
|
9314
9525
|
const opacityOf = new Float32Array(256);
|
|
9315
9526
|
for (let b = 0; b < 256; b++) {
|
|
9316
|
-
const a = v2 ? b / 255 : 1 / (1 + Math.exp(-
|
|
9527
|
+
const a = v2 ? b / 255 : 1 / (1 + Math.exp(-lerp2(meta.sh0.mins[3], meta.sh0.maxs[3], b / 255)));
|
|
9317
9528
|
opacityOf[b] = a <= 0 ? -40 : a >= 1 ? 40 : -Math.log(1 / a - 1);
|
|
9318
9529
|
}
|
|
9319
9530
|
const out = {};
|
|
@@ -9633,7 +9844,6 @@ function fileNameOf(url) {
|
|
|
9633
9844
|
}
|
|
9634
9845
|
function splatFormatOf(filename) {
|
|
9635
9846
|
const lower = filename.toLowerCase();
|
|
9636
|
-
if (lower.endsWith(".compressed.ply")) return null;
|
|
9637
9847
|
if (lower.endsWith(".ply")) return "ply";
|
|
9638
9848
|
if (lower.endsWith(".spz")) return "spz";
|
|
9639
9849
|
if (lower.endsWith(".sog")) return "sog";
|
|
@@ -9711,7 +9921,7 @@ var CharacterBundleError = class extends Error {
|
|
|
9711
9921
|
// src/loader/character/legacy/interleaved-splat.ts
|
|
9712
9922
|
var CHARACTER_BUNDLE_MAGIC = "VFCHARB1";
|
|
9713
9923
|
var FIRST_PLANAR_VERSION = 3;
|
|
9714
|
-
var
|
|
9924
|
+
var SH_C03 = 0.28209479177387814;
|
|
9715
9925
|
var _f16Buf = new ArrayBuffer(4);
|
|
9716
9926
|
var _f16U32 = new Uint32Array(_f16Buf);
|
|
9717
9927
|
var _f16F32 = new Float32Array(_f16Buf);
|
|
@@ -9821,9 +10031,9 @@ function parseBinaryGsplat(bundleBuffer) {
|
|
|
9821
10031
|
const r = splatData.getUint8(offset + 0);
|
|
9822
10032
|
const g = splatData.getUint8(offset + 1);
|
|
9823
10033
|
const b = splatData.getUint8(offset + 2);
|
|
9824
|
-
storage_f_dc_0[i] = (r / 255 - 0.5) /
|
|
9825
|
-
storage_f_dc_1[i] = (g / 255 - 0.5) /
|
|
9826
|
-
storage_f_dc_2[i] = (b / 255 - 0.5) /
|
|
10034
|
+
storage_f_dc_0[i] = (r / 255 - 0.5) / SH_C03;
|
|
10035
|
+
storage_f_dc_1[i] = (g / 255 - 0.5) / SH_C03;
|
|
10036
|
+
storage_f_dc_2[i] = (b / 255 - 0.5) / SH_C03;
|
|
9827
10037
|
offset += 4;
|
|
9828
10038
|
const opacity = f16ToF32(splatData.getUint16(offset + 0, true));
|
|
9829
10039
|
const clampedOpacity = Math.max(1e-4, Math.min(0.9999, opacity));
|
|
@@ -9855,9 +10065,9 @@ function parseBinaryGsplat(bundleBuffer) {
|
|
|
9855
10065
|
const r = splatData.getUint8(offset + 0);
|
|
9856
10066
|
const g = splatData.getUint8(offset + 1);
|
|
9857
10067
|
const b = splatData.getUint8(offset + 2);
|
|
9858
|
-
storage_f_dc_0[i] = (r / 255 - 0.5) /
|
|
9859
|
-
storage_f_dc_1[i] = (g / 255 - 0.5) /
|
|
9860
|
-
storage_f_dc_2[i] = (b / 255 - 0.5) /
|
|
10068
|
+
storage_f_dc_0[i] = (r / 255 - 0.5) / SH_C03;
|
|
10069
|
+
storage_f_dc_1[i] = (g / 255 - 0.5) / SH_C03;
|
|
10070
|
+
storage_f_dc_2[i] = (b / 255 - 0.5) / SH_C03;
|
|
9861
10071
|
offset += 4;
|
|
9862
10072
|
const opacity = splatData.getFloat32(offset + 0, true);
|
|
9863
10073
|
const clampedOpacity = Math.max(1e-4, Math.min(0.9999, opacity));
|
|
@@ -9973,7 +10183,7 @@ function parseBinaryGsplat(bundleBuffer) {
|
|
|
9973
10183
|
}
|
|
9974
10184
|
|
|
9975
10185
|
// src/loader/character/legacy/planar-splat.ts
|
|
9976
|
-
var
|
|
10186
|
+
var SH_C04 = 0.28209479177387814;
|
|
9977
10187
|
var OPACITY_CLAMP_LO = 1e-4;
|
|
9978
10188
|
var OPACITY_CLAMP_HI = 0.9999;
|
|
9979
10189
|
var MIN_SCALE = 1e-8;
|
|
@@ -10181,7 +10391,7 @@ async function parsePlanarSplats(buffer) {
|
|
|
10181
10391
|
for (let c = 0; c < 3; c++) {
|
|
10182
10392
|
const src = readU8(colorPlane, c);
|
|
10183
10393
|
const out = dcOut[c];
|
|
10184
|
-
for (let i = 0; i < numSplats; i++) out[i] = (src[i] / 255 - 0.5) /
|
|
10394
|
+
for (let i = 0; i < numSplats; i++) out[i] = (src[i] / 255 - 0.5) / SH_C04;
|
|
10185
10395
|
}
|
|
10186
10396
|
if (isQ23) {
|
|
10187
10397
|
const lo = header.logitOpacity.min;
|
|
@@ -10339,7 +10549,7 @@ async function decodeLegacyBundle(file) {
|
|
|
10339
10549
|
}
|
|
10340
10550
|
|
|
10341
10551
|
// src/loader/character/v1/decode.ts
|
|
10342
|
-
var
|
|
10552
|
+
var SH_C05 = 0.28209479177387814;
|
|
10343
10553
|
var POSITION_LEVELS = 65536;
|
|
10344
10554
|
var BYTE_LEVELS = 256;
|
|
10345
10555
|
var BYTES_PER_ELEMENT2 = { f32: 4, u16: 2, u8: 1 };
|
|
@@ -10614,7 +10824,7 @@ async function decodeV1(file, payloadOffset, payloadLength) {
|
|
|
10614
10824
|
for (let c = 0; c < 3; c++) {
|
|
10615
10825
|
const src = readU8(p, c);
|
|
10616
10826
|
const dst = dcOut[c];
|
|
10617
|
-
for (let i = 0; i < numSplats; i++) dst[i] = (src[i] / 255 - 0.5) /
|
|
10827
|
+
for (let i = 0; i < numSplats; i++) dst[i] = (src[i] / 255 - 0.5) / SH_C05;
|
|
10618
10828
|
}
|
|
10619
10829
|
}
|
|
10620
10830
|
let boneIndices;
|
|
@@ -17127,8 +17337,9 @@ var Environment = class _Environment {
|
|
|
17127
17337
|
/**
|
|
17128
17338
|
* Fetch, decode and add an environment splat.
|
|
17129
17339
|
*
|
|
17130
|
-
* Reads
|
|
17131
|
-
* 4), and SOG (a `.sog` bundle or
|
|
17340
|
+
* Reads 3D Gaussian Splatting `.ply` (uncompressed, or PlayCanvas's
|
|
17341
|
+
* `.compressed.ply`), `.spz` (versions 1 to 4), and SOG (a `.sog` bundle or
|
|
17342
|
+
* an unbundled `meta.json`). The format is
|
|
17132
17343
|
* told by the file name: pass `filename` when the URL does not end in one.
|
|
17133
17344
|
* `.spz` and SOG decode in a worker.
|
|
17134
17345
|
*
|
|
@@ -17242,6 +17453,95 @@ var SplatSPZLoader = class extends Loader2 {
|
|
|
17242
17453
|
}
|
|
17243
17454
|
};
|
|
17244
17455
|
|
|
17456
|
+
// src/three/sog-loader.ts
|
|
17457
|
+
import { FileLoader as FileLoader3, Loader as Loader3 } from "three";
|
|
17458
|
+
function isMetaJson(url) {
|
|
17459
|
+
return url.split(/[?#]/)[0].toLowerCase().endsWith("meta.json");
|
|
17460
|
+
}
|
|
17461
|
+
function meshName(url) {
|
|
17462
|
+
const parts = url.split(/[?#]/)[0].split("/").filter(Boolean);
|
|
17463
|
+
const file = parts.pop() ?? "";
|
|
17464
|
+
if (isMetaJson(file) && parts.length > 0) return parts.pop();
|
|
17465
|
+
return file.replace(/\.\w+$/, "") || "splat";
|
|
17466
|
+
}
|
|
17467
|
+
var SplatSOGLoader = class extends Loader3 {
|
|
17468
|
+
/**
|
|
17469
|
+
* The engine loaded meshes belong to: the lights they respond to. Leave
|
|
17470
|
+
* unset to use {@link SplatEngine.shared}.
|
|
17471
|
+
*/
|
|
17472
|
+
engine = null;
|
|
17473
|
+
constructor(manager) {
|
|
17474
|
+
super(manager);
|
|
17475
|
+
}
|
|
17476
|
+
setEngine(engine) {
|
|
17477
|
+
this.engine = engine;
|
|
17478
|
+
return this;
|
|
17479
|
+
}
|
|
17480
|
+
/**
|
|
17481
|
+
* Decode a `.sog` bundle already in memory. `name` labels the mesh; for a
|
|
17482
|
+
* loaded file it is the file's base name. An unbundled `meta.json` cannot
|
|
17483
|
+
* be parsed this way, since its images are separate files: {@link load} it.
|
|
17484
|
+
*/
|
|
17485
|
+
async parseAsync(data, name = "splat") {
|
|
17486
|
+
return this._toMesh(await decodeSogBundle(new Uint8Array(data)), name);
|
|
17487
|
+
}
|
|
17488
|
+
load(url, onLoad, onProgress, onError) {
|
|
17489
|
+
const fail2 = (error) => {
|
|
17490
|
+
if (onError) onError(error);
|
|
17491
|
+
else console.error(error);
|
|
17492
|
+
this.manager.itemError(url);
|
|
17493
|
+
};
|
|
17494
|
+
if (isMetaJson(url)) {
|
|
17495
|
+
this._loadMeta(url, onProgress).then(onLoad, (error) => {
|
|
17496
|
+
if (onError) onError(error);
|
|
17497
|
+
else console.error(error);
|
|
17498
|
+
});
|
|
17499
|
+
return;
|
|
17500
|
+
}
|
|
17501
|
+
const loader = this._fileLoader("arraybuffer");
|
|
17502
|
+
loader.setPath(this.path);
|
|
17503
|
+
loader.load(
|
|
17504
|
+
url,
|
|
17505
|
+
(data) => {
|
|
17506
|
+
this.parseAsync(data, meshName(this.path + url)).then(onLoad, fail2);
|
|
17507
|
+
},
|
|
17508
|
+
onProgress,
|
|
17509
|
+
onError
|
|
17510
|
+
);
|
|
17511
|
+
}
|
|
17512
|
+
async _loadMeta(url, onProgress) {
|
|
17513
|
+
const metaLoader = this._fileLoader("json");
|
|
17514
|
+
metaLoader.setPath(this.path);
|
|
17515
|
+
const meta = await metaLoader.loadAsync(url, onProgress);
|
|
17516
|
+
const base = this.path + url;
|
|
17517
|
+
const imageLoader = this._fileLoader("arraybuffer");
|
|
17518
|
+
const images = await Promise.all(
|
|
17519
|
+
imageFiles(meta).map(async (file) => new Uint8Array(await imageLoader.loadAsync(resolveUrl(file, base))))
|
|
17520
|
+
);
|
|
17521
|
+
try {
|
|
17522
|
+
return this._toMesh(await decodeImages(meta, images), meshName(base));
|
|
17523
|
+
} catch (error) {
|
|
17524
|
+
this.manager.itemError(url);
|
|
17525
|
+
throw error;
|
|
17526
|
+
}
|
|
17527
|
+
}
|
|
17528
|
+
/** A `FileLoader` carrying this loader's manager, headers and credentials mode. */
|
|
17529
|
+
_fileLoader(responseType) {
|
|
17530
|
+
const loader = new FileLoader3(this.manager);
|
|
17531
|
+
loader.setResponseType(responseType);
|
|
17532
|
+
loader.setRequestHeader(this.requestHeader);
|
|
17533
|
+
loader.setWithCredentials(this.withCredentials);
|
|
17534
|
+
return loader;
|
|
17535
|
+
}
|
|
17536
|
+
_toMesh(packed, name) {
|
|
17537
|
+
const splat = new Splat(this.engine ?? SplatEngine.shared, { packed });
|
|
17538
|
+
const mesh = splat.object3D;
|
|
17539
|
+
mesh.name = name;
|
|
17540
|
+
mesh.renderOrder = -1;
|
|
17541
|
+
return mesh;
|
|
17542
|
+
}
|
|
17543
|
+
};
|
|
17544
|
+
|
|
17245
17545
|
// src/lighting/sun-light.ts
|
|
17246
17546
|
import { Color as Color5, Vector3 as Vector314 } from "three";
|
|
17247
17547
|
|
|
@@ -18112,7 +18412,7 @@ var ParticleEmitter = class {
|
|
|
18112
18412
|
let outLife = inLife + delta;
|
|
18113
18413
|
const nlife = Math.min(1, Math.max(0, outLife / lifetime));
|
|
18114
18414
|
const [a, b, c] = nearestPair(nlife);
|
|
18115
|
-
const
|
|
18415
|
+
const lerp2 = (q) => q[a] + (q[b] - q[a]) * c;
|
|
18116
18416
|
const p = i * 3;
|
|
18117
18417
|
if (inLife <= 0 || outLife >= lifetime) {
|
|
18118
18418
|
this._spawnPosition(rx, ry, rz, _v);
|
|
@@ -18122,8 +18422,8 @@ var ParticleEmitter = class {
|
|
|
18122
18422
|
this.angle[i] = this._startAngle + (this._startAngle2 - this._startAngle) * rx;
|
|
18123
18423
|
}
|
|
18124
18424
|
const px = this.pos[p], py = this.pos[p + 1], pz = this.pos[p + 2];
|
|
18125
|
-
const radial =
|
|
18126
|
-
const radialDiv =
|
|
18425
|
+
const radial = lerp2(g.radial);
|
|
18426
|
+
const radialDiv = lerp2(g.radial2) - radial;
|
|
18127
18427
|
let rvx = px - _emitterPos.x, rvy = py - _emitterPos.y, rvz = pz - _emitterPos.z;
|
|
18128
18428
|
const rl = rvx * rvx + rvy * rvy + rvz * rvz;
|
|
18129
18429
|
if (rl > 1e-8) {
|
|
@@ -18137,16 +18437,16 @@ var ParticleEmitter = class {
|
|
|
18137
18437
|
rvx += radialDiv * rx;
|
|
18138
18438
|
rvy += radialDiv * ry;
|
|
18139
18439
|
rvz += radialDiv * rz;
|
|
18140
|
-
let lvx =
|
|
18141
|
-
lvx += (
|
|
18142
|
-
lvy += (
|
|
18143
|
-
lvz += (
|
|
18144
|
-
let vx =
|
|
18145
|
-
vx += (
|
|
18146
|
-
vy += (
|
|
18147
|
-
vz += (
|
|
18148
|
-
const rot =
|
|
18149
|
-
const rotSpeed = rot + (
|
|
18440
|
+
let lvx = lerp2(g.localVel[0]), lvy = lerp2(g.localVel[1]), lvz = lerp2(g.localVel[2]);
|
|
18441
|
+
lvx += (lerp2(g.localVel2[0]) - lvx) * rx;
|
|
18442
|
+
lvy += (lerp2(g.localVel2[1]) - lvy) * ry;
|
|
18443
|
+
lvz += (lerp2(g.localVel2[2]) - lvz) * rz;
|
|
18444
|
+
let vx = lerp2(g.vel[0]), vy = lerp2(g.vel[1]), vz = lerp2(g.vel[2]);
|
|
18445
|
+
vx += (lerp2(g.vel2[0]) - vx) * rx;
|
|
18446
|
+
vy += (lerp2(g.vel2[1]) - vy) * ry;
|
|
18447
|
+
vz += (lerp2(g.vel2[2]) - vz) * rz;
|
|
18448
|
+
const rot = lerp2(g.rotSpeed);
|
|
18449
|
+
const rotSpeed = rot + (lerp2(g.rotSpeed2) - rot) * ry;
|
|
18150
18450
|
if (this._box) {
|
|
18151
18451
|
lvz -= iv;
|
|
18152
18452
|
} else if (iv !== 0) {
|
|
@@ -23266,6 +23566,7 @@ export {
|
|
|
23266
23566
|
Ragdoll,
|
|
23267
23567
|
Environment,
|
|
23268
23568
|
SplatSPZLoader,
|
|
23569
|
+
SplatSOGLoader,
|
|
23269
23570
|
SunLight,
|
|
23270
23571
|
SkyLight,
|
|
23271
23572
|
PointLight,
|
|
@@ -23319,4 +23620,4 @@ export {
|
|
|
23319
23620
|
SplatRelight,
|
|
23320
23621
|
setPlayCanvasLightColor
|
|
23321
23622
|
};
|
|
23322
|
-
//# sourceMappingURL=chunk-
|
|
23623
|
+
//# sourceMappingURL=chunk-NNGE5LDC.js.map
|