Browse Source

Merge pull request #4628 from RaananW/small-fix-drag-drop

 small fix for viewer drag and drop
David Catuhe 7 năm trước cách đây
mục cha
commit
76dca33829

+ 8 - 8
Viewer/src/loader/modelLoader.ts

@@ -61,24 +61,24 @@ export class ModelLoader {
 
         model.loadId = this._loadId++;
 
-        if (!modelConfiguration.url) {
-            model.state = ModelState.ERROR;
-            Tools.Error("No URL provided");
-            return model;
-        }
-
-        let base: string;
+        let base: string = "";
 
         let filename: any;
         if (modelConfiguration.file) {
             base = "file:";
             filename = modelConfiguration.file;
         }
-        else {
+        else if (modelConfiguration.url) {
             filename = Tools.GetFilename(modelConfiguration.url) || modelConfiguration.url;
             base = modelConfiguration.root || Tools.GetFolderPath(modelConfiguration.url);
         }
 
+        if (!filename || !base) {
+            model.state = ModelState.ERROR;
+            Tools.Error("No URL provided");
+            return model;
+        }
+
 
         let plugin = modelConfiguration.loader;
 

+ 18 - 10
Viewer/src/viewer/defaultViewer.ts

@@ -35,6 +35,12 @@ export class DefaultViewer extends AbstractViewer {
                 this._configureLights();
             })
         });
+
+        this.onInitDoneObservable.add(() => {
+            if (!this.sceneManager.models.length) {
+                this.hideLoadingScreen();
+            }
+        })
     }
 
     private _registeredPlugins: Array<IViewerTemplatePlugin> = [];
@@ -89,16 +95,18 @@ export class DefaultViewer extends AbstractViewer {
 
         if (this.configuration.templates && this.configuration.templates.viewer) {
             if (this.configuration.templates.viewer.params && this.configuration.templates.viewer.params.enableDragAndDrop) {
-                let filesInput = new FilesInput(this.engine, this.sceneManager.scene, () => {
-                }, () => {
-                }, () => {
-                }, () => {
-                }, function () {
-                }, (file: File) => {
-                    this.loadModel(file);
-                }, () => {
-                });
-                filesInput.monitorElementForDragNDrop(this.templateManager.getCanvas()!);
+                this.onSceneInitObservable.addOnce(() => {
+                    let filesInput = new FilesInput(this.engine, this.sceneManager.scene, () => {
+                    }, () => {
+                    }, () => {
+                    }, () => {
+                    }, function () {
+                    }, (file: File) => {
+                        this.loadModel(file);
+                    }, () => {
+                    });
+                    filesInput.monitorElementForDragNDrop(this.templateManager.getCanvas()!);
+                })
             }
         }
 

+ 1 - 0
dist/preview release/what's new.md

@@ -126,6 +126,7 @@
 - Removed element IDs from viewer's templates to allow muitiple viewers in a single page [#4500](https://github.com/BabylonJS/Babylon.js/issues/4500) ([RaananW](https://github.com/RaananW))
 - Viewer is not using Engine.LastCreatedScene anymore, to support multiple viewers in a single page [#4500](https://github.com/BabylonJS/Babylon.js/issues/4500) ([RaananW](https://github.com/RaananW))
 - Template location was ignored if html was defined ([RaananW](https://github.com/RaananW))
+- Drag and Drop only worked if a model was already loaded before ([RaananW](https://github.com/RaananW))
 
 ### Loaders