2019-12-22 02:40:42 +08:00
|
|
|
import { ViewerView } from "./gui/ViewerView";
|
|
|
|
import { GuiStore } from "../core/stores/GuiStore";
|
2019-12-22 05:49:41 +08:00
|
|
|
import { HttpClient } from "../core/HttpClient";
|
2020-01-20 00:16:28 +08:00
|
|
|
import { DisposableThreeRenderer } from "../core/rendering/ThreeRenderer";
|
2019-12-25 07:17:02 +08:00
|
|
|
import { Disposable } from "../core/observable/Disposable";
|
|
|
|
import { Disposer } from "../core/observable/Disposer";
|
2020-01-06 01:40:35 +08:00
|
|
|
import { Random } from "../core/Random";
|
2020-01-20 00:16:28 +08:00
|
|
|
import { Renderer } from "../core/rendering/Renderer";
|
2019-12-22 02:40:42 +08:00
|
|
|
|
2019-12-22 07:43:27 +08:00
|
|
|
export function initialize_viewer(
|
|
|
|
http_client: HttpClient,
|
2020-01-06 01:40:35 +08:00
|
|
|
random: Random,
|
2019-12-22 07:43:27 +08:00
|
|
|
gui_store: GuiStore,
|
|
|
|
create_three_renderer: () => DisposableThreeRenderer,
|
2019-12-25 07:17:02 +08:00
|
|
|
): { view: ViewerView } & Disposable {
|
|
|
|
const disposer = new Disposer();
|
|
|
|
|
|
|
|
const view = new ViewerView(
|
2020-01-05 08:07:35 +08:00
|
|
|
gui_store,
|
2020-01-06 01:40:35 +08:00
|
|
|
|
2019-12-22 02:40:42 +08:00
|
|
|
async () => {
|
2020-01-06 01:40:35 +08:00
|
|
|
const { ModelController } = await import("./controllers/model/ModelController");
|
2020-01-20 00:16:28 +08:00
|
|
|
const { ModelRenderer } = await import("./rendering/ModelRenderer");
|
2020-01-06 01:40:35 +08:00
|
|
|
const { ModelView } = await import("./gui/model/ModelView");
|
2019-12-22 05:49:41 +08:00
|
|
|
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"
|
|
|
|
);
|
|
|
|
|
2020-01-02 03:15:39 +08:00
|
|
|
const asset_loader = disposer.add(new CharacterClassAssetLoader(http_client));
|
2020-01-06 05:40:26 +08:00
|
|
|
const store = disposer.add(new ModelStore(gui_store, asset_loader, random));
|
2020-01-06 01:40:35 +08:00
|
|
|
const model_controller = new ModelController(store);
|
|
|
|
const model_tool_bar_controller = new ModelToolBarController(store);
|
|
|
|
const character_class_options_controller = new CharacterClassOptionsController(store);
|
2019-12-25 07:17:02 +08:00
|
|
|
|
2020-01-06 01:40:35 +08:00
|
|
|
return new ModelView(
|
|
|
|
model_controller,
|
|
|
|
new ModelToolBarView(model_tool_bar_controller),
|
|
|
|
new CharacterClassOptionsView(character_class_options_controller),
|
|
|
|
new ModelRenderer(store, create_three_renderer()),
|
|
|
|
);
|
2019-12-22 02:40:42 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
async () => {
|
2020-01-06 01:40:35 +08:00
|
|
|
const { TextureController } = await import("./controllers/TextureController");
|
2019-12-22 02:40:42 +08:00
|
|
|
const { TextureView } = await import("./gui/TextureView");
|
2020-01-20 00:16:28 +08:00
|
|
|
|
2020-01-06 01:40:35 +08:00
|
|
|
const controller = disposer.add(new TextureController());
|
2019-12-25 07:17:02 +08:00
|
|
|
|
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 { TextureWebgpuRenderer } = await import("./rendering/TextureWebgpuRenderer");
|
|
|
|
renderer = new TextureWebgpuRenderer(controller);
|
|
|
|
} else if (gui_store.feature_active("webgl")) {
|
2020-01-20 05:38:45 +08:00
|
|
|
const { TextureWebglRenderer } = await import("./rendering/TextureWebglRenderer");
|
|
|
|
renderer = new TextureWebglRenderer(controller);
|
2020-01-20 00:16:28 +08:00
|
|
|
} else {
|
|
|
|
const { TextureRenderer } = await import("./rendering/TextureRenderer");
|
|
|
|
renderer = new TextureRenderer(controller, create_three_renderer());
|
|
|
|
}
|
|
|
|
|
|
|
|
return new TextureView(controller, renderer);
|
2019-12-22 02:40:42 +08:00
|
|
|
},
|
|
|
|
);
|
2019-12-25 07:17:02 +08:00
|
|
|
|
|
|
|
return {
|
|
|
|
view,
|
|
|
|
dispose(): void {
|
|
|
|
disposer.dispose();
|
|
|
|
},
|
|
|
|
};
|
2019-12-22 02:40:42 +08:00
|
|
|
}
|