UVTransformNode.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { ExpressionNode } from '../core/ExpressionNode.js';
  2. import { Matrix3Node } from '../inputs/Matrix3Node.js';
  3. import { UVNode } from '../accessors/UVNode.js';
  4. class UVTransformNode extends ExpressionNode {
  5. constructor( uv, position ) {
  6. super( '( uvTransform * vec3( uvNode, 1 ) ).xy', 'vec2' );
  7. this.uv = uv || new UVNode();
  8. this.position = position || new Matrix3Node();
  9. }
  10. generate( builder, output ) {
  11. this.keywords[ 'uvNode' ] = this.uv;
  12. this.keywords[ 'uvTransform' ] = this.position;
  13. return super.generate( builder, output );
  14. }
  15. setUvTransform( tx, ty, sx, sy, rotation, cx, cy ) {
  16. cx = cx !== undefined ? cx : .5;
  17. cy = cy !== undefined ? cy : .5;
  18. this.position.value.setUvTransform( tx, ty, sx, sy, rotation, cx, cy );
  19. }
  20. copy( source ) {
  21. super.copy( source );
  22. this.uv = source.uv;
  23. this.position = source.position;
  24. return this;
  25. }
  26. toJSON( meta ) {
  27. var data = this.getJSONNode( meta );
  28. if ( ! data ) {
  29. data = this.createJSONNode( meta );
  30. data.uv = this.uv.toJSON( meta ).uuid;
  31. data.position = this.position.toJSON( meta ).uuid;
  32. }
  33. return data;
  34. }
  35. }
  36. UVTransformNode.prototype.nodeType = 'UVTransform';
  37. export { UVTransformNode };