Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

2.6 KB
Raw Blame
// The built-in three.ws catalogues.
//
// three.ws hosts the model library this package pulls from by default: a few
// hundred CC0 props (Poly Haven, packed to web GLB) plus the community feed of
// models people generated on the platform. Both are keyless and free. Assets are
// served first-party through https://three.ws/cdn/<key>, which answers
// `access-control-allow-origin: *`, so they load from any origin: your GitHub
// Pages demo included.
//
// Nothing here is required. Point `assets` at your own manifest and three.ws
// drops out of the picture entirely.

import { THREE_WS } from '../config.js';
import { manifestSource, normalizeCatalogue } from './manifest.js';

/**
 * Rewrite a raw bucket URL onto the first-party CDN path, which is the copy that
 * answers CORS. Leaves anything else untouched.
 */
export function cdnUrl(url, origin = THREE_WS.origin) {
	const s = String(url || '');
	const m = s.match(/^https:\/\/pub-[a-z0-9]+\.r2\.dev\/(.+)$/i);
	return m ? `${origin.replace(/\/$/, '')}/cdn/${m[1]}` : s;
}

/** The CC0 prop library: hundreds of public-domain objects, free for commercial use. */
export function threeWsObjectsSource(cfg = {}) {
	const origin = (cfg.origin || THREE_WS.origin).replace(/\/$/, '');
	const url = cfg.objectsManifest || THREE_WS.objectsManifest;
	return {
		...manifestSource({
			url,
			id: 'objects',
			label: 'Objects',
			searchable: true,
			rewriteUrl: (u) => cdnUrl(u, origin),
		}),
		hint: 'Public-domain (CC0) props from three.ws: free to use anywhere, commercially too.',
		emptyCopy: 'The object library is unreachable right now. Check your connection and retry.',
	};
}

/**
 * Models the three.ws community generated. Read-only and free.
 *
 * Note: unlike the CDN catalogue above, this endpoint answers CORS for a fixed
 * allow-list of origins, so it is not part of the default tab set: enable it
 * with `assets: ['recent', 'objects', 'community']` when your page is served
 * from three.ws, from localhost against a dev API, or through your own proxy
 * (`endpoint` below points it anywhere).
 */
export function threeWsCommunitySource(cfg = {}) {
	const origin = (cfg.origin || THREE_WS.origin).replace(/\/$/, '');
	const endpoint = cfg.galleryEndpoint || `${origin}/api/forge-gallery`;
	return {
		id: 'community',
		label: 'Community',
		hint: 'Fresh models generated by the three.ws community.',
		emptyCopy: 'The community feed is quiet right now. Check back in a bit.',
		async list() {
			const res = await fetch(`${endpoint}?scope=community&limit=48`);
			if (!res.ok) throw new Error(`gallery ${res.status}`);
			return normalizeCatalogue(await res.json(), { rewriteUrl: (u) => cdnUrl(u, origin) });
		},
	};
}