JoinNode.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. THREE.JoinNode = function( x, y, z, w ) {
  5. THREE.TempNode.call( this, 'fv1' );
  6. this.x = x;
  7. this.y = y;
  8. this.z = z;
  9. this.w = w;
  10. };
  11. THREE.JoinNode.inputs = [ 'x', 'y', 'z', 'w' ];
  12. THREE.JoinNode.prototype = Object.create( THREE.TempNode.prototype );
  13. THREE.JoinNode.prototype.constructor = THREE.JoinNode;
  14. THREE.JoinNode.prototype.getNumElements = function() {
  15. var inputs = THREE.JoinNode.inputs;
  16. var i = inputs.length;
  17. while ( i -- ) {
  18. if ( this[ inputs[ i ] ] !== undefined ) {
  19. ++ i;
  20. break;
  21. }
  22. }
  23. return Math.max( i, 2 );
  24. };
  25. THREE.JoinNode.prototype.getType = function( builder ) {
  26. return builder.getFormatFromLength( this.getNumElements() );
  27. };
  28. THREE.JoinNode.prototype.generate = function( builder, output ) {
  29. var material = builder.material;
  30. var type = this.getType( builder );
  31. var length = this.getNumElements();
  32. var inputs = THREE.JoinNode.inputs;
  33. var outputs = [];
  34. for ( var i = 0; i < length; i ++ ) {
  35. var elm = this[ inputs[ i ] ];
  36. outputs.push( elm ? elm.build( builder, 'fv1' ) : '0.' );
  37. }
  38. var code = ( length > 1 ? builder.getConstructorFromLength( length ) : '' ) + '(' + outputs.join( ',' ) + ')';
  39. return builder.format( code, type, output );
  40. };