Forráskód Böngészése

Big fix for varying transport

David Catuhe 6 éve
szülő
commit
231c16215e

+ 0 - 29
nodeEditor/src/components/diagram/defaultNodeModel.ts

@@ -1,7 +1,6 @@
 import { NodeModel, DiagramModel } from "storm-react-diagrams";
 import { Nullable } from 'babylonjs/types';
 import { NodeMaterialBlock } from 'babylonjs/Materials/Node/nodeMaterialBlock';
-import { NodeMaterialBlockConnectionPointTypes } from 'babylonjs/Materials/Node/nodeMaterialBlockConnectionPointTypes';
 import { GraphEditor, NodeCreationOptions } from '../../graphEditor';
 import { GlobalState } from '../../globalState';
 import { DefaultPortModel } from './defaultPortModel';
@@ -63,34 +62,6 @@ export class DefaultNodeModel extends NodeModel {
                 } else {
                     model.addAll(link);
                 }
-            } else {
-                // Create value node for the connection
-                var type = ""
-                if (connection.type == NodeMaterialBlockConnectionPointTypes.Matrix) {
-                    type = "Matrix"
-                } else if (connection.type & NodeMaterialBlockConnectionPointTypes.Vector3OrColor3) {
-                    type = "Vector3"
-                } else if (connection.type & NodeMaterialBlockConnectionPointTypes.Vector2) {
-                    type = "Vector2"
-                } else if (connection.type & NodeMaterialBlockConnectionPointTypes.Vector3OrColor3OrVector4OrColor4) {
-                    type = "Vector4"
-                } else if (connection.type & NodeMaterialBlockConnectionPointTypes.Float) {
-                    type = "Float"
-                }
-
-                // Create links
-                var localNode = graphEditor.addValueNode(type, options.column + 1, connection);
-                if (localNode) {
-                    var ports = localNode.getPorts()
-                    for (var key in ports) {
-                        let link = (ports[key] as DefaultPortModel).link(inputPort);
-                        if (graphEditor._toAdd) {
-                            graphEditor._toAdd.push(link);
-                        } else {
-                            model.addAll(link);
-                        }
-                    }
-                }
             }
         });
     }

+ 0 - 2
nodeEditor/src/components/diagram/input/inputNodeModel.tsx

@@ -3,13 +3,11 @@ import { DefaultNodeModel } from '../defaultNodeModel';
 import { GlobalState } from '../../../globalState';
 import { InputPropertyTabComponentProps } from './inputNodePropertyComponent';
 import { InputBlock } from 'babylonjs/Materials/Node/Blocks/Input/inputBlock';
