Project Layout

Summary

In this section, we will discuss the layout and directory structure of the Basic Application tutorial.

Concepts

  • Introduction to the npm/Vite development environment
  • Required packages

Unlike the very first version of this tutorial, this version builds its UI out of packaged Web Components (@ts3d-hoops/web-viewer-components) rather than plain HTML. Those components are distributed as ES modules with real package dependencies (lit, @lit/context, etc.), so they need to go through Node module resolution and a bundler rather than being referenced directly by a <script> tag.

Note

If you would rather avoid a build step entirely, the HOOPS Web Viewer engine itself (@ts3d-hoops/web-viewer) is still available as a plain, dependency-free ESM/IIFE/UMD bundle you can drop into a page with no tooling at all. See the legacy tutorial for that path. This tutorial’s trade-off is: a small amount of npm/bundler setup, in exchange for ready-made toolbar, model tree, and panel components instead of hand-rolled HTML controls.

We use Vite here because that’s what the packages themselves are developed and tested against, but any modern bundler (webpack, esbuild, Rollup) that supports ES modules will work.

Note

All JavaScript/TypeScript provided by HOOPS Visualize Web is written to modern ECMAScript standards with TypeScript declaration files included, so it works equally well in plain TypeScript projects or inside frameworks such as React, Vue, or Angular.

Sample Code

In your installation directory for HOOPS Visualize Web, we have provided a library of sample code that corresponds to tutorials in this documentation. There is a directory named basic_app that holds all of the starting files you need to start this tutorial. You will find other directories with names that correspond to the tutorials listed in the sidebar to the left under Tutorials.

<INSTALL_DIR>
├── tutorials
│   ├── basic_app
│   │   ├── index.html
│   │   ├── package.json
│   │   ├── vite.config.ts
│   │   ├── public
│   │   │   └── engine.esm.wasm
│   │   ├── src
│   │   │   └── main.ts

Let’s take a closer look at the contents of the basic_app directory.

  • package.json – Declares our project’s dependency on @ts3d-hoops/web-viewer-components (see Copying Files below).
  • vite.config.ts – A minimal Vite configuration; no special options are required for this tutorial.
  • public/ – Static files Vite copies verbatim into the built output without processing them. Holds engine.esm.wasm, the WebAssembly binary that does the actual rendering (see below).
  • src/ – This directory will contain all of the TypeScript files for our application.

Copying Files

The HOOPS Visualize Web packages are located in <INSTALL_DIR>/web_viewer/@ts3d-hoops:

<INSTALL_DIR>
└── web_viewer
        └── @ts3d-hoops
                ├── web-viewer
                ├── sc-engine
                ├── ui-kit
                └── web-viewer-components

Copy the @ts3d-hoops folder to the root of your project (npm needs it to be a sibling of your own package.json in order to resolve inter-package dependencies correctly), then install the package this tutorial uses directly:

npm install ./@ts3d-hoops/web-viewer-components

This will also pull in @ts3d-hoops/web-viewer and @ts3d-hoops/ui-kit as transitive dependencies, since web-viewer-components depends on both.

@ts3d-hoops/web-viewer-components renders using the base @ts3d-hoops/web-viewer package, which needs a WebAssembly binary, engine.esm.wasm, at runtime. Copy it from @ts3d-hoops/sc-engine/engine.esm.wasm into a new public folder at your project root:

mkdir -p public
cp @ts3d-hoops/sc-engine/engine.esm.wasm public/engine.esm.wasm

Vite copies anything in public/ into the site root as-is, both for the dev server and for a production build, so once it’s there the Web Viewer finds it automatically with no further configuration - it looks for /engine.esm.wasm by default. (If your application is ever served from a subpath rather than a domain root, or you’d rather host the binary somewhere else, set the enginePath attribute or property on <hoops-web-viewer> to the directory that contains it instead.)

Note

You may also see a separate @ts3d-hoops/web-viewer-monolith package in web_viewer/@ts3d-hoops, which embeds this same binary directly inside its own JS bundle instead of loading it separately. Don’t combine it with @ts3d-hoops/web-viewer-components (or with @ts3d-hoops/web-viewer imported directly) in the same application - each of those packages is prebuilt independently, and once a bundler like Vite processes them together, the monolith’s embedded binary never actually reaches the code that web-viewer-components/web-viewer uses to render, so the viewer fails at startup with “Unable to load engine binary”. Hosting engine.esm.wasm as a static file, as described above, is the approach this tutorial uses throughout.

To keep things simple, we will use only a handful of the packaged components in this tutorial (the viewer itself, the model tree, and a couple of toolbar buttons); everything else in @ts3d-hoops/web-viewer-components can be added the same way as your application grows.