vector3TransformBlock.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 output component
  38. */
  39. public get output(): NodeMaterialConnectionPoint {
  40. return this._outputs[0];
  41. }
  42. /**
  43. * Gets the current class name
  44. * @returns the class name
  45. */
  46. public getClassName() {
  47. return "Vector3TransformBlock";
  48. }
  49. protected _buildBlock(state: NodeMaterialBuildState) {
  50. super._buildBlock(state);
  51. let output = this._outputs[0];
  52. let vector = this.vector;
  53. let transform = this.transform;
  54. state.compilationString += this._declareOutput(output, state) + ` = ${transform.associatedVariableName} * vec4(${vector.associatedVariableName}, ${this.complement});\r\n`;
  55. return this;
  56. }
  57. }