@kitware/vtk.js 34.2.0 → 34.3.1
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.
- package/Common/Core/Math/index.js +1 -1
- package/Common/Core/Math.js +1 -1
- package/Rendering/Core/TextActor.d.ts +64 -0
- package/Rendering/Core/TextActor.js +134 -0
- package/Rendering/Core/TextProperty.d.ts +206 -0
- package/Rendering/Core/TextProperty.js +61 -0
- package/Rendering/Core.js +4 -0
- package/Rendering/OpenGL/Texture.js +1 -1
- package/Rendering/WebGPU/CellArrayMapper.js +68 -46
- package/Widgets/Widgets3D/AngleWidget.js +1 -1
- package/Widgets/Widgets3D/ResliceCursorWidget/behavior.js +1 -1
- package/Widgets/Widgets3D/ResliceCursorWidget/helpers.js +1 -1
- package/index.d.ts +2 -0
- package/package.json +1 -1
|
@@ -2256,4 +2256,4 @@ var vtkMath$1 = /*#__PURE__*/Object.freeze({
|
|
|
2256
2256
|
'default': vtkMath
|
|
2257
2257
|
});
|
|
2258
2258
|
|
|
2259
|
-
export {
|
|
2259
|
+
export { ceil as $, degreesFromRadians as A, ldexp as B, xyz2rgb as C, areEquals as D, clampValue as E, arrayRange as F, getMajorAxisIndex as G, createUninitializedBounds as H, identity as I, multiplyMatrix as J, floor as K, isInf as L, rgb2hsv as M, rgb2lab as N, lab2rgb as O, round as P, normalize2D as Q, nearestPowerOfTwo as R, multiply3x3_vect3 as S, getSparseOrthogonalMatrix as T, areBoundsInitialized as U, floatRGB2HexCode as V, isPowerOfTwo as W, angleBetweenVectors as X, signedAngleBetweenVectors as Y, createArray as Z, Pi as _, areMatricesEqual as a, floatToHex2 as a$, min as a0, max as a1, arrayMin as a2, arrayMax as a3, ceilLog2 as a4, factorial as a5, binomial as a6, beginCombination as a7, nextCombination as a8, randomSeed as a9, matrix3x3ToQuaternion as aA, multiplyQuaternion as aB, orthogonalize3x3 as aC, diagonalize3x3 as aD, singularValueDecomposition3x3 as aE, luFactorLinearSystem as aF, luSolveLinearSystem as aG, invertMatrix as aH, estimateMatrixCondition as aI, solveHomogeneousLeastSquares as aJ, solveLeastSquares as aK, hex2float as aL, lab2xyz as aM, xyz2lab as aN, rgb2xyz as aO, computeBoundsFromPoints as aP, clampAndNormalizeValue as aQ, getScalarTypeFittingRange as aR, getAdjustedScalarRange as aS, extentIsWithinOtherExtent as aT, boundsIsWithinOtherBounds as aU, pointIsWithinBounds as aV, solve3PointCircle as aW, inf as aX, negInf as aY, isFinite as aZ, isNaN as a_, getSeed as aa, gaussian as ab, multiplyScalar2D as ac, multiplyAccumulate2D as ad, outer as ae, projectVector as af, dot2D as ag, projectVector2D as ah, gaussianAmplitude as ai, gaussianWeight as aj, outer2D as ak, norm2D as al, rowsToMat4 as am, columnsToMat4 as an, columnsToMat3 as ao, LUFactor3x3 as ap, LUSolve3x3 as aq, linearSolve3x3 as ar, multiply3x3_mat3 as as, transpose3x3 as at, invert3x3 as au, identity3x3 as av, isIdentity as aw, isIdentity3x3 as ax, quaternionToMatrix3x3 as ay, roundNumber as az, roundVector as b, float2CssRGBA as b0, clampVector as c, dot as d, distance2BetweenPoints as e, vtkMath as f, solveLinearSystem as g, hsv2rgb as h, isNan as i, cross as j, add as k, normalize as l, multiplyAccumulate as m, norm as n, determinant2x2 as o, jacobiN as p, perpendiculars as q, radiansFromDegrees as r, subtract as s, jacobi as t, uninitializeBounds as u, vtkMath$1 as v, multiplyScalar as w, random as x, determinant3x3 as y, rowsToMat3 as z };
|
package/Common/Core/Math.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import 'seedrandom';
|
|
2
2
|
import '../../macros2.js';
|
|
3
3
|
import './Math/Constants.js';
|
|
4
|
-
export {
|
|
4
|
+
export { ap as LUFactor3x3, aq as LUSolve3x3, _ as Pi, k as add, X as angleBetweenVectors, U as areBoundsInitialized, D as areEquals, a as areMatricesEqual, a3 as arrayMax, a2 as arrayMin, F as arrayRange, a7 as beginCombination, a6 as binomial, aU as boundsIsWithinOtherBounds, $ as ceil, a4 as ceilLog2, aQ as clampAndNormalizeValue, E as clampValue, c as clampVector, ao as columnsToMat3, an as columnsToMat4, aP as computeBoundsFromPoints, Z as createArray, H as createUninitializedBounds, j as cross, f as default, A as degreesFromRadians, o as determinant2x2, y as determinant3x3, aD as diagonalize3x3, e as distance2BetweenPoints, d as dot, ag as dot2D, aI as estimateMatrixCondition, aT as extentIsWithinOtherExtent, a5 as factorial, b0 as float2CssRGBA, V as floatRGB2HexCode, a$ as floatToHex2, K as floor, ab as gaussian, ai as gaussianAmplitude, aj as gaussianWeight, aS as getAdjustedScalarRange, G as getMajorAxisIndex, aR as getScalarTypeFittingRange, aa as getSeed, T as getSparseOrthogonalMatrix, aL as hex2float, h as hsv2rgb, I as identity, av as identity3x3, aX as inf, au as invert3x3, aH as invertMatrix, aZ as isFinite, aw as isIdentity, ax as isIdentity3x3, L as isInf, a_ as isNaN, i as isNan, W as isPowerOfTwo, t as jacobi, p as jacobiN, O as lab2rgb, aM as lab2xyz, B as ldexp, ar as linearSolve3x3, aF as luFactorLinearSystem, aG as luSolveLinearSystem, aA as matrix3x3ToQuaternion, a1 as max, a0 as min, as as multiply3x3_mat3, S as multiply3x3_vect3, m as multiplyAccumulate, ad as multiplyAccumulate2D, J as multiplyMatrix, aB as multiplyQuaternion, w as multiplyScalar, ac as multiplyScalar2D, R as nearestPowerOfTwo, aY as negInf, a8 as nextCombination, n as norm, al as norm2D, l as normalize, Q as normalize2D, aC as orthogonalize3x3, ae as outer, ak as outer2D, q as perpendiculars, aV as pointIsWithinBounds, af as projectVector, ah as projectVector2D, ay as quaternionToMatrix3x3, r as radiansFromDegrees, x as random, a9 as randomSeed, M as rgb2hsv, N as rgb2lab, aO as rgb2xyz, P as round, az as roundNumber, b as roundVector, z as rowsToMat3, am as rowsToMat4, Y as signedAngleBetweenVectors, aE as singularValueDecomposition3x3, aW as solve3PointCircle, aJ as solveHomogeneousLeastSquares, aK as solveLeastSquares, g as solveLinearSystem, s as subtract, at as transpose3x3, u as uninitializeBounds, aN as xyz2lab, C as xyz2rgb } from './Math/index.js';
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import vtkActor2D, { IActor2DInitialValues } from './Actor2D';
|
|
2
|
+
import vtkTextProperty, { ITextPropertyInitialValues } from './TextProperty';
|
|
3
|
+
|
|
4
|
+
export interface ITextActorInitialValues extends IActor2DInitialValues {
|
|
5
|
+
property?: vtkTextProperty;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface vtkTextActor extends vtkActor2D {
|
|
9
|
+
/**
|
|
10
|
+
* Get the property object that controls this actors properties.
|
|
11
|
+
* @returns {vtkTextProperty} The vtkTextProperty instance.
|
|
12
|
+
*/
|
|
13
|
+
getProperty(): vtkTextProperty;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Create a new property suitable for use with this type of TextActor.
|
|
17
|
+
* @param {ITextPropertyInitialValues} [initialValues] (default: {})
|
|
18
|
+
* @return {vtkTextProperty} A new vtkTextProperty instance.
|
|
19
|
+
*/
|
|
20
|
+
makeProperty(initialValues?: ITextPropertyInitialValues): vtkTextProperty;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Set the text to be displayed by the actor.
|
|
24
|
+
* @param input The text to be displayed by the actor.
|
|
25
|
+
*/
|
|
26
|
+
setInput(input: string): boolean;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Set the property object that controls this actors properties.
|
|
30
|
+
* @param {vtkTextProperty} property The vtkTextProperty instance.
|
|
31
|
+
*/
|
|
32
|
+
setProperty(property: vtkTextProperty): boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Method used to decorate a given object (publicAPI+model) with vtkActor characteristics.
|
|
37
|
+
*
|
|
38
|
+
* @param publicAPI object on which methods will be bounds (public)
|
|
39
|
+
* @param model object on which data structure will be bounds (protected)
|
|
40
|
+
* @param {ITextActorInitialValues} [initialValues] (default: {})
|
|
41
|
+
*/
|
|
42
|
+
export function extend(
|
|
43
|
+
publicAPI: object,
|
|
44
|
+
model: object,
|
|
45
|
+
initialValues?: ITextActorInitialValues
|
|
46
|
+
): void;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Method used to create a new instance of vtkTextActor
|
|
50
|
+
*
|
|
51
|
+
* @param {ITextActorInitialValues} [initialValues] for pre-setting some of its content
|
|
52
|
+
*/
|
|
53
|
+
export function newInstance(
|
|
54
|
+
initialValues?: ITextActorInitialValues
|
|
55
|
+
): vtkTextActor;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* vtkTextActor can be used to place text annotation into a window.
|
|
59
|
+
*/
|
|
60
|
+
export declare const vtkTextActor: {
|
|
61
|
+
newInstance: typeof newInstance;
|
|
62
|
+
extend: typeof extend;
|
|
63
|
+
};
|
|
64
|
+
export default vtkTextActor;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { m as macro } from '../../macros2.js';
|
|
2
|
+
import vtkPlaneSource from '../../Filters/Sources/PlaneSource.js';
|
|
3
|
+
import vtkTexture from './Texture.js';
|
|
4
|
+
import vtkActor2D from './Actor2D.js';
|
|
5
|
+
import vtkMapper2D from './Mapper2D.js';
|
|
6
|
+
import vtkTextProperty from './TextProperty.js';
|
|
7
|
+
import ImageHelper from '../../Common/Core/ImageHelper.js';
|
|
8
|
+
import { V as floatRGB2HexCode } from '../../Common/Core/Math/index.js';
|
|
9
|
+
|
|
10
|
+
// ----------------------------------------------------------------------------
|
|
11
|
+
// vtkTextActor methods
|
|
12
|
+
// ----------------------------------------------------------------------------
|
|
13
|
+
function vtkTextActor(publicAPI, model) {
|
|
14
|
+
// Set our className
|
|
15
|
+
model.classHierarchy.push('vtkTextActor');
|
|
16
|
+
publicAPI.makeProperty = vtkTextProperty.newInstance;
|
|
17
|
+
const texture = vtkTexture.newInstance({
|
|
18
|
+
resizable: true
|
|
19
|
+
});
|
|
20
|
+
const canvas = new OffscreenCanvas(1, 1);
|
|
21
|
+
const mapper = vtkMapper2D.newInstance();
|
|
22
|
+
const plane = vtkPlaneSource.newInstance({
|
|
23
|
+
xResolution: 1,
|
|
24
|
+
yResolution: 1
|
|
25
|
+
});
|
|
26
|
+
function createImageData(text) {
|
|
27
|
+
const fontSizeScale = publicAPI.getProperty().getFontSizeScale();
|
|
28
|
+
const fontStyle = publicAPI.getProperty().getFontStyle();
|
|
29
|
+
const fontFamily = publicAPI.getProperty().getFontFamily();
|
|
30
|
+
const fontColor = publicAPI.getProperty().getFontColor();
|
|
31
|
+
const shadowColor = publicAPI.getProperty().getShadowColor();
|
|
32
|
+
const shadowOffset = publicAPI.getProperty().getShadowOffset();
|
|
33
|
+
const shadowBlur = publicAPI.getProperty().getShadowBlur();
|
|
34
|
+
const resolution = publicAPI.getProperty().getResolution();
|
|
35
|
+
const backgroundColor = publicAPI.getProperty().getBackgroundColor();
|
|
36
|
+
const dpr = Math.max(window.devicePixelRatio || 1, 1);
|
|
37
|
+
const ctx = canvas.getContext('2d');
|
|
38
|
+
|
|
39
|
+
// Set the text properties to measure
|
|
40
|
+
const textSize = fontSizeScale(resolution) * dpr;
|
|
41
|
+
ctx.font = `${fontStyle} ${textSize}px "${fontFamily}"`;
|
|
42
|
+
ctx.textBaseline = 'middle';
|
|
43
|
+
ctx.textAlign = 'center';
|
|
44
|
+
|
|
45
|
+
// Measure the text
|
|
46
|
+
const metrics = ctx.measureText(text);
|
|
47
|
+
const textWidth = metrics.width / dpr;
|
|
48
|
+
const {
|
|
49
|
+
actualBoundingBoxLeft,
|
|
50
|
+
actualBoundingBoxRight,
|
|
51
|
+
actualBoundingBoxAscent,
|
|
52
|
+
actualBoundingBoxDescent
|
|
53
|
+
} = metrics;
|
|
54
|
+
const hAdjustment = (actualBoundingBoxLeft - actualBoundingBoxRight) / 2;
|
|
55
|
+
const vAdjustment = (actualBoundingBoxAscent - actualBoundingBoxDescent) / 2;
|
|
56
|
+
const textHeight = textSize / dpr - vAdjustment;
|
|
57
|
+
|
|
58
|
+
// Update canvas size to fit text and ensure it is at least 1x1 pixel
|
|
59
|
+
const width = Math.max(Math.round(textWidth * dpr), 1);
|
|
60
|
+
const height = Math.max(Math.round(textHeight * dpr), 1);
|
|
61
|
+
canvas.width = width;
|
|
62
|
+
canvas.height = height;
|
|
63
|
+
|
|
64
|
+
// Vertical flip
|
|
65
|
+
ctx.translate(0, height);
|
|
66
|
+
ctx.scale(1, -1);
|
|
67
|
+
|
|
68
|
+
// Clear the canvas
|
|
69
|
+
ctx.clearRect(0, 0, width, height);
|
|
70
|
+
if (backgroundColor) {
|
|
71
|
+
ctx.fillStyle = floatRGB2HexCode(backgroundColor);
|
|
72
|
+
ctx.fillRect(0, 0, width, height);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Reset context after resize and prepare for rendering
|
|
76
|
+
ctx.imageSmoothingEnabled = true;
|
|
77
|
+
ctx.imageSmoothingQuality = 'high';
|
|
78
|
+
ctx.font = `${fontStyle} ${textSize}px "${fontFamily}"`;
|
|
79
|
+
ctx.fillStyle = floatRGB2HexCode(fontColor);
|
|
80
|
+
ctx.textBaseline = 'middle';
|
|
81
|
+
ctx.textAlign = 'center';
|
|
82
|
+
|
|
83
|
+
// Set shadow
|
|
84
|
+
if (shadowColor) {
|
|
85
|
+
ctx.shadowColor = floatRGB2HexCode(shadowColor);
|
|
86
|
+
ctx.shadowOffsetX = shadowOffset[0];
|
|
87
|
+
ctx.shadowOffsetY = shadowOffset[1];
|
|
88
|
+
ctx.shadowBlur = shadowBlur;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Draw the text
|
|
92
|
+
ctx.fillText(text, width / 2 + hAdjustment, height / 2 + vAdjustment);
|
|
93
|
+
|
|
94
|
+
// Update plane dimensions to match text size
|
|
95
|
+
plane.set({
|
|
96
|
+
point1: [width, 0, 0],
|
|
97
|
+
point2: [0, height, 0]
|
|
98
|
+
});
|
|
99
|
+
return ImageHelper.canvasToImageData(canvas);
|
|
100
|
+
}
|
|
101
|
+
mapper.setInputConnection(plane.getOutputPort());
|
|
102
|
+
publicAPI.setMapper(mapper);
|
|
103
|
+
publicAPI.addTexture(texture);
|
|
104
|
+
model._onInputChanged = (_publicAPI, _model, value) => {
|
|
105
|
+
const image = createImageData(value);
|
|
106
|
+
texture.setInputData(image, 0);
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Default property values
|
|
111
|
+
const DEFAULT_VALUES = {
|
|
112
|
+
mapper: null,
|
|
113
|
+
property: null
|
|
114
|
+
};
|
|
115
|
+
function extend(publicAPI, model) {
|
|
116
|
+
let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
117
|
+
Object.assign(model, DEFAULT_VALUES, initialValues);
|
|
118
|
+
|
|
119
|
+
// Inheritance
|
|
120
|
+
vtkActor2D.extend(publicAPI, model, initialValues);
|
|
121
|
+
|
|
122
|
+
// Build VTK API
|
|
123
|
+
macro.setGet(publicAPI, model, ['input']);
|
|
124
|
+
|
|
125
|
+
// Object methods
|
|
126
|
+
vtkTextActor(publicAPI, model);
|
|
127
|
+
}
|
|
128
|
+
const newInstance = macro.newInstance(extend, 'vtkTextActor');
|
|
129
|
+
var vtkTextActor$1 = {
|
|
130
|
+
newInstance,
|
|
131
|
+
extend
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export { vtkTextActor$1 as default, extend, newInstance };
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { RGBColor } from './../../types';
|
|
2
|
+
import vtkProperty2D, { IProperty2DInitialValues } from './Property2D';
|
|
3
|
+
|
|
4
|
+
export interface ITextPropertyInitialValues extends IProperty2DInitialValues {
|
|
5
|
+
backgroundColor?: RGBColor;
|
|
6
|
+
fillStyle?: string;
|
|
7
|
+
fontColor?: RGBColor;
|
|
8
|
+
fontFamily?: string;
|
|
9
|
+
fontSizeScale?: (resolution: number) => number;
|
|
10
|
+
fontStyle?: string;
|
|
11
|
+
resolution?: number;
|
|
12
|
+
shadowBlur?: number;
|
|
13
|
+
shadowColor?: RGBColor;
|
|
14
|
+
shadowOffset?: [number, number];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface vtkTextProperty extends vtkProperty2D {
|
|
18
|
+
/**
|
|
19
|
+
* Get the background color.
|
|
20
|
+
*/
|
|
21
|
+
getBackgroundColor(): RGBColor;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Get the background color by reference.
|
|
25
|
+
*/
|
|
26
|
+
getBackgroundColorByReference(): RGBColor;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Get the fill style.
|
|
30
|
+
*/
|
|
31
|
+
getFillStyle(): string;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Get the font color.
|
|
35
|
+
*/
|
|
36
|
+
getFontColor(): RGBColor;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Get the font color by reference.
|
|
40
|
+
*/
|
|
41
|
+
getFontColorByReference(): RGBColor;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Get the font family.
|
|
45
|
+
*/
|
|
46
|
+
getFontFamily(): string;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Get the font size scale.
|
|
50
|
+
*/
|
|
51
|
+
getFontSizeScale(): (resolution: number) => number;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Get the font style.
|
|
55
|
+
*/
|
|
56
|
+
getFontStyle(): string;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Get the resolution.
|
|
60
|
+
*/
|
|
61
|
+
getResolution(): number;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Get the shadow blur radius.
|
|
65
|
+
*/
|
|
66
|
+
getShadowBlur(): number;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Get the shadow color.
|
|
70
|
+
*/
|
|
71
|
+
getShadowColor(): RGBColor;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Get the shadow color by reference.
|
|
75
|
+
*/
|
|
76
|
+
getShadowColorByReference(): RGBColor;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Get the shadow offset.
|
|
80
|
+
*/
|
|
81
|
+
getShadowOffset(): [number, number];
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Get the shadow offset by reference.
|
|
85
|
+
*/
|
|
86
|
+
getShadowOffsetByReference(): [number, number];
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Set the background color.
|
|
90
|
+
* @param {RGBColor} backgroundColor The background color to set.
|
|
91
|
+
*/
|
|
92
|
+
setBackgroundColor(backgroundColor: RGBColor): boolean;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Set the fill style.
|
|
96
|
+
* @param {string} fillStyle The fill style to set.
|
|
97
|
+
*/
|
|
98
|
+
setFillStyle(fillStyle: string): boolean;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Set the font color from RGB values.
|
|
102
|
+
* @param {number} r Red component (0-255)
|
|
103
|
+
* @param {number} g Green component (0-255)
|
|
104
|
+
* @param {number} b Blue component (0-255)
|
|
105
|
+
*/
|
|
106
|
+
setFontColor(r: number, g: number, b: number): boolean;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Set the font color.
|
|
110
|
+
* @param {RGBColor} fontColor The font color to set.
|
|
111
|
+
*/
|
|
112
|
+
setFontColorFrom(fontColor: RGBColor): boolean;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Set the font family.
|
|
116
|
+
* @param {string} fontFamily The font family to set.
|
|
117
|
+
*/
|
|
118
|
+
setFontFamily(fontFamily: string): boolean;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Set the font size scale.
|
|
122
|
+
* Scales the font size based on the given resolution.
|
|
123
|
+
* Dividing by 1.8 ensures the font size is proportionate and not too large.
|
|
124
|
+
* The value 1.8 is a chosen scaling factor for visual balance.
|
|
125
|
+
* @param {number} resolution The resolution to set.
|
|
126
|
+
*/
|
|
127
|
+
setFontSizeScale(resolution: number): number;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Set the font style.
|
|
131
|
+
* @param {string} fontStyle The font style to set.
|
|
132
|
+
*/
|
|
133
|
+
setFontStyle(fontStyle: string): boolean;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Set the resolution.
|
|
137
|
+
* @param {number} resolution The resolution to set.
|
|
138
|
+
*/
|
|
139
|
+
setResolution(resolution: number): boolean;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Set the shadow blur radius.
|
|
143
|
+
* @param {number} shadowBlur The shadow blur radius to set.
|
|
144
|
+
*/
|
|
145
|
+
setShadowBlur(shadowBlur: number): boolean;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Set the shadow color from RGB values.
|
|
149
|
+
* @param {number} r Red component (0-255)
|
|
150
|
+
* @param {number} g Green component (0-255)
|
|
151
|
+
* @param {number} b Blue component (0-255)
|
|
152
|
+
*/
|
|
153
|
+
setShadowColor(r: number, g: number, b: number): boolean;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Set the shadow color.
|
|
157
|
+
* @param {RGBColor} shadowColor The shadow color to set.
|
|
158
|
+
*/
|
|
159
|
+
setShadowColorFrom(shadowColor: RGBColor): boolean;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Set the shadow offset from x and y values.
|
|
163
|
+
* @param {number} x Horizontal offset
|
|
164
|
+
* @param {number} y Vertical offset
|
|
165
|
+
*/
|
|
166
|
+
setShadowOffset(x: number, y: number): boolean;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Set the shadow offset.
|
|
170
|
+
* @param {Array} shadowOffset The shadow offset to set, as an array of [x, y].
|
|
171
|
+
*/
|
|
172
|
+
setShadowOffsetFrom(shadowOffset: [number, number]): boolean;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Method use to decorate a given object (publicAPI+model) with vtkProperty characteristics.
|
|
177
|
+
*
|
|
178
|
+
* @param publicAPI object on which methods will be bounds (public)
|
|
179
|
+
* @param model object on which data structure will be bounds (protected)
|
|
180
|
+
* @param {ITextPropertyInitialValues} [initialValues] (default: {})
|
|
181
|
+
*/
|
|
182
|
+
export function extend(
|
|
183
|
+
publicAPI: object,
|
|
184
|
+
model: object,
|
|
185
|
+
initialValues?: ITextPropertyInitialValues
|
|
186
|
+
): void;
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Method use to create a new instance of vtkTextProperty.
|
|
190
|
+
* @param {ITextPropertyInitialValues} [initialValues] for pre-setting some of its content
|
|
191
|
+
*/
|
|
192
|
+
export function newInstance(
|
|
193
|
+
initialValues?: ITextPropertyInitialValues
|
|
194
|
+
): vtkTextProperty;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* vtkTextProperty is an object that represents text properties. The primary
|
|
198
|
+
* properties that can be set are color, opacity, font size, font family
|
|
199
|
+
* horizontal and vertical justification, bold/italic/shadow styles.
|
|
200
|
+
*/
|
|
201
|
+
export declare const vtkTextProperty: {
|
|
202
|
+
newInstance: typeof newInstance;
|
|
203
|
+
extend: typeof extend;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
export default vtkTextProperty;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { m as macro } from '../../macros2.js';
|
|
2
|
+
import vtkProperty2D from './Property2D.js';
|
|
3
|
+
|
|
4
|
+
// ----------------------------------------------------------------------------
|
|
5
|
+
// vtkTextProperty methods
|
|
6
|
+
// ----------------------------------------------------------------------------
|
|
7
|
+
|
|
8
|
+
function vtkTextProperty(publicAPI, model) {
|
|
9
|
+
// Set our className
|
|
10
|
+
model.classHierarchy.push('vtkTextProperty');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// ----------------------------------------------------------------------------
|
|
14
|
+
// Object factory
|
|
15
|
+
// ----------------------------------------------------------------------------
|
|
16
|
+
|
|
17
|
+
const DEFAULT_VALUES = {
|
|
18
|
+
fontFamily: 'Arial',
|
|
19
|
+
fontColor: [0, 0, 0],
|
|
20
|
+
fontStyle: 'normal',
|
|
21
|
+
// backgroundColor: [1, 1, 1],
|
|
22
|
+
// Scales the font size based on the given resolution.
|
|
23
|
+
// Dividing by 1.8 ensures the font size is proportionate and not too large.
|
|
24
|
+
// The value 1.8 is a chosen scaling factor for visual balance.
|
|
25
|
+
fontSizeScale: resolution => resolution / 1.8,
|
|
26
|
+
resolution: 200
|
|
27
|
+
// shadowColor: [1, 1, 0],
|
|
28
|
+
// shadowOffset: [1, -1],
|
|
29
|
+
// shadowBlur: 0,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// ----------------------------------------------------------------------------
|
|
33
|
+
function extend(publicAPI, model) {
|
|
34
|
+
let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
35
|
+
Object.assign(model, DEFAULT_VALUES, initialValues);
|
|
36
|
+
|
|
37
|
+
// Inheritance
|
|
38
|
+
vtkProperty2D.extend(publicAPI, model, initialValues);
|
|
39
|
+
|
|
40
|
+
// Build VTK API
|
|
41
|
+
|
|
42
|
+
macro.setGet(publicAPI, model, ['fontFamily', 'fontStyle', 'fillStyle', 'fontSizeScale', 'resolution', 'shadowBlur']);
|
|
43
|
+
macro.setGetArray(publicAPI, model, ['shadowOffset'], 2);
|
|
44
|
+
macro.setGetArray(publicAPI, model, ['backgroundColor', 'fontColor', 'shadowColor'], 3);
|
|
45
|
+
|
|
46
|
+
// Object methods
|
|
47
|
+
vtkTextProperty(publicAPI, model);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// ----------------------------------------------------------------------------
|
|
51
|
+
|
|
52
|
+
const newInstance = macro.newInstance(extend, 'vtkTextProperty');
|
|
53
|
+
|
|
54
|
+
// ----------------------------------------------------------------------------
|
|
55
|
+
|
|
56
|
+
var vtkTextProperty$1 = {
|
|
57
|
+
newInstance,
|
|
58
|
+
extend
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export { vtkTextProperty$1 as default, extend, newInstance };
|
package/Rendering/Core.js
CHANGED
|
@@ -38,6 +38,8 @@ import vtkSkybox from './Core/Skybox.js';
|
|
|
38
38
|
import vtkSphereMapper from './Core/SphereMapper.js';
|
|
39
39
|
import vtkStickMapper from './Core/StickMapper.js';
|
|
40
40
|
import vtkTexture from './Core/Texture.js';
|
|
41
|
+
import vtkTextActor from './Core/TextActor.js';
|
|
42
|
+
import vtkTextProperty from './Core/TextProperty.js';
|
|
41
43
|
import vtkVector from './Core/VectorText.js';
|
|
42
44
|
import vtkViewport from './Core/Viewport.js';
|
|
43
45
|
import vtkVolume from './Core/Volume.js';
|
|
@@ -88,6 +90,8 @@ var Core = {
|
|
|
88
90
|
vtkSphereMapper,
|
|
89
91
|
vtkStickMapper,
|
|
90
92
|
vtkTexture,
|
|
93
|
+
vtkTextActor,
|
|
94
|
+
vtkTextProperty,
|
|
91
95
|
vtkVector,
|
|
92
96
|
vtkViewport,
|
|
93
97
|
vtkVolume,
|
|
@@ -3,7 +3,7 @@ import Constants from './Texture/Constants.js';
|
|
|
3
3
|
import HalfFloat from '../../Common/Core/HalfFloat.js';
|
|
4
4
|
import { n as newInstance$1, o as obj, s as set, e as setGet, g as get, i as moveToProtected, a as newTypedArray, c as macro } from '../../macros2.js';
|
|
5
5
|
import vtkDataArray from '../../Common/Core/DataArray.js';
|
|
6
|
-
import {
|
|
6
|
+
import { W as isPowerOfTwo, R as nearestPowerOfTwo } from '../../Common/Core/Math/index.js';
|
|
7
7
|
import vtkViewNode from '../SceneGraph/ViewNode.js';
|
|
8
8
|
import { registerOverride } from './ViewNodeFactory.js';
|
|
9
9
|
import supportsNorm16LinearCached from './Texture/supportsNorm16Linear.js';
|
|
@@ -71,6 +71,30 @@ struct PBRData {
|
|
|
71
71
|
specular: vec3<f32>,
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
struct Material {
|
|
75
|
+
ior: f32,
|
|
76
|
+
roughness: f32,
|
|
77
|
+
metallic: f32,
|
|
78
|
+
base: vec3<f32>,
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
struct DirectionalLight {
|
|
82
|
+
direction: vec3<f32>,
|
|
83
|
+
color: vec3<f32>,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
struct PointLight {
|
|
87
|
+
position: vec3<f32>,
|
|
88
|
+
color: vec3<f32>,
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
struct SpotLight {
|
|
92
|
+
position: vec3<f32>,
|
|
93
|
+
direction: vec3<f32>,
|
|
94
|
+
cones: vec2<f32>,
|
|
95
|
+
color: vec3<f32>,
|
|
96
|
+
};
|
|
97
|
+
|
|
74
98
|
const pi: f32 = 3.14159265359;
|
|
75
99
|
|
|
76
100
|
// Dot product with the max already in it
|
|
@@ -175,53 +199,51 @@ fn cookTorrance(D: f32, F: f32, G: f32, N: vec3<f32>, V: vec3<f32>, L: vec3<f32>
|
|
|
175
199
|
}
|
|
176
200
|
|
|
177
201
|
// Different lighting calculations for different light sources
|
|
178
|
-
fn calcDirectionalLight(N: vec3<f32>, V: vec3<f32>,
|
|
179
|
-
var L: vec3<f32> = normalize(direction); // Light Vector
|
|
202
|
+
fn calcDirectionalLight(N: vec3<f32>, V: vec3<f32>, mat: Material, light: DirectionalLight) -> PBRData {
|
|
203
|
+
var L: vec3<f32> = normalize(light.direction); // Light Vector
|
|
180
204
|
var H: vec3<f32> = normalize(L + V); // Halfway Vector
|
|
181
205
|
|
|
182
|
-
var alpha = roughness*roughness;
|
|
183
|
-
var k: f32 = alpha*alpha / 2;
|
|
206
|
+
var alpha = mat.roughness * mat.roughness;
|
|
207
|
+
var k: f32 = alpha * alpha / 2.0;
|
|
184
208
|
|
|
185
209
|
var D: f32 = trGGX(N, H, alpha); // Distribution
|
|
186
210
|
// var F: f32 = schlickFresnelIOR(V, N, ior, k); // Fresnel
|
|
187
211
|
var G: f32 = smithSurfaceRoughness(N, V, L, k); // Geometry
|
|
188
212
|
|
|
189
213
|
var brdf: f32 = cookTorrance(D, 1.0, G, N, V, L); // Fresnel term is replaced with 1 because it is added later
|
|
190
|
-
var incoming: vec3<f32> = color;
|
|
214
|
+
var incoming: vec3<f32> = light.color;
|
|
191
215
|
var angle: f32 = mdot(L, N);
|
|
192
216
|
angle = pow(angle, 1.5);
|
|
193
217
|
|
|
194
|
-
var specular: vec3<f32> = brdf*incoming*angle;
|
|
218
|
+
var specular: vec3<f32> = brdf * incoming * angle;
|
|
195
219
|
// Oren-Nayar gives a clay-like effect when fully rough which some people may not want, so it might be better to give a separate
|
|
196
220
|
// control property for the diffuse vs specular roughness
|
|
197
|
-
var diffuse: vec3<f32> = incoming*fujiiOrenNayar(base, roughness, N, L, V);
|
|
221
|
+
var diffuse: vec3<f32> = incoming * fujiiOrenNayar(mat.base, mat.roughness, N, L, V);
|
|
198
222
|
// Stores the specular and diffuse separately to allow for finer post processing
|
|
199
223
|
var out = PBRData(diffuse, specular);
|
|
200
224
|
|
|
201
225
|
return out; // Returns angle along with color of light so the final color can be multiplied by angle as well (creates black areas)
|
|
202
226
|
}
|
|
203
227
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
var
|
|
207
|
-
var
|
|
208
|
-
var dist = distance(position, fragPos);
|
|
228
|
+
fn calcPointLight(N: vec3<f32>, V: vec3<f32>, fragPos: vec3<f32>, mat: Material, light: PointLight) -> PBRData {
|
|
229
|
+
var L: vec3<f32> = normalize(light.position - fragPos);
|
|
230
|
+
var H: vec3<f32> = normalize(L + V);
|
|
231
|
+
var dist = distance(light.position, fragPos);
|
|
209
232
|
|
|
210
|
-
var alpha = roughness*roughness;
|
|
211
|
-
var k: f32 = alpha*alpha / 2.0;
|
|
233
|
+
var alpha = mat.roughness * mat.roughness;
|
|
234
|
+
var k: f32 = alpha * alpha / 2.0;
|
|
212
235
|
|
|
213
236
|
var D: f32 = trGGX(N, H, alpha); // Distribution
|
|
214
|
-
|
|
237
|
+
var F: f32 = schlickFresnelIOR(V, N, mat.ior, k); // Fresnel
|
|
215
238
|
var G: f32 = smithSurfaceRoughness(N, V, L, k); // Geometry
|
|
216
239
|
|
|
217
240
|
var brdf: f32 = cookTorrance(D, 1.0, G, N, V, L);
|
|
218
|
-
var incoming: vec3<f32> = color * (1.0 / (dist*dist));
|
|
241
|
+
var incoming: vec3<f32> = light.color * (1.0 / (dist * dist));
|
|
219
242
|
var angle: f32 = mdot(L, N);
|
|
220
|
-
angle = pow(angle, 1.5); // Smoothing factor makes it less accurate, but reduces ugly "seams"
|
|
221
|
-
|
|
222
|
-
var specular: vec3<f32> = brdf*incoming*angle;
|
|
223
|
-
var diffuse: vec3<f32> = incoming*fujiiOrenNayar(base, roughness, N, L, V);
|
|
243
|
+
angle = pow(angle, 1.5); // Smoothing factor makes it less accurate, but reduces ugly "seams" between light sources
|
|
224
244
|
|
|
245
|
+
var specular: vec3<f32> = brdf * incoming * angle;
|
|
246
|
+
var diffuse: vec3<f32> = incoming * fujiiOrenNayar(mat.base, mat.roughness, N, L, V);
|
|
225
247
|
// Stores the specular and diffuse separately to allow for finer post processing
|
|
226
248
|
// Could also be done (propably more properly) with a struct
|
|
227
249
|
var out = PBRData(diffuse, specular);
|
|
@@ -230,13 +252,13 @@ fn calcPointLight(N: vec3<f32>, V: vec3<f32>, fragPos: vec3<f32>, ior: f32, roug
|
|
|
230
252
|
}
|
|
231
253
|
|
|
232
254
|
// For a reason unknown to me, spheres dont seem to behave propperly with head-on spot lights
|
|
233
|
-
fn calcSpotLight(N: vec3<f32>, V: vec3<f32>, fragPos: vec3<f32>,
|
|
234
|
-
var L: vec3<f32> = normalize(position - fragPos);
|
|
255
|
+
fn calcSpotLight(N: vec3<f32>, V: vec3<f32>, fragPos: vec3<f32>, mat: Material, light: SpotLight) -> PBRData {
|
|
256
|
+
var L: vec3<f32> = normalize(light.position - fragPos);
|
|
235
257
|
var H: vec3<f32> = normalize(L + V); // Halfway Vector
|
|
236
|
-
var dist = distance(position, fragPos);
|
|
258
|
+
var dist = distance(light.position, fragPos);
|
|
237
259
|
|
|
238
|
-
var alpha = roughness*roughness;
|
|
239
|
-
var k: f32 = alpha*alpha / 2.0; // could also be pow(alpha + 1.0, 2) / 8
|
|
260
|
+
var alpha = mat.roughness * mat.roughness;
|
|
261
|
+
var k: f32 = alpha * alpha / 2.0; // could also be pow(alpha + 1.0, 2) / 8
|
|
240
262
|
|
|
241
263
|
var D: f32 = trGGX(N, H, alpha); // Distribution
|
|
242
264
|
// var F: f32 = schlickFresnelIOR(V, N, ior, k); // Fresnel
|
|
@@ -244,20 +266,19 @@ fn calcSpotLight(N: vec3<f32>, V: vec3<f32>, fragPos: vec3<f32>, ior: f32, rough
|
|
|
244
266
|
|
|
245
267
|
var brdf: f32 = cookTorrance(D, 1.0, G, N, V, L);
|
|
246
268
|
|
|
247
|
-
|
|
248
|
-
var
|
|
249
|
-
var
|
|
250
|
-
var intensity: f32 = (theta - cones.y) / epsilon;
|
|
269
|
+
var theta: f32 = mdot(normalize(light.direction), L);
|
|
270
|
+
var epsilon: f32 = light.cones.x - light.cones.y;
|
|
271
|
+
var intensity: f32 = (theta - light.cones.y) / epsilon;
|
|
251
272
|
intensity = clamp(intensity, 0.0, 1.0);
|
|
252
|
-
intensity /= dist*dist;
|
|
273
|
+
intensity /= dist * dist;
|
|
253
274
|
|
|
254
|
-
var incoming: vec3<f32> = color * intensity;
|
|
275
|
+
var incoming: vec3<f32> = light.color * intensity;
|
|
255
276
|
|
|
256
277
|
var angle: f32 = mdot(L, N);
|
|
257
|
-
angle = pow(angle, 1.5); // Smoothing factor makes it less accurate, but reduces ugly "seams"
|
|
278
|
+
angle = pow(angle, 1.5); // Smoothing factor makes it less accurate, but reduces ugly "seams" between light sources
|
|
258
279
|
|
|
259
|
-
var specular: vec3<f32> = brdf*incoming*angle;
|
|
260
|
-
var diffuse: vec3<f32> = incoming*fujiiOrenNayar(base, roughness, N, L, V);
|
|
280
|
+
var specular: vec3<f32> = brdf * incoming * angle;
|
|
281
|
+
var diffuse: vec3<f32> = incoming * fujiiOrenNayar(mat.base, mat.roughness, N, L, V);
|
|
261
282
|
|
|
262
283
|
// Stores the specular and diffuse separately to allow for finer post processing
|
|
263
284
|
// Could also be done (propably more properly) with a struct
|
|
@@ -310,6 +331,7 @@ fn main(
|
|
|
310
331
|
var ambientColor: vec4<f32> = mapperUBO.AmbientColor;
|
|
311
332
|
var diffuseColor: vec4<f32> = mapperUBO.DiffuseColor;
|
|
312
333
|
var opacity: f32 = mapperUBO.Opacity;
|
|
334
|
+
var ior: f32 = mapperUBO.BaseIOR;
|
|
313
335
|
|
|
314
336
|
// This should be declared somewhere else
|
|
315
337
|
var _diffuseMap: vec4<f32> = vec4<f32>(1.0);
|
|
@@ -331,6 +353,8 @@ fn main(
|
|
|
331
353
|
|
|
332
354
|
//VTK::Select::Impl
|
|
333
355
|
|
|
356
|
+
// Use texture alpha for transparency
|
|
357
|
+
computedColor.a = mapperUBO.Opacity * _diffuseMap.a;
|
|
334
358
|
if (computedColor.a == 0.0) { discard; };
|
|
335
359
|
|
|
336
360
|
//VTK::Position::Impl
|
|
@@ -525,31 +549,29 @@ function vtkWebGPUCellArrayMapper(publicAPI, model) {
|
|
|
525
549
|
if (code.includes('var normal:') && model.useRendererMatrix && !isEdges(hash) && !model.is2D && !hash.includes('sel')) {
|
|
526
550
|
const lightingCode = [
|
|
527
551
|
// Vectors needed for light calculations
|
|
528
|
-
'
|
|
552
|
+
' let fragPos = vec3<f32>(input.vertexVC.xyz);', ' let V = mix(normalize(-fragPos), vec3<f32>(0, 0, 1), f32(rendererUBO.cameraParallel)); // View Vector',
|
|
529
553
|
// Values needed for light calculations
|
|
530
|
-
'
|
|
554
|
+
' let baseColor = _diffuseMap.rgb * diffuseColor.rgb;', ' let roughness = max(0.000001, mapperUBO.Roughness * _roughnessMap.r);',
|
|
531
555
|
// Need to have a different way of sampling greyscale values aside from .r
|
|
532
|
-
'
|
|
556
|
+
' let metallic = mapperUBO.Metallic * _metallicMap.r;', ' let alpha = roughness * roughness;', ' let k = alpha * alpha / 2.0;',
|
|
533
557
|
// Split diffuse and specular components
|
|
534
|
-
' var diffuse
|
|
558
|
+
' var diffuse = vec3<f32>(0.);', ' var specular = vec3<f32>(0.);', ' let emission = _emissionMap.rgb * mapperUBO.Emission;', '', ' // Material struct', ' let mat = Material(ior, roughness, metallic, baseColor);', '',
|
|
535
559
|
// Summing diffuse and specular components of directional lights
|
|
536
|
-
' {', ' var i
|
|
560
|
+
' {', ' var i = 0;', ' loop {', ' if (!(i < rendererUBO.LightCount)) { break; }', ' switch (i32(rendererLightSSBO.values[i].LightData.x)) {', ' // Point Light', ' case 0 {', ' let color = rendererLightSSBO.values[i].LightColor.rgb * rendererLightSSBO.values[i].LightColor.w;', ' let pos = (rendererLightSSBO.values[i].LightPos).xyz;', ' let pointLight = PointLight(pos, color);', ' let result = calcPointLight(normal, V, fragPos, mat, pointLight);', ' diffuse += max(vec3<f32>(0), result.diffuse);', ' specular += max(vec3<f32>(0), result.specular);', ' }', ' // Directional light', ' case 1 {', ' let dir = normalize((rendererUBO.WCVCNormals * vec4<f32>(normalize(rendererLightSSBO.values[i].LightDir.xyz), 0.)).xyz);', ' let color = rendererLightSSBO.values[i].LightColor.rgb * rendererLightSSBO.values[i].LightColor.w;', ' let dirLight = DirectionalLight(dir, color);', ' let result = calcDirectionalLight(normal, V, mat, dirLight); // diffuseColor.rgb needs to be fixed with a more dynamic diffuse color', ' diffuse += max(vec3<f32>(0), result.diffuse);', ' specular += max(vec3<f32>(0), result.specular);', ' }', ' // Spot Light', ' case 2 {', ' let color = rendererLightSSBO.values[i].LightColor.rgb * rendererLightSSBO.values[i].LightColor.w;', ' let pos = (rendererLightSSBO.values[i].LightPos).xyz;', ' let dir = normalize((rendererUBO.WCVCNormals * vec4<f32>(normalize(rendererLightSSBO.values[i].LightDir.xyz), 0.)).xyz);', ' let cones = vec2<f32>(rendererLightSSBO.values[i].LightData.y, rendererLightSSBO.values[i].LightData.z);', ' let spotLight = SpotLight(pos, dir, cones, color);', ' let result = calcSpotLight(normal, V, fragPos, mat, spotLight);', ' diffuse += max(vec3<f32>(0), result.diffuse);', ' specular += max(vec3<f32>(0), result.specular);', ' }', ' default { continue; }', ' }', ' continuing { i++; }', ' }', ' }',
|
|
537
561
|
// Final variables for combining specular and diffuse
|
|
538
|
-
'
|
|
562
|
+
' let fresnel = min(1.0, schlickFresnelIOR(V, normal, ior, k)); // Fresnel', ' // This could be controlled with its own variable (that isnt base color) for better artistic control', ' let fresnelMetallic = schlickFresnelRGB(V, normal, baseColor); // Fresnel for metal, takes color into account', ' let kS = min(vec3<f32>(1.0), mix(vec3<f32>(fresnel), fresnelMetallic, metallic));', ' let kD = (1.0 - kS) * (1.0 - metallic);', ' let PBR = mapperUBO.DiffuseIntensity * kD * diffuse + kS * specular;', ' computedColor = vec4<f32>(PBR + emission, mapperUBO.Opacity);'];
|
|
539
563
|
if (renderer.getEnvironmentTexture()?.getImageLoaded()) {
|
|
540
|
-
lightingCode.push(' // To get diffuse IBL, the texture is sampled with normals in worldspace', '
|
|
564
|
+
lightingCode.push(' // To get diffuse IBL, the texture is sampled with normals in worldspace', ' let diffuseIBLCoords = (transpose(rendererUBO.WCVCNormals) * vec4<f32>(normal, 1.)).xyz;', ' let diffuseCoords = vecToRectCoord(diffuseIBLCoords);', ' // To get specular IBL, the texture is sampled as the worldspace reflection between the normal and view vectors', ' // Reflections are first calculated in viewspace, then converted to worldspace to sample the environment', ' let VreflN = normalize(reflect(-V, normal));', ' let reflectionIBLCoords = (transpose(rendererUBO.WCVCNormals) * vec4<f32>(VreflN, 1.)).xyz;', ' let specularCoords = vecToRectCoord(reflectionIBLCoords);', ' let diffuseIBL = textureSampleLevel(EnvironmentTexture, EnvironmentTextureSampler, diffuseCoords, rendererUBO.MaxEnvironmentMipLevel);',
|
|
541
565
|
// Level multiplier should be set by UBO
|
|
542
|
-
'
|
|
566
|
+
' let level = roughness * rendererUBO.MaxEnvironmentMipLevel;', ' let specularIBL = textureSampleLevel(EnvironmentTexture, EnvironmentTextureSampler, specularCoords, level);',
|
|
543
567
|
// Manual mip smoothing since not all formats support smooth level sampling
|
|
544
|
-
'
|
|
545
|
-
// Multipy by baseColor may be changed
|
|
546
|
-
' computedColor += vec4<f32>(diffuseIBLContribution*kD, 0);');
|
|
568
|
+
' let specularIBLContribution = specularIBL.rgb * rendererUBO.BackgroundSpecularStrength;', ' computedColor += vec4<f32>(specularIBLContribution * kS, 0);', ' let diffuseIBLContribution = diffuseIBL.rgb * rendererUBO.BackgroundDiffuseStrength;', ' computedColor += vec4<f32>(diffuseIBLContribution * baseColor * _ambientOcclusionMap.rgb * kD, 0);');
|
|
547
569
|
}
|
|
548
570
|
code = vtkWebGPUShaderCache.substitute(code, '//VTK::Light::Impl', lightingCode).result;
|
|
549
571
|
fDesc.setCode(code);
|
|
550
572
|
// If theres no normals, just set the specular color to be flat
|
|
551
573
|
} else {
|
|
552
|
-
code = vtkWebGPUShaderCache.substitute(code, '//VTK::Light::Impl', ['
|
|
574
|
+
code = vtkWebGPUShaderCache.substitute(code, '//VTK::Light::Impl', [' let diffuse = diffuseColor.rgb;', ' let specular = mapperUBO.SpecularColor.rgb * mapperUBO.SpecularColor.a;', ' computedColor = vec4<f32>(diffuse * _diffuseMap.rgb, mapperUBO.Opacity);']).result;
|
|
553
575
|
fDesc.setCode(code);
|
|
554
576
|
}
|
|
555
577
|
};
|
|
@@ -3,7 +3,7 @@ import vtkAbstractWidgetFactory from '../Core/AbstractWidgetFactory.js';
|
|
|
3
3
|
import vtkPlanePointManipulator from '../Manipulators/PlaneManipulator.js';
|
|
4
4
|
import vtkPolyLineRepresentation from '../Representations/PolyLineRepresentation.js';
|
|
5
5
|
import vtkSphereHandleRepresentation from '../Representations/SphereHandleRepresentation.js';
|
|
6
|
-
import { s as subtract,
|
|
6
|
+
import { s as subtract, X as angleBetweenVectors } from '../../Common/Core/Math/index.js';
|
|
7
7
|
import widgetBehavior from './AngleWidget/behavior.js';
|
|
8
8
|
import generateState from './AngleWidget/state.js';
|
|
9
9
|
import { ViewTypes } from '../Core/WidgetManager/Constants.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { m as macro } from '../../../macros2.js';
|
|
2
2
|
import vtkBoundingBox from '../../../Common/DataModel/BoundingBox.js';
|
|
3
3
|
import vtkLine from '../../../Common/DataModel/Line.js';
|
|
4
|
-
import { k as add, l as normalize, s as subtract, d as dot, j as cross, m as multiplyAccumulate, w as multiplyScalar,
|
|
4
|
+
import { k as add, l as normalize, s as subtract, d as dot, j as cross, m as multiplyAccumulate, w as multiplyScalar, Y as signedAngleBetweenVectors } from '../../../Common/Core/Math/index.js';
|
|
5
5
|
import { getLineNames, getOtherLineName, updateState, boundPointOnPlane, getLinePlaneName, getLineInPlaneName, rotateVector } from './helpers.js';
|
|
6
6
|
import { InteractionMethodsName, ScrollingMethods, planeNameToViewType } from './Constants.js';
|
|
7
7
|
|
|
@@ -2,7 +2,7 @@ import vtkBoundingBox, { STATIC } from '../../../Common/DataModel/BoundingBox.js
|
|
|
2
2
|
import vtkCubeSource from '../../../Filters/Sources/CubeSource.js';
|
|
3
3
|
import vtkCutter from '../../../Filters/Core/Cutter.js';
|
|
4
4
|
import vtkPlane from '../../../Common/DataModel/Plane.js';
|
|
5
|
-
import { s as subtract, l as normalize, j as cross, w as multiplyScalar, m as multiplyAccumulate,
|
|
5
|
+
import { s as subtract, l as normalize, j as cross, w as multiplyScalar, m as multiplyAccumulate, Y as signedAngleBetweenVectors } from '../../../Common/Core/Math/index.js';
|
|
6
6
|
import vtkMatrixBuilder from '../../../Common/Core/MatrixBuilder.js';
|
|
7
7
|
import { viewTypeToPlaneName, planeNameToViewType, planeNames } from './Constants.js';
|
|
8
8
|
|
package/index.d.ts
CHANGED
|
@@ -205,6 +205,8 @@
|
|
|
205
205
|
/// <reference path="./Rendering/Core/Skybox.d.ts" />
|
|
206
206
|
/// <reference path="./Rendering/Core/SphereMapper.d.ts" />
|
|
207
207
|
/// <reference path="./Rendering/Core/StickMapper.d.ts" />
|
|
208
|
+
/// <reference path="./Rendering/Core/TextActor.d.ts" />
|
|
209
|
+
/// <reference path="./Rendering/Core/TextProperty.d.ts" />
|
|
208
210
|
/// <reference path="./Rendering/Core/Texture.d.ts" />
|
|
209
211
|
/// <reference path="./Rendering/Core/VectorText.d.ts" />
|
|
210
212
|
/// <reference path="./Rendering/Core/Viewport.d.ts" />
|