surface reconstruction in javascript

Make a copy of the MultiCone folder in the src\Examples\Emscripten\Cxx directory and name the folder whatever your project is (keep your copy in the src\Examples\Emscripten\Cxx directory) . Then modify the CMakeList.txt file in the new folder to match your project sources. Here is my CMakeList.txt file for my project named SwisRadar:

cmake_minimum_required(VERSION 3.13)
project(SwisRadar)

# -----------------------------------------------------------------------------
# EMSCRIPTEN only
# -----------------------------------------------------------------------------

if (NOT EMSCRIPTEN)
  message("Skipping example: This needs to run inside an Emscripten build environment")
  return ()
endif ()

# -----------------------------------------------------------------------------
# Handle VTK dependency
# -----------------------------------------------------------------------------

find_package(VTK
  COMPONENTS
    FiltersSources      # VTK pipeline
    InteractionStyle    # Mouse handling
    RenderingOpenGL2    # For Rendering
    RenderingUI         # For SDL2 Window
)

if (NOT VTK_FOUND)
  message("Skipping example: ${VTK_NOT_FOUND_MESSAGE}")
  return ()
endif ()


# -----------------------------------------------------------------------------
# WebAssembly build options
# (-s) https://github.com/emscripten-core/emscripten/blob/master/src/settings.js
# -----------------------------------------------------------------------------

set(emscripten_options)
list(APPEND emscripten_options
  "--bind"
  --preload-file Data
  "-g3"
  "-O3"
  "SHELL:-s EXPORT_NAME=vtkRadar"
  "SHELL:-s MODULARIZE=1"
  "SHELL:-s ALLOW_MEMORY_GROWTH=1"
  "SHELL:-s DEMANGLE_SUPPORT=1"
  "SHELL:-s EMULATE_FUNCTION_POINTER_CASTS=0"
  "SHELL:-s ERROR_ON_UNDEFINED_SYMBOLS=0"
  "SHELL:-s USE_PTHREADS=0"
  "SHELL:-s WASM=1"  
  "SHELL:-s EXPORTED_FUNCTIONS=\"['_main', '_stop', '_addRadarCue', '_buildScene', '_gotoNextCue', '_gotoPreviousCue', '_gotoFirstCue', '_gotoLastCue']\""
  "SHELL:-s EXTRA_EXPORTED_RUNTIME_METHODS=\"['ccall', 'cwrap']\""
  "SHELL:-s ENVIRONMENT=web"
  # "SHELL:-s ASSERTIONS=2"
  "SHELL:-s USE_BZIP2=1"
  "SHELL:-s FETCH=1"
  
)

# -----------------------------------------------------------------------------
# EXPORTED_FUNCTIONS=\"['_main', '_stop', '_addRadarCue', '_buildScene', '_gotoNextCue', '_gotoPreviousCue', '_gotoFirstCue', '_gotoLastCue']\""
# Compile example code
# -----------------------------------------------------------------------------

add_executable(SwisRadar SwisRadar.cxx SwisVtkRadarWindow.cxx SwisVtkGlobeRenderer.cxx SwisCapRenderer.cxx SwisLineCapActor.cxx SwisPolyCapActor.cxx SwisVtkMapRenderer.cxx SwisVtkRadarLegendRenderer.cxx SwisVtkRpgSuperResRefRenderer.cxx SwisVtkRpgSuperResVelRenderer.cxx SwisVtkScalarBarRenderer.cxx SwisRpgProdLoad.cxx)

target_link_libraries(SwisRadar
  PRIVATE
    VTK::FiltersSources
    VTK::InteractionStyle
    VTK::RenderingOpenGL2
    VTK::RenderingUI
    VTK::RenderingContext2D
    VTK::RenderingAnnotation
    VTK::RenderingVolumeOpenGL2
    VTK::RenderingVolume
    VTK::IOImage
    VTK::IOXML
    VTK::InfovisLayout
    VTK::GeovisCore
    VTK::ChartsCore
    VTK::IOLegacy
)

target_compile_options(SwisRadar
  PUBLIC
    ${emscripten_options}
)

target_link_options(SwisRadar
  PUBLIC
    ${emscripten_options}
)

# -----------------------------------------------------------------------------
# VTK modules initialization
# -----------------------------------------------------------------------------

vtk_module_autoinit(
  TARGETS  SwisRadar
  MODULES  ${VTK_LIBRARIES}
)

# -----------------------------------------------------------------------------
# Copy HTML to build directory
# -----------------------------------------------------------------------------

add_custom_command(
  TARGET SwisRadar
  COMMAND
    ${CMAKE_COMMAND} -E copy_if_different
      "${CMAKE_CURRENT_SOURCE_DIR}/SwisRadar.html"
      $<TARGET_FILE_DIR:SwisRadar>
)

Then I create a project folder in the directory: “build-examples-wasm\Emscripten\Cxx” and navigate to that folder. Then run the following command (changing the name to your project):

cmake \
  -G Ninja \
  -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} \
  -DVTK_DIR=/work/build-vtk-wasm \
  /work/src/Examples/Emscripten/Cxx/SwisRadar

And then run cmake --build .

1 Like