LightNode.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. import { TempNode } from '../core/TempNode.js';
  5. function LightNode( scope ) {
  6. TempNode.call( this, 'v3', { shared: false } );
  7. this.scope = scope || LightNode.TOTAL;
  8. }
  9. LightNode.TOTAL = 'total';
  10. LightNode.prototype = Object.create( TempNode.prototype );
  11. LightNode.prototype.constructor = LightNode;
  12. LightNode.prototype.nodeType = "Light";
  13. LightNode.prototype.generate = function ( builder, output ) {
  14. if ( builder.isCache( 'light' ) ) {
  15. return builder.format( 'reflectedLight.directDiffuse', this.type, output );
  16. } else {
  17. console.warn( "THREE.LightNode is only compatible in \"light\" channel." );
  18. return builder.format( 'vec3( 0.0 )', this.type, output );
  19. }
  20. };
  21. LightNode.prototype.copy = function ( source ) {
  22. TempNode.prototype.copy.call( this, source );
  23. this.scope = source.scope;
  24. return this;
  25. };
  26. LightNode.prototype.toJSON = function ( meta ) {
  27. var data = this.getJSONNode( meta );
  28. if ( ! data ) {
  29. data = this.createJSONNode( meta );
  30. data.scope = this.scope;
  31. }
  32. return data;
  33. };
  34. export { LightNode };