NodeJoin.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. THREE.NodeJoin = function( x, y, z, w ) {
  5. THREE.NodeGL.call( this, 'fv1' );
  6. this.x = x;
  7. this.y = y;
  8. this.z = z;
  9. this.w = w;
  10. };
  11. THREE.NodeJoin.prototype = Object.create( THREE.NodeGL.prototype );
  12. THREE.NodeJoin.prototype.constructor = THREE.NodeJoin;
  13. THREE.NodeJoin.inputs = ['x','y','z','w'];
  14. THREE.NodeJoin.prototype.getNumElements = function() {
  15. var inputs = THREE.NodeJoin.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.NodeJoin.prototype.getType = function( builder ) {
  26. return builder.getFormatByLength( this.getNumElements() );
  27. };
  28. THREE.NodeJoin.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.NodeJoin.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 = builder.getFormatConstructor(length) + '(' + outputs.join(',') + ')';
  39. return builder.format( code, type, output );
  40. };