Browse Source

Moar nodes!!! #6012

David Catuhe 5 years ago
parent
commit
f2981cdd1c

+ 4 - 1
nodeEditor/src/blockTools.ts

@@ -46,6 +46,7 @@ import { PowBlock } from 'babylonjs/Materials/Node/Blocks/powBlock';
 import { Scene } from 'babylonjs/scene';
 import { RandomNumberBlock } from 'babylonjs/Materials/Node/Blocks/randomNumberBlock';
 import { ReplaceColorBlock } from 'babylonjs/Materials/Node/Blocks/replaceColorBlock';
+import { PosterizeBlock } from 'babylonjs/Materials/Node/Blocks/posterizeBlock';
 import { ArcTan2Block } from 'babylonjs/Materials/Node/Blocks/arcTan2Block';
 import { ReciprocalBlock } from 'babylonjs/Materials/Node/Blocks/reciprocalBlock';
 
@@ -141,7 +142,9 @@ export class BlockTools {
             case "RandomNumberBlock":                                          
                 return new RandomNumberBlock("Random number");         
             case "ReplaceColorBlock":                                          
-                return new ReplaceColorBlock("Replace color");                             
+                return new ReplaceColorBlock("Replace color");      
+            case "PosterizeBlock":                                          
+                return new PosterizeBlock("Posterize");                              
             case "ArcTan2Block":                                          
                 return new ArcTan2Block("ArcTan2");          
             case "CosBlock": {

+ 1 - 1
nodeEditor/src/components/nodeList/nodeListComponent.tsx

@@ -27,7 +27,7 @@ export class NodeListComponent extends React.Component<INodeListComponentProps,
         const allBlocks = {
             Animation: ["BonesBlock", "MorphTargetsBlock"],
             Basic_Math: ["AddBlock",  "DivideBlock", "MultiplyBlock", "ScaleBlock", "SubtractBlock", "OneMinusBlock", "MaxBlock", "MinBlock", "LengthBlock", "DistanceBlock", "NegateBlock", "RandomNumberBlock", "ReciprocalBlock"],
-            Color_Management: ["ReplaceColorBlock"],
+            Color_Management: ["ReplaceColorBlock", "PosterizeBlock"],
             Conversion_Blocks: ["ColorMergerBlock", "ColorSplitterBlock", "VectorMergerBlock", "VectorSplitterBlock"],
             Inputs: ["Float", "Vector2", "Vector3", "Vector4", "Color3", "Color4", "TextureBlock", "TimeBlock", "DeltaTimeBlock"],
             Interpolation: ["LerpBlock", "SmoothStepBlock"],

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

@@ -33,4 +33,5 @@ export * from "./randomNumberBlock";
 export * from "./arcTan2Block";
 export * from "./smoothStepBlock";
 export * from "./reciprocalBlock";
-export * from "./replaceColorBlock";
+export * from "./replaceColorBlock";
+export * from "./posterizeBlock";

+ 70 - 0
src/Materials/Node/Blocks/posterizeBlock.ts

@@ -0,0 +1,70 @@
+import { NodeMaterialBlock } from '../nodeMaterialBlock';
+import { NodeMaterialBlockConnectionPointTypes } from '../Enums/nodeMaterialBlockConnectionPointTypes';
+import { NodeMaterialBuildState } from '../nodeMaterialBuildState';
+import { NodeMaterialConnectionPoint } from '../nodeMaterialBlockConnectionPoint';
+import { NodeMaterialBlockTargets } from '../Enums/nodeMaterialBlockTargets';
+import { _TypeStore } from '../../../Misc/typeStore';
+
+/**
+ * Block used to posterize a value
+ * @see https://en.wikipedia.org/wiki/Posterization
+ */
+export class PosterizeBlock extends NodeMaterialBlock {
+    /**
+     * Creates a new PosterizeBlock
+     * @param name defines the block name
+     */
+    public constructor(name: string) {
+        super(name, NodeMaterialBlockTargets.Neutral);
+
+        this.registerInput("value", NodeMaterialBlockConnectionPointTypes.AutoDetect);
+        this.registerInput("steps", NodeMaterialBlockConnectionPointTypes.AutoDetect);
+        this.registerOutput("output", NodeMaterialBlockConnectionPointTypes.BasedOnInput);
+
+        this._outputs[0]._typeConnectionSource = this._inputs[0];
+        this._linkConnectionTypes(0, 1);
+
+        this._inputs[0].excludedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Matrix);
+        this._inputs[1].excludedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Matrix);
+    }
+
+    /**
+     * Gets the current class name
+     * @returns the class name
+     */
+    public getClassName() {
+        return "PosterizeBlock";
+    }
+
+    /**
+     * Gets the value input component
+     */
+    public get value(): NodeMaterialConnectionPoint {
+        return this._inputs[0];
+    }
+
+    /**
+     * Gets the steps input component
+     */
+    public get steps(): NodeMaterialConnectionPoint {
+        return this._inputs[1];
+    }
+
+    /**
+     * Gets the output component
+     */
+    public get output(): NodeMaterialConnectionPoint {
+        return this._outputs[0];
+    }
+
+    protected _buildBlock(state: NodeMaterialBuildState) {
+        super._buildBlock(state);
+
+        let output = this._outputs[0];
+
+        state.compilationString += this._declareOutput(output, state) + ` = floor(${this.value.associatedVariableName} / (1.0 / ${this.steps.associatedVariableName})) * (1.0 / ${this.steps.associatedVariableName});\r\n`;
+        return this;
+    }
+}
+
+_TypeStore.RegisteredTypes["BABYLON.PosterizeBlock"] = PosterizeBlock;