瀏覽代碼

example and documentation for scene element

Falko Schindler 3 年之前
父節點
當前提交
054b9f8b79
共有 2 個文件被更改,包括 30 次插入0 次删除
  1. 19 0
      main.py
  2. 11 0
      nicegui/elements/scene.py

+ 19 - 0
main.py

@@ -270,6 +270,25 @@ with example(ui.log):
     log = ui.log(max_lines=10).classes('h-16')
     log = ui.log(max_lines=10).classes('h-16')
     ui.button('Log time', on_click=lambda: log.push(datetime.now().strftime("%X.%f")[:-5]))
     ui.button('Log time', on_click=lambda: log.push(datetime.now().strftime("%X.%f")[:-5]))
 
 
+with example(ui.scene):
+
+    with ui.scene(width=200, height=200) as scene:
+        scene.sphere().material('#4488ff')
+        scene.cylinder(1, 0.5, 2, 20).material('#ff8800', opacity=0.5).move(-2, 1)
+        scene.extrusion([[0, 0], [1, 0], [1, 1], [0, 1]], 0.1).material('#ff8888').move(-2, -2)
+
+        with scene.group().move(z=2):
+            box1 = scene.box().move(x=2)
+            scene.box().move(y=2).rotate(0.25, 0.5, 0.75)
+            scene.box(wireframe=True).material('#888888').move(x=2, y=2)
+
+        scene.line([-4, 0, 0], [-4, 2, 0]).material('#ff0000')
+        scene.curve([-4, -2, 0], [-4, -1, 0], [-3, -1, 0], [-3, 0, 0]).material('#008800')
+
+        scene.texture("https://avatars.githubusercontent.com/u/2843826",
+                      [[[0, 3, 0], [3, 3, 0]],
+                       [[0, 0, 0], [3, 0, 0]]]).move(1, -2)
+
 with example(ui.joystick):
 with example(ui.joystick):
 
 
     ui.joystick(
     ui.joystick(

+ 11 - 0
nicegui/elements/scene.py

@@ -34,6 +34,17 @@ class Scene(Element):
     from .scene_objects import Texture as texture
     from .scene_objects import Texture as texture
 
 
     def __init__(self, width: int = 400, height: int = 300, on_click: Callable = None):
     def __init__(self, width: int = 400, height: int = 300, on_click: Callable = None):
+        """3D Scene
+
+        Display a 3d scene using `three.js <https://threejs.org/>`_.
+        Currently NiceGUI supports boxes, spheres, cylinders/cones, extrusions, straight lines, curves and textured meshes.
+        Objects can be translated, rotated and displayed with different color, opacity or as wireframes.
+        They can also be grouped to apply joint movements.
+
+        :param width: width of the canvas
+        :param height: height of the canvas
+        :param on_click: callback to execute when a 3d object is clicked
+        """
         super().__init__(SceneView(width=width, height=height, on_click=on_click))
         super().__init__(SceneView(width=width, height=height, on_click=on_click))
 
 
     def __enter__(self):
     def __enter__(self):