Skip to content

Commit 0da4fb9

Browse files
authored
Merge pull request #5 from jspanchu/update-cpp-docs
Update C++ docs - Added getting started and building VTK sections.
2 parents 38f8572 + e819318 commit 0da4fb9

File tree

6 files changed

+148
-4
lines changed

6 files changed

+148
-4
lines changed

docs/.vitepress/config.mjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ export default defineConfig({
5858
{
5959
text: 'For C++ developers',
6060
items: [
61-
// { text: 'Getting started', link: '/guide/cpp/index' },
62-
// { text: 'Tools', link: '/guide/cpp/tools' },
63-
// { text: 'Building an application', link: '/guide/cpp/app' },
61+
{ text: 'Getting started', link: '/guide/cpp/' },
62+
{ text: 'Building VTK', link: '/guide/cpp/setup' },
63+
{ text: 'Embind Simple', link: '/guide/cpp/app-1' },
64+
{ text: 'Embind Advanced', link: '/guide/cpp/app-2' },
65+
{ text: 'Plain JavaScript', link: '/guide/cpp/app-3' },
6466
]
6567
},
6668
{

docs/guide/cpp/app-1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Write the business logic of your application in C++ and wrap a simple interface to JavaScript with Embind.

docs/guide/cpp/app-2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
only wrap what you need from VTK.

docs/guide/cpp/app-3.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Enable code gen for serdes of C++ classes and initialize a standalone VTK session with your module's serdes registrar functions.

docs/guide/cpp/index.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,14 @@
1-
C++
1+
# VTK.wasm for C++ developers
2+
3+
This guide shows you how to compile VTK for WebAssembly, extend the functionality of VTK with your own C++ code and ultimately leverage your
4+
extensions to build 3D web visualization apps.
5+
6+
## Usage patterns
7+
8+
Writing parts of your application in C/C++ allows you to optimize data processing, IO, and rendering. In addition, you can integrate highly
9+
efficient third-party C++ libraries that were traditionally used only outside the browser. There are three approaches when choosing the C/C++
10+
approach for web apps in VTK.
11+
12+
1. [__Embind Simple__](./app-1.md): Write the business logic of your application in C++ and wrap a simple interface to JavaScript with Embind.
13+
2. [__Embind Advanced__](./app-2.md): Audit the VTK classes and only wrap what you need from VTK.
14+
3. [__Plain JavaScript__](./app-3.md): Enable code gen for serdes of C++ classes and initialize a standalone VTK session with your module's serdes registrar functions.

docs/guide/cpp/setup.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# Building VTK
2+
3+
## Tools
4+
5+
We will use the Emscripten SDK to compile C++ for wasm architecture. NodeJS will be used as a cross compiling emulator. CMake and Ninja are required to
6+
setup the project.
7+
8+
### Install requirements
9+
10+
First, clone VTK and checkout a release version.
11+
12+
```sh
13+
git clone https://gitlab.kitware.com/vtk/vtk.git
14+
```
15+
16+
Now, install NodeJS and EMSDK. Go to https://nodejs.org/en/download and follow the instructions for your platform.
17+
18+
::: code-group
19+
```sh [macOS/Linux]
20+
# Download and install fnm:
21+
curl -o- https://fnm.vercel.app/install | bash
22+
# Download and install Node.js
23+
fnm install 24.0.1
24+
fnm use 24.0.1
25+
26+
# Download and install EMSDK
27+
git clone https://github.com/emscripten-core/emsdk.git
28+
./emsdk/emsdk install 4.0.9
29+
export PATH=$PWD/emsdk/upstream/bin:$PWD/emsdk/upstream/emscripten:$PATH
30+
```
31+
```sh [Windows]
32+
# In Powershell
33+
# Download and install fnm:
34+
winget install Schniz.fnm
35+
# Download and install Node.js
36+
fnm install 24.0.1
37+
fnm env --use-on-cd --shell power-shell | Out-String | Invoke-Expression
38+
fnm use 24.0.1
39+
40+
git clone https://github.com/emscripten-core/emsdk.git
41+
.\emsdk\emsdk install 4.0.9
42+
$env:PATH="$PWD\emsdk\upstream\bin;$PWD\emsdk\upstream\emscripten;$env:PATH"
43+
```
44+
:::
45+
46+
Finally, download prebuilt webgpu static libraries and headers for `emdawnwebgpu`.
47+
48+
::: code-group
49+
```sh [wasm32:macOS/Linux]
50+
cd vtk
51+
CMAKE_CONFIGURATION="wasm32" cmake -P ./.gitlab/ci/download_dawn.cmake
52+
```
53+
```sh [wasm64:macOS/Linux]
54+
cd vtk
55+
CMAKE_CONFIGURATION="wasm64" cmake -P ./.gitlab/ci/download_dawn.cmake
56+
```
57+
```sh [wasm32:Windows]
58+
# In Powershell
59+
cd vtk
60+
$env:CMAKE_CONFIGURATION="wasm32"
61+
cmake -P .\.gitlab\ci\download_dawn.cmake
62+
```
63+
```sh [wasm64:Windows]
64+
# In Powershell
65+
cd vtk
66+
$env:CMAKE_CONFIGURATION="wasm64"
67+
cmake -P .\.gitlab\ci\download_dawn.cmake
68+
```
69+
:::
70+
71+
## Building VTK
72+
73+
:::code-group
74+
```sh [wasm32:macOS/Linux]
75+
emcmake cmake \
76+
-S . \
77+
-B buildRelease \
78+
-G "Ninja" \
79+
-DCMAKE_BUILD_TYPE=Release \
80+
-DBUILD_SHARED_LIBS:BOOL=OFF \
81+
-DVTK_ENABLE_WEBGPU:BOOL=ON \
82+
-Demdawnwebgpu_DIR="$PWD/.gitlab/dawn/lib/cmake/emdawnwebgpu"
83+
cmake --build ./buildRelease
84+
cmake --install ./buildRelease --prefix ./installRelease
85+
```
86+
```sh [wasm64:macOS/Linux]
87+
emcmake cmake \
88+
-S . \
89+
-B buildRelease \
90+
-G "Ninja" \
91+
-DCMAKE_BUILD_TYPE=Release \
92+
-DBUILD_SHARED_LIBS:BOOL=OFF \
93+
-DVTK_ENABLE_WEBGPU:BOOL=ON \
94+
-DVTK_WEBASSEMBLY_64_BIT:BOOL=ON \
95+
-Demdawnwebgpu_DIR="$PWD/.gitlab/dawn/lib/cmake/emdawnwebgpu"
96+
cmake --build ./buildRelease
97+
cmake --install ./buildRelease --prefix ./installRelease
98+
```
99+
```sh [wasm32:Windows]
100+
# In Powershell
101+
emcmake cmake `
102+
-S . `
103+
-B buildRelease `
104+
-G "Ninja" `
105+
-DCMAKE_BUILD_TYPE=Release `
106+
-DBUILD_SHARED_LIBS:BOOL=OFF `
107+
-DVTK_ENABLE_WEBGPU:BOOL=ON `
108+
-Demdawnwebgpu_DIR="$PWD\.gitlab\dawn\lib\cmake\emdawnwebgpu"
109+
cmake --build .\buildRelease
110+
cmake --install .\buildRelease --prefix .\installRelease
111+
```
112+
```sh [wasm64:Windows]
113+
# In Powershell
114+
emcmake cmake `
115+
-S . `
116+
-B buildRelease `
117+
-G "Ninja" `
118+
-DCMAKE_BUILD_TYPE=Release `
119+
-DBUILD_SHARED_LIBS:BOOL=OFF `
120+
-DVTK_ENABLE_WEBGPU:BOOL=ON `
121+
-DVTK_WEBASSEMBLY_64_BIT:BOOL=ON `
122+
-Demdawnwebgpu_DIR="$PWD\.gitlab\dawn\lib\cmake\emdawnwebgpu"
123+
cmake --build .\buildRelease
124+
cmake --install .\buildRelease --prefix .\installRelease
125+
```
126+
:::

0 commit comments

Comments
 (0)