Ver código fonte

avoid white texture during download; skip new urls when still busy downloading

Falko Schindler 3 anos atrás
pai
commit
7fec4afe5b
1 arquivos alterados com 14 adições e 8 exclusões
  1. 14 8
      nicegui/elements/scene.js

+ 14 - 8
nicegui/elements/scene.js

@@ -235,14 +235,20 @@ Vue.component("scene", {
       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;
+      const obj = objects.get(object_id);
+      if (obj.busy) return;
+      obj.busy = true;
+      const on_success = (texture) => {
+        texture.flipY = false;
+        texture.minFilter = THREE.LinearFilter;
+        obj.material = new THREE.MeshLambertMaterial({
+          map: texture,
+          side: THREE.DoubleSide,
+        });
+        obj.busy = false;
+      };
+      const on_error = () => (obj.busy = false);
+      texture_loader.load(url, on_success, undefined, on_error);
     },
   },