Source code for simvx.editor.panels.inspector_sections._mesh_section
"""MeshSection -- mesh primitive creation.
Registered with the section registry via @register_inspector_section at
import time.
"""
from simvx.core import Button, Control, HBoxContainer, MeshInstance3D, Vec2
from ._base import (
InspectorSection,
_font_size,
_row_h,
register_inspector_section,
)
[docs]
@register_inspector_section
class MeshSection(InspectorSection):
section_title = "Mesh"
priority = 10
[docs]
def can_handle(self, node):
return isinstance(node, MeshInstance3D)
[docs]
def build_rows(self, node, ctx):
from simvx.core import Mesh
rows: list[Control] = []
if node.mesh is None:
mesh_row = HBoxContainer()
mesh_row.separation = 4
for prim_name, factory in [
("Cube", lambda: Mesh.cube(size=1.0)),
("Sphere", lambda: Mesh.sphere(radius=1.0, rings=16, segments=16)),
("Cylinder", lambda: Mesh.cylinder(radius=1.0, height=1.0, segments=16)),
]:
btn = Button(prim_name)
btn.size = Vec2(70, _row_h())
btn.font_size = _font_size()
btn.pressed.connect(lambda f=factory, c=ctx, n=node: _set_mesh(n, f(), c))
mesh_row.add_child(btn)
rows.append(mesh_row)
elif node.material is None:
mat_btn = Button("Add Material")
mat_btn.size = Vec2(120, _row_h())
mat_btn.font_size = _font_size()
mat_btn.pressed.connect(lambda c=ctx, n=node: _add_material(n, c))
rows.append(mat_btn)
return rows
def _set_mesh(node, mesh, ctx):
node.mesh = mesh
if ctx.editor_state:
ctx.editor_state.modified = True
ctx.rebuild()
def _add_material(node, ctx):
from simvx.core import Material
node.material = Material()
if ctx.editor_state:
ctx.editor_state.modified = True
ctx.rebuild()