UVTransformNode.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. THREE.UVTransformNode = function ( uv, transform ) {
  5. THREE.FunctionNode.call( this, "( uvTransform * vec3( uvNode, 1 ) ).xy", "vec2" );
  6. this.uv = uv || new THREE.UVNode();
  7. this.transform = transform || new THREE.Matrix3Node();
  8. };
  9. THREE.UVTransformNode.prototype = Object.create( THREE.FunctionNode.prototype );
  10. THREE.UVTransformNode.prototype.constructor = THREE.UVTransformNode;
  11. THREE.UVTransformNode.prototype.nodeType = "UVTransform";
  12. THREE.UVTransformNode.prototype.generate = function ( builder, output ) {
  13. this.keywords[ "uvNode" ] = this.uv;
  14. this.keywords[ "uvTransform" ] = this.transform;
  15. return THREE.FunctionNode.prototype.generate.call( this, builder, output );
  16. };
  17. THREE.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.transform.value.setUvTransform( tx, ty, sx, sy, rotation, cx, cy );
  21. };
  22. THREE.UVTransformNode.prototype.copy = function ( source ) {
  23. THREE.GLNode.prototype.copy.call( this, source );
  24. this.uv = source.uv;
  25. this.transform = source.transform;
  26. };
  27. THREE.UVTransformNode.prototype.toJSON = function ( meta ) {
  28. var data = this.getJSONNode( meta );
  29. if ( ! data ) {
  30. data = this.createJSONNode( meta );
  31. data.uv = this.uv.toJSON( meta ).uuid;
  32. data.transform = this.transform.toJSON( meta ).uuid;
  33. }
  34. return data;
  35. };