MCPcopy
hub / github.com/sparkjsdev/spark / maybeUpdateSource

Method maybeUpdateSource

src/PackedSplats.ts:700–737  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

698
699 // Check if source texture needs to be created/updated
700 private maybeUpdateSource(): THREE.DataArrayTexture {
701 if (!this.packedArray) {
702 throw new Error("No packed splats");
703 }
704
705 if (this.needsUpdate || !this.source) {
706 this.needsUpdate = false;
707
708 if (this.source) {
709 const { width, height, depth } = this.source.image;
710 if (this.maxSplats !== width * height * depth) {
711 // The existing source texture isn't the right size, so dispose it
712 this.source.dispose();
713 this.source = null;
714 }
715 }
716 if (!this.source) {
717 // Allocate a new source texture of the right size
718 const { width, height, depth } = getTextureSize(this.maxSplats);
719 this.source = new THREE.DataArrayTexture(
720 this.packedArray as Uint32Array<ArrayBuffer>,
721 width,
722 height,
723 depth,
724 );
725 this.source.format = THREE.RGBAIntegerFormat;
726 this.source.type = THREE.UnsignedIntType;
727 this.source.internalFormat = "RGBA32UI";
728 this.source.needsUpdate = true;
729 } else if (this.packedArray.buffer !== this.source.image.data.buffer) {
730 // The source texture is the right size, update the data
731 this.source.image.data = new Uint8Array(this.packedArray.buffer);
732 }
733 // Indicate to Three.js that the source texture needs to be uploaded to the GPU
734 this.source.needsUpdate = true;
735 }
736 return this.source;
737 }
738
739 static getEmptyArray = (() => {
740 const { width, height, depth, maxSplats } = getTextureSize(1);

Callers 1

getTextureMethod · 0.95

Calls 2

getTextureSizeFunction · 0.90
disposeMethod · 0.65

Tested by

no test coverage detected