Skip to content

Refactor preview.js and model_stats.js#86

Closed
thunderbird7413 wants to merge 10 commits into
fossgis:mainfrom
thunderbird7413:Refactor-preview.js-and-model_stats.js
Closed

Refactor preview.js and model_stats.js#86
thunderbird7413 wants to merge 10 commits into
fossgis:mainfrom
thunderbird7413:Refactor-preview.js-and-model_stats.js

Conversation

@thunderbird7413

Copy link
Copy Markdown
Contributor

In this PR, I have modified the Function structure code to the Class type in model_stats.js and preview.js which was actually required for many crucial reasons such as the ownership of the variables, lifecycle of the components, clean code and expecially no memory leaks.

Another change is that, We have removed the separate GLB File Loading for both the components stats and preview one.
This was achieved by loading the GLB file in the preview.js only and then parsing it and passing as a reference to the model_stats component, which then uses it to calculate the stats such as faceCount, meshCount etc.

@thunderbird7413

thunderbird7413 commented Mar 8, 2026

Copy link
Copy Markdown
Contributor Author

@AyushDharDubey, I have solved the issue. Do, tell me if any further changes are needed.

@AyushDharDubey AyushDharDubey left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a pile, this is exactly what was required, to load the gltf object once and then reuse the same object: a single-pass architecture.

I have left some minor comments, Additionally,
on setUpRenderPane call it would be nice to use named-parameters:

setUpRenderPane({
    onLoaded: function (gltf) {
        const stats = new ModelStats();
        stats.processModel(gltf);
    }
});

for better readability.

Comment thread mainapp/static_src/src/preview.js Outdated
Comment on lines 399 to 400
window.setUpRenderPane = setUpRenderPane;
window.displayPreview = displayPreview;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two no longer exist independently in the scope and need to be removed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, removed from [preview.js] as requested, and exposed from [main.js] for backward compatibility while templates are still using global calls.

Comment thread mainapp/templates/mainapp/model.html
Comment thread mainapp/templates/mainapp/modelform.html
Comment thread mainapp/static_src/src/preview.js Outdated
@thunderbird7413

Copy link
Copy Markdown
Contributor Author

Thanks a pile, this is exactly what was required, to load the gltf object once and then reuse the same object: a single-pass architecture.

I have left some minor comments, Additionally, on setUpRenderPane call it would be nice to use named-parameters:

setUpRenderPane({
    onLoaded: function (gltf) {
        const stats = new ModelStats();
        stats.processModel(gltf);
    }
});

for better readability.

Okay, Changed it to use named paramaters

@thunderbird7413

Copy link
Copy Markdown
Contributor Author

Implemented all the fixes as suggested by you, plss review again and update me.

@AyushDharDubey AyushDharDubey left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from this, the commit history would need a rebase to display meaningful commit messages pertaining to the actual changes.

Comment thread mainapp/static_src/src/preview.js Outdated
Comment on lines +380 to +395
export function setUpRenderPane({ onLoaded } = {}) {
const elems = document.querySelectorAll('div.render-pane');

fullscreenButton.addEventListener('click', function (event) {
const renderPane = document.querySelector('.render-pane');
for (const elem of elems) {
const model_id = elem.dataset.model;
const revision = elem.dataset.revision;
const url = "/api/model/" + model_id + "/" + revision;

if (!document.fullscreenElement && renderPane.requestFullscreen) {
renderPane.requestFullscreen();
} else if (document.exitFullscreen) {
document.exitFullscreen();
}
});
const preview = new ModelPreview(elem.id);
preview.loadAndDisplay(url, onLoaded);
}
}

document.addEventListener('fullscreenchange', function (event) {
handleFullscreenChange(threeInstance);
});
export function displayPreview(elementId, url, options = {}, onLoaded) {
const preview = new ModelPreview(elementId, options);
preview.loadAndDisplay(url, onLoaded);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to move these logic in the respective templates wherever they are applicable, the static assets would better contain only the reusable objects, rather than helper functions specific to page

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@thunderbird7413

Copy link
Copy Markdown
Contributor Author

I think now also, there are some indentations and space flows. Lemme check them also

@thunderbird7413

Copy link
Copy Markdown
Contributor Author

Okay, Now everything is fixed and corrected. You can have a review and then look forward for any other changes.

@thunderbird7413

Copy link
Copy Markdown
Contributor Author

Any updates?

@AyushDharDubey

Copy link
Copy Markdown
Collaborator

It’s difficult to identify the actual changes due to the large number of redundant indentation and formatting updates, which don’t affect the underlying logic.

There are still excessive reformatting changes in models.html that introduce no functional or logical differences.

A full reformat of the rendering logic is a substantial task in itself. It would be preferable to reopen a cleaner PR containing only the intended changes...

@thunderbird7413

Copy link
Copy Markdown
Contributor Author

Ok, I'll do that

@AyushDharDubey

Copy link
Copy Markdown
Collaborator

closing this due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor preview.js and model_stats.js for better modularity and performance

3 participants