Skip to content

Commit e7d63f1

Browse files
committed
feat(Rendering): report missing view node profile imports
fixes #3343
1 parent 9d00695 commit e7d63f1

File tree

3 files changed

+79
-3
lines changed

3 files changed

+79
-3
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: Rendering Profiles
3+
---
4+
5+
# Rendering Profiles
6+
7+
VTK.js rendering profiles are side-effect imports that register rendering implementations for classes used by the scene graph. They keep applications smaller by letting you import only the rendering backends and mapper support you need.
8+
9+
## Why profiles exist
10+
11+
Many VTK.js classes are pure pipeline or data-model classes. They only become renderable after a matching rendering profile registers the view-node overrides required by the active backend such as OpenGL or WebGPU.
12+
13+
Without the relevant profile import, VTK.js can still construct the data objects, actors, mappers, and pipeline, but rendering may fail when the scene graph asks `ViewNodeFactory` to create a backend-specific implementation for one of those classes.
14+
15+
## Typical usage
16+
17+
Import a profile near your application entry point before creating the render window content:
18+
19+
```js
20+
import '@kitware/vtk.js/Rendering/Profiles/Geometry';
21+
```
22+
23+
If you need broader coverage, import the combined profile:
24+
25+
```js
26+
import '@kitware/vtk.js/Rendering/Profiles/All';
27+
```
28+
29+
## Common profiles
30+
31+
- `Geometry`: core polygonal rendering support.
32+
- `Volume`: image and volume rendering support.
33+
- `Glyph`: glyph-specific mapper support.
34+
- `Molecule`: sphere and stick mapper support.
35+
- `LIC`: line integral convolution rendering support.
36+
- `All`: imports all supported profiles.
37+
38+
## When a profile is missing
39+
40+
A missing profile often shows up as an error from `Rendering/SceneGraph/ViewNodeFactory` saying that no implementation was found for a class and that a rendering profile is likely missing.
41+
42+
That warning means one of these is true:
43+
44+
- A built-in renderable class is being used without importing the profile that registers its rendering implementation.
45+
- A custom renderable class has not been registered with the view-node factory.
46+
47+
If you are unsure which profile is required, importing `Rendering/Profiles/All` is the easiest way to confirm that the issue is profile-related. After that, you can narrow it back down to the smallest profile set your application needs.

Documentation/scripts/generate-sidebar-config.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ const docsMenu = [
3636
},
3737
{
3838
text: 'Concepts',
39-
items: [{ text: 'Widgets', link: 'concepts_widgets.html' }],
39+
items: [
40+
{ text: 'Widgets', link: 'concepts_widgets.html' },
41+
{ text: 'Profiles', link: 'concepts_profile.html' },
42+
],
4043
},
4144
{
4245
text: 'Miscellaneous',

Sources/Rendering/SceneGraph/ViewNodeFactory/index.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
import macro from 'vtk.js/Sources/macros';
22

3+
function listClassHierarchy(dataObject) {
4+
const classNames = [];
5+
let depth = 0;
6+
let className = dataObject.getClassName(depth++);
7+
while (className) {
8+
classNames.push(className);
9+
className = dataObject.getClassName(depth++);
10+
}
11+
return classNames;
12+
}
13+
14+
function buildMissingImplementationMessage(factoryName, classNames) {
15+
const classList = classNames.join(' → ');
16+
return [
17+
`No ${factoryName} implementation found for ${classNames[0]}.`,
18+
`Class hierarchy: ${classList}.`,
19+
`A rendering Profile is likely missing for ${classNames[0]}.`,
20+
"Try importing '@kitware/vtk.js/Rendering/Profiles/All' or 'vtk.js/Sources/Rendering/Profiles/All',",
21+
'or import the specific rendering profile needed by this renderable if known.',
22+
'See https://kitware.github.io/vtk-js/docs/concepts_profile.html for details.',
23+
].join('\n');
24+
}
25+
326
// ----------------------------------------------------------------------------
427
// vtkViewNodeFactory methods
528
// ----------------------------------------------------------------------------
@@ -18,8 +41,9 @@ function vtkViewNodeFactory(publicAPI, model) {
1841
return null;
1942
}
2043

44+
const classNames = listClassHierarchy(dataObject);
2145
let cpt = 0;
22-
let className = dataObject.getClassName(cpt++);
46+
let className = classNames[cpt++];
2347
let isObject = false;
2448
const keys = Object.keys(model.overrides);
2549
while (className && !isObject) {
@@ -31,7 +55,9 @@ function vtkViewNodeFactory(publicAPI, model) {
3155
}
3256

3357
if (!isObject) {
34-
return null;
58+
throw new Error(
59+
buildMissingImplementationMessage(publicAPI.getClassName(), classNames)
60+
);
3561
}
3662
const vn = model.overrides[className]();
3763
vn.setMyFactory(publicAPI);

0 commit comments

Comments
 (0)