tweakpane: `exportPreset` doesn't capture pane
I have a large root Pane with many folders and parameters nested inside. But when I call pane.exportPreset()
on the root, it returns what appears to be a random folder from the middle of the tree.
screenshot

I’m not sure if this is intended functionality or not. Is this because I neglected to specify the presetKey
for each controller? (I’m just now reading about presetKey
🤦♂️
As I try to figure it out, it appears there is no API exposed at all for things like recursive children, controller values / titles / etc.
I got the folders recursively in the screenshot like so:
const walk = (gui: FolderApi) => {
for (const child of gui.children) {
console.log(child)
const isFolder = child.rackApi_ !== undefined
if (isFolder) {
console.log('🗂')
walk(child as FolderApi)
}
}
}
But now, getting all the targets / titles / values doesn’t seem to be very straightforward.
Unless I’m missing something big, it seems like my best bet is to build a system over top of tweakpane to expose important information like values, names, targets, default values, etc in order to implement a preset system that functions like gui.save()
in lil-gui
or dat.gui
Sorry for the long post! I’m knee deep in a huge project and was tasked with implementing presets so I’m a bit scatter brained 😅
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (9 by maintainers)
Commits related to this issue
- Add import/export state to BladeController, #431 — committed to cocopon/tweakpane by cocopon a year ago
- Add `readonly` to monitor blade state, #431 — committed to cocopon/tweakpane by cocopon a year ago
After considering, preset will be replaced with “blade state” in v4.
Every blade has the method
importState()
andexportState()
, and the pane uses them recursively to create a whole state.Blade state contains more information about blades and it can convert into classic preset easily with small utility function.
Blade state is literally a state of the blade, so I think related data is out of scope of the state. All binding blades have a string field
tag
and you can use it as a key for the data like this:Blade state of the pane:
Generally you can determine input blades by binding
key
andvalue
, unless someone creates a blade plugin that exports these fields.And here is an example of a folder state:
You’ll be able to except monitor bindings by
readonly: true
.Big +1 for this feature! I’ve actually recently ended up hacking together my own version of this which works nicely but required overwriting core methods so it isn’t future-proofed.
What’s nice about the ability to export all data is that you can place this in localStorage and retrieve it on refresh so you can persist your settings. It might be nice to have this as a built-in option on tweakpane 😃
I also found that I needed the ability to exclude certain folders from the export for things like monitor bindings and other settings since there was no use for them when re-importing.
Haha thanks, I love hacking on tweakpane! 🙏 Let me know if there is anything I can do to help.
There are several possibilities for the preset format.
1. Flatten object (current format)
Pros:
Cons:
presetKey
can solve this problem, but not smart a bit…2. Nested object
Pros:
Cons:
3. Nested array
Pros:
Cons: