phantasmal-world/src/viewer/index.ts

99 lines
4.2 KiB
TypeScript
Raw Normal View History

import { ViewerView } from "./gui/ViewerView";
import { GuiStore } from "../core/stores/GuiStore";
import { HttpClient } from "../core/HttpClient";
import { Disposable } from "../core/observable/Disposable";
import { Disposer } from "../core/observable/Disposer";
import { Random } from "../core/Random";
2020-01-20 00:16:28 +08:00
import { Renderer } from "../core/rendering/Renderer";
import { DisposableThreeRenderer } from "../core/rendering/ThreeRenderer";
export function initialize_viewer(
http_client: HttpClient,
random: Random,
gui_store: GuiStore,
create_three_renderer: () => DisposableThreeRenderer,
): { view: ViewerView } & Disposable {
const disposer = new Disposer();
const view = new ViewerView(
gui_store,
async () => {
const { ModelController } = await import("./controllers/model/ModelController");
const { ModelView } = await import("./gui/model/ModelView");
const { CharacterClassAssetLoader } = await import(
"./loading/CharacterClassAssetLoader"
);
2020-01-20 00:16:28 +08:00
const { ModelToolBarView } = await import("./gui/model/ModelToolBarView");
const { ModelStore } = await import("./stores/ModelStore");
const { ModelToolBarController } = await import(
"./controllers/model/ModelToolBarController"
);
const { CharacterClassOptionsView } = await import(
"./gui/model/CharacterClassOptionsView"
);
const { CharacterClassOptionsController } = await import(
"./controllers/model/CharacterClassOptionsController"
);
const asset_loader = disposer.add(new CharacterClassAssetLoader(http_client));
const store = disposer.add(new ModelStore(gui_store, asset_loader, random));
const model_controller = new ModelController(store);
const model_tool_bar_controller = new ModelToolBarController(store);
const character_class_options_controller = new CharacterClassOptionsController(store);
let renderer: Renderer;
if (gui_store.feature_active("webgpu")) {
const { WebgpuRenderer } = await import("../core/rendering/webgpu/WebgpuRenderer");
const { ModelGfxRenderer } = await import("./rendering/ModelGfxRenderer");
renderer = new ModelGfxRenderer(store, new WebgpuRenderer(true, http_client));
} else if (gui_store.feature_active("webgl")) {
const { WebglRenderer } = await import("../core/rendering/webgl/WebglRenderer");
const { ModelGfxRenderer } = await import("./rendering/ModelGfxRenderer");
renderer = new ModelGfxRenderer(store, new WebglRenderer(true));
} else {
const { ModelRenderer } = await import("./rendering/ModelRenderer");
renderer = new ModelRenderer(store, create_three_renderer());
}
return new ModelView(
model_controller,
new ModelToolBarView(model_tool_bar_controller),
new CharacterClassOptionsView(character_class_options_controller),
renderer,
);
},
async () => {
const { TextureController } = await import("./controllers/texture/TextureController");
const { TextureView } = await import("./gui/texture/TextureView");
const { TextureRenderer } = await import("./rendering/TextureRenderer");
2020-01-20 00:16:28 +08:00
const controller = disposer.add(new TextureController());
2020-01-20 00:16:28 +08:00
let renderer: Renderer;
2020-01-23 08:16:52 +08:00
if (gui_store.feature_active("webgpu")) {
const { WebgpuRenderer } = await import("../core/rendering/webgpu/WebgpuRenderer");
renderer = new TextureRenderer(controller, new WebgpuRenderer(false, http_client));
2020-01-20 00:16:28 +08:00
} else {
const { WebglRenderer } = await import("../core/rendering/webgl/WebglRenderer");
renderer = new TextureRenderer(controller, new WebglRenderer(false));
2020-01-20 00:16:28 +08:00
}
return new TextureView(controller, renderer);
},
);
return {
view,
dispose(): void {
disposer.dispose();
},
};
}