vector3TransformBlock.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { NodeMaterialBlock } from '../nodeMaterialBlock';
  2. import { NodeMaterialBlockConnectionPointTypes } from '../nodeMaterialBlockConnectionPointTypes';
  3. import { NodeMaterialBuildState } from '../nodeMaterialBuildState';
  4. import { NodeMaterialBlockTargets } from '../nodeMaterialBlockTargets';
  5. import { NodeMaterialConnectionPoint } from '../nodeMaterialBlockConnectionPoint';
  6. /**
  7. * Block used to transform a vector3 with a matrix
  8. */
  9. export class Vector3TransformBlock extends NodeMaterialBlock {
  10. /**
  11. * Defines the value to use to complement Vector3 to transform it to a Vector4
  12. */
  13. public complement = 1;
  14. /**
  15. * Creates a new Vector3TransformBlock
  16. * @param name defines the block name
  17. */
  18. public constructor(name: string) {
  19. super(name, NodeMaterialBlockTargets.Vertex);
  20. this.registerInput("vector", NodeMaterialBlockConnectionPointTypes.Vector3);
  21. this.registerInput("transform", NodeMaterialBlockConnectionPointTypes.Matrix);
  22. this.registerOutput("output", NodeMaterialBlockConnectionPointTypes.Vector4);
  23. }
  24. /**
  25. * Gets the vector input
  26. */
  27. public get vector(): NodeMaterialConnectionPoint {
  28. return this._inputs[0];
  29. }
  30. /**
  31. * Gets the matrix transform input
  32. */
  33. public get transform(): NodeMaterialConnectionPoint {
  34. return this._inputs[1];
  35. }
  36. /**
  37. * Gets the current class name
  38. * @returns the class name
  39. */
  40. public getClassName() {
  41. return "Vector3TransformBlock";
  42. }
  43. protected _buildBlock(state: NodeMaterialBuildState) {
  44. super._buildBlock(state);
  45. let output = this._outputs[0];
  46. let vector = this.vector;
  47. let transform = this.transform;
  48. state.compilationString += this._declareOutput(output, state) + ` = ${transform.associatedVariableName} * vec4(${vector.associatedVariableName}, ${this.complement});\r\n`;
  49. return this;
  50. }
  51. }