UVTransformNode.js 1.5 KB

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