Recently, I delved into using the dat.GUI API alongside Three.js and found myself contemplating the best method to personalize the GUI across various files. My goal is to incorporate new Controllers into a single GUI instance from different files, each file focusing on specific aspects of my project like camera or light controls.
My initial attempt involved exporting the GUI instance from one file and importing it into another. However, I encountered an issue where the gui variable was deemed undefined.
// File containing camera settings
import * as dat from 'three/examples/js/libs/dat.gui.min.js';
export const gui = new dat.GUI();
let guiController = { moveModel: true };
gui.add(guiController, 'moveModel');
// File with light settings
import { gui } from <file with camera settings>;
const dir = new SpotLight(0xdeaa88, 1);
gui.add(dir, 'intensity', 0, 2, 0.01);
So, how can I efficiently customize the same GUI from multiple files? My instincts suggest that leveraging JSON data or localStorage might hold the key, yet concrete examples seem elusive online. This discussion could serve as a valuable resource for future learners grappling with similar challenges.