LightNode.js 1.1 KB

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