LightNode.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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.getType( builder ), output );
  16. } else {
  17. console.warn( "THREE.LightNode is only compatible in \"light\" channel." );
  18. return builder.format( 'vec3( 0.0 )', this.getType( builder ), output );
  19. }
  20. };
  21. LightNode.prototype.copy = function ( source ) {
  22. TempNode.prototype.copy.call( this, source );
  23. this.scope = source.scope;
  24. };
  25. LightNode.prototype.toJSON = function ( meta ) {
  26. var data = this.getJSONNode( meta );
  27. if ( ! data ) {
  28. data = this.createJSONNode( meta );
  29. data.scope = this.scope;
  30. }
  31. return data;
  32. };
  33. export { LightNode };