mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-13 10:57:49 +00:00
ifcviewer-web: load user sidecars via a file-browse button (#46)
Adds an "Open .ifcview…" button that opens the browser's native file chooser. The picked file's bytes are written into MEMFS and a new exported entry point, load_uploaded_model_c, reads them back via the existing loadSidecarFromPath: it resetScene()s the current model (replace, not append), loads the sidecar, and viewAll()s it. Geometry becomes resident over subsequent frames through render()'s inline driveStreamingLoads, same as the embedded sample. Deliberately a file picker, not drag-drop: browser file drag-drop needs an X11 drag source (a file manager) to drag *from*, which a minimal WM (ratpoison) doesn't provide. The native chooser is WM-independent. Exports _load_uploaded_model_c and the FS runtime method; URL/byte-range fetch of remote models stays for #88. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -41,6 +41,10 @@ namespace {
|
||||
// WebViewportHost selector below.
|
||||
constexpr const char* kCanvasSelector = "#viewer-canvas";
|
||||
|
||||
// MEMFS path the file-browse handler writes the picked sidecar to, and
|
||||
// that load_uploaded_model_c reads back. Must match shell.html.
|
||||
constexpr const char* kUploadPath = "/uploads/model.ifcview";
|
||||
|
||||
struct AppState {
|
||||
WebViewportHost host{ kCanvasSelector };
|
||||
ViewportCore core{ &host };
|
||||
@@ -152,6 +156,28 @@ extern "C" EMSCRIPTEN_KEEPALIVE void raf_tick_c(void* user) {
|
||||
}
|
||||
}
|
||||
|
||||
// Called from shell.html's file-browse handler after it has written the
|
||||
// picked file's bytes into MEMFS at kUploadPath. Replaces whatever is
|
||||
// currently loaded (the embedded sample on first use, or a prior upload)
|
||||
// with the new sidecar and frames it. Geometry becomes resident over the
|
||||
// next frames via render()'s inline driveStreamingLoads. Exported to JS
|
||||
// via EXPORTED_FUNCTIONS in CMakeLists.txt.
|
||||
extern "C" EMSCRIPTEN_KEEPALIVE void load_uploaded_model_c() {
|
||||
if (!g_app || !g_app->ready) return;
|
||||
|
||||
// resetScene drops the previous model's GPU resources so a fresh load
|
||||
// replaces rather than accumulates (loadSidecarFromPath appends).
|
||||
g_app->core.resetScene();
|
||||
const unsigned int mid = g_app->core.loadSidecarFromPath(kUploadPath);
|
||||
if (mid == 0) {
|
||||
Log::warn() << "ifcviewer-web: uploaded model load failed";
|
||||
return;
|
||||
}
|
||||
g_app->core.viewAll();
|
||||
g_app->host.requestFrame();
|
||||
Log::info() << "ifcviewer-web: loaded uploaded model (id " << mid << ")";
|
||||
}
|
||||
|
||||
int main(int /*argc*/, char** /*argv*/) {
|
||||
Log::info() << "ifcviewer-web: starting";
|
||||
g_app = new AppState();
|
||||
|
||||
Reference in New Issue
Block a user