-
Notifications
You must be signed in to change notification settings - Fork 1
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
Streaming loader #656
Open
adius
wants to merge
16
commits into
develop
Choose a base branch
from
feature/streamingLoader
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Streaming loader #656
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c6b6ce1
Add span element to load-button
ad-si 67aefae
Use streamed loading instead of buffered loading to load models
ad-si ccf59c5
Add styling for load-button
ad-si c5d8862
Merge branch 'develop' of https://github.com/stuikomma/lowfab into fe…
ad-si c41a86d
Fix drag & drop file loading in editor
ad-si 4063a5a
Remove obsolete fileLoader
ad-si b03cab6
Add missing filestream dependency
ad-si d80d627
Increase stability of progress calculations by initializing faceCounter
ad-si 0e27021
Give loading-status text element its own id
ad-si 062d8a4
Replace magic numbers with variables
ad-si 8ae4e58
Merge branch 'develop' into feature/streamingLoader
ad-si b2d9a42
Update stl-parser from 0.8.0 to 0.9.1
ad-si e66218e
Move modelBuilder initialization up
ad-si 786c545
Log warnings emitted by stl-parser
ad-si 3be38b2
Display popup and stop streaming on stl-parser errors
ad-si 6cb4a19
Replace nanobar with a custom progress-bar, unify loading-button design
ad-si File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,9 @@ | |
left 0 | ||
user-select none | ||
|
||
#loadButton | ||
position relative | ||
|
||
.navbar-toggle | ||
margin-top 5px | ||
.icon-bar | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#progressBar | ||
position absolute | ||
top 0 | ||
left 0 | ||
background-color rgba(255, 255, 255, 0.5) | ||
width 0% | ||
height 0.3em |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
ReadableFileStream = require('filestream').read | ||
stlParser = require 'stl-parser' | ||
meshlib = require 'meshlib' | ||
log = require 'loglevel' | ||
|
||
modelCache = require './modelCache' | ||
|
||
averageFaceSize = 240 # Bytes | ||
|
||
loadingPercentage = 80 | ||
processingPercentage = 90 | ||
|
||
idleText = 'Drop an STL File' | ||
processingText = 'Processing Geometry' | ||
viewPreparationText = 'Preparing View' | ||
|
||
$loadingTextElement = $ '#loadingStatus' | ||
progressBarElement = document.getElementById 'progressBar' | ||
|
||
module.exports = (files) -> | ||
|
||
return new Promise (resolve, reject) -> | ||
|
||
if files.length > 1 | ||
errorObject = { | ||
title: 'Import failed' | ||
message: 'Loading of multiple files is not supported.' | ||
} | ||
bootbox.alert errorObject | ||
return reject errorObject | ||
|
||
file = files[0] | ||
|
||
if not /stl$/i.test file.name | ||
bootbox.alert( | ||
title: 'Your file does not have the right format!' | ||
message: 'Only .stl files are supported at the moment. | ||
We are working on adding more file formats' | ||
) | ||
return Promise.reject('Wrong file format') | ||
|
||
faceCounter = file.size / averageFaceSize | ||
|
||
progressBarElement.style.width = 0 | ||
$loadingTextElement.text 'Loading File' | ||
|
||
fileStream = new ReadableFileStream file | ||
fileStream.on 'error', (error) -> | ||
bootbox.alert { | ||
title: 'Import failed' | ||
message: 'Your file contains errors that we could not fix. | ||
You can try to fix your model with e.g. | ||
<a href=http://meshlab.sourceforge.net>meshlab</a> | ||
before uploading it.' | ||
} | ||
reject error | ||
|
||
streamingStlParser = stlParser {blocking: false} | ||
modelBuilder = new meshlib.ModelBuilder() | ||
|
||
streamingStlParser.on 'data', (data) -> | ||
# if data-chunk is the header | ||
if data.faceCount? | ||
faceCounter = data.faceCount | ||
# or a face | ||
else | ||
progress = (data.number / faceCounter) * loadingPercentage | ||
if progress < loadingPercentage | ||
progressBarElement.style.width = progress + '%' | ||
|
||
streamingStlParser.on 'warning', log.warn | ||
|
||
streamingStlParser.on 'error', (error) -> | ||
@end() | ||
streamingStlParser.unpipe modelBuilder | ||
bootbox.alert { | ||
title: 'Invalid STL-file' | ||
message: error.message | ||
callback: -> | ||
progressBarElement.style.width = 0 | ||
$loadingTextElement.text idleText | ||
} | ||
reject error | ||
|
||
|
||
modelBuilder.on 'model', (model) -> | ||
progressBarElement.style.width = loadingPercentage + '%' | ||
$loadingTextElement.text processingText | ||
|
||
processModel = -> | ||
model | ||
.setFileName file.name | ||
.calculateNormals() | ||
.buildFaceVertexMesh() | ||
.done() | ||
.then -> | ||
progressBarElement.style.width = processingPercentage + '%' | ||
$loadingTextElement.text viewPreparationText | ||
return modelCache.store model | ||
.then (hash) -> | ||
progressBarElement.style.width = '100%' | ||
$loadingTextElement.text idleText | ||
resolve hash | ||
progressBarElement.style.width = 0 | ||
|
||
# Give time to render text | ||
setTimeout processModel, 50 | ||
|
||
fileStream | ||
.pipe streamingStlParser | ||
.pipe modelBuilder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pls replace with e.g. progress of
read bytes / file size
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fixed in another pull request.
…but it's already noted: ad-si/stl-parser#7