-import { NodeMaterialBlockConnectionPointTypes } from 'babylonjs/Materials/Node/nodeMaterialBlockConnectionPointTypes';
 
 /**
  * Generic node model which stores information about a node editor block
  */
 export class InputNodeModel extends DefaultNodeModel {
-    public outputType: NodeMaterialBlockConnectionPointTypes;
 
     public get inputBlock(): InputBlock {
         return this.block as InputBlock;

+ 1 - 1
nodeEditor/src/components/diagram/input/inputNodePropertyComponent.tsx

@@ -83,7 +83,7 @@ export class InputPropertyTabComponentProps extends React.Component<IInputProper
         return (
             <div>
                 <LineContainerComponent title="GENERAL">
-                    <TextLineComponent label="Type" value={StringTools.GetBaseType(this.props.inputNode.outputType)} />
+                    <TextLineComponent label="Type" value={StringTools.GetBaseType(inputBlock.type)} />
                 </LineContainerComponent>
                 <LineContainerComponent title="PROPERTIES">
                     <CheckBoxLineComponent label="Is mesh attribute" onSelect={value => {

+ 2 - 2
nodeEditor/src/components/diagram/input/inputNodeWidget.tsx

@@ -89,7 +89,7 @@ export class InputNodeWidget extends React.Component<InputNodeWidgetProps> {
 
         let inputBlock = this.props.node!.inputBlock;
         let value = "";
-        let name = StringTools.GetBaseType(this.props.node!.outputType);
+        let name = StringTools.GetBaseType(inputBlock.output.type);
 
         if (inputBlock) {
             if (inputBlock.isAttribute) {
@@ -118,7 +118,7 @@ export class InputNodeWidget extends React.Component<InputNodeWidgetProps> {
                         value = "Camera position";
                         break;
                     case NodeMaterialWellKnownValues.FogColor:
-                        value = "Automatic";
+                        value = "Fog color";
                         break;
                 }
             }

+ 2 - 1
nodeEditor/src/graphEditor.tsx

@@ -303,7 +303,8 @@ export class GraphEditor extends React.Component<IGraphEditorProps> {
                 break;
         }
 
-        let newInputBlock = new InputBlock(type, undefined, nodeType)
+        let newInputBlock = new InputBlock(type, undefined, nodeType);
+        newInputBlock.setDefaultValue();
         var localNode = this.createNodeFromObject({ column: column, type: type, connection: connection, nodeMaterialBlock: newInputBlock })
 
         return localNode;

+ 2 - 1
src/Materials/Node/Blocks/Dual/index.ts

@@ -1,3 +1,4 @@
 
 export * from "./fogBlock";
-export * from "./lightBlock";
+export * from "./lightBlock";
+export * from "./textureBlock";

+ 3 - 3
src/Materials/Node/Blocks/Dual/lightBlock.ts

@@ -158,12 +158,12 @@ export class LightBlock extends NodeMaterialBlock {
         super._buildBlock(state);
 
         if (state.target !== NodeMaterialBlockTargets.Fragment) {
+            // Vertex
+            this._injectVertexCode(state);
+
             return;
         }
 
-        // Vertex
-        this._injectVertexCode(state._vertexState);
-
         // Fragment
         state.sharedData.bindableBlocks.push(this);
         state.sharedData.blocksWithDefines.push(this);

+ 13 - 5
src/Materials/Node/Blocks/Fragment/textureBlock.ts

@@ -7,7 +7,7 @@ import { BaseTexture } from '../../../Textures/baseTexture';
 import { AbstractMesh } from '../../../../Meshes/abstractMesh';
 import { NodeMaterial, NodeMaterialDefines } from '../../nodeMaterial';
 import { InputBlock } from '../Input/inputBlock';
-import { Effect } from '../../../../Materials/effect';
+import { Effect } from '../../../effect';
 import { Mesh } from '../../../../Meshes/mesh';
 import { Nullable } from '../../../../types';
 
@@ -35,9 +35,9 @@ export class TextureBlock extends NodeMaterialBlock {
     public constructor(name: string) {
         super(name, NodeMaterialBlockTargets.VertexAndFragment);
 
-        this.registerInput("uv", NodeMaterialBlockConnectionPointTypes.Vector2, false);
+        this.registerInput("uv", NodeMaterialBlockConnectionPointTypes.Vector2, false, NodeMaterialBlockTargets.Vertex);
 
-        this.registerOutput("color", NodeMaterialBlockConnectionPointTypes.Color4);
+        this.registerOutput("color", NodeMaterialBlockConnectionPointTypes.Color4, NodeMaterialBlockTargets.Fragment);
     }
 
     /**
@@ -120,6 +120,14 @@ export class TextureBlock extends NodeMaterialBlock {
         this._defineName = state._getFreeDefineName("UVTRANSFORM");
         this._mainUVDefineName = state._getFreeDefineName("vMain" + uvInput.associatedVariableName);
 
+        if (uvInput.connectedPoint!.ownerBlock.isInput) {
+            let uvInputOwnerBlock = uvInput.connectedPoint!.ownerBlock as InputBlock;
+
+            if (!uvInputOwnerBlock.isAttribute) {
+                state._emitUniformFromString(uvInput.associatedVariableName, "vec2");
+            }
+        }
+
         this._mainUVName = "vMain" + uvInput.associatedVariableName;
         this._transformedUVName = state._getFreeVariableName("transformedUV");
         this._textureTransformName = state._getFreeVariableName("textureTransform");
@@ -144,6 +152,8 @@ export class TextureBlock extends NodeMaterialBlock {
         super._buildBlock(state);
 
         if (state.target !== NodeMaterialBlockTargets.Fragment) {
+            // Vertex
+            this._injectVertexCode(state);
             return;
         }
 
@@ -154,8 +164,6 @@ export class TextureBlock extends NodeMaterialBlock {
         state.samplers.push(this._samplerName);
         state._samplerDeclaration += `uniform sampler2D ${this._samplerName};\r\n`;
 
-        // Vertex
-        this._injectVertexCode(state._vertexState);
 
         // Fragment
         state.sharedData.blocksWithDefines.push(this);

+ 0 - 1
src/Materials/Node/Blocks/Fragment/index.ts

@@ -5,5 +5,4 @@ export * from "./rgbaMergerBlock";
 export * from "./rgbMergerBlock";
 export * from "./rgbaSplitterBlock";
 export * from "./rgbSplitterBlock";
-export * from "./textureBlock";
 export * from "./imageProcessingBlock";

+ 2 - 1
src/Materials/Node/Blocks/addBlock.ts

@@ -2,6 +2,7 @@ import { NodeMaterialBlock } from '../nodeMaterialBlock';
 import { NodeMaterialBlockConnectionPointTypes } from '../nodeMaterialBlockConnectionPointTypes';
 import { NodeMaterialBuildState } from '../nodeMaterialBuildState';
 import { NodeMaterialConnectionPoint } from '../nodeMaterialBlockConnectionPoint';
+import { NodeMaterialBlockTargets } from '../nodeMaterialBlockTargets';
 /**
  * Block used to add 2 vector4
  */
@@ -11,7 +12,7 @@ export class AddBlock extends NodeMaterialBlock {
      * @param name defines the block name
      */
     public constructor(name: string) {
-        super(name);
+        super(name, NodeMaterialBlockTargets.Neutral);
 
         this.registerInput("left", NodeMaterialBlockConnectionPointTypes.AutoDetect);
         this.registerInput("right", NodeMaterialBlockConnectionPointTypes.AutoDetect);

+ 2 - 1
src/Materials/Node/Blocks/clampBlock.ts

@@ -2,6 +2,7 @@ import { NodeMaterialBlock } from '../nodeMaterialBlock';
 import { NodeMaterialBlockConnectionPointTypes } from '../nodeMaterialBlockConnectionPointTypes';
 import { NodeMaterialBuildState } from '../nodeMaterialBuildState';
 import { NodeMaterialConnectionPoint } from '../nodeMaterialBlockConnectionPoint';
+import { NodeMaterialBlockTargets } from '../nodeMaterialBlockTargets';
 /**
  * Block used to clamp a float
  */
@@ -17,7 +18,7 @@ export class ClampBlock extends NodeMaterialBlock {
      * @param name defines the block name
      */
     public constructor(name: string) {
-        super(name);
+        super(name, NodeMaterialBlockTargets.Neutral);
 
         this.registerInput("value", NodeMaterialBlockConnectionPointTypes.Float);
         this.registerOutput("output", NodeMaterialBlockConnectionPointTypes.Float);

+ 2 - 1
src/Materials/Node/Blocks/multiplyBlock.ts

@@ -2,6 +2,7 @@ import { NodeMaterialBlock } from '../nodeMaterialBlock';
 import { NodeMaterialBlockConnectionPointTypes } from '../nodeMaterialBlockConnectionPointTypes';
 import { NodeMaterialBuildState } from '../nodeMaterialBuildState';
 import { NodeMaterialConnectionPoint } from '../nodeMaterialBlockConnectionPoint';
+import { NodeMaterialBlockTargets } from '../nodeMaterialBlockTargets';
 /**
  * Block used to multiply 2 values
  */
@@ -11,7 +12,7 @@ export class MultiplyBlock extends NodeMaterialBlock {
      * @param name defines the block name
      */
     public constructor(name: string) {
-        super(name);
+        super(name, NodeMaterialBlockTargets.Neutral);
 
         this.registerInput("left", NodeMaterialBlockConnectionPointTypes.AutoDetect);
         this.registerInput("right", NodeMaterialBlockConnectionPointTypes.AutoDetect);

+ 1 - 1
src/Materials/Node/Blocks/vector2TransformBlock.ts

@@ -23,7 +23,7 @@ export class Vector2TransformBlock extends NodeMaterialBlock {
      * @param name defines the block name
      */
     public constructor(name: string) {
-        super(name, NodeMaterialBlockTargets.Vertex);
+        super(name, NodeMaterialBlockTargets.Neutral);
 
         this.registerInput("vector", NodeMaterialBlockConnectionPointTypes.Vector2);
         this.registerInput("transform", NodeMaterialBlockConnectionPointTypes.Matrix);

+ 1 - 1
src/Materials/Node/Blocks/vector3TransformBlock.ts

@@ -18,7 +18,7 @@ export class Vector3TransformBlock extends NodeMaterialBlock {
      * @param name defines the block name
      */
     public constructor(name: string) {
-        super(name, NodeMaterialBlockTargets.Vertex);
+        super(name, NodeMaterialBlockTargets.Neutral);
 
         this.registerInput("vector", NodeMaterialBlockConnectionPointTypes.Vector3);
         this.registerInput("transform", NodeMaterialBlockConnectionPointTypes.Matrix);

+ 1 - 1
src/Materials/Node/Blocks/vector4TransformBlock.ts

@@ -18,7 +18,7 @@ export class Vector4TransformBlock extends NodeMaterialBlock {
      * @param name defines the block name
      */
     public constructor(name: string) {
-        super(name, NodeMaterialBlockTargets.Vertex);
+        super(name, NodeMaterialBlockTargets.Neutral);
 
         this.registerInput("vector", NodeMaterialBlockConnectionPointTypes.Vector3OrVector4);
         this.registerInput("transform", NodeMaterialBlockConnectionPointTypes.Matrix);

+ 27 - 9
src/Materials/Node/nodeMaterial.ts

@@ -373,19 +373,32 @@ export class NodeMaterial extends PushMaterial {
         return this._sharedData.hints.needAlphaTesting;
     }
 
-    private _initializeBlock(node: NodeMaterialBlock, state: NodeMaterialBuildState) {
+    private _initializeBlock(node: NodeMaterialBlock, state: NodeMaterialBuildState, nodesToProcessForOtherBuildState: NodeMaterialBlock[]) {
         node.initialize(state);
         node.autoConfigure();
 
-        for (var inputs of node.inputs) {
-            let connectedPoint = inputs.connectedPoint;
+        if (node.isInput) {
+            (node as InputBlock).associatedVariableName = "";
+        }
+
+        for (var input of node.inputs) {
+            input.associatedVariableName = "";
+
+            let connectedPoint = input.connectedPoint;
             if (connectedPoint) {
                 let block = connectedPoint.ownerBlock;
                 if (block !== node) {
-                    this._initializeBlock(block, state);
+                    if (block.target === NodeMaterialBlockTargets.VertexAndFragment) {
+                        nodesToProcessForOtherBuildState.push(block);
+                    }
+                    this._initializeBlock(block, state, nodesToProcessForOtherBuildState);
                 }
             }
         }
+
+        for (var output of node.outputs) {
+            output.associatedVariableName = "";
+        }
     }
 
     private _resetDualBlocks(node: NodeMaterialBlock, id: number) {
@@ -437,30 +450,35 @@ export class NodeMaterial extends PushMaterial {
         this._sharedData.verbose = verbose;
 
         // Initialize blocks
+        let vertexNodes: NodeMaterialBlock[] = [];
+        let fragmentNodes: NodeMaterialBlock[] = [];
+
         for (var vertexOutputNode of this._vertexOutputNodes) {
-            this._initializeBlock(vertexOutputNode, this._vertexCompilationState);
+            vertexNodes.push(vertexOutputNode);
+            this._initializeBlock(vertexOutputNode, this._vertexCompilationState, fragmentNodes);
         }
 
         for (var fragmentOutputNode of this._fragmentOutputNodes) {
-            this._initializeBlock(fragmentOutputNode, this._fragmentCompilationState);
+            fragmentNodes.push(fragmentOutputNode);
+            this._initializeBlock(fragmentOutputNode, this._fragmentCompilationState, vertexNodes);
         }
 
         // Optimize
         this.optimize();
 
         // Vertex
-        for (var vertexOutputNode of this._vertexOutputNodes) {
+        for (var vertexOutputNode of vertexNodes) {
             vertexOutputNode.build(this._vertexCompilationState);
         }
 
         // Fragment
         this._fragmentCompilationState._vertexState = this._vertexCompilationState;
 
-        for (var fragmentOutputNode of this._fragmentOutputNodes) {
+        for (var fragmentOutputNode of fragmentNodes) {
             this._resetDualBlocks(fragmentOutputNode, this._buildId - 1);
         }
 
-        for (var fragmentOutputNode of this._fragmentOutputNodes) {
+        for (var fragmentOutputNode of fragmentNodes) {
             fragmentOutputNode.build(this._fragmentCompilationState);
         }
 

+ 15 - 11
src/Materials/Node/nodeMaterialBlock.ts

@@ -238,7 +238,7 @@ export class NodeMaterialBlock {
      */
     public getFirstAvailableOutput(forBlock: Nullable<NodeMaterialBlock> = null) {
         for (var output of this._outputs) {
-            if (!forBlock || !forBlock.target || (forBlock.target & output.target) !== 0) {
+            if (!forBlock || !forBlock.target || forBlock.target === NodeMaterialBlockTargets.Neutral || (forBlock.target & output.target) !== 0) {
                 return output;
             }
         }
@@ -385,12 +385,14 @@ export class NodeMaterialBlock {
                 continue;
             }
 
-            if ((input.target & this.target!) === 0) {
-                continue;
-            }
+            if (this.target !== NodeMaterialBlockTargets.Neutral) {
+                if ((input.target & this.target!) === 0) {
+                    continue;
+                }
 
-            if ((input.target & state.target!) === 0) {
-                continue;
+                if ((input.target & state.target!) === 0) {
+                    continue;
+                }
             }
 
             let block = input.connectedPoint.ownerBlock;
@@ -411,11 +413,13 @@ export class NodeMaterialBlock {
         if (!this.isInput) {
             /** Prepare outputs */
             for (var output of this._outputs) {
-                if ((output.target & this.target!) === 0) {
-                    continue;
-                }
-                if ((output.target & state.target!) === 0) {
-                    continue;
+                if (this.target !== NodeMaterialBlockTargets.Neutral) {
+                    if ((output.target & this.target!) === 0) {
+                        continue;
+                    }
+                    if ((output.target & state.target!) === 0) {
+                        continue;
+                    }
                 }
 
                 if (!output.associatedVariableName) {

+ 2 - 0
src/Materials/Node/nodeMaterialBlockTargets.ts

@@ -6,6 +6,8 @@ export enum NodeMaterialBlockTargets {
     Vertex = 1,
     /** Fragment shader */
     Fragment = 2,
+    /** Neutral */
+    Neutral = 4,
     /** Vertex and Fragment */
     VertexAndFragment = Vertex | Fragment
 }

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

@@ -1,7 +1,7 @@
 import { NodeMaterialConnectionPoint } from './nodeMaterialBlockConnectionPoint';
 import { NodeMaterialBlock } from './nodeMaterialBlock';
 import { InputBlock } from './Blocks/Input/inputBlock';
-import { TextureBlock } from './Blocks/Fragment/textureBlock';
+import { TextureBlock } from './Blocks/Dual/textureBlock';
 
 /**
  * Class used to store shared data between 2 NodeMaterialBuildState