threejs-fog.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. 'use strict';
  2. /* global threejsLessonUtils */
  3. {
  4. function fogExample(scene, fog) {
  5. scene.fog = fog;
  6. const width = 4;
  7. const height = 3;
  8. const depth = 10;
  9. const geometry = new THREE.BoxBufferGeometry(width, height, depth);
  10. const material = new THREE.MeshPhongMaterial({color: 'hsl(130,50%,50%)'});
  11. return new THREE.Mesh(geometry, material);
  12. }
  13. threejsLessonUtils.addDiagrams({
  14. fog: {
  15. create(props) {
  16. const {scene} = props;
  17. const color = 0xFFFFFF;
  18. const near = 12;
  19. const far = 18;
  20. return fogExample(scene, new THREE.Fog(color, near, far));
  21. },
  22. },
  23. fogExp2: {
  24. create(props) {
  25. const {scene} = props;
  26. const color = 0xFFFFFF;
  27. const density = 0.1;
  28. return fogExample(scene, new THREE.FogExp2(color, density));
  29. },
  30. },
  31. fogBlueBackgroundRed: {
  32. create(props) {
  33. const {scene} = props;
  34. scene.background = new THREE.Color('#F00');
  35. const color = '#00F';
  36. const near = 12;
  37. const far = 18;
  38. return fogExample(scene, new THREE.Fog(color, near, far));
  39. },
  40. },
  41. fogBlueBackgroundBlue: {
  42. create(props) {
  43. const {scene} = props;
  44. scene.background = new THREE.Color('#00F');
  45. const color = '#00F';
  46. const near = 12;
  47. const far = 18;
  48. return fogExample(scene, new THREE.Fog(color, near, far));
  49. },
  50. },
  51. });
  52. }