فهرست منبع

Fix some nme issues

David Catuhe 5 سال پیش
والد
کامیت
62642c109c

+ 3 - 3
inspector/src/components/actionTabs/tabs/propertyGrids/materials/nodeMaterialPropertyGridComponent.tsx

@@ -56,7 +56,7 @@ export class NodeMaterialPropertyGridComponent extends React.Component<INodeMate
                     textureBlocks.map((textureBlock, i) => {
                         return (
                             <TextureLinkLineComponent label={textureBlock.name} 
-                                key={i} 
+                                key={"nodematText" + i} 
                                 texture={textureBlock.texture} 
                                 material={material} 
                                 onTextureCreated={texture => textureBlock.texture = texture}
@@ -147,9 +147,9 @@ export class NodeMaterialPropertyGridComponent extends React.Component<INodeMate
                     }           
                 </LineContainerComponent>
                 {
-                    namedGroups.map(name => {
+                    namedGroups.map((name, i) => {
                         return (
-                            <LineContainerComponent globalState={this.props.globalState} title={name.toUpperCase()}>
+                            <LineContainerComponent key={"inputValue" + i} globalState={this.props.globalState} title={name.toUpperCase()}>
                             {
                                 configurableInputBlocks.filter(block => block.groupInInspector === name).map(block => {
                                     return this.renderInputBlock(block);

+ 28 - 9
nodeEditor/src/diagram/properties/inputNodePropertyComponent.tsx

@@ -18,6 +18,7 @@ import { IPropertyComponentProps } from './propertyComponentProps';
 import { InputBlock } from 'babylonjs/Materials/Node/Blocks/Input/inputBlock';
 import { GenericPropertyTabComponent } from './genericNodePropertyComponent';
 import { TextInputLineComponent } from '../../sharedComponents/textInputLineComponent';
+import { CheckBoxLineComponent } from '../../sharedComponents/checkBoxLineComponent';
 
 export class InputPropertyTabComponent extends React.Component<IPropertyComponentProps> {
     constructor(props: IPropertyComponentProps) {
@@ -28,22 +29,40 @@ export class InputPropertyTabComponent extends React.Component<IPropertyComponen
         let inputBlock = this.props.block as InputBlock;
         switch (inputBlock.type) {
             case NodeMaterialBlockConnectionPointTypes.Float: {
-                let cantDisplaySlider = (isNaN(inputBlock.min) || isNaN(inputBlock.max) || inputBlock.min === inputBlock.max);
+                let cantDisplaySlider = (isNaN(inputBlock.min) || isNaN(inputBlock.max) || inputBlock.min === inputBlock.max);            
                 return (
                     <>
-                        <FloatLineComponent label="Min" target={inputBlock} propertyName="min" onChange={() => {
+                        <CheckBoxLineComponent label="Is boolean" target={inputBlock} propertyName="isBoolean" onValueChanged={() => {
                             this.forceUpdate();
-                        }}></FloatLineComponent>
-                        <FloatLineComponent label="Max" target={inputBlock} propertyName="max" onChange={() => {
-                            this.forceUpdate();
-                        }}></FloatLineComponent>      
-
+                        }}/>
+                        {
+                            inputBlock.isBoolean &&
+                            <CheckBoxLineComponent label="Value" isSelected={() => {
+                                return inputBlock.value === 1
+                            }} onSelect={(value) => {
+                                inputBlock.value = value ? 1 : 0;
+                                this.props.globalState.onUpdateRequiredObservable.notifyObservers();
+                                this.forceUpdate();
+                            }}/>
+                        }
+                        {
+                            !inputBlock.isBoolean &&
+                            <FloatLineComponent label="Min" target={inputBlock} propertyName="min" onChange={() => {
+                                this.forceUpdate();
+                            }}></FloatLineComponent>
+                        }
+                        {
+                            !inputBlock.isBoolean &&
+                            <FloatLineComponent label="Max" target={inputBlock} propertyName="max" onChange={() => {
+                                    this.forceUpdate();
+                                }}></FloatLineComponent>      
+                        }
                         {
-                            cantDisplaySlider &&
+                            !inputBlock.isBoolean && cantDisplaySlider &&
                             <FloatPropertyTabComponent globalState={globalState} inputBlock={inputBlock} />
                         }        
                         {
-                            !cantDisplaySlider &&
+                            !inputBlock.isBoolean && !cantDisplaySlider &&
                             <SliderLineComponent label="Value" target={inputBlock} propertyName="value" step={(inputBlock.max - inputBlock.min) / 100.0} minimum={inputBlock.min} maximum={inputBlock.max} onChange={() => {
                                 this.props.globalState.onUpdateRequiredObservable.notifyObservers();
                             }}/>

+ 16 - 0
src/Materials/Node/Blocks/Input/inputBlock.ts

@@ -30,6 +30,9 @@ export class InputBlock extends NodeMaterialBlock {
     /** Gets or set a value used to limit the range of float values */
     public max: number = 0;
 
+    /** Gets or set a value indicating that this input can only get 0 and 1 values */
+    public isBoolean: boolean = false;
+
     /** Gets or sets a value used by the Node Material editor to determine how to configure the current value if it is a matrix */
     public matrixMode: number = 0;
 
@@ -181,6 +184,16 @@ export class InputBlock extends NodeMaterialBlock {
     }
 
     public set value(value: any) {
+        if (this.type === NodeMaterialBlockConnectionPointTypes.Float) {
+            if (this.isBoolean) {
+                value = value ? 1 : 0;
+            }
+            else if (this.min !== this.max) {
+                value = Math.max(this.min, value);
+                value = Math.min(this.max, value);
+            }
+        }
+
         this._storedValue = value;
         this._mode = NodeMaterialBlockConnectionPointMode.Uniform;
     }
@@ -557,6 +570,7 @@ export class InputBlock extends NodeMaterialBlock {
 
                     returnValue += `${variableName}.min = ${this.min};\r\n`;
                     returnValue += `${variableName}.max = ${this.max};\r\n`;
+                    returnValue += `${variableName}.isBoolean = ${this.isBoolean};\r\n`;
                     returnValue += `${variableName}.matrixMode = ${this.matrixMode};\r\n`;
                     returnValue += `${variableName}.animationType  = BABYLON.AnimatedInputBlockTypes.${AnimatedInputBlockTypes[this.animationType]};\r\n`;
 
@@ -596,6 +610,7 @@ export class InputBlock extends NodeMaterialBlock {
         serializationObject.visibleInInspector = this.visibleInInspector;
         serializationObject.min = this.min;
         serializationObject.max = this.max;
+        serializationObject.isBoolean = this.isBoolean;
         serializationObject.matrixMode = this.matrixMode;
         serializationObject.isConstant = this.isConstant;
         serializationObject.groupInInspector = this.groupInInspector;
@@ -623,6 +638,7 @@ export class InputBlock extends NodeMaterialBlock {
         this.visibleInInspector = serializationObject.visibleInInspector;
         this.min = serializationObject.min || 0;
         this.max = serializationObject.max || 0;
+        this.isBoolean = !!serializationObject.isBoolean;
         this.matrixMode = serializationObject.matrixMode || 0;
         this.isConstant = !!serializationObject.isConstant;
         this.groupInInspector = serializationObject.groupInInspector || "";

+ 0 - 4
src/Materials/Node/nodeMaterial.ts

@@ -656,10 +656,6 @@ export class NodeMaterial extends PushMaterial {
     }
 
     private _prepareDefinesForAttributes(mesh: AbstractMesh, defines: NodeMaterialDefines) {
-        if (!defines._areAttributesDirty) {
-            return;
-        }
-
         defines["NORMAL"] = mesh.isVerticesDataPresent(VertexBuffer.NormalKind);
 
         defines["TANGENT"] = mesh.isVerticesDataPresent(VertexBuffer.TangentKind);