Explorar o código

Merge pull request #9198 from Popov72/master

NME: Fix bug when changing the types of the lerp/nlerp inputs
David Catuhe %!s(int64=4) %!d(string=hai) anos
pai
achega
c27a825fb6

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

@@ -22,7 +22,7 @@ export class LerpBlock extends NodeMaterialBlock {
 
         this._outputs[0]._typeConnectionSource = this._inputs[0];
         this._linkConnectionTypes(0, 1);
-        this._linkConnectionTypes(1, 2);
+        this._linkConnectionTypes(1, 2, true);
 
         this._inputs[2].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Float);
     }

+ 4 - 1
src/Materials/Node/Blocks/nLerpBlock.ts

@@ -17,11 +17,14 @@ export class NLerpBlock extends NodeMaterialBlock {
 
         this.registerInput("left", NodeMaterialBlockConnectionPointTypes.AutoDetect);
         this.registerInput("right", NodeMaterialBlockConnectionPointTypes.AutoDetect);
-        this.registerInput("gradient", NodeMaterialBlockConnectionPointTypes.Float);
+        this.registerInput("gradient", NodeMaterialBlockConnectionPointTypes.AutoDetect);
         this.registerOutput("output", NodeMaterialBlockConnectionPointTypes.BasedOnInput);
 
         this._outputs[0]._typeConnectionSource = this._inputs[0];
         this._linkConnectionTypes(0, 1);
+        this._linkConnectionTypes(1, 2, true);
+
+        this._inputs[2].acceptedConnectionPointTypes.push(NodeMaterialBlockConnectionPointTypes.Float);
     }
 
     /**

+ 6 - 2
src/Materials/Node/nodeMaterialBlock.ts

@@ -425,8 +425,12 @@ export class NodeMaterialBlock {
         return true;
     }
 
-    protected _linkConnectionTypes(inputIndex0: number, inputIndex1: number) {
-        this._inputs[inputIndex0]._linkedConnectionSource = this._inputs[inputIndex1];
+    protected _linkConnectionTypes(inputIndex0: number, inputIndex1: number, looseCoupling = false) {
+        if (looseCoupling) {
+            this._inputs[inputIndex1]._acceptedConnectionPointType = this._inputs[inputIndex0];
+        } else {
+            this._inputs[inputIndex0]._linkedConnectionSource = this._inputs[inputIndex1];
+        }
         this._inputs[inputIndex1]._linkedConnectionSource = this._inputs[inputIndex0];
     }
 

+ 46 - 26
src/Materials/Node/nodeMaterialBlockConnectionPoint.ts

@@ -32,6 +32,44 @@ export enum NodeMaterialConnectionPointDirection {
  * Defines a connection point for a block
  */
 export class NodeMaterialConnectionPoint {
+
+    /**
+     * Checks if two types are equivalent
+     * @param type1 type 1 to check
+     * @param type2 type 2 to check
+     * @returns true if both types are equivalent, else false
+     */
+    public static AreEquivalentTypes(type1: number, type2: number): boolean {
+        switch (type1) {
+            case NodeMaterialBlockConnectionPointTypes.Vector3: {
+                if (type2 === NodeMaterialBlockConnectionPointTypes.Color3) {
+                    return true;
+                }
+                break;
+            }
+            case NodeMaterialBlockConnectionPointTypes.Vector4: {
+                if (type2 === NodeMaterialBlockConnectionPointTypes.Color4) {
+                    return true;
+                }
+                break;
+            }
+            case NodeMaterialBlockConnectionPointTypes.Color3: {
+                if (type2 === NodeMaterialBlockConnectionPointTypes.Vector3) {
+                    return true;
+                }
+                break;
+            }
+            case NodeMaterialBlockConnectionPointTypes.Color4: {
+                if (type2 === NodeMaterialBlockConnectionPointTypes.Vector4) {
+                    return true;
+                }
+                break;
+            }
+        }
+
+        return false;
+    }
+
     /** @hidden */
     public _ownerBlock: NodeMaterialBlock;
     /** @hidden */
@@ -47,6 +85,9 @@ export class NodeMaterialConnectionPoint {
     /** @hidden */
     public _linkedConnectionSource: Nullable<NodeMaterialConnectionPoint> = null;
 
+    /** @hidden */
+    public _acceptedConnectionPointType: Nullable<NodeMaterialConnectionPoint> = null;
+
     private _type = NodeMaterialBlockConnectionPointTypes.Float;
 
     /** @hidden */
@@ -367,35 +408,14 @@ export class NodeMaterialConnectionPoint {
 
         if (this.type !== connectionPoint.type && connectionPoint.innerType !== NodeMaterialBlockConnectionPointTypes.AutoDetect) {
             // Equivalents
-            switch (this.type) {
-                case NodeMaterialBlockConnectionPointTypes.Vector3: {
-                    if (connectionPoint.type === NodeMaterialBlockConnectionPointTypes.Color3) {
-                        return NodeMaterialConnectionPointCompatibilityStates.Compatible;
-                    }
-                    break;
-                }
-                case NodeMaterialBlockConnectionPointTypes.Vector4: {
-                    if (connectionPoint.type === NodeMaterialBlockConnectionPointTypes.Color4) {
-                        return NodeMaterialConnectionPointCompatibilityStates.Compatible;
-                    }
-                    break;
-                }
-                case NodeMaterialBlockConnectionPointTypes.Color3: {
-                    if (connectionPoint.type === NodeMaterialBlockConnectionPointTypes.Vector3) {
-                        return NodeMaterialConnectionPointCompatibilityStates.Compatible;
-                    }
-                    break;
-                }
-                case NodeMaterialBlockConnectionPointTypes.Color4: {
-                    if (connectionPoint.type === NodeMaterialBlockConnectionPointTypes.Vector4) {
-                        return NodeMaterialConnectionPointCompatibilityStates.Compatible;
-                    }
-                    break;
-                }
+            if (NodeMaterialConnectionPoint.AreEquivalentTypes(this.type, connectionPoint.type)) {
+                return NodeMaterialConnectionPointCompatibilityStates.Compatible;
             }
 
             // Accepted types
-            if (connectionPoint.acceptedConnectionPointTypes && connectionPoint.acceptedConnectionPointTypes.indexOf(this.type) !== -1) {
+            if (connectionPoint.acceptedConnectionPointTypes && connectionPoint.acceptedConnectionPointTypes.indexOf(this.type) !== -1 ||
+                connectionPoint._acceptedConnectionPointType && NodeMaterialConnectionPoint.AreEquivalentTypes(connectionPoint._acceptedConnectionPointType.type, this.type))
+            {
                 return NodeMaterialConnectionPointCompatibilityStates.Compatible;
             } else {
                 return NodeMaterialConnectionPointCompatibilityStates.TypeIncompatible;