123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- /**
- * @author sunag / http://www.sunag.com.br/
- */
- THREE.UVTransformNode = function () {
- THREE.FunctionNode.call( this, "( uvTransform * vec4( uvNode, 0, 1 ) ).xy", "vec2" );
- this.uv = new THREE.UVNode();
- this.transform = new THREE.Matrix4Node();
- };
- THREE.UVTransformNode.prototype = Object.create( THREE.FunctionNode.prototype );
- THREE.UVTransformNode.prototype.constructor = THREE.UVTransformNode;
- THREE.UVTransformNode.prototype.nodeType = "UVTransform";
- THREE.UVTransformNode.prototype.generate = function ( builder, output ) {
- this.keywords[ "uvNode" ] = this.uv;
- this.keywords[ "uvTransform" ] = this.transform;
- return THREE.FunctionNode.prototype.generate.call( this, builder, output );
- };
- THREE.UVTransformNode.prototype.compose = function () {
- var defaultPivot = new THREE.Vector2( .5, .5 ),
- tempVector = new THREE.Vector3(),
- tempMatrix = new THREE.Matrix4();
- return function compose( translate, rotate, scale, optionalCenter ) {
- optionalCenter = optionalCenter !== undefined ? optionalCenter : defaultPivot;
- var matrix = this.transform.value;
- matrix.identity()
- .setPosition( tempVector.set( - optionalCenter.x, - optionalCenter.y, 0 ) )
- .premultiply( tempMatrix.makeRotationZ( rotate ) )
- .multiply( tempMatrix.makeScale( scale.x, scale.y, 0 ) )
- .multiply( tempMatrix.makeTranslation( translate.x, translate.y, 0 ) );
- return this;
- };
- }();
- THREE.UVTransformNode.prototype.toJSON = function ( meta ) {
- var data = this.getJSONNode( meta );
- if ( ! data ) {
- data = this.createJSONNode( meta );
- data.uv = this.uv.toJSON( meta ).uuid;
- data.elements = this.transform.value.elements.concat();
- }
- return data;
- };
|