UVTransformNode.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. THREE.UVTransformNode = function () {
  5. THREE.FunctionNode.call( this, "( uvTransform * vec3( uvNode, 1 ) ).xy", "vec2" );
  6. this.uv = new THREE.UVNode();
  7. this.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.toJSON = function ( meta ) {
  23. var data = this.getJSONNode( meta );
  24. if ( ! data ) {
  25. data = this.createJSONNode( meta );
  26. data.uv = this.uv.toJSON( meta ).uuid;
  27. data.transform = this.transform.toJSON( meta ).uuid;
  28. }
  29. return data;
  30. };