| 108 | // of the axis direction and a uint8 to encode rotation amount from 0..Pi. |
| 109 | |
| 110 | export class PackedSplats implements SplatSource { |
| 111 | maxSplats = 0; |
| 112 | numSplats = 0; |
| 113 | packedArray: Uint32Array | null = null; |
| 114 | extra: Record<string, unknown>; |
| 115 | maxSh = 3; |
| 116 | splatEncoding?: SplatEncoding; |
| 117 | lod?: boolean | "quality"; |
| 118 | nonLod?: boolean; |
| 119 | lodSplats?: PackedSplats; |
| 120 | |
| 121 | initialized: Promise<PackedSplats>; |
| 122 | isInitialized = false; |
| 123 | |
| 124 | // Either target or source will be non-null, depending on whether the PackedSplats |
| 125 | // is being used as a data source or generated to. |
| 126 | target: THREE.WebGLArrayRenderTarget | null = null; |
| 127 | source: THREE.DataArrayTexture | null = null; |
| 128 | // Set to true if source packedArray is updated to have it upload to GPU |
| 129 | needsUpdate = true; |
| 130 | |
| 131 | // A PackedSplats can be used in a dyno graph using the below property dyno: |
| 132 | // const gsplat = dyno.readPackedSplats(this.dyno, dynoIndex); |
| 133 | dyno: DynoUniform<typeof TPackedSplats, "packedSplats">; |
| 134 | dynoRgbMinMaxLnScaleMinMax: DynoUniform<"vec4", "rgbMinMaxLnScaleMinMax">; |
| 135 | dynoNumSh: DynoInt<"numSh">; |
| 136 | dynoShMax: DynoVec3<THREE.Vector3, "shMax">; |
| 137 | |
| 138 | constructor(options: PackedSplatsOptions = {}) { |
| 139 | this.extra = {}; |
| 140 | this.dyno = new DynoPackedSplats({ packedSplats: this }); |
| 141 | this.dynoRgbMinMaxLnScaleMinMax = new DynoVec4({ |
| 142 | key: "rgbMinMaxLnScaleMinMax", |
| 143 | value: new THREE.Vector4(0.0, 1.0, LN_SCALE_MIN, LN_SCALE_MAX), |
| 144 | update: (value) => { |
| 145 | value.set( |
| 146 | this.splatEncoding?.rgbMin ?? 0.0, |
| 147 | this.splatEncoding?.rgbMax ?? 1.0, |
| 148 | this.splatEncoding?.lnScaleMin ?? LN_SCALE_MIN, |
| 149 | this.splatEncoding?.lnScaleMax ?? LN_SCALE_MAX, |
| 150 | ); |
| 151 | return value; |
| 152 | }, |
| 153 | }); |
| 154 | this.dynoNumSh = new DynoInt({ |
| 155 | key: "numSh", |
| 156 | value: 0, |
| 157 | update: () => { |
| 158 | return Math.min(this.getNumSh(), this.maxSh); |
| 159 | }, |
| 160 | }); |
| 161 | this.dynoShMax = new DynoVec3({ |
| 162 | key: "shMax", |
| 163 | value: new THREE.Vector3(), |
| 164 | update: (value) => { |
| 165 | value.set( |
| 166 | this.splatEncoding?.sh1Max ?? 1.0, |
| 167 | this.splatEncoding?.sh2Max ?? 1.0, |
nothing calls this directly
no test coverage detected