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.3 KB
Raw Blame
import { UIRow, UIText, UICheckbox, UIButton } from './libs/ui.js';

class GLTFImportDialog {

	constructor( strings ) {

		this.strings = strings;

		const dom = document.createElement( 'div' );
		dom.className = 'Dialog';
		this.dom = dom;

		const background = document.createElement( 'div' );
		background.className = 'Dialog-background';
		background.addEventListener( 'click', () => this.cancel() );
		dom.appendChild( background );

		const content = document.createElement( 'div' );
		content.className = 'Dialog-content';
		dom.appendChild( content );

		// Title

		const titleBar = document.createElement( 'div' );
		titleBar.className = 'Dialog-title';
		titleBar.textContent = strings.getKey( 'dialog/gltf/title' );
		content.appendChild( titleBar );

		// Body

		const body = document.createElement( 'div' );
		body.className = 'Dialog-body';
		content.appendChild( body );

		// As Scene Checkbox

		const asSceneRow = new UIRow();
		body.appendChild( asSceneRow.dom );

		this.asSceneCheckbox = new UICheckbox( false );
		asSceneRow.add( this.asSceneCheckbox );

		asSceneRow.add( new UIText( strings.getKey( 'dialog/gltf/asScene' ) ).setMarginLeft( '6px' ) );

		// Buttons

		const buttonsRow = document.createElement( 'div' );
		buttonsRow.className = 'Dialog-buttons';
		body.appendChild( buttonsRow );

		const okButton = new UIButton( strings.getKey( 'dialog/ok' ) );
		okButton.setWidth( '80px' );
		okButton.onClick( () => this.confirm() );
		buttonsRow.appendChild( okButton.dom );

		const cancelButton = new UIButton( strings.getKey( 'dialog/cancel' ) );
		cancelButton.setWidth( '80px' );
		cancelButton.setMarginLeft( '8px' );
		cancelButton.onClick( () => this.cancel() );
		buttonsRow.appendChild( cancelButton.dom );

		// Promise handlers

		this.resolve = null;
		this.reject = null;

	}

	show() {

		document.body.appendChild( this.dom );

		return new Promise( ( resolve, reject ) => {

			this.resolve = resolve;
			this.reject = reject;

		} );

	}

	confirm() {

		const result = {
			asScene: this.asSceneCheckbox.getValue()
		};

		this.dom.remove();

		if ( this.resolve ) {

			this.resolve( result );

		}

	}

	cancel() {

		this.dom.remove();

		if ( this.reject ) {

			this.reject( new Error( 'Import cancelled' ) );

		}

	}

}

export { GLTFImportDialog };