Skip to content

Commit

Permalink
Additional improvements to web viewer
Browse files Browse the repository at this point in the history
- Merge separate code paths for GUI initialization and folder clearing.
- Use the GUI constructor for title assignment.
  • Loading branch information
jstone-lucasfilm committed Dec 20, 2023
1 parent 00e5f73 commit 39138cf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 30 deletions.
4 changes: 2 additions & 2 deletions javascript/MaterialXView/source/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function init()
materialsSelect.value = materialFilename;
materialsSelect.addEventListener('change', (e) => {
materialFilename = e.target.value;
viewer.getEditor().clearFolders();
viewer.getEditor().initialize();
viewer.getMaterial().loadMaterials(viewer, materialFilename);
viewer.getEditor().updateProperties(0.9);
viewer.getScene().setUpdateTransforms();
Expand Down Expand Up @@ -122,7 +122,7 @@ function init()

setLoadingCallback(file => {
materialFilename = file.fullPath || file.name;
viewer.getEditor().clearFolders();
viewer.getEditor().initialize();
viewer.getMaterial().loadMaterials(viewer, materialFilename);
viewer.getEditor().updateProperties(0.9);
viewer.getScene().setUpdateTransforms();
Expand Down
43 changes: 15 additions & 28 deletions javascript/MaterialXView/source/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,21 @@ export class Scene
*/
export class Editor
{
// Initialize the editor, clearing any elements from previous materials.
initialize()
{
Array.from(document.getElementsByClassName('lil-gui')).forEach(
function (element, index, array) {
if (element.className) {
element.remove();
}
}
);

this._gui = new GUI( { title: "Property Editor" } );
this._gui.close();
}

// Update ui properties
// - Hide close button
// - Update transparency so scene shows through if overlapping
Expand All @@ -439,34 +454,6 @@ export class Editor
}
}

//
// Clear folders with children contain elements for any previous material
// and recreate top gui.
//
clearFolders()
{
Array.from(document.getElementsByClassName('lil-gui')).forEach(
function (element, index, array) {
if (element.className) {
element.remove();
}
}
);

// Create new GUI.
this._gui = new GUI();
}

// Create the editor
initialize()
{
this.clearFolders();
this._gui.title("Property Editor");
this._gui.close();

return this._gui;
}

getGUI()
{
return this._gui;
Expand Down

0 comments on commit 39138cf

Please sign in to comment.