threex.atmospheredatgui.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /**
  2. * vendor.js framework definition
  3. * @type {Object}
  4. */
  5. var THREEx = THREEx || {};
  6. /**
  7. * add a THREEx.AtmosphereMaterial to Dat.DUI
  8. *
  9. * @param {THREE.ShaderMaterial} material the material to handle
  10. * @param {dat.GUI+} datGui the dat.GUI to which we need to add
  11. */
  12. THREEx.addAtmosphereMaterial2DatGui = function(material, datGui){
  13. datGui = datGui || new dat.GUI()
  14. var uniforms = material.uniforms
  15. // options
  16. var options = {
  17. coeficient : uniforms['coeficient'].value,
  18. power : uniforms['power'].value,
  19. glowColor : '#'+uniforms.glowColor.value.getHexString(),
  20. presetFront : function(){
  21. options.coeficient = 1
  22. options.power = 2
  23. onChange()
  24. },
  25. presetBack : function(){
  26. options.coeficient = 0.5
  27. options.power = 4.0
  28. onChange()
  29. },
  30. }
  31. var onChange = function(){
  32. uniforms['coeficient'].value = options.coeficient
  33. uniforms['power'].value = options.power
  34. uniforms.glowColor.value.set( options.glowColor );
  35. }
  36. onChange()
  37. // config datGui
  38. datGui.add( options, 'coeficient' , 0.0 , 2)
  39. .listen().onChange( onChange )
  40. datGui.add( options, 'power' , 0.0 , 30)
  41. .listen().onChange( onChange )
  42. datGui.addColor( options, 'glowColor' )
  43. .listen().onChange( onChange )
  44. datGui.add( options, 'presetFront' )
  45. datGui.add( options, 'presetBack' )
  46. }