issueatlas · · Reply permalink
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