Skip to content

Commit c8d1783

Browse files
committed
feat(web): open a bundled scene on startup instead of an empty document
A browser tab has no command line to name a scene on, and MeshCraft's Open dialog is a path field over Emscripten's virtual filesystem -- whose entire contents are whatever CMakeLists.txt preloaded from test/ at build time. So the web build always came up on an empty document, which reads as "it failed to load anything" rather than as a working editor. Web builds now start on /test/medieval_castle.mc3.xml: 548 objects across 272 instances and 21 groups, with real textures, so the first thing the page shows exercises the renderer rather than an empty grid. Guarded by std::filesystem::exists so a build whose preload set changes degrades to the old empty-scene start with a message, not a failure. Emscripten-only and only for the plain interactive start: --screenshot/--export/--benchmark each require their own scene argument and are rejected above without one, so an empty filePath here can only be the interactive case. Native builds are untouched. Verified in a browser on real hardware: the scene loads ("[MeshCraft] Loaded: /test/medieval_castle.mc3.xml"), the hierarchy fills, the Properties panel shows the MedievalCastle document and the status bar reads 548 objects. Note for anyone testing headless: SwiftShader cannot draw this scene at a usable rate and leaves the canvas black -- that is the software rasteriser, not the build.
1 parent 2dbcd52 commit c8d1783

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

src/MeshCraft/main.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,27 @@ int main(int argc, char* argv[]) {
130130
return 1;
131131
}
132132

133+
#if defined(__EMSCRIPTEN__)
134+
// Web builds only. A browser tab has no command line to pass a scene on, and the Open dialog
135+
// can reach nothing but Emscripten's virtual filesystem -- whose entire contents are whatever
136+
// CMakeLists.txt preloaded from test/ at build time (--preload-file ... @/test). So the page
137+
// opened on an empty document and looked like it had failed to load anything. Open one of the
138+
// bundled scenes instead, and one with real geometry and textures rather than a primitive.
139+
//
140+
// Deliberately only when nothing else was requested: --screenshot/--export/--benchmark all
141+
// demand their own scene argument and are rejected above without one, so reaching here with
142+
// an empty filePath means the plain interactive start.
143+
if (filePath.empty()) {
144+
constexpr const char* kWebStartupScene = "/test/medieval_castle.mc3.xml";
145+
if (std::filesystem::exists(kWebStartupScene)) {
146+
filePath = kWebStartupScene;
147+
} else {
148+
std::cerr << "[MeshCraft] Bundled startup scene missing from the virtual filesystem: "
149+
<< kWebStartupScene << " — starting with an empty scene.\n";
150+
}
151+
}
152+
#endif
153+
133154
if (benchmarkMode) {
134155
auto* app = new MeshCraft::Application::MeshCraftApplication(
135156
std::filesystem::path(filePath), /*benchmarkMode=*/true);

0 commit comments

Comments
 (0)