@kitware/vtk.js 33.1.1 → 33.2.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.
@@ -208,16 +208,15 @@ async function createPropertyFromGLTFMaterial(model, material, actor) {
208
208
  property.setDiffuseTexture(diffuseTex);
209
209
  }
210
210
  }
211
+
212
+ // Handle metallic-roughness texture (metallicRoughnessTexture)
211
213
  if (pbr.metallicRoughnessTexture) {
212
214
  pbr.metallicRoughnessTexture.extensions;
213
215
  const tex = pbr.metallicRoughnessTexture.texture;
214
216
  const sampler = tex.sampler;
215
- const metallicImage = await loadImage(tex.source, 'b');
216
- const metallicTex = createVTKTextureFromGLTFTexture(metallicImage, sampler);
217
- property.setMetallicTexture(metallicTex);
218
- const roughnessImage = await loadImage(tex.source, 'g');
219
- const roughnessTex = createVTKTextureFromGLTFTexture(roughnessImage, sampler);
220
- property.setRoughnessTexture(roughnessTex);
217
+ const rmImage = await loadImage(tex.source);
218
+ const rmTex = createVTKTextureFromGLTFTexture(rmImage, sampler);
219
+ property.setRMTexture(rmTex);
221
220
  }
222
221
 
223
222
  // Handle ambient occlusion texture (occlusionTexture)
@@ -1,5 +1,5 @@
1
1
  import { vtkObject } from './../../interfaces';
2
- import { RGBColor } from './../../types';
2
+ import { Nullable, RGBColor } from './../../types';
3
3
  import { Interpolation, Representation, Shading } from './Property/Constants';
4
4
  import { vtkTexture } from './Texture';
5
5
 
