-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
vtkGridAxesActor3D always renders white, small titles/labels. All text properties are set to black with larger font sizes, and getters return those values both before and after render. Grid lines obey color. Text does not work for me.
Minimal reproducible example.
import logging
from trame.app import get_server
from trame.ui.html import DivLayout
from trame.widgets import html, client
from trame_vtklocal.widgets import vtklocal
# VTK imports
from vtkmodules.vtkFiltersSources import vtkConeSource
from vtkmodules.vtkRenderingCore import (
vtkActor,
vtkPolyDataMapper,
vtkRenderer,
vtkRenderWindow,
vtkRenderWindowInteractor,
vtkTextProperty,
)
# Required for VTK factory initializations
import vtkmodules.vtkRenderingOpenGL2 # noqa: F401
from vtkmodules.vtkInteractionStyle import vtkInteractorStyleSwitch # noqa: F401
from vtkmodules.vtkRenderingGridAxes import vtkGridAxesActor3D
def log_axes(axes: vtkGridAxesActor3D, where: str):
try:
logging.info("[grid] %s: property color=%s lineWidth=%.2f", where, axes.GetProperty().GetColor(), axes.GetProperty().GetLineWidth())
except Exception:
pass
for i, name in enumerate(["X", "Y", "Z"]):
try:
tp = axes.GetTitleTextProperty(i)
lp = axes.GetLabelTextProperty(i)
logging.info(
"[grid] %s: %s title='%s' tColor=%s tSize=%s lColor=%s lSize=%s",
where,
name,
axes.GetTitle(i),
tuple(round(c, 3) for c in (tp.GetColor() if tp else ())),
tp.GetFontSize() if tp else None,
tuple(round(c, 3) for c in (lp.GetColor() if lp else ())),
lp.GetFontSize() if lp else None,
)
except Exception:
pass
def build_vtk_pipeline():
# Renderer / window / interactor
renderer = vtkRenderer()
ren_win = vtkRenderWindow()
ren_win.AddRenderer(renderer)
iren = vtkRenderWindowInteractor()
iren.SetRenderWindow(ren_win)
iren.GetInteractorStyle().SetCurrentStyleToTrackballCamera()
# Cone
cone = vtkConeSource()
mapper = vtkPolyDataMapper()
mapper.SetInputConnection(cone.GetOutputPort())
actor = vtkActor()
actor.SetMapper(mapper)
renderer.AddActor(actor)
# Grid axes (style applied once at creation)
axes = vtkGridAxesActor3D()
axes.SetGridBounds(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0)
axes.SetLabelUniqueEdgesOnly(False)
axes.SetNumberOfXLabels(6)
axes.SetNumberOfYLabels(6)
axes.SetNumberOfZLabels(6)
# Make grid/axes lines black and slightly thicker
axes.GetProperty().SetColor(0.0, 0.0, 0.0)
axes.GetProperty().SetLineWidth(1.25)
# Strong, visible colors per axis and larger font sizes
titles = ("X-Axis", "Y-Axis", "Z-Axis")
# Black text for titles and labels
text_color = (0.0, 0.0, 0.0)
for i in range(3):
axes.SetTitle(i, titles[i])
t_prop = vtkTextProperty()
t_prop.SetFontFamilyToArial()
t_prop.SetBold(True)
t_prop.SetItalic(False)
t_prop.SetOpacity(1.0)
t_prop.SetFontSize(36)
t_prop.SetColor(*text_color)
axes.SetTitleTextProperty(i, t_prop)
l_prop = vtkTextProperty()
l_prop.SetFontFamilyToArial()
l_prop.SetBold(False)
l_prop.SetItalic(False)
l_prop.SetOpacity(1.0)
l_prop.SetFontSize(28)
l_prop.SetColor(*text_color)
axes.SetLabelTextProperty(i, l_prop)
renderer.AddViewProp(axes)
renderer.SetBackground(0.93, 0.94, 0.97)
renderer.ResetCamera()
# Log what we set before rendering
log_axes(axes, "before-render")
ren_win.Render()
# Log what VTK reports after rendering
log_axes(axes, "after-render")
return ren_win
def main():
logging.basicConfig(level=logging.INFO, format="%(message)s")
server = get_server(client_type="vue3")
ren_win = build_vtk_pipeline()
with DivLayout(server) as layout:
client.Style("body, html, #app { margin: 0; height: 100%; }")
with html.Div(style="position:absolute; inset:0;"):
vtklocal.LocalView(
ren_win,
throttle_rate=20,
# Use WebGL2 by default; change to webgpu if desired
config="{rendering: 'webgl2'}",
style="width: 100%; height: 100%;",
)
server.start()
if __name__ == "__main__":
main()
Is this a known limitation/bug for vtkGridAxesActor3D text styling in the WASM/WebGL stack?
Any recommended API or renderer-side approach to style grid axes text in vtklocal?
Metadata
Metadata
Assignees
Labels
No labels