@margoengine/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 +201 -0
- package/NOTICE +4 -0
- package/README.md +443 -3
- package/dist/animate.d.ts +138 -0
- package/dist/animate.js +31 -0
- package/dist/brush.d.ts +94 -0
- package/dist/brush.js +36 -0
- package/dist/compat-CDoDsXE8.js +19 -0
- package/dist/compat.d.ts +7 -0
- package/dist/compressed.d.ts +40 -0
- package/dist/data-D31W24Wu.js +2 -0
- package/dist/data.d.ts +28 -0
- package/dist/data.js +1 -0
- package/dist/depth.d.ts +42 -0
- package/dist/depth.js +14 -0
- package/dist/edit.d.ts +48 -0
- package/dist/encode-BA6xu973.js +1 -0
- package/dist/encode.d.ts +40 -0
- package/dist/formats.d.ts +24 -0
- package/dist/formats.js +5 -0
- package/dist/index.d.ts +167 -0
- package/dist/index.js +1 -0
- package/dist/lighting.d.ts +89 -0
- package/dist/lighting.js +48 -0
- package/dist/lod-sog.d.ts +44 -0
- package/dist/lod-sog.js +1 -0
- package/dist/lod.d.ts +129 -0
- package/dist/lod.js +4 -0
- package/dist/modify.d.ts +83 -0
- package/dist/modify.js +24 -0
- package/dist/pick.d.ts +75 -0
- package/dist/pick.js +14 -0
- package/dist/ply.d.ts +62 -0
- package/dist/progressive.d.ts +37 -0
- package/dist/progressive.js +5 -0
- package/dist/scene-scope-C5HWuOIb.js +4 -0
- package/dist/session.d.ts +127 -0
- package/dist/session.js +1 -0
- package/dist/set.d.ts +59 -0
- package/dist/set.js +4 -0
- package/dist/shader-B7zZyYz-.js +64 -0
- package/dist/shader.d.ts +17 -0
- package/dist/shared/fog.d.ts +33 -0
- package/dist/shared/pass.d.ts +53 -0
- package/dist/sog-D0LYo48N.js +1 -0
- package/dist/sog.d.ts +20 -0
- package/dist/sort.d.ts +4 -0
- package/dist/spz-BTy6CPTp.js +1 -0
- package/dist/spz.d.ts +23 -0
- package/dist/src-DlpBlCx1.js +48 -0
- package/dist/view-DyJeX8rJ.js +1 -0
- package/dist/view-rect-G-t2gTqO.js +1 -0
- package/dist/webp.d.ts +11 -0
- package/dist/zip-DNluwYbe.js +1 -0
- package/dist/zip.d.ts +7 -0
- package/dist/zstd-BPbUkXlY.js +1 -0
- package/package.json +107 -6
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** A reusable pass descriptor drawing over the frame: colour load/store, depth and stencil read only. */
|
|
2
|
+
export function overlayPass(): GPURenderPassDescriptor & {
|
|
3
|
+
colorAttachments: [GPURenderPassColorAttachment];
|
|
4
|
+
depthStencilAttachment: GPURenderPassDepthStencilAttachment;
|
|
5
|
+
};
|
|
6
|
+
/** {@link overlayPass} that also loads and stores depth. */
|
|
7
|
+
export function overlayDepthPass(): GPURenderPassDescriptor & {
|
|
8
|
+
colorAttachments: [GPURenderPassColorAttachment];
|
|
9
|
+
depthStencilAttachment: GPURenderPassDepthStencilAttachment;
|
|
10
|
+
};
|
|
11
|
+
/** Straight (non-premultiplied) alpha blending. */
|
|
12
|
+
export const alphaBlend: GPUBlendState;
|
|
13
|
+
/** Straight alpha blending that leaves the target's alpha channel unchanged: precipitation and other overlays drawn into a frame. */
|
|
14
|
+
export const overlayBlend: GPUBlendState;
|
|
15
|
+
|
|
16
|
+
/** `mesh` when it is null or a core mesh handle (checked live); else a TypeError. */
|
|
17
|
+
export function attachableMesh<M extends { check(): void } | null>(mesh: M): M;
|
|
18
|
+
/**
|
|
19
|
+
* What an order-independent pass offers an effect that is no PBR surface (particles, splats, points), in place of
|
|
20
|
+
* gltf/pbr's transparency hook. Same contract, but `surface` declares `fn margoTransparentAt(color:vec4f,clip:vec4f,
|
|
21
|
+
* depth:f32)->MargoTransparent`: `clip` is the fragment's position builtin, `depth` its view depth.
|
|
22
|
+
*/
|
|
23
|
+
export interface SurfaceTransparency {
|
|
24
|
+
/** Module-scope WGSL: `struct MargoTransparent` (one output per target), `margoTransparentAt` and its bindings in `group`. */
|
|
25
|
+
surface(group: number): string;
|
|
26
|
+
/** Layout of those bindings, for an effect with explicit pipeline layouts. */
|
|
27
|
+
readonly layout: readonly GPUBindGroupLayoutEntry[];
|
|
28
|
+
/** Entries for those bindings. */
|
|
29
|
+
bindings(): GPUBindGroupEntry[];
|
|
30
|
+
/** True: declarations hold `override margoKind:u32`, 0 normal, 1 additive; additive surfaces may draw here. */
|
|
31
|
+
readonly blends?: boolean;
|
|
32
|
+
/** Colour targets of the transparent pass, in `MargoTransparent` location order. */
|
|
33
|
+
readonly targets: readonly GPUColorTargetState[];
|
|
34
|
+
/** This frame's transparent pass, begun on the first draw and ended by the owner. */
|
|
35
|
+
begin(): GPURenderPassEncoder;
|
|
36
|
+
}
|
|
37
|
+
/** The fragment entry `transparent` of an effect under a transparency hook: `inputs` are its parameters, the rest WGSL expressions. */
|
|
38
|
+
export function surfaceEntry(declarations: string, inputs: string, color: string, clip: string, depth: string): string;
|
|
39
|
+
/** Holds an effect's transparency hook: `set` takes it and `released`, and returns the remover. */
|
|
40
|
+
export function transparencySlot(): {
|
|
41
|
+
hook?: SurfaceTransparency;
|
|
42
|
+
released?: () => void;
|
|
43
|
+
set(hook: SurfaceTransparency, released?: () => void): () => void;
|
|
44
|
+
};
|
|
45
|
+
/** `hook`'s pass with `pipeline` set, `group` at group 0 and the hook's bindings at group 1, for an effect with an auto layout. */
|
|
46
|
+
export function surfacePass(
|
|
47
|
+
device: GPUDevice,
|
|
48
|
+
hook: SurfaceTransparency,
|
|
49
|
+
pipeline: GPURenderPipeline,
|
|
50
|
+
group: GPUBindGroup,
|
|
51
|
+
): GPURenderPassEncoder;
|
|
52
|
+
/** The WGSL `make(group)` builds for bind group `group`, made once per group and kept in `cache`. */
|
|
53
|
+
export function groupCode(cache: Map<number, string>, group: number, make: (group: number) => string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{_ as e,v as t}from"./data-D31W24Wu.js";import{n}from"./zip-DNluwYbe.js";import{MargoError as r}from"@margoengine/math/errors";var i=(e,t)=>Object.assign(Error(e,t===void 0?void 0:{cause:t}),{name:`MargoError`,code:`failed`}),a=e=>Object.assign(Error(e),{name:`MargoError`,code:`unsupported`}),o=e=>{throw i(`Not a valid lossless WebP image: ${e}; pass the complete bytes of the file`)},s=[0,1,1,0,1,1,-1,1,0,2,2,0,1,2,-1,2,2,1,-2,1,2,2,-2,2,0,3,3,0,1,3,-1,3,3,1,-3,1,2,3,-2,3,3,2,-3,2,0,4,4,0,1,4,-1,4,4,1,-4,1,3,3,-3,3,2,4,-2,4,4,2,-4,2,0,5,3,4,-3,4,4,3,-4,3,5,0,1,5,-1,5,5,1,-5,1,2,5,-2,5,5,2,-5,2,4,4,-4,4,3,5,-3,5,5,3,-5,3,0,6,6,0,1,6,-1,6,6,1,-6,1,2,6,-2,6,6,2,-6,2,4,5,-4,5,5,4,-5,4,3,6,-3,6,6,3,-6,3,0,7,7,0,1,7,-1,7,5,5,-5,5,7,1,-7,1,4,6,-4,6,6,4,-6,4,2,7,-2,7,7,2,-7,2,3,7,-3,7,7,3,-7,3,5,6,-5,6,6,5,-6,5,8,0,4,7,-4,7,7,4,-7,4,8,1,8,2,6,6,-6,6,8,3,5,7,-5,7,7,5,-7,5,8,4,6,7,-6,7,7,6,-7,6,8,5,7,7,-7,7,8,6,8,7],c=[17,18,0,1,2,3,4,5,16,6,7,8,9,10,11,12,13,14,15],l=class{constructor(e,t){this.bytes=e,this.offset=t,this.acc=0,this.have=0}read(e){for(;this.have<e;)this.offset>=this.bytes.length&&o(`the data ends early`),this.acc|=this.bytes[this.offset++]<<this.have,this.have+=8;let t=this.acc&(1<<e)-1;return this.acc>>>=e,this.have-=e,t}},u=class{constructor(e){this.count=/* @__PURE__ */ new Uint32Array(16);let t=0,n=0;for(let r=0;r<e.length;r++)e[r]&&(this.count[e[r]]++,t++,n=r);if(this.single=t===1?n:-1,t===0&&o(`an empty prefix code`),t>1){let e=1;for(let t=1;t<16;t++)e=e*2-this.count[t],e<0&&o(`an over-subscribed prefix code`);e!==0&&o(`an incomplete prefix code`)}let r=/* @__PURE__ */ new Uint32Array(17);for(let e=1;e<16;e++)r[e+1]=r[e]+this.count[e];this.symbols=new Uint16Array(t);for(let t=0;t<e.length;t++)e[t]&&(this.symbols[r[e[t]]++]=t)}decode(e){if(this.single>=0)return this.single;let t=0,n=0,r=0;for(let i=1;i<16;i++){t|=e.read(1);let a=this.count[i];if(t-a<n)return this.symbols[r+(t-n)];r+=a,n=n+a<<1,t<<=1}return o(`an invalid prefix code in the data`)}};function d(e,t){let n=new Uint8Array(t);if(e.read(1)){let r=e.read(1),i=e.read(1)?e.read(8):e.read(1);if(i>=t&&o(`a symbol outside its alphabet`),n[i]=1,r){let r=e.read(8);r>=t&&o(`a symbol outside its alphabet`),r===i&&o(`a simple code that repeats a symbol`),n[r]=1}return new u(n)}let r=/* @__PURE__ */ new Uint8Array(19),i=4+e.read(4);for(let t=0;t<i;t++)r[c[t]]=e.read(3);let a=new u(r),s=t;e.read(1)&&(s=2+e.read(2+2*e.read(3)),s>t&&o(`a code-length run longer than the alphabet`));let l=0,d=8;for(;l<t&&s--!==0;){let r=a.decode(e);if(r<16){n[l++]=r,r&&(d=r);continue}let i=r===16?3+e.read(2):r===17?3+e.read(3):11+e.read(7),s=r===16?d:0;l+i>t&&o(`a code-length repeat past the alphabet`);for(let e=0;e<i;e++)n[l++]=s}return new u(n)}var f=(e,t)=>{if(t<4)return t+1;let n=t-2>>1;return(2+(t&1)<<n)+e.read(n)+1};function p(e,t,n,r){let i=0;e.read(1)&&(i=e.read(4),(i<1||i>11)&&o(`a colour cache size outside 1..11 bits`));let a=0,c,l=1;if(r&&e.read(1)){a=e.read(3)+2;let r=p(e,Math.ceil(t/(1<<a)),Math.ceil(n/(1<<a)),!1);c=new Uint32Array(r.length);for(let e=0;e<r.length;e++)c[e]=r[e]>>>8&65535,l=Math.max(l,c[e]+1)}let u=i?1<<i:0,m=[];for(let t=0;t<l;t++)m.push([d(e,280+u),d(e,256),d(e,256),d(e,256),d(e,40)]);let h=new Uint32Array(t*n),g=i?new Uint32Array(u):void 0,_=32-i,v=0,y=0,b=()=>{if(g)for(;y<v;y++)g[Math.imul(506832829,h[y])>>>_]=h[y]};for(;v<h.length;){let n=v%t,r=(v-n)/t,i=c?m[c[(r>>a)*Math.ceil(t/(1<<a))+(n>>a)]]:m[0];i||o(`a pixel that names a missing prefix group`);let l=i[0].decode(e);if(l<256){let t=i[1].decode(e),n=i[2].decode(e),r=i[3].decode(e);h[v++]=(r<<24|t<<16|l<<8|n)>>>0}else if(l<280){let n=f(e,l-256),r=f(e,i[4].decode(e)),a;r>120?a=r-120:(a=s[(r-1)*2]+s[(r-1)*2+1]*t,a<1&&(a=1)),(a>v||v+n>h.length)&&o(`a backward reference outside the image`);for(let e=0;e<n;e++,v++)h[v]=h[v-a]}else g||o(`a colour-cache symbol with no cache`),b(),h[v++]=g[l-280];b()}return h}var m=(e,t)=>(((e^t)&4278124286)>>>1)+(e&t)>>>0,h=e=>e<0?0:e>255?255:e,g=(e,t)=>e>>>t&255;function _(e,t,n,r){let i=t[n-1],a=t[n-r],o=t[n-r+1],s=t[n-r-1];switch(e){case 1:return i;case 2:return a;case 3:return o;case 4:return s;case 5:return m(m(i,o),a);case 6:return m(i,s);case 7:return m(i,a);case 8:return m(s,a);case 9:return m(a,o);case 10:return m(m(i,s),m(a,o));case 11:{let e=0,t=0;for(let n=0;n<32;n+=8){let r=g(i,n)+g(a,n)-g(s,n);e+=Math.abs(r-g(i,n)),t+=Math.abs(r-g(a,n))}return e<t?i:a}case 12:{let e=0;for(let t=0;t<32;t+=8)e+=h(g(i,t)+g(a,t)-g(s,t))*2**t;return e>>>0}case 13:{let e=m(i,a),t=0;for(let n=0;n<32;n+=8)t+=h(g(e,n)+Math.trunc((g(e,n)-g(s,n))/2))*2**n;return t>>>0}default:return 4278190080}}var v=(e,t)=>(((e&4278255360)>>>0)+((t&4278255360)>>>0)&4278255360|(e&16711935)+(t&16711935)&16711935)>>>0,y=(e,t)=>(e<<24>>24)*(t<<24>>24)>>5;function b(e,t,n){let r=[],i=/* @__PURE__ */ new Set,a=t;for(;e.read(1);){let t=e.read(2);i.has(t)&&o(`a repeated transform`),i.add(t);let s={type:t,bits:0,width:a,data:/* @__PURE__ */ new Uint32Array};if(t===0||t===1)s.bits=e.read(3)+2,s.data=p(e,Math.ceil(a/(1<<s.bits)),Math.ceil(n/(1<<s.bits)),!1);else if(t===3){let t=e.read(8)+1,n=p(e,t,1,!1);for(let e=1;e<t;e++)n[e]=v(n[e],n[e-1]);s.data=n,s.bits=t<=2?3:t<=4?2:+(t<=16),a=Math.ceil(a/(1<<s.bits))}r.push(s)}let s=p(e,a,n,!0);for(let e=r.length-1;e>=0;e--){let t=r[e];if(t.type===2)for(let e=0;e<s.length;e++){let t=s[e],n=t>>>8&255;s[e]=(t&4278255360|((t>>>16&255)+n&255)<<16|(t&255)+n&255)>>>0}else if(t.type===1){let e=Math.ceil(t.width/(1<<t.bits));for(let r=0;r<n;r++)for(let n=0;n<t.width;n++){let i=t.data[(r>>t.bits)*e+(n>>t.bits)],a=r*t.width+n,o=s[a],c=o>>>8&255,l=o>>>16&255,u=o&255;l=l+y(i&255,c)&255,u=u+y(i>>>8&255,c)+y(i>>>16&255,l)&255,s[a]=(o&4278255360|l<<16|u)>>>0}}else if(t.type===0){let e=Math.ceil(t.width/(1<<t.bits)),r=t.width;for(let i=0;i<n;i++)for(let n=0;n<r;n++){let a=i*r+n,o;o=i===0?n===0?4278190080:s[a-1]:n===0?s[a-r]:_(t.data[(i>>t.bits)*e+(n>>t.bits)]>>>8&15,s,a,r),s[a]=v(s[a],o)}}else{let e=8>>t.bits,r=(1<<e)-1,i=new Uint32Array(t.width*n),a=t.data,o=Math.ceil(t.width/(1<<t.bits));for(let c=0;c<n;c++)for(let n=0;n<t.width;n++){let l=s[c*o+(n>>t.bits)]>>>8&255,u=t.bits?l>>(n&(1<<t.bits)-1)*e&r:l;i[c*t.width+n]=u<a.length?a[u]:0}s=i}}return s}function x(e,t,n){let r=new l(e.subarray(0,n),t);r.read(8)!==47&&o(`a bad VP8L signature`);let i=r.read(14)+1,a=r.read(14)+1;r.read(1),r.read(3)!==0&&o(`an unknown VP8L version`);let s=b(r,i,a),c=new Uint8Array(i*a*4);for(let e=0;e<i*a;e++){let t=s[e];c[e*4]=t>>>16&255,c[e*4+1]=t>>>8&255,c[e*4+2]=t&255,c[e*4+3]=t>>>24}return{width:i,height:a,data:c}}function S(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength);(e.length<20||t.getUint32(0,!0)!==1179011410||t.getUint32(8,!0)!==1346520407)&&o(`missing the RIFF WEBP header`);let n=12,r=-1,i=0;for(;n+8<=e.length;){let e=t.getUint32(n,!0),o=t.getUint32(n+4,!0);if(e===1278758998){r=n+8,i=o;break}if(e===540561494)throw a(`This WebP is lossy (VP8); read it with parseWebP.`);n+=8+o+(o&1)}return(r<0||r+i>e.length)&&o(`no VP8L chunk`),x(e,r,r+i)}var C=/* @__PURE__ */ t({parseSog:()=>E}),w=e=>e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength),T=[0,3,8,15,24];async function E(t,i={}){let{signal:a}=i,o;if(t instanceof ArrayBuffer||ArrayBuffer.isView(t)){let e=w(t);if(e.length<4||e[0]!==80||e[1]!==75)throw RangeError(`Not a SOG file: a bundled .sog is a ZIP archive; pass the whole file or its loose files.`);o=await n(e,a)}else if(t&&typeof t==`object`)o=new Map(Object.entries(t).map(([e,t])=>{if(!(t instanceof ArrayBuffer)&&!ArrayBuffer.isView(t))throw TypeError(`SOG file ${e} must be an ArrayBuffer or typed array`);return[e,w(t)]}));else throw TypeError(`Expected .sog bytes or a map of SOG file names to bytes; pass an ArrayBuffer, typed array or file map`);let s=o.get(`meta.json`);if(!s)throw RangeError(`The SOG has no meta.json; pass the complete archive or all of its files.`);let c;try{c=JSON.parse(new TextDecoder().decode(s))}catch{throw RangeError(`The SOG meta.json is not valid JSON; check that the file is complete.`)}if(c.version!==2&&c.version!==3)throw RangeError(`SOG version ${c.version} is not supported; this reader handles versions 2 and 3, re-export the scene.`);if(c.model!==void 0&&c.model!==`antialiased`)throw new r(`unsupported`,`SOG model ${c.model} is not supported; 2D Gaussian scenes cannot be drawn here.`);let l=c.count;if(!Number.isInteger(l)||l<1||l>3e6)throw RangeError(`A SOG needs 1 to 3,000,000 splats.`);let u=e=>{a?.throwIfAborted();let t=e===void 0?void 0:o.get(e);if(!t)throw RangeError(`The SOG is missing the texture ${e}; pass the complete archive.`);try{return S(t)}catch(t){throw t.code===`unsupported`?new r(`unsupported`,`The SOG texture ${e} is lossy WebP; re-export the SOG with lossless textures.`):RangeError(`The SOG texture ${e} is damaged; re-export the SOG with lossless textures.`,{cause:t})}},[d,f]=c.means?.files??[],p=u(d),m=u(f),h=u(c.scales?.files?.[0]),g=c.version===2?u(c.quats?.files?.[0]):void 0,_=u(c.sh0?.files?.[0]);for(let e of[m,h,...g?[g]:[],_])if(e.width!==p.width||e.height!==p.height)throw RangeError(`The SOG textures differ in size; the file is damaged.`);if(p.width*p.height<l)throw RangeError(`The SOG textures hold fewer pixels than its splat count; the file is damaged, re-export it`);for(let e of[c.scales?.codebook,c.sh0?.codebook])if(!Array.isArray(e)||e.length!==256)throw RangeError(`A SOG codebook must have 256 entries.`);if(!Array.isArray(c.means.mins)||!Array.isArray(c.means.maxs)||c.means.mins.length!==3||c.means.maxs.length!==3)throw RangeError(`The SOG means need three mins and three maxs.`);let v={count:l,positions:new Float32Array(l*3),logScales:new Float32Array(l*3),rotations:new Float32Array(l*4),dc:new Float32Array(l*3),alphas:new Float32Array(l)},{mins:y,maxs:b}=c.means,x=c.scales.codebook,C=c.sh0.codebook;for(let e=0;e<l;e++){let t=e*4;for(let n=0;n<3;n++){let r=m.data[t+n]*256+p.data[t+n],i=y[n]+(b[n]-y[n])*r/65535;v.positions[e*3+n]=Math.sign(i)*(Math.exp(Math.abs(i))-1),v.logScales[e*3+n]=x[h.data[t+n]],v.dc[e*3+n]=C[_.data[t+n]]}if(v.alphas[e]=c.version===3?(_.data[t+3]/204)**2:_.data[t+3]/255,c.version===3){let n=(p.data[t+3]-128)/127,r=(m.data[t+3]-128)/127,i=(h.data[t+3]-128)/127,a=Math.hypot(n,r,i),o=a*Math.PI/2,s=a>1e-6?Math.sin(o)/a:Math.PI/2;v.rotations.set([Math.cos(o),n*s,r*s,i*s],e*4);continue}let n=g.data[t+3]-252;if(n<0||n>3)throw RangeError(`A SOG rotation has a reserved mode; the file is damaged.`);let r=[0,0,0,0],i=0,a=0;for(let e=0;e<4;e++){if(e===n)continue;let o=(g.data[t+a++]/255*2-1)*Math.SQRT1_2;r[e]=o,i+=o*o}r[n]=Math.sqrt(Math.max(0,1-i)),v.rotations.set(r,e*4)}if(c.shN){let e=c.shN,t=T[e.bands];if(!t||e.bands>(c.version===3?4:3)||!Number.isInteger(e.count)||e.count<1||e.count>(c.version===3?16777216:65536)||!Array.isArray(e.codebook)||e.codebook.length!==256||!Array.isArray(e.files))throw RangeError(`The SOG shN block is damaged; bands must be 1 to 3 and the codebook 256 entries.`);let n=u(e.files[0]),r=u(e.files[1]);if(r.width*r.height<l||n.width<64*t)throw RangeError(`The SOG spherical-harmonic textures are too small for its splat count; the file is damaged, re-export it`);v.rest=new Float32Array(l*t*3);for(let i=0;i<l;i++){let a=r.data[i*4]+r.data[i*4+1]*256+(c.version===3?r.data[i*4+2]*65536:0);if(a>=e.count)throw RangeError(`A SOG spherical-harmonic label is outside its palette; the file is damaged, re-export it`);for(let r=0;r<t;r++){let o=((a>>6)*n.width+(a&63)*t+r)*4;if(o+2>=n.data.length)throw RangeError(`A SOG palette entry lies outside its texture; the file is damaged, re-export it`);for(let a=0;a<3;a++)v.rest[(i*t+r)*3+a]=e.codebook[n.data[o+a]]}}}return e(v)}export{C as n,E as t};
|
package/dist/sog.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { SplatData } from './data.js';
|
|
2
|
+
/** The loose files of an unbundled SOG, by file name; must include `meta.json`. */
|
|
3
|
+
export type SogFiles = Record<string, ArrayBuffer | ArrayBufferView>;
|
|
4
|
+
/** Options for {@link parseSog}. */
|
|
5
|
+
export interface ParseSogOptions {
|
|
6
|
+
/** Aborts decoding; the promise rejects with the signal's reason. */
|
|
7
|
+
signal?: AbortSignal;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Decodes a SOG Gaussian-splat scene (version 2 or 3) to {@link SplatData}: either a bundled `.sog` file (a ZIP archive) or
|
|
11
|
+
* the loose files of an unbundled one (`meta.json` plus its lossless WebP textures). Positions, scales, rotations,
|
|
12
|
+
* colours, opacity and spherical harmonics are dequantised as the format describes; the splats keep the file's
|
|
13
|
+
* coordinate frame. The textures are decoded by a built-in lossless WebP decoder, so it works in any runtime with
|
|
14
|
+
* `DecompressionStream`.
|
|
15
|
+
* @throws TypeError when `input` is not bytes or a file map; RangeError for a damaged archive, texture or `meta.json`
|
|
16
|
+
* or an unknown SOG version; MargoError `unsupported` for lossy textures, ZIP64 or a missing `DecompressionStream`.
|
|
17
|
+
* @example
|
|
18
|
+
* const splats = await parseSog(await (await fetch('scene.sog')).arrayBuffer());
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseSog(input: ArrayBuffer | ArrayBufferView | SogFiles, options?: ParseSogOptions): Promise<SplatData>;
|
package/dist/sort.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{_ as e,v as t}from"./data-D31W24Wu.js";import{t as n}from"./zip-DNluwYbe.js";var r=/* @__PURE__ */ t({SPZ_BODY_MAX:()=>a,decodeSpzBody:()=>u,parseSpz:()=>o}),i=[0,3,8,15],a=16+195e6;async function o(e,t={}){if(!(e instanceof ArrayBuffer)&&!ArrayBuffer.isView(e))throw TypeError(`Expected .spz bytes; pass an ArrayBuffer or typed array of the file`);let r=e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength);if(r.length>=8&&new DataView(r.buffer,r.byteOffset).getUint32(0,!0)===1347635022)return u(await s(r,t.signal),4);if(r.length<2||r[0]!==31||r[1]!==139)throw RangeError(`Not an SPZ file: it starts with neither gzip (versions 2-3) nor NGSP (version 4); check that the file is a complete .spz.`);return u(await n(r,`gzip`,t.signal,a),3)}async function s(e,t){let n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(e.length<32)throw RangeError(`The SPZ header is truncated; check that the file is complete.`);let r=n.getUint32(4,!0),a=n.getUint32(8,!0),o=e[12],s=e[15],u=n.getUint32(16,!0);if(r!==4)throw RangeError(`SPZ version ${r} with a plain header is not supported; re-export the scene as SPZ version 4 or 3.`);l(a,o);let d=i[o]*3,f=[a*9,a,a*3,a*3,a*4,a*d],p=d?6:5;if(s<p)throw RangeError(`This SPZ file holds ${s} attribute streams where ${p} are needed; check that the file is complete.`);if(u<32||u+s*16>e.length)throw RangeError(`The SPZ table of contents lies outside the file; check that the file is complete.`);let m=new Uint8Array(16+f.reduce((e,t)=>e+t,0));m.set(e.subarray(0,16));let{decompressZstd:h}=await import(`./zstd-BPbUkXlY.js`),g=u+s*16,_=16;for(let r=0;r<s;r++){let i=u+r*16,a=c(n,i),o=c(n,i+8);if(g+a>e.length)throw RangeError(`An SPZ attribute stream runs past the end of the file; check that the file is complete.`);if(r<p){if(o!==f[r])throw RangeError(`SPZ attribute stream ${r} holds ${o} bytes where ${f[r]} are needed; check that the file is complete.`);let n=await h(e.subarray(g,g+a),{signal:t,maxOutputSize:o,maxWindowSize:Math.max(o,1<<27)});if(n.length!==o)throw RangeError(`SPZ attribute stream ${r} decodes to ${n.length} bytes where ${o} are needed; check that the file is complete.`);m.set(n,_),_+=o}g+=a}return m}function c(e,t){let n=e.getUint32(t+4,!0);if(n>2097151)throw RangeError(`An SPZ stream size is too large; check that the file is complete.`);return n*2**32+e.getUint32(t,!0)}function l(e,t){if(!Number.isInteger(e)||e<1||e>3e6)throw RangeError(`An SPZ file needs 1 to 3,000,000 splats.`);if(t>3)throw RangeError(`SPZ spherical-harmonic degree ${t} is not supported; Margo draws degrees 0 to 3.`)}function u(t,n){let r=new DataView(t.buffer,t.byteOffset,t.byteLength);if(t.length<16||r.getUint32(0,!0)!==1347635022)throw RangeError(`Not an SPZ file: the magic number is wrong; check that the file is complete.`);let a=r.getUint32(4,!0),o=r.getUint32(8,!0),s=t[12],c=t[13];if(a<(n===4?4:2)||a>n)throw RangeError(`SPZ version ${a} is not supported here; re-export the scene as SPZ version 3 or 4.`);l(o,s);let u=i[s]*3,d=a===2?3:4;if(t.length<16+o*(16+d+u))throw RangeError(`The SPZ data is shorter than its header promises; check that the file is complete.`);let f={count:o,positions:new Float32Array(o*3),logScales:new Float32Array(o*3),rotations:new Float32Array(o*4),dc:new Float32Array(o*3),alphas:new Float32Array(o),rest:u?new Float32Array(o*u):void 0},p=16+o*9,m=p+o,h=m+o*3,g=h+o*3,_=g+o*d,v=1/2**c;for(let e=0;e<o;e++){for(let n=0;n<3;n++){let r=16+e*9+n*3,i=t[r]|t[r+1]<<8|t[r+2]<<16;f.positions[e*3+n]=(i<<8>>8)*v,f.dc[e*3+n]=(t[m+e*3+n]/255-.5)/.15,f.logScales[e*3+n]=t[h+e*3+n]/16-10}f.alphas[e]=t[p+e]/255;let n=g+e*d;if(a!==2){let t=r.getUint32(n,!0),i=t>>>30,a=[0,0,0,0],o=0;for(let e=3;e>=0;e--){if(e===i)continue;let n=t&511,r=t>>>9&1;t>>>=10;let s=Math.SQRT1_2*n/511;a[e]=r?-s:s,o+=s*s}a[i]=Math.sqrt(Math.max(0,1-o)),f.rotations.set([a[3],a[0],a[1],a[2]],e*4)}else{let r=t[n]/127.5-1,i=t[n+1]/127.5-1,a=t[n+2]/127.5-1;f.rotations.set([Math.sqrt(Math.max(0,1-r*r-i*i-a*a)),r,i,a],e*4)}if(f.rest)for(let n=0;n<u;n++)f.rest[e*u+n]=(t[_+e*u+n]-128)/128}return e(f)}export{r as n,u as t};
|
package/dist/spz.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { SplatData } from './data.js';
|
|
2
|
+
/** Options for {@link parseSpz}. */
|
|
3
|
+
export interface ParseSpzOptions {
|
|
4
|
+
/** Aborts decoding; the promise rejects with the signal's reason. */
|
|
5
|
+
signal?: AbortSignal;
|
|
6
|
+
}
|
|
7
|
+
/** The largest version 2 or 3 body: a 16-byte header and 3,000,000 splats of degree 3 (20 + 45 bytes each). */
|
|
8
|
+
export declare const SPZ_BODY_MAX: number;
|
|
9
|
+
/**
|
|
10
|
+
* Decodes an SPZ file (versions 2 and 3, the gzip-compressed layout, and version 4, a plain header, a table of
|
|
11
|
+
* contents and one Zstandard stream per attribute) to {@link SplatData}. Positions are 24-bit fixed point, scales
|
|
12
|
+
* and colours are byte-quantised, rotations are 3 bytes (version 2) or the smallest-three 10-bit packing (versions 3
|
|
13
|
+
* and 4), spherical harmonics are signed bytes. Splats keep the file's coordinate frame (SPZ stores right-up-back,
|
|
14
|
+
* the same as Margo). Version 4's Zstandard decoder is built in and loads only when a version 4 file is read.
|
|
15
|
+
* @throws TypeError when `input` is not bytes; RangeError for a damaged file (including a failed Zstandard
|
|
16
|
+
* checksum), a wrong magic number or an unknown version (version 1 stored float16 positions and is not read);
|
|
17
|
+
* MargoError `unsupported` for a version 4 stream that needs a Zstandard dictionary.
|
|
18
|
+
* @example
|
|
19
|
+
* const splats = await parseSpz(await (await fetch('scene.spz')).arrayBuffer());
|
|
20
|
+
*/
|
|
21
|
+
export declare function parseSpz(input: ArrayBuffer | ArrayBufferView, options?: ParseSpzOptions): Promise<SplatData>;
|
|
22
|
+
/** Decodes the SPZ body (gzip bodies hold versions 2-3, unpacked version 4 files version 4): a 16-byte header (magic, version, count, degree, fractional bits) and the attributes. */
|
|
23
|
+
export declare function decodeSpzBody(bytes: Uint8Array, newest: 3 | 4): SplatData;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// @margo/core-built 0.1.0
|
|
2
|
+
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
|
+
const p=(engine,version="0.1.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
|
|
4
|
+
import{n as e}from"./data-D31W24Wu.js";import{t}from"./view-DyJeX8rJ.js";import{c as n,d as r,f as i,l as a,o,p as s,r as c,s as l,t as u,u as d}from"./shader-B7zZyYz-.js";import{t as f}from"./view-rect-G-t2gTqO.js";import{engineRuntime as __margoRuntime}from"@margoengine/core/extension";import{MargoError as m}from"@margoengine/math/errors";function h(e){if(e.length!==2||!e.every(Number.isFinite)||e[0]<0||e[1]>1||e[0]>e[1])throw RangeError(`Dither fade needs 0 <= lower <= upper <= 1; correct the coverage interval`)}var g=`fn margoDitherRank(p:vec2f)->u32 {
|
|
5
|
+
let x=u32(p.x)&3u;let y=u32(p.y)&3u;
|
|
6
|
+
return 4u*(2u*((x&1u)^(y&1u))+(y&1u))+2u*(((x>>1u)&1u)^((y>>1u)&1u))+((y>>1u)&1u);
|
|
7
|
+
}`,_=`struct Sort {count:u32,groups:u32,blocks:u32,shift:u32}
|
|
8
|
+
@group(0) @binding(0) var<uniform> sort:Sort;`,v=_+`
|
|
9
|
+
@group(0) @binding(1) var<storage,read> input:array<vec2u>;
|
|
10
|
+
@group(0) @binding(2) var<storage,read_write> histograms:array<u32>;
|
|
11
|
+
var<workgroup> bins:array<atomic<u32>,16>;
|
|
12
|
+
@compute @workgroup_size(256) fn main(@builtin(global_invocation_id) id:vec3u,@builtin(local_invocation_index) lane:u32,@builtin(workgroup_id) group:vec3u){
|
|
13
|
+
if(lane<16){atomicStore(&bins[lane],0);}workgroupBarrier();
|
|
14
|
+
if(id.x<sort.count){atomicAdd(&bins[(input[id.x].x>>sort.shift)&15],1);}workgroupBarrier();
|
|
15
|
+
if(lane<16){histograms[lane*sort.groups+group.x]=atomicLoad(&bins[lane]);}}`,y=_+`
|
|
16
|
+
@group(0) @binding(1) var<storage,read> histograms:array<u32>;
|
|
17
|
+
@group(0) @binding(2) var<storage,read_write> offsets:array<u32>;
|
|
18
|
+
@group(0) @binding(3) var<storage,read_write> totals:array<u32>;
|
|
19
|
+
var<workgroup> values:array<u32,256>;
|
|
20
|
+
@compute @workgroup_size(256) fn main(@builtin(local_invocation_index) lane:u32,@builtin(workgroup_id) group:vec3u){
|
|
21
|
+
let index=group.x*256+lane;values[lane]=0;if(index<sort.groups){values[lane]=histograms[group.y*sort.groups+index];}workgroupBarrier();
|
|
22
|
+
for(var stride=1u;stride<256;stride*=2){let at=(lane+1)*stride*2-1;if(at<256){values[at]+=values[at-stride];}workgroupBarrier();}
|
|
23
|
+
if(lane==0){totals[group.y*sort.blocks+group.x]=values[255];values[255]=0;}workgroupBarrier();
|
|
24
|
+
for(var stride=128u;stride>0;stride/=2){let at=(lane+1)*stride*2-1;if(at<256){let left=values[at-stride];values[at-stride]=values[at];values[at]+=left;}workgroupBarrier();}
|
|
25
|
+
if(index<sort.groups){offsets[group.y*sort.groups+index]=values[lane];}}`,b=_+`
|
|
26
|
+
@group(0) @binding(1) var<storage,read> totals:array<u32>;
|
|
27
|
+
@group(0) @binding(2) var<storage,read_write> bases:array<u32>;
|
|
28
|
+
var<workgroup> values:array<u32,1024>;
|
|
29
|
+
@compute @workgroup_size(256) fn main(@builtin(local_invocation_index) lane:u32){
|
|
30
|
+
for(var i=lane;i<1024;i+=256){values[i]=0;if(i<sort.blocks*16){values[i]=totals[i];}}workgroupBarrier();
|
|
31
|
+
for(var stride=1u;stride<1024;stride*=2){for(var i=lane;i<1024/(stride*2);i+=256){let at=(i+1)*stride*2-1;values[at]+=values[at-stride];}workgroupBarrier();}
|
|
32
|
+
if(lane==0){values[1023]=0;}workgroupBarrier();
|
|
33
|
+
for(var stride=512u;stride>0;stride/=2){for(var i=lane;i<1024/(stride*2);i+=256){let at=(i+1)*stride*2-1;let left=values[at-stride];values[at-stride]=values[at];values[at]+=left;}workgroupBarrier();}
|
|
34
|
+
for(var i=lane;i<sort.blocks*16;i+=256){bases[i]=values[i];}}`,x=_+`
|
|
35
|
+
@group(0) @binding(1) var<storage,read> input:array<vec2u>;
|
|
36
|
+
@group(0) @binding(2) var<storage,read_write> output:array<vec2u>;
|
|
37
|
+
@group(0) @binding(3) var<storage,read> offsets:array<u32>;
|
|
38
|
+
@group(0) @binding(4) var<storage,read> bases:array<u32>;
|
|
39
|
+
var<workgroup> masks:array<atomic<u32>,128>;
|
|
40
|
+
@compute @workgroup_size(256) fn main(@builtin(global_invocation_id) id:vec3u,@builtin(local_invocation_index) lane:u32,@builtin(workgroup_id) group:vec3u){
|
|
41
|
+
if(lane<128){atomicStore(&masks[lane],0);}workgroupBarrier();
|
|
42
|
+
var item=vec2u(0);var digit=0u;let word=lane/32;let bit=lane%32;
|
|
43
|
+
if(id.x<sort.count){item=input[id.x];digit=(item.x>>sort.shift)&15;atomicOr(&masks[digit*8+word],1u<<bit);}workgroupBarrier();
|
|
44
|
+
if(id.x<sort.count){var rank=countOneBits(atomicLoad(&masks[digit*8+word])&((1u<<bit)-1));
|
|
45
|
+
for(var i=0u;i<word;i++){rank+=countOneBits(atomicLoad(&masks[digit*8+i]));}
|
|
46
|
+
let destination=bases[digit*sort.blocks+group.x/256]+offsets[digit*sort.groups+group.x]+rank;output[destination]=item;}}`;function S(e){return e?.adapterInfo?.vendor===`margo-webgl2`?`webgl2`:`native`}function C(e,t){return S(e)===`webgl2`?t():void 0}var w=e=>typeof e==`string`&&e.endsWith(`float`),T=0,E=class _{coreRequirement=__margoCoreRequirement("0.1.0",import.meta.url);constructor(t){this.name=`splats:`+T++,this.buffers=[],this.inputs=[],this.keys=[],this.projectionBuffers=[],this.fogSource=null,this.fogData=/* @__PURE__ */ new Float32Array(12),this.sortPipelines=[],this.sortGroups=[],this.renders=/* @__PURE__ */ new Map,this.disposed=!1,this.mip=!1,this.writes=0,this.transparency=d(),this.attachment={view:void 0,loadOp:`load`,storeOp:`store`},this.plainDepth={view:void 0,depthReadOnly:!0},this.stencilDepth={view:void 0,depthReadOnly:!0,stencilReadOnly:!0},this.presentation={colorAttachments:[this.attachment],depthStencilAttachment:this.plainDepth},this.values=/* @__PURE__ */ new Float32Array(48),this.integers=new Uint32Array(this.values.buffer),this.view=this.values.subarray(16,32),this.count=e(t),this.positions=new Float32Array(this.count*4),this.covariances=new Float32Array(this.count*8),this.colors=t.colors.slice(),this.sh=t.sphericalHarmonics?.slice()??/* @__PURE__ */ new Float32Array(4);for(let e=0;e<this.count;e++)this.positions.set(t.positions.subarray(e*3,e*3+3),e*4),this.positions[e*4+3]=t.colors[e*4+3],this.covariances.set(t.covariances.subarray(e*6,e*6+6),e*8)}static reserve(e,t=0){if(![0,4,9,16,25].includes(t))throw RangeError(`Splat SH coefficients must be 0, 4, 9, 16 or 25`);if(!Number.isInteger(e)||e<1||e>3e6)throw RangeError(`Splats.reserve needs 1 to 3,000,000 splats`);let n=new Float32Array(e*6);for(let t=0;t<e;t++)n[t*6]=n[t*6+3]=n[t*6+5]=1;return new _({positions:new Float32Array(e*3),covariances:n,colors:new Float32Array(e*4),...t?{sphericalHarmonics:new Float32Array(e*t*3)}:{}})}get coefficients(){return this.sh.length===4?0:this.sh.length/this.count/3}write(t,n){let r=e(n),i=this.coefficients;if((n.sphericalHarmonics?n.sphericalHarmonics.length/r/3:0)!==i)throw RangeError(`Splats.write needs ${i} SH coefficients per channel, as the cloud has`);this.range(t,r);for(let e=0;e<r;e++)this.positions.set(n.positions.subarray(e*3,e*3+3),(t+e)*4),this.positions[(t+e)*4+3]=n.colors[e*4+3],this.covariances.set(n.covariances.subarray(e*6,e*6+6),(t+e)*8);return this.colors.set(n.colors,t*4),i&&this.sh.set(n.sphericalHarmonics,t*i*3),this.upload(t,r,!0)}clear(e,t){this.range(e,t);for(let n=e;n<e+t;n++)this.positions[n*4+3]=this.colors[n*4+3]=0;return this.upload(e,t,!1)}setOpacities(e,t,n=1){if(this.range(e,t.length),!(n>=0&&n<=1))throw RangeError(`Splats.setOpacities scale must be 0 to 1`);for(let r=0;r<t.length;r++)this.positions[(e+r)*4+3]=this.colors[(e+r)*4+3]=t[r]*n;return this.upload(e,t.length,!1)}range(e,t){if(this.disposed)throw new m(`disposed`,`The splats were disposed; write to a live cloud`);if(!Number.isInteger(e)||!Number.isInteger(t)||e<0||t<0||e+t>this.count)throw RangeError(`Splats ${e} to ${e+t-1} are outside this cloud of ${this.count}; keep first + count within the cloud`)}upload(e,t,n){this.writes++;let[r,i,a,o]=this.inputs,s=this.device?.queue,c=this.coefficients;return!s||!r||!t||(s.writeBuffer(r,e*16,this.positions,e*4,t*4),s.writeBuffer(a,e*16,this.colors,e*4,t*4),n&&s.writeBuffer(i,e*32,this.covariances,e*8,t*8),n&&c&&s.writeBuffer(o,e*c*12,this.sh,e*c*3,t*c*3)),this}get ditherFadeBytes(){return this.fadeData?.byteLength??0}setDitherFade(e,t,n=0,r=1){this.range(e,t),h([n,r]),this.fadeData||(this.fadeData=new Uint32Array(this.count).fill(4096),this.record=void 0,this.renders.clear());let i=Math.ceil(Math.fround(n)*16-.5),a=Math.ceil(Math.fround(r)*16-.5),o=Math.max(0,i)|Math.max(0,a)<<8;return this.fadeData.fill(o,e,e+t),this.device&&(this.fadeBuffer?t&&this.device.queue.writeBuffer(this.fadeBuffer,e*4,this.fadeData,e,t):this.prepareFade()),this}prepareFade(){if(!this.fadeData||!this.device||this.fadeBuffer)return;let e=this.device;this.fadeBuffer=e.createBuffer({size:this.fadeData.byteLength,usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST}),this.buffers.push(this.fadeBuffer),e.queue.writeBuffer(this.fadeBuffer,0,this.fadeData)}async read(){this.range(0,0);let e=this.device,[t,n,r,i]=this.inputs;for(let a=-1;e&&t&&a!==this.writes;){a=this.writes;let o=[[t,this.positions],[n,this.covariances],[r,this.colors],[i,this.sh]],s=e.createCommandEncoder(),c=o.map(([t,n])=>{let r=e.createBuffer({size:n.byteLength,usage:GPUBufferUsage.MAP_READ|GPUBufferUsage.COPY_DST});return s.copyBufferToBuffer(t,0,r,0,n.byteLength),r});e.queue.submit([s.finish()]);try{await Promise.all(c.map(e=>e.mapAsync(GPUMapMode.READ))),a===this.writes&&c.forEach((e,t)=>o[t][1].set(new Float32Array(e.getMappedRange())))}finally{for(let e of c)e.destroy()}}let a=this.count,o={positions:new Float32Array(a*3),covariances:new Float32Array(a*6),colors:this.colors.slice()};for(let e=0;e<a;e++)o.positions.set(this.positions.subarray(e*4,e*4+3),e*3),o.covariances.set(this.covariances.subarray(e*8,e*8+6),e*6);return this.coefficients&&(o.sphericalHarmonics=this.sh.slice()),o}get antialias(){return this.mip}set antialias(e){this.mip=!!e}get fog(){return this.fogSource}setFog(e){return this.fogSource=r(e),this}static attach(e,t){__margoAssertCore(e,__margoCoreRequirement("0.1.0",import.meta.url));let n=new _(t);return p(e).use(n),n}setup(e){if(this.disposed||!e.gpu)throw new m(this.disposed?`disposed`:`unsupported`,`Splats require WebGPU and a live cloud; attach a new Splats to a WebGPU engine; see https://margoengine.com/errors#webgpu`);this.engine=e,this.device=e.gpu;let t=this.device,n=Math.ceil(this.count/256),r=Math.ceil(n/256);if(r*16>1024||n>t.limits.maxComputeWorkgroupsPerDimension||t.limits.maxComputeInvocationsPerWorkgroup<256||t.limits.maxComputeWorkgroupSizeX<256||t.limits.maxStorageBuffersPerShaderStage<7)throw RangeError(`Splat compute exceeds device limits; use fewer splats or a device with larger compute limits.`);for(let e of[this.positions.byteLength,this.covariances.byteLength,this.colors.byteLength,this.sh.byteLength,this.count*32,this.count*16,this.count*8,n*16*4])if(e>t.limits.maxBufferSize||e>t.limits.maxStorageBufferBindingSize)throw RangeError(`Splat attributes exceed device storage limits; use fewer splats.`);let i=(e,n,r)=>{let i=t.createBuffer({size:e,usage:n|GPUBufferUsage.COPY_DST});return this.buffers.push(i),r&&t.queue.writeBuffer(i,0,r),i};this.prepareFade(),this.uniform=i(192,GPUBufferUsage.UNIFORM),this.index=i(24,GPUBufferUsage.INDEX,new Uint32Array([0,1,2,2,1,3]));let a=GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_SRC,o=i(this.positions.byteLength,a,this.positions),s=i(this.covariances.byteLength,a,this.covariances),l=i(this.colors.byteLength,a,this.colors),u=i(this.sh.byteLength,a,this.sh);this.inputs=[o,s,l,u],this.projected=i(this.count*32,GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_SRC),this.evaluated=i(this.count*16,GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_SRC),this.keys=[0,1].map(()=>i(this.count*8,GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_SRC));let d=i(n*16*4,GPUBufferUsage.STORAGE),f=i(n*16*4,GPUBufferUsage.STORAGE),p=i(r*16*4,GPUBufferUsage.STORAGE),h=i(r*16*4,GPUBufferUsage.STORAGE),g=e=>t.createComputePipeline({layout:`auto`,compute:{module:t.createShaderModule({code:e}),entryPoint:`main`}}),_=(e,n)=>t.createBindGroup({layout:e.getBindGroupLayout(0),entries:n.map((e,t)=>({binding:t,resource:{buffer:e}}))});this.projection=g(c),this.projectionBuffers=[this.uniform,o,s,l,u,this.projected,this.evaluated,this.keys[0]],this.projectionGroup=_(this.projection,this.projectionBuffers),this.sortPipelines=[v,y,b,x].map(g);let S=[];for(let e=0;e<8;e++){let t=i(16,GPUBufferUsage.UNIFORM,new Uint32Array([this.count,n,r,e*4])),a=e%2;S.push(t),this.sortGroups.push([_(this.sortPipelines[0],[t,this.keys[a],d]),_(this.sortPipelines[1],[t,d,f,p]),_(this.sortPipelines[2],[t,p,h]),_(this.sortPipelines[3],[t,this.keys[a],this.keys[1-a],f,h])])}let w=this.keys;C(t,()=>import(`./compat-CDoDsXE8.js`))?.then(({splatCompatSort:e})=>{this.keys===w&&(this.compatSort=e(t,S[0],w))})}registerPasses(e){e.add({name:this.name+`:project-sort`,order:-7,execute:e=>{e.backend===`webgpu`&&this.sort(e)}}),e.add({name:this.name+`:draw`,order:3,execute:e=>{e.backend===`webgpu`&&this.draw(e)}})}sort(e){this.values.set(e.camera.matrix),t(this.view,e.camera),this.values.set(e.camera.position,32);let n=e.height/(2*Math.tan(e.camera.fov*Math.PI/360)),r=this.values,a=this.integers,o=e.encoder;r[36]=e.width,r[37]=e.height,r[38]=r[39]=n,r[40]=e.camera.near,r[41]=e.camera.far,r[42]=+w(e.format),r[43]=0;let c=s(e.camera.matrix,e.camera.position);c&&(r[38]=c.sx*e.width/2,r[39]=c.sy*e.height/2,r[40]=c.near,r[41]=c.far,r[43]=1),a[44]=this.count,a[45]=this.sh.length===4?0:this.sh.length/this.count/3,a[46]=+this.mip,a[47]=0,e.device.queue.writeBuffer(this.uniform,0,this.values);let l=this.fogSource&&this.fogResources(e.device);l&&(i(this.fogSource,e.camera.position,this.fogData),e.device.queue.writeBuffer(l.buffer,0,this.fogData));let u=Math.ceil(this.count/256),d=Math.ceil(u/256),f=o.beginComputePass();try{if(l?this.dispatch(f,l.pipeline,l.group,u,1):this.dispatch(f,this.projection,this.projectionGroup,u,1),this.transparency.hook)return;if(this.compatSort)this.dispatch(f,this.compatSort.pipeline,this.compatSort.group,1,1);else for(let e=0;e<8;e++){let t=this.sortGroups[e];this.dispatch(f,this.sortPipelines[0],t[0],u,1),this.dispatch(f,this.sortPipelines[1],t[1],d,16),this.dispatch(f,this.sortPipelines[2],t[2],1,1),this.dispatch(f,this.sortPipelines[3],t[3],u,1)}}finally{f.end()}}fogResources(e){if(this.fogged)return this.fogged;let t=e.createBuffer({size:48,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});this.buffers.push(t);let n=e.createComputePipeline({layout:`auto`,compute:{module:e.createShaderModule({code:u()}),entryPoint:`main`}});return this.fogged={buffer:t,pipeline:n,group:e.createBindGroup({layout:n.getBindGroupLayout(0),entries:[...this.projectionBuffers,t].map((e,t)=>({binding:t,resource:{buffer:e}}))})}}dispatch(e,t,n,r,i){e.setPipeline(t),e.setBindGroup(0,n),e.dispatchWorkgroups(r,i)}fadeShader(e){return this.fadeData?g+`
|
|
47
|
+
@group(0) @binding(4) var<storage,read> fadeRanges:array<u32>;
|
|
48
|
+
`+e.replace(`@location(1) color:vec4f}`,`@location(1) color:vec4f,@location(3) @interpolate(flat) margoFade:u32}`).replace(`@location(1) color:vec4f,@location(2) margoDepth:f32}`,`@location(1) color:vec4f,@location(2) margoDepth:f32,@location(3) @interpolate(flat) margoFade:u32}`).replace(`o.corner=corner;`,`o.corner=corner;o.margoFade=fadeRanges[index];`).replace(`let power=-4.5*dot(i.corner,i.corner);`,`let fade=margoDitherRank(i.clip.xy);if(fade<(i.margoFade&255u)||fade>=(i.margoFade>>8u)){discard;}let power=-4.5*dot(i.corner,i.corner);`):e}pipeline(e,t,r){t+=this.fadeData?`|dither`:``;let i=this.renders.get(t);if(i)return i;let a=r?.surface(1),s=e.device.createShaderModule({code:this.fadeShader(a?l(a):o)}),c=e.device.createRenderPipeline({layout:`auto`,vertex:{module:s,entryPoint:`vertex`},fragment:{module:s,entryPoint:r?`transparent`:`fragment`,...r?.blends?{constants:{margoKind:0}}:{},targets:r?[...r.targets]:[{format:e.format,blend:n}]},multisample:e.descriptor.multisample,depthStencil:{format:e.descriptor.depthStencil.format,depthWriteEnabled:!1,depthCompare:`greater-equal`}});return i={pipeline:c,group:e.device.createBindGroup({layout:c.getBindGroupLayout(0),entries:[this.uniform,this.projected,this.evaluated,this.keys[0],...this.fadeBuffer?[this.fadeBuffer]:[]].map((e,t)=>({binding:t,resource:{buffer:e}}))})},this.renders.set(t,i),i}draw(e){if(this.transparency.hook)return;let t=e.descriptor.multisample?.count,n=e.descriptor.depthStencil.format,r=this.record;(!r||this.recordSamples!==t||this.recordFormat!==e.format||this.recordDepth!==n)&&(r=this.pipeline(e,t+`:`+e.format+`:`+n),this.record=r,this.recordSamples=t,this.recordFormat=e.format,this.recordDepth=n,this.presentation.depthStencilAttachment=n.includes(`stencil`)?this.stencilDepth:this.plainDepth),this.attachment.view=e.color,this.presentation.depthStencilAttachment.view=e.depth;let i=e.encoder.beginRenderPass(this.presentation);f(i,e),i.setPipeline(r.pipeline),i.setBindGroup(0,r.group),i.setIndexBuffer(this.index,`uint32`),i.drawIndexed(6,this.count),i.end(),this.engine.stats.drawCalls++}setTransparency(e,t){return this.transparency.set(e,t)}drawTransparent(e,t){if(!this.uniform)return;let n=t.surface(1),{pipeline:r,group:i}=this.pipeline(e,e.descriptor.multisample?.count+`:`+e.format+`:`+e.descriptor.depthStencil.format+n,t),o=a(e.device,t,r,i);o.setIndexBuffer(this.index,`uint32`),o.drawIndexed(6,this.count),this.engine.stats.drawCalls++}get attached(){return!!this.projected}get gpuState(){if(!this.projected||!this.evaluated||!this.keys.length)throw new m(`state`,`Splats are not attached; attach them to an engine first`);let[e,t,n,r]=this.inputs;return{sorted:this.keys[0],ellipses:this.projected,colors:this.evaluated,positions:e,covariances:t,inputColors:n,sh:r}}release(){for(let e of this.buffers)e.destroy();this.buffers=[],this.inputs=[],this.keys=[],this.sortGroups=[],this.sortPipelines=[],this.compatSort=void 0,this.renders.clear(),this.record=void 0,this.fadeBuffer=void 0,this.uniform=this.index=this.projected=this.evaluated=void 0,this.projection=void 0,this.projectionGroup=void 0,this.projectionBuffers=[],this.fogged=void 0}onDeviceRestored(e){this.release(),this.setup(e)}dispose(){this.disposed||(this.disposed=!0,this.transparency.released?.(),this.engine?.sceneOf(this)?.removePlugin(this.name),this.release(),this.engine=this.device=void 0)}[Symbol.dispose??Symbol()](){this.dispose()}destroy(){this.dispose()}};export{E as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e,t){let n=t.position,r=t.up??[0,1,0],i=n[0]-t.target[0],a=n[1]-t.target[1],o=n[2]-t.target[2],s=Math.abs(i),c=Math.abs(a),l=Math.abs(o),u=s>c?s:c,d=u>l?u:l,f;if(s===1/0||c===1/0||l===1/0)f=1/0;else if(s!==s||c!==c||l!==l)f=s+c+l;else if(d===0)f=0;else{let e=s/d*(s/d),t=c/d*(c/d),n=e+t-e-t,r=l/d*(l/d)-n;f=Math.sqrt(e+t+r)*d}i/=f,a/=f,o/=f;let p=r[1]*o-r[2]*a,m=r[2]*i-r[0]*o,h=r[0]*a-r[1]*i,g=Math.abs(p),_=Math.abs(m),v=Math.abs(h),y=g>_?g:_,b=y>v?y:v,x;if(g===1/0||_===1/0||v===1/0)x=1/0;else if(g!==g||_!==_||v!==v)x=g+_+v;else if(b===0)x=0;else{let e=g/b*(g/b),t=_/b*(_/b),n=e+t-e-t,r=v/b*(v/b)-n;x=Math.sqrt(e+t+r)*b}if(!f||!x)throw RangeError(`Invalid camera view; pass distinct eye and target and another up vector`);p/=x,m/=x,h/=x;let S=a*h-o*m,C=o*p-i*h,w=i*m-a*p;return e[0]=p,e[1]=S,e[2]=i,e[3]=0,e[4]=m,e[5]=C,e[6]=a,e[7]=0,e[8]=h,e[9]=w,e[10]=o,e[11]=0,e[12]=-p*n[0]-m*n[1]-h*n[2],e[13]=-S*n[0]-C*n[1]-w*n[2],e[14]=-i*n[0]-a*n[1]-o*n[2],e[15]=1,e}export{e as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e){return e?.view?.viewport}function t(t,n){let r=e(n);if(!r)return;t.setViewport(r[0],r[1],r[2],r[3],0,1);let i=n.view.scissor??r;t.setScissorRect(i[0],i[1],i[2],i[3])}export{t};
|
package/dist/webp.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code lengths of a prefix code for `counts`, none longer than `limit`: Huffman's construction, with the counts
|
|
3
|
+
* halved (keeping every used symbol at 1 or more) and rebuilt until the longest code fits.
|
|
4
|
+
*/
|
|
5
|
+
export declare function codeLengths(counts: ArrayLike<number>, limit: number): Uint8Array;
|
|
6
|
+
/**
|
|
7
|
+
* Encodes `rgba` (`width x height` pixels, 4 bytes each) as a lossless WebP file (RIFF, one VP8L chunk). Every value
|
|
8
|
+
* decodes exactly.
|
|
9
|
+
* @throws RangeError for a size outside 1 to 16,384 or a pixel array of another length.
|
|
10
|
+
*/
|
|
11
|
+
export declare function encodeWebpLossless(rgba: Uint8Array, width: number, height: number): Uint8Array<ArrayBuffer>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{MargoError as e}from"@margoengine/math/errors";var t={deflate:[120,156,3,0,0,0,0,1],"deflate-raw":[3,0],gzip:[31,139,8,0,0,0,0,0,0,3,3,0,0,0,0,0,0,0,0,0]},n=/* @__PURE__ */ new Map;async function r(e,t){try{return await new Response(new Blob([e]).stream().pipeThrough(new DecompressionStream(t))).arrayBuffer(),!0}catch{return!1}}function i(e){if(!(e in t))throw TypeError(`format must be deflate, deflate-raw or gzip (got ${e})`);let i=n.get(e);return i||(i=r(new Uint8Array([...t[e],0]),e),n.set(e,i)),i}async function a(e,t){return!await i(t)||e.byteLength===0?!1:r(e.subarray(0,e.byteLength-1),t)}async function o(t,n,r,i){if(r?.throwIfAborted(),typeof DecompressionStream>`u`)throw new e(`unsupported`,`This runtime has no DecompressionStream; use a current browser or Node 18+.`);let o=new Blob([t]).stream().pipeThrough(new DecompressionStream(n)).getReader(),s=[],c=0;try{for(;;){r?.throwIfAborted();let{done:e,value:t}=await o.read();if(e||(s.push(t),c+=t.length,c>i))break}}catch(e){throw r?.aborted?r.reason:RangeError(`The compressed data is damaged (${e.message}); check that the file is complete.`)}if(c>i)throw await o.cancel().catch(()=>{}),RangeError(`The compressed data expands past ${i} bytes, more than the file can hold; check that the file is complete and not damaged.`);if(await a(t,n))throw RangeError(`The compressed data is damaged (data after the end of the stream); check that the file is complete.`);let l=new Uint8Array(c),u=0;for(let e of s)l.set(e,u),u+=e.length;return l}async function s(t,n){let r=new DataView(t.buffer,t.byteOffset,t.byteLength),i=e=>{throw RangeError(`Not a readable ZIP archive: ${e}; check that the file is complete.`)},a=-1;for(let e=t.length-22;e>=Math.max(0,t.length-22-65535);e--)if(r.getUint32(e,!0)===101010256){a=e;break}a<0&&i(`no end-of-directory record`);let s=r.getUint16(a+10,!0),c=r.getUint32(a+16,!0);if(s===65535||c===4294967295)throw new e(`unsupported`,`ZIP64 archives are not supported; re-export the SOG.`);let l=/* @__PURE__ */ new Map;for(let a=0;a<s;a++){(c+46>t.length||r.getUint32(c,!0)!==33639248)&&i(`a damaged central directory`);let a=r.getUint16(c+10,!0),s=r.getUint32(c+20,!0),u=r.getUint32(c+24,!0),d=r.getUint16(c+28,!0),f=r.getUint16(c+30,!0),p=r.getUint16(c+32,!0),m=r.getUint32(c+42,!0),h=new TextDecoder().decode(t.subarray(c+46,c+46+d));if(c+=46+d+f+p,h.endsWith(`/`))continue;(m+30>t.length||r.getUint32(m,!0)!==67324752)&&i(`a damaged local header`);let g=m+30+r.getUint16(m+26,!0)+r.getUint16(m+28,!0);g+s>t.length&&i(`an entry that runs past the end of the file`);let _=t.subarray(g,g+s),v;if(a===0)v=_;else if(a===8)v=await o(_,`deflate-raw`,n,u);else throw new e(`unsupported`,`ZIP entry ${h} uses compression method ${a}; only stored and deflate are supported.`);v.length!==u&&i(`entry ${h} has the wrong size`),l.set(h,v)}return l}export{s as n,o as t};
|
package/dist/zip.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inflates `bytes` with the platform decompressor (`'gzip'` or raw `'deflate-raw'`), stopping with a RangeError as
|
|
3
|
+
* soon as the output passes `maxBytes`, so a small hostile stream cannot expand without bound.
|
|
4
|
+
*/
|
|
5
|
+
export declare function inflate(bytes: Uint8Array, format: 'gzip' | 'deflate-raw', signal: AbortSignal | undefined, maxBytes: number): Promise<Uint8Array<ArrayBuffer>>;
|
|
6
|
+
/** Reads every file of a ZIP archive into a name to bytes map. */
|
|
7
|
+
export declare function readZip(bytes: Uint8Array, signal?: AbortSignal): Promise<Map<string, Uint8Array>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=(e,t)=>Object.assign(Error(t),{name:`MargoError`,code:e}),t=e=>/* @__PURE__ */ RangeError(`The Zstandard data is damaged (${e}); check that the file is complete.`),n=1<<17,r=1<<23,i=/* @__PURE__ */ new Uint32Array(36),a=/* @__PURE__ */ new Uint8Array(36),o=/* @__PURE__ */ new Uint32Array(53),s=/* @__PURE__ */ new Uint8Array(53);{let e=[0,0,1,1,1,1,2,2,3,3,4,6,7,8,9,10,11,12,13,14,15,16];for(let t=0,n=0;t<36;t++)a[t]=t<16?0:e[t-14],i[t]=n,n+=1<<a[t];let t=[1,1,1,1,2,2,3,3,4,4,5,7,8,9,10,11,12,13,14,15,16];for(let e=0,n=3;e<53;e++)s[e]=e<32?0:t[e-32],o[e]=n,n+=1<<s[e]}var c=[4,3,2,2,2,2,2,2,2,2,2,2,2,1,1,1,2,2,2,2,2,2,2,2,2,3,2,1,1,1,1,1,-1,-1,-1,-1],l=[1,4,3,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1],u=[1,1,1,1,1,1,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,-1,-1,-1,-1,-1],d=class{constructor(e,n,r){if(this.data=e,this.start=n,this.length=r,r<1)throw t(`an empty bitstream`);let i=e[n+r-1];if(i===0)throw t(`a bitstream without its end marker`);this.pos=r*8-8+(31-Math.clz32(i))}byte(e){return e>=0&&e<this.length?this.data[this.start+e]:0}peek(e){if(e===0)return 0;let t=this.pos-e,n=t>>3;return(this.byte(n)|this.byte(n+1)<<8|this.byte(n+2)<<16|this.byte(n+3)<<24)>>>0>>>(t&7)&(1<<e)-1}read(e){if(e>24)return this.read(e-16)*65536+this.read(16);let t=this.peek(e);return this.pos-=e,t}};function f(e,n,r){let i=1<<r,a=new Uint8Array(i),o=new Uint8Array(i),s=new Uint32Array(i),c=new Uint32Array(n),l=i-1;for(let t=0;t<n;t++)e[t]===-1?(a[l--]=t,c[t]=1):c[t]=e[t];let u=(i>>1)+(i>>3)+3,d=i-1,f=0;for(let t=0;t<n;t++)for(let n=0;n<e[t];n++){a[f]=t;do f=f+u&d;while(f>l)}if(f!==0)throw t(`an FSE table whose probabilities do not fill it`);for(let e=0;e<i;e++){let t=c[a[e]]++,n=r-(31-Math.clz32(t));o[e]=n,s[e]=(t<<n)-i}return{log:r,symbol:a,bits:o,base:s}}function p(e){return{log:0,symbol:Uint8Array.of(e),bits:/* @__PURE__ */ new Uint8Array(1),base:/* @__PURE__ */ new Uint32Array(1)}}function m(e,n,r,i,a){let o=0,s=i=>{let a=n*8+o,s=a>>3;if(s>=r)throw t(`a truncated FSE table description`);return(e[s]|(e[s+1]??0)<<8|(e[s+2]??0)<<16)>>>(a&7)&(1<<i)-1},c=s(4)+5;if(o=4,c>i)throw t(`an FSE accuracy log of ${c} (at most ${i})`);let l=[],u=(1<<c)+1,d=1<<c,p=c+1;for(;u>1;){if(l.length>a)throw t(`an FSE table with too many symbols`);let e=2*d-1-u,n=s(p-1);n<e?o+=p-1:(n=s(p),n>=d&&(n-=e),o+=p);let r=n-1;if(l.push(r),u-=r<0?-r:r,r===0)for(;;){let e=s(2);o+=2;for(let t=0;t<e;t++)l.push(0);if(e!==3)break}for(;u<d;)p--,d>>=1}if(u!==1||l.length>a+1)throw t(`an FSE table that does not sum`);let m=o+7>>3;if(n+m>r)throw t(`a truncated FSE table description`);return[f(l,l.length,c),m]}function h(e,n,r){if(n>=r)throw t(`a missing Huffman tree`);let i=e[n],a=/* @__PURE__ */ new Uint8Array(256),o=0,s;if(i>=128){if(o=i-127,s=1+(o+1>>1),n+s>r)throw t(`a truncated Huffman tree`);for(let t=0;t<o;t++){let r=e[n+1+(t>>1)];a[t]=t&1?r&15:r>>4}}else{if(s=1+i,n+s>r)throw t(`a truncated Huffman tree`);let[c,l]=m(e,n+1,n+s,6,255),u=new d(e,n+1+l,i-l),f=u.read(c.log),p=u.read(c.log);for(;;){if(o>254)throw t(`a Huffman tree with too many weights`);if(a[o++]=c.symbol[f],f=c.base[f]+u.read(c.bits[f]),u.pos<0){a[o++]=c.symbol[p];break}if(a[o++]=c.symbol[p],p=c.base[p]+u.read(c.bits[p]),u.pos<0){a[o++]=c.symbol[f];break}}}let c=0;for(let e=0;e<o;e++){if(a[e]>11)throw t(`a Huffman weight above 11`);a[e]&&(c+=1<<a[e]-1)}if(c===0||o>255)throw t(`an empty Huffman tree`);let l=32-Math.clz32(c),u=(1<<l)-c;if(l>11||u&u-1)throw t(`a Huffman tree that is not complete`);a[o++]=32-Math.clz32(u);let f=1<<l,p=new Uint8Array(f),h=new Uint8Array(f),g=0;for(let e=1;e<=l;e++)for(let t=0;t<o;t++)if(a[t]===e){let n=1<<e-1;p.fill(t,g,g+n),h.fill(l+1-e,g,g+n),g+=n}return[{bits:l,symbol:p,length:h},s]}function g(e,n,r,i,a,o,s){let c=new d(n,r,i),{bits:l,symbol:u,length:f}=e;for(let e=0;e<s;e++){let t=c.peek(l);a[o+e]=u[t],c.pos-=f[t]}if(c.pos!==0)throw t(`a Huffman stream that does not end where its literals do`)}var _,v,y,b=class{length=0;constructor(e,t){this.limit=Math.min(e,t?.length??e),this.fixed=t!==void 0,this.capacity=t?.length,this.bytes=t??new Uint8Array(Math.min(e,65536))}reserve(e){if(this.fixed&&this.bytes.length!==this.capacity)throw t(`a detached output destination`);let n=this.length+e;if(n>this.limit)throw RangeError(`Zstandard output passes the ${this.limit}-byte limit; raise maxOutputSize if the data is trusted.`);if(n<=this.bytes.length)return;let r=new Uint8Array(Math.min(this.limit,Math.max(n,this.bytes.length*2)));r.set(this.bytes.subarray(0,this.length)),this.bytes=r}};function x(e,r,i,a,o){let s=e[r],c=s&3,l=s>>2&3;if(c<2){let a,u;if(l&1?l===1?(a=s>>4|e[r+1]<<4,u=2):(a=s>>4|e[r+1]<<4|e[r+2]<<12,u=3):(a=s>>3,u=1),a>n)throw t(`a literals section larger than a block`);let d=r+u;if(c===0){if(d+a>i)throw t(`truncated raw literals`);return[e.subarray(d,d+a),d+a]}if(d+1>i)throw t(`truncated RLE literals`);return o.fill(e[d],0,a),[o.subarray(0,a),d+1]}let u,d,f,p=e[r+1],m=e[r+2];if(l<2?(u=s>>4|(p&63)<<4,d=p>>6|m<<2,f=3):l===2?(u=s>>4|p<<4|(m&3)<<12,d=m>>2|e[r+3]<<6,f=4):(u=s>>4|p<<4|(m&63)<<12,d=m>>6|e[r+3]<<2|e[r+4]<<10,f=5),u>n)throw t(`a literals section larger than a block`);let _=r+f,v=_+d;if(v>i)throw t(`truncated compressed literals`);if(c===2){let[t,n]=h(e,_,v);a.huffman=t,_+=n}else if(!a.huffman)throw t(`treeless literals with no earlier Huffman tree`);let y=a.huffman;if(l===0)g(y,e,_,v-_,o,0,u);else{if(_+6>v)throw t(`a truncated literals jump table`);let n=e[_]|e[_+1]<<8,r=e[_+2]|e[_+3]<<8,i=e[_+4]|e[_+5]<<8,a=u+3>>2,s=u-3*a,c=_+6,l=v-c-n-r-i;if(l<1||s<0)throw t(`a literals jump table that does not fit`);g(y,e,c,n,o,0,a),c+=n,g(y,e,c,r,o,a,a),c+=r,g(y,e,c,i,o,2*a,a),c+=i,g(y,e,c,l,o,3*a,s)}return[o.subarray(0,u),v]}function S(e,n,r,i,a,o,s,c){if(e===0)return[o(),0];if(e===1){if(r>=i)throw t(`a missing RLE sequence symbol`);if(n[r]>c)throw t(`an RLE sequence symbol out of range`);return[p(n[r]),1]}if(e===2)return m(n,r,i,s,c);if(!a)throw t(`a repeated sequence table with no earlier table`);return[a,0]}function C(e,n,r,p,m,h,g,b){let[C,w]=x(e,n,r,g,b),T=w;if(T>=r)throw t(`a block without its sequences section`);let E=e[T++];if(E>=128&&(E<255?E=(E-128<<8)+e[T++]:(E=e[T]+(e[T+1]<<8)+32512,T+=2)),T>r)throw t(`a truncated sequences header`);let D=0;if(E>0){if(T>=r)throw t(`a truncated sequences header`);let n=e[T++];if(n&3)throw t(`reserved bits set in the sequence compression modes`);let b;if([g.ll,b]=S(n>>6,e,T,r,g.ll,()=>_??=f(c,36,6),9,35),T+=b,[g.of,b]=S(n>>4&3,e,T,r,g.of,()=>y??=f(u,29,5),8,31),T+=b,[g.ml,b]=S(n>>2&3,e,T,r,g.ml,()=>v??=f(l,53,6),9,52),T+=b,T>=r)throw t(`a missing sequences bitstream`);let x=g.ll,w=g.of,O=g.ml,k=new d(e,T,r-T),A=g.repeats,j=k.read(x.log),M=k.read(w.log),N=k.read(O.log);for(let e=0;e<E;e++){let n=w.symbol[M],r=O.symbol[N],c=x.symbol[j];if(n>31)throw t(`an offset code above 31`);let l=2**n+k.read(n),u=o[r]+k.read(s[r]),d=i[c]+k.read(a[c]),f;if(l>3)f=l-3,A[2]=A[1],A[1]=A[0],A[0]=f;else{let e=d===0?l:l-1;e===0?f=A[0]:(f=e===3?A[0]-1:A[e],e!==1&&(A[2]=A[1]),A[1]=A[0],A[0]=f)}if(e+1<E&&(j=x.base[j]+k.read(x.bits[j]),N=O.base[N]+k.read(O.bits[N]),M=w.base[M]+k.read(w.bits[M])),D+d>C.length)throw t(`a sequence that runs past its literals`);p.reserve(d+u);let g=p.bytes;g.set(C.subarray(D,D+d),p.length),D+=d,p.length+=d;let _=p.length-m;if(f<1||f>_||f>h)throw t(`a match offset of ${f} reaching before the start of the frame or window`);let v=p.length,y=v-f;if(f>=u)g.copyWithin(v,y,y+u);else for(let e=0;e<u;e++)g[v+e]=g[y+e];v+=u,p.length=v}if(k.pos!==0)throw t(`a sequences bitstream that does not end where its sequences do`)}else if(T!==r)throw t(`bytes after a block with no sequences`);let O=C.length-D;p.reserve(O),p.bytes.set(C.subarray(D),p.length),p.length+=O}async function w(e,t={}){let n=T(e,t);for(let e=n.next();;e=n.next()){if(e.done)return e.value;await new Promise(e=>setTimeout(e,0)),t.signal?.throwIfAborted()}}function*T(i,a){if(!(i instanceof Uint8Array))throw TypeError(`Expected Zstandard bytes as a Uint8Array`);let{signal:o,maxOutputSize:s=1<<28,maxWindowSize:c=1<<27,destination:l}=a;if(l!==void 0&&!(l instanceof Uint8Array))throw TypeError(`Expected a Zstandard destination as a Uint8Array`);if(l&&i.buffer===l.buffer&&i.byteOffset<l.byteOffset+l.length&&l.byteOffset<i.byteOffset+i.length)throw RangeError(`Zstandard input and destination overlap; use separate byte ranges.`);if(!(s>=0)||!(c>=0))throw RangeError(`maxOutputSize and maxWindowSize must be 0 or more bytes; pass byte counts.`);o?.throwIfAborted();let u=i,d=new b(s,l),f=new Uint8Array(n),p=0,m=r;if(u.length===0)throw t(`no frames`);for(;p<u.length;){if(p+4>u.length)throw t(`a truncated frame magic number`);let i=(u[p]|u[p+1]<<8|u[p+2]<<16|u[p+3]<<24)>>>0;if((i&4294967280)==407710288){if(p+8>u.length)throw t(`a truncated skippable frame`);let e=(u[p+4]|u[p+5]<<8|u[p+6]<<16|u[p+7]<<24)>>>0;if(p+=8+e,p>u.length)throw t(`a truncated skippable frame`);continue}if(i!==4247762216)throw t(`a wrong frame magic number`);if(p+=4,p>=u.length)throw t(`a truncated frame header`);let a=u[p++],s=a>>6,l=a>>5&1,h=a>>2&1,g=a&3;if(a&8)throw t(`a reserved frame header bit set`);let _=+!l+[0,1,2,4][g]+[l,2,4,8][s];if(p+_>u.length)throw t(`a truncated frame header`);let v=0;if(!l){let e=u[p++],t=2**(10+(e>>3));v=t+t/8*(e&7)}let y=0;for(let e=0,t=[0,1,2,4][g];e<t;e++)y+=u[p++]*2**(8*e);if(y!==0)throw e(`unsupported`,`This Zstandard frame needs dictionary ${y}, and dictionaries are not supported; compress without a dictionary.`);let b=-1,x=[l,2,4,8][s];if(x){b=0;for(let e=0;e<x;e++)b+=u[p++]*2**(8*e);x===2&&(b+=256)}if(l&&(v=b),v>c)throw RangeError(`A Zstandard frame needs a ${v}-byte window, above the ${c}-byte limit; raise maxWindowSize if the data is trusted.`);b>=0&&d.reserve(b);let S=d.length,w=Math.min(v,n),T={repeats:[1,4,8]};for(let e=0;!e;){if(o?.throwIfAborted(),d.length>=m&&(m=d.length+r,yield,o?.throwIfAborted()),p+3>u.length)throw t(`a truncated block header`);let n=u[p]|u[p+1]<<8|u[p+2]<<16;p+=3,e=n&1;let i=n>>1&3,a=n>>>3;if(i===3)throw t(`a reserved block type`);if(a>w)throw t(`a block larger than the frame allows`);if(i===1){if(p+1>u.length)throw t(`a truncated RLE block`);d.reserve(a),d.bytes.fill(u[p],d.length,d.length+a),d.length+=a,p+=1}else{if(p+a>u.length)throw t(`a truncated block`);if(i===0)d.reserve(a),d.bytes.set(u.subarray(p,p+a),d.length),d.length+=a;else{if(a===0)throw t(`an empty compressed block`);let e=d.length;if(C(u,p,p+a,d,S,v,T,f),d.length-e>w)throw t(`a block that decodes larger than the frame allows`)}p+=a}}let E=d.length-S;if(b>=0&&E!==b)throw t(`a frame that decodes to ${E} bytes but declares ${b}`);if(h){if(p+4>u.length)throw t(`a truncated content checksum`);let e=(u[p]|u[p+1]<<8|u[p+2]<<16|u[p+3]<<24)>>>0;if(p+=4,U(d.bytes,S,d.length)!==e)throw t(`a content checksum mismatch`)}}return d.fixed?d.bytes.subarray(0,d.length):d.bytes.length===d.length?d.bytes:d.bytes.slice(0,d.length)}var E=0,D=0,O=2654435761,k=2246822535,A=3266489917,j=668265295,M=374761393,N=2654435833,P=2246822519,F=3266489955,I=668265263,L=374761413;function R(e,t,n,r){let i=t&65535,a=t>>>16,o=r&65535,s=r>>>16,c=i*o,l=i*s,u=a*o,d=(c>>>16)+(l&65535)+(u&65535);D=(d<<16|c&65535)>>>0,E=a*s+(l>>>16)+(u>>>16)+(d>>>16)+Math.imul(t,n)+Math.imul(e,r)>>>0}function z(e,t,n,r){let i=t+r;D=i>>>0,E=e+n+ +(i>4294967295)>>>0}function B(e,t,n){if(n>=32){let r=e;e=t,t=r,n-=32}n===0?(E=e,D=t):(E=(e<<n|t>>>32-n)>>>0,D=(t<<n|e>>>32-n)>>>0)}function V(e,t,n,r){R(n,r,A,j),z(e,t,E,D),B(E,D,31),R(E,D,O,k)}var H=(e,t)=>(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0;function U(e,t,n){let r=n-t,i=t,a,o;if(r>=32){z(O,k,A,j);let t=E,r=D,s=A,c=j,l=0,u=0;z(0,0,1640531534,2048144760),z(E,D,0,1);let d=E,f=D;for(let a=n-32;i<=a;i+=32)V(t,r,H(e,i+4),H(e,i)),t=E,r=D,V(s,c,H(e,i+12),H(e,i+8)),s=E,c=D,V(l,u,H(e,i+20),H(e,i+16)),l=E,u=D,V(d,f,H(e,i+28),H(e,i+24)),d=E,f=D;B(t,r,1),a=E,o=D,B(s,c,7),z(a,o,E,D),a=E,o=D,B(l,u,12),z(a,o,E,D),a=E,o=D,B(d,f,18),z(a,o,E,D),a=E,o=D;for(let[e,n]of[[t,r],[s,c],[l,u],[d,f]])V(0,0,e,n),a=(a^E)>>>0,o=(o^D)>>>0,R(a,o,O,k),z(E,D,P,F),a=E,o=D}else a=I,o=L;for(z(a,o,Math.floor(r/2**32),r>>>0),a=E,o=D;i+8<=n;i+=8)V(0,0,H(e,i+4),H(e,i)),a=(a^E)>>>0,o=(o^D)>>>0,B(a,o,27),R(E,D,O,k),z(E,D,P,F),a=E,o=D;for(i+4<=n&&(R(0,H(e,i),O,k),a=(a^E)>>>0,o=(o^D)>>>0,B(a,o,23),R(E,D,A,j),z(E,D,M,N),a=E,o=D,i+=4);i<n;i++)R(0,e[i],I,L),a=(a^E)>>>0,o=(o^D)>>>0,B(a,o,11),R(E,D,O,k),a=E,o=D;return o=(o^a>>>1)>>>0,R(a,o,A,j),a=E,o=D,o=(o^(o>>>29|a<<3))>>>0,a=(a^a>>>29)>>>0,R(a,o,M,N),(D^E)>>>0}export{w as decompressZstd};
|
package/package.json
CHANGED
|
@@ -1,6 +1,107 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@margoengine/splats",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@margoengine/splats",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Optional Gaussian splats with GPU covariance projection and stable compute radix sorting.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"margoengine",
|
|
7
|
+
"webgpu",
|
|
8
|
+
"3d",
|
|
9
|
+
"gaussian-splatting"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://margoengine.com",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/scottcampbelldata/margoengine/issues"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/scottcampbelldata/margoengine.git",
|
|
18
|
+
"directory": "packages/splats"
|
|
19
|
+
},
|
|
20
|
+
"license": "Apache-2.0",
|
|
21
|
+
"author": "Scott Campbell",
|
|
22
|
+
"type": "module",
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"test:gpu": "cd ../.. && node packages/splats/test/gpu/check.mjs",
|
|
28
|
+
"test": "node --test test/*.test.js ../../tests/modern-temporal.test.js ../../tests/modern-data-subpaths.test.js ../../examples/package-benchmarks/proofs/package-guard.mjs",
|
|
29
|
+
"prepack": "npm --prefix ../.. run build:packages",
|
|
30
|
+
"test:gpu:formats": "cd ../.. && node packages/splats/test/gpu/formats-check.mjs && node packages/splats/test/gpu/formats-check.mjs --compat",
|
|
31
|
+
"test:gpu:lod-sog": "cd ../.. && node packages/splats/test/gpu/lod-sog-check.mjs",
|
|
32
|
+
"test:gpu:modify": "cd ../.. && node packages/splats/test/gpu/modify-check.mjs",
|
|
33
|
+
"test:gpu:scale": "cd ../.. && node packages/splats/test/gpu/scale-check.mjs"
|
|
34
|
+
},
|
|
35
|
+
"sideEffects": false,
|
|
36
|
+
"exports": {
|
|
37
|
+
".": {
|
|
38
|
+
"types": "./dist/index.d.ts",
|
|
39
|
+
"import": "./dist/index.js"
|
|
40
|
+
},
|
|
41
|
+
"./depth": {
|
|
42
|
+
"types": "./dist/depth.d.ts",
|
|
43
|
+
"import": "./dist/depth.js"
|
|
44
|
+
},
|
|
45
|
+
"./lod": {
|
|
46
|
+
"types": "./dist/lod.d.ts",
|
|
47
|
+
"import": "./dist/lod.js"
|
|
48
|
+
},
|
|
49
|
+
"./lighting": {
|
|
50
|
+
"types": "./dist/lighting.d.ts",
|
|
51
|
+
"import": "./dist/lighting.js"
|
|
52
|
+
},
|
|
53
|
+
"./set": {
|
|
54
|
+
"types": "./dist/set.d.ts",
|
|
55
|
+
"import": "./dist/set.js"
|
|
56
|
+
},
|
|
57
|
+
"./session": {
|
|
58
|
+
"types": "./dist/session.d.ts",
|
|
59
|
+
"import": "./dist/session.js"
|
|
60
|
+
},
|
|
61
|
+
"./edit": {
|
|
62
|
+
"types": "./dist/brush.d.ts",
|
|
63
|
+
"import": "./dist/brush.js"
|
|
64
|
+
},
|
|
65
|
+
"./pick": {
|
|
66
|
+
"types": "./dist/pick.d.ts",
|
|
67
|
+
"import": "./dist/pick.js"
|
|
68
|
+
},
|
|
69
|
+
"./animate": {
|
|
70
|
+
"types": "./dist/animate.d.ts",
|
|
71
|
+
"import": "./dist/animate.js"
|
|
72
|
+
},
|
|
73
|
+
"./data": {
|
|
74
|
+
"types": "./dist/data.d.ts",
|
|
75
|
+
"import": "./dist/data.js"
|
|
76
|
+
},
|
|
77
|
+
"./progressive": {
|
|
78
|
+
"types": "./dist/progressive.d.ts",
|
|
79
|
+
"import": "./dist/progressive.js"
|
|
80
|
+
},
|
|
81
|
+
"./formats": {
|
|
82
|
+
"types": "./dist/formats.d.ts",
|
|
83
|
+
"import": "./dist/formats.js"
|
|
84
|
+
},
|
|
85
|
+
"./lod-sog": {
|
|
86
|
+
"types": "./dist/lod-sog.d.ts",
|
|
87
|
+
"import": "./dist/lod-sog.js"
|
|
88
|
+
},
|
|
89
|
+
"./modify": {
|
|
90
|
+
"types": "./dist/modify.d.ts",
|
|
91
|
+
"import": "./dist/modify.js"
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
"files": [
|
|
95
|
+
"dist",
|
|
96
|
+
"NOTICE"
|
|
97
|
+
],
|
|
98
|
+
"dependencies": {
|
|
99
|
+
"@margoengine/math": "^0.1.0"
|
|
100
|
+
},
|
|
101
|
+
"peerDependencies": {
|
|
102
|
+
"@margoengine/core": "^0.1.0"
|
|
103
|
+
},
|
|
104
|
+
"devDependencies": {
|
|
105
|
+
"@margoengine/decoders": "^0.1.0"
|
|
106
|
+
}
|
|
107
|
+
}
|