UVTransformNode.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. THREE.UVTransformNode = function () {
  5. THREE.FunctionNode.call( this, "( uvTransform * vec4( uvNode, 0, 1 ) ).xy", "vec2" );
  6. this.uv = new THREE.UVNode();
  7. this.transform = new THREE.Matrix4Node();
  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.compose = function () {
  18. var defaultPivot = new THREE.Vector2( .5, .5 ),
  19. tempVector = new THREE.Vector3(),
  20. tempMatrix = new THREE.Matrix4();
  21. return function compose( translate, rotate, scale, optionalCenter ) {
  22. optionalCenter = optionalCenter !== undefined ? optionalCenter : defaultPivot;
  23. var matrix = this.transform.value;
  24. matrix.identity()
  25. .setPosition( tempVector.set( - optionalCenter.x, - optionalCenter.y, 0 ) )
  26. .premultiply( tempMatrix.makeRotationZ( rotate ) )
  27. .multiply( tempMatrix.makeScale( scale.x, scale.y, 0 ) )
  28. .multiply( tempMatrix.makeTranslation( translate.x, translate.y, 0 ) );
  29. return this;
  30. };
  31. }();
  32. THREE.UVTransformNode.prototype.toJSON = function ( meta ) {
  33. var data = this.getJSONNode( meta );
  34. if ( ! data ) {
  35. data = this.createJSONNode( meta );
  36. data.uv = this.uv.toJSON( meta ).uuid;
  37. data.elements = this.transform.value.elements.concat();
  38. }
  39. return data;
  40. };