0

I have multiple models in a scene which I currently control by placing them inside a function and calling the function when I want to load them.

I'd like to have dat.gui add or remove the object based on a checkbox.

I've successfully loaded the object using dat.gui, but I can't figure out how to remove it (using the same checkbox).

I know I can remove the object using a scene.delete(object) or similar but I don't know how to tie this all into a single checkbox.

Huskie69
  • 795
  • 3
  • 11
  • 31
  • You can do all the stuff you want with the active object in the scene, using `.onChange()` event of a dat.gui controller. – prisoner849 Oct 03 '18 at 12:41
  • I've tried it using this: `var params ={checkbox=false}; gui.add(params, checkbox').onChange(function (value) { model(); }); `This adds the model when I press the checkbox but won't do anything when I "disable" the checkbox. And then if I press it again, it loads the model again (it's .5 opacity so I can see it being added to the scene again each time I tick the checkbox. Is there a way to unload it with the same tickbox? – Huskie69 Oct 03 '18 at 13:35
  • 1
    You pass the `value` in the callback function of the event, but you don't check what value it has. Check it and add a condition, like `if (value == something){model();} else {removeModel();}`. – prisoner849 Oct 03 '18 at 13:56

0 Answers0