Browse Source

allow changing texture url

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

+ 10 - 0
nicegui/elements/scene.js

@@ -234,6 +234,16 @@ Vue.component("scene", {
       objects.get(object_id).removeFromParent();
       objects.delete(object_id);
     },
+    set_texture_url(object_id, url) {
+      const texture = texture_loader.load(url);
+      texture.flipY = false;
+      texture.minFilter = THREE.LinearFilter;
+      const material = new THREE.MeshLambertMaterial({
+        map: texture,
+        side: THREE.DoubleSide,
+      });
+      objects.get(object_id).material = material;
+    },
   },
 
   props: {

+ 1 - 1
nicegui/elements/scene_object3d.py

@@ -15,7 +15,7 @@ class Object3D:
         self.parent = self.stack[-1]
         self.view = self.parent.view
         self.page = self.parent.page
-        self.args = args
+        self.args = list(args)
         self.color = '#ffffff'
         self.opacity = 1.0
         self.x = 0

+ 6 - 0
nicegui/elements/scene_objects.py

@@ -1,5 +1,6 @@
 from __future__ import annotations
 from typing import List, Optional
+from justpy import WebPage
 from .scene_object3d import Object3D
 
 class Scene(Object3D):
@@ -87,3 +88,8 @@ class Texture(Object3D):
                  coordinates: List[List[Optional[List[float]]]],
                  ):
         super().__init__('texture', url, coordinates)
+
+    async def set_url(self, url: str):
+        self.args[0] = url
+        for socket in WebPage.sockets.get(self.page.page_id, {}).values():
+            await self.view.run_method(f'set_texture_url("{self.id}", "{url}")', socket)