geop-cad-web
This page is a reference to the crate; the protocol and the front ends are taught in Lecture 39.
The WebAssembly bindings the web app loads, published as crate geop.
Compiled with wasm-pack and consumed by the React front end in web/.
cd web
npm run build:wasm # wasm-pack build ../cad/geop-cad-web --target web ...
The package is named geop rather than geop-cad-web so that the output
files (geop.js, geop_bg.wasm) match what web/src/geop.ts imports.
The editor’s view of the kernel
The browser edits a program through one Editor (geop_cad_base::editor(), see
geop-core-editor), and only through it:
| Export | Does |
|---|---|
init_panic_hook | forwards Rust panics to the JS console with a stack trace |
handle(command) | applies a Command, and returns the Update to show |
Everything crosses the boundary as JSON, elements by the target, kind and
name a pick gives them ({"target": "/bolt:model", "kind": "face", "name": "extrude(head,end)"}), never by number. The types web/src/geop.ts gives
that JSON are checked against what the kernel reads and sends:
cargo test -p geop protocol keeps samples of every command and of every
shape of update in web/test/protocol.samples.ts, typed as geop.ts
types them, and the web build (tsc -b) checks them. A field renamed on
either side fails one of the two.
web/src/App.tsx keeps the last update and nothing else of the program:
- Dialog fields send
{type: "dialog", key, value}events with the key of the field used.web/src/DialogView.tsxrenders any dialog from its primitives alone. - The viewport (
web/src/SceneViewer.tsx) sends hovers (once a frame), clicks — primary or secondary, double or not — and drags, each as aPointer: the ray from the eye through the cursor, and how far from it the pointer reaches —REACH_PXpixels, as a cone from the eye in perspective or a tube in an orthographic view. A press starts a drag only where the last presentation offered agrab; anywhere else it moves the camera. - Keys go to the step unless a field is being typed into.
The viewer draws the part (a serialized geop_core_editor::view::PartView), lights
the presentation’s highlights, draws its visuals (web/src/visuals3d.ts)
over the model at the same on-screen sizes the kernel hit-tests them at,
fades reference geometry that cannot be picked, and — when the presentation
names a plane to work in — turns to face it, stops orbiting (dragging pans)
and draws a grid on it.