@kitware/vtk.js 25.1.1 → 25.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.
@@ -5,7 +5,7 @@ import { RGBColor, Vector3 } from './../../types';
5
5
  export enum LIGHT_TYPES {
6
6
  'HeadLight',
7
7
  'CameraLight',
8
- 'SceneLight'
8
+ 'SceneLight',
9
9
  }
10
10
 
11
11
  export interface ILightInitialValues {
@@ -17,6 +17,7 @@ export interface ILightInitialValues {
17
17
  positional?: boolean;
18
18
  exponent?: number;
19
19
  coneAngle?: number;
20
+ coneFalloff?: number;
20
21
  attenuationValues?: number[];
21
22
  lightType?: LIGHT_TYPES;
22
23
  shadowAttenuation?: number;
@@ -54,6 +55,15 @@ export interface vtkLight extends vtkObject {
54
55
  */
55
56
  getConeAngle(): number;
56
57
 
58
+ /**
59
+ * Get the lighting falloff angle of a positional light in degrees.
60
+ * This is the angle that sets how much the cone will be extended to
61
+ * smooth the border. A value of 0 indicates that the spot light will
62
+ * have a completely sharp edge (this does not mean completely sharp
63
+ * lighting, just that the border will be sharp).
64
+ */
65
+ getConeFalloff(): number;
66
+
57
67
  /**
58
68
  * Set the position and focal point of a light based on elevation and azimuth.
59
69
  * The light is moved so it is shining from the given angle. Angles are
@@ -174,6 +184,16 @@ export interface vtkLight extends vtkObject {
174
184
  */
175
185
  setConeAngle(coneAngle: number): boolean;
176
186
 
187
+ /**
188
+ * Set the lighting falloff angle of a positional light in degrees.
189
+ * This is the angle that sets how much the cone will be extended to
190
+ * smooth the border. A value of 0 indicates that the spot light will
191
+ * have a completely sharp edge (this does not mean completely sharp
192
+ * lighting, just that the border will be sharp).
193
+ * @param {Number} coneFalloff The cone falloff angle.
194
+ */
195
+ setConeFalloff(coneFalloff: number): boolean;
196
+
177
197
  /**
178
198
  * Set the position and focal point of a light based on elevation and
179
199
  * azimuth. The light is moved so it is shining from the given angle. Angles
@@ -184,6 +204,20 @@ export interface vtkLight extends vtkObject {
184
204
  */
185
205
  setDirectionAngle(elevation: number, azimuth: number): boolean;
186
206
 
207
+ /**
208
+ * Set the direction vector of the light from X, Y, and Z values
209
+ * @param {Number} x The x coordinate.
210
+ * @param {Number} y The y coordinate.
211
+ * @param {Number} z The z coordinate.
212
+ */
213
+ setDirection(x: number, y: number, z: number): boolean;
214
+
215
+ /**
216
+ * Set the direction vector of the light from X, Y, and Z values
217
+ * @param {Vector3} direction
218
+ */
219
+ setDirection(direction: Vector3): boolean;
220
+
187
221
  /**
188
222
  * Set the exponent of the cosine used in positional lighting.
189
223
  * @param {Number} exponent The exponent of the cosine.
@@ -299,7 +333,7 @@ export function extend(publicAPI: object, model: object, initialValues?: ILightI
299
333
  /**
300
334
  * Method use to create a new instance of vtkLight with the focal point at the origin and its position
301
335
  * set to [0, 0, 1]. The light is a SceneLight, its color is white, intensity=1, the light is turned on,
302
- * positional lighting is off, coneAngle=30, AttenuationValues=[1, 0, 0], exponent=1 and the transformMatrix is null.
336
+ * positional lighting is off, coneAngle=30, coneFalloff=5, AttenuationValues=[1, 0, 0], exponent=1 and the transformMatrix is null.
303
337
  * @param {ILightInitialValues} [initialValues] for pre-setting some of its content
304
338
  */
305
339
  export function newInstance(initialValues?: ILightInitialValues): vtkLight;
@@ -33,14 +33,19 @@ function vtkLight(publicAPI, model) {
33
33
 
34
34
  publicAPI.getDirection = function () {
35
35
  if (model.directionMTime < model.mtime) {
36
- model.direction[0] = model.focalPoint[0] - model.position[0];
37
- model.direction[1] = model.focalPoint[1] - model.position[1];
38
- model.direction[2] = model.focalPoint[2] - model.position[2];
36
+ vec3.sub(model.direction, model.focalPoint, model.position);
39
37
  normalize(model.direction);
40
38
  model.directionMTime = model.mtime;
41
39
  }
42
40
 
43
41
  return model.direction;
42
+ }; // Sets the direction from a vec3 instead of a focal point
43
+
44
+
45
+ publicAPI.setDirection = function (directionVector) {
46
+ var newFocalPoint = new Float64Array(3);
47
+ vec3.sub(newFocalPoint, model.position, directionVector);
48
+ model.focalPoint = newFocalPoint;
44
49
  };
45
50
 
46
51
  publicAPI.setDirectionAngle = function (elevation, azimuth) {
@@ -89,6 +94,7 @@ var DEFAULT_VALUES = {
89
94
  positional: false,
90
95
  exponent: 1,
91
96
  coneAngle: 30,
97
+ coneFalloff: 5,
92
98
  attenuationValues: [1, 0, 0],
93
99
  transformMatrix: null,
94
100
  lightType: 'SceneLight',
@@ -102,7 +108,7 @@ function extend(publicAPI, model) {
102
108
  Object.assign(model, DEFAULT_VALUES, initialValues); // Build VTK API
103
109
 
104
110
  macro.obj(publicAPI, model);
105
- macro.setGet(publicAPI, model, ['intensity', 'switch', 'positional', 'exponent', 'coneAngle', 'transformMatrix', 'lightType', 'shadowAttenuation', 'attenuationValues']);
111
+ macro.setGet(publicAPI, model, ['intensity', 'switch', 'positional', 'exponent', 'coneAngle', 'coneFalloff', 'transformMatrix', 'lightType', 'shadowAttenuation', 'attenuationValues']);
106
112
  macro.setGetArray(publicAPI, model, ['color', 'position', 'focalPoint', 'attenuationValues'], 3); // Object methods
107
113
 
108
114
  vtkLight(publicAPI, model);
@@ -1,15 +1,27 @@
1
1
  import { vtkObject } from './../../interfaces';
2
2
  import { RGBColor } from './../../types';
3
3
  import { Interpolation, Representation, Shading } from './Property/Constants';
4
+ import { vtkTexture } from './Texture';
4
5
 
5
6
  export interface IPropertyInitialValues {
6
7
  color?: RGBColor;
7
8
  ambientColor?: RGBColor;
8
9
  diffuseColor?: RGBColor;
9
10
  specularColor?: RGBColor;
11
+ diffuseTexture?: vtkTexture;
12
+ metallicTexture?: vtkTexture;
13
+ roughnessTexture?: vtkTexture;
14
+ normalTexture?: vtkTexture;
15
+ ambientOcclusionTexture?: vtkTexture;
16
+ emissionTexture?: vtkTexture;
10
17
  edgeColor?: RGBColor;
11
18
  ambient?: number;
12
19
  diffuse?: number;
20
+ metallic?: number;
21
+ roughness?: number;
22
+ normalStrength?: number;
23
+ emission?: number;
24
+ baseIOR?: number;
13
25
  specular?: number;
14
26
  specularPower?: number;
15
27
  opacity?: number;
@@ -161,6 +173,36 @@ export interface vtkProperty extends vtkObject {
161
173
  */
162
174
  getSpecular(): number;
163
175
 
176
+ /**
177
+ * Get the roughness coefficient.
178
+ * @default 1
179
+ */
180
+ getRoughness(): number;
181
+
182
+ /**
183
+ * Get the metallic coefficient.
184
+ * @default 0
185
+ */
186
+ getMetallic(): number;
187
+
188
+ /**
189
+ * Get the index of refraction.
190
+ * @default 0
191
+ */
192
+ getBaseIOR(): number;
193
+
194
+ /**
195
+ * Get the strength of the normal map.
196
+ * @default 1
197
+ */
198
+ getNormalStrength(): number;
199
+
200
+ /**
201
+ * Get the emission coefficient.
202
+ * @default 0
203
+ */
204
+ getEmission(): number;
205
+
164
206
  /**
165
207
  * Get the specular surface color.
166
208
  * @return {RGBColor} Array of RGB color.
@@ -178,6 +220,36 @@ export interface vtkProperty extends vtkObject {
178
220
  */
179
221
  getSpecularPower(): number;
180
222
 
223
+ /**
224
+ * Get the diffuse texture.
225
+ */
226
+ getDiffuseTexture(): vtkTexture;
227
+
228
+ /**
229
+ * Get the metallic texture.
230
+ */
231
+ getMetallicTexture(): vtkTexture;
232
+
233
+ /**
234
+ * Get the roughness texture.
235
+ */
236
+ getRoughnessTexture(): vtkTexture;
237
+
238
+ /**
239
+ * Get the normal texture.
240
+ */
241
+ getNormalTexture(): vtkTexture;
242
+
243
+ /**
244
+ * Get the ambient occlusion texture.
245
+ */
246
+ getAmbientOcclusionTexture(): vtkTexture;
247
+
248
+ /**
249
+ * Get the emission texture.
250
+ */
251
+ getEmissionTexture(): vtkTexture;
252
+
181
253
  /**
182
254
  * Set the ambient lighting coefficient.
183
255
  * @param {Number} ambient The ambient lighting coefficient.
@@ -385,6 +457,18 @@ export interface vtkProperty extends vtkObject {
385
457
  */
386
458
  setSpecular(specular: number): boolean;
387
459
 
460
+ /**
461
+ * Set the normal map strength.
462
+ * @param {Boolean} normal
463
+ */
464
+ setNormalStrength(normalStrength: number): boolean;
465
+
466
+ /**
467
+ * Set the ambient occlusion map strength.
468
+ * @param {Boolean} emission
469
+ */
470
+ setEmission(emission: number): boolean;
471
+
388
472
  /**
389
473
  * Set the specular surface color.
390
474
  * @param {Number} r Defines the red component (between 0 and 1)
@@ -410,6 +494,42 @@ export interface vtkProperty extends vtkObject {
410
494
  * @param {Number} specularPower
411
495
  */
412
496
  setSpecularPower(specularPower: number): boolean;
497
+
498
+ /**
499
+ * Set the diffuse texture.
500
+ * @param {vtkTexture} diffuseTexture
501
+ */
502
+ setDiffuseTexture(diffuseTexture: vtkTexture): boolean;
503
+
504
+ /**
505
+ * Set the metallic texture.
506
+ * @param {vtkTexture} metallicTexture
507
+ */
508
+ setMetallicTexture(metallicTexture: vtkTexture): boolean;
509
+
510
+ /**
511
+ * Set the roughness texture.
512
+ * @param {vtkTexture} roughnessTexture
513
+ */
514
+ setRoughnessTexture(roughnessTexture: vtkTexture): boolean;
515
+
516
+ /**
517
+ * Set the normal texture.
518
+ * @param {vtkTexture} normalTexture
519
+ */
520
+ setNormalTexture(normalTexture: vtkTexture): boolean;
521
+
522
+ /**
523
+ * Set the ambient occlusion texture.
524
+ * @param {vtkTexture} ambientOcclusionTexture
525
+ */
526
+ setAmbientOcclusionTexture(ambientOcclusionTexture: vtkTexture): boolean;
527
+
528
+ /**
529
+ * Set the emission texture.
530
+ * @param {vtkTexture} emissionTexture
531
+ */
532
+ setEmissionTexture(emissionTexture: vtkTexture): boolean;
413
533
  }
414
534
 
415
535
  /**
@@ -58,6 +58,17 @@ function vtkProperty(publicAPI, model) {
58
58
  return [].concat(model.color);
59
59
  };
60
60
 
61
+ publicAPI.setSpecularPower = function (specularPower) {
62
+ var roughness = 1 / Math.max(1.0, specularPower);
63
+
64
+ if (model.roughness !== roughness || model.specularPower !== specularPower) {
65
+ model.specularPower = specularPower; // Specular power still needs to be set as long as webgl is using it (otherwise testShaderReplacementsClear fails)
66
+
67
+ model.roughness = roughness;
68
+ publicAPI.modified();
69
+ }
70
+ };
71
+
61
72
  publicAPI.addShaderVariable = notImplemented('AddShaderVariable');
62
73
 
63
74
  publicAPI.setInterpolationToFlat = function () {
@@ -104,6 +115,11 @@ var DEFAULT_VALUES = {
104
115
  edgeColor: [0, 0, 0],
105
116
  ambient: 0,
106
117
  diffuse: 1,
118
+ metallic: 0,
119
+ roughness: 0.6,
120
+ normalStrength: 1,
121
+ emission: 1,
122
+ baseIOR: 1.45,
107
123
  specular: 0,
108
124
  specularPower: 1,
109
125
  opacity: 1,
@@ -124,7 +140,7 @@ function extend(publicAPI, model) {
124
140
  Object.assign(model, DEFAULT_VALUES, initialValues); // Build VTK API
125
141
 
126
142
  macro.obj(publicAPI, model);
127
- macro.setGet(publicAPI, model, ['lighting', 'interpolation', 'ambient', 'diffuse', 'specular', 'specularPower', 'opacity', 'edgeVisibility', 'lineWidth', 'pointSize', 'backfaceCulling', 'frontfaceCulling', 'representation']);
143
+ 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']);
128
144
  macro.setGetArray(publicAPI, model, ['ambientColor', 'specularColor', 'diffuseColor', 'edgeColor'], 3); // Object methods
129
145
 
130
146
  vtkProperty(publicAPI, model);
@@ -72,6 +72,37 @@ function vtkTexture(publicAPI, model) {
72
72
 
73
73
  publicAPI.modified();
74
74
  };
75
+
76
+ publicAPI.getDimensionality = function () {
77
+ var width = 0;
78
+ var height = 0;
79
+ var depth = 1;
80
+
81
+ if (publicAPI.getInputData()) {
82
+ var data = publicAPI.getInputData();
83
+ width = data.getDimensions()[0];
84
+ height = data.getDimensions()[1];
85
+ depth = data.getDimensions()[2];
86
+ }
87
+
88
+ if (model.jsImageData) {
89
+ width = model.jsImageData.width;
90
+ height = model.jsImageData.height;
91
+ }
92
+
93
+ if (model.canvas) {
94
+ width = model.canvas.width;
95
+ height = model.canvas.height;
96
+ }
97
+
98
+ if (model.image) {
99
+ width = model.image.width;
100
+ height = model.image.height;
101
+ }
102
+
103
+ var dimensionality = (width > 1) + (height > 1) + (depth > 1);
104
+ return dimensionality;
105
+ };
75
106
  } // ----------------------------------------------------------------------------
76
107
  // Object factory
77
108
  // ----------------------------------------------------------------------------
@@ -98,6 +98,8 @@ function vtkWebGPUActor2D(publicAPI, model) {
98
98
 
99
99
  if (model.renderable.getCoordinateSystem() === CoordinateSystem.WORLD) {
100
100
  mat4.translate(model.keyMatrices.bcsc, model.keyMatrices.bcwc, [-center[0], -center[1], -center[2]]);
101
+ } else {
102
+ mat4.copy(model.keyMatrices.bcsc, model.keyMatrices.bcwc);
101
103
  }
102
104
 
103
105
  model.keyMatricesTime.modified();
@@ -65,7 +65,7 @@ function _getFormatForDataArray(dataArray) {
65
65
 
66
66
  case 3:
67
67
  // only 32bit types support x3
68
- if (!format.contains('32')) {
68
+ if (!format.includes('32')) {
69
69
  vtkErrorMacro("unsupported x3 type for ".concat(format));
70
70
  }
71
71