๐Ÿฆˆ A 3D companion that swims on top of any web page (Chrome extension)

Hi everyone! :waving_hand:

I built a small Chrome extension with Babylon.js

  • a cute 3D shark that swims across whatever page youโ€™re viewing,
    in a transparent overlay that stays click-through everywhere except the character itself.

:package: Chrome Web Store: https://chromewebstore.google.com/detail/units-cfc-โ€”-cute-floating/fcodbljmmbhhkofinngcephgjjfpfcfl
:film_frames: Video: https://www.youtube.com/watch?v=ZELAYtwPhKM
:memo: Blog post: UNIT's Page

preview

What it does

  • Swims freely around the viewport; drag and toss it, and wall hits spawn rising bubbles
  • Double-click empty space โ†’ a procedural flag pops up and the shark swims to it
  • Every so often it lunges at the camera to startle you (can be turned off)
  • Continues seamlessly when you switch tabs

A few Babylon.js bits that might be useful to others

  • Tree-shaken bundle for MV3: @babylonjs/core + glTF loader bundled with esbuild as an IIFE exposing a BABYLON global. No dynamic import(), so it runs as an extension content script.
  • Transparent canvas over a live page: alpha: true with premultipliedAlpha: true and clearColor (0,0,0,0). With false, translucent meshes looked grey and washed out because the compositor multiplied alpha twice.
  • Pixel-space camera: an orthographic camera where 1 unit = 1 CSS px (X from the viewport center, Y from the bottom). All movement and edge bouncing becomes plain 2D math, and resize just refits the ortho bounds.
  • Selective click-through: the overlay is pointer-events: none. Capture-phase window listeners run scene.pick() against an invisible proxy box and switch to auto only while hovering or dragging.
  • One engine at a time: the engine is created only in the visible tab and engine.dispose()d shortly after the tab is hidden, so background tabs hold no WebGL context.
  • Cheap effects: the goal flag is a CreateRibbon updated in place via instance for the waving cloth, plus thin tori as pulse rings. Bubbles are a fixed pool of cloned planes sharing one DynamicTexture, with per-bubble alpha through mesh.visibility, so nothing is allocated at runtime.

Feedback is very welcome, especially ideas for keeping the overlay even lighter. Thanks for making Babylon.js such a joy to build with! :shark:

3 Likes

I wonder how smaller Lite could make it?

2 Likes

Iโ€™ll give it a try and share the results once Iโ€™m done.

2 Likes

I tried this on a small Chrome extension (a single skinned glTF character floating over web pages in a transparent canvas). I ported it from Babylon.js 9.31 (prebuilt UMD, WebGL2) to Babylon Lite 1.37.1 (native API, esbuild tree-shaken, WebGPU) and ran the same scripted scenario on both.

Metric classic (WebGL2) lite (MSAA 4) lite (MSAA 1)
Bundle (gzip) 845 KB 154 KB (โˆ’82%) 154 KB
Script load 322 ms 58 ms 54 ms
Engine init 113 ms 30 ms 31 ms
Model load 134 ms 69 ms 79 ms
Ready (first visible frame) 465 ms 177 ms (โˆ’62%) 190 ms
Main-thread task / frame 6.11 ms 3.93 ms 2.60 ms
JS heap 14.8 MB 5.1 MB 4.2 MB

Headless Chromium + SwiftShader, 1280ร—800, median of 2 runs. FPS is left out because software rendering doesnโ€™t say much about real GPUs. Real-hardware numbers will follow.

For my use case the difference was meaningful. The character shows up about 2.6ร— faster, per-frame main-thread cost drops by 35โ€“55%, and heap is about a third. That matters a lot for something injected into every tab the user opens.

I havenโ€™t updated it yet, but these results are really meaningful. Thanks for sharing!

1 Like

These are GOOD numbers :wink:

1 Like