Working on a custom scripted module in 3D Slicer for pre-post surgical maxillofacial and orthognathic studies. The goal is to automate the export workflow for clinical web visualization: (1) combine and center multiple quantification models (e.g. airway and mandible distance maps) into a single .glb file with baked vertex colors, and (2) export clean, transparent individual color-legend images for each model's active scalars. The core logic works (VTK coordinate transforms, scalar extraction, vertex color baking, mesh combination into GLB with trimesh), but capturing the color legends by isolating models and grabbing/cropping the 3D view widget produces PNGs that cut off parts of the model, miss the legend, or have rendering artifacts. Looking for a fix to the legend-export approach (or a native Slicer API to export a model's active color legend as a clean transparent PNG) and guidance on structuring this as a GUI module with model selection, opacity controls, and batch export.
Exporting pre-post maxillofacial quantification models to GLB with color legends
- Slicerproduct
- trimeshlibrary
- 3d widgetproduct
- extension wizardtool
- gltf/glbproduct
- gui moduleproduct
- +5 more
hit the same wall with legend captures a while back. two things that helped me:
the trimesh part is fine, but you can skip it entirely. the models module has a native gltf/glb export (export to file, or the save data dialog) that writes the model's active scalars out as vertex colors. so what you see in slicer is what ends up in the glb, and theres one less place for colors to drift.
for the legends: grabbing the whole 3d widget then cropping is always flaky. what worked for me was turning the model's color legend on, hiding everything else in the 3d view, forcing a render before the grab (viewWidget.renderWindow().render()), then cropping just the legend region. most of my artifacts came from grabbing mid update, the forced render fixed that. and the crop is way easier to get right when the model isnt in the frame. for transparent background, set the 3d view background to a solid color you can key out, or render on black and composite it later.
for the gui module side: the standard scripted module template covers most of the scaffolding. a couple qMRMLNodeComboBoxes for model selection, an opacity slider wired to the model display node, and a button that runs the batch export. the extension wizard generates the widget and logic files, you just fill in the callbacks.
Source: https://discourse.slicer.org/t/exporting-pre-post-maxillofacial-quantification-models-to-glb/48209