Skip to content

A lightweight 2.5D character player for the web, with lip sync and webcam face tracking.

Examples: a cover shows at once and the character fades in, ?model= stays on the same site

LivLiv42f5de8d7a52
diff --git a/API.md b/API.md
index 8da87de..6b67363 100644
--- a/API.md
+++ b/API.md
@@ -30,7 +30,7 @@ Serve the file as it is, or unzip it and serve the folder like any static files:
sena/
model.json # the manifest and the rig: layers, anchors, expressions, meta (author, licence, the mark)
textures/*.webp # the layer images
- avatar.webp # a small square picture; cover.webp: the character at rest
+ avatar.webp # a small square picture
keyforms.json # head-turn key poses (refined characters only)
```
@@ -353,4 +353,4 @@ npm run build # dist/: index.js, tracking.js, voice.js (ES modules), ch
Examples: serve this repository's folder with any static server (for example `python3 -m http.server`) and open
`/example/` (a few lines) or `/example/demo.html` (expressions, actions, microphone, camera, open a folder;
-`?model=<url>` loads another model). Both start with a featured character from `characters/`.
+`?model=<url>` loads another model from the same site). Both start with a featured character from `characters/`.
diff --git a/README.ja.md b/README.ja.md
index 1932467..602e436 100644
--- a/README.ja.md
+++ b/README.ja.md
@@ -75,6 +75,8 @@ API の全体は [API.md](API.md)(英語)にあります:オプション
Kujira、Kujira Q、Pen は他の方の作品に基づくもので、上記のライセンスとクレジットは適用されません。出典、クレジット、条件は [characters/CREDITS.md](characters/CREDITS.md) をご覧ください。
+各キャラクターには `cover.webp`(512 x 768、約 50 KB)もあります。最初のフレームで、マークは入っていません。キャンバスの下に `object-fit: contain` で置き、準備ができたらキャラクターをフェードインさせます([example/loading.js](example/loading.js) がこの方法です)。ページにすぐ絵が出て、切り替わるときにずれません。
+
キャラクターの一覧は[英語の README](README.md#featured-characters) にあります。
## 自分のキャラクター
diff --git a/README.md b/README.md
index 9fe43e7..4e35921 100644
--- a/README.md
+++ b/README.md
@@ -83,6 +83,10 @@ LivLiv's mascot. The terms are in [characters/LICENSE.md](characters/LICENSE.md)
Kujira, Kujira Q and Pen come from other people's work: that licence and that credit don't cover them. Their sources,
credits and terms are in [characters/CREDITS.md](characters/CREDITS.md).
+Each also has a `cover.webp` (512 x 768, about 50 KB), its first frame without the mark. Show it under the canvas with
+`object-fit: contain` and fade the character in over it, as [example/loading.js](example/loading.js) does: the page has a
+picture at once, and nothing jumps.
+
| id | name | id | name | id | name |
|---|---|---|---|---|---|
| `k01` | Sena | `d01` | Yui | `v01` | Aster |
diff --git a/README.zh-CN.md b/README.zh-CN.md
index 49c3e06..1b9a0f5 100644
--- a/README.zh-CN.md
+++ b/README.zh-CN.md
@@ -77,6 +77,8 @@ await png.load({ closed: 'me-closed.png', open: 'me-open.png' })
Kujira、Kujira Q 和 Pen 来自别人的作品,不适用上面的许可和署名。它们的来源、署名和条款见 [characters/CREDITS.md](characters/CREDITS.md)。
+每个角色还带一张 `cover.webp`(512 x 768,约 50 KB),是它的第一帧,不带标。把它放在画布下面(`object-fit: contain`),角色好了再淡入,[example/loading.js](example/loading.js) 就是这样做的:页面马上有画面,也不会跳一下。
+
角色列表见[英文 README](README.md#featured-characters)。
## 用自己的角色
diff --git a/characters/char06/cover.webp b/characters/char06/cover.webp
new file mode 100644
index 0000000..3943b4a
Binary files /dev/null and b/characters/char06/cover.webp differ
diff --git a/characters/char07/cover.webp b/characters/char07/cover.webp
new file mode 100644
index 0000000..d0c3442
Binary files /dev/null and b/characters/char07/cover.webp differ
diff --git a/characters/d01/cover.webp b/characters/d01/cover.webp
new file mode 100644
index 0000000..6bd886b
Binary files /dev/null and b/characters/d01/cover.webp differ
diff --git a/characters/d02/cover.webp b/characters/d02/cover.webp
new file mode 100644
index 0000000..acc60c5
Binary files /dev/null and b/characters/d02/cover.webp differ
diff --git a/characters/d03/cover.webp b/characters/d03/cover.webp
new file mode 100644
index 0000000..52f8221
Binary files /dev/null and b/characters/d03/cover.webp differ
diff --git a/characters/d03ft/cover.webp b/characters/d03ft/cover.webp
new file mode 100644
index 0000000..f75425f
Binary files /dev/null and b/characters/d03ft/cover.webp differ
diff --git a/characters/k01/cover.webp b/characters/k01/cover.webp
new file mode 100644
index 0000000..7b36539
Binary files /dev/null and b/characters/k01/cover.webp differ
diff --git a/characters/k02/cover.webp b/characters/k02/cover.webp
new file mode 100644
index 0000000..b83f1d9
Binary files /dev/null and b/characters/k02/cover.webp differ
diff --git a/characters/p01/cover.webp b/characters/p01/cover.webp
new file mode 100644
index 0000000..4256f2b
Binary files /dev/null and b/characters/p01/cover.webp differ
diff --git a/characters/p02/cover.webp b/characters/p02/cover.webp
new file mode 100644
index 0000000..18fd008
Binary files /dev/null and b/characters/p02/cover.webp differ
diff --git a/characters/p03/cover.webp b/characters/p03/cover.webp
new file mode 100644
index 0000000..43d1c03
Binary files /dev/null and b/characters/p03/cover.webp differ
diff --git a/characters/q02/cover.webp b/characters/q02/cover.webp
new file mode 100644
index 0000000..fe04fd7
Binary files /dev/null and b/characters/q02/cover.webp differ
diff --git a/characters/q03/cover.webp b/characters/q03/cover.webp
new file mode 100644
index 0000000..ee848a7
Binary files /dev/null and b/characters/q03/cover.webp differ
diff --git a/characters/s01/cover.webp b/characters/s01/cover.webp
new file mode 100644
index 0000000..3136445
Binary files /dev/null and b/characters/s01/cover.webp differ
diff --git a/characters/v01/cover.webp b/characters/v01/cover.webp
new file mode 100644
index 0000000..436f5fd
Binary files /dev/null and b/characters/v01/cover.webp differ
diff --git a/characters/v03/cover.webp b/characters/v03/cover.webp
new file mode 100644
index 0000000..0180d1d
Binary files /dev/null and b/characters/v03/cover.webp differ
diff --git a/characters/v04/cover.webp b/characters/v04/cover.webp
new file mode 100644
index 0000000..f968425
Binary files /dev/null and b/characters/v04/cover.webp differ
diff --git a/characters/v05/cover.webp b/characters/v05/cover.webp
new file mode 100644
index 0000000..c60924d
Binary files /dev/null and b/characters/v05/cover.webp differ
diff --git a/characters/v06/cover.webp b/characters/v06/cover.webp
new file mode 100644
index 0000000..1fd408c
Binary files /dev/null and b/characters/v06/cover.webp differ
diff --git a/characters/v07/cover.webp b/characters/v07/cover.webp
new file mode 100644
index 0000000..259238f
Binary files /dev/null and b/characters/v07/cover.webp differ
diff --git a/characters/w01/cover.webp b/characters/w01/cover.webp
new file mode 100644
index 0000000..94a23d8
Binary files /dev/null and b/characters/w01/cover.webp differ
diff --git a/example/demo.html b/example/demo.html
index 374579d..71f3217 100644
--- a/example/demo.html
+++ b/example/demo.html
@@ -7,12 +7,15 @@
<script type="importmap">{ "imports": { "@mediapipe/tasks-vision": "https://cdn.jsdelivr.net/npm/@mediapipe/[email protected]/vision_bundle.mjs" } }</script>
<style>
html, body { margin: 0; height: 100%; background: #20222b; color: #eef; font: 14px system-ui, sans-serif }
- canvas { display: block; width: 100%; height: 100% }
+ canvas { position: relative; display: block; width: 100%; height: 100% }
+ #cover { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; pointer-events: none }
.bar { position: fixed; z-index: 1; left: 12px; right: 12px; top: 12px; display: flex; flex-wrap: wrap; gap: 6px }
button, label { font: inherit; padding: 6px 11px; border: 0; border-radius: 8px; background: #ffffff1c; color: inherit; cursor: pointer }
button[aria-pressed="true"] { background: #ff4d5e }
#status { position: fixed; z-index: 1; left: 12px; bottom: 12px; margin: 0; opacity: .8 }
</style>
+<img id="cover" alt="" src="../characters/d03ft/cover.webp">
+<script>if (new URLSearchParams(location.search).has('model')) document.getElementById('cover').removeAttribute('src')</script>
<canvas id="stage"></canvas>
<div class="bar" id="bar"></div>
<p id="status" role="status"></p>
@@ -20,10 +23,11 @@
<script type="module">
import { Player } from '../dist/index.js'
import { cameraButton } from './camera.js'
- import { loadWithFallback, loading, needWebGL } from './loading.js'
+ import { loadWithFallback, loading, needWebGL, sameSite } from './loading.js'
needWebGL(Player)
- const player = new Player(document.getElementById('stage'))
+ const canvas = document.getElementById('stage'), cover = document.getElementById('cover')
+ const player = new Player(canvas)
const bar = document.getElementById('bar'), status = document.getElementById('status')
window.player = player // to try things in the console
@@ -31,11 +35,10 @@
const b = document.createElement('button'); b.textContent = text; b.onclick = () => onClick(b); bar.append(b); return b
}
- // a model: a featured character, ?model=<URL of a model.json or its folder>, or a folder picked below
+ // a model: a featured character, ?model=<URL of a model.json or its folder, on this site>, or a file picked below
async function show(source) {
status.textContent = ''
- // a featured character's small picture lies in its folder, beside its package
- const done = loading(document.body, typeof source === 'string' && /(\/|\.livliv)$/.test(source) ? `${source.replace(/\.livliv$/, '/')}avatar.webp` : null)
+ const done = loading(canvas, cover, source)
try {
const m = await loadWithFallback(player, source)
status.textContent = `${m.name} · ${m.format} ${m.version} · mark: ${m.watermark ?? 'none'}${m.meta?.license ? ` · ${m.meta.license.id}` : ''}`
@@ -76,6 +79,11 @@
window.camera = cameraButton(button('camera'), player, status)
}
- show(new URLSearchParams(location.search).get('model') || '../characters/d03ft.livliv')
+ const asked = new URLSearchParams(location.search).get('model')
+ if (!asked || sameSite(asked)) show(asked || '../characters/d03ft.livliv')
+ else {
+ status.textContent = '?model= opens files on this site only. For another file, save it and use the buttons above.'
+ controls(null)
+ }
</script>
</html>
diff --git a/example/gallery.html b/example/gallery.html
index 1c41845..781599e 100644
--- a/example/gallery.html
+++ b/example/gallery.html
@@ -8,7 +8,8 @@
main { max-width: 900px; margin: 0 auto; padding: 16px }
.stage { background: #fff; border-radius: 16px; overflow: hidden }
.view { position: relative }
- canvas { display: block; width: 100%; height: min(70vh, 640px); cursor: pointer }
+ canvas { position: relative; display: block; width: 100%; height: min(70vh, 640px); cursor: pointer }
+ #cover { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; pointer-events: none }
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 10px 14px }
.bar b { margin-right: auto; font-size: 15px }
#credit { margin: 0; padding: 0 14px 10px; color: #666; font-size: 12px }
@@ -22,7 +23,10 @@
</style>
<main>
<div class="stage">
- <div class="view" id="view"><canvas id="stage"></canvas></div>
+ <div class="view"><img id="cover" alt=""><canvas id="stage"></canvas></div>
+ <script> // the first character's cover, before anything else arrives
+ document.getElementById('cover').src = `../characters/${new URLSearchParams(location.search).get('id')?.match(/^\w+$/)?.[0] ?? 'd03ft'}/cover.webp`
+ </script>
<div class="bar" id="bar"><b id="name"></b></div>
<p id="credit"></p>
</div>
@@ -42,7 +46,8 @@
const cast = list.sort((a, b) => rank(a.id) - rank(b.id)) // the rest keep the list's order
needWebGL(Player)
- const player = new Player(document.getElementById('stage'), { maxPixelRatio: 1.5 })
+ const canvas = document.getElementById('stage'), cover = document.getElementById('cover')
+ const player = new Player(canvas, { maxPixelRatio: 1.5 })
const bar = document.getElementById('bar'), name = document.getElementById('name'), credit = document.getElementById('credit'), ul = document.getElementById('cast')
const buttons = new Map()
let current = null, exprs = [], next = -1
@@ -63,10 +68,10 @@
current = id
const press = (on) => { for (const [k, b] of buttons) b.setAttribute('aria-pressed', String(k === on)) }
press(id)
- const done = loading(document.getElementById('view'), `../characters/${id}/avatar.webp`)
+ const source = `../characters/${id}.livliv`, done = loading(canvas, cover, source)
let m
try {
- m = await loadWithFallback(player, `../characters/${id}.livliv`).finally(done)
+ m = await loadWithFallback(player, source).finally(done)
} catch (e) { // the one on the stage stays; a click can try this one again
if (id === current) { current = before; press(before); name.textContent = e.message }
return
@@ -86,7 +91,7 @@
}
}
// a click on the stage: the next expression, then neutral again
- document.getElementById('stage').onclick = () => { next = next + 1 < exprs.length ? next + 1 : -1; player.setExpression(exprs[next]?.id ?? null) }
+ canvas.onclick = () => { next = next + 1 < exprs.length ? next + 1 : -1; player.setExpression(exprs[next]?.id ?? null) }
await show(cast.some((c) => c.id === q.get('id')) ? q.get('id') : 'd03ft')
if (demo) {
diff --git a/example/index.html b/example/index.html
index 90b92e7..42b2694 100644
--- a/example/index.html
+++ b/example/index.html
@@ -3,19 +3,21 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>LivLiv Player: minimal</title>
-<style>html, body { margin: 0; height: 100%; background: #20222b } canvas { display: block; width: 100%; height: 100% }</style>
+<style>html, body { margin: 0; height: 100%; background: #20222b } canvas { position: relative; display: block; width: 100%; height: 100% }
+#cover { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain }</style>
+<img id="cover" alt="" src="../characters/d03ft/cover.webp">
<canvas id="stage"></canvas>
-<p id="wait" style="position:fixed;inset:45% 0 auto;margin:0;color:#eef;font:14px system-ui,sans-serif;text-align:center">Loading…</p>
+<p id="note" style="position:fixed;z-index:1;inset:45% 0 auto;margin:0;color:#eef;font:14px system-ui,sans-serif;text-align:center"></p>
<script type="module">
import { Player } from '../dist/index.js'
- import { loadWithFallback } from './loading.js'
+ import { loadWithFallback, loading } from './loading.js'
// a featured character; your own export works the same
- const wait = document.getElementById('wait')
- if (!Player.isSupported()) { wait.textContent = 'This browser has no WebGL2'; throw new Error('no WebGL2') }
- const player = new Player(document.getElementById('stage'))
- const model = await loadWithFallback(player, '../characters/d03ft.livliv').catch((e) => { wait.textContent = e.message; throw e })
- wait.remove()
+ const note = document.getElementById('note'), canvas = document.getElementById('stage')
+ if (!Player.isSupported()) { note.textContent = 'This browser has no WebGL2'; throw new Error('no WebGL2') }
+ const player = new Player(canvas)
+ const done = loading(canvas, document.getElementById('cover'), '../characters/d03ft.livliv')
+ const model = await loadWithFallback(player, '../characters/d03ft.livliv').catch((e) => { note.textContent = e.message; throw e }).finally(done)
// each click shows the next expression, then neutral again
let i = -1
diff --git a/example/loading.js b/example/loading.js
index 65e1634..decbfd3 100644
--- a/example/loading.js
+++ b/example/loading.js
@@ -1,26 +1,52 @@
// The example pages' wait for a character.
-/** A picture and "Loading…" over the page until `done()`, shown only if the load takes a moment. */
-export function loading(parent, picture) {
- const box = document.createElement('div')
- box.style.cssText = 'position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:8px;pointer-events:none'
- if (picture) {
- const img = new Image(96, 96)
- img.alt = ''
- img.style.borderRadius = '12px'
- img.onerror = () => img.remove()
- img.src = picture
- box.append(img)
+let latest = 0
+
+/** Until `done()`: `cover`, an <img> under the canvas sized like it with object-fit: contain, shows the character's
+ * cover.webp (its first frame, so nothing jumps), then the character fades in over it. Only a model with a folder has a
+ * cover (a package's folder lies beside it); else, and when the load takes long, "Loading…". A newer call takes over. */
+export function loading(canvas, cover, source) {
+ const me = ++latest
+ const url = typeof source === 'string' && /(\/|\.livliv)$/.test(source) ? `${source.replace(/\.livliv$/, '/')}cover.webp` : ''
+ if (cover.getAttribute('src') !== url) {
+ cover.hidden = true // not the last character's picture while this one comes
+ if (url) cover.src = url; else cover.removeAttribute('src')
+ }
+ let waiting = true
+ if (url) {
+ cover.decode().then(() => {
+ if (me !== latest || !waiting) return
+ cover.hidden = false
+ canvas.style.transition = ''
+ canvas.style.opacity = 0
+ }, () => { if (me === latest) cover.hidden = true }) // no cover: the note below is enough
+ }
+ const note = document.createElement('p')
+ note.textContent = 'Loading…'
+ note.style.cssText = 'position:absolute;z-index:1;left:50%;bottom:12%;transform:translateX(-50%);margin:0;padding:4px 10px;border-radius:8px;background:#000a;color:#fff;font:13px system-ui,sans-serif;pointer-events:none'
+ const later = setTimeout(() => canvas.parentElement.append(note), url ? 800 : 150)
+ return () => {
+ waiting = false
+ clearTimeout(later)
+ note.remove()
+ if (me !== latest) return
+ if (canvas.style.opacity !== '0') { cover.hidden = true; return }
+ canvas.style.transition = 'opacity .25s'
+ canvas.style.opacity = 1
+ setTimeout(() => { if (me === latest) cover.hidden = true }, 300)
}
- box.append('Loading…')
- const later = setTimeout(() => parent.append(box), 150)
- return () => { clearTimeout(later); box.remove() }
+}
+
+/** Is this URL on the page's own site? ?model= opens nothing else: a link must not put someone else's file on this
+ * page, under its address. The buttons are there for other files: a visitor picks those on purpose. */
+export function sameSite(url) {
+ try { return new URL(url, location.href).origin === location.origin } catch { return false }
}
/** Where WebGL2 is missing: says so on the page and stops the page's script here (new Player() would throw). */
export function needWebGL(Player) {
if (Player.isSupported()) return
const note = document.createElement('p')
- note.style.cssText = 'margin:32px 16px;text-align:center;font:15px/1.5 system-ui,sans-serif'
+ note.style.cssText = 'position:fixed;z-index:2;left:16px;right:16px;top:32px;margin:0;padding:8px 12px;border-radius:8px;background:#000c;color:#fff;text-align:center;font:15px/1.5 system-ui,sans-serif'
note.textContent = 'This browser cannot show the character: it needs WebGL2, which is missing or turned off here.'
document.body.append(note)
throw new Error('no WebGL2')
diff --git a/example/vrm.html b/example/vrm.html
index 63d24d0..669ecc4 100644
--- a/example/vrm.html
+++ b/example/vrm.html
@@ -24,11 +24,12 @@
<button id="mic">microphone</button>
<button id="cam">camera</button>
</div>
-<p id="status" role="status">Open a .vrm (VRoid Studio exports them), or add ?model=&lt;URL of a .vrm&gt;</p>
+<p id="status" role="status">Open a .vrm (VRoid Studio exports them), or add ?model=&lt;URL of a .vrm on this site&gt;</p>
<script type="module">
import { BodyPlayer } from '../dist/body.js'
import { VrmBody } from '../dist/vrm.js'
import { cameraButton } from './camera.js'
+ import { sameSite } from './loading.js'
const player = new BodyPlayer(document.getElementById('stage'), new VrmBody())
const status = document.getElementById('status'), bar = document.getElementById('bar')
@@ -53,7 +54,8 @@
}
document.getElementById('pick').onchange = (e) => e.target.files.length && show(e.target.files[0])
const url = new URLSearchParams(location.search).get('model')
- if (url) show(url)
+ if (url && sameSite(url)) show(url)
+ else if (url) status.textContent = '?model= opens files on this site only. For another file, save it and open it here.'
let mic = null
document.getElementById('mic').onclick = async (e) => {
diff --git a/scripts/pack-characters.mjs b/scripts/pack-characters.mjs
index 40e8ff1..3439e25 100644
--- a/scripts/pack-characters.mjs
+++ b/scripts/pack-characters.mjs
@@ -2,7 +2,8 @@
// Each featured character as one file, characters/<id>.livliv, next to its folder (FORMAT.md §1: model.json first, images
// and model.json stored, keyforms.json deflated). The examples load these: one request instead of one per image, which on
// a slow path saves more than half the wait. Written by `npm run build`, not kept in git: they would only double what the
-// repository holds. The bytes depend on the files alone (no dates), so a build changes nothing it need not.
+// repository holds. The bytes depend on the files alone (no dates), so a build changes nothing it need not. The cover stays
+// out: it is what a page shows before the package arrives.
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
@@ -15,7 +16,7 @@ function zip(dir) {
const p = at ? `${at}/${e.name}` : e.name
return e.isDirectory() ? list(p) : [p]
}).sort()
- const names = ['model.json', ...list().filter((f) => f !== 'model.json')]
+ const names = ['model.json', ...list().filter((f) => f !== 'model.json' && f !== 'cover.webp')]
const local = [], central = []
let at = 0
for (const name of names) {
diff --git a/test/characters.test.ts b/test/characters.test.ts
index 7dc5d61..d00c594 100644
--- a/test/characters.test.ts
+++ b/test/characters.test.ts
@@ -33,6 +33,12 @@ describe('featured characters', { skip: !ids.length && 'no characters/ here' },
assert.equal(raw.meta?.watermark?.center, false)
for (const e of raw.expressions || []) assert.deepEqual(LANGS.filter((l) => !e.label?.[l]), [], `${e.id}'s names`)
for (const f of Object.values(raw.files || {}) as string[]) assert.ok(existsSync(join(dir, f)), f)
+ // the cover a page shows first: a WebP with alpha (VP8X), 512 x 768, small enough to come well before the package
+ const cover = readFileSync(join(dir, 'cover.webp'))
+ assert.equal(cover.toString('latin1', 8, 16), 'WEBPVP8X')
+ assert.deepEqual([cover.readUIntLE(24, 3) + 1, cover.readUIntLE(27, 3) + 1], [512, 768])
+ assert.ok(cover.length < 120_000, `${cover.length} bytes`)
+ if (existsSync(join(root, `${id}.livliv`))) assert.ok(!readFileSync(join(root, `${id}.livliv`)).includes('cover.webp'), 'the package has no cover')
// as the player reads it: every image it will ask for is there, each expression has its layer
const m = readModel(raw, 'en')
assert.ok(m.name)
diff --git a/test/smoke.mjs b/test/smoke.mjs
index 45f1850..f1828d8 100644
--- a/test/smoke.mjs
+++ b/test/smoke.mjs
@@ -170,6 +170,47 @@ try {
if (!vaOk) failed++
console.log(`${vaOk ? 'ok ' : 'FAIL'} VRM, loaded again on a wide canvas: aspect ${vrmAgain?.aspect1}, ${vrmAgain?.aspect2}; a failed load kept ${vrmAgain?.kept}, covers ${(vrmAgain?.share * 100).toFixed(1)} %; on a 2D canvas: ${vrmOn2d}`)
if (errors.length) { failed++; console.log(`FAIL page errors:\n ${errors.join('\n ')}`) }
+ // the example pages: the cover in the canvas's box until the character is ready, then the character over it
+ for (const name of ['index', 'demo', 'gallery']) {
+ const p = await browser.newPage()
+ let go
+ const held = new Promise((r) => { go = r })
+ await p.route('**/characters/*.livliv', async (route) => { await held; await route.continue() })
+ await p.goto(`http://127.0.0.1:${server.address().port}/example/${name}.html`)
+ const waited = await p.waitForFunction(() => {
+ const c = document.getElementById('cover'), s = document.getElementById('stage'), a = c.getBoundingClientRect(), b = s.getBoundingClientRect()
+ return c.naturalWidth > 0 && !c.hidden && getComputedStyle(s).opacity === '0' && a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height
+ }, null, { timeout: 8000 }).then(() => true, () => false)
+ go()
+ const faded = await p.waitForFunction(() => document.getElementById('cover').hidden && getComputedStyle(document.getElementById('stage')).opacity === '1', null, { timeout: 20000 }).then(() => true, () => false)
+ if (!waited || !faded) failed++
+ console.log(`${waited && faded ? 'ok ' : 'FAIL'} example/${name}.html: cover first ${waited}, then the character ${faded}`)
+ await p.close()
+ }
+ // ?model=: never a request to another site, however it is written; the page's own files still open
+ for (const name of ['demo', 'vrm']) {
+ const p = await browser.newPage(), asked = []
+ p.on('request', (r) => asked.push(r.url()))
+ let tried = 0, left = 0, said = 0
+ for (const other of ['https://example.invalid/x/', '//example.invalid/x/', '\\\\example.invalid/x/', 'https:example.invalid/x/', ' https://example.invalid/x/']) {
+ await p.goto(`http://127.0.0.1:${server.address().port}/example/${name}.html?model=${encodeURIComponent(other)}`)
+ await p.waitForFunction(() => /this site only/.test(document.getElementById('status').textContent), null, { timeout: 8000 }).then(() => { said++ }, () => {})
+ tried++
+ }
+ left = asked.filter((u) => /example\.invalid/.test(new URL(u).host)).length
+ const ok = said === tried && !left
+ if (!ok) failed++
+ console.log(`${ok ? 'ok ' : 'FAIL'} example/${name}.html: ?model= on another site: ${said}/${tried} said no, ${left} requests left this site`)
+ await p.close()
+ }
+ {
+ const p = await browser.newPage()
+ await p.goto(`http://127.0.0.1:${server.address().port}/example/demo.html?model=${encodeURIComponent(`../characters/${ids[0]}/`)}`)
+ const ok = await p.waitForFunction(() => window.player?.model, null, { timeout: 20000 }).then(() => true, () => false)
+ if (!ok) failed++
+ console.log(`${ok ? 'ok ' : 'FAIL'} example/demo.html: ?model= on this site opens`)
+ await p.close()
+ }
// no WebGL at all: the example pages say so, the check says no, new Player() says why (the pages fail on purpose: no
// error of theirs counts here)
const plain = await chromium.launch({ args: ['--disable-gpu', '--disable-software-rasterizer', '--disable-webgl', '--disable-webgl2', '--disable-3d-apis'] })
@@ -178,7 +219,11 @@ try {
for (const name of ['index', 'demo', 'gallery']) {
await p.goto(`http://127.0.0.1:${server.address().port}/example/${name}.html`)
await p.waitForFunction(() => /WebGL2/.test(document.body.innerText), null, { timeout: 8000 }).catch(() => {})
- const said = /WebGL2/.test(await p.evaluate(() => document.body.innerText))
+ // said where it can be read: on the first screen, whatever the canvas takes up
+ const said = await p.evaluate(() => {
+ const e = [...document.querySelectorAll('p')].find((x) => /WebGL2/.test(x.textContent)), r = e?.getBoundingClientRect()
+ return !!r && r.top >= 0 && r.bottom <= innerHeight
+ })
if (!said) failed++
console.log(`${said ? 'ok ' : 'FAIL'} no WebGL: example/${name}.html ${said ? 'says so' : 'says nothing'}`)
}