|
@@ -1,11 +1,7 @@
|
|
import { NodeMaterialBlockConnectionPointTypes } from './nodeMaterialBlockConnectionPointTypes';
|
|
import { NodeMaterialBlockConnectionPointTypes } from './nodeMaterialBlockConnectionPointTypes';
|
|
import { NodeMaterialBlockTargets } from './nodeMaterialBlockTargets';
|
|
import { NodeMaterialBlockTargets } from './nodeMaterialBlockTargets';
|
|
import { Nullable } from '../../types';
|
|
import { Nullable } from '../../types';
|
|
-import { Effect } from '../effect';
|
|
|
|
-import { NodeMaterialWellKnownValues } from './nodeMaterialWellKnownValues';
|
|
|
|
-import { Scene } from '../../scene';
|
|
|
|
-import { Matrix } from '../../Maths/math';
|
|
|
|
-import { NodeMaterialBlockConnectionPointMode } from './NodeMaterialBlockConnectionPointMode';
|
|
|
|
|
|
+import { InputBlock } from './Blocks/Input/inputBlock';
|
|
|
|
|
|
declare type NodeMaterialBlock = import("./nodeMaterialBlock").NodeMaterialBlock;
|
|
declare type NodeMaterialBlock = import("./nodeMaterialBlock").NodeMaterialBlock;
|
|
|
|
|
|
@@ -16,15 +12,10 @@ export class NodeMaterialConnectionPoint {
|
|
/** @hidden */
|
|
/** @hidden */
|
|
public _ownerBlock: NodeMaterialBlock;
|
|
public _ownerBlock: NodeMaterialBlock;
|
|
/** @hidden */
|
|
/** @hidden */
|
|
- public _connectedPoint: Nullable<NodeMaterialConnectionPoint>;
|
|
|
|
- private _associatedVariableName: string;
|
|
|
|
- private _endpoints = new Array<NodeMaterialConnectionPoint>();
|
|
|
|
- private _storedValue: any;
|
|
|
|
- private _valueCallback: () => any;
|
|
|
|
- private _mode = NodeMaterialBlockConnectionPointMode.Undefined;
|
|
|
|
|
|
+ public _connectedPoint: Nullable<NodeMaterialConnectionPoint> = null;
|
|
|
|
|
|
- /** @hidden */
|
|
|
|
- public _wellKnownValue: Nullable<NodeMaterialWellKnownValues> = null;
|
|
|
|
|
|
+ private _endpoints = new Array<NodeMaterialConnectionPoint>();
|
|
|
|
+ private _associatedVariableName: string;
|
|
|
|
|
|
/** @hidden */
|
|
/** @hidden */
|
|
public _typeConnectionSource: Nullable<NodeMaterialConnectionPoint> = null;
|
|
public _typeConnectionSource: Nullable<NodeMaterialConnectionPoint> = null;
|
|
@@ -32,36 +23,38 @@ export class NodeMaterialConnectionPoint {
|
|
/** @hidden */
|
|
/** @hidden */
|
|
public _needToEmitVarying = true;
|
|
public _needToEmitVarying = true;
|
|
|
|
|
|
- /** @hidden */
|
|
|
|
- public _forceUniformInVertexShaderOnly = false;
|
|
|
|
-
|
|
|
|
private _type = NodeMaterialBlockConnectionPointTypes.Float;
|
|
private _type = NodeMaterialBlockConnectionPointTypes.Float;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Gets or sets the associated variable name in the shader
|
|
|
|
+ */
|
|
|
|
+ public get associatedVariableName(): string {
|
|
|
|
+ if (this._ownerBlock.isInput) {
|
|
|
|
+ return (this._ownerBlock as InputBlock).associatedVariableName;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (this._connectedPoint) {
|
|
|
|
+ return this._connectedPoint.associatedVariableName;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return this._associatedVariableName;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public set associatedVariableName(value: string) {
|
|
|
|
+ this._associatedVariableName = value;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Gets or sets the connection point type (default is float)
|
|
* Gets or sets the connection point type (default is float)
|
|
*/
|
|
*/
|
|
public get type(): NodeMaterialBlockConnectionPointTypes {
|
|
public get type(): NodeMaterialBlockConnectionPointTypes {
|
|
if (this._type === NodeMaterialBlockConnectionPointTypes.AutoDetect) {
|
|
if (this._type === NodeMaterialBlockConnectionPointTypes.AutoDetect) {
|
|
- if (this._connectedPoint) {
|
|
|
|
- return this._connectedPoint.type;
|
|
|
|
|
|
+ if (this._ownerBlock.isInput) {
|
|
|
|
+ return (this._ownerBlock as InputBlock).type;
|
|
}
|
|
}
|
|
|
|
|
|
- if (this.isUniform && this.value != null) {
|
|
|
|
- if (!isNaN(this.value)) {
|
|
|
|
- return NodeMaterialBlockConnectionPointTypes.Float;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- switch (this.value.getClassName()) {
|
|
|
|
- case "Vector2":
|
|
|
|
- return NodeMaterialBlockConnectionPointTypes.Vector2;
|
|
|
|
- case "Vector3":
|
|
|
|
- return NodeMaterialBlockConnectionPointTypes.Vector3;
|
|
|
|
- case "Vector4":
|
|
|
|
- return NodeMaterialBlockConnectionPointTypes.Vector4;
|
|
|
|
- case "Color3":
|
|
|
|
- return NodeMaterialBlockConnectionPointTypes.Color3;
|
|
|
|
- case "Color4":
|
|
|
|
- return NodeMaterialBlockConnectionPointTypes.Color4;
|
|
|
|
- }
|
|
|
|
|
|
+ if (this._connectedPoint) {
|
|
|
|
+ return this._connectedPoint.type;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -100,92 +93,28 @@ export class NodeMaterialConnectionPoint {
|
|
public target: NodeMaterialBlockTargets = NodeMaterialBlockTargets.VertexAndFragment;
|
|
public target: NodeMaterialBlockTargets = NodeMaterialBlockTargets.VertexAndFragment;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Gets or sets the value of that point.
|
|
|
|
- * Please note that this value will be ignored if valueCallback is defined
|
|
|
|
|
|
+ * Gets a boolean indicating that the current point is connected
|
|
*/
|
|
*/
|
|
- public get value(): any {
|
|
|
|
- return this._storedValue;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public set value(value: any) {
|
|
|
|
- this._storedValue = value;
|
|
|
|
- this._mode = NodeMaterialBlockConnectionPointMode.Uniform;
|
|
|
|
|
|
+ public get isConnected(): boolean {
|
|
|
|
+ return this.connectedPoint !== null;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Gets or sets a callback used to get the value of that point.
|
|
|
|
- * Please note that setting this value will force the connection point to ignore the value property
|
|
|
|
|
|
+ * Gets a boolean indicating that the current point is connected to an input block
|
|
*/
|
|
*/
|
|
- public get valueCallback(): () => any {
|
|
|
|
- return this._valueCallback;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public set valueCallback(value: () => any) {
|
|
|
|
- this._valueCallback = value;
|
|
|
|
- this._mode = NodeMaterialBlockConnectionPointMode.Uniform;
|
|
|
|
|
|
+ public get isConnectedToInput(): boolean {
|
|
|
|
+ return this.connectedPoint !== null && this.connectedPoint.ownerBlock.isInput;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Gets or sets the associated variable name in the shader
|
|
|
|
|
|
+ * Gets a the connected input block (if any)
|
|
*/
|
|
*/
|
|
- public get associatedVariableName(): string {
|
|
|
|
- if (!this._associatedVariableName && this._connectedPoint) {
|
|
|
|
- return this._connectedPoint.associatedVariableName;
|
|
|
|
|
|
+ public get connectInputBlock(): Nullable<InputBlock> {
|
|
|
|
+ if (!this.isConnectedToInput) {
|
|
|
|
+ return null;
|
|
}
|
|
}
|
|
|
|
|
|
- return this._associatedVariableName;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public set associatedVariableName(value: string) {
|
|
|
|
- this._associatedVariableName = value;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Gets a boolean indicating that this connection point not defined yet
|
|
|
|
- */
|
|
|
|
- public get isUndefined(): boolean {
|
|
|
|
- return this._mode === NodeMaterialBlockConnectionPointMode.Undefined;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Gets or sets a boolean indicating that this connection point is coming from an uniform.
|
|
|
|
- * In this case the connection point name must be the name of the uniform to use.
|
|
|
|
- * Can only be set on inputs
|
|
|
|
- */
|
|
|
|
- public get isUniform(): boolean {
|
|
|
|
- return this._mode === NodeMaterialBlockConnectionPointMode.Uniform;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public set isUniform(value: boolean) {
|
|
|
|
- this._mode = value ? NodeMaterialBlockConnectionPointMode.Uniform : NodeMaterialBlockConnectionPointMode.Undefined;
|
|
|
|
- this.associatedVariableName = "";
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Gets or sets a boolean indicating that this connection point is coming from an attribute.
|
|
|
|
- * In this case the connection point name must be the name of the attribute to use
|
|
|
|
- * Can only be set on inputs
|
|
|
|
- */
|
|
|
|
- public get isAttribute(): boolean {
|
|
|
|
- return this._mode === NodeMaterialBlockConnectionPointMode.Attribute;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public set isAttribute(value: boolean) {
|
|
|
|
- this._mode = value ? NodeMaterialBlockConnectionPointMode.Attribute : NodeMaterialBlockConnectionPointMode.Undefined;
|
|
|
|
- this.associatedVariableName = "";
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Gets or sets a boolean indicating that this connection point is generating a varying variable.
|
|
|
|
- * Can only be set on exit points
|
|
|
|
- */
|
|
|
|
- public get isVarying(): boolean {
|
|
|
|
- return this._mode === NodeMaterialBlockConnectionPointMode.Varying;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public set isVarying(value: boolean) {
|
|
|
|
- this._mode = value ? NodeMaterialBlockConnectionPointMode.Varying : NodeMaterialBlockConnectionPointMode.Undefined;
|
|
|
|
- this.associatedVariableName = "";
|
|
|
|
|
|
+ return this.connectedPoint!.ownerBlock as InputBlock;
|
|
}
|
|
}
|
|
|
|
|
|
/** Get the other side of the connection (if any) */
|
|
/** Get the other side of the connection (if any) */
|
|
@@ -234,49 +163,6 @@ export class NodeMaterialConnectionPoint {
|
|
return "NodeMaterialConnectionPoint";
|
|
return "NodeMaterialConnectionPoint";
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * Set the source of this connection point to a vertex attribute
|
|
|
|
- * @param attributeName defines the attribute name (position, uv, normal, etc...). If not specified it will take the connection point name
|
|
|
|
- * @returns the current connection point
|
|
|
|
- */
|
|
|
|
- public setAsAttribute(attributeName?: string): NodeMaterialConnectionPoint {
|
|
|
|
- if (attributeName) {
|
|
|
|
- this.name = attributeName;
|
|
|
|
- }
|
|
|
|
- this._mode = NodeMaterialBlockConnectionPointMode.Attribute;
|
|
|
|
- return this;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Set the source of this connection point to a well known value
|
|
|
|
- * @param value define the well known value to use (world, view, etc...) or null to switch to manual value
|
|
|
|
- * @returns the current connection point
|
|
|
|
- */
|
|
|
|
- public setAsWellKnownValue(value: Nullable<NodeMaterialWellKnownValues>): NodeMaterialConnectionPoint {
|
|
|
|
- this.wellKnownValue = value;
|
|
|
|
- return this;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Gets a boolean indicating that the current connection point is a well known value
|
|
|
|
- */
|
|
|
|
- public get isWellKnownValue(): boolean {
|
|
|
|
- return this._wellKnownValue != null;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Gets or sets the current well known value or null if not defined as well know value
|
|
|
|
- */
|
|
|
|
- public get wellKnownValue(): Nullable<NodeMaterialWellKnownValues> {
|
|
|
|
- return this._wellKnownValue;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public set wellKnownValue(value: Nullable<NodeMaterialWellKnownValues>) {
|
|
|
|
- this._mode = NodeMaterialBlockConnectionPointMode.Uniform;
|
|
|
|
- this.associatedVariableName = "";
|
|
|
|
- this._wellKnownValue = value;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
private _getTypeLength(type: NodeMaterialBlockConnectionPointTypes) {
|
|
private _getTypeLength(type: NodeMaterialBlockConnectionPointTypes) {
|
|
switch (type) {
|
|
switch (type) {
|
|
case NodeMaterialBlockConnectionPointTypes.Float:
|
|
case NodeMaterialBlockConnectionPointTypes.Float:
|
|
@@ -349,101 +235,4 @@ export class NodeMaterialConnectionPoint {
|
|
endpoint._connectedPoint = null;
|
|
endpoint._connectedPoint = null;
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
-
|
|
|
|
- /**
|
|
|
|
- * When connection point is an uniform, this function will send its value to the effect
|
|
|
|
- * @param effect defines the effect to transmit value to
|
|
|
|
- * @param world defines the world matrix
|
|
|
|
- * @param worldView defines the worldxview matrix
|
|
|
|
- * @param worldViewProjection defines the worldxviewxprojection matrix
|
|
|
|
- */
|
|
|
|
- public transmitWorld(effect: Effect, world: Matrix, worldView: Matrix, worldViewProjection: Matrix) {
|
|
|
|
- if (!this._wellKnownValue) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- let variableName = this.associatedVariableName;
|
|
|
|
- switch (this._wellKnownValue) {
|
|
|
|
- case NodeMaterialWellKnownValues.World:
|
|
|
|
- effect.setMatrix(variableName, world);
|
|
|
|
- break;
|
|
|
|
- case NodeMaterialWellKnownValues.WorldView:
|
|
|
|
- effect.setMatrix(variableName, worldView);
|
|
|
|
- break;
|
|
|
|
- case NodeMaterialWellKnownValues.WorldViewProjection:
|
|
|
|
- effect.setMatrix(variableName, worldViewProjection);
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * When connection point is an uniform, this function will send its value to the effect
|
|
|
|
- * @param effect defines the effect to transmit value to
|
|
|
|
- * @param scene defines the hosting scene
|
|
|
|
- */
|
|
|
|
- public transmit(effect: Effect, scene: Scene) {
|
|
|
|
- let variableName = this.associatedVariableName;
|
|
|
|
- if (this._wellKnownValue) {
|
|
|
|
- switch (this._wellKnownValue) {
|
|
|
|
- case NodeMaterialWellKnownValues.World:
|
|
|
|
- case NodeMaterialWellKnownValues.WorldView:
|
|
|
|
- case NodeMaterialWellKnownValues.WorldViewProjection:
|
|
|
|
- return;
|
|
|
|
- case NodeMaterialWellKnownValues.View:
|
|
|
|
- effect.setMatrix(variableName, scene.getViewMatrix());
|
|
|
|
- break;
|
|
|
|
- case NodeMaterialWellKnownValues.Projection:
|
|
|
|
- effect.setMatrix(variableName, scene.getProjectionMatrix());
|
|
|
|
- break;
|
|
|
|
- case NodeMaterialWellKnownValues.ViewProjection:
|
|
|
|
- effect.setMatrix(variableName, scene.getTransformMatrix());
|
|
|
|
- break;
|
|
|
|
- case NodeMaterialWellKnownValues.CameraPosition:
|
|
|
|
- effect.setVector3(variableName, scene.activeCamera!.globalPosition);
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- let value = this._valueCallback ? this._valueCallback() : this._storedValue;
|
|
|
|
-
|
|
|
|
- if (value === null) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- switch (this.type) {
|
|
|
|
- case NodeMaterialBlockConnectionPointTypes.Float:
|
|
|
|
- effect.setFloat(variableName, value);
|
|
|
|
- break;
|
|
|
|
- case NodeMaterialBlockConnectionPointTypes.Int:
|
|
|
|
- effect.setInt(variableName, value);
|
|
|
|
- break;
|
|
|
|
- case NodeMaterialBlockConnectionPointTypes.Color3:
|
|
|
|
- effect.setColor3(variableName, value);
|
|
|
|
- break;
|
|
|
|
- case NodeMaterialBlockConnectionPointTypes.Color4:
|
|
|
|
- effect.setDirectColor4(variableName, value);
|
|
|
|
- break;
|
|
|
|
- case NodeMaterialBlockConnectionPointTypes.Vector2:
|
|
|
|
- effect.setVector2(variableName, value);
|
|
|
|
- break;
|
|
|
|
- case NodeMaterialBlockConnectionPointTypes.Vector3:
|
|
|
|
- effect.setVector3(variableName, value);
|
|
|
|
- break;
|
|
|
|
- case NodeMaterialBlockConnectionPointTypes.Color3OrColor4:
|
|
|
|
- effect.setFloat4(variableName, value.r, value.g, value.b, value.a || 1.0);
|
|
|
|
- break;
|
|
|
|
- case NodeMaterialBlockConnectionPointTypes.Vector4OrColor4:
|
|
|
|
- case NodeMaterialBlockConnectionPointTypes.Vector4:
|
|
|
|
- effect.setVector4(variableName, value);
|
|
|
|
- break;
|
|
|
|
- case NodeMaterialBlockConnectionPointTypes.Matrix:
|
|
|
|
- effect.setMatrix(variableName, value);
|
|
|
|
- break;
|
|
|
|
- case NodeMaterialBlockConnectionPointTypes.Texture:
|
|
|
|
- case NodeMaterialBlockConnectionPointTypes.Texture3D:
|
|
|
|
- effect.setTexture(variableName, value);
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
}
|
|
}
|