rayzee 7.6.0 → 7.8.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.
@@ -34,14 +34,18 @@ export class MaterialDataManager {
34
34
  this.materialStorageNode = null;
35
35
  this.materialCount = 0;
36
36
 
37
- // Material texture arrays
38
- this.albedoMaps = null;
39
- this.emissiveMaps = null;
40
- this.normalMaps = null;
41
- this.bumpMaps = null;
42
- this.roughnessMaps = null;
43
- this.metalnessMaps = null;
44
- this.displacementMaps = null;
37
+ // Consolidated size-bucketed material texture arrays (see SceneProcessor._bucketTextures):
38
+ // srgbBuckets[K] — albedo + emissive (SRGBColorSpace)
39
+ // linearBuckets[K] normal/bump/roughness/metalness/displacement
40
+ // Each entry is a DataArrayTexture | null (null = empty bucket).
41
+ this.srgbBuckets = null;
42
+ this.linearBuckets = null;
43
+
44
+ // uuid → packed (bucket,layer) index maps for the current scene, handed over by the
45
+ // SceneProcessor that built the buckets. Let runtime material edits (updateMaterial)
46
+ // re-pack a texture's index against the current bucket layout.
47
+ this._srgbTexPacked = null;
48
+ this._linearTexPacked = null;
45
49
 
46
50
  // Compiled features cache (for change detection)
47
51
  this.compiledFeatures = null;
@@ -112,45 +116,60 @@ export class MaterialDataManager {
112
116
  */
113
117
  setMaterialTextures( textures ) {
114
118
 
115
- if ( textures.albedoMaps ) this.albedoMaps = textures.albedoMaps;
116
- if ( textures.emissiveMaps ) this.emissiveMaps = textures.emissiveMaps;
117
- if ( textures.normalMaps ) this.normalMaps = textures.normalMaps;
118
- if ( textures.bumpMaps ) this.bumpMaps = textures.bumpMaps;
119
- if ( textures.roughnessMaps ) this.roughnessMaps = textures.roughnessMaps;
120
- if ( textures.metalnessMaps ) this.metalnessMaps = textures.metalnessMaps;
121
- if ( textures.displacementMaps ) this.displacementMaps = textures.displacementMaps;
119
+ if ( textures.srgbBuckets ) this.srgbBuckets = textures.srgbBuckets;
120
+ if ( textures.linearBuckets ) this.linearBuckets = textures.linearBuckets;
122
121
 
123
122
  }
124
123
 
125
124
  /**
126
- * Load texture arrays from sdfs.
125
+ * Receive the scene's uuid→packed texture-index maps (from the SceneProcessor that bucketed).
126
+ * @param {Map|null} srgb
127
+ * @param {Map|null} linear
128
+ */
129
+ setTexturePackMaps( srgb, linear ) {
130
+
131
+ this._srgbTexPacked = srgb || null;
132
+ this._linearTexPacked = linear || null;
133
+
134
+ }
135
+
136
+ /**
137
+ * Packed (bucket, layer) index for a Three.js texture against the current bucket layout,
138
+ * or -1 if it isn't bucketed (a genuinely new texture → needs rebuildMaterials).
139
+ * @param {import('three').Texture|null} texture
140
+ * @param {boolean} isSrgb - true for albedo/emissive pool, false for the linear pool
141
+ * @returns {number}
142
+ */
143
+ getPackedTextureIndex( texture, isSrgb ) {
144
+
145
+ if ( ! texture ) return - 1;
146
+ const uuid = texture.source?.uuid ?? texture.uuid;
147
+ const map = isSrgb ? this._srgbTexPacked : this._linearTexPacked;
148
+ const packed = map?.get( uuid );
149
+ return packed === undefined ? - 1 : packed;
150
+
151
+ }
152
+
153
+ /**
154
+ * Load consolidated bucket arrays + pack maps from the SceneProcessor.
127
155
  */
128
156
  loadTexturesFromSdfs() {
129
157
 
130
- this.albedoMaps = this.sdfs.albedoTextures;
131
- this.emissiveMaps = this.sdfs.emissiveTextures;
132
- this.normalMaps = this.sdfs.normalTextures;
133
- this.bumpMaps = this.sdfs.bumpTextures;
134
- this.roughnessMaps = this.sdfs.roughnessTextures;
135
- this.metalnessMaps = this.sdfs.metalnessTextures;
136
- this.displacementMaps = this.sdfs.displacementTextures;
158
+ this.srgbBuckets = this.sdfs.srgbBucketTextures;
159
+ this.linearBuckets = this.sdfs.linearBucketTextures;
160
+ this.setTexturePackMaps( this.sdfs._srgbTexPacked, this.sdfs._linearTexPacked );
137
161
 
138
162
  }
139
163
 
140
164
  /**
141
- * Get all texture arrays.
142
- * @returns {Object}
165
+ * Get the consolidated bucket arrays.
166
+ * @returns {{ srgbBuckets: Array, linearBuckets: Array }}
143
167
  */
144
168
  getTextureArrays() {
145
169
 
146
170
  return {
147
- albedoMaps: this.albedoMaps,
148
- emissiveMaps: this.emissiveMaps,
149
- normalMaps: this.normalMaps,
150
- bumpMaps: this.bumpMaps,
151
- roughnessMaps: this.roughnessMaps,
152
- metalnessMaps: this.metalnessMaps,
153
- displacementMaps: this.displacementMaps,
171
+ srgbBuckets: this.srgbBuckets,
172
+ linearBuckets: this.linearBuckets,
154
173
  };
155
174
 
156
175
  }
@@ -550,6 +569,22 @@ export class MaterialDataManager {
550
569
  updateMaterial( materialIndex, material ) {
551
570
 
552
571
  const completeMaterialData = this.sdfs.geometryExtractor.createMaterialObject( material );
572
+
573
+ // createMaterialObject returns stale per-type indices; re-pack each map to the packed
574
+ // (bucket, layer) index for the CURRENT bucket layout. -1 for a texture not yet bucketed
575
+ // (a genuinely new map → the caller must rebuildMaterials to add it to a bucket array).
576
+ if ( this._srgbTexPacked || this._linearTexPacked ) {
577
+
578
+ completeMaterialData.map = this.getPackedTextureIndex( material.map, true );
579
+ completeMaterialData.emissiveMap = this.getPackedTextureIndex( material.emissiveMap, true );
580
+ completeMaterialData.normalMap = this.getPackedTextureIndex( material.normalMap, false );
581
+ completeMaterialData.bumpMap = this.getPackedTextureIndex( material.bumpMap, false );
582
+ completeMaterialData.roughnessMap = this.getPackedTextureIndex( material.roughnessMap, false );
583
+ completeMaterialData.metalnessMap = this.getPackedTextureIndex( material.metalnessMap, false );
584
+ completeMaterialData.displacementMap = this.getPackedTextureIndex( material.displacementMap, false );
585
+
586
+ }
587
+
553
588
  this.updateMaterialDataFromObject( materialIndex, completeMaterialData );
554
589
 
555
590
  }
@@ -813,13 +848,10 @@ export class MaterialDataManager {
813
848
  this.materialStorageAttr = null;
814
849
  this.materialStorageNode = null;
815
850
  this.materialCount = 0;
816
- this.albedoMaps = null;
817
- this.emissiveMaps = null;
818
- this.normalMaps = null;
819
- this.bumpMaps = null;
820
- this.roughnessMaps = null;
821
- this.metalnessMaps = null;
822
- this.displacementMaps = null;
851
+ this.srgbBuckets = null;
852
+ this.linearBuckets = null;
853
+ this._srgbTexPacked = null;
854
+ this._linearTexPacked = null;
823
855
  this.compiledFeatures = null;
824
856
 
825
857
  }