No description
  • Go 84.5%
  • HTML 15.5%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
lestrrat 5c6c6fc7f0
retain STEP assembly face identity (#48)
* retain STEP assembly face identity

* keep input and mesh limits separate

* complete STEP fixture options
2026-12-02 09:11:01 +09:00
.github/workflows add navigator and settings fuzz targets to matrix (#33) 2026-11-30 23:50:40 +09:00
_e2e measure body clearance with decad (#46) 2026-12-01 13:15:17 +09:00
agent-docs retain STEP assembly face identity (#48) 2026-12-02 09:11:01 +09:00
cmd apply the chord field to STEP files (#42) 2026-12-01 09:24:03 +09:00
internal retain STEP assembly face identity (#48) 2026-12-02 09:11:01 +09:00
web read mass properties from decad (#45) 2026-12-01 13:06:01 +09:00
.gitattributes add ci and fuzz workflows (#21) 2026-11-30 22:19:14 +09:00
.gitignore add initial repository scaffold 2026-11-30 16:38:41 +09:00
.golangci.yml add test helpers and step fixture corpus (#2) 2026-11-30 17:45:01 +09:00
CLAUDE.md add viewer design doc (#5) 2026-11-30 18:54:41 +09:00
doc.go add initial repository scaffold 2026-11-30 16:38:41 +09:00
go.mod update decad and cylinder mass readings (#47) 2026-12-02 08:54:43 +09:00
go.sum update decad and cylinder mass readings (#47) 2026-12-02 08:54:43 +09:00
LICENSE add initial repository scaffold 2026-11-30 16:38:41 +09:00
README.md retain STEP assembly face identity (#48) 2026-12-02 09:11:01 +09:00
SECURITY.md add initial repository scaffold 2026-11-30 16:38:41 +09:00
tolerance_lint_test.go add test helpers and step fixture corpus (#2) 2026-11-30 17:45:01 +09:00

decad-viewer

A viewer for solids and sheets built with decad.

The viewer reads decad's read-only binary body interchange and STEP output. It lives in its own repository so that decad stays a library with no rendering or UI dependencies. It is Go compiled to WebAssembly, drawing with WebGL2.

Run it

From the repository root, with Go installed:

go run ./cmd/decad-viewer-serve \
  -body internal/fixture/testdata/corpus/current/box.dcs \
  -body internal/fixture/testdata/corpus/current/plate-hole.dcs \
  -body internal/fixture/testdata/corpus/current/cylinder-rotated.step

The command builds the browser program, serves the page and prints its address. Open it in a recent Chrome. Three bodies make every tool useful at once, the exploded view among them, which needs two or more. To try it on a phone, serve on your network address (-addr 0.0.0.0:8080) and open that address on the phone; a phone has no WebHID, so the SpaceMouse group says it is unavailable there. -body takes a .dcs or .step file and may be given any number of times, and not at all: the page then starts empty, and its Load sample button offers scenes from the committed corpus, among them one of four bodies (-samples names the corpus directory; -samples "" offers none). -addr sets the listen address (default 127.0.0.1:8080). The command compiles ./cmd/decad-viewer, so it must run from inside the module.

The committed corpus under internal/fixture/testdata/corpus/current/ holds a .dcs and a .step file for each test body: box, plate-hole, cylinder-rotated, cavity, cone and the open sheet sheet-open.

What it does

Where each tool is. On a desktop the toolbar floats at the bottom of the view and the panel is on the right. On a phone or a narrow window the toolbar is a dock at the bottom (a rail on the right in landscape), the panel is a sheet that the Scene button opens, and the file, export and help actions are under ⋯ at the top right. Help (?, or the help button) lists every tool and where it is on the screen in use.

Feature Desktop Phone
Open, add files Open, Add files (top left), or drop files ⋯ menu, or Scene
Sample scenes (with nothing open) Load sample in the empty view Load sample in the empty view
Standard views, fit, fit selection, projection toolbar View
Display mode, pick mode toolbar: Style Style
Section planes: axis, offset, flip, planes, animation, exact area and perimeter toolbar: Section; panel: Section groups Section, which opens the Section page
Distance, selection readings, density toolbar: Measure; panel: Selection, Readings, Measure Measure, which opens the Inspect page
Exploded view: factor, direction, exit toolbar: Explode; Exit on the banner Explode; Exit on the banner
Bodies: visibility, colour, show only, remove, show all panel: Bodies Scene
Undo, redo top right top right
Screenshot, save view, load view top right icons ⋯ menu
Theme (auto, light, dark), help and shortcuts top right icons ⋯ menu
Keep model in view (refit when the canvas changes size) top right fit icon ⋯ menu
Background colour panel: Appearance Scene, Settings page
Chord for .dcs and STEP files panel: Open options Scene
SpaceMouse panel: SpaceMouse Scene, Settings page (says WebHID is unavailable)

Input

  • Binary frames written by decad's bodywire.Write (.dcs, one or more bodies per file) and STEP files written by decad's export.STEP (.stp or .step, one body per file) or export.STEPItems (a single-level assembly). Each part of an assembly is one body with its own name, placement and colour, so the Scene panel lists the parts and Explode has parts to move apart. Nested assemblies are refused.
  • Open replaces the scene, Add appends. Drag files onto the page to open them, hold Shift to add. Several bodies can be open together. A file over 128 MiB, a file with more than 64 bodies, a body over 2 million triangles, or frames that decompress to more than 256 MiB in total are refused, and the scene stays as it was.

Camera

  • Drag orbits. Shift-drag, middle-drag or right-drag pans. The wheel zooms about the cursor.
  • Touch: one finger orbits, two fingers pinch-zoom and pan, a tap selects and the line under the view names what it selected with its main reading. A long press on a button says what it does. Trackpad: two-finger scroll pans, pinch zooms.
  • Standard views (front, back, left, right, top, bottom, iso), fit all, fit selection, perspective or orthographic.
  • Keys: 1 to 7 views, F or Home fit, Z fit the selection, P projection, arrows orbit, Shift plus arrows pan, plus and minus zoom, M display mode, C section, D distance tool, E leaves the exploded view, Ctrl+Z undoes, Ctrl+Shift+Z or Ctrl+Y redoes, ? shows help, Escape closes a menu or clears the selection and measured points.

Selection

  • The cursor highlights what a click would select. A click selects the edge within 6 px, else the face under the cursor. The Pick menu limits it to faces, edges or bodies. Shift or Ctrl adds to the selection, a click on nothing clears it. The panel lists the selection.
  • A face and an edge are decad's own: the faces and edges a frame or STEP product states. A tangent fillet is its own face, a circle is one edge, and the label of a face names its surface (plane, cylinder, cone, sphere, torus or faceted). A body decad states no faces for (a legacy DCS3 sheet or a faceted product without labels) falls back to patches of triangles that meet at less than 30 degrees and runs of feature segments, and its readings say they come from the mesh.

Appearance

  • Shaded with edges, shaded, wireframe (every triangle edge) and hidden line.
  • A colour and a visibility toggle per body, a button to show only that body, a remove button, and the background colour with four presets.
  • Dark and light themes follow the system, and the theme button sets one and remembers it. The theme colours the page around the view; the view keeps its navy background in both, so readings and colours look the same, and the Settings page (or the panel's Appearance group) sets another background.

Exploded view

  • Moves each body away from the scene centre, or along X, Y or Z, by a factor up to 4. Measuring, sections and position readings are off in it, and a banner with an Exit button says so; leaving brings them back as they were. With one body there is nothing to move apart, and the Explode flyout says it needs two or more bodies.

History

  • Undo and redo step through edits of the scene: body removal, colour and visibility, the exploded view, the selection, display mode and background, the section planes and the measuring tool. Camera moves are not steps.

Section

  • Up to six clip planes, each perpendicular to X, Y or Z with an offset slider and a flip; the kept part is what every plane keeps, and a plane's offset can sweep back and forth by itself. Solids get a flat cap where the plane cuts them, with the right shape for bodies with cavities, and an outline of the cut drawn on the plane. Sheets are only clipped.
  • For each plane and each visible solid body the panel gives the exact area and perimeter of the cut, with decad's bound and the number of regions and holes. They are the mesh's cut, not the source solid's: the tessellation differs from it by about chord/radius. A body of over 50,000 triangles is read once the plane has rested.

Measuring

  • Distance: toggle the tool, click two points (a corner of an edge within 8 px is snapped to). The panel gives the distance and its components, with the tessellation bound.
  • Clearance: select two bodies, or click the two points of the distance tool on different bodies. The panel gives decad's least distance between the two solids with decad's bound (zero when they touch or overlap) and the two closest points, and the view draws the segment between them. Both bodies must be closed solids.
  • Selected faces read their area and selected edges their length, both from decad's received geometry with decad's bound (the sum of the facets for a faceted face), selected bodies their bounds, area, volume, mass at a density you set (default 1 g/cm³, remembered by the page; a list offers common materials), centre of mass and inertia tensor.
  • Every reading says where it comes from. Area and volume of a body, and its bounds, are decad's own reading of the mesh with decad's bound. Mass, centre and inertia are decad's reading of the mesh's enclosed region with its bound; for a curved body they differ from the source solid by the tessellation, by about chord/radius. The area of a face or the length of an edge of a body with no decad identity is computed from the mesh. A sheet has no volume or mass.

Output

  • Screenshot saves the frame as a PNG. Save view writes the camera, display mode, section, background and each body's colour and visibility as JSON. Load view (or dropping the .json file) restores it onto bodies of the same names.

SpaceMouse

The SpaceMouse group (in the panel; on a phone or a narrow window, on the Settings page of the sheet) drives the camera from a 3Dconnexion SpaceMouse that the page reads directly with WebHID, with no helper program. It needs a Chromium-based browser (Chrome, Edge) and a page served over https or from localhost. The browser asks you to pick the device once per origin. The page hands each report to Go (internal/spacemouse), which decodes it and moves the camera.

  • Pan: push the cap right, and lift it to pan up. Zoom: push it away to zoom in, pull to zoom out. Orbit: tilt it forward or back to tip the eye, tilt or twist it sideways to turn the model about the vertical axis.
  • Settings: sensitivity, dead zone, locks for pan, orbit and zoom (uncheck to lock), "one axis at a time" (only the strongest axis acts), and a sign flip for each of the six axes. They are kept in the browser's local storage.
  • Buttons: button 0 fits the scene and button 1 shows the iso view. Button numbers differ between models, so pick an action (a standard view, fit, fit selection or the projection toggle), click "Assign a button" and press the button on the device. The × beside an assignment removes it.
  • The state line says Not connected, Connected, receiving data, No device was chosen, Permission denied, or Device disconnected. After three seconds of silence it says "No data. Is 3DxWare running?".
  • The Report descriptor and Live reports parts of the block stay available as diagnostics. Copy diagnostics copies the device ids, the report layout and the last reports as text.

The signs and the report layout of each model are not checked against a device in CI. The report layout used is the one older devices document: report 1 translation, report 2 rotation, report 3 buttons.

If the 3DxWare driver holds the device, WebHID opens it but gets no reports. Exit 3DxWare from its tray icon, then click Connect again. If the driver has to stay on, 3Dconnexion's own web interface, 3DconnexionJS, works with the driver running. It needs the 3DxWare driver and the SDK from 3Dconnexion's developer area under its licence, and the viewer does not include it.

What to try on a SpaceMouse Pro Wireless (Windows, Chrome or Edge, viewer on localhost):

  1. Load a body. Click Connect in the SpaceMouse block and choose the device. The state says "receiving data" after you touch it. Try this with 3DxWare running and with it exited, and over Bluetooth and over the receiver.
  2. Push the cap right, left, away and toward you. The model should slide right, slide left, grow and shrink. If a direction is backwards, tick Invert for that axis (Tx, Ty or Tz).
  3. Lift and press the cap. The model should move up and down. Tick Invert Tz if it does not.
  4. Tilt the cap forward and back, then left and right, then twist it. Forward should tip the eye up, and left and right should turn the model. Tick Invert Rx, Ry or Rz for a backwards axis.
  5. Let go of the cap. The camera must stop within a moment. If it drifts, raise the dead zone.
  6. Raise and lower Sensitivity and check the speed follows. Uncheck Pan, Orbit or Zoom and check that motion stops; tick "One axis at a time" and check that a diagonal push moves along one axis only.
  7. Press button 0 (the left one on a Compact; try each on the Pro) for Fit and button 1 for the iso view. Assign the labelled view buttons of the Pro Wireless with "Assign a button", then press each and check the view.
  8. Reload the page. The settings and button assignments must still be there.
  9. Click Disconnect, then Connect again. Unplug or switch off the device while connected. The state line must say so.
  10. Click Copy diagnostics at the end and keep the text, for any step that failed.

Layout

Path Role
cmd/decad-viewer the WebAssembly program: canvas, DOM events, file bytes
cmd/decad-viewer-serve builds the program and serves the page and body files
web/index.html the page: app bar, toolbar, panel or sheet and status line, plain HTML, CSS and JavaScript
internal/load decoding of frames and STEP, with limits
internal/meshprep meshes for the GPU: normals, feature edges, faces and edge chains
internal/scene, internal/pick camera and picking
internal/drawlist, internal/present backend-neutral draw lists and the WebGL2 renderer
internal/session the state that input, commands and the page drive
internal/measure, internal/output readings and PNG export
internal/spacemouse decoding of SpaceMouse HID reports, and the model table
internal/serve the HTTP server behind decad-viewer-serve
internal/fixture, internal/vtest test fixtures built with decad, the committed corpus, bounded comparison helpers
_e2e browser tests, a separate module
agent-docs/design.md, agent-docs/testing.md design and test rules

Known limits

  • Section readings describe the decoded mesh. Sheets and meshes that are not closed solids have none, and a plane through a vertex where loops touch reads area and perimeter but not the region count.
  • A nested STEP assembly is refused.
  • The browser tests run only in headless Chrome on a software renderer (SwiftShader). The viewer has also been run in the owner's desktop browser, which is the only hardware-rendered run. The phone layouts are checked under headless Chrome's phone emulation with emulated touch, not on a phone.

Tests

go test ./...
go vet ./...
golangci-lint run
GOOS=js GOARCH=wasm go vet ./...

The browser tests are a separate module under _e2e and need Chrome:

CHROME_BIN=/path/to/chrome go -C _e2e test ./...

CI (.github/workflows/ci.yml) runs on pushes to main, on pull requests and on dispatch, in five jobs:

  • test: go build and go test on Ubuntu, Windows and macOS, plus go test -race on Ubuntu.
  • wasm: builds ./cmd/decad-viewer for js/wasm and runs go test ./internal/... under wasm.
  • browser: the _e2e tests in headless Chrome.
  • golangci-lint: golangci-lint and go vet, for the root module, for js/wasm and for _e2e.
  • verify: go mod tidy in both modules must leave no diff.

.github/workflows/fuzz.yml runs weekly (Monday 03:00 UTC) and on dispatch. It fuzzes FuzzLoadWire, FuzzLoadSTEP, FuzzCameraEvents, FuzzMeshPrep, FuzzPick, FuzzSessionInput, FuzzRestoreView, FuzzDecode, FuzzNavigator and FuzzLoadSettings for 10 minutes each, and uploads the reproducers of a failing target as an artifact.

License

PolyForm Noncommercial 1.0.0.