vertexOutputBlock.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 output the vertex position
  8. */
  9. export class VertexOutputBlock extends NodeMaterialBlock {
  10. /**
  11. * Creates a new VertexOutputBlock
  12. * @param name defines the block name
  13. */
  14. public constructor(name: string) {
  15. super(name, NodeMaterialBlockTargets.Vertex, true);
  16. this.registerInput("vector", NodeMaterialBlockConnectionPointTypes.Vector4);
  17. }
  18. /**
  19. * Gets the current class name
  20. * @returns the class name
  21. */
  22. public getClassName() {
  23. return "VertexOutputBlock";
  24. }
  25. /**
  26. * Gets the vector input component
  27. */
  28. public get vector(): NodeMaterialConnectionPoint {
  29. return this._inputs[0];
  30. }
  31. /** @hidden */
  32. public get _canAddAtVertexRoot(): boolean {
  33. return false;
  34. }
  35. /** @hidden */
  36. public get _canAddAtFragmentRoot(): boolean {
  37. return false;
  38. }
  39. protected _buildBlock(state: NodeMaterialBuildState) {
  40. super._buildBlock(state);
  41. let input = this.vector;
  42. state.compilationString += `gl_Position = ${input.associatedVariableName};\r\n`;
  43. return this;
  44. }
  45. }