diff --git a/doc/dev/BUILD_WASM.md b/doc/dev/BUILD_WASM.md index ad5128cb94..0912da950c 100644 --- a/doc/dev/BUILD_WASM.md +++ b/doc/dev/BUILD_WASM.md @@ -4,7 +4,7 @@ F3D can be built in WebAssembly using emscripten in order to embed it into a web It is still experimental and only a small fraction of the libf3d public API is bound. An example can be seen at https://f3d.app/web -This guide is describing how to build VTK and F3D with emscripten using Docker on Linux. +This guide is describing how to build VTK and F3D with emscripten using Docker on Linux or Windows. # Building @@ -25,7 +25,7 @@ Clone VTK and F3D, it will be assumed that the source code is located in `$VTK_D Configure VTK by running the following command: ```sh -docker run -v $VTK_DIR:/vtk \ +docker run -v ${VTK_DIR}:/vtk \ --rm dockcross/web-wasm:20240529-0dade71 \ cmake -S /vtk -B /vtk/build-wasm \ -DBUILD_SHARED_LIBS=OFF \ @@ -67,7 +67,7 @@ docker run -v $VTK_DIR:/vtk \ Build VTK by running the following command: ```sh -docker run -v $VTK_DIR:/vtk --rm dockcross/web-wasm:20240529-0dade71 cmake --build /vtk/build-wasm --parallel 8 +docker run -v ${VTK_DIR}:/vtk --rm dockcross/web-wasm:20240529-0dade71 cmake --build /vtk/build-wasm --parallel 8 ``` ## Building F3D @@ -75,14 +75,14 @@ docker run -v $VTK_DIR:/vtk --rm dockcross/web-wasm:20240529-0dade71 cmake --bui Configure F3D by running the following command: ```sh -docker run -v $VTK_DIR:/vtk -v $F3D_DIR:/f3d \ +docker run -v ${VTK_DIR}:/vtk -v ${F3D_DIR}:/f3d \ --rm dockcross/web-wasm:20240529-0dade71 \ cmake -S /f3d -B /f3d/build-wasm \ -DBUILD_SHARED_LIBS=OFF \ -DCMAKE_BUILD_TYPE=Release \ -DVTK_DIR=/vtk/build-wasm \ -DF3D_PLUGIN_BUILD_EXODUS=OFF \ - -DF3D_WASM_DATA_FILE=/f3d/testing/data/f3d.vtp + -DF3D_WASM_DATA_FILE="/f3d/testing/data/f3d.vtp" ``` > You can change the value of `F3D_WASM_DATA_FILE` to embed another file in the virtual filesystem. @@ -90,7 +90,7 @@ docker run -v $VTK_DIR:/vtk -v $F3D_DIR:/f3d \ Build F3D by running the following command: ```sh -docker run -v $VTK_DIR:/vtk -v $F3D_DIR:/f3d --rm dockcross/web-wasm:20240529-0dade71 cmake --build /f3d/build-wasm --parallel 8 +docker run -v ${VTK_DIR}:/vtk -v ${F3D_DIR}:/f3d --rm dockcross/web-wasm:20240529-0dade71 cmake --build /f3d/build-wasm --parallel 8 ``` # Testing it locally diff --git a/vtkext/private/module/vtkF3DRenderer.cxx b/vtkext/private/module/vtkF3DRenderer.cxx index 51e45274d2..a0fa98f969 100644 --- a/vtkext/private/module/vtkF3DRenderer.cxx +++ b/vtkext/private/module/vtkF3DRenderer.cxx @@ -98,6 +98,7 @@ std::string ComputeFileHash(const std::string& filepath) return md5Hash; } +#ifndef __EMSCRIPTEN__ //---------------------------------------------------------------------------- // Download texture from the GPU to a vtkImageData vtkSmartPointer SaveTextureToImage( @@ -123,6 +124,7 @@ vtkSmartPointer SaveTextureToImage( return img; } #endif +#endif } //---------------------------------------------------------------------------- @@ -837,6 +839,7 @@ void vtkF3DRenderer::ConfigureHDRILUT() } assert(lut->GetTextureObject()); +#ifndef __EMSCRIPTEN__ vtkSmartPointer img = ::SaveTextureToImage( lut->GetTextureObject(), GL_TEXTURE_2D, 0, lut->GetLUTSize(), VTK_UNSIGNED_SHORT); assert(img); @@ -845,6 +848,7 @@ void vtkF3DRenderer::ConfigureHDRILUT() writer->SetFileName(lutCachePath.c_str()); writer->SetInputData(img); writer->Write(); +#endif } this->HasValidHDRILUT = true; } @@ -881,6 +885,7 @@ void vtkF3DRenderer::ConfigureHDRISphericalHarmonics() vtkTable::SafeDownCast(sh->GetOutputDataObject(0))->GetColumn(0)); } +#ifndef __EMSCRIPTEN__ // Create spherical harmonics cache file vtkNew table; table->AddColumn(this->SphericalHarmonics); @@ -889,6 +894,7 @@ void vtkF3DRenderer::ConfigureHDRISphericalHarmonics() writer->SetInputData(table); writer->SetFileName(shCachePath.c_str()); writer->Write(); +#endif } this->HasValidHDRISH = true; } @@ -923,6 +929,7 @@ void vtkF3DRenderer::ConfigureHDRISpecular() } assert(spec->GetTextureObject()); +#ifndef __EMSCRIPTEN__ unsigned int nbLevels = spec->GetPrefilterLevels(); unsigned int size = spec->GetPrefilterSize(); @@ -945,6 +952,7 @@ void vtkF3DRenderer::ConfigureHDRISpecular() writer->SetFileName(specCachePath.c_str()); writer->SetInputData(mb); writer->Write(); +#endif } this->HasValidHDRISpec = true; } diff --git a/webassembly/CMakeLists.txt b/webassembly/CMakeLists.txt index bf41208170..7e6cd88fec 100644 --- a/webassembly/CMakeLists.txt +++ b/webassembly/CMakeLists.txt @@ -35,16 +35,16 @@ target_link_options(f3djs PRIVATE "SHELL:-sEXPORT_EXCEPTION_HANDLING_HELPERS" ) -# Option to copy example.html file to index.html in the binary folder -# In order to test the example: +# Option to copy app.html file to index.html in the binary folder +# In order to test the app: # - go to the binary folder where f3d.js, f3d.wasm and f3d.data are located # - run `python -m http.server 8000` # - open a browser to http://localhost:8000 -option(F3D_WASM_COPY_EXAMPLE "Copy HTML example to binary folder" ON) +option(F3D_WASM_COPY_APP "Copy HTML app file to binary folder" ON) -if(F3D_WASM_COPY_EXAMPLE) +if(F3D_WASM_COPY_APP) configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/example.html" + "${CMAKE_CURRENT_SOURCE_DIR}/app.html" "${CMAKE_BINARY_DIR}/bin/index.html" COPYONLY) configure_file( diff --git a/webassembly/example.html b/webassembly/app.html similarity index 78% rename from webassembly/example.html rename to webassembly/app.html index 0378d37c57..90353522fb 100644 --- a/webassembly/example.html +++ b/webassembly/app.html @@ -1,5 +1,5 @@ - + @@ -20,11 +20,19 @@
-
-

F3D Web

-

- A WebAssembly application using libf3d -

+
+
+

F3D Web

+

+ A WebAssembly application using libf3d +

+
+
+
+ + +
+
@@ -39,14 +47,14 @@

F3D Web

-
+
- +
@@ -62,6 +70,15 @@

F3D Web

+
+ + +
+ +
+ + +
@@ -72,6 +89,21 @@

F3D Web