瀏覽代碼

fixes

Made changes to fix the properites and make this more dynamic
Pryme8 5 年之前
父節點
當前提交
a1e16888be

+ 1 - 1
nodeEditor/src/blockTools.ts

@@ -59,7 +59,7 @@ import { WorleyNoise3DBlock } from 'babylonjs/Materials/Node/Blocks/worleyNoise3
 export class BlockTools {
     public static GetBlockFromString(data: string, scene: Scene, nodeMaterial: NodeMaterial) {
         switch (data) {
-            case "Worley3DBlock":
+            case "WorleyNoise3DBlock":
                 return new WorleyNoise3DBlock("WorleyNoise3DBlock");
             case "BonesBlock":
                 return new BonesBlock("Bones");

+ 7 - 1
nodeEditor/src/components/diagram/generic/genericNodeModel.tsx

@@ -71,7 +71,13 @@ export class GenericNodeModel extends DefaultNodeModel {
                     <CheckBoxLineComponent label="Invert X axis" target={this.block} propertyName="invertX" onValueChanged={() => globalState.onRebuildRequiredObservable.notifyObservers()} />
                     <CheckBoxLineComponent label="Invert Y axis" target={this.block} propertyName="invertY" onValueChanged={() => globalState.onRebuildRequiredObservable.notifyObservers()}/>                    
                 </LineContainerComponent>
-            }               
+            }
+            {
+                this.block!.getClassName() === "WorleyNoise3DBlock" &&
+                <LineContainerComponent title="PROPERTIES">
+                    <CheckBoxLineComponent label="Use Manhattan Distance" target={this.block} propertyName="manhattanDistance" onValueChanged={() => globalState.onRebuildRequiredObservable.notifyObservers()} />              
+                </LineContainerComponent>
+            }
             </div>
         );
     }

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

@@ -33,7 +33,7 @@ export class NodeListComponent extends React.Component<INodeListComponentProps,
             Interpolation: ["LerpBlock", "SmoothStepBlock", "NLerpBlock"],
             Matrices: ["Matrix", "WorldMatrixBlock", "WorldViewMatrixBlock", "WorldViewProjectionMatrixBlock", "ViewMatrixBlock", "ViewProjectionMatrixBlock", "ProjectionMatrixBlock"],
             Mesh: ["InstancesBlock", "PositionBlock", "UVBlock", "ColorBlock", "NormalBlock", "TangentBlock", "MatrixIndicesBlock", "MatrixWeightsBlock", "WorldPositionBlock", "WorldNormalBlock", "FrontFacingBlock"], 
-            Noises: ["Worley3DBlock"],
+            Noises: ["WorleyNoise3DBlock"],
             Output_Blocks: ["VertexOutputBlock", "FragmentOutputBlock", "DiscardBlock"],
             Range: ["ClampBlock", "RemapBlock", "NormalizeBlock"],
             Round: ["StepBlock", "RoundBlock", "CeilingBlock", "FloorBlock"],

+ 33 - 12
src/Materials/Node/Blocks/worleyNoise3DBlock.ts

@@ -4,6 +4,8 @@ import { NodeMaterialBuildState } from '../nodeMaterialBuildState';
 import { NodeMaterialConnectionPoint } from '../nodeMaterialBlockConnectionPoint';
 import { NodeMaterialBlockTargets } from '../Enums/nodeMaterialBlockTargets';
 import { _TypeStore } from '../../../Misc/typeStore';
+import { Scene } from '../../../scene';
+
 /**
  * block used to Generate a Worley Noise 3D Noise Pattern
  */
@@ -15,6 +17,9 @@ import { _TypeStore } from '../../../Misc/typeStore';
 //  Return vec2 value range of -1.0->1.0, F1-F2 respectivly
 
 export class WorleyNoise3DBlock extends NodeMaterialBlock {
+    /** Gets or sets a boolean indicating that normal should be inverted on X axis */
+    public manhattanDistance = false;
+
     /**
      * Creates a new WorleyNoise3DBlock
      * @param name defines the block name
@@ -23,7 +28,7 @@ export class WorleyNoise3DBlock extends NodeMaterialBlock {
         super(name, NodeMaterialBlockTargets.Neutral);
         this.registerInput("position", NodeMaterialBlockConnectionPointTypes.Vector3);
         this.registerInput("jitter", NodeMaterialBlockConnectionPointTypes.Float);
-        this.registerInput("manhattan", NodeMaterialBlockConnectionPointTypes.Float);
+
         this.registerOutput("output", NodeMaterialBlockConnectionPointTypes.Vector2);
     }
 
@@ -50,16 +55,6 @@ export class WorleyNoise3DBlock extends NodeMaterialBlock {
     }
 
     /**
-    * Gets true false value of if it is manhattan or not
-    */
-    public get manhattan(): Boolean {
-        if (!this._inputs[2].isConnected) {
-            return false;
-        }
-        return true;
-    }
-
-    /**
      * Gets the output component
      */
     public get output(): NodeMaterialConnectionPoint {
@@ -230,10 +225,36 @@ export class WorleyNoise3DBlock extends NodeMaterialBlock {
         functionString += `}\r\n\r\n`;
 
         state._emitFunction('worley3D', functionString, 'worley3D');
-        state.compilationString += this._declareOutput(this._outputs[0], state) + ` = worley(${this.position.associatedVariableName}, ${this.jitter.associatedVariableName}, ${this.manhattan});\r\n`;
+        state.compilationString += this._declareOutput(this._outputs[0], state) + ` = worley(${this.position.associatedVariableName}, ${this.jitter.associatedVariableName}, ${this.manhattanDistance});\r\n`;
 
         return this;
     }
+    /**
+     * Exposes the properties to the UI?
+     */
+    protected _dumpPropertiesCode() {
+        var codeString = `${this._codeVariableName}.manhattanDistance = ${this.manhattanDistance};\r\n`;
+
+        return codeString;
+    }
+    /**
+     * Exposes the properties to the Seralize?
+     */
+    public serialize(): any {
+        let serializationObject = super.serialize();
+
+        serializationObject.manhattanDistance = this.manhattanDistance;
+
+        return serializationObject;
+    }
+    /**
+     * Exposes the properties to the deseralize?
+     */
+    public _deserialize(serializationObject: any, scene: Scene, rootUrl: string) {
+        super._deserialize(serializationObject, scene, rootUrl);
+
+        this.manhattanDistance = serializationObject.manhattanDistance;
+    }
 }
 
 _TypeStore.RegisteredTypes["BABYLON.WorleyNoise3DBlock"] = WorleyNoise3DBlock;