1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- import { NodeMaterialBlock } from '../nodeMaterialBlock';
- import { NodeMaterialBlockConnectionPointTypes } from '../nodeMaterialBlockConnectionPointTypes';
- import { NodeMaterialBuildState } from '../nodeMaterialBuildState';
- import { NodeMaterialBlockTargets } from '../nodeMaterialBlockTargets';
- import { NodeMaterialConnectionPoint } from '../nodeMaterialBlockConnectionPoint';
- /**
- * Block used to transform a vector3 with a matrix
- */
- export class Vector3TransformBlock extends NodeMaterialBlock {
- /**
- * Defines the value to use to complement Vector3 to transform it to a Vector4
- */
- public complement = 1;
- /**
- * Creates a new Vector3TransformBlock
- * @param name defines the block name
- */
- public constructor(name: string) {
- super(name, NodeMaterialBlockTargets.Vertex);
- this.registerInput("vector", NodeMaterialBlockConnectionPointTypes.Vector3);
- this.registerInput("transform", NodeMaterialBlockConnectionPointTypes.Matrix);
- this.registerOutput("output", NodeMaterialBlockConnectionPointTypes.Vector4);
- }
- /**
- * Gets the vector input
- */
- public get vector(): NodeMaterialConnectionPoint {
- return this._inputs[0];
- }
- /**
- * Gets the matrix transform input
- */
- public get transform(): NodeMaterialConnectionPoint {
- return this._inputs[1];
- }
- /**
- * Gets the output component
- */
- public get output(): NodeMaterialConnectionPoint {
- return this._outputs[0];
- }
- /**
- * Gets the current class name
- * @returns the class name
- */
- public getClassName() {
- return "Vector3TransformBlock";
- }
- protected _buildBlock(state: NodeMaterialBuildState) {
- super._buildBlock(state);
- let output = this._outputs[0];
- let vector = this.vector;
- let transform = this.transform;
- state.compilationString += this._declareOutput(output, state) + ` = ${transform.associatedVariableName} * vec4(${vector.associatedVariableName}, ${this.complement});\r\n`;
- return this;
- }
- }
|