Pārlūkot izejas kodu

Added inputs as properties

David Catuhe 6 gadi atpakaļ
vecāks
revīzija
f979ff67ff

+ 37 - 9
src/Materials/Node/Blocks/Dual/fogBlock.ts

@@ -8,8 +8,8 @@ import { Effect } from '../../../effect';
 import { NodeMaterialConnectionPoint } from '../../nodeMaterialBlockConnectionPoint';
 import { MaterialDefines } from '../../../materialDefines';
 import { AbstractMesh } from '../../../../Meshes/abstractMesh';
-import { MaterialHelper} from '../../../materialHelper';
-import { NodeMaterial} from '../../nodeMaterial';
+import { MaterialHelper } from '../../../materialHelper';
+import { NodeMaterial } from '../../nodeMaterial';
 
 /**
  * Block used to add support for scene fog
@@ -23,7 +23,7 @@ export class FogBlock extends NodeMaterialBlock {
         super(name, NodeMaterialBlockTargets.VertexAndFragment, true);
 
         // Vertex
-        this.registerInput("worldPos", NodeMaterialBlockConnectionPointTypes.Vector4, false, NodeMaterialBlockTargets.Vertex);
+        this.registerInput("worldPosition", NodeMaterialBlockConnectionPointTypes.Vector4, false, NodeMaterialBlockTargets.Vertex);
         this.registerInput("view", NodeMaterialBlockConnectionPointTypes.Matrix, false, NodeMaterialBlockTargets.Vertex);
 
         this.registerOutput("vFogDistance", NodeMaterialBlockConnectionPointTypes.Vector3, NodeMaterialBlockTargets.Vertex);
@@ -32,7 +32,7 @@ export class FogBlock extends NodeMaterialBlock {
         this.registerInput("color", NodeMaterialBlockConnectionPointTypes.Color3OrColor4, false, NodeMaterialBlockTargets.Fragment);
         this.registerInput("fogColor", NodeMaterialBlockConnectionPointTypes.Color3, false, NodeMaterialBlockTargets.Fragment);
         this.registerInput("fogParameters", NodeMaterialBlockConnectionPointTypes.Vector4, false, NodeMaterialBlockTargets.Fragment);
-        
+
         this.registerOutput("output", NodeMaterialBlockConnectionPointTypes.Color3, NodeMaterialBlockTargets.Fragment);
 
         // Auto configuration
@@ -51,15 +51,43 @@ export class FogBlock extends NodeMaterialBlock {
     }
 
     /**
+     * Gets the world position input component
+     */
+    public get worldPosition(): NodeMaterialConnectionPoint {
+        return this._inputs[0];
+    }
+
+    /**
+     * Gets the view input component
+     */
+    public get view(): NodeMaterialConnectionPoint {
+        return this._inputs[1];
+    }
+
+    /**
      * Gets the color input component
      */
     public get color(): NodeMaterialConnectionPoint {
         return this._inputs[2];
     }
 
