HemisphereLightHelper.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. * @author mrdoob / http://mrdoob.com/
  4. */
  5. THREE.HemisphereLightHelper = function ( light, sphereSize, arrowLength, domeSize ) {
  6. THREE.Object3D.call( this );
  7. this.light = light;
  8. this.light.updateMatrixWorld();
  9. this.matrixWorld = light.matrixWorld;
  10. this.matrixAutoUpdate = false;
  11. this.colors = [ new THREE.Color(), new THREE.Color() ];
  12. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  13. geometry.applyMatrix( new THREE.Matrix4().makeRotationX( - Math.PI / 2 ) );
  14. for ( var i = 0, il = 8; i < il; i ++ ) {
  15. geometry.faces[ i ].color = this.colors[ i < 4 ? 0 : 1 ];
  16. }
  17. var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors, wireframe: true } );
  18. this.lightSphere = new THREE.Mesh( geometry, material );
  19. this.add( this.lightSphere );
  20. this.update();
  21. };
  22. THREE.HemisphereLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  23. THREE.HemisphereLightHelper.prototype.dispose = function () {
  24. this.lightSphere.geometry.dispose();
  25. this.lightSphere.material.dispose();
  26. };
  27. THREE.HemisphereLightHelper.prototype.update = function () {
  28. var vector = new THREE.Vector3();
  29. return function () {
  30. this.colors[ 0 ].copy( this.light.color ).multiplyScalar( this.light.intensity );
  31. this.colors[ 1 ].copy( this.light.groundColor ).multiplyScalar( this.light.intensity );
  32. this.lightSphere.lookAt( vector.getPositionFromMatrix( this.light.matrixWorld ).negate() );
  33. this.lightSphere.geometry.colorsNeedUpdate = true;
  34. }
  35. }();