Browse Source

add point-cloud support to 3D scene

kielnino 2 years ago
parent
commit
3f5e6dd14d
3 changed files with 17 additions and 0 deletions
  1. 6 0
      nicegui/elements/scene.js
  2. 1 0
      nicegui/elements/scene.py
  3. 10 0
      nicegui/elements/scene_objects.py

+ 6 - 0
nicegui/elements/scene.js

@@ -198,6 +198,12 @@ export default {
         light.target.position.set(1, 0, 0);
         mesh.add(light);
         mesh.add(light.target);
+      } else if (type == "point_cloud") {
+        const geometry = new THREE.BufferGeometry();
+        geometry.setAttribute('position', new THREE.Float32BufferAttribute(args[0].flat(), 3));
+        geometry.setAttribute('color', new THREE.Float32BufferAttribute(args[1].flat(), 3));
+        const material = new THREE.PointsMaterial( { size: args[2], vertexColors: true } );
+        mesh = new THREE.Points(geometry, material);
       } else {
         let geometry;
         const wireframe = args.pop();

+ 1 - 0
nicegui/elements/scene.py

@@ -52,6 +52,7 @@ class Scene(Element):
     from .scene_objects import Text as text
     from .scene_objects import Text3d as text3d
     from .scene_objects import Texture as texture
+    from .scene_objects import PointCloud as pointcloud
 
     def __init__(self, width: int = 400, height: int = 300, on_click: Optional[Callable] = None) -> None:
         """3D Scene

+ 10 - 0
nicegui/elements/scene_objects.py

@@ -169,3 +169,13 @@ class SpotLight(Object3D):
                  decay: float = 1.0,
                  ) -> None:
         super().__init__('spot_light', color, intensity, distance, angle, penumbra, decay)
+
+
+class PointCloud(Object3D):
+
+    def __init__(self,
+                points: List[List[float]],
+                color: List[List[float]],
+                point_size: float = 1.0,
+                ) -> None:
+        super().__init__('point_cloud', points, color, point_size)