+    /**
+     * Gets the fog color input component
+     */
+    public get fogColor(): NodeMaterialConnectionPoint {
+        return this._inputs[3];
+    }
+
+    /**
+     * Gets the for parameter input component
+     */
+    public get fogParameters(): NodeMaterialConnectionPoint {
+        return this._inputs[4];
+    }
+
     public prepareDefines(mesh: AbstractMesh, nodeMaterial: NodeMaterial, defines: MaterialDefines) {
         let scene = mesh.getScene();
-        defines["FOG"] = nodeMaterial.fogEnabled && MaterialHelper.GetFogState(mesh, scene)
+        defines["FOG"] = nodeMaterial.fogEnabled && MaterialHelper.GetFogState(mesh, scene);
     }
 
     public bind(effect: Effect, mesh?: Mesh) {
@@ -87,8 +115,8 @@ export class FogBlock extends NodeMaterialBlock {
 
             let tempFogVariablename = state._getFreeVariableName("fog");
             let color = this.color;
-            let fogColor = this._inputs[3];
-            let fogParameters = this._inputs[4];
+            let fogColor = this.fogColor;
+            let fogParameters = this.fogParameters;
             let output = this._outputs[1];
             let vFogDistance = this._outputs[0];
 
@@ -98,8 +126,8 @@ export class FogBlock extends NodeMaterialBlock {
             state.compilationString += `#else\r\n${this._declareOutput(output, state)} =  ${color.associatedVariableName}.rgb;\r\n`;
             state.compilationString += `#endif\r\n`;
         } else {
-            let worldPos = this._inputs[0];
-            let view = this._inputs[1];
+            let worldPos = this.worldPosition;
+            let view = this.view;
             let vFogDistance = this._outputs[0];
             state.compilationString += this._declareOutput(vFogDistance, state) + ` = (${view.associatedVariableName} * ${worldPos.associatedVariableName}).xyz;\r\n`;
         }

+ 9 - 3
src/Materials/Node/Blocks/Fragment/alphaTestBlock.ts

@@ -2,6 +2,7 @@ import { NodeMaterialBlock } from '../../nodeMaterialBlock';
 import { NodeMaterialBlockConnectionPointTypes } from '../../nodeMaterialBlockConnectionPointTypes';
 import { NodeMaterialBuildState } from '../../nodeMaterialBuildState';
 import { NodeMaterialBlockTargets } from '../../nodeMaterialBlockTargets';
+import { NodeMaterialConnectionPoint } from '../../nodeMaterialBlockConnectionPoint';
 
 /**
  * Block used to add an alpha test in the fragment shader
@@ -31,6 +32,13 @@ export class AlphaTestBlock extends NodeMaterialBlock {
         return "AlphaTestBlock";
     }
 
+    /**
+     * Gets the color input component
+     */
+    public get color(): NodeMaterialConnectionPoint {
+        return this._inputs[0];
+    }
+
     /** @hidden */
     public get _canAddAtVertexRoot(): boolean {
         return false;
@@ -44,11 +52,9 @@ export class AlphaTestBlock extends NodeMaterialBlock {
     protected _buildBlock(state: NodeMaterialBuildState) {
         super._buildBlock(state);
 
-        let input = this._inputs[0];
-
         state.sharedData.hints.needAlphaTesting = true;
 
-        state.compilationString += `if (${input.associatedVariableName}.a < ${this.alphaCutOff}) discard;\r\n`;
+        state.compilationString += `if (${this.color.associatedVariableName}.a < ${this.alphaCutOff}) discard;\r\n`;
 
         return this;
     }

+ 1 - 1
src/Materials/Node/Blocks/Fragment/fragmentOutputBlock.ts

@@ -29,7 +29,7 @@ export class FragmentOutputBlock extends NodeMaterialBlock {
     public getClassName() {
         return "FragmentOutputBlock";
     }
-        
+
     /**
      * Gets the color input component
      */

+ 1 - 1
src/Materials/Node/Blocks/Fragment/rgbMergerBlock.ts

@@ -42,7 +42,7 @@ export class RGBMergerBlock extends NodeMaterialBlock {
      */
     public get g(): NodeMaterialConnectionPoint {
         return this._inputs[1];
-    }    
+    }
 
     /**
      * Gets the B component input

+ 10 - 10
src/Materials/Node/Blocks/Fragment/rgbaMergerBlock.ts

@@ -2,7 +2,7 @@ import { NodeMaterialBlock } from '../../nodeMaterialBlock';
 import { NodeMaterialBlockConnectionPointTypes } from '../../nodeMaterialBlockConnectionPointTypes';
 import { NodeMaterialBuildState } from '../../nodeMaterialBuildState';
 import { NodeMaterialBlockTargets } from '../../nodeMaterialBlockTargets';
-import { NodeMaterialConnectionPoint } from 'Materials/Node/nodeMaterialBlockConnectionPoint';
+import { NodeMaterialConnectionPoint } from '../../nodeMaterialBlockConnectionPoint';
 
 /**
  * Block used to create a Color4 out of 4 inputs (one for each component)
@@ -33,39 +33,39 @@ export class RGBAMergerBlock extends NodeMaterialBlock {
     }
 
     /**
-     * Gets the R component input
+     * Gets the R input component
      */
     public get r(): NodeMaterialConnectionPoint {
         return this._inputs[0];
     }
 
     /**
-     * Gets the G component input
+     * Gets the G input component
      */
     public get g(): NodeMaterialConnectionPoint {
         return this._inputs[1];
-    }    
+    }
 
     /**
-     * Gets the B component input
+     * Gets the B input component
      */
     public get b(): NodeMaterialConnectionPoint {
         return this._inputs[2];
     }
 
     /**
-     * Gets the RGB component input
+     * Gets the RGB input component
      */
     public get rgb(): NodeMaterialConnectionPoint {
         return this._inputs[3];
-    }   
-    
+    }
+
     /**
-     * Gets the R component input
+     * Gets the R input component
      */
     public get a(): NodeMaterialConnectionPoint {
         return this._inputs[4];
-    }    
+    }
 
     protected _buildBlock(state: NodeMaterialBuildState) {
         super._buildBlock(state);

+ 37 - 1
src/Materials/Node/Blocks/Vertex/bonesBlock.ts

@@ -7,6 +7,7 @@ import { AbstractMesh } from '../../../../Meshes/abstractMesh';
 import { Mesh } from '../../../../Meshes/mesh';
 import { Effect, EffectFallbacks } from '../../../effect';
 import { MaterialHelper } from '../../../materialHelper';
+import { NodeMaterialConnectionPoint } from '../../nodeMaterialBlockConnectionPoint';
 
 /**
  * Block used to add support for vertex skinning (bones)
@@ -54,6 +55,41 @@ export class BonesBlock extends NodeMaterialBlock {
         return "BonesBlock";
     }
 
+    /**
+     * Gets the matrix indices input component
+     */
+    public get matricesIndices(): NodeMaterialConnectionPoint {
+        return this._inputs[0];
+    }    
+
+    /**
+     * Gets the matrix weights input component
+     */
+    public get matricesWeights(): NodeMaterialConnectionPoint {
+        return this._inputs[1];
+    } 
+    
+    /**
+     * Gets the extra matrix indices input component
+     */
+    public get matricesIndicesExtra(): NodeMaterialConnectionPoint {
+        return this._inputs[2];
+    } 
+    
+    /**
+     * Gets the extra matrix weights input component
+     */
+    public get matricesWeightsExtra(): NodeMaterialConnectionPoint {
+        return this._inputs[3];
+    }    
+    
+    /**
+     * Gets the world input component
+     */
+    public get world(): NodeMaterialConnectionPoint {
+        return this._inputs[4];
+    }      
+
     public provideFallbacks(mesh: AbstractMesh, fallbacks: EffectFallbacks) {
         if (mesh && mesh.useBones && mesh.computeBonesUsingShaders && mesh.skeleton) {
             fallbacks.addCPUSkinningFallback(0, mesh);
@@ -103,7 +139,7 @@ export class BonesBlock extends NodeMaterialBlock {
         });
 
         let output = this._outputs[0];
-        let worldInput = this._inputs[4];
+        let worldInput = this.world;
 
         state.compilationString += this._declareOutput(output, state) + ` = ${worldInput.associatedVariableName} * ${influenceVariablename};`;
         return this;

+ 3 - 3
src/Materials/Node/Blocks/Vertex/vertexOutputBlock.ts

@@ -26,11 +26,11 @@ export class VertexOutputBlock extends NodeMaterialBlock {
     public getClassName() {
         return "VertexOutputBlock";
     }
-    
+
     /**
      * Gets the vector input component
      */
-    public get input(): NodeMaterialConnectionPoint {
+    public get vector(): NodeMaterialConnectionPoint {
         return this._inputs[0];
     }
 
@@ -47,7 +47,7 @@ export class VertexOutputBlock extends NodeMaterialBlock {
     protected _buildBlock(state: NodeMaterialBuildState) {
         super._buildBlock(state);
 
-        let input = this.input;
+        let input = this.vector;
 
         state.compilationString += `gl_Position = ${input.associatedVariableName};\r\n`;
 

+ 18 - 6
src/Materials/Node/Blocks/addBlock.ts

@@ -1,6 +1,7 @@
 import { NodeMaterialBlock } from '../nodeMaterialBlock';
 import { NodeMaterialBlockConnectionPointTypes } from '../nodeMaterialBlockConnectionPointTypes';
 import { NodeMaterialBuildState } from '../nodeMaterialBuildState';
+import { NodeMaterialConnectionPoint } from '../nodeMaterialBlockConnectionPoint';
 /**
  * Block used to add 2 vector4
  */
@@ -12,8 +13,8 @@ export class AddBlock extends NodeMaterialBlock {
     public constructor(name: string) {
         super(name);
 
-        this.registerInput("vector0", NodeMaterialBlockConnectionPointTypes.Vector4OrColor4);
-        this.registerInput("vector1", NodeMaterialBlockConnectionPointTypes.Vector4OrColor4);
+        this.registerInput("left", NodeMaterialBlockConnectionPointTypes.Vector4OrColor4);
+        this.registerInput("right", NodeMaterialBlockConnectionPointTypes.Vector4OrColor4);
         this.registerOutput("output", NodeMaterialBlockConnectionPointTypes.Vector4OrColor4);
     }
 
@@ -25,15 +26,26 @@ export class AddBlock extends NodeMaterialBlock {
         return "AddBlock";
     }
 
+    /**
+     * Gets the left operand input component
+     */
+    public get left(): NodeMaterialConnectionPoint {
+        return this._inputs[0];
+    }
+
+    /**
+     * Gets the right operand input component
+     */
+    public get right(): NodeMaterialConnectionPoint {
+        return this._inputs[1];
+    }    
+
     protected _buildBlock(state: NodeMaterialBuildState) {
         super._buildBlock(state);
 
         let output = this._outputs[0];
 
-        let vector0 = this._inputs[0];
-        let vector1 = this._inputs[1];
-
-        state.compilationString += this._declareOutput(output, state) + ` = ${vector0.associatedVariableName} + ${vector1.associatedVariableName};\r\n`;
+        state.compilationString += this._declareOutput(output, state) + ` = ${this.left.associatedVariableName} + ${this.right.associatedVariableName};\r\n`;
 
         return this;
     }

+ 9 - 3
src/Materials/Node/Blocks/clampBlock.ts

@@ -1,6 +1,7 @@
 import { NodeMaterialBlock } from '../nodeMaterialBlock';
 import { NodeMaterialBlockConnectionPointTypes } from '../nodeMaterialBlockConnectionPointTypes';
 import { NodeMaterialBuildState } from '../nodeMaterialBuildState';
+import { NodeMaterialConnectionPoint } from '../nodeMaterialBlockConnectionPoint';
 /**
  * Block used to clamp a float
  */
@@ -30,14 +31,19 @@ export class ClampBlock extends NodeMaterialBlock {
         return "ClampBlock";
     }
 
+    /**
+     * Gets the value input component
+     */
+    public get value(): NodeMaterialConnectionPoint {
+        return this._inputs[0];
+    }
+
     protected _buildBlock(state: NodeMaterialBuildState) {
         super._buildBlock(state);
 
         let output = this._outputs[0];
 
-        let value = this._inputs[0];
-
-        state.compilationString += this._declareOutput(output, state) + ` = clamp(${value.associatedVariableName}, ${this._writeFloat(this.minimum)}, ${this._writeFloat(this.maximum)});\r\n`;
+        state.compilationString += this._declareOutput(output, state) + ` = clamp(${this.value.associatedVariableName}, ${this._writeFloat(this.minimum)}, ${this._writeFloat(this.maximum)});\r\n`;
 
         return this;
     }

+ 18 - 6
src/Materials/Node/Blocks/multiplyBlock.ts

@@ -1,6 +1,7 @@
 import { NodeMaterialBlock } from '../nodeMaterialBlock';
 import { NodeMaterialBlockConnectionPointTypes } from '../nodeMaterialBlockConnectionPointTypes';
 import { NodeMaterialBuildState } from '../nodeMaterialBuildState';
+import { NodeMaterialConnectionPoint } from '../nodeMaterialBlockConnectionPoint';
 /**
  * Block used to multiply 2 vector4
  */
@@ -12,8 +13,8 @@ export class MultiplyBlock extends NodeMaterialBlock {
     public constructor(name: string) {
         super(name);
 
-        this.registerInput("vector0", NodeMaterialBlockConnectionPointTypes.Vector4OrColor4);
-        this.registerInput("vector1", NodeMaterialBlockConnectionPointTypes.Vector4OrColor4);
+        this.registerInput("left", NodeMaterialBlockConnectionPointTypes.Vector4OrColor4);
+        this.registerInput("right", NodeMaterialBlockConnectionPointTypes.Vector4OrColor4);
         this.registerOutput("output", NodeMaterialBlockConnectionPointTypes.Vector4OrColor4);
     }
 
@@ -25,15 +26,26 @@ export class MultiplyBlock extends NodeMaterialBlock {
         return "MultiplyBlock";
     }
 
+    /**
+     * Gets the left operand input component
+     */
+    public get left(): NodeMaterialConnectionPoint {
+        return this._inputs[0];
+    }
+
+    /**
+     * Gets the right operand input component
+     */
+    public get right(): NodeMaterialConnectionPoint {
+        return this._inputs[1];
+    }      
+
     protected _buildBlock(state: NodeMaterialBuildState) {
         super._buildBlock(state);
 
         let output = this._outputs[0];
 
-        let vector0 = this._inputs[0];
-        let vector1 = this._inputs[1];
-
-        state.compilationString += this._declareOutput(output, state) + ` = ${vector0.associatedVariableName} * ${vector1.associatedVariableName};\r\n`;
+        state.compilationString += this._declareOutput(output, state) + ` = ${this.left.associatedVariableName} * ${this.right.associatedVariableName};\r\n`;
 
         return this;
     }

+ 17 - 2
src/Materials/Node/Blocks/textureBlock.ts

@@ -2,6 +2,7 @@ import { NodeMaterialBlock } from '../nodeMaterialBlock';
 import { NodeMaterialBlockConnectionPointTypes } from '../nodeMaterialBlockConnectionPointTypes';
 import { NodeMaterialBuildState } from '../nodeMaterialBuildState';
 import { NodeMaterialBlockTargets } from '../nodeMaterialBlockTargets';
+import { NodeMaterialConnectionPoint } from '../nodeMaterialBlockConnectionPoint';
 
 /**
  * Block used to read a texture from a sampler
@@ -28,11 +29,25 @@ export class TextureBlock extends NodeMaterialBlock {
         return "TextureBlock";
     }
 
+    /**
+     * Gets the uv input component
+     */
+    public get uv(): NodeMaterialConnectionPoint {
+        return this._inputs[0];
+    }
+
+    /**
+     * Gets the texture input component
+     */
+    public get texture(): NodeMaterialConnectionPoint {
+        return this._inputs[1];
+    }      
+
     protected _buildBlock(state: NodeMaterialBuildState) {
         super._buildBlock(state);
 
-        let uvInput = this._inputs[0];
-        let samplerInput = this._inputs[1];
+        let uvInput = this.uv;
+        let samplerInput = this.texture;
 
         let output = this._outputs[0];
 

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

@@ -41,7 +41,7 @@ export class Vector4TransformBlock extends NodeMaterialBlock {
      */
     public get transform(): NodeMaterialConnectionPoint {
         return this._inputs[1];
-    }    
+    }
 
     protected _buildBlock(state: NodeMaterialBuildState) {
         super._buildBlock(state);

+ 5 - 7
src/Materials/Node/nodeMaterial.ts

@@ -17,7 +17,6 @@ import { SubMesh } from '../../Meshes/subMesh';
 import { MaterialDefines } from '../../Materials/materialDefines';
 import { MaterialHelper } from '../../Materials/materialHelper';
 
-
 /** @hidden */
 export class NodeMaterialDefines extends MaterialDefines {
 
@@ -29,7 +28,6 @@ export class NodeMaterialDefines extends MaterialDefines {
     public BonesPerMesh = 0;
     public BONETEXTURE = false;
 
-
     constructor() {
         super();
         this.rebuild();
@@ -353,10 +351,10 @@ export class NodeMaterial extends PushMaterial {
         }
 
         // Shared defines
-        MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true, false, false);  
-        this._sharedData.blocksWithDefines.forEach(b => {
+        MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true, false, false);
+        this._sharedData.blocksWithDefines.forEach((b) => {
             b.prepareDefines(mesh, this, defines);
-        })
+        });
 
         // Need to recompile?
         if (defines.isDirty) {
@@ -385,9 +383,9 @@ export class NodeMaterial extends PushMaterial {
 
             var fallbacks = new EffectFallbacks();
 
-            this._sharedData.blocksWithFallbacks.forEach(b => {
+            this._sharedData.blocksWithFallbacks.forEach((b) => {
                 b.provideFallbacks(mesh, fallbacks);
-            })
+            });
 
             let previousEffect = subMesh.effect;
             // Compilation

+ 2 - 2
src/Materials/Node/nodeMaterialBlockConnectionPoint.ts

@@ -259,10 +259,10 @@ export class NodeMaterialConnectionPoint {
      * @param worldViewProjection defines the worldxviewxprojection matrix
      */
     public transmitWorld(effect: Effect, world: Matrix, worldView: Matrix, worldViewProjection: Matrix) {
-        if (!this._wellKnownValue) { 
+        if (!this._wellKnownValue) {
             return;
         }
-        
+
         let variableName = this.associatedVariableName;
         switch (this._wellKnownValue) {
             case NodeMaterialWellKnownValues.World:

+ 3 - 3
src/Materials/Node/nodeMaterialBuildState.ts

@@ -262,9 +262,9 @@ export class NodeMaterialBuildState {
                         hints.needWorldViewProjectionMatrix = true;
                         break;
                 }
-            } 
-        
-            this.sharedData.uniformConnectionPoints.push(point);                    
+            }
+
+            this.sharedData.uniformConnectionPoints.push(point);
 
             return;
         }