Skip to content

Commit

Permalink
Prefer loadScene when supported in the web app (f3d-app#1451)
Browse files Browse the repository at this point in the history
  • Loading branch information
Meakk authored Jun 4, 2024
1 parent 7040c4f commit ad897fb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
12 changes: 11 additions & 1 deletion webassembly/F3DEmscriptenBindings.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ f3d::loader* loadScene(f3d::loader& l, const std::string& p)
{
return &l.loadScene(p);
}
bool hasGeometryReader(f3d::loader& l, const std::string& p)
{
return l.hasGeometryReader(p);
}
bool hasSceneReader(f3d::loader& l, const std::string& p)
{
return l.hasSceneReader(p);
}

f3d::window* getWindowPtr(f3d::engine& e)
{
Expand Down Expand Up @@ -92,7 +100,9 @@ EMSCRIPTEN_BINDINGS(f3d)
// f3d::loader
emscripten::class_<f3d::loader>("Loader")
.function("loadGeometry", &loadGeometry, emscripten::allow_raw_pointers())
.function("loadScene", &loadScene, emscripten::allow_raw_pointers());
.function("loadScene", &loadScene, emscripten::allow_raw_pointers())
.function("hasGeometryReader", &hasGeometryReader, emscripten::allow_raw_pointers())
.function("hasSceneReader", &hasSceneReader, emscripten::allow_raw_pointers());

// f3d::window
emscripten::class_<f3d::window>("Window")
Expand Down
17 changes: 15 additions & 2 deletions webassembly/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ <h1 class="title">F3D Web</h1>
<aside class="menu">
<div class="file has-name">
<label class="file-label">
<input class="file-input" type="file" id="file-selector" accept=".gml,.gltf,.glb,.obj,.ply,.pts,.stl,.vtk,.vtp,.vtu" />
<input class="file-input" type="file" id="file-selector" accept=".gml,.gltf,.glb,.obj,.ply,.pts,.stl,.vtk,.vtp,.vtu,.3ds,.wrl,.vrml" />
<span class="file-cta">
<span class="file-label">Open a file...</span>
</span>
Expand Down Expand Up @@ -136,7 +136,20 @@ <h1 class="title">F3D Web</h1>

const openFile = (name) => {
document.getElementById('file-name').innerHTML = name;
Module.engineInstance.getLoader().loadGeometry('/' + name);
const filePath = '/' + name;
const loader = Module.engineInstance.getLoader();
if (loader.hasSceneReader(filePath))
{
loader.loadScene(filePath);
}
else if (loader.hasGeometryReader(filePath))
{
loader.loadGeometry(filePath);
}
else
{
console.error('File ' + filePath + ' cannot be opened');
}
Module.engineInstance.getWindow().resetCamera();
Module.engineInstance.getWindow().render();
};
Expand Down

0 comments on commit ad897fb

Please sign in to comment.