DirectionalLightHelper.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. * @author mrdoob / http://mrdoob.com/
  4. */
  5. THREE.DirectionalLightHelper = function ( light, sphereSize ) {
  6. THREE.Object3D.call( this );
  7. this.light = light;
  8. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  9. var material = new THREE.MeshBasicMaterial( { fog: false, wireframe: true } );
  10. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  11. this.lightSphere = new THREE.Mesh( geometry, material );
  12. this.lightSphere.position = this.light.position;
  13. this.add( this.lightSphere );
  14. /*
  15. this.targetSphere = new THREE.Mesh( geometry, material );
  16. this.targetSphere.position = this.light.target.position;
  17. this.add( this.targetSphere );
  18. */
  19. geometry = new THREE.Geometry();
  20. geometry.vertices.push( this.light.position );
  21. geometry.vertices.push( this.light.target.position );
  22. geometry.computeLineDistances();
  23. material = new THREE.LineDashedMaterial( { dashSize: 4, gapSize: 4, opacity: 0.75, transparent: true, fog: false } );
  24. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  25. this.targetLine = new THREE.Line( geometry, material );
  26. this.add( this.targetLine );
  27. }
  28. THREE.DirectionalLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  29. THREE.DirectionalLightHelper.prototype.update = function () {
  30. this.lightSphere.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  31. this.targetLine.geometry.computeLineDistances();
  32. this.targetLine.geometry.verticesNeedUpdate = true;
  33. this.targetLine.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  34. };
粤ICP备19079148号