LightNode.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import Node, { addNodeClass } from '../core/Node.js';
  2. import { nodeProxy } from '../shadernode/ShaderNode.js';
  3. import { objectPosition } from '../accessors/Object3DNode.js';
  4. import { cameraViewMatrix } from '../accessors/CameraNode.js';
  5. class LightNode extends Node {
  6. constructor( scope = LightNode.TARGET_DIRECTION, light = null ) {
  7. super();
  8. this.scope = scope;
  9. this.light = light;
  10. }
  11. setup() {
  12. const { scope, light } = this;
  13. let output = null;
  14. if ( scope === LightNode.TARGET_DIRECTION ) {
  15. output = cameraViewMatrix.transformDirection( objectPosition( light ).sub( objectPosition( light.target ) ) );
  16. }
  17. return output;
  18. }
  19. serialize( data ) {
  20. super.serialize( data );
  21. data.scope = this.scope;
  22. }
  23. deserialize( data ) {
  24. super.deserialize( data );
  25. this.scope = data.scope;
  26. }
  27. }
  28. LightNode.TARGET_DIRECTION = 'targetDirection';
  29. export default LightNode;
  30. export const lightTargetDirection = nodeProxy( LightNode, LightNode.TARGET_DIRECTION );
  31. addNodeClass( 'LightNode', LightNode );