Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serialize and de-serialize dxfViewer scene #65

Open
jshenguru opened this issue Mar 25, 2023 · 3 comments
Open

serialize and de-serialize dxfViewer scene #65

jshenguru opened this issue Mar 25, 2023 · 3 comments

Comments

@jshenguru
Copy link

jshenguru commented Mar 25, 2023

For a large dxf file, it takes about 10 seconds before user can see the model. Below is the timeline from the console log:

[DxfViewer] Initialized in 0.027s
[DxfViewer] Font file(s) load time in 0.046s
[DxfLoader] Loaded DxfData from indexedDb in 0.436s
[DxfLoader] loadEntities() done in 4.493s
[DxfViewer] Loaded 'data/Large_Model.dxf' in 4.933s, adding to scene...
[DxfViewer] Activated layout 'Model' in 0.004s
[DxfViewer] Added 'data/Large_Model.dxf' to scene in 5.163s

As can be seen here, the loadEntities() took ~4.5 seconds (despite the function name, I think this is the parsing step), and the adding to scene took ~5 seconds.

How can I serialize the scene in the dxfViewer and de-serialize the scene in the dxfViewer to reduce this 10 seconds to sub second? Please refer to the following discussion for what I am talking about.

https://discourse.threejs.org/t/the-best-way-to-save-and-open-three-js-scene/16158

@jshenguru jshenguru changed the title [feature request] save and load viewer [feature request] save and load scene Mar 25, 2023
@jshenguru jshenguru changed the title [feature request] save and load scene serialize and de-serialize dxfViewer scene Mar 25, 2023
@yanzexuan1
Copy link
Collaborator

It must be the second time you load this model as I can see "Loaded DxfData from indexedDb in 0.436s". For the first time, we parse the dxf file and save it to indexeddb, so the second time just load from indexeddb.

And loadEntities() for the second load, means generating threejs objects from dxf data.

We should be able to serialize theejs scene, and directly load it. The problem is, threejs objects are large, indexeddb is not large enough to store many of them.

@jshenguru
Copy link
Author

jshenguru commented Mar 26, 2023

Yes, my application has to switch across several CAD drawings back and forth. The ideal user experience would be that when user switch to a CAD drawing the 2nd time or onward, the application should skip the loadEntities() and "adding model to scene", instead it should simply load the scene.

Regarding the threejs scene object being large, there are several options:

Option 1. Zip up the threejs scene JSON before storing into indexedDB.
Option 2. Allow user download the threejs JSON to local drive. I have already tried manually run viewer.scene.toJSON() then download. My problem is that the xdfViewer does not allow me to load that scene JSON.

@yanzexuan1
Copy link
Collaborator

How large is your drawings usually?

Is it ok to create several DxfViewers, and don't destroy them if user is likely to switch back?

By seralizing the scene, we are ok to see objects, while there are other data in memory, like layouts, layers and many others. Many features won't work without these data.

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

No branches or pull requests

2 participants