LightNode.js 865 B

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