x_ite-spz-parser 1.0.0 → 1.0.2
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/dist/x_ite-spz-parser.js +1 -1
- package/package.json +1 -1
package/dist/x_ite-spz-parser.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const X3D=window[Symbol.for("X_ITE.X3D")],ANTIALIASED_FLAG=1,COLOR_SCALE=.15;class SPZParser extends X3D.X3DParser{constructor(e){super(e),this.offset=0}getEncoding(){return"ARRAY_BUFFER"}setInput(e){this.buffer=e,this.dataView=new DataView(e),this.header=this.parseHeader()}isValid(){const{magic:e,version:s,shDegree:t}=this.header;return 1347635022===e&&(!(s<1||s>2)&&!(t>3))}parseIntoScene(e,s){this.spz().then(e).catch(s)}async spz(){const e=this.getBrowser(),s=this.getScene();s.setEncoding("SPZ"),s.setProfile(e.getProfile("Interchange")),s.addComponent(e.getComponent("X_ITE")),await this.getBrowser().loadComponents(s);const t=s.createNode("Transform"),r=s.createNode("GaussianSplats"),o=this.parseSplats();r.positions=o.positions,r.orientations=o.orientations,r.scales=o.scales,r.opacities=o.opacities,r.sphericalHarmonicsDegree0Coef0=o.colors;const i=this.header.shDegree;for(let e=0;e<i;++e){const s=this.coefsForDegree(e);for(let t=0;t<s;++t)r[`sphericalHarmonicsDegree${e+1}Coef${t}`]=o.shs[e][t]}return t.rotation=new X3D.Rotation4(1,0,0,Math.PI),t.children.push(r),s.rootNodes.push(t),s}parseHeader(){const{dataView:e}=this,s={magic:e.getUint32(this.offset,!0),version:e.getUint32(this.offset+=4,!0),numPoints:e.getUint32(this.offset+=4,!0),shDegree:e.getUint8(this.offset+=4),fractionalBits:e.getUint8(this.offset+=1),flags:e.getUint8(this.offset+=1),reserved:e.getUint8(this.offset+=1)};return this.offset+=1,s}parseSplats(){const{version:e,numPoints:s,shDegree:t,fractionalBits:r,flags:o}=this.header,i={numPoints:s,shDegree:t,fractionalBits:r,antialiased:!!(1&o),numPositions:3*s*(1===e?2:3),numRotations:3*s,numScales:3*s,numOpacities:s,numColors:3*s,numShs:s*this.dimForDegree(t)*3},n=new Uint8Array(this.buffer);let a=this.offset;if(i.positions=n.subarray(a,a+=i.numPositions),i.opacities=n.subarray(a,a+=i.numOpacities),i.colors=n.subarray(a,a+=i.numColors),i.scales=n.subarray(a,a+=i.numScales),i.rotations=n.subarray(a,a+=i.numRotations),i.shs=n.subarray(a,a+=i.numShs),a!==this.buffer.byteLength)throw new Error("x_ite-spz-parser: incorrect buffer size.");return this.unpackSplats(i)}unpackSplats(e){const{numPoints:s,positions:t,rotations:r,scales:o,colors:i,shs:n,shDegree:a}=e,h=this.dimForDegree(a),c=t.length===3*s*2;if(!this.checkSizes2(e,s,h,c))throw new Error("x_ite-spz-parser: incorrect array sizes.");const
|
|
1
|
+
const X3D=window[Symbol.for("X_ITE.X3D")],ANTIALIASED_FLAG=1,COLOR_SCALE=.15;class SPZParser extends X3D.X3DParser{constructor(e){super(e),this.offset=0}getEncoding(){return"ARRAY_BUFFER"}setInput(e){this.buffer=e,this.dataView=new DataView(e),this.header=this.parseHeader()}isValid(){const{magic:e,version:s,shDegree:t}=this.header;return 1347635022===e&&(!(s<1||s>2)&&!(t>3))}parseIntoScene(e,s){this.spz().then(e).catch(s)}async spz(){const e=this.getBrowser(),s=this.getScene();s.setEncoding("SPZ"),s.setProfile(e.getProfile("Interchange")),s.addComponent(e.getComponent("X_ITE")),await this.getBrowser().loadComponents(s);const t=s.createNode("Transform"),r=s.createNode("GaussianSplats"),o=this.parseSplats();r.positions=o.positions,r.orientations=o.orientations,r.scales=o.scales,r.opacities=o.opacities,r.sphericalHarmonicsDegree0Coef0=o.colors;const i=this.header.shDegree;for(let e=0;e<i;++e){const s=this.coefsForDegree(e);for(let t=0;t<s;++t)r[`sphericalHarmonicsDegree${e+1}Coef${t}`]=o.shs[e][t]}return t.rotation=new X3D.Rotation4(1,0,0,Math.PI),t.children.push(r),s.rootNodes.push(t),s}parseHeader(){const{dataView:e}=this,s={magic:e.getUint32(this.offset,!0),version:e.getUint32(this.offset+=4,!0),numPoints:e.getUint32(this.offset+=4,!0),shDegree:e.getUint8(this.offset+=4),fractionalBits:e.getUint8(this.offset+=1),flags:e.getUint8(this.offset+=1),reserved:e.getUint8(this.offset+=1)};return this.offset+=1,s}parseSplats(){const{version:e,numPoints:s,shDegree:t,fractionalBits:r,flags:o}=this.header,i={numPoints:s,shDegree:t,fractionalBits:r,antialiased:!!(1&o),numPositions:3*s*(1===e?2:3),numRotations:3*s,numScales:3*s,numOpacities:s,numColors:3*s,numShs:s*this.dimForDegree(t)*3},n=new Uint8Array(this.buffer);let a=this.offset;if(i.positions=n.subarray(a,a+=i.numPositions),i.opacities=n.subarray(a,a+=i.numOpacities),i.colors=n.subarray(a,a+=i.numColors),i.scales=n.subarray(a,a+=i.numScales),i.rotations=n.subarray(a,a+=i.numRotations),i.shs=n.subarray(a,a+=i.numShs),a!==this.buffer.byteLength)throw new Error("x_ite-spz-parser: incorrect buffer size.");return this.unpackSplats(i)}unpackSplats(e){const{numPoints:s,positions:t,rotations:r,scales:o,colors:i,shs:n,shDegree:a}=e,h=this.dimForDegree(a),c=t.length===3*s*2;if(!this.checkSizes2(e,s,h,c))throw new Error("x_ite-spz-parser: incorrect array sizes.");const u=[],f=[],l=[],p=[],g=[],m=Array.from({length:a},(e,s)=>Array.from({length:this.coefsForDegree(s)}).map(()=>[]));let d;c&&(d=new Uint16Array(t.buffer,t.byteOffset,3*s));const D=1/(1<<e.fractionalBits),S=this.dimForDegree(a);for(let h=0;h<s;++h){if(c)for(let e=0;e<3;++e)u.push(this.halfToFloat(d[3*h+e]));else for(let e=0;e<3;++e){const s=9*h+3*e;let r=t[s];r|=t[s+1]<<8,r|=t[s+2]<<16,r|=8388608&r?4278190080:0,u.push(r*D)}for(let e=0;e<3;++e)l.push(Math.exp(o[3*h+e]/16-10));const s=r.subarray(3*h,3*h+3),w=[s[0]/127.5-1,s[1]/127.5-1,s[2]/127.5-1];f.push(w[0]),f.push(w[1]),f.push(w[2]);const y=Math.hypot(w[0],w[1],w[2]);f.push(Math.sqrt(Math.max(0,1-y))),p.push(e.opacities[h]/255);for(let e=0;e<3;++e)g.push((i[3*h+e]/255-.5)/.15);for(let e=0,s=0;e<a;++e){const t=this.coefsForDegree(e);for(let r=0;r<t;++r)for(let t=0;t<3;++t,++s)m[e][r].push(this.unquantizeSH(n[S*h*3+s]))}}return{positions:u,orientations:f,scales:l,opacities:p,colors:g,shs:m}}checkSizes2(e,s,t,r){return e.positions.length===3*s*(r?2:3)&&(e.scales.length===3*s&&(e.rotations.length===3*s&&(e.opacities.length===s&&(e.colors.length===3*s&&e.shs.length===s*t*3))))}halfToFloat(e){const s=e>>10&31,t=1023&e,r=1===(e>>15&1)?-1:1;return 0===s?r*Math.pow(2,-14)*t/1024:31===s?0!==t?NaN:r*(1/0):r*Math.pow(2,s-15)*(1+t/1024)}unquantizeSH(e){return(e-128)/128}dimForDegree(e){switch(e){case 0:return 0;case 1:return 3;case 2:return 8;case 3:return 15}}coefsForDegree(e){switch(e){case 0:return 3;case 1:return 5;case 2:return 7}}}X3D.GoldenGate.addParsers(SPZParser);
|