diff --git a/.gitignore b/.gitignore index c1bbf8f..344808a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ dist/ wasm/viro-web.js wasm/viro-web.wasm wasm/viro-web.data +wasm/Roboto-*.ttf # The tinyvio tracking engine, copied in by scripts/copy-slam.sh. Same policy as # the renderer binaries above: build output of another repo, not tracked here, diff --git a/CHANGELOG.md b/CHANGELOG.md index e06d960..f609005 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,21 @@ # Changelog +## Unreleased + +### Added + +- **Styled text:** `ViroSceneApi.createStyledText` takes a family list, weight, italic, extrusion depth and an outline or drop shadow, and `ViroWebRenderer.loadTextFace` fetches the Roboto face a weight or italic needs from beside the wasm. The 11 faces ship as `wasm/Roboto-*.ttf`; `viro-web.data` is unchanged. On an older binary `createStyledText` draws plain text. +- **Material alpha, bloom threshold, colour write mask and chroma key:** `ViroSceneApi.setMaterialAlpha`, `setMaterialBloomThreshold`, `setMaterialColorWriteMask` (`ViroColorWriteMask` bits) and `setMaterialChromaKey`. On an older binary they do nothing and `supportsMaterialEffects` is false. +- **Pinch, rotate and fuse:** two touch pointers on the canvas become a pinch and a rotate on the node under their midpoint, as on iOS and Android (`ViroNodeEventHandlers.onPinch`, `onRotate`, and `onFuse` for the screen-centre gaze, with `ViroSceneApi.setNodeTimeToFuse`). They start on the first two-finger move; the first finger's press is cancelled without a click. +- **Node reads:** `ViroSceneApi.getNodeWorldTransform` and `getNodeBoundingBox`, decomposed as native's `getTransformAsync` and `getBoundingBoxAsync` are. `supportsGestures` is false on an older binary. +- **Context loss:** `ViroWebRenderer.isContextLost` and `addContextListener`. After a restore, dispose the renderer and create a new one on the same canvas. + +### Fixed + +- **The canvas is opaque, as a native view is.** Empty space showed the page behind the canvas; it now shows the scene's clear colour (black). +- **`dispose()` stops the render loop.** A disposed renderer kept drawing, so every remount added another loop. +- **`pointercancel` no longer completes a click.** It was sent as a release and could click the pressed node. + ## 1.1.1 Needs the virocore web build of 3.1.1; it ships in this package. diff --git a/THIRD-PARTY-LICENSES.md b/THIRD-PARTY-LICENSES.md index e0f458b..caf1ec2 100644 --- a/THIRD-PARTY-LICENSES.md +++ b/THIRD-PARTY-LICENSES.md @@ -46,8 +46,10 @@ This software is based in part on the work of the Independent JPEG Group. ## Roboto The typeface every text geometry renders in, baked into `wasm/viro-web.data` -and therefore redistributed with this package. Roboto is also what Viro renders -text in on Android and Quest, so the three agree. +and therefore redistributed with this package. Its other weights and italics +(`wasm/Roboto-*.ttf`, from Android's system fonts) ship beside the wasm and are +fetched when a text uses them. Roboto is also what Viro renders text in on +Android and Quest, so the three agree. Copyright the Roboto Project Authors, licensed under the Apache License, Version 2.0. You may obtain a copy of the licence at diff --git a/scripts/copy-wasm.sh b/scripts/copy-wasm.sh index 352d86d..aa33b9b 100755 --- a/scripts/copy-wasm.sh +++ b/scripts/copy-wasm.sh @@ -19,5 +19,15 @@ fi mkdir -p "$DEST_DIR" cp "$SRC_DIR/viro-web.js" "$SRC_DIR/viro-web.wasm" "$SRC_DIR/viro-web.data" "$DEST_DIR/" +# Roboto's other weights and italics, served beside the wasm and fetched only +# when a text asks for one (ViroWebRenderer.loadTextFace), so viro-web.data +# stays one face. +FONTS_DIR="${VIRO_WASM_FONTS:-$SRC_DIR/../../fonts}" +if ! ls "$FONTS_DIR"/Roboto-*.ttf >/dev/null 2>&1; then + echo "ERROR: no Roboto faces at $FONTS_DIR (set VIRO_WASM_FONTS to virocore/wasm/fonts)" + exit 1 +fi +cp "$FONTS_DIR"/Roboto-*.ttf "$DEST_DIR/" + echo "Copied into $DEST_DIR:" -ls -lh "$DEST_DIR"/viro-web.* +ls -lh "$DEST_DIR"/viro-web.* "$DEST_DIR"/Roboto-*.ttf diff --git a/src/ViroWebRenderer.ts b/src/ViroWebRenderer.ts index 0fa80d4..07f2645 100644 --- a/src/ViroWebRenderer.ts +++ b/src/ViroWebRenderer.ts @@ -8,7 +8,7 @@ import { type ViroAnimationHandlers, } from "./sceneApi.js"; import { ViroRendererAbortError } from "./types.js"; -import type { ViroWebModule, ViroWebRendererOptions } from "./types.js"; +import type { LocateFile, ViroWebModule, ViroWebRendererOptions } from "./types.js"; const MODEL_EXT: Record = { [ViroModelFormat.GLB]: "glb", @@ -73,6 +73,12 @@ function computeSize( * `create()` gives you an empty scene. Build into it through {@link scene}, * the handle-based API the Viro web bridge's reconciler drives. */ +/** Context loss notifications; see ViroWebRenderer.isContextLost. */ +export interface ViroContextListener { + onLost?: () => void; + onRestored?: () => void; +} + export class ViroWebRenderer { private disposed = false; private detachInput?: () => void; @@ -81,7 +87,11 @@ export class ViroWebRenderer { private readonly modelLoadResolvers = new Map void>(); private readonly animationHandlers = new Map(); private readonly abortListeners = new Set<(error: ViroRendererAbortError) => void>(); + private readonly textFaces = new Map>(); private abortError: ViroRendererAbortError | null = null; + private contextLost = false; + private readonly contextListeners = new Set(); + private detachContext?: () => void; private constructor( private readonly module: ViroWebModule, @@ -196,6 +206,40 @@ export class ViroWebRenderer { } } + /** + * Makes the face a text at `weight` (100 to 900) and `italic` draws in ready + * to use. Only the regular face is preloaded; the others are served beside + * the wasm and fetched the first time a text asks for them, and stay in the + * FS after. Resolves false when the face could not be had, in which case + * such a text draws in the regular face. + */ + loadTextFace(weight = 400, italic = false): Promise { + const file = this.module.viroTextFaceFile?.(weight, italic); + if (!file || file === "Roboto") return Promise.resolve(true); + let pending = this.textFaces.get(file); + if (!pending) { + const locate = this.module.locateFile as LocateFile | undefined; + const url = locate ? locate(`${file}.ttf`, "") : `${file}.ttf`; + pending = fetch(url) + .then((res) => { + if (!res.ok) throw new Error(`HTTP ${res.status}`); + return res.arrayBuffer(); + }) + .then((buf) => { + this.module.FS.writeFile(`/${file}.ttf`, new Uint8Array(buf)); + return true; + }) + .catch((err) => { + console.warn(`[Viro web] could not load the ${file} face from ${url} (${err}); drawing that text in Roboto`); + // Asked again next time, rather than failing for the rest of the page. + this.textFaces.delete(file); + return false; + }); + this.textFaces.set(file, pending); + } + return pending; + } + /** * Load a radiance .hdr from a URL and apply it as the scene's IBL lighting * environment. Fetches the bytes, writes them to the WASM FS, then loads + @@ -253,6 +297,12 @@ export class ViroWebRenderer { handlers.onClick?.(intArg, source, position); } else if (action === ViroEventAction.Hover) { handlers.onHover?.(intArg === 1, source, position); + } else if (action === ViroEventAction.Pinch) { + handlers.onPinch?.(intArg, position[0], source); + } else if (action === ViroEventAction.Rotate) { + handlers.onRotate?.(intArg, position[0], source); + } else if (action === ViroEventAction.Fuse) { + handlers.onFuse?.(source); } } @@ -284,37 +334,126 @@ export class ViroWebRenderer { console.log("[Viro web] renderer build " + buildId); } renderer.attachInput(); + renderer.attachContextLoss(); return renderer; } /** * Forward canvas pointer events to the renderer as touch actions, converting * CSS coordinates to the canvas's device-pixel backing store. + * + * A second finger turns the touch into a pinch and a rotate, as on a phone: + * the first finger's press is cancelled without a click, both gestures start + * on the node under the fingers' midpoint, and nothing more reaches the scene + * until every finger has lifted. `pointercancel` cancels the press too, for + * any pointer id (the virtual camera sends one when it takes two fingers). */ private attachInput(): void { const canvas = this.canvas; - const send = (action: number, e: PointerEvent) => { + const m = this.module; + const toCanvas = (clientX: number, clientY: number): [number, number] | null => { const rect = canvas.getBoundingClientRect(); - if (rect.width === 0 || rect.height === 0) return; - const x = (e.clientX - rect.left) * (canvas.width / rect.width); - const y = (e.clientY - rect.top) * (canvas.height / rect.height); - this.module.viroOnTouch(action, x, y); + if (rect.width === 0 || rect.height === 0) return null; + return [(clientX - rect.left) * (canvas.width / rect.width), (clientY - rect.top) * (canvas.height / rect.height)]; + }; + const send = (action: number, e: PointerEvent) => { + const p = toCanvas(e.clientX, e.clientY); + if (p) m.viroOnTouch(action, p[0], p[1]); }; - const onDown = (e: PointerEvent) => send(0, e); - const onMove = (e: PointerEvent) => send(1, e); - const onUp = (e: PointerEvent) => send(2, e); + const fingers = new Map(); + // Starts on the first move, as iOS and Android recognisers do: two fingers + // that land and lift without moving are no gesture at all. + let gesture: { spread: number; angle: number; started: boolean; at: [number, number] } | null = null; + // Set once a gesture starts and cleared when the last finger lifts. + let held = false; + const pair = () => { + const [a, b] = [...fingers.values()]; + return { + mid: toCanvas((a!.x + b!.x) / 2, (a!.y + b!.y) / 2), + spread: Math.hypot(b!.x - a!.x, b!.y - a!.y), + angle: Math.atan2(b!.y - a!.y, b!.x - a!.x), + }; + }; + const gestureEvent = (state: number, scale: number, radians: number, at: [number, number]) => { + m.viroOnPinch!(state, scale, at[0], at[1]); + m.viroOnRotate!(state, radians, at[0], at[1]); + }; + let last = { scale: 1, radians: 0, at: [0, 0] as [number, number] }; + const endGesture = () => { + if (gesture?.started) gestureEvent(3, last.scale, last.radians, last.at); + gesture = null; + }; + + const onDown = (e: PointerEvent) => { + if (e.pointerType === "touch" && typeof m.viroOnPinch === "function") { + fingers.set(e.pointerId, { x: e.clientX, y: e.clientY }); + if (fingers.size === 2 && !held) { + held = true; + m.viroOnTouch(3, 0, 0); + const p = pair(); + if (p.mid && p.spread > 0) { + gesture = { spread: p.spread, angle: p.angle, started: false, at: p.mid }; + last = { scale: 1, radians: 0, at: p.mid }; + } + } + if (held) return; + } + send(0, e); + }; + const onMove = (e: PointerEvent) => { + if (fingers.has(e.pointerId)) { + fingers.set(e.pointerId, { x: e.clientX, y: e.clientY }); + if (held) { + if (gesture && fingers.size >= 2) { + if (!gesture.started) { + gesture.started = true; + gestureEvent(1, 1, 0, gesture.at); + } + const p = pair(); + // Screen y points down, so a clockwise turn grows the angle; native + // reports counterclockwise as positive. + let turn = gesture.angle - p.angle; + turn = Math.atan2(Math.sin(turn), Math.cos(turn)); + last = { scale: p.spread / gesture.spread, radians: last.radians + turn, at: p.mid ?? last.at }; + gesture.angle = p.angle; + gestureEvent(2, last.scale, last.radians, last.at); + } + return; + } + } + send(1, e); + }; + const onUp = (e: PointerEvent) => { + fingers.delete(e.pointerId); + if (held) { + if (fingers.size < 2) endGesture(); + if (fingers.size === 0) held = false; + return; + } + send(2, e); + }; + // Any id ends the press: the virtual camera cancels with the second finger's + // id and then keeps both fingers' events to itself. + const onCancel = (e: PointerEvent) => { + if (held) { + onUp(e); + return; + } + fingers.clear(); + m.viroOnTouch(3, 0, 0); + }; canvas.addEventListener("pointerdown", onDown); canvas.addEventListener("pointermove", onMove); canvas.addEventListener("pointerup", onUp); - canvas.addEventListener("pointercancel", onUp); + canvas.addEventListener("pointercancel", onCancel); this.detachInput = () => { canvas.removeEventListener("pointerdown", onDown); canvas.removeEventListener("pointermove", onMove); canvas.removeEventListener("pointerup", onUp); - canvas.removeEventListener("pointercancel", onUp); + canvas.removeEventListener("pointercancel", onCancel); }; } @@ -340,17 +479,18 @@ export class ViroWebRenderer { /** * Release references and stop responding to input. * - * NOTE: the WASM main loop is not stoppable from the C API yet — a proper - * teardown (emscripten_cancel_main_loop + context destroy) is a follow-up. - * Until then a disposed renderer keeps drawing, so an app that mounts and - * unmounts repeatedly accumulates render loops. Create one and keep it. + * Stops the render loop on a binary that can (older ones keep drawing). * * Any model load still in flight is settled as failed: its native callback * would have nowhere to arrive. */ dispose(): void { + this.module.viroStopMainLoop?.(); this.detachInput?.(); this.detachInput = undefined; + this.detachContext?.(); + this.detachContext = undefined; + this.contextListeners.clear(); for (const resolve of this.modelLoadResolvers.values()) resolve(false); this.modelLoadResolvers.clear(); this.eventHandlers.clear(); @@ -358,6 +498,44 @@ export class ViroWebRenderer { this.disposed = true; } + /** + * True once the browser has taken the WebGL context away (a GPU reset, or a + * mobile browser reclaiming memory). Nothing this renderer made comes back + * with the context: when it is restored, dispose this renderer and create a + * new one on the same canvas. + */ + get isContextLost(): boolean { + return this.contextLost; + } + + /** Be told when the context is lost and when it is back. Returns an unsubscribe. */ + addContextListener(listener: ViroContextListener): () => void { + this.contextListeners.add(listener); + return () => { + this.contextListeners.delete(listener); + }; + } + + private attachContextLoss(): void { + const canvas = this.canvas; + const onLost = (e: Event) => { + // Without this the browser never restores the context. + e.preventDefault(); + this.contextLost = true; + this.module.viroStopMainLoop?.(); + for (const l of [...this.contextListeners]) l.onLost?.(); + }; + const onRestored = () => { + for (const l of [...this.contextListeners]) l.onRestored?.(); + }; + canvas.addEventListener("webglcontextlost", onLost); + canvas.addEventListener("webglcontextrestored", onRestored); + this.detachContext = () => { + canvas.removeEventListener("webglcontextlost", onLost); + canvas.removeEventListener("webglcontextrestored", onRestored); + }; + } + /** * Set once the WASM runtime has aborted (see ViroWebRendererOptions.onAbort). * A renderer in that state cannot recover; a new one has to be created. diff --git a/src/index.ts b/src/index.ts index c1042db..7b175fc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,7 +4,7 @@ * WebAssembly/WebGL2 build of the Viro renderer (virocore) for the web platform. */ -export { ViroWebRenderer } from "./ViroWebRenderer.js"; +export { ViroWebRenderer, type ViroContextListener } from "./ViroWebRenderer.js"; export { loadViroWebModule } from "./loader.js"; export { loadBundledSlam } from "./slamLoader.js"; export { @@ -12,16 +12,19 @@ export { ViroLightingModel, ViroLightType, ViroEventAction, + ViroGestureState, ViroClickState, ViroTextureChannel, ViroWrapMode, ViroFilterMode, ViroCullMode, ViroBlendMode, + ViroColorWriteMask, ViroModelFormat, ViroEasing, ViroTrackingState, ViroTextHorizontalAlignment, + ViroTextOuterStroke, ViroTextVerticalAlignment, ViroLineBreakMode, ViroTextClipMode, @@ -37,8 +40,11 @@ export { VIRO_INVALID_HANDLE, } from "./sceneApi.js"; export type { + ViroTextStyle, ViroHandle, ViroNodeEventHandlers, + ViroNodeTransform, + ViroBoundingBox, ViroAnimationHandlers, ViroShaderEntryPoint, } from "./sceneApi.js"; diff --git a/src/sceneApi.ts b/src/sceneApi.ts index 967f4c1..583ef61 100644 --- a/src/sceneApi.ts +++ b/src/sceneApi.ts @@ -56,6 +56,16 @@ export enum ViroBlendMode { Screen = 5, } +/** Bits of VROColorMask (VRODriver.h); combine with `|`. */ +export enum ViroColorWriteMask { + None = 0, + Red = 1, + Green = 2, + Blue = 4, + Alpha = 8, + All = 15, +} + /** Mirrors VROShaderEntryPoint (VROShaderModifier.h). Unknown strings fall back to "fragment". */ export type ViroShaderEntryPoint = | "geometry" @@ -66,6 +76,27 @@ export type ViroShaderEntryPoint = | "image"; /** Text horizontal alignment (mirrors VROTextHorizontalAlignment). */ +export enum ViroTextOuterStroke { + None = 0, + Outline = 1, + DropShadow = 2, +} + +/** What createStyledText adds to createText, with ViroText's defaults when left out. */ +export interface ViroTextStyle { + /** Comma-separated families, tried in order; a family this build lacks draws in Roboto. */ + typefaces?: string; + /** 100 to 900. Faces other than the regular one need ViroWebRenderer.loadTextFace first. */ + weight?: number; + italic?: boolean; + /** Depth of 3D text; 0 draws flat text. */ + extrusion?: number; + stroke?: ViroTextOuterStroke; + /** In glyph pixels, as native takes it. */ + strokeWidth?: number; + strokeColor?: { r: number; g: number; b: number; a: number }; +} + export enum ViroTextHorizontalAlignment { Left = 0, Right = 1, @@ -209,6 +240,16 @@ export enum ViroEventAction { Hover = 1, Click = 2, Touch = 3, + Fuse = 9, + Pinch = 10, + Rotate = 11, +} + +/** Mirrors VROEventDelegate::PinchState and RotateState. */ +export enum ViroGestureState { + Start = 1, + Move = 2, + End = 3, } /** Mirrors VROEventDelegate::ClickState. */ @@ -236,6 +277,29 @@ export interface ViroNodeEventHandlers { source: number, position: [number, number, number], ) => void; + /** scale is cumulative from 1 at the start. */ + onPinch?: (state: ViroGestureState, scale: number, source: number) => void; + /** Radians, counterclockwise on screen, cumulative from 0 at the start. */ + onRotate?: (state: ViroGestureState, radians: number, source: number) => void; + /** The gaze (screen centre) stayed on the node for its time to fuse. */ + onFuse?: (source: number) => void; +} + +/** A node's last-frame world transform; rotation in degrees. */ +export interface ViroNodeTransform { + position: [number, number, number]; + rotation: [number, number, number]; + scale: [number, number, number]; +} + +/** A node's and its subtree's bounding box. */ +export interface ViroBoundingBox { + minX: number; + maxX: number; + minY: number; + maxY: number; + minZ: number; + maxZ: number; } /** @@ -268,6 +332,10 @@ export class ViroSceneApi { setNodeVisible(node: ViroHandle, visible: boolean): void { this.m.viroSetNodeVisible(node, visible); } + /** A node that is not selectable is skipped by taps and hit tests, along with its whole subtree. */ + setNodeSelectable(node: ViroHandle, selectable: boolean): void { + this.m.viroSetNodeSelectable(node, selectable); + } setNodeGeometry(node: ViroHandle, geometry: ViroHandle): void { this.m.viroSetNodeGeometry(node, geometry); } @@ -319,6 +387,33 @@ export class ViroSceneApi { if (!p || p.length < 3) return null; return [p[0]!, p[1]!, p[2]!]; } + /** + * Last frame's world transform, decomposed as native's getTransformAsync does, + * or null on a binary without it. Zero until the node has been drawn once. + */ + getNodeWorldTransform(node: ViroHandle): ViroNodeTransform | null { + const t = this.m.viroGetNodeWorldTransform?.(node); + if (!t || t.length < 9) return null; + return { + position: [t[0]!, t[1]!, t[2]!], + rotation: [t[3]!, t[4]!, t[5]!], + scale: [t[6]!, t[7]!, t[8]!], + }; + } + /** The node's and its subtree's box, or null on a binary without it. */ + getNodeBoundingBox(node: ViroHandle): ViroBoundingBox | null { + const b = this.m.viroGetNodeBoundingBox?.(node); + if (!b || b.length < 6) return null; + return { minX: b[0]!, maxX: b[1]!, minY: b[2]!, maxY: b[3]!, minZ: b[4]!, maxZ: b[5]! }; + } + /** How long the gaze must rest on the node before onFuse; virocore's default is 2000 ms. */ + setNodeTimeToFuse(node: ViroHandle, millis: number): void { + this.m.viroSetNodeTimeToFuse?.(node, millis); + } + /** False on a binary without pinch, rotate, fuse and the node transform reads. */ + get supportsGestures(): boolean { + return typeof this.m.viroOnPinch === "function"; + } // --- Geometries --- createBox(width: number, height: number, length: number): ViroHandle { @@ -377,6 +472,39 @@ export class ViroSceneApi { color.a, ); } + /** False on a binary without styled text, where createStyledText draws plain text. */ + get supportsTextStyle(): boolean { + return typeof this.m.viroCreateStyledText === "function"; + } + createStyledText( + text: string, + width: number, + height: number, + fontSize: number, + hAlign: ViroTextHorizontalAlignment, + vAlign: ViroTextVerticalAlignment, + lineBreak: ViroLineBreakMode, + clipMode: ViroTextClipMode, + maxLines: number, + color: { r: number; g: number; b: number; a: number }, + style: ViroTextStyle, + ): ViroHandle { + if (typeof this.m.viroCreateStyledText !== "function") { + return this.createText(text, width, height, fontSize, hAlign, vAlign, lineBreak, clipMode, maxLines, color); + } + return this.m.viroCreateStyledText(text, { + ...style, + width, + height, + fontSize, + hAlign, + vAlign, + lineBreak, + clipMode, + maxLines, + color, + }); + } /** points: flat [x,y,z, …]. */ createPolyline(points: Float32Array | number[], thickness: number): ViroHandle { return this.m.viroCreatePolyline(points, thickness); @@ -444,6 +572,28 @@ export class ViroSceneApi { setMaterialReadsFromDepthBuffer(material: ViroHandle, reads: boolean): void { this.m.viroSetMaterialReadsFromDepthBuffer(material, reads); } + /** + * False on a binary without the four setters below, where they do nothing: + * alpha, bloom threshold, colour write mask and chroma key. + */ + get supportsMaterialEffects(): boolean { + return typeof this.m.viroSetMaterialTransparency === "function"; + } + /** 0 to 1, multiplied with the diffuse colour's alpha and the node's opacity. */ + setMaterialAlpha(material: ViroHandle, alpha: number): void { + this.m.viroSetMaterialTransparency?.(material, alpha); + } + /** Under 0 (the default, -1) keeps the material out of the bloom pass. */ + setMaterialBloomThreshold(material: ViroHandle, threshold: number): void { + this.m.viroSetMaterialBloomThreshold?.(material, threshold); + } + setMaterialColorWriteMask(material: ViroHandle, mask: ViroColorWriteMask | number): void { + this.m.viroSetMaterialColorWriteMask?.(material, mask); + } + /** Pixels near `color` are discarded; null turns the filter off. */ + setMaterialChromaKey(material: ViroHandle, color: { r: number; g: number; b: number } | null): void { + this.m.viroSetMaterialChromaKey?.(material, color !== null, color?.r ?? 0, color?.g ?? 1, color?.b ?? 0); + } // shaderCode should already have any `uniforms` declarations prepended // (uniforms + "\n" + body) — the caller owns that concatenation, same as // MaterialManager.java::parseShaderModifiers on Android. diff --git a/src/types.ts b/src/types.ts index 7bc06b3..234dd75 100644 --- a/src/types.ts +++ b/src/types.ts @@ -18,6 +18,9 @@ export interface ViroWebModule { /** Feed a pointer/touch event. action: 0 = down, 1 = move, 2 = up. x/y in device pixels. */ viroOnTouch(action: number, x: number, y: number): void; + viroStopMainLoop?(): void; + viroOnPinch?(state: number, scale: number, x: number, y: number): void; + viroOnRotate?(state: number, radians: number, x: number, y: number): void; /** Build the hardcoded demo cube scene (smoke test). */ viroBuildDemoCube(): void; @@ -30,6 +33,7 @@ export interface ViroWebModule { viroSetNodeScale(node: number, x: number, y: number, z: number): void; viroSetNodeOpacity(node: number, opacity: number): void; viroSetNodeVisible(node: number, visible: boolean): void; + viroSetNodeSelectable(node: number, selectable: boolean): void; viroSetNodeGeometry(node: number, geometry: number): void; viroAddChildNode(parent: number, child: number): void; viroRemoveNodeFromParent(node: number): void; @@ -40,6 +44,9 @@ export interface ViroWebModule { // axis: 0 X, 1 Y, 2 Z, 3 all; anything else removes the constraint. viroSetNodeBillboard(node: number, axis: number): void; viroGetNodeWorldPosition(node: number): number[]; + viroGetNodeWorldTransform?(node: number): number[]; + viroGetNodeBoundingBox?(node: number): number[]; + viroSetNodeTimeToFuse?(node: number, millis: number): void; viroCreateBox(width: number, height: number, length: number): number; viroCreateSphere(radius: number): number; @@ -67,6 +74,11 @@ export interface ViroWebModule { b: number, a: number, ): number; + // viroCreateText's fields by name, plus the style; see ViroSceneApi.createStyledText. + // Absent from binaries before 1.2.0, as is viroTextFaceFile. + viroCreateStyledText?(text: string, options: Record): number; + // The face file (no suffix) a text at this weight and style draws in. + viroTextFaceFile?(weight: number, italic: boolean): string; // Flat [x,y,z, …] point list. viroCreatePolyline(points: Float32Array | number[], thickness: number): number; viroCreatePolygon(points: Float32Array | number[]): number; @@ -93,6 +105,10 @@ export interface ViroWebModule { viroSetMaterialBlendMode(material: number, mode: number): void; viroSetMaterialWritesToDepthBuffer(material: number, writes: boolean): void; viroSetMaterialReadsFromDepthBuffer(material: number, reads: boolean): void; + viroSetMaterialTransparency?(material: number, alpha: number): void; + viroSetMaterialBloomThreshold?(material: number, threshold: number): void; + viroSetMaterialColorWriteMask?(material: number, mask: number): void; + viroSetMaterialChromaKey?(material: number, enabled: boolean, r: number, g: number, b: number): void; // shaderCode is the modifier body with any `uniforms` block already // prepended by the caller (uniforms + "\n" + body), matching the native // bridges' convention. varyings is optional; pass undefined for none. diff --git a/test/package.test.mjs b/test/package.test.mjs index 5027fd8..5e1fb29 100644 --- a/test/package.test.mjs +++ b/test/package.test.mjs @@ -81,6 +81,14 @@ if (!haveWasm) { "viro-web.data names a font but carries no TrueType or OpenType data", ); console.log(` ok ${preloaded.join(", ")} preloaded, and redistributable`); + + // Every face VROTypefaceWasm::systemFaceFile can name, served beside the wasm. + const faces = ["Thin", "Light", "Medium", "Bold", "Black"] + .flatMap((w) => [`Roboto-${w}`, `Roboto-${w}Italic`]) + .concat("Roboto-Italic"); + const absentFaces = faces.filter((f) => !existsSync(`${root}wasm/${f}.ttf`)); + assert.deepEqual(absentFaces, [], "Roboto faces missing beside the wasm -- run npm run copy-wasm"); + console.log(` ok ${faces.length} Roboto faces beside the wasm`); } const pkg = JSON.parse(read("package.json").toString());