OperatorNode.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. THREE.OperatorNode = function( a, b, op ) {
  5. THREE.TempNode.call( this );
  6. this.a = a;
  7. this.b = b;
  8. this.op = op || THREE.OperatorNode.ADD;
  9. };
  10. THREE.OperatorNode.ADD = '+';
  11. THREE.OperatorNode.SUB = '-';
  12. THREE.OperatorNode.MUL = '*';
  13. THREE.OperatorNode.DIV = '/';
  14. THREE.OperatorNode.prototype = Object.create( THREE.TempNode.prototype );
  15. THREE.OperatorNode.prototype.constructor = THREE.OperatorNode;
  16. THREE.OperatorNode.prototype.getType = function( builder ) {
  17. var a = this.a.getType( builder );
  18. var b = this.b.getType( builder );
  19. if ( builder.isFormatMatrix( a ) ) {
  20. return 'v4';
  21. } else if ( builder.getFormatLength( b ) > builder.getFormatLength( a ) ) {
  22. // use the greater length vector
  23. return b;
  24. }
  25. return a;
  26. };
  27. THREE.OperatorNode.prototype.generate = function( builder, output ) {
  28. var material = builder.material,
  29. data = material.getDataNode( this.uuid );
  30. var type = this.getType( builder );
  31. var a = this.a.build( builder, type );
  32. var b = this.b.build( builder, type );
  33. return builder.format( '(' + a + this.op + b + ')', type, output );
  34. };