diff --git a/Sources/Rendering/Core/Mapper2D/index.js b/Sources/Rendering/Core/Mapper2D/index.js index 6c0a61a5356..897df3c5e07 100644 --- a/Sources/Rendering/Core/Mapper2D/index.js +++ b/Sources/Rendering/Core/Mapper2D/index.js @@ -166,7 +166,7 @@ function defaultValues(initialValues) { transformCoordinate: null, - viewSpecificProperties: null, + viewSpecificProperties: {}, customShaderAttributes: [], ...initialValues, }; @@ -196,10 +196,6 @@ export function extend(publicAPI, model, initialValues = {}) { ]); macro.setGetArray(publicAPI, model, ['scalarRange'], 2); - if (!initialValues.viewSpecificProperties) { - initialValues.viewSpecificProperties = {}; - } - // Object methods vtkMapper2D(publicAPI, model); } diff --git a/Sources/Rendering/Core/Prop3D/index.js b/Sources/Rendering/Core/Prop3D/index.js index 9454207da06..3c29d34654e 100644 --- a/Sources/Rendering/Core/Prop3D/index.js +++ b/Sources/Rendering/Core/Prop3D/index.js @@ -91,7 +91,9 @@ function vtkProp3D(publicAPI, model) { return false; } model.orientation = [x, y, z]; - if (!model.rotation) model.rotation = mat4.identity(new Float64Array(16)); + // Instanciation time + if (model.rotation === undefined) + model.rotation = mat4.identity(new Float64Array(16)); mat4.identity(model.rotation); publicAPI.rotateZ(z); publicAPI.rotateX(x); @@ -101,13 +103,10 @@ function vtkProp3D(publicAPI, model) { }; publicAPI.setUserMatrix = (matrix) => { - if (!matrix) { - model.userMatrix = null; - } else { - if (!model.userMatrix) - model.userMatrix = mat4.identity(new Float64Array(16)); - mat4.copy(model.userMatrix, matrix); - } + if (model.userMatrix === undefined) + model.userMatrix = mat4.identity(new Float64Array(16)); + mat4.copy(model.userMatrix, matrix); + publicAPI.modified(); }; @@ -118,7 +117,7 @@ function vtkProp3D(publicAPI, model) { publicAPI.computeMatrix = () => { // check whether or not need to rebuild the matrix - if (!model.matrixMTime) { + if (model.matrixMTime === undefined) { return; } if (publicAPI.getMTime() > model.matrixMTime.getMTime()) { diff --git a/Sources/Rendering/Core/Property/index.js b/Sources/Rendering/Core/Property/index.js index 3dfb4fdf6a6..197fecd7dae 100644 --- a/Sources/Rendering/Core/Property/index.js +++ b/Sources/Rendering/Core/Property/index.js @@ -16,7 +16,8 @@ function vtkProperty(publicAPI, model) { model.classHierarchy.push('vtkProperty'); publicAPI.setColor = (r, g, b) => { - if (!model.color) { + // Instanciation time + if (model.color === undefined) { model.color = [0, 0, 0]; } if (Array.isArray(r)) { diff --git a/Sources/Rendering/Core/RenderWindow/index.js b/Sources/Rendering/Core/RenderWindow/index.js index f5072862711..e974d8969fa 100644 --- a/Sources/Rendering/Core/RenderWindow/index.js +++ b/Sources/Rendering/Core/RenderWindow/index.js @@ -21,22 +21,6 @@ export function newAPISpecificView(name, initialValues = {}, toSet = true) { ); } -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -function defaultValues(initialValues) { - return { - defaultViewAPI: DEFAULT_VIEW_API, - renderers: [], - views: [], - interactor: null, - neverRendered: true, - numberOfLayers: 1, - ...initialValues, - }; -} - // ---------------------------------------------------------------------------- // vtkRenderWindow methods // ---------------------------------------------------------------------------- @@ -151,6 +135,22 @@ function vtkRenderWindow(publicAPI, model) { }; } +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + defaultViewAPI: DEFAULT_VIEW_API, + renderers: [], + views: [], + interactor: null, + neverRendered: true, + numberOfLayers: 1, + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { diff --git a/Sources/Rendering/Core/Renderer/index.js b/Sources/Rendering/Core/Renderer/index.js index 1bb1ba08eda..7be064fc1a4 100644 --- a/Sources/Rendering/Core/Renderer/index.js +++ b/Sources/Rendering/Core/Renderer/index.js @@ -565,6 +565,8 @@ function vtkRenderer(publicAPI, model) { function defaultValues(initialValues) { return { + background: [0, 0, 0, 1], + pickedProp: null, activeCamera: null, @@ -633,7 +635,6 @@ export function extend(publicAPI, model, initialValues = {}) { vtkViewport.extend(publicAPI, model, initialValues); // make sure background has 4 entries. Default to opaque black - if (!initialValues.background) initialValues.background = [0, 0, 0, 1]; while (initialValues.background.length < 3) initialValues.background.push(0); if (initialValues.background.length === 3) initialValues.background.push(1); diff --git a/Sources/Rendering/Core/Viewport/index.js b/Sources/Rendering/Core/Viewport/index.js index 253e5554979..238ac9c3f27 100644 --- a/Sources/Rendering/Core/Viewport/index.js +++ b/Sources/Rendering/Core/Viewport/index.js @@ -6,25 +6,6 @@ function notImplemented(method) { return () => vtkErrorMacro(`vtkViewport::${method} - NOT IMPLEMENTED`); } -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -function defaultValues(initialValues) { - return { - // _vtkWindow: null, - background: [0, 0, 0], - background2: [0.2, 0.2, 0.2], - gradientBackground: false, - viewport: [0, 0, 1, 1], - aspect: [1, 1], - pixelAspect: [1, 1], - props: [], - actors2D: [], - ...initialValues, - }; -} - // ---------------------------------------------------------------------------- // vtkViewport methods // ---------------------------------------------------------------------------- @@ -153,6 +134,25 @@ function vtkViewport(publicAPI, model) { publicAPI.PickPropFrom = notImplemented('PickPropFrom'); } +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + // _vtkWindow: null, + background: [0, 0, 0], + background2: [0.2, 0.2, 0.2], + gradientBackground: false, + viewport: [0, 0, 1, 1], + aspect: [1, 1], + pixelAspect: [1, 1], + props: [], + actors2D: [], + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { diff --git a/Sources/Rendering/OpenGL/HardwareSelector/index.js b/Sources/Rendering/OpenGL/HardwareSelector/index.js index 5397657cff6..93ed4687e02 100644 --- a/Sources/Rendering/OpenGL/HardwareSelector/index.js +++ b/Sources/Rendering/OpenGL/HardwareSelector/index.js @@ -329,26 +329,6 @@ function generateSelectionWithData(buffdata, fx1, fy1, fx2, fy2) { ); } -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -function defaultValues(initialValues) { - return { - area: undefined, - // _renderer: null, - // _openGLRenderWindow: null, - // _openGLRenderer: null, - currentPass: -1, - propColorValue: null, - props: null, - maximumPointId: 0, - maximumCellId: 0, - idOffset: 1, - ...initialValues, - }; -} - // ---------------------------------------------------------------------------- // vtkOpenGLHardwareSelector methods // ---------------------------------------------------------------------------- @@ -897,7 +877,8 @@ function vtkOpenGLHardwareSelector(publicAPI, model) { const superSetArea = publicAPI.setArea; publicAPI.setArea = (...args) => { if (!args[0]) return false; - if (!model.area) model.area = [0, 0, 0, 0]; + // Instanciation time + if (model.area === undefined) model.area = [0, 0, 0, 0]; if (superSetArea(...args)) { model.area[0] = Math.floor(model.area[0]); model.area[1] = Math.floor(model.area[1]); @@ -909,6 +890,26 @@ function vtkOpenGLHardwareSelector(publicAPI, model) { }; } +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + area: [0, 0, 0, 0], + // _renderer: null, + // _openGLRenderWindow: null, + // _openGLRenderer: null, + currentPass: -1, + propColorValue: [0, 0, 0], + props: [], + maximumPointId: 0, + maximumCellId: 0, + idOffset: 1, + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { @@ -921,13 +922,6 @@ export function extend(publicAPI, model, initialValues = {}) { // Build VTK API vtkHardwareSelector.extend(publicAPI, model, initialValues); - initialValues.propColorValue = [0, 0, 0]; - initialValues.props = []; - - if (!initialValues.area) { - initialValues.area = [0, 0, 0, 0]; - } - macro.setGetArray(publicAPI, model, ['area'], 4); macro.setGet(publicAPI, model, [ '_renderer', diff --git a/Sources/Rendering/OpenGL/RenderWindow/index.js b/Sources/Rendering/OpenGL/RenderWindow/index.js index cdc6964a312..66da171bb6d 100644 --- a/Sources/Rendering/OpenGL/RenderWindow/index.js +++ b/Sources/Rendering/OpenGL/RenderWindow/index.js @@ -82,35 +82,6 @@ export function popMonitorGLContextCount(cb) { return GL_CONTEXT_LISTENERS.pop(); } -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -function defaultValues(initialValues) { - return { - cullFaceEnabled: false, - initialized: false, - context: null, - cursorVisibility: true, - cursor: 'pointer', - textureUnitManager: null, - containerSize: null, - renderPasses: [], - notifyStartCaptureImage: false, - webgl2: false, - defaultToWebgl2: true, // attempt webgl2 on by default - activeFramebuffer: null, - xrSession: null, - xrSessionIsAR: false, - xrReferenceSpace: null, - xrSupported: true, - imageFormat: 'image/png', - useOffScreen: false, - useBackgroundImage: false, - ...initialValues, - }; -} - // ---------------------------------------------------------------------------- // vtkOpenGLRenderWindow methods // ---------------------------------------------------------------------------- @@ -1238,6 +1209,41 @@ function vtkOpenGLRenderWindow(publicAPI, model) { ); } +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + // Internal + selector: vtkOpenGLHardwareSelector.newInstance(), + bgImage: new Image(), + _textureResourceIds: new Map(), + shaderCache: vtkShaderCache.newInstance(), + + cullFaceEnabled: false, + initialized: false, + context: null, + cursorVisibility: true, + cursor: 'pointer', + textureUnitManager: null, + containerSize: null, + renderPasses: [], + notifyStartCaptureImage: false, + webgl2: false, + defaultToWebgl2: true, // attempt webgl2 on by default + activeFramebuffer: null, + xrSession: null, + xrSessionIsAR: false, + xrReferenceSpace: null, + xrSupported: true, + imageFormat: 'image/png', + useOffScreen: false, + useBackgroundImage: false, + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { @@ -1246,35 +1252,24 @@ export function extend(publicAPI, model, initialValues = {}) { // Inheritance vtkRenderWindowViewNode.extend(publicAPI, model, initialValues); - // Create internal instances + // model.canvas needs to be set to model before calling other setters model.canvas = document.createElement('canvas'); model.canvas.style.width = '100%'; createGLContext(); - if (!initialValues.selector) { - initialValues.selector = vtkOpenGLHardwareSelector.newInstance(); - initialValues.selector.setOpenGLRenderWindow(publicAPI); - } - // Create internal bgImage - model.bgImage = new Image(); - model.bgImage.style.position = 'absolute'; - model.bgImage.style.left = '0'; - model.bgImage.style.top = '0'; - model.bgImage.style.width = '100%'; - model.bgImage.style.height = '100%'; - model.bgImage.style.zIndex = '-1'; - - model._textureResourceIds = new Map(); + initialValues.bgImage.style.position = 'absolute'; + initialValues.bgImage.style.left = '0'; + initialValues.bgImage.style.top = '0'; + initialValues.bgImage.style.width = '100%'; + initialValues.bgImage.style.height = '100%'; + initialValues.bgImage.style.zIndex = '-1'; initialValues.myFactory = vtkOpenGLViewNodeFactory.newInstance(); /* eslint-disable no-use-before-define */ initialValues.myFactory.registerOverride('vtkRenderWindow', newInstance); /* eslint-enable no-use-before-define */ - initialValues.shaderCache = vtkShaderCache.newInstance(); - initialValues.shaderCache.setOpenGLRenderWindow(publicAPI); - // setup default forward pass rendering initialValues.renderPasses[0] = vtkForwardPass.newInstance(); @@ -1311,6 +1306,9 @@ export function extend(publicAPI, model, initialValues = {}) { // Object methods vtkOpenGLRenderWindow(publicAPI, model); + + initialValues.selector.setOpenGLRenderWindow(publicAPI); + initialValues.shaderCache.setOpenGLRenderWindow(publicAPI); } // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/OpenGL/ShaderCache/index.js b/Sources/Rendering/OpenGL/ShaderCache/index.js index 9f6720959dc..a4f41b3f752 100644 --- a/Sources/Rendering/OpenGL/ShaderCache/index.js +++ b/Sources/Rendering/OpenGL/ShaderCache/index.js @@ -236,6 +236,8 @@ function vtkShaderCache(publicAPI, model) { function defaultValues(initialValues) { return { + // Internal objects + shaderPrograms: {}, lastShaderBound: null, context: null, // _openGLRenderWindow: null, @@ -249,9 +251,6 @@ export function extend(publicAPI, model, initialValues = {}) { macro.moveToProtected(publicAPI, initialValues, ['openGLRenderWindow']); Object.assign(initialValues, defaultValues(initialValues)); - // Internal objects - initialValues.shaderPrograms = {}; - // Build VTK API macro.obj(publicAPI, model); macro.setGet(publicAPI, model, SET_GET_FIELDS); diff --git a/Sources/Rendering/OpenGL/Texture/index.js b/Sources/Rendering/OpenGL/Texture/index.js index 30b8dc30a30..7c3dedb5e85 100644 --- a/Sources/Rendering/OpenGL/Texture/index.js +++ b/Sources/Rendering/OpenGL/Texture/index.js @@ -1531,7 +1531,7 @@ export function extend(publicAPI, model, initialValues = {}) { // ---------------------------------------------------------------------------- -export const newInstance = macro.newInstance(extend, 'vtkOpenGLTexture'); +export const newInstance = macro.newInstance(extend, 'vtkOpenGLTexture', true); // ---------------------------------------------------------------------------- diff --git a/Sources/Rendering/OpenGL/ViewNodeFactory/index.js b/Sources/Rendering/OpenGL/ViewNodeFactory/index.js index ccdf5c46394..11141a20765 100644 --- a/Sources/Rendering/OpenGL/ViewNodeFactory/index.js +++ b/Sources/Rendering/OpenGL/ViewNodeFactory/index.js @@ -21,7 +21,11 @@ function vtkOpenGLViewNodeFactory(publicAPI, model) { // ---------------------------------------------------------------------------- function defaultValues(initialValues) { - return { ...initialValues }; + return { + // Static class mapping shared across instances + overrides: CLASS_MAPPING, + ...initialValues, + }; } // ---------------------------------------------------------------------------- @@ -29,9 +33,6 @@ function defaultValues(initialValues) { export function extend(publicAPI, model, initialValues = {}) { Object.assign(initialValues, defaultValues(initialValues)); - // Static class mapping shared across instances - initialValues.overrides = CLASS_MAPPING; - // Inheritance vtkViewNodeFactory.extend(publicAPI, model, initialValues); diff --git a/Sources/Rendering/SceneGraph/RenderPass/index.js b/Sources/Rendering/SceneGraph/RenderPass/index.js index 303e8f3bb75..6eae0809daf 100644 --- a/Sources/Rendering/SceneGraph/RenderPass/index.js +++ b/Sources/Rendering/SceneGraph/RenderPass/index.js @@ -1,20 +1,5 @@ import macro from 'vtk.js/Sources/macros'; -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -function defaultValues(initialValues) { - return { - delegates: [], - currentOperation: null, - preDelegateOperations: [], - postDelegateOperations: [], - currentParent: null, - ...initialValues, - }; -} - // ---------------------------------------------------------------------------- function vtkRenderPass(publicAPI, model) { @@ -62,6 +47,21 @@ function vtkRenderPass(publicAPI, model) { }; } +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + delegates: [], + currentOperation: null, + preDelegateOperations: [], + postDelegateOperations: [], + currentParent: null, + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { diff --git a/Sources/Rendering/SceneGraph/RenderWindowViewNode/index.js b/Sources/Rendering/SceneGraph/RenderWindowViewNode/index.js index b3d5c45a2ea..52e96586aee 100644 --- a/Sources/Rendering/SceneGraph/RenderWindowViewNode/index.js +++ b/Sources/Rendering/SceneGraph/RenderWindowViewNode/index.js @@ -152,6 +152,7 @@ function vtkRenderWindowViewNode(publicAPI, model) { function defaultValues(initialValues) { return { + size: [300, 300], selector: undefined, ...initialValues, }; @@ -161,11 +162,6 @@ function defaultValues(initialValues) { export function extend(publicAPI, model, initialValues = {}) { Object.assign(initialValues, defaultValues(initialValues)); - - if (!initialValues.size) { - initialValues.size = [300, 300]; - } - macro.getArray(publicAPI, model, ['size'], 2); macro.get(publicAPI, model, ['selector']); diff --git a/Sources/Rendering/SceneGraph/ViewNodeFactory/index.js b/Sources/Rendering/SceneGraph/ViewNodeFactory/index.js index dc703ecca80..f4a222b51b9 100644 --- a/Sources/Rendering/SceneGraph/ViewNodeFactory/index.js +++ b/Sources/Rendering/SceneGraph/ViewNodeFactory/index.js @@ -1,16 +1,5 @@ import macro from 'vtk.js/Sources/macros'; -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -function defaultValues(initialValues) { - return { - // overrides: {}, - ...initialValues, - }; -} - // ---------------------------------------------------------------------------- // vtkViewNodeFactory methods // ---------------------------------------------------------------------------- @@ -54,6 +43,17 @@ function vtkViewNodeFactory(publicAPI, model) { }; } +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + // overrides: {}, + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { diff --git a/Sources/Rendering/WebGPU/Actor/index.js b/Sources/Rendering/WebGPU/Actor/index.js index be47e4b7011..3b185b8cca0 100644 --- a/Sources/Rendering/WebGPU/Actor/index.js +++ b/Sources/Rendering/WebGPU/Actor/index.js @@ -5,18 +5,6 @@ import vtkViewNode from 'vtk.js/Sources/Rendering/SceneGraph/ViewNode'; import { registerOverride } from 'vtk.js/Sources/Rendering/WebGPU/ViewNodeFactory'; -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -function defaultValues(initialValues) { - return { - propID: undefined, - bufferShift: undefined, - ...initialValues, - }; -} - // ---------------------------------------------------------------------------- // vtkWebGPUActor methods // ---------------------------------------------------------------------------- @@ -160,6 +148,27 @@ function vtkWebGPUActor(publicAPI, model) { }; } +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + // Internal objects + keyMatricesTime: macro.obj({}, { mtime: 0 }), + keyMatrices: { + normalMatrix: new Float64Array(16), + bcwc: new Float64Array(16), + bcsc: new Float64Array(16), + }, + bufferShift: [0, 0, 0, 0], + + propID: undefined, + bufferShift: undefined, + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { @@ -168,18 +177,8 @@ export function extend(publicAPI, model, initialValues = {}) { // Inheritance vtkViewNode.extend(publicAPI, model, initialValues); - initialValues.keyMatricesTime = {}; - macro.obj(initialValues.keyMatricesTime, { mtime: 0 }); - initialValues.keyMatrices = { - normalMatrix: new Float64Array(16), - bcwc: new Float64Array(16), - bcsc: new Float64Array(16), - }; - macro.get(publicAPI, model, ['propID', 'keyMatricesTime']); - initialValues.bufferShift = [0, 0, 0, 0]; - // Object methods vtkWebGPUActor(publicAPI, model); } diff --git a/Sources/Rendering/WebGPU/HardwareSelectionPass/index.js b/Sources/Rendering/WebGPU/HardwareSelectionPass/index.js index 5577dc79518..5b1d81f1577 100644 --- a/Sources/Rendering/WebGPU/HardwareSelectionPass/index.js +++ b/Sources/Rendering/WebGPU/HardwareSelectionPass/index.js @@ -4,19 +4,6 @@ import vtkWebGPUTexture from 'vtk.js/Sources/Rendering/WebGPU/Texture'; import vtkWebGPUShaderCache from 'vtk.js/Sources/Rendering/WebGPU/ShaderCache'; import vtkRenderPass from 'vtk.js/Sources/Rendering/SceneGraph/RenderPass'; -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -function defaultValues(initialValues) { - return { - selectionRenderEncoder: null, - colorTexture: null, - depthTexture: null, - ...initialValues, - }; -} - // ---------------------------------------------------------------------------- function vtkWebGPUHardwareSelectionPass(publicAPI, model) { @@ -129,6 +116,19 @@ function vtkWebGPUHardwareSelectionPass(publicAPI, model) { }; } +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + selectionRenderEncoder: null, + colorTexture: null, + depthTexture: null, + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { diff --git a/Sources/Rendering/WebGPU/HardwareSelector/index.js b/Sources/Rendering/WebGPU/HardwareSelector/index.js index c73830208f3..aa32b14e7c3 100644 --- a/Sources/Rendering/WebGPU/HardwareSelector/index.js +++ b/Sources/Rendering/WebGPU/HardwareSelector/index.js @@ -252,18 +252,6 @@ function generateSelectionWithData(buffdata, fx1, fy1, fx2, fy2) { return convertSelection(buffdata.fieldAssociation, dataMap, buffdata); } -// ---------------------------------------------------------------------------- -// Object factory -// ---------------------------------------------------------------------------- - -function defaultValues(initialValues) { - return { - WebGPURenderWindow: null, - _selectionPass: vtkWebGPUHardwareSelectionPass.newInstance(), - ...initialValues, - }; -} - // ---------------------------------------------------------------------------- // vtkWebGPUHardwareSelector methods // ---------------------------------------------------------------------------- @@ -425,6 +413,18 @@ function vtkWebGPUHardwareSelector(publicAPI, model) { }; } +// ---------------------------------------------------------------------------- +// Object factory +// ---------------------------------------------------------------------------- + +function defaultValues(initialValues) { + return { + WebGPURenderWindow: null, + _selectionPass: vtkWebGPUHardwareSelectionPass.newInstance(), + ...initialValues, + }; +} + // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { diff --git a/Sources/Rendering/WebGPU/RenderWindow/index.js b/Sources/Rendering/WebGPU/RenderWindow/index.js index ca0252aaf44..6c50df58ced 100644 --- a/Sources/Rendering/WebGPU/RenderWindow/index.js +++ b/Sources/Rendering/WebGPU/RenderWindow/index.js @@ -550,6 +550,11 @@ function vtkWebGPURenderWindow(publicAPI, model) { function defaultValues(initialValues) { return { + // Internal instances + bgImage: new Image(), + myFactory: vtkWebGPUViewNodeFactory.newInstance(), + selector: vtkWebGPUHardwareSelector.newInstance(), + initialized: false, context: null, adapter: null, @@ -574,35 +579,28 @@ function defaultValues(initialValues) { export function extend(publicAPI, model, initialValues = {}) { Object.assign(initialValues, defaultValues(initialValues)); - // Create internal instances + // model.canvas needs to be set to model before calling other setters model.canvas = document.createElement('canvas'); model.canvas.style.width = '100%'; - // Create internal bgImage - model.bgImage = new Image(); - delete initialValues.bgImage; - model.bgImage.style.position = 'absolute'; - model.bgImage.style.left = '0'; - model.bgImage.style.top = '0'; - model.bgImage.style.width = '100%'; - model.bgImage.style.height = '100%'; - model.bgImage.style.zIndex = '-1'; + initialValues.bgImage.style.position = 'absolute'; + initialValues.bgImage.style.left = '0'; + initialValues.bgImage.style.top = '0'; + initialValues.bgImage.style.width = '100%'; + initialValues.bgImage.style.height = '100%'; + initialValues.bgImage.style.zIndex = '-1'; // Inheritance vtkRenderWindowViewNode.extend(publicAPI, model, initialValues); - model.myFactory = vtkWebGPUViewNodeFactory.newInstance(); /* eslint-disable no-use-before-define */ - model.myFactory.registerOverride('vtkRenderWindow', newInstance); + initialValues.myFactory.registerOverride('vtkRenderWindow', newInstance); /* eslint-enable no-use-before-define */ // setup default forward pass rendering - model.renderPasses[0] = vtkForwardPass.newInstance(); + initialValues.renderPasses[0] = vtkForwardPass.newInstance(); - if (!initialValues.selector) { - initialValues.selector = vtkWebGPUHardwareSelector.newInstance(); - initialValues.selector.setWebGPURenderWindow(publicAPI); - } + initialValues.selector.setWebGPURenderWindow(publicAPI); macro.event(publicAPI, model, 'imageReady'); macro.event(publicAPI, model, 'initialized'); diff --git a/Sources/Rendering/WebGPU/ShaderCache/index.js b/Sources/Rendering/WebGPU/ShaderCache/index.js index 6a21632ec2c..85d1d9a19aa 100644 --- a/Sources/Rendering/WebGPU/ShaderCache/index.js +++ b/Sources/Rendering/WebGPU/ShaderCache/index.js @@ -54,7 +54,7 @@ function vtkWebGPUShaderCache(publicAPI, model) { function defaultValues(initialValues) { return { - shaderModules: null, + _shaderModules: new Map(), device: null, window: null, ...initialValues, @@ -64,11 +64,8 @@ function defaultValues(initialValues) { // ---------------------------------------------------------------------------- export function extend(publicAPI, model, initialValues = {}) { + macro.moveToProtected(publicAPI, initialValues, ['shaderModules']); Object.assign(initialValues, defaultValues(initialValues)); - - // Internal objects - model._shaderModules = new Map(); - // Build VTK API macro.obj(publicAPI, model); macro.setGet(publicAPI, model, ['device', 'window']); diff --git a/Sources/Rendering/WebGPU/ViewNodeFactory/index.js b/Sources/Rendering/WebGPU/ViewNodeFactory/index.js index 1bf7c86784d..829fd28dee2 100644 --- a/Sources/Rendering/WebGPU/ViewNodeFactory/index.js +++ b/Sources/Rendering/WebGPU/ViewNodeFactory/index.js @@ -21,7 +21,11 @@ function vtkWebGPUViewNodeFactory(publicAPI, model) { // ---------------------------------------------------------------------------- function defaultValues(initialValues) { - return { ...initialValues }; + return { + // Static class mapping shared across instances + overrides: CLASS_MAPPING, + ...initialValues, + }; } // ---------------------------------------------------------------------------- @@ -29,9 +33,6 @@ function defaultValues(initialValues) { export function extend(publicAPI, model, initialValues = {}) { Object.assign(initialValues, defaultValues(initialValues)); - // Static class mapping shared across instances - model.overrides = CLASS_MAPPING; - // Inheritance vtkViewNodeFactory.extend(publicAPI, model, initialValues);