OperatorNode.js 1.0 KB

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