Browse Source

more optimal fix for nme custom mesh preview bug

Kyle Belfort 5 years ago
parent
commit
50d197aab6

+ 3 - 3
nodeEditor/src/components/preview/previewMeshControlComponent.tsx

@@ -5,7 +5,6 @@ import { Color3, Color4 } from 'babylonjs/Maths/math.color';
 import { PreviewMeshType } from './previewMeshType';
 import { DataStorage } from 'babylonjs/Misc/dataStorage';
 import { OptionsLineComponent } from '../../sharedComponents/optionsLineComponent';
-import * as ReactDOM from 'react-dom';
 
 const popUpIcon: string = require("./svgs/popOut.svg");
 const colorPicker: string = require("./svgs/colorPicker.svg");
@@ -47,7 +46,8 @@ export class PreviewMeshControlComponent extends React.Component<IPreviewMeshCon
 
             this.props.globalState.previewMeshFile = file;
             this.props.globalState.previewMeshType = PreviewMeshType.Custom;
-            this.props.globalState.onPreviewCommandActivated.notifyObservers();        
+            this.props.globalState.onPreviewCommandActivated.notifyObservers();
+            this.props.globalState.listOfCustomPreviewMeshFiles = [file];       
             this.forceUpdate();
         }
         if(this.filePickerRef.current){
@@ -92,7 +92,7 @@ export class PreviewMeshControlComponent extends React.Component<IPreviewMeshCon
             { label: "Load...", value: PreviewMeshType.Custom + 1 }
         ];
 
-        if (this.props.globalState.previewMeshType === PreviewMeshType.Custom) {
+        if (this.props.globalState.listOfCustomPreviewMeshFiles.length > 0) {
             meshTypeOptions.splice(0, 0, {
                 label: "Custom", value: PreviewMeshType.Custom
             });

+ 1 - 0
nodeEditor/src/globalState.ts

@@ -43,6 +43,7 @@ export class GlobalState {
     onGridSizeChanged = new Observable<void>();
     previewMeshType: PreviewMeshType;
     previewMeshFile: File;
+    listOfCustomPreviewMeshFiles: File[] = [];
     rotatePreview: boolean;
     backgroundColor: Color4;
     backFaceCulling: boolean;

+ 8 - 0
nodeEditor/src/nodeEditor.ts

@@ -6,6 +6,8 @@ import { NodeMaterial } from "babylonjs/Materials/Node/nodeMaterial"
 import { Popup } from "../src/sharedComponents/popup"
 import { SerializationTools } from './serializationTools';
 import { Observable } from 'babylonjs/Misc/observable';
+import { DataStorage } from 'babylonjs';
+import { PreviewMeshType } from './components/preview/previewMeshType';
 /**
  * Interface used to specify creation options for the node editor
  */
@@ -75,8 +77,14 @@ export class NodeEditor {
                 if (popupWindow) {
                     popupWindow.close();
                 }
+
             };
         }
+        window.onbeforeunload = () => {
+            if(DataStorage.ReadNumber("PreviewMeshType", PreviewMeshType.Box) === PreviewMeshType.Custom){
+                DataStorage.WriteNumber("PreviewMeshType", PreviewMeshType.Box)
+            }
+        }
     }
 }