David Catuhe 6 سال پیش
والد
کامیت
0b17e0e256
5فایلهای تغییر یافته به همراه25 افزوده شده و 8 حذف شده
  1. 2 1
      nodeEditor/src/graphEditor.tsx
  2. 0 1
      nodeEditor/src/main.scss
  3. 21 5
      nodeEditor/src/previewManager.ts
  4. 1 1
      src/Materials/Node/nodeMaterial.ts
  5. 1 0
      src/Misc/tools.ts

+ 2 - 1
nodeEditor/src/graphEditor.tsx

@@ -403,6 +403,7 @@ export class GraphEditor extends React.Component<IGraphEditorProps> {
             this._rightWidth -= deltaX;
             this._rightWidth -= deltaX;
             this._rightWidth = Math.max(250, Math.min(500, this._rightWidth));
             this._rightWidth = Math.max(250, Math.min(500, this._rightWidth));
             DataStorage.StoreNumber("RightWidth", this._rightWidth);
             DataStorage.StoreNumber("RightWidth", this._rightWidth);
+            rootElement.ownerDocument!.getElementById("preview")!.style.height = this._rightWidth + "px";
         }
         }
 
 
         rootElement.style.gridTemplateColumns = this.buildColumnLayout();
         rootElement.style.gridTemplateColumns = this.buildColumnLayout();
@@ -481,7 +482,7 @@ export class GraphEditor extends React.Component<IGraphEditorProps> {
                     {/* Property tab */}
                     {/* Property tab */}
                     <div className="right-panel">
                     <div className="right-panel">
                         <PropertyTabComponent globalState={this.props.globalState} />
                         <PropertyTabComponent globalState={this.props.globalState} />
-                        <div id="preview">
+                        <div id="preview" style={{height: this._rightWidth + "px"}}>
                             <canvas id="preview-canvas"/>
                             <canvas id="preview-canvas"/>
                         </div>
                         </div>
                     </div>
                     </div>

+ 0 - 1
nodeEditor/src/main.scss

@@ -54,7 +54,6 @@
         grid-row: 2;
         grid-row: 2;
         grid-column: 1;
         grid-column: 1;
         width: 100%;
         width: 100%;
-        padding-top: 100%;
         display: grid;
         display: grid;
         
         
         #preview-canvas {
         #preview-canvas {

+ 21 - 5
nodeEditor/src/previewManager.ts

@@ -17,12 +17,14 @@ export class PreviewManager {
     private _light: HemisphericLight;
     private _light: HemisphericLight;
     private _dummySphere: Mesh;
     private _dummySphere: Mesh;
     private _camera: ArcRotateCamera;
     private _camera: ArcRotateCamera;
+    private _material: NodeMaterial;
 
 
     public constructor(targetCanvas: HTMLCanvasElement, globalState: GlobalState) {
     public constructor(targetCanvas: HTMLCanvasElement, globalState: GlobalState) {
         this._nodeMaterial = globalState.nodeMaterial;
         this._nodeMaterial = globalState.nodeMaterial;
 
 
-        this._onBuildObserver = this._nodeMaterial.onBuildObservable.add(() => {
-            this._updatePreview();
+        this._onBuildObserver = this._nodeMaterial.onBuildObservable.add((nodeMaterial) => {
+            let serializationObject = nodeMaterial.serialize();
+            this._updatePreview(serializationObject);
         });
         });
 
 
         this._engine = new Engine(targetCanvas, true);
         this._engine = new Engine(targetCanvas, true);
@@ -32,20 +34,34 @@ export class PreviewManager {
 
 
         this._dummySphere = Mesh.CreateSphere("sphere", 32, 2, this._scene);
         this._dummySphere = Mesh.CreateSphere("sphere", 32, 2, this._scene);
 
 
-       // this._camera.attachControl(targetCanvas, false);
+        this._camera.lowerRadiusLimit = 2.5;
+        this._camera.upperRadiusLimit = 10;
+        this._camera.attachControl(targetCanvas, false);
 
 
         this._engine.runRenderLoop(() => {
         this._engine.runRenderLoop(() => {
             this._scene.render();
             this._scene.render();
         })
         })
     }
     }
 
 
-    private _updatePreview() {
-        
+    private _updatePreview(serializationObject: any) {
+        if (this._material) {
+            this._material.dispose();
+        }        
+
+        this._material = NodeMaterial.Parse(serializationObject, this._scene);
+
+        this._material.build();
+
+        this._dummySphere.material = this._material;
     }
     }
 
 
     public dispose() {
     public dispose() {
         this._nodeMaterial.onBuildObservable.remove(this._onBuildObserver);
         this._nodeMaterial.onBuildObservable.remove(this._onBuildObserver);
 
 
+        if (this._material) {
+            this._material.dispose();
+        }
+
         this._camera.dispose();
         this._camera.dispose();
         this._dummySphere.dispose();
         this._dummySphere.dispose();
         this._light.dispose();
         this._light.dispose();

+ 1 - 1
src/Materials/Node/nodeMaterial.ts

@@ -386,7 +386,7 @@ export class NodeMaterial extends PushMaterial {
      * @returns a boolean specifying if an alpha test is needed.
      * @returns a boolean specifying if an alpha test is needed.
      */
      */
     public needAlphaTesting(): boolean {
     public needAlphaTesting(): boolean {
-        return this._sharedData.hints.needAlphaTesting;
+        return this._sharedData && this._sharedData.hints.needAlphaTesting;
     }
     }
 
 
     private _initializeBlock(node: NodeMaterialBlock, state: NodeMaterialBuildState, nodesToProcessForOtherBuildState: NodeMaterialBlock[]) {
     private _initializeBlock(node: NodeMaterialBlock, state: NodeMaterialBuildState, nodesToProcessForOtherBuildState: NodeMaterialBlock[]) {

+ 1 - 0
src/Misc/tools.ts

@@ -575,6 +575,7 @@ export class Tools {
 
 
     /**
     /**
      * Function used to unregister events from window level
      * Function used to unregister events from window level
+     * @param windowElement defines the Window object to use
      * @param events defines the events to unregister
      * @param events defines the events to unregister
      */
      */
     public static UnregisterTopRootEvents(windowElement: Window, events: { name: string; handler: Nullable<(e: FocusEvent) => any> }[]): void {
     public static UnregisterTopRootEvents(windowElement: Window, events: { name: string; handler: Nullable<(e: FocusEvent) => any> }[]): void {