|
@@ -5,22 +5,27 @@ import { NodeMaterialBlockTargets } from '../nodeMaterialBlockTargets';
|
|
|
import { NodeMaterialConnectionPoint } from '../nodeMaterialBlockConnectionPoint';
|
|
|
|
|
|
/**
|
|
|
- * Block used to transform a vector4 with a matrix
|
|
|
+ * Block used to transform a vector (2, 3 or 4) with a matrix. It will generate a Vector4
|
|
|
*/
|
|
|
-export class Vector4TransformBlock extends NodeMaterialBlock {
|
|
|
+export class VectorTransformBlock extends NodeMaterialBlock {
|
|
|
/**
|
|
|
- * Defines the value to use to complement Vector3 to transform it to a Vector4
|
|
|
+ * Defines the value to use to complement W value to transform it to a Vector4
|
|
|
*/
|
|
|
public complementW = 1;
|
|
|
|
|
|
/**
|
|
|
- * Creates a new Vector4TransformBlock
|
|
|
+ * Defines the value to use to complement z value to transform it to a Vector4
|
|
|
+ */
|
|
|
+ public complementZ = 0;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Creates a new VectorTransformBlock
|
|
|
* @param name defines the block name
|
|
|
*/
|
|
|
public constructor(name: string) {
|
|
|
super(name, NodeMaterialBlockTargets.Neutral);
|
|
|
|
|
|
- this.registerInput("vector", NodeMaterialBlockConnectionPointTypes.Vector3OrVector4);
|
|
|
+ this.registerInput("vector", NodeMaterialBlockConnectionPointTypes.AutoDetect);
|
|
|
this.registerInput("transform", NodeMaterialBlockConnectionPointTypes.Matrix);
|
|
|
this.registerOutput("output", NodeMaterialBlockConnectionPointTypes.Vector4);
|
|
|
}
|
|
@@ -30,7 +35,7 @@ export class Vector4TransformBlock extends NodeMaterialBlock {
|
|
|
* @returns the class name
|
|
|
*/
|
|
|
public getClassName() {
|
|
|
- return "Vector4TransformBlock";
|
|
|
+ return "VectorTransformBlock";
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -61,10 +66,17 @@ export class Vector4TransformBlock extends NodeMaterialBlock {
|
|
|
let vector = this.vector;
|
|
|
let transform = this.transform;
|
|
|
|
|
|
- if (vector.connectedPoint && vector.connectedPoint!.type === NodeMaterialBlockConnectionPointTypes.Vector3) {
|
|
|
- state.compilationString += this._declareOutput(output, state) + ` = ${transform.associatedVariableName} * vec4(${vector.associatedVariableName}, ${this._writeFloat(this.complementW)});\r\n`;
|
|
|
- } else {
|
|
|
- state.compilationString += this._declareOutput(output, state) + ` = ${transform.associatedVariableName} * ${vector.associatedVariableName};\r\n`;
|
|
|
+ if (vector.connectedPoint) {
|
|
|
+ switch (vector.connectedPoint.type) {
|
|
|
+ case NodeMaterialBlockConnectionPointTypes.Vector2:
|
|
|
+ state.compilationString += this._declareOutput(output, state) + ` = ${transform.associatedVariableName} * vec4(${vector.associatedVariableName}, ${this._writeFloat(this.complementZ)}, ${this._writeFloat(this.complementW)});\r\n`;
|
|
|
+ case NodeMaterialBlockConnectionPointTypes.Vector3:
|
|
|
+ state.compilationString += this._declareOutput(output, state) + ` = ${transform.associatedVariableName} * vec4(${vector.associatedVariableName}, ${this._writeFloat(this.complementW)});\r\n`;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ state.compilationString += this._declareOutput(output, state) + ` = ${transform.associatedVariableName} * ${vector.associatedVariableName};\r\n`;
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return this;
|