mirror of
https://github.com/DaanVandenBosch/phantasmal-world.git
synced 2025-04-04 22:58:29 +08:00
The model viewer camera now resets when loading a model with "Open file...".
This commit is contained in:
parent
3836612972
commit
3983ce2613
@ -56,13 +56,9 @@ export class ModelToolBarController extends Controller {
|
||||
const cursor = new ArrayBufferCursor(buffer, Endianness.Little);
|
||||
|
||||
if (file.name.endsWith(".nj")) {
|
||||
const nj_object = parse_nj(cursor)[0];
|
||||
|
||||
this.store.set_current_nj_object(nj_object);
|
||||
this.store.set_current_nj_object(parse_nj(cursor)[0]);
|
||||
} else if (file.name.endsWith(".xj")) {
|
||||
const nj_object = parse_xj(cursor)[0];
|
||||
|
||||
this.store.set_current_nj_object(nj_object);
|
||||
this.store.set_current_nj_object(parse_xj(cursor)[0]);
|
||||
} else if (file.name.endsWith(".njm")) {
|
||||
this.store.set_current_animation(undefined);
|
||||
this.store.set_current_nj_motion(undefined);
|
||||
|
@ -25,6 +25,7 @@ import { Disposer } from "../../core/observable/Disposer";
|
||||
import { ChangeEvent } from "../../core/observable/Observable";
|
||||
import { LogManager } from "../../core/Logger";
|
||||
import { ModelStore } from "../stores/ModelStore";
|
||||
import { CharacterClassModel } from "../model/CharacterClassModel";
|
||||
|
||||
const logger = LogManager.get("viewer/rendering/ModelRenderer");
|
||||
|
||||
@ -37,10 +38,13 @@ const DEFAULT_SKINNED_MATERIAL = new MeshLambertMaterial({
|
||||
color: 0xffffff,
|
||||
side: DoubleSide,
|
||||
});
|
||||
const CAMERA_POSITION = Object.freeze(new Vector3(0, 10, 20));
|
||||
const CAMERA_LOOKAT = Object.freeze(new Vector3(0, 0, 0));
|
||||
|
||||
export class ModelRenderer extends Renderer implements Disposable {
|
||||
private readonly disposer = new Disposer();
|
||||
private readonly clock = new Clock();
|
||||
private character_class_active: boolean;
|
||||
private mesh?: Object3D;
|
||||
private skeleton_helper?: SkeletonHelper;
|
||||
private animation?: {
|
||||
@ -54,7 +58,10 @@ export class ModelRenderer extends Renderer implements Disposable {
|
||||
constructor(private readonly store: ModelStore, three_renderer: DisposableThreeRenderer) {
|
||||
super(three_renderer);
|
||||
|
||||
this.character_class_active = store.current_character_class.val != undefined;
|
||||
|
||||
this.disposer.add_all(
|
||||
store.current_character_class.observe(this.current_character_class_changed),
|
||||
store.current_nj_object.observe(this.nj_object_or_xvm_changed),
|
||||
store.current_textures.observe(this.nj_object_or_xvm_changed),
|
||||
store.current_nj_motion.observe(this.nj_motion_changed),
|
||||
@ -65,7 +72,7 @@ export class ModelRenderer extends Renderer implements Disposable {
|
||||
);
|
||||
|
||||
this.init_camera_controls();
|
||||
this.reset_camera(new Vector3(0, 10, 20), new Vector3(0, 0, 0));
|
||||
this.reset_camera(CAMERA_POSITION, CAMERA_LOOKAT);
|
||||
}
|
||||
|
||||
set_size(width: number, height: number): void {
|
||||
@ -93,6 +100,18 @@ export class ModelRenderer extends Renderer implements Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
private current_character_class_changed = (
|
||||
change: ChangeEvent<CharacterClassModel | undefined>,
|
||||
): void => {
|
||||
const character_class_active = change.value != undefined;
|
||||
|
||||
if (this.character_class_active !== character_class_active) {
|
||||
this.reset_camera(CAMERA_POSITION, CAMERA_LOOKAT);
|
||||
}
|
||||
|
||||
this.character_class_active = character_class_active;
|
||||
};
|
||||
|
||||
private nj_object_or_xvm_changed = (): void => {
|
||||
if (this.mesh) {
|
||||
this.scene.remove(this.mesh);
|
||||
|
@ -30,12 +30,6 @@ import { NjObject } from "../../core/data_formats/parsing/ninja";
|
||||
|
||||
const logger = LogManager.get("viewer/stores/ModelStore");
|
||||
|
||||
export type NjData = {
|
||||
readonly nj_object: NjObject;
|
||||
readonly bone_count: number;
|
||||
readonly has_skeleton: boolean;
|
||||
};
|
||||
|
||||
export class ModelStore extends Store {
|
||||
// Character classes and their animations.
|
||||
private readonly _current_character_class: WritableProperty<
|
||||
|
Loading…
Reference in New Issue
Block a user