Skip to content

Commit

Permalink
add option to rename object
Browse files Browse the repository at this point in the history
  • Loading branch information
dpwoert committed Jan 22, 2024
1 parent b290f5b commit bcb951a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/three-gltf-editor/src/Viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ export default class Viewer {
},
canDelete: true,
onDelete: () => this.syncGUI(),
onRename: () => this.syncGUI(),
})
);

Expand Down
13 changes: 12 additions & 1 deletion plugins/three/src/object3d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type MatrixSettings = {
onTransformEnd?: () => void;
canDelete?: boolean;
onDelete?: () => void;
onRename?: (object: Object3D) => void;
};

type Object3dSettings = Partial<MatrixSettings>;
Expand All @@ -30,6 +31,8 @@ export type MeshSettings = Object3dSettings & {
customMaterial?: materialTransform;
};

let renameDebounce: ReturnType<typeof setTimeout> | undefined;

export function matrixFolders(
object: Object3D,
settings: MatrixSettings
Expand All @@ -38,7 +41,15 @@ export function matrixFolders(

const general = new Folder('General');
general.add([
new TextControl(object, 'name'),
new TextControl(object, 'name').on('update', () => {
if (renameDebounce) {
clearTimeout(renameDebounce);
}

renameDebounce = setTimeout(() => {
if (settings.onRename) settings.onRename(object);
}, 500);
}),
new TextControl(object, 'id'),
new BooleanControl(object, 'visible'),
]);
Expand Down

0 comments on commit bcb951a

Please sign in to comment.