Skip to content

Commit

Permalink
tool: support preview anm
Browse files Browse the repository at this point in the history
  • Loading branch information
dontpanic92 committed Apr 14, 2024
1 parent 03fbca0 commit 9828a83
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 20 deletions.
1 change: 0 additions & 1 deletion yaobow/shared/src/openpal4/asset_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ impl AssetLoader {
default_act: Option<&str>,
) -> anyhow::Result<ComRc<IEntity>> {
let model_path = format!("/gamedata/PALActor/{}/{}.dff", actor_name, actor_name);

let entity = create_entity_from_dff_model(
&self.component_factory,
&self.vfs,
Expand Down
82 changes: 64 additions & 18 deletions yaobow/yaobow_editor/src/preview/previewers/models/dff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ use std::{io::Read, path::Path, rc::Rc};
use crosscom::ComRc;
use fileformats::rwbs::read_dff;
use mini_fs::{MiniFs, StoreExt};
use radiance::comdef::IEntity;
use radiance::comdef::{IArmatureComponent, IComponent, IEntity};
use shared::{
loaders::{
anm::load_anm,
dff::{create_entity_from_dff_model, DffLoaderConfig},
Pal4TextureResolver,
},
openpal3::asset_manager::AssetManager,
openpal4::{
actor::{Pal4ActorAnimationConfig, Pal4ActorAnimationController},
comdef::IPal4ActorAnimationController,
},
GameType,
};

Expand All @@ -33,29 +38,70 @@ impl DffModelLoader {

impl ModelLoader for DffModelLoader {
fn load_text(&self, vfs: &MiniFs, path: &Path) -> String {
let mut buf = vec![];
_ = vfs.open(&path).unwrap().read_to_end(&mut buf);
read_dff(&buf)
.map(|f| jsonify(&f))
.unwrap_or("Unsupported".to_string())
if get_extension(path).as_deref() == Some("dff") {
let mut buf = vec![];
_ = vfs.open(&path).unwrap().read_to_end(&mut buf);
read_dff(&buf)
.map(|f| jsonify(&f))
.unwrap_or("Unsupported".to_string())
} else {
load_anm(vfs, path)
.map(|f| jsonify(&f))
.unwrap_or("Unsupported".to_string())
}
}

fn is_supported(&self, path: &Path) -> bool {
let extension = get_extension(path);
extension.as_deref() == Some("dff")
let extension = extension.as_deref();
extension == Some("dff") || extension == Some("anm")
}

fn load(&self, vfs: &MiniFs, path: &Path) -> ComRc<IEntity> {
create_entity_from_dff_model(
&self.asset_mgr.component_factory(),
vfs,
path,
"preview".to_string(),
true,
&DffLoaderConfig {
texture_resolver: &Pal4TextureResolver {},
keep_right_to_render_only: false,
}, //self.game_type.dff_loader_config().unwrap(),
)
if get_extension(path).as_deref() == Some("dff") {
create_entity_from_dff_model(
&self.asset_mgr.component_factory(),
vfs,
path,
"preview".to_string(),
true,
&DffLoaderConfig {
texture_resolver: &Pal4TextureResolver {},
keep_right_to_render_only: false,
}, //self.game_type.dff_loader_config().unwrap(),
)
} else {
let folder_path = path.parent().unwrap();
let actor_name = folder_path.file_name().unwrap().to_str().unwrap();
let dff_path = folder_path.join(format!("{}.dff", actor_name));
let entity = create_entity_from_dff_model(
&self.asset_mgr.component_factory(),
vfs,
dff_path,
"preview".to_string(),
true,
&DffLoaderConfig {
texture_resolver: &Pal4TextureResolver {},
keep_right_to_render_only: false,
},
);

let armature = entity
.get_component(IArmatureComponent::uuid())
.unwrap()
.query_interface::<IArmatureComponent>()
.unwrap();

let controller = Pal4ActorAnimationController::create(armature);
entity.add_component(
IPal4ActorAnimationController::uuid(),
controller.query_interface::<IComponent>().unwrap(),
);

let anm = load_anm(self.asset_mgr.vfs(), path).unwrap_or(vec![]);
controller.play_animation(anm, vec![], Pal4ActorAnimationConfig::Looping);

entity
}
}
}
2 changes: 1 addition & 1 deletion yaobow/yaobow_editor/src/preview/previewers/others.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl TextContentLoader for OthersTextContentLoader {
fn is_supported(&self, path: &std::path::Path) -> bool {
let extension = get_extension(path);
match extension.as_deref() {
Some("scn" | "nav" | "sce" | "anm" | "nod") => true,
Some("scn" | "nav" | "sce" | "nod") => true,
_ => false,
}
}
Expand Down

0 comments on commit 9828a83

Please sign in to comment.