LightNode.js 985 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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.toJSON = function ( 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. };