Project Layout

Summary

In this chapter, we will discuss the layout and directory structure of the Inventory Management tutorial. The tutorial is structured so that you can add code snippets as you read. If you’d like to see the completed tutorial, it is located in the completed branch of the repository.

Concepts

  • Introduction to the npm/Vite development environment
  • Required packages
  • Overview of provided files

Like the Building A Basic Application tutorial, this tutorial builds its UI out of packaged Web Components (@ts3d-hoops/web-viewer-components) rather than a hand-rolled <div> and a direct new WebViewer(...) call. 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. We use Vite here, the same as the Basic Application tutorial, but any modern bundler that supports ES modules will work equally well.

These tutorials will use a working development environment to enable you to code along through this exercise. If you have not already reviewed the Environment setup section of these tutorials, please do that first.

Once you have your IDE set up and Node.js installed, open the Inventory Management project directory in your editor.

<INSTALL_DIR>
├── tutorials
│   ├── inventory_management // HERE
│   │   ├── data
│   │   │   ├── database
│   │   │   ├── thumbnails
│   │   │   └── xml
│   │   ├── favicon.ico
│   │   ├── img
│   │   ├── index.html
│   │   ├── package.json
│   │   ├── vite.config.ts
│   │   ├── public
│   │   │   └── engine
│   │   │       └── engine.esm.wasm
│   │   └── src
│   │       ├── css
│   │       └── js
│   │           └── completed_reference_code

A brief overview of this directory structure:

  • data – contains the provided .SCS model data and subdirectories
    • database – user data linking the node IDs to additional data
    • thumbnails – thumbnails for models that will be used
    • xml – xml output directory for converted models
  • public – static files Vite copies verbatim into the served/built output without processing them. Holds the graphics engine’s engine.esm.wasm binary (see Copying Files below).
  • src – source code for the application
    • css – style sheets for the application
    • img – static image assets used by the application
    • js – where we will write and place our application Javascript files, starting from a blank app.js
      • completed_reference_code - a directory containing a completed JavaScript implementation of this tutorial for your reference
  • favicon.ico – TS3D favicon
  • index.html – defines the document hierarchy and entry point of our application; the HTML and CSS have been provided for you
  • 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

In order to focus more on the HOOPS Visualize Web WebViewer API, we have provided the HTML, CSS, and project configuration files for you, so you do not need to write them yourself.

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/engine folder at your project root:

mkdir -p public/engine
cp @ts3d-hoops/sc-engine/engine.esm.wasm public/engine/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 at /engine/engine.esm.wasm with no further configuration, matching the enginePath="./engine" attribute we will set on <hoops-web-viewer> in the next chapter.

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 the base <hoops-web-viewer> component in this tutorial; everything else in @ts3d-hoops/web-viewer-components can be added the same way as your application grows.