Requirements
- A browser app that uses a bundler, such as Vite.
- Three.js
0.168. Floorkit makes Three.js objects and your app shows them. - TypeScript is optional. The package includes its type declarations.
Install the package
1
Add Floorkit and its peer packages
@opengeometry/catalog is a peer package: Floorkit reads and builds each catalog block with its reader, so your app has one copy of it. It is not on npm: it installs from its private GitHub repository, OpenGeometry-io/floorkit-catalog, at a fixed commit, so the install needs read access to that repository with your local git credentials. npm 7 or later installs peers by itself; name it as above for a package manager that does not. opengeometry is the geometry kernel. Floorkit installs it as a dependency. Install it directly too, because the next step imports its WebAssembly file.2
Start the geometry kernel
The kernel is a WebAssembly file, and it makes the display meshes in a worker file. Give both addresses to Floorkit one time, when your app starts. With Vite, the Wait for this call to finish before you create geometry. To make the meshes without a worker, pass
?url import gives you each address.{ tessellation: 'inline' } in place of { workerURL }.3
Keep the kernel out of the Vite pre-bundle
Vite pre-bundles packages and moves their files. Tell it to leave
opengeometry as it is. Put this in vite.config.ts:4
Add the Vite types
TypeScript must know the
?url import. A new Vite app knows it already: its tsconfig.json has "types": ["vite/client"]. If yours does not, put this line in src/vite-env.d.ts:Use one copy of Three.js
The text package currently depends on a different Three.js version. Tell npm to use your app’s version everywhere. Add this field to your app’spackage.json, then run the install commands above:
npm ls three should show one version. If you installed before adding the override, follow Troubleshooting.
Use a different bundler
Floorkit needs only the addresses ofopengeometry_bg.wasm and tessellation-worker.js. Each bundler that can copy a file and give you its address works. You can also copy the two files into your public folder and pass their paths as text.
Import from one place
All classes, functions and types come from the package root:Next steps
Quickstart
Show a room with a door and a window.
Troubleshooting
Fix an install or a start-up problem.