This commit is contained in:
23
src/main.ts
23
src/main.ts
@ -2,7 +2,8 @@ import { MainApp } from './babylonjs/MainApp';
|
||||
import { AppConfig } from './babylonjs/AppConfig';
|
||||
import configurator, { ConfiguratorParams } from './components/conf';
|
||||
import auth from './components/auth';
|
||||
import { on } from './utils/event';
|
||||
import { on, off, once, emit } from './event/bus';
|
||||
import { EventBridge } from './event/bridge';
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
@ -14,10 +15,11 @@ declare global {
|
||||
type InitParams = {
|
||||
container?: string;
|
||||
modelUrlList?: string[];
|
||||
apiConfig?: ConfiguratorParams;
|
||||
onSuccess?: () => void;
|
||||
onError?: (error?: unknown) => void;
|
||||
env?: {
|
||||
envPath?: string;
|
||||
hdrPath?: string;
|
||||
intensity?: number;
|
||||
rotationY?: number;
|
||||
};
|
||||
@ -26,10 +28,26 @@ type InitParams = {
|
||||
let mainApp: MainApp | null = null;
|
||||
|
||||
const kernel = {
|
||||
// 事件工具,提供给外部订阅/退订
|
||||
on,
|
||||
off,
|
||||
once,
|
||||
emit,
|
||||
/** 初始化应用 */
|
||||
init: async function (params: InitParams): Promise<void> {
|
||||
if (!params) { console.error('params is required'); return; }
|
||||
|
||||
if (params.apiConfig) {
|
||||
await configurator.init(params.apiConfig);
|
||||
if (params.apiConfig.name) {
|
||||
const userInfo = await auth.login(params.apiConfig.name);
|
||||
if (!userInfo) {
|
||||
console.error('failed to fetch user');
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mainApp = new MainApp();
|
||||
mainApp.loadAConfig({
|
||||
container: params.container || 'renderDom',
|
||||
@ -42,7 +60,6 @@ const kernel = {
|
||||
await mainApp.Awake();
|
||||
await mainApp.loadModel();
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
if (!window.faceSDK) {
|
||||
|
||||
Reference in New Issue
Block a user