UVTransformNode.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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.compose = function () {
  18. var defaultPivot = new THREE.Vector2( .5, .5 );
  19. return function compose( translate, scale, rotate, optionalCenter ) {
  20. optionalCenter = optionalCenter !== undefined ? optionalCenter : defaultPivot;
  21. this.transform.value.setUvTransform( translate.x, translate.y, scale.x, scale.y, rotate, optionalCenter.x, optionalCenter.y );
  22. return this;
  23. };
  24. }();
  25. THREE.UVTransformNode.prototype.toJSON = function ( meta ) {
  26. var data = this.getJSONNode( meta );
  27. if ( ! data ) {
  28. data = this.createJSONNode( meta );
  29. data.uv = this.uv.toJSON( meta ).uuid;
  30. data.transform = this.transform.toJSON( meta ).uuid;
  31. }
  32. return data;
  33. };