Files
endorphin-tessera-gui/examples/scene3d.endor

47 lines
1.7 KiB
Plaintext

class SceneActions {
view: Viewport3D
cube: Mesh3D
function front(self: SceneActions): Unit {
self.view.camera.x = 0
self.view.camera.y = 0
self.view.camera.z = 6
}
function side(self: SceneActions): Unit {
self.view.camera.x = 6
self.view.camera.y = 2
self.view.camera.z = 0
}
function rotate(self: SceneActions): Unit { self.cube.rotate(0, 15, 0) }
function select(self: SceneActions, event: Event): Unit { event.hit.mesh.color = "#6B9B81" }
}
cube = Box3D(1.6, 1.6, 1.6, "#6687AB")
cube.rotationY = 25
cube.rotationX = 15
small = Box3D(0.7, 0.7, 0.7, "#DBA36E")
small.x = 1.8
small.z = -0.8
group = Group3D(cube, small)
floor = Box3D(6, 0.08, 4, "#D8DEE6")
floor.y = -1.1
light = DirectionalLight(-1, -2, -3, "#FFFFFF", 0.9)
scene = Scene3D(group, floor, light)
scene.ambient = 0.35
perspective = Viewport3D(480, 360, scene)
perspective.camera.z = 6
orthographic = Viewport3D(320, 360, scene)
orthographic.camera = OrthographicCamera()
orthographic.camera.height = 5
orthographic.camera.x = 4
orthographic.camera.y = 2
orthographic.camera.z = 5
actions = SceneActions(perspective, cube)
front = Button("正面")
front.onClick(actions.front)
side = Button("侧面")
side.onClick(actions.side)
rotate = Button("物体旋转 +15°")
rotate.onClick(actions.rotate)
page = Page()
page.title = "场景、视口和摄像机"
page.render(Column(24, 16, TextBlock("同一个 3D 场景,两个摄像机", 2), Row(0, 16, perspective, orthographic), Row(0, 12, front, side, rotate), TextBlock("左键拖动旋转 · 中键或空格拖动平移 · 滚轮缩放\n摄像机和控制器都是可编程对象;2D 控件由 Endor 自己排版。")))