LightNode.js 1.0 KB

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