vole
Site
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software/vole.git
Self-hosted forge that lives in your Git repo.
Render images and 3D models in the browser views
3b2bcc30534f24b4628b6365e69dcb9065115065 · Keenan Nemetz · 13d ago · parent 87bab8e1
Render images and 3D models in the browser views A blob whose name is an image is served as that image, so the <img> a README already emitted works and the source view can show it. An SVG keeps its source view and previews on request. The instance introduction resolves assets/, so a landing-page picture is no longer a broken link. A changed image or model shows both sides in the commit, compare, and change request diffs, where git only says "binary". The 3D viewer is a vendored three.js bundle, loaded only when a page has a model, with a download fallback for a reader without JavaScript or WebGL. closes: 01M7XQ9AKKKFNEX0F679JRRYQD
server/web/static/models/README.md +45
| @@ -0,0 +1,45 @@ | |||
| 1 | # 3D model preview | ||
| 2 | |||
| 3 | `model-viewer.js` is Vole's viewer: it draws a blob into a canvas with | ||
| 4 | orbit/zoom and a wireframe toggle. `app.js` imports it only when a page contains | ||
| 5 | a `[data-model]` element, so no other page downloads it. | ||
| 6 | |||
| 7 | `three.bundle.js` is a generated ES module containing three.js and the loaders | ||
| 8 | the viewer uses. It is committed so an instance is still one binary and there is | ||
| 9 | no npm step in the build: | ||
| 10 | |||
| 11 | - three.js r187, `three.module.js` and the `OrbitControls`, `STLLoader`, | ||
| 12 | `OBJLoader`, `GLTFLoader` and `ThreeMFLoader` example modules. | ||
| 13 | MIT License. See `three.LICENSE`. | ||
| 14 | - fflate 0.8.3, which the 3MF loader uses to unzip the package. | ||
| 15 | MIT License. See `fflate.LICENSE`. | ||
| 16 | |||
| 17 | Regenerate the bundle after bumping `THREE_VERSION` in the script: | ||
| 18 | |||
| 19 | ```sh | ||
| 20 | python3 scripts/vendor-three.py # write three.bundle.js and three.LICENSE | ||
| 21 | python3 scripts/vendor-three.py --check # compare, exit 1 if they differ | ||
| 22 | ``` | ||
| 23 | |||
| 24 | Node and `npx` are needed to regenerate the bundle, because esbuild resolves the | ||
| 25 | loaders' bare `three` imports and their own dependencies into one module. Running | ||
| 26 | Vole does not need either. Bump `ESBUILD_VERSION` with `THREE_VERSION` when the | ||
| 27 | pinned esbuild no longer builds the release. | ||
| 28 | |||
| 29 | ## Formats | ||
| 30 | |||
| 31 | | Extension | Loader | Notes | | ||
| 32 | |---|---|---| | ||
| 33 | | `.stl` | `STLLoader` | Binary and ASCII | | ||
| 34 | | `.obj` | `OBJLoader` | Geometry only; a companion `.mtl` is not loaded | | ||
| 35 | | `.gltf` | `GLTFLoader` | Relative buffers and textures resolve through the raw route | | ||
| 36 | | `.glb` | `GLTFLoader` | Same, self-contained | | ||
| 37 | | `.3mf` | `ThreeMFLoader` | Unzipped in the browser by fflate | | ||
| 38 | |||
| 39 | Compressed glTF assets are not supported: Draco, KTX2 and meshopt need their own | ||
| 40 | decoders, and those would add a WASM eval or more vendored code. A model that | ||
| 41 | uses them reports that it could not be loaded and keeps its download link. | ||
| 42 | |||
| 43 | The viewer creates blob URLs to decode textures embedded in a glTF or 3MF file. | ||
| 44 | That is why the page's Content-Security-Policy allows `blob:` for images and | ||
| 45 | connections; see `server/web/auth.go`. | ||