UVTransformNode.js 1.5 KB

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