RotateUVNode.js 816 B

1234567891011121314151617181920212223242526272829303132
  1. import TempNode from '../core/TempNode.js';
  2. import { vec2, add, sub, mul, cos, sin } from '../shadernode/ShaderNodeBaseElements.js';
  3. class RotateUVNode extends TempNode {
  4. constructor( uvNode, rotationNode, centerNode = vec2( .5 ) ) {
  5. super( 'vec2' );
  6. this.uvNode = uvNode;
  7. this.rotationNode = rotationNode;
  8. this.centerNode = centerNode;
  9. }
  10. construct() {
  11. const { uvNode, rotationNode, centerNode } = this;
  12. const cosAngle = cos( rotationNode );
  13. const sinAngle = sin( rotationNode );
  14. return vec2(
  15. add( add( mul( cosAngle, sub( uvNode.x, centerNode.x ) ), mul( sinAngle, sub( uvNode.y, centerNode.y ) ) ), centerNode.x ),
  16. add( sub( mul( cosAngle, sub( uvNode.y, centerNode.y ) ), mul( sinAngle, sub( uvNode.x, centerNode.x ) ) ), centerNode.y )
  17. );
  18. }
  19. }
  20. export default RotateUVNode;