ar-models
Convert a 3D model into the two files phones need to place an object in the room through the camera from a web page, a .glb for Android (Scene Viewer) and a .usdz for iPhone and iPad (AR Quick Look), at real-world size with the base on the floor, plus the web snippet and button that opens them. Reads GLB, glTF, OBJ, STL and URDF robots (in a chosen joint pose), simplifies meshes, caps textures, adapts materials for USDZ, then inspects and verifies both files. Use whenever the user wants "view in AR", "see it in your room", "view in your space", an AR button, AR Quick Look, Scene Viewer, a USDZ file, GLB to USDZ, a model "at real size" on a phone, a product, furniture or robot placed in AR on a website, or wants to check or fix an existing .glb/.usdz pair or the MIME types and headers for serving them.
Safety scan
A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.
Badge for your README
Markdown
[](/listings/vinvirtual--ar-models)HTML
<a href="/listings/vinvirtual--ar-models"><img src="/api/listings/vinvirtual--ar-models/badge.svg" alt="findsafeskills safety rating" /></a>Install
Install instructions from the README
As written by the repo's author. findsafeskills has not verified these steps.
# 1. the skill itself (for Claude Code; any folder works if you only use the command line) git clone https://github.com/VinVirtual/ar-models ~/.claude/skills/ar-models # 2. its four packages npm install --prefix ~/.claude/skills/ar-models # 3. check ~/.claude/skills/ar-models/ar check
What was scanned
The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.
SKILL.md · Manifest · 74 lines
- ---
- name: ar-models
- description: Convert a 3D model into the two files phones need to place an object in the room through the camera from a web page, a .glb for Android (Scene Viewer) and a .usdz for iPhone and iPad (AR Quick Look), at real-world size with the base on the floor, plus the web snippet and button that opens them. Reads GLB, glTF, OBJ, STL and URDF robots (in a chosen joint pose), simplifies meshes, caps textures, adapts materials for USDZ, then inspects and verifies both files. Use whenever the user wants "view in AR", "see it in your room", "view in your space", an AR button, AR Quick Look, Scene Viewer, a USDZ file, GLB to USDZ, a model "at real size" on a phone, a product, furniture or robot placed in AR on a website, or wants to check or fix an existing .glb/.usdz pair or the MIME types and headers for serving them.
- ---
- # ar-models
- Pipeline: **load** (three.js loaders in Node) → **flatten and fit** (upright, metres, base on the floor) → **lighten** (meshoptimizer, texture cap) → **write and check** (`.glb` with GLTFExporter, `.usdz` with USDZExporter from a copy adapted for Quick Look, then read both back).
- Skill folder: `~/.claude/skills/ar-models/` (written below as `$A`). Every command is `$A/ar <command>`. `$A/ar help` lists them all with options.
- ```
- $A/ar the command line (check, convert, inspect, verify, snippet, test)
- $A/lib/ the pipeline: load, urdf, geometry, fit, quicklook, convert, inspect, verify, snippet
- $A/web/ar-button.js browser module to copy into the user's site (ESM, no dependencies)
- $A/references/materials.md what is changed or dropped in the .usdz, and what is not read
- $A/examples/lamp/ a model built in code, its converted files and a demo page
- $A/README.md install, licences, limits, all options
- ```
- ## Before you start
- - **Rights.** Ask where the model came from if it is not clearly the user's own. The converted files are copies that the web page hands to every visitor, so the user needs the right to redistribute the model. Say this once, plainly. Do not convert a model the user says they have no right to share.
- - **Real size.** AR is only useful at true scale. Get the real height (or longest side) in metres from the user or from the product's specification. Never guess a size. If the file is already in metres, say that you kept it and show the size for them to confirm.
- - **Phones.** You cannot see AR from here. Nothing on this machine shows Quick Look or Scene Viewer. Say so when you deliver, and ask the user to try it on a real iPhone and a real Android phone.
- ## Workflow
- 1. **Check the machine**: `$A/ar check`. If packages are missing it prints the `npm install` line to run.
- 2. **Convert**:
- ```
- $A/ar convert <input> --height <metres> --out <site's public models folder> [--name <name>]
- ```
- - Put the output where the site serves static files (`public/models/`, `static/models/`, `assets/ar/`). Check how the project serves static files first.
- - Size: `--height` (floor to top), or `--longest`, or `--scale` (`0.001` for millimetres, `0.01` for centimetres). Use one.
- - Up axis: glTF and OBJ are read as Y up, STL and URDF as Z up. If the result lies on its side (width and height swapped in the printed size), pass `--up z` or `--up y`.
- - URDF: pass `--mesh-dir` and a `--pose` so the robot stands in a natural resting pose, not with every joint at zero. Example: `--pose "left_elbow=0.5,right_elbow=0.5,*_knee=20deg"`.
- - It prints what it did, every material change made for the `.usdz`, and then the verify checks.
- 3. **Read the output.** Fix what it reports:
- - `PROBLEM` or `warning` about file size or triangles → lower `--triangles` (20000 to 60000 suits most products) or `--texture-size` (512 or 1024).
- - "still N triangles after simplifying" → raise `--simplify-error` to 0.02 or 0.05, and look at the result afterwards.
- - "check the units" → the size option is wrong or missing.
- - `texture dropped` → a WebP or AVIF texture with no PNG/JPEG copy. Export the model again with PNG or JPEG textures to keep it.
- - KTX2/Basis error or Draco error → export the model again with PNG or JPEG textures and without Draco compression.
- - `not a valid ... file` → the file is broken or is not what its extension says. Ask for the original.
- - "the files are named ..." → the input's name had spaces or other characters. Use that name in `ar snippet`.
- - `usdz` lines → tell the user which looks will differ on iPhone (see `references/materials.md`).
- 4. **Look at it.** Load the `.glb` in a browser with three.js (or the project's own 3D viewer), take a screenshot with a floor grid, and Read it. Check that it is the right way up, stands on the floor, and has its colours and textures. `inspect` gives numbers. Only a picture shows a model that is upside down or inside out.
- 5. **Verify again after any manual change**: `$A/ar verify <out>/<name>` and `$A/ar inspect <out>/<name>.glb <out>/<name>.usdz`.
- 6. **Add the button**: `$A/ar snippet <name> --base <url folder> --title "<label>" --host <vercel|netlify|nginx|apache>`.
- - Copy `$A/web/ar-button.js` into the site's source and import it. Do not load it from the skill folder.
- - In React, Vue or Svelte, call `arLink(options)` once on the client (after mount, it reads `navigator` and `document`) and `openAR(link)` in the click handler, or render nothing when `link.mode === 'none'`. Do not call it during server rendering.
- - Match the button to the site's own design. The snippet's markup is a starting point.
- - Give desktops the fallback: the message and `link.url`, or a QR code of `link.url`. In-app Android browsers (Instagram, Facebook) get an "open in Chrome" message the same way.
- - Model addresses must be relative or `https`. Pass `onWarning` or watch the console: it warns when the `.glb` is not on `https`.
- 7. **Set the MIME types.** Add the header rules the snippet prints to the host's config (`vercel.json`, `_headers`, nginx, `.htaccess`). For nginx, never add a bare `types { }` block to a `server` block (it replaces the whole MIME map). The types are `.usdz` → `model/vnd.usdz+zip`, `.glb` → `model/gltf-binary`. Without them Quick Look shows a download page.
- 8. **Deliver.** Tell the user:
- - the two file paths and sizes, the real size in metres, and the triangle count;
- - every `usdz` change that was reported;
- - that AR was **not** tested, and how to test: deploy to a public `https` address, open the page in Safari on an iPhone and in Chrome on an ARCore Android phone, tap the button;
- - how to check the headers: `curl -sI https://<site>/<path>.usdz | grep -i content-type`.
- ## Rules
- - One still pose only. If the user asks for animation or tapping on parts in AR, say this tool does not do it.
- - Do not claim the model "works in AR". Claim what was checked: the files parse, match each other, stand on the floor, and render in a desktop browser.
- - Do not shrink a model to make the files small unless the user agrees: `--height` is the real size, and the files are made lighter with `--triangles` and `--texture-size`.
- - Keep the source model out of the site's public folder unless the user wants it there. Only the `.glb` and `.usdz` are needed.
- - Scene Viewer downloads the `.glb` from the public internet. A preview behind a login, `localhost` and plain `http` will not work on Android.
- - Files over about 5 MB are slow on mobile data. Aim for 1 to 4 MB each.
- ## Limits
- Static pose only. USDZ carries fewer material features than glTF (glass, sheen, unlit, vertex colours and double-sided surfaces are approximated or dropped: see `references/materials.md`). PNG and JPEG textures only (copies carried for WebP, AVIF or KTX2 textures are used). No Draco input, no COLLADA meshes, no Xacro, no OBJ textures. AR Quick Look needs Safari on iOS or iPadOS. Scene Viewer needs an ARCore-capable Android phone with the Google app. Built and tested on Linux. Behaviour on real phones was not tested by the author.
README.md · README · 256 lines
- # ar-models
- [](https://github.com/VinVirtual/ar-models/actions/workflows/test.yml) [](LICENSE)
- Turns a 3D model into the two files phones need to place an object in the room through the camera, straight from a web page:
- - a **`.glb`** for Android, opened by Google's **Scene Viewer**
- - a **`.usdz`** for iPhone and iPad, opened by Apple's **AR Quick Look**
- Both come out at real-world size in metres, upright, centred, with the base on the floor. You also get the small piece of HTML and JavaScript that opens the right file on each kind of phone. No app and no AR library is needed on the page.
- It is packaged as a [Claude Code](https://claude.com/claude-code) skill (`SKILL.md` tells the assistant how to use it), and it also works by hand from the command line.
- ```
- $ ar convert lamp-source.glb --name lamp --height 0.45
- lamp-source.glb → lamp.glb, lamp.usdz
- up axis y → y, scale × 0.023905
- size 0.651 × 0.450 × 0.307 m (width × height × depth)
- mesh 3,744 triangles in → 3,744 out (usdz 3,920), 4 mesh(es)
- texture map: 256×256
- usdz double-sided material: back faces added in the .usdz (USD draws one side)
- wrote examples/lamp/lamp.glb (223.3 kB)
- wrote examples/lamp/lamp.usdz (460.2 kB)
- pass GLB parses and has geometry (3,744 triangles)
- pass USDZ is a valid uncompressed zip with a USD layer first (6 file(s), first is model.usda)
- pass USDZ parses and has geometry (3,920 triangles)
- pass both files are the same size and position (largest difference 0.00 mm (allowed 5.25 mm))
- pass GLB base sits on the floor (lowest point at y = 0.0000 m)
- pass USDZ base sits on the floor (lowest point at y = 0.0000 m)
- ```
- ## What it does
- - **Reads** `.glb` and `.gltf` (with its `.bin` and image files), `.obj` (with the plain colours of its `.mtl`), `.stl`, and `.urdf` robot descriptions with their mesh folder, in a joint pose you choose.
- - **Stands the model upright** from any up axis, **scales it to metres** from a real height, a real longest side or a plain factor, **puts its base on the floor** and centres it.
- - **Lightens it for phones**: merges meshes that share a material, simplifies to a triangle budget with [meshoptimizer](https://github.com/zeux/meshoptimizer), and caps texture size.
- - **Writes both files** with [three.js](https://threejs.org)'s exporters, running in Node with no browser.
- - **Adapts materials for the `.usdz`**, which supports fewer material features than glTF, and tells you each change.
- - **Inspects** any `.glb` or `.usdz`: size in metres, triangles, textures, file size, and warnings against budgets for mobile.
- - **Verifies** a pair: both files parse again, their bounding boxes match, the `.usdz` is a valid uncompressed zip with its USD layer first, and the base sits at the floor.
- - **Prints the web snippet**: the AR button, the right `Content-Type` for each file, and header settings for Vercel, Netlify, nginx and Apache.
- - **`web/ar-button.js`**: a dependency-free browser module that picks Quick Look or Scene Viewer per device and gives desktops a fallback message with the page address (ready to show as a QR code).
- ## Limits
- Read these before you plan around it.
- - **One still pose.** No animation, no skinning, no interactivity in AR. An animated or rigged model is frozen in the pose its file opens in. A URDF robot is frozen in the pose you pass with `--pose`.
- - **USDZ materials are narrower than glTF.** Transmission (glass), sheen, iridescence, anisotropy, unlit shading, vertex colours and double-sided surfaces have no direct counterpart. They are approximated or dropped, and each case is reported. The full list is in [`references/materials.md`](references/materials.md).
- - **AR Quick Look needs Safari on iOS or iPadOS** (or another iOS browser that supports `rel="ar"` links). It does not exist on Android or desktop.
- - **Scene Viewer needs an ARCore-capable Android phone with the Google app installed, opened from Chrome.** On other Android phones the link falls back to the web page. Browsers inside other apps (Instagram, Facebook, other WebViews) do not open Scene Viewer, so `ar-button.js` shows them an "open this page in Chrome" message instead of the button. It recognises them by their user-agent string, which catches the common apps but not every one. The `.glb` must be at a public `https` address, because Scene Viewer downloads it itself: it cannot reach `localhost` or a page behind a login.
- - **AR cannot be tested without real phones.** Nothing in this tool, and no desktop browser or emulator, shows the AR view. See "What was tested" below.
- - **Textures must be PNG or JPEG.** When a file carries PNG or JPEG copies of its WebP, AVIF or KTX2 textures, the copies are used. A WebP or AVIF texture with no copy is dropped with a note. A KTX2/Basis texture with no copy stops the conversion with advice to export again with PNG or JPEG textures.
- - **Files outside the model's folder are never read.** A `.gltf` may only refer to files in its own folder, an OBJ's `.mtl` must sit in the OBJ's folder, a `.glb` must hold everything itself, and URDF meshes are read only from `--mesh-dir`, the URDF's folder and the folder above it. Paths are compared after resolving them in full (symbolic links included), so `..` and absolute paths cannot reach elsewhere.
- - **Not read:** Draco-compressed glTF (export it again without Draco; meshopt compression is read), COLLADA meshes in a URDF, Xacro files, OBJ texture maps, FBX, USD as input.
- - **The node hierarchy is flattened.** Meshes that share a material become one mesh. Names are not kept.
- - Simplification moves surfaces by at most `--simplify-error` (1 % of size by default). If a model cannot reach the triangle budget inside that limit, the tool says so and keeps the extra triangles.
- - The `.usdz` holds its geometry as text (`.usda`), so it is usually two to three times the size of the `.glb`.
- ### What was tested
- Built and tested on **Linux** (Ubuntu 22.04, Node.js 24) only. macOS and Windows were not tried.
- Checked by the author: the unit tests; converting GLB, glTF with outside files, OBJ, STL and URDF inputs; reading both output files back; loading the example `.glb` and `.usdz` in headless Chrome with three.js's own loaders and looking at the rendered pictures; the button's choice of viewer under emulated Android and desktop browsers.
- **Not tested: behaviour on a phone.** The author did not open any output in AR Quick Look on an iPhone or iPad, or in Scene Viewer on an Android phone. Whether the files open, how the materials look there, and whether the button launches the viewer are unverified. The link formats follow Apple's and Google's public documentation. Test on real devices before you ship.
- ## You must have the right to share the model
- Converting a model does not change who owns it. The `.glb` and `.usdz` are copies of the original, and putting them on a web page distributes them to every visitor. Only convert and publish models you made yourself, or whose licence allows redistribution (and follow its terms, such as attribution). Models bought from a marketplace or downloaded from a manufacturer often do not allow this.
- ## Requirements
- | Needed | Why | Licence |
- |---|---|---|
- | Node.js 20 or newer | runs everything | MIT |
- | [three](https://www.npmjs.com/package/three) 0.187.0 | loaders, geometry, GLB and USDZ exporters | MIT |
- | [meshoptimizer](https://www.npmjs.com/package/meshoptimizer) 1.3.0 | mesh simplification, meshopt decoding | MIT |
- | [pngjs](https://www.npmjs.com/package/pngjs) 7.0.0 | reads and writes PNG textures | MIT |
- | [jpeg-js](https://www.npmjs.com/package/jpeg-js) 0.4.4 | reads and writes JPEG textures | BSD-3-Clause |
- None of these is included in this repository. `npm install` fetches them, and their licences apply to your use of them. No GPU, browser or Python is needed to convert. The versions are pinned because the tool leans on the exact behaviour of three.js's exporters.
- ### Licence notes
- Checked on 21 November 2026 against the licence files inside the installed packages. Check again before you rely on them.
- - **three.js** is MIT (`LICENSE`: "Copyright © 2010-2026 three.js authors"). Its USDZ exporter bundles **fflate**, which is MIT (stated in the header of `examples/jsm/libs/fflate.module.js`).
- - **meshoptimizer** is MIT (`LICENSE.md`: "Copyright (c) 2016-2026 Arseny Kapoulkine").
- - **pngjs** is MIT (`LICENSE`).
- - **jpeg-js** is BSD-3-Clause (`LICENSE` and package metadata).
- - **The example model** in `examples/lamp/` was made for this repository from primitive shapes by `make-lamp.mjs`. It is covered by this repository's MIT licence.
- - **Files you convert** keep the rights of the model they came from. See the section above.
- ar-models' own code is under the **MIT License** (see `LICENSE`).
- ## Install
- ```bash
- # 1. the skill itself (for Claude Code; any folder works if you only use the command line)
- git clone https://github.com/VinVirtual/ar-models ~/.claude/skills/ar-models
- # 2. its four packages
- npm install --prefix ~/.claude/skills/ar-models
- # 3. check
- ~/.claude/skills/ar-models/ar check
- ```
- ## Quick start
- ```bash
- AR=~/.claude/skills/ar-models/ar
- $AR convert chair.glb --height 0.82 --out public/models # public/models/chair.glb and chair.usdz, then checks them
- $AR inspect public/models/chair.glb public/models/chair.usdz
- $AR verify public/models/chair
- $AR snippet chair --base /models/ --title "Oak chair" # the button, and the server settings
- ```
- Copy `web/ar-button.js` next to your page, paste the snippet, deploy, and open the page on a phone.
- Other inputs:
- ```bash
- $AR convert bracket.stl --scale 0.001 # an STL in millimetres (Z up is assumed for STL)
- $AR convert vase.obj --longest 0.3 --up z # 30 cm on its longest side, source is Z up
- $AR convert robot.urdf --mesh-dir robot/meshes \
- --pose "left_elbow=0.6,right_elbow=0.6,knee_*=20deg" # a robot in a chosen pose
- $AR convert scan.glb --height 1.7 --triangles 60000 --texture-size 1024
- ```
- ### The example
- `examples/lamp/` holds a small desk lamp built in code, its two converted files and a demo page.
- ```bash
- node examples/lamp/make-lamp.mjs # writes lamp-source.glb: 30 units tall, origin off-centre
- ./ar convert examples/lamp/lamp-source.glb --name lamp --height 0.45
- ```
- To see the demo page, serve the repository folder with any static server and open `examples/lamp/index.html`. On a desktop it shows the fallback message. For AR it must be on a public `https` address and opened on a phone.
- ## Commands
- | Command | What it does |
- |---|---|
- | `ar check` | checks Node.js and the four packages, and says how to fix what is missing |
- | `ar convert <input>` | writes `<name>.glb` and `<name>.usdz`, prints what changed, then runs the `verify` checks and budget warnings. Exits non-zero if a check fails |
- | `ar inspect <file ...>` | size in metres, where the base is, triangles, meshes, materials, textures, file size, warnings. Reads `.glb`, `.gltf` and `.usdz`. Exits non-zero on a serious problem |
- | `ar verify <name>` | takes `models/chair`, `chair.glb` or `chair.usdz`. Both files parse, the `.usdz` is a valid uncompressed zip with a `.usda`/`.usdc` first entry on 64-byte boundaries, the two bounding boxes match (within 2 mm plus 0.5 % of size), both bases are within 1 mm of the floor |
- | `ar snippet <name>` | prints the button's HTML and JavaScript, a no-JavaScript Quick Look link, the two MIME types and header settings. `--base /models/`, `--title`, `--host vercel\|netlify\|nginx\|apache\|all` |
- | `ar test` | runs the unit tests (plain `node --test`, no extra packages) |
- `convert` options:
- | Option | Default | What |
- |---|---|---|
- | `--out <dir>` | next to the input | where to write |
- | `--name <name>` | the input's name, made safe | output file name, without extension: letters, digits, dots, dashes and underscores, no folders. Without `--name`, an input such as `my chair.obj` becomes `my-chair`, and `convert` says so |
- | `--height <m>` | | real height in metres, floor to top |
- | `--longest <m>` | | or the real length of the longest side |
- | `--scale <factor>` | 1 | or a plain factor (`0.001` for millimetres, `0.01` for centimetres, `0.0254` for inches) |
- | `--up <axis>` | `y` for glTF and OBJ, `z` for STL and URDF | the input's up axis: `y`, `z`, `x`, `-y`, `-z`, `-x` |
- | `--no-floor`, `--no-center` | | keep the model's own height or sideways position |
- | `--triangles <n>` | 100000 | triangle budget. `0` never simplifies |
- | `--simplify-error <x>` | 0.01 | how far simplifying may move a surface, as a share of the model's size |
- | `--texture-size <px>` | 1024 | cap on the longer side of each texture. `0` for no cap |
- | `--double-sided <mode>` | `duplicate` | `duplicate` adds back faces in the `.usdz`, `keep` leaves surfaces one-sided |
- | `--colour <hex>` | `#b8bcc4` | colour for models that have none |
- | `--pose <list>` | all joints at 0 | URDF joint values: radians, `30deg`, or metres for sliding joints. `*` matches any part of a name. Values are held inside the joint's limits |
- | `--pose-file <json>` | | the same as a JSON object |
- | `--mesh-dir <dir>` | beside the URDF | folder with the URDF's mesh files. `package://` paths are looked up inside it |
- | `--json` | | print the result as JSON |
- Budgets that `inspect` and `convert` warn about (the tool's own defaults, not limits set by Apple or Google): a file over 5 MB (a serious problem over 15 MB), over 100,000 triangles (250,000), a texture over 2048 px, more than 60 meshes, a height over 5 m or under 2 cm (usually a units mistake), and a base that is not on the floor.
- ## Serving the files
- The server must send these types, or the phone shows a download page instead of AR:
- | File | `Content-Type` |
- |---|---|
- | `.usdz` | `model/vnd.usdz+zip` |
- | `.glb` | `model/gltf-binary` |
- `ar snippet <name> --host all` prints ready settings. For example, Vercel (`vercel.json`):
- ```json
- {
- "headers": [
- { "source": "/models/(.*)\\.usdz", "headers": [{ "key": "Content-Type", "value": "model/vnd.usdz+zip" }] },
- { "source": "/models/(.*)\\.glb", "headers": [{ "key": "Content-Type", "value": "model/gltf-binary" }] }
- ]
- }
- ```
- Netlify (`_headers` in the publish folder):
- ```
- /models/*.usdz
- Content-Type: model/vnd.usdz+zip
- /models/*.glb
- Content-Type: model/gltf-binary
- ```
- nginx: add the two types to the existing `types { }` block in `mime.types`, or add `location ~* \.usdz$ { default_type model/vnd.usdz+zip; }` (and the same for `.glb`) to your `server` block. Do not put a new `types { }` block holding only these two types in a `server` or `location` block: it replaces nginx's whole MIME map there, and the rest of the site loses its types. `ar snippet <name> --host nginx` prints both safe forms.
- Check after deploying: `curl -sI https://your.site/models/chair.usdz | grep -i content-type`.
- ## The browser module
- `web/ar-button.js` is one ES module with no dependencies. Copy it into your site.
- ```html
- <button id="ar" type="button" hidden>See it in your room</button>
- <p id="ar-fallback" hidden></p>
- <script type="module">
- import { mountARButton } from './ar-button.js';
- mountARButton(document.querySelector('#ar'), {
- glb: '/models/chair.glb',
- usdz: '/models/chair.usdz',
- title: 'Oak chair',
- fallback: document.querySelector('#ar-fallback'),
- });
- </script>
- ```
- - On iPhone and iPad it opens the `.usdz` in AR Quick Look, at real size (`allowsContentScaling=0`).
- - On Android it opens the `.glb` in Scene Viewer through an `intent://` link, with the page as the fallback address.
- - In a browser inside another Android app (Instagram, Facebook, a WebView), and in Firefox for Android, it shows "Open this page in Chrome" instead, because Scene Viewer would not open from there.
- - Anywhere else the button stays hidden and the fallback element gets a short message and the page address. Use `onUnavailable(link)` instead of `fallback` to draw your own, such as a QR code of `link.url`.
- - Model addresses must be relative or `http(s)`. Anything else (`javascript:`, `data:`, `blob:`, `file:`) is refused with reason `bad-model-url`, and `openAR` only ever clicks the two kinds of link this module builds.
- - When the `.glb` is not on `https` (for example on `localhost`), the button is still shown but Scene Viewer will not load the model. The warning goes to `onWarning(text, link)` if you pass one, otherwise to `console.warn`.
- For React, Vue or anything else, use the pure functions: `arLink(options, env)` returns `{ mode, href, rel }` or `{ mode: 'none', reason, message, url }`, and `openAR(link)` opens it from a click handler. `detectAR({ userAgent, maxTouchPoints, relSupportsAR })` only decides the viewer. All of them take the browser's facts as arguments, which is how the unit tests cover them.
- Pass `scaling: true` to let people resize the object with a pinch.
- ## How it works
- 1. **Load.** `lib/load.mjs` opens the file with three.js's loaders. A small stand-in for the browser's image and canvas functions (`lib/images.mjs`) lets textures load and save in Node. A URDF is assembled link by link in the pose given (`lib/urdf.mjs`).
- 2. **Flatten and fit.** `lib/geometry.mjs` bakes every transform into the vertices and merges meshes by material. `lib/fit.mjs` turns the up axis to Y, scales to metres and moves the base to `y = 0`.
- 3. **Lighten.** Meshes over the triangle budget are simplified, and textures over the cap are shrunk.
- 4. **Write and check.** `lib/convert.mjs` writes the `.glb`, then the `.usdz` from a copy adapted for Quick Look (`lib/quicklook.mjs`). `lib/verify.mjs` reads both back and compares them.
- ## Development
- ```bash
- ./ar test # 163 unit tests: scaling and floor maths, budgets, device detection, snippet text, zip structure, URDF, the whole pipeline, hostile paths and corrupt files
- ```
- The maths that decides size and placement is in `lib/fit.mjs` and works on plain numbers, so it is tested without three.js. `lib/zip.mjs` and `lib/usda.mjs` read the `.usdz` back without any USD library.
Ratings and comments
Sign in to rate this skill.
Sign inFree to use. If it’s helped, pass it on.