index.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //UI
  2. var gui = new dat.GUI();
  3. var options = {
  4. material: "standard",
  5. mesh: "sphere",
  6. hemisphericLight: true,
  7. pointLight: false,
  8. directionalLight: false,
  9. castShadows: false,
  10. spotLight: false,
  11. fog: false,
  12. skybox: false
  13. }
  14. var registeredUIs = {};
  15. var materialgui;
  16. window.registerRangeUI = function(material, name, minValue, maxValue, onChange, onSet) {
  17. if (!registeredUIs[material]) {
  18. registeredUIs[material] = [];
  19. }
  20. registeredUIs[material].push({
  21. name: name,
  22. minValue: minValue,
  23. maxValue: maxValue,
  24. onChange: onChange,
  25. onSet: onSet
  26. });
  27. }
  28. var setUi = function(ui) {
  29. options[ui.name] = ui.onSet();
  30. materialgui.add(options, ui.name, ui.minValue, ui.maxValue).onChange(function(value) {
  31. ui.onChange(value);
  32. });
  33. }
  34. window.enableMaterial = function(material) {
  35. if (materialgui) {
  36. materialgui.domElement.parentElement.removeChild(materialgui.domElement);
  37. materialgui = null;
  38. }
  39. if (registeredUIs[material]) {
  40. materialgui = new dat.GUI();
  41. for (var index = 0; index < registeredUIs[material].length; index++) {
  42. var ui = registeredUIs[material][index];
  43. setUi(ui);
  44. }
  45. }
  46. }