UVTransformNode.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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, position ) {
  8. ExpressionNode.call( this, "( uvTransform * vec3( uvNode, 1 ) ).xy", "vec2" );
  9. this.uv = uv || new UVNode();
  10. this.position = position || 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.position;
  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.position.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.position = source.position;
  29. return this;
  30. };
  31. UVTransformNode.prototype.toJSON = function ( meta ) {
  32. var data = this.getJSONNode( meta );
  33. if ( ! data ) {
  34. data = this.createJSONNode( meta );
  35. data.uv = this.uv.toJSON( meta ).uuid;
  36. data.position = this.position.toJSON( meta ).uuid;
  37. }
  38. return data;
  39. };
  40. export { UVTransformNode };