// Outlines — a Meep example for the `Outline` component.
//
// Three loaded props stand behind a low wall, three shapes built in code stand
// in front of it. Each wears an `Outline`, and between them they use every part
// of an `OutlineSpec`:
//
// chair a plain solid line
// bag a line, a soft fade beyond it and a faint fill; the fade breathes
// bookcase a line cut into dashes by a mask
// behind the wall, all three: a hidden spec, a thin line and a striped fill
// knot + octahedron one spec shared by both, a line and a dotted fill:
// a shared spec outlines its entities as one shape
// box a fill and no line
//
// How outlining works:
//
// - `Outline` holds two `OutlineSpec`s. `visible` draws where the entity is
// the front surface; `hidden` draws where other geometry stands in front of
// it, over that geometry. `OutlineSpec.NONE` draws nothing.
// - An `OutlineSpec` is one look: a solid line `solid_width` output pixels
// wide, a soft fade a further `soft_width` pixels beyond it, a fill over the
// object, and a black-and-white mask for the line and one for the fill, each
// tiled across the screen at one texel per pixel.
// - Specs are held by reference and read every frame. Edit one in place and
// every entity holding it changes on the next frame; hand the same spec to
// several entities and they are outlined as one shape.
// - Three systems draw them. `OutlineSystem` owns the pass and observes no
// entities. Two pairing systems tell it what to outline:
// `SGMeshOutlineSystem` for a loaded model (`Outline + SGMesh`) and
// `ShadedGeometryOutlineSystem` for a primitive built in code
// (`Outline + ShadedGeometry`).
//
// Sections:
// §1 Tuning constants
// §2 Engine bootstrap loaders, MeshSystem, the outline pass + its two pairing systems
// §3 Masks two black-and-white patterns drawn into a canvas
// §4 Specs every look in the scene
// §5 Ground and wall
// §6 The props three models behind the wall
// §7 The primitives three shapes in front of it
// §8 Per-frame turn everything, breathe the glow
import { EngineHarness } from "@woosh/meep-engine/src/engine/EngineHarness.js";
import TopDownCameraController from "@woosh/meep-engine/src/engine/graphics/ecs/camera/topdown/TopDownCameraController.js";
import { Light } from "@woosh/meep-engine/src/engine/graphics/ecs/light/Light.js";
import { LightType } from "@woosh/meep-engine/src/engine/graphics/ecs/light/LightType.js";
import { GameAssetType } from "@woosh/meep-engine/src/engine/asset/GameAssetType.js";
import { load_model_scene_bundle } from "@woosh/meep-engine/src/engine/asset/load_model_scene_bundle.js";
import { ArrayBufferLoader } from "@woosh/meep-engine/src/engine/asset/loaders/ArrayBufferLoader.js";
import {
GLTFSceneBundleAssetLoader
} from "@woosh/meep-engine/src/engine/asset/loaders/GLTFSceneBundleAssetLoader.js";
import {
ImageBitmapAssetLoader
} from "@woosh/meep-engine/src/engine/asset/loaders/image/ImageBitmapAssetLoader.js";
import { ImageRGBADataLoader } from "@woosh/meep-engine/src/engine/asset/loaders/image/ImageRGBADataLoader.js";
import Entity from "@woosh/meep-engine/src/engine/ecs/Entity.js";
import { ParentEntitySystem } from "@woosh/meep-engine/src/engine/ecs/parent/ParentEntitySystem.js";
import {
TransformAttachmentSystem
} from "@woosh/meep-engine/src/engine/ecs/transform-attachment/TransformAttachmentSystem.js";
import { Transform64 } from "@woosh/meep-engine/src/engine/ecs/transform/Transform64.js";
import { t64_announce_change } from "@woosh/meep-engine/src/engine/ecs/transform/t64_announce_change.js";
import { Outline } from "@woosh/meep-engine/src/engine/graphics/ecs/outline/Outline.js";
import { OutlineSpec } from "@woosh/meep-engine/src/engine/graphics/ecs/outline/OutlineSpec.js";
import { SGMeshOutlineSystem } from "@woosh/meep-engine/src/engine/graphics/ecs/outline/SGMeshOutlineSystem.js";
import {
ShadedGeometryOutlineSystem
} from "@woosh/meep-engine/src/engine/graphics/ecs/outline/ShadedGeometryOutlineSystem.js";
import { OutlineSystem } from "@woosh/meep-engine/src/engine/graphics3/OutlineSystem.js";
import { SGMesh } from "@woosh/meep-engine/src/engine/graphics/ecs/mesh-v2/aggregate/SGMesh.js";
import { ShadedGeometry } from "@woosh/meep-engine/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.js";
import { MeshSystem } from "@woosh/meep-engine/src/engine/graphics3/MeshSystem.js";
import { ShadedGeometrySystem } from "@woosh/meep-engine/src/engine/graphics3/ShadedGeometrySystem.js";
import { make_box_geometry } from "@woosh/meep-engine/src/shade/renderer/geometry/primitives/make_box_geometry.js";
import {
make_octahedron_geometry
} from "@woosh/meep-engine/src/shade/renderer/geometry/primitives/make_octahedron_geometry.js";
import {
make_torus_knot_geometry
} from "@woosh/meep-engine/src/shade/renderer/geometry/primitives/make_torus_knot_geometry.js";
import {
meshlet_geometry_build_from_geometry
} from "@woosh/meep-engine/src/shade/renderer/geometry/meshlet_geometry_build_from_geometry.js";
import { StandardShadeMaterial } from "@woosh/meep-engine/src/shade/renderer/material/StandardShadeMaterial.js";
import { Color } from "@woosh/meep-engine/src/core/color/Color.js";
import Vector3 from "@woosh/meep-engine/src/core/geom/Vector3.js";
import Quaternion from "@woosh/meep-engine/src/core/geom/Quaternion.js";
// ─── §1 Tuning constants ────────────────────────────────────────────────────
const SPACING = 3.4; // distance between neighbours in a row, metres
const PROP_Z = 1.3; // the props stand this far behind the wall
const PRIMITIVE_Z = -3.2; // the primitives this far in front of it
const WALL_HEIGHT = 1.3; // low enough to see over, high enough to hide
// the lower part of every prop behind it
const TURN_RATE = 0.3; // rad/s: a slow turn, so the outlines follow
// changing silhouettes
const GROUND_COLOR = "#161c24"; // near-black floor; the outlines carry the colour
const WALL_COLOR = "#3a4350";
const PRIMITIVE_COLOR = "#8b98a8";
const PROP_URL_BASE = "./models/fantasy-props/";
// ─── §2 Engine bootstrap ────────────────────────────────────────────────────
//
// Outlining a model takes the model's own systems plus three for the outline:
//
// - `MeshSystem` turns an `SGMesh`'s URL into a subtree of entities, one
// `ShadedGeometry` per glTF primitive, and `ShadedGeometrySystem` draws
// them (and the ground, the wall and the code-built shapes).
// - `OutlineSystem` is the pass. It takes the asset manager because a spec's
// masks are textures it loads by URL, as `GameAssetType.Image`.
// - `SGMeshOutlineSystem` is handed the mesh system, which it asks every frame
// which primitives a model spawned; `ShadedGeometryOutlineSystem` needs
// nothing more, since a primitive is its own single row.
//
// `ParentEntitySystem` + `TransformAttachmentSystem` tie a model's subtree to
// the prop entity, lifetime and pose.
let meshSystem = null;
let outlineSystem = null;
const engine = await EngineHarness.bootstrap({
configuration: (config, engine) => {
const scene = EngineHarness.shadeScene(engine);
// glTF yields a `SceneBundle` whose `.bin` buffers and images are
// requested back through the asset manager.
const gltfLoader = new GLTFSceneBundleAssetLoader();
config.addLoader(GameAssetType.ModelGLTF, gltfLoader);
config.addLoader(GameAssetType.ModelGLTF_JSON, gltfLoader);
config.addLoader(GameAssetType.ArrayBuffer, new ArrayBufferLoader());
config.addLoader(GameAssetType.ImageBitmap, new ImageBitmapAssetLoader());
// the outline masks
config.addLoader(GameAssetType.Image, new ImageRGBADataLoader());
meshSystem = new MeshSystem(
engine.graphics,
scene,
(url) => load_model_scene_bundle(engine.assetManager, url),
);
config.addSystem(meshSystem);
config.addSystem(new ShadedGeometrySystem(engine.graphics, scene));
config.addSystem(new ParentEntitySystem());
config.addSystem(new TransformAttachmentSystem());
// One pass draws every outline, because outlines share space: two passes
// would paint over each other. The pairing systems only say which rows
// each entity's outline covers.
outlineSystem = new OutlineSystem(engine.graphics, scene, engine.assetManager);
config.addSystem(outlineSystem);
config.addSystem(new SGMeshOutlineSystem(outlineSystem, meshSystem));
config.addSystem(new ShadedGeometryOutlineSystem(outlineSystem));
},
});
await EngineHarness.buildBasics({
engine,
enableTerrain: false,
enableWater: false,
enableLights: true,
enableShadows: true,
focus: new Vector3(0, 0.6, -0.8),
distance: 12.5,
pitch: 0.6,
yaw: 0,
// the sun's shadow cascades spread over the camera's whole near..far range,
// so far is three opening distances and zooming out stops at two (below)
cameraFarDistance: 45,
showFps: false,
});
engine.entityManager.dataset.getAnyComponent(TopDownCameraController).component.distanceMax = 30;
// Exposure and key light, the same in every demo on this site: automatic
// exposure off, so two screenshots of the same demo agree, and a directional
// light bright enough to be read as lux.
engine.graphics.renderer.feature_automatic_exposure_enabled = false;
engine.entityManager.dataset.traverseEntities([Light], (light) => {
if (light.type.getValue() === LightType.DIRECTION) {
light.intensity.set(6);
}
});
const ecd = engine.entityManager.dataset;
ecd.registerComponentType(Outline);
// ─── §3 Masks ───────────────────────────────────────────────────────────────
//
// A mask is a black-and-white texture named by URL. It is tiled across the
// screen at one texel per output pixel, and its red channel `m` scales the part
// it masks by `saturate(m * scale + offset)`. A data URL drawn into a canvas is
// as good a URL as any, so these two need no files.
/**
* Diagonal stripes, `period` texels from one stripe to the next.
* @param {number} period
* @returns {string}
*/
function stripeMask(period) {
const canvas = document.createElement("canvas");
canvas.width = period;
canvas.height = period;
const context = canvas.getContext("2d");
const image = context.createImageData(period, period);
for (let y = 0; y < period; y++) {
for (let x = 0; x < period; x++) {
const v = ((x + y) % period) < period / 2 ? 255 : 0;
const i = (y * period + x) * 4;
image.data[i] = v;
image.data[i + 1] = v;
image.data[i + 2] = v;
image.data[i + 3] = 255;
}
}
context.putImageData(image, 0, 0);
return canvas.toDataURL("image/png");
}
/**
* A grid of dots, one per `cell` texels.
* @param {number} cell
* @returns {string}
*/
function dotMask(cell) {
const canvas = document.createElement("canvas");
canvas.width = cell;
canvas.height = cell;
const context = canvas.getContext("2d");
context.fillStyle = "#000";
context.fillRect(0, 0, cell, cell);
context.fillStyle = "#fff";
context.beginPath();
context.arc(cell / 2, cell / 2, cell * 0.3, 0, Math.PI * 2);
context.fill();
return canvas.toDataURL("image/png");
}
// ─── §4 Specs ───────────────────────────────────────────────────────────────
//
// Colours are linear RGB with straight alpha: they go into the frame before
// tone mapping, so they are not sRGB hex the way a material's colour is.
// Widths are output pixels, so an outline is as wide at every distance.
// A plain solid line.
const line = new OutlineSpec();
line.solid_color.set(1, 1, 1, 1);
line.solid_width = 2;
// A line, a soft fade beyond it and a faint fill: a glow. §8 breathes the fade
// between 6 and 18 px by editing this spec in place.
const glow = new OutlineSpec();
glow.solid_color.set(1.0, 0.62, 0.18, 1);
glow.solid_width = 2;
glow.soft_color.set(1.0, 0.62, 0.18, 0.7);
glow.soft_width = 12;
glow.fill_color.set(1.0, 0.62, 0.18, 0.1);
// A line cut into dashes: stripes 12 texels apart mask it.
const dashed = new OutlineSpec();
dashed.solid_color.set(0.3, 0.85, 1.0, 1);
dashed.solid_width = 4;
dashed.outline_mask = stripeMask(12);
// What the props look like where the wall hides them: a thin line and a striped
// fill. The mask's offset keeps the dark stripes faintly filled rather than
// empty. One spec for all three props.
const xray = new OutlineSpec();
xray.solid_color.set(0.6, 0.5, 1.0, 1);
xray.solid_width = 1.5;
xray.fill_color.set(0.6, 0.5, 1.0, 0.5);
xray.fill_mask = stripeMask(8);
xray.fill_mask_offset = 0.15;
// A line and a dotted fill, shared by the knot and the octahedron, which are
// outlined as one shape where they meet.
const group = new OutlineSpec();
group.solid_color.set(0.31, 0.94, 0.66, 1);
group.solid_width = 2;
group.fill_color.set(0.31, 0.94, 0.66, 0.4);
group.fill_mask = dotMask(10);
// A fill and no line.
const tint = new OutlineSpec();
tint.solid_width = 0;
tint.fill_color.set(1.0, 0.25, 0.2, 0.45);
/**
* @param {OutlineSpec} visible
* @param {OutlineSpec} hidden
* @returns {Outline}
*/
function outline(visible, hidden) {
const o = new Outline();
o.visible = visible;
o.hidden = hidden;
return o;
}
// ─── §5 Ground and wall ─────────────────────────────────────────────────────
//
// Plain boxes. Clustering a geometry runs the meshoptimizer WASM module, which
// is ready only once the engine has bootstrapped, hence built here rather than
// at module scope.
function material(hex, roughness) {
const m = new StandardShadeMaterial();
m.diffuse_color.copy(Color.from_sRGB_to_linear(Color.parse(hex)));
m.roughness_factor = roughness;
m.metallic_factor = 0;
return m;
}
function box(width, height, depth, x, y, z, mat) {
const t = new Transform64();
t.setTranslation(x, y, z);
return new Entity()
.add(t)
.add(ShadedGeometry.from(
meshlet_geometry_build_from_geometry(make_box_geometry(width, height, depth)),
mat,
))
.build(ecd);
}
box(3 * SPACING + 2.5, 0.5, 8, 0, -0.25, -1, material(GROUND_COLOR, 1));
box(3 * SPACING + 1, WALL_HEIGHT, 0.3, 0, WALL_HEIGHT / 2, 0, material(WALL_COLOR, 0.9));
// ─── §6 The props ───────────────────────────────────────────────────────────
//
// The `Outline` goes on the prop entity itself, the one carrying `SGMesh`, not
// on the primitives `MeshSystem` builds under it. A model still loading has no
// primitives yet; it starts being outlined when they arrive.
const turners = []; // transforms to turn in §8
const PROPS = [
{ url: "chair.gltf", visible: line },
{ url: "bag-big.gltf", visible: glow },
{ url: "bookcase.gltf", visible: dashed },
];
for (let i = 0; i < PROPS.length; i++) {
const p = PROPS[i];
const t = new Transform64();
t.setTranslation((i - 1) * SPACING, 0, PROP_Z);
const entity = new Entity()
.add(t)
.add(SGMesh.fromURL(PROP_URL_BASE + p.url))
.add(outline(p.visible, xray))
.build(ecd);
turners.push({ transform: t, entity, phase: i * 1.3 });
}
// ─── §7 The primitives ──────────────────────────────────────────────────────
//
// Shapes built in code, each a single `ShadedGeometry`. Nothing stands in front
// of them, so they carry no hidden spec. The knot and the octahedron stand close
// enough to touch and share `group`, so their outlines merge into one.
const primitiveMaterial = material(PRIMITIVE_COLOR, 0.4);
const PRIMITIVES = [
{ geometry: () => make_torus_knot_geometry(0.62, 0.2, 96, 14), x: -SPACING * 0.95, y: 0.95, visible: group },
{ geometry: () => make_octahedron_geometry(0.9), x: -SPACING * 0.45, y: 0.95, visible: group },
{ geometry: () => make_box_geometry(1.2, 1.2, 1.2), x: SPACING, y: 0.7, visible: tint },
];
for (let i = 0; i < PRIMITIVES.length; i++) {
const p = PRIMITIVES[i];
const t = new Transform64();
t.setTranslation(p.x, p.y, PRIMITIVE_Z);
const entity = new Entity()
.add(t)
.add(ShadedGeometry.from(meshlet_geometry_build_from_geometry(p.geometry()), primitiveMaterial))
.add(outline(p.visible, OutlineSpec.NONE))
.build(ecd);
turners.push({ transform: t, entity, phase: 2.1 + i * 0.9 });
}
// ─── §8 Per-frame: turn everything, breathe the glow ───────────────────────
let time = 0;
const spin = new Quaternion(); // scratch for the per-frame turn
let lastFrameMs = performance.now();
engine.graphics.on.postRender.add(() => {
const nowMs = performance.now();
const dt = Math.min((nowMs - lastFrameMs) / 1000, 0.1);
lastFrameMs = nowMs;
time += dt;
// A Transform64 has no signals: a write is invisible until the entity
// announces it. A model's primitives follow through TransformAttachmentSystem;
// the outline follows whatever the frame draws.
for (let i = 0; i < turners.length; i++) {
const s = turners[i];
spin.fromAxisAngle(Vector3.up, TURN_RATE * time + s.phase);
s.transform.setRotation(spin.x, spin.y, spin.z, spin.w);
s.transform.updateMatrix();
t64_announce_change(ecd, s.entity);
}
// Specs are read every frame, so an edit in place shows on the next one.
const breath = 0.5 + 0.5 * Math.sin(time * 2.5);
glow.soft_width = 6 + 12 * breath;
glow.soft_color.setA(0.35 + 0.45 * breath);
});
// A handle for poking at the demo from the console: edit a spec in
// `__outline.specs` and the outlines follow on the next frame.
window.__outline = {
engine, ecd, turners, meshSystem, outlineSystem,
specs: { line, glow, dashed, xray, group, tint },
components: { Transform64, SGMesh, ShadedGeometry, Outline, OutlineSpec },
};
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Outlines · Meep</title>
<meta name="robots" content="noindex">
<style>
*, *::before, *::after { box-sizing: border-box; }
html, body {
margin: 0; padding: 0;
width: 100%; height: 100%;
overflow: hidden;
background: #07090c;
color: #e6edf3;
font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
user-select: none;
}
.hint { position: fixed; z-index: 100; bottom: 1rem; right: 1rem; margin: 0; padding: 0.55rem 0.85rem; background: rgba(7, 9, 12, 0.76); border: 1px solid #1f2731; border-radius: 10px; backdrop-filter: blur(10px); box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4); color: #9aa5b1; font-size: 0.78rem; pointer-events: none; }
@media (max-width: 650px) { .hint { display: none; } }
</style>
</head>
<body>
<p class="hint">Drag to orbit · Scroll to zoom</p>
<script type="module" src="./src/main.js"></script>
</body>
</html>
{
"title": "Outlines",
"description": "Three glTF props behind a low wall and three shapes built in code in front of it, each wearing an Outline: a plain line, a breathing soft glow, a mask-dashed line, a fill with no line, and one spec shared by two shapes that merge into one outline. Where the wall hides a prop, its hidden spec draws a striped x-ray over the wall.",
"category": "Rendering",
"status": "live",
"order": 6,
"tags": [
"rendering",
"outline",
"highlight",
"selection",
"x-ray",
"gltf",
"ecs",
"primitives"
],
"sourceHint": "examples-src/highlight/",
"demoUrl": "/examples/highlight/demo.html",
"defaultFile": "src/main.js"
}
{
"name": "@meep-examples/highlight",
"version": "0.1.0",
"private": true,
"type": "module",
"description": "A 3x3 grid of glTF props showing every Highlight outline configuration — solid colors, opacity, stacked definitions, and live pulse/hue-cycle mutations.",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"@woosh/meep-engine": "3.71.0"
},
"devDependencies": {
"@rollup/plugin-strip": "^3.0.4",
"vite": "^8.0.13"
}
}
# Outlines
Three glTF props stand behind a low wall and three shapes built in code stand in
front of it. Each wears an `Outline`, and between them they use every part of an
`OutlineSpec`:
| Entity | Visible spec | Hidden spec |
| --- | --- | --- |
| chair | a 2 px white line | the shared x-ray |
| bag | a line, a soft fade that breathes between 6 and 18 px, and a faint fill | the shared x-ray |
| bookcase | a 4 px line cut into dashes by a striped mask | the shared x-ray |
| torus knot + octahedron | one shared spec: a line and a dot-masked fill | none |
| box | a translucent fill and no line | none |
The x-ray is one spec held by all three props: a thin violet line and a
stripe-masked fill, drawn over the wall wherever the wall hides a prop.
What it demonstrates:
- `Outline` holds two specs. `visible` draws where the entity is the front
surface; `hidden` draws where other geometry stands in front of it, over that
geometry. `OutlineSpec.NONE` draws nothing. A fresh `Outline` holds two fresh
specs, a 2 px white line each, so set the side you do not want to
`OutlineSpec.NONE`.
- `OutlineSpec` is one look: a solid line (`solid_color`, `solid_width`), a
soft fade beyond it (`soft_color`, whose alpha is where the fade starts, and
`soft_width`), a fill over the object (`fill_color`), and a mask for the line
and one for the fill. Widths are output pixels, so a line is as wide at every
distance. Colours are linear RGB with straight alpha.
- A mask is a black-and-white texture named by URL (`outline_mask`,
`fill_mask`), tiled across the screen at one texel per output pixel. Its red
channel `m` scales its part by `saturate(m * scale + offset)`. Both masks here
are drawn into a canvas and handed over as PNG data URLs, so the example ships
no mask files. The x-ray's `fill_mask_offset = 0.15` keeps the dark stripes
faintly filled.
- Specs are held by reference and read every frame. The bag's glow breathes
because the per-frame callback edits `glow.soft_width` and `glow.soft_color`
in place. Every entity holding a spec changes with it.
- A spec shared by several entities outlines them as one shape. The knot and the
octahedron stand close enough to touch and hold the same spec, so where they
meet their outlines merge into one silhouette.
## How it is wired
```js
const outlineSystem = new OutlineSystem(engine.graphics, scene, engine.assetManager);
config.addSystem(outlineSystem);
config.addSystem(new SGMeshOutlineSystem(outlineSystem, meshSystem)); // loaded models
config.addSystem(new ShadedGeometryOutlineSystem(outlineSystem)); // primitives
```
`OutlineSystem` owns the pass and observes no entities. The two pairing systems
tell it which mesh rows each entity's outline covers: `SGMeshOutlineSystem`
asks the mesh system every frame which primitives a model spawned, so the
`Outline` goes on the prop entity itself and a model that is still loading
starts being outlined when it arrives; `ShadedGeometryOutlineSystem` outlines a
primitive's own row. The asset manager is there for the masks, which load as
`GameAssetType.Image`, so the example registers `ImageRGBADataLoader` for that
type. Pass `null` when no spec names a mask.
## Run
```sh
npm install
npm run dev
```
## Build
`npm run build` emits the static demo into `public/examples/highlight/`, with
`models/fantasy-props/` copied through from this example's `public/` folder.
## Assets
Three fantasy props under `public/models/fantasy-props/`: `chair`, `bag-big`
and `bookcase`, copied from the `entity-stress-test` example, which uses the
same prop set. Each contributes:
- `<name>.gltf`
- `<name>.bin` (sibling buffer the glTF references)
- the shared `diffuse_1024.png` every one of their materials samples
The prop set is not authored here and carries no licence note in this
repository (see `examples-src/entity-stress-test/README.md`, which says to
bring your own). Any glTF set will do. Swap the file names in `PROPS` in
`src/main.js`, as long as each prop ships its `.bin` and its texture.
import { defineConfig } from "vite";
import { copyFileSync, existsSync, mkdirSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { resolve, dirname } from "node:path";
import strip from "@rollup/plugin-strip";
const __dirname = dirname(fileURLToPath(import.meta.url));
export default defineConfig({
// Vite's dependency pre-bundling rewrites the engine's own asset imports and
// loses their URLs, so a dev server ends up serving ".../deps/undefined" for
// the renderer's data files. The engine is source-only ESM and needs no
// pre-bundling - but its CommonJS dependencies do, or the import of them from inside
// the excluded engine finds no default export.
optimizeDeps: {
exclude: ["@woosh/meep-engine"],
include: ["dat.gui", "opentype.js"],
},
plugins: [
{
// Copy the committed source thumbnail into the generated gallery folder.
// public/examples/<id>/ is build output (gitignored); thumbnail.png is
// kept in source here and copied through on every build so the gallery
// (src/data/examples.ts) can resolve it.
name: "copy-thumbnail",
apply: "build",
closeBundle() {
const thumb = resolve(__dirname, "thumbnail.png");
const dst = resolve(__dirname, "../../public/examples/highlight");
if (existsSync(thumb)) {
mkdirSync(dst, { recursive: true });
copyFileSync(thumb, resolve(dst, "thumbnail.png"));
}
},
},
],
base: "./",
build: {
outDir: resolve(__dirname, "../../public/examples/highlight"),
emptyOutDir: false,
rollupOptions: {
input: resolve(__dirname, "demo.html"),
plugins: [
{
// this will remove all assert statements from the production build
...strip(),
apply: 'build'
}
],
},
target: "es2022",
},
});