@@ -14,6 +14,8 @@ export interface IPropertyInitialValues {
14
14
  normalTexture?: vtkTexture;
15
15
  ambientOcclusionTexture?: vtkTexture;
16
16
  emissionTexture?: vtkTexture;
17
+ RMTexture?: vtkTexture;
18
+ ORMTexture?: vtkTexture;
17
19
  edgeColor?: RGBColor;
18
20
  ambient?: number;
19
21
  diffuse?: number;
@@ -216,32 +218,42 @@ export interface vtkProperty extends vtkObject {
216
218
  /**
217
219
  * Get the diffuse texture.
218
220
  */
219
- getDiffuseTexture(): vtkTexture;
221
+ getDiffuseTexture(): Nullable<vtkTexture>;
220
222
 
221
223
  /**
222
224
  * Get the metallic texture.
223
225
  */
224
- getMetallicTexture(): vtkTexture;
226
+ getMetallicTexture(): Nullable<vtkTexture>;
227
+
228
+ /**
229
+ * Get the roughness & metallic texture.
230
+ */
231
+ getRMTexture(): Nullable<vtkTexture>;
232
+
233
+ /**
234
+ * Get the occlusion, roughness & metallic texture.
235
+ */
236
+ getORMTexture(): Nullable<vtkTexture>;
225
237
 
226
238
  /**
227
239
  * Get the roughness texture.
228
240
  */
229
- getRoughnessTexture(): vtkTexture;
241
+ getRoughnessTexture(): Nullable<vtkTexture>;
230
242
 
231
243
  /**
232
244
  * Get the normal texture.
233
245
  */
234
- getNormalTexture(): vtkTexture;
246
+ getNormalTexture(): Nullable<vtkTexture>;
235
247
 
236
248
  /**
237
249
  * Get the ambient occlusion texture.
238
250
  */
239
- getAmbientOcclusionTexture(): vtkTexture;
251
+ getAmbientOcclusionTexture(): Nullable<vtkTexture>;
240
252
 
241
253
  /**
242
254
  * Get the emission texture.
243
255
  */
244
- getEmissionTexture(): vtkTexture;
256
+ getEmissionTexture(): Nullable<vtkTexture>;
245
257
 
246
258
  /**
247
259
  * Set the ambient lighting coefficient.
@@ -500,6 +512,18 @@ export interface vtkProperty extends vtkObject {
500
512
  */
501
513
  setRoughnessTexture(roughnessTexture: vtkTexture): boolean;
502
514
 
515
+ /**
516
+ * Set the roughness & metallic texture.
517
+ * @param {vtkTexture} RMTexture
518
+ */
519
+ setRMTexture(RMTexture: vtkTexture): boolean;
520
+
521
+ /**
522
+ * Set the occlusion, roughness & metallic texture.
523
+ * @param {vtkTexture} ORMTexture
524
+ */
525
+ setORMTexture(ORMTexture: vtkTexture): boolean;
526
+
503
527
  /**
504
528
  * Set the normal texture.
505
529
  * @param {vtkTexture} normalTexture
@@ -94,7 +94,9 @@ const DEFAULT_VALUES = {
94
94
  lineWidth: 1,
95
95
  lighting: true,
96
96
  shading: false,
97
- materialName: null
97
+ materialName: null,
98
+ ORMTexture: null,
99
+ RMTexture: null
98
100
  };
99
101
 
100
102
  // ----------------------------------------------------------------------------
@@ -105,7 +107,7 @@ function extend(publicAPI, model) {
105
107
 
106
108
  // Build VTK API
107
109
  macro.obj(publicAPI, model);
108
- macro.setGet(publicAPI, model, ['lighting', 'interpolation', 'ambient', 'diffuse', 'metallic', 'roughness', 'normalStrength', 'emission', 'baseIOR', 'specular', 'specularPower', 'opacity', 'edgeVisibility', 'lineWidth', 'pointSize', 'backfaceCulling', 'frontfaceCulling', 'representation', 'diffuseTexture', 'metallicTexture', 'roughnessTexture', 'normalTexture', 'ambientOcclusionTexture', 'emissionTexture']);
110
+ macro.setGet(publicAPI, model, ['lighting', 'interpolation', 'ambient', 'diffuse', 'metallic', 'roughness', 'normalStrength', 'emission', 'baseIOR', 'specular', 'specularPower', 'opacity', 'edgeVisibility', 'lineWidth', 'pointSize', 'backfaceCulling', 'frontfaceCulling', 'representation', 'diffuseTexture', 'metallicTexture', 'roughnessTexture', 'normalTexture', 'ambientOcclusionTexture', 'emissionTexture', 'ORMTexture', 'RMTexture']);
109
111
  macro.setGetArray(publicAPI, model, ['ambientColor', 'specularColor', 'diffuseColor', 'edgeColor'], 3);
110
112
 
111
113
  // Object methods
@@ -42,13 +42,14 @@ function vtkWebGPUBuffer(publicAPI, model) {
42
42
  bufferSubData(model.device.getHandle(), model.handle, 0, data.buffer);
43
43
  };
44
44
  publicAPI.createAndWrite = (data, usage) => {
45
+ const paddedSize = Math.ceil(data.byteLength / 4) * 4;
45
46
  model.handle = model.device.getHandle().createBuffer({
46
- size: data.byteLength,
47
+ size: paddedSize,
47
48
  usage,
48
49
  mappedAtCreation: true,
49
50
  label: model.label
50
51
  });
51
- model.sizeInBytes = data.byteLength;
52
+ model.sizeInBytes = paddedSize;
52
53
  model.usage = usage;
53
54
  new Uint8Array(model.handle.getMappedRange()).set(new Uint8Array(data.buffer)); // memcpy
54
55
  model.handle.unmap();
@@ -595,44 +595,65 @@ function vtkWebGPUCellArrayMapper(publicAPI, model) {
595
595
  const fDesc = pipeline.getShaderDescription('fragment');
596
596
  code = fDesc.getCode();
597
597
  const actor = model.WebGPUActor.getRenderable();
598
+ const property = actor.getProperty();
598
599
  const checkDims = texture => {
599
600
  if (!texture) return false;
600
601
  const dims = texture.getDimensionality();
601
602
  return dims === numComp;
602
603
  };
603
604
  const usedTextures = [];
604
- if (actor.getProperty().getDiffuseTexture?.()?.getImageLoaded() || actor.getTextures()[0] || model.colorTexture) {
605
+ const diffuseTexture = property.getDiffuseTexture?.();
606
+ if (diffuseTexture?.getImageLoaded() || actor.getTextures()[0] || model.colorTexture) {
605
607
  if (
606
608
  // Chained or statements here are questionable
607
- checkDims(actor.getProperty().getDiffuseTexture?.()) || checkDims(actor.getTextures()[0]) || checkDims(model.colorTexture)) {
609
+ checkDims(diffuseTexture) || checkDims(actor.getTextures()[0]) || checkDims(model.colorTexture)) {
608
610
  usedTextures.push('_diffuseMap = textureSample(DiffuseTexture, DiffuseTextureSampler, input.tcoordVS);');
609
611
  }
610
612
  }
611
- if (actor.getProperty().getRoughnessTexture?.()?.getImageLoaded()) {
612
- if (checkDims(actor.getProperty().getRoughnessTexture())) {
613
- usedTextures.push('_roughnessMap = textureSample(RoughnessTexture, RoughnessTextureSampler, input.tcoordVS);');
613
+ const ormTexture = property.getORMTexture?.();
614
+ const rmTexture = property.getRMTexture?.();
615
+ const roughnessTexture = property.getRoughnessTexture?.();
616
+ const metallicTexture = property.getMetallicTexture?.();
617
+ const ambientOcclusionTexture = property.getAmbientOcclusionTexture?.();
618
+ const emissionTexture = property.getEmissionTexture?.();
619
+ const normalTexture = property.getNormalTexture?.();
620
+
621
+ // ORM texture support: if present, sample R/G/B for AO/Roughness/Metallic
622
+ if (ormTexture?.getImageLoaded()) {
623
+ if (checkDims(ormTexture)) {
624
+ usedTextures.push('_ambientOcclusionMap = textureSample(ORMTexture, ORMTextureSampler, input.tcoordVS).rrra;', '_roughnessMap = textureSample(ORMTexture, ORMTextureSampler, input.tcoordVS).ggga;', '_metallicMap = textureSample(ORMTexture, ORMTextureSampler, input.tcoordVS).bbba;');
614
625
  }
615
- }
616
- if (actor.getProperty().getMetallicTexture?.()?.getImageLoaded()) {
617
- if (checkDims(actor.getProperty().getMetallicTexture())) {
618
- usedTextures.push('_metallicMap = textureSample(MetallicTexture, MetallicTextureSampler, input.tcoordVS);');
626
+ } else if (rmTexture?.getImageLoaded()) {
627
+ if (checkDims(rmTexture)) {
628
+ usedTextures.push('_roughnessMap = textureSample(RMTexture, RMTextureSampler, input.tcoordVS).ggga;', '_metallicMap = textureSample(RMTexture, RMTextureSampler, input.tcoordVS).bbba;');
619
629
  }
620
- }
621
- if (actor.getProperty().getNormalTexture?.()?.getImageLoaded()) {
622
- if (checkDims(actor.getProperty().getNormalTexture())) {
623
- usedTextures.push('_normalMap = textureSample(NormalTexture, NormalTextureSampler, input.tcoordVS);');
630
+ } else {
631
+ if (roughnessTexture?.getImageLoaded()) {
632
+ if (checkDims(roughnessTexture)) {
633
+ usedTextures.push('_roughnessMap = textureSample(RoughnessTexture, RoughnessTextureSampler, input.tcoordVS);');
634
+ }
624
635
  }
625
- }
626
- if (actor.getProperty().getAmbientOcclusionTexture?.()?.getImageLoaded()) {
627
- if (checkDims(actor.getProperty().getAmbientOcclusionTexture())) {
628
- usedTextures.push('_ambientOcclusionMap = textureSample(AmbientOcclusionTexture, AmbientOcclusionTextureSampler, input.tcoordVS);');
636
+ if (metallicTexture?.getImageLoaded()) {
637
+ if (checkDims(metallicTexture)) {
638
+ usedTextures.push('_metallicMap = textureSample(MetallicTexture, MetallicTextureSampler, input.tcoordVS);');
639
+ }
640
+ }
641
+ if (ambientOcclusionTexture?.getImageLoaded()) {
642
+ if (checkDims(ambientOcclusionTexture)) {
643
+ usedTextures.push('_ambientOcclusionMap = textureSample(AmbientOcclusionTexture, AmbientOcclusionTextureSampler, input.tcoordVS);');
644
+ }
629
645
  }
630
646
  }
631
- if (actor.getProperty().getEmissionTexture?.()?.getImageLoaded()) {
632
- if (checkDims(actor.getProperty().getEmissionTexture())) {
647
+ if (emissionTexture?.getImageLoaded()) {
648
+ if (checkDims(emissionTexture)) {
633
649
  usedTextures.push('_emissionMap = textureSample(EmissionTexture, EmissionTextureSampler, input.tcoordVS);');
634
650
  }
635
651
  }
652
+ if (normalTexture?.getImageLoaded()) {
653
+ if (checkDims(normalTexture)) {
654
+ usedTextures.push('_normalMap = textureSample(NormalTexture, NormalTextureSampler, input.tcoordVS);');
655
+ }
656
+ }
636
657
  code = vtkWebGPUShaderCache.substitute(code, '//VTK::TCoord::Impl', usedTextures).result;
637
658
  fDesc.setCode(code);
638
659
  };
@@ -863,6 +884,14 @@ function vtkWebGPUCellArrayMapper(publicAPI, model) {
863
884
  const pair = ['Diffuse', model.colorTexture];
864
885
  textures.push(pair);
865
886
  }
887
+ if (actor.getProperty().getORMTexture?.()) {
888
+ const pair = ['ORM', actor.getProperty().getORMTexture()];
889
+ textures.push(pair);
890
+ }
891
+ if (actor.getProperty().getRMTexture?.()) {
892
+ const pair = ['RM', actor.getProperty().getRMTexture()];
893
+ textures.push(pair);
894
+ }
866
895
  if (actor.getProperty().getRoughnessTexture?.()) {
867
896
  const pair = ['Roughness', actor.getProperty().getRoughnessTexture()];
868
897
  textures.push(pair);
@@ -144,7 +144,7 @@ function vtkForwardPass(publicAPI, model) {
144
144
  dstFactor: 'one-minus-src-alpha'
145
145
  },
146
146
  alpha: {
147
- srcfactor: 'one',
147
+ srcFactor: 'one',
148
148
  dstFactor: 'one-minus-src-alpha'
149
149
  }
150
150
  }
@@ -156,7 +156,7 @@ function vtkWebGPUOrderIndependentTranslucentPass(publicAPI, model) {
156
156
  dstFactor: 'one'
157
157
  },
158
158
  alpha: {
159
- srcfactor: 'one',
159
+ srcFactor: 'one',
160
160
  dstFactor: 'one'
161
161
  }
162
162
  }
@@ -168,7 +168,7 @@ function vtkWebGPUOrderIndependentTranslucentPass(publicAPI, model) {
168
168
  dstFactor: 'one-minus-src'
169
169
  },
170
170
  alpha: {
171
- srcfactor: 'one',
171
+ srcFactor: 'one',
172
172
  dstFactor: 'one-minus-src-alpha'
173
173
  }
174
174
  }
@@ -209,7 +209,7 @@ function vtkWebGPUOrderIndependentTranslucentPass(publicAPI, model) {
209
209
  dstFactor: 'one-minus-src-alpha'
210
210
  },
211
211
  alpha: {
212
- srcfactor: 'one',
212
+ srcFactor: 'one',
213
213
  dstFactor: 'one-minus-src-alpha'
214
214
  }
215
215
  }
@@ -190,7 +190,7 @@ function extend(publicAPI, model) {
190
190
  dstFactor: 'one-minus-src-alpha'
191
191
  },
192
192
  alpha: {
193
- srcfactor: 'one',
193
+ srcFactor: 'one',
194
194
  dstFactor: 'one-minus-src-alpha'
195
195
  }
196
196
  }
@@ -424,7 +424,7 @@ function vtkWebGPUVolumePass(publicAPI, model) {
424
424
  operation: 'max'
425
425
  },
426
426
  alpha: {
427
- srcfactor: 'one',
427
+ srcFactor: 'one',
428
428
  dstFactor: 'one',
429
429
  operation: 'max'
430
430
  }
@@ -438,7 +438,7 @@ function vtkWebGPUVolumePass(publicAPI, model) {
438
438
  operation: 'min'
439
439
  },
440
440
  alpha: {
441
- srcfactor: 'one',
441
+ srcFactor: 'one',
442
442
  dstFactor: 'one',
443
443
  operation: 'min'
444
444
  }
@@ -516,7 +516,7 @@ function vtkWebGPUVolumePass(publicAPI, model) {
516
516
  dstFactor: 'one-minus-src-alpha'
517
517
  },
518
518
  alpha: {
519
- srcfactor: 'one',
519
+ srcFactor: 'one',
520
520
  dstFactor: 'one-minus-src-alpha'
521
521
  }
522
522
  }
@@ -549,7 +549,7 @@ function vtkWebGPUVolumePass(publicAPI, model) {
549
549
  dstFactor: 'one-minus-src-alpha'
550
550
  },
551
551
  alpha: {
552
- srcfactor: 'one',
552
+ srcFactor: 'one',
553
553
  dstFactor: 'one-minus-src-alpha'
554
554
  }
555
555
  }
@@ -590,7 +590,7 @@ function vtkWebGPUVolumePass(publicAPI, model) {
590
590
  dstFactor: 'one-minus-src-alpha'
591
591
  },
592
592
  alpha: {
593
- srcfactor: 'one',
593
+ srcFactor: 'one',
594
594
  dstFactor: 'one-minus-src-alpha'
595
595
  }
596
596
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "33.1.1",
3
+ "version": "33.2.0",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",