UNPKG

@needle-tools/engine

Version:

Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.

38 lines (33 loc) 1.28 kB
/** * Interface for a quicklook handler that can export and open a USDZ file. * Used as an abstraction layer to break the circular dependency between * WebXRButtons and USDZExporter. */ export interface IQuicklookHandler { objectToExport: any; exportAndOpen(): Promise<any>; } type QuicklookHandlerFactory = { /** Find an existing quicklook handler in the scene */ find(): IQuicklookHandler | null; /** Create a new quicklook handler instance */ create(): IQuicklookHandler; }; let _factory: QuicklookHandlerFactory | undefined; /** * Register a factory for creating quicklook handlers. * Called by USDZExporter to register itself as the handler. */ export function setQuicklookHandlerFactory(factory: QuicklookHandlerFactory) { _factory = factory; } /** * Find an existing quicklook handler in the scene, or create a new one if none exists. * @returns A quicklook handler, or null if no factory has been registered. */ export function getOrCreateQuicklookHandler(): { readonly handler: IQuicklookHandler, readonly created: boolean } | null { if (!_factory) return null; const existing = _factory.find(); if (existing) return { handler: existing, created: false }; return { handler: _factory.create(), created: true }; }