"""Default scene builders for the editor."""
from __future__ import annotations
import math
from simvx.core import (
DirectionalLight3D,
MeshInstance3D,
Node3D,
OrbitCamera3D,
WorldEnvironment,
)
from simvx.core.graphics.material import Material
from simvx.core.graphics.mesh import Mesh
from simvx.core.math import Vec3
[docs]
def populate_default_scene(root: Node3D) -> None:
"""Add a default 3D scene with primitives, lighting, and environment to *root*."""
if not isinstance(root, Node3D):
return
# Floor
root.add_child(MeshInstance3D(
name="Floor",
mesh=Mesh.cube(),
material=Material(colour=(0.45, 0.45, 0.45), roughness=0.85, metallic=0.0),
position=Vec3(0, -0.025, 0),
scale=Vec3(10, 0.05, 10),
))
# Cube
root.add_child(MeshInstance3D(
name="Cube",
mesh=Mesh.cube(),
material=Material(colour=(0.76, 0.35, 0.25), roughness=0.4, metallic=0.1),
position=Vec3(0, 0.5, 0),
))
# Sphere (slightly metallic for bloom highlights)
root.add_child(MeshInstance3D(
name="Sphere",
mesh=Mesh.sphere(radius=0.5),
material=Material(colour=(0.3, 0.5, 0.85), roughness=0.25, metallic=0.6),
position=Vec3(-1.8, 0.5, 0.8),
))
# Cylinder (fairly metallic)
root.add_child(MeshInstance3D(
name="Cylinder",
mesh=Mesh.cylinder(radius=0.4, height=1.0),
material=Material(colour=(0.55, 0.65, 0.25), roughness=0.3, metallic=0.8),
position=Vec3(1.8, 0.5, 0.8),
))
# Sun light
sun = DirectionalLight3D(name="Sun")
sun.position = Vec3(5, 8, -3)
sun.look_at((0, 0, 0))
sun.intensity = 1.2
sun.colour = (1.0, 0.95, 0.9, 1.0)
root.add_child(sun)
# Camera (orbit camera for interactive play mode)
cam = OrbitCamera3D(name="Camera")
cam.pivot = Vec3(0, 0.5, 0)
cam.distance = 6.0
cam.yaw = math.radians(30.0)
cam.pitch = math.radians(-25.0)
cam._update_transform()
root.add_child(cam)
# Environment — dark blue background with bloom
env = WorldEnvironment()
env.sky_colour_top = (0.04, 0.05, 0.12, 1.0)
env.sky_colour_bottom = (0.06, 0.07, 0.15, 1.0)
env.ambient_light_colour = (0.12, 0.14, 0.22, 1.0)
env.ambient_light_energy = 0.6
env.bloom_enabled = True
env.bloom_threshold = 0.8
env.bloom_intensity = 0.6
env.tonemap_mode = "aces"
root.add_child(env)