Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.
C++ 3d3d-sculptingcppdear-imguidigital-sculptingfbxgame-developmentgaussian-splattinggltfimage-to-3dmcpopenglopenusdsculptingtext-to-3dunreal-engine
AR page: Google's AR viewer (Scene Viewer) through an opt-in readable copy on the relay
islandmed8bd0cacb5bad
diff --git a/services/link-worker/.wrangler/cache/wrangler-account.json b/services/link-worker/.wrangler/cache/wrangler-account.jsonnew file mode 100644index 00000000..81da4024--- /dev/null+++ b/services/link-worker/.wrangler/cache/wrangler-account.json@@ -0,0 +1,6 @@+{+ "account": {+ "id": "5d0c8d4911fb65ef478488b800741552",+ "name": "[email protected]'s Account"+ }+}\ No newline at end of filediff --git a/services/link-worker/src/index.js b/services/link-worker/src/index.jsindex c1bf8304..a6782eb6 100644--- a/services/link-worker/src/index.js+++ b/services/link-worker/src/index.js@@ -51,23 +51,25 @@ export class Topic {// The AR model for Android Chrome, which can't reach the computer on the home network: the desktop posts it// encrypted (AES-GCM, key only in the AR page's #fragment), the page polls the version and downloads it. A newer// version replaces an older one; posting keeps the topic alive for another TTL.- async putBlob(version, bytes) {- const meta = await this.ctx.storage.get("blob");+ // `name` "blob": the encrypted model; "share": a readable copy the AR page posts when the person picks Google's+ // AR viewer (Scene Viewer), which can only load a model from a public HTTPS address.+ async putBlob(version, bytes, name = "blob") {+ const meta = await this.ctx.storage.get(name);if (meta && meta.version >= version) return { version: meta.version, stale: true };const chunks = Math.ceil(bytes.byteLength / BLOB_CHUNK);- for (let i = 0; i < chunks; ++i) await this.ctx.storage.put(`blob:${i}`, bytes.slice(i * BLOB_CHUNK, (i + 1) * BLOB_CHUNK));- await this.ctx.storage.put("blob", { version, bytes: bytes.byteLength, chunks });- await this.ctx.storage.setAlarm(Date.now() + TTL_MS);+ for (let i = 0; i < chunks; ++i) await this.ctx.storage.put(`${name}:${i}`, bytes.slice(i * BLOB_CHUNK, (i + 1) * BLOB_CHUNK));+ await this.ctx.storage.put(name, { version, bytes: bytes.byteLength, chunks });+ if (name === "blob" || (await this.ctx.storage.getAlarm()) === null) await this.ctx.storage.setAlarm(Date.now() + TTL_MS);return { version };}- async getBlob(withData) {- const meta = await this.ctx.storage.get("blob");+ async getBlob(withData, name = "blob") {+ const meta = await this.ctx.storage.get(name);if (!meta) return null;if (!withData) return { meta };const data = new Uint8Array(meta.bytes);for (let i = 0, at = 0; i < meta.chunks; ++i) {- const chunk = new Uint8Array(await this.ctx.storage.get(`blob:${i}`));+ const chunk = new Uint8Array(await this.ctx.storage.get(`${name}:${i}`));data.set(chunk, at);at += chunk.byteLength;}@@ -82,10 +84,11 @@ export class Topic {// "cloudflare:workers", which plain Node can't import, and the tests run this file under plain Node.async fetch(request) {const url = new URL(request.url);- if (url.pathname === "/blob") {+ if (url.pathname === "/blob" || url.pathname === "/share") {+ const name = url.pathname.slice(1);if (request.method === "POST")- return Response.json(await this.putBlob(Number(url.searchParams.get("v")), await request.arrayBuffer()));- const blob = await this.getBlob(url.searchParams.has("data"));+ return Response.json(await this.putBlob(Number(url.searchParams.get("v")), await request.arrayBuffer(), name));+ const blob = await this.getBlob(url.searchParams.has("data"), name);if (!blob) return Response.json({ error: "no model yet" }, { status: 404 });if (!blob.data) return Response.json(blob.meta);return new Response(blob.data, { headers: { "X-Version": String(blob.meta.version) } });@@ -119,7 +122,7 @@ function respond(body, status, origin, type = "application/json") {const headers = { "Content-Type": type, "Cache-Control": "no-store", "X-Content-Type-Options": "nosniff" };if (origin) {headers["Access-Control-Allow-Origin"] = origin;- headers["Access-Control-Allow-Methods"] = "GET, POST";+ headers["Access-Control-Allow-Methods"] = "GET, POST, HEAD";headers["Access-Control-Expose-Headers"] = "X-Version";headers["Access-Control-Max-Age"] = "86400";headers["Vary"] = "Origin";@@ -164,6 +167,34 @@ export default {return out;}+ // A readable copy for Scene Viewer: posted by the AR page (after the person taps Google's AR viewer), read by+ // Google's app, which fetches it itself. Deleted with the topic, 10 minutes after the first model.+ const shareMatch = url.pathname.match(/^\/share\/([^/]+)\/model\.glb$/);+ if (shareMatch) {+ const topic = shareMatch[1];+ if (!TOPIC_PATTERN.test(topic)) return json({ error: "bad topic" }, 400, origin);+ const stub = env.TOPICS.get(env.TOPICS.idFromName(topic));+ if (request.method === "POST") {+ if (!origin) return json({ error: "posted by the AR page only" }, 403, origin);+ const version = Number(url.searchParams.get("v"));+ if (!Number.isSafeInteger(version) || version < 1) return json({ error: "bad version" }, 400, origin);+ const body = await request.arrayBuffer();+ if (body.byteLength > MAX_BLOB_BYTES) return json({ error: "too large" }, 413, origin);+ if (new TextDecoder().decode(new Uint8Array(body, 0, Math.min(4, body.byteLength))) !== "glTF")+ return json({ error: "not a GLB model" }, 400, origin);+ if (!(await stub.fetch(new Request("https://topic/blob"))).ok) return json({ error: "no model for this link" }, 404, origin);+ const r = await stub.fetch(new Request(`https://topic/share?v=${version}`, { method: "POST", body }));+ return json(await r.json(), 200, origin);+ }+ if (request.method !== "GET" && request.method !== "HEAD") return json({ error: "method not allowed" }, 405, origin);+ const r = await stub.fetch(new Request("https://topic/share?data=1"));+ if (r.status === 404) return json({ error: "no model" }, 404, origin);+ return new Response(request.method === "HEAD" ? null : await r.arrayBuffer(), {+ headers: { "Content-Type": "model/gltf-binary", "Cache-Control": "no-store", "Access-Control-Allow-Origin": "*",+ "X-Content-Type-Options": "nosniff" },+ });+ }+const match = url.pathname.match(/^\/relay\/([^/]+)(\/json)?$/);if (!match) return json({ error: "not found" }, 404, origin);const [, topic, poll] = match;diff --git a/services/link-worker/test/relay.test.mjs b/services/link-worker/test/relay.test.mjsindex 8f7751a6..418daa72 100644--- a/services/link-worker/test/relay.test.mjs+++ b/services/link-worker/test/relay.test.mjs@@ -90,3 +90,21 @@ test("an encrypted AR model: SculptForge posts it, the page reads the version anawait env.fireAlarms(Date.now() + TTL_MS + 1000);assert.equal((await blob("", { headers: { Origin: PAGE } })).status, 404);});++test("a readable copy for Google's AR viewer: only the page posts it, only for a live link, anyone with the URL reads it", async () => {+ const env = fakeEnv();+ const share = (query = "", init = {}) => worker.fetch(new Request(`${BASE}/share/${TOPIC}/model.glb${query}`, init), env);+ const glb = new Uint8Array([0x67, 0x6c, 0x54, 0x46, 1, 2, 3, 4, 5, 6, 7, 8]); // "glTF..."+ assert.equal((await share("?v=1", { method: "POST", body: glb, headers: { Origin: PAGE } })).status, 404); // no link yet+ await worker.fetch(new Request(`${BASE}/blob/${TOPIC}?v=1`, { method: "POST", body: new Uint8Array(64) }), env);+ assert.equal((await share("?v=1", { method: "POST", body: glb })).status, 403); // not from the page+ assert.equal((await share("?v=1", { method: "POST", body: new Uint8Array(40), headers: { Origin: PAGE } })).status, 400);+ assert.equal((await share("?v=1", { method: "POST", body: glb, headers: { Origin: PAGE } })).status, 200);+ const got = await share();+ assert.equal(got.status, 200);+ assert.equal(got.headers.get("Content-Type"), "model/gltf-binary");+ assert.equal(got.headers.get("Access-Control-Allow-Origin"), "*");+ assert.deepEqual(new Uint8Array(await got.arrayBuffer()), glb);+ await env.fireAlarms(Date.now() + TTL_MS + 1000);+ assert.equal((await share()).status, 404);+});diff --git a/src/link/PhoneLink.cpp b/src/link/PhoneLink.cppindex 6519893a..15c29de0 100644--- a/src/link/PhoneLink.cpp+++ b/src/link/PhoneLink.cpp@@ -1085,7 +1085,7 @@ bool PhoneLink::createFaceLink(std::string& faceUrl, std::string& error, bool ar// Everything after '#' stays on the phone: the website never sees the offer, the token or the key.std::string page = options_.siteUrl;// ?v= changes with each page change that SculptForge depends on, so phones don't use a cached older copy.- if (ar) page = page.substr(0, page.rfind('/') + 1) + "ar.html?v=4";+ if (ar) page = page.substr(0, page.rfind('/') + 1) + "ar.html?v=5";// AR: the model also goes through our relay (its /blob/ path), for phones whose browser can't reach this computer.std::string blobUrl;if (ar)diff --git a/tests/test_phone_link.cpp b/tests/test_phone_link.cppindex c44090e0..32a1dc47 100644--- a/tests/test_phone_link.cpp+++ b/tests/test_phone_link.cpp@@ -588,7 +588,7 @@ TEST(ar_link_sends_the_model_over_webrtc) {HttpRequest r = request("GET", "/api/face-link", link.token());r.query = "mode=ar&scope=scene&size=35";const std::string url = parseJson(link.handle(r).body)["url"].asString();- CHECK(url.rfind("https://example.org/link/ar.html?v=4#v=1&", 0) == 0);+ CHECK(url.rfind("https://example.org/link/ar.html?v=5#v=1&", 0) == 0);const std::string fragment = url.substr(url.find('#') + 1);CHECK(queryParameter(fragment, "m") == "ar");CHECK(queryParameter(fragment, "s") == "scene");diff --git a/website/link/ar.html b/website/link/ar.htmlindex 813b9998..998aeca6 100644--- a/website/link/ar.html+++ b/website/link/ar.html@@ -73,8 +73,11 @@ footer { text-align:center; color:#6f6f78; font-size:12px; padding:20px 18px 30p<div class="wait" id="wait"><div><div id="waitText">Connecting to your computer...</div><div class="bar hidden" id="bar"><b id="barFill"></b></div></div></div></div><div id="liveMsg"></div>- <button class="primary hidden" id="enter">Place it in your room</button>- <p class="muted small hidden" id="hint" style="margin-top:10px">Move the phone slowly over a table or the floor until it finds the surface, then tap to place. It's shown at real size; pinch to rescale is off so the size stays true.</p>+ <button class="primary hidden" id="google">View in your room</button>+ <a class="primary hidden" id="googleOpen" href="#">Open Google's AR viewer</a>+ <p class="muted small hidden" id="googleNote" style="margin-top:8px">Opens in Google's AR viewer. It can only load a model from the internet, so a readable copy is put on SculptForge's relay at a secret address and deleted within 10 minutes.</p>+ <button class="secondary hidden" id="enter">Place it with Chrome's AR instead</button>+ <p class="muted small hidden" id="hint" style="margin-top:10px">Use a well-lit room. Move the phone slowly over a table or the floor until it finds the surface. The model is shown at real size.</p><button class="secondary hidden" id="direct">Connect without internet</button></section><a class="secondary hidden" id="back" href="#">Back to capture</a>@@ -221,6 +224,32 @@ function receive(data) {incoming = null;}}+// Google's AR viewer (Scene Viewer), the most dependable AR on Android: it only loads a model from a public HTTPS+// address, so on request the page posts a readable copy to the relay (deleted with the link) and opens the viewer.+// Two taps: Chrome only opens another app from a fresh tap, and the upload takes a moment.+let currentModel = null;+const shareUrl = blobUrl ? blobUrl.replace("/blob/", "/share/") + "/model.glb" : "";+$("google").onclick = async () => {+ if (!currentModel) return;+ $("google").disabled = true;+ $("google").textContent = "Preparing...";+ try {+ const r = await fetch(`${shareUrl}?v=${shownVersion}`, { method: "POST", body: currentModel });+ if (!r.ok) throw new Error((await r.json().catch(() => ({}))).error || "HTTP " + r.status);+ const page = location.href.split("#")[0];+ $("googleOpen").href = "intent://arvr.google.com/scene-viewer/1.0?file=" + encodeURIComponent(`${shareUrl}?v=${shownVersion}`) ++ "&mode=ar_preferred&resizable=false&title=" + encodeURIComponent("Your sculpt") ++ "#Intent;scheme=https;package=com.google.ar.core;action=android.intent.action.VIEW;S.browser_fallback_url=" ++ encodeURIComponent(page) + ";end;";+ $("google").classList.add("hidden");+ $("googleOpen").classList.remove("hidden");+ } catch (e) {+ note($("liveMsg"), "Couldn't prepare it: " + esc(e.message || e), "bad");+ }+ $("google").disabled = false;+ $("google").textContent = "View in your room";+};+// While the camera view is open a new model waits: swapping the model mid-session loses it in WebXR.let inAr = false, waiting = null;function showModel(blob, version, summary) {@@ -229,7 +258,13 @@ function showModel(blob, version, summary) {shownVersion = version;if (modelUrl) URL.revokeObjectURL(modelUrl);modelUrl = URL.createObjectURL(blob);+ currentModel = blob;$("mv").src = modelUrl;+ $("googleOpen").classList.add("hidden");+ if (shareUrl) {+ $("google").classList.remove("hidden");+ $("googleNote").classList.remove("hidden");+ }$("wait").classList.add("hidden");note($("liveMsg"), first ? (summary ? "Ready: " + esc(summary) : "") : "Updated from your sculpt.", first ? "" : "ok");}