-
-
Notifications
You must be signed in to change notification settings - Fork 225
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
f3d-web updates: parse other ui params, loading visual feedback, alert user on error, documentation #1738
base: master
Are you sure you want to change the base?
Conversation
…up` (in addition to `model, extension`) These url params are now parsed: `#axis=false&grid=false&fxaa=false&tone=false&ssao=false&ambient=false&up=+Y` sad thing is options.toggle requires knowing the param state beforehand, rather than setting it explicitly
Awesome! I'll try that locally as soon as I can. |
Here's my feedback: |
webassembly/app.html
Outdated
if (parsed_param_value && parsed_param_value.toLowerCase() === 'false') { | ||
// we can use toggle, set_string, set_integer, set_color | ||
// sad thing is toggle requires knowing the param state beforehand, rather than setting it explicitly | ||
options.toggle(option) |
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.
As you already figured out, the JS bindings are not complete enough yet to achieve what you're attempting here.
f3d/webassembly/F3DEmscriptenBindings.cxx
Lines 80 to 84 in f3d7627
emscripten::class_<f3d::options>("Options") | |
.function("toggle", &toggle, emscripten::return_value_policy::reference()) | |
.function("set_string", &set_string, emscripten::return_value_policy::reference()) | |
.function("set_integer", &set_integer, emscripten::return_value_policy::reference()) | |
.function("set_color", &set_color, emscripten::return_value_policy::reference()); |
You could use the value of the UI switches to guess the current values and decide whether to toggle but that'd be sketchy as there is no proper guarantee that they'll be in sync.
At the very least set_boolean
would need to be added, but ideally the bindings should expose the newer setAsString
method that would let you do options.set_as_string(option, parsed_param_value)
directly (passing a "false"
/"true"
string and having the parsing done internally, as opposed to converting from string to bool in the JS and calling .set_boolean
).
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.
The current implementation takes for granted that:
- every DOM
input
ischecked
when page loads, see this code block - the corresponding f3d
settings.options
are toggled on, see this code block - so I can only watch for when these
axis, grid, fxaa, tone, ssao, ambient
url-params are set to false, in which case I toggle them a second time before calling a finalModule.engineInstance.getWindow().render();
just before returnging from methodload_from_url()
The current implementation does work under these assumptions from my testing.
I think this PR can be merged, and the code could then be updated to account for a new set_boolean
function + binding, or even higher-level set_as_string
binding, once either is available.
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.
Unless I'm missing something the PR's code currently only handles toggling options off (guarded by if ( ... === 'false')
) so if, for example, the grid is off and I change the hash to #grid=true
it will not even attempt to turn it on.
In order to handle both #x=true
and #x=false
parameters values you'd need to do something like this:
if (parsed_param_value) {
const new_val = parsed_param_value.toLowerCase() === 'true'; //TODO actual input validation?
const ui_switch = document.querySelector('#' + id); //TODO check the element actually exists?
const old_val = ui_switch.checked; // let's hope this is in sync
if(new_val != old_val) {
options.toggle(option)
}
ui_switch.checked = new_val;
}
This is still a janky workaround the limitations of the API but at least it will handle toggling things back on
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.
Alright, this is correct, I don't usually change hash after page was loaded but you're right. I'll include your modifications.
Thanks for the feedback!
|
Changing the hash in the browser URL box indeed should not produce a full page reload, but a reload shouldn't be needed because the script is already listening for the hash change event ( edit: I guess you'd need a reload if you want to re-apply the options from the same hash without it having changed? |
Can be tested with http://localhost:8080/app.html#model=https://hub.dronedb.app/orgs/pierotofy/ds/brighton-beach/download?path=3d-model%2Fodm_textured_model_geo.obj
Just pushed a quick PR to add a fetchWithProgress function so progress-bar can be displayed both for FileReader and model url parsed. |
Useful in case hash change after page loaded
Needs to be passed with special character since + in urls means space `&up=%2BY`
Pushed 2 more commits addressing the suggested modifications, should be good to go! |
Co-authored-by: snoyer <[email protected]>
FYI the wasm bindings have been improved to support set_as_string/get_as_string |
Alright just committed a minor update, hich should be mergeable - don't hesitate to edit the PR in case you'd want a better approach. |
Ready to be reviewed by f3d team from my point of view |
Solves improvements of web url-param parsing listed in #1604 :
axis, grid, fxaa, tone, ssao, ambient, up