Skip to content

Commit

Permalink
add node_handles to gltf asset
Browse files Browse the repository at this point in the history
  • Loading branch information
kayhhh committed Mar 15, 2024
1 parent 4777bb2 commit d2bd3c4
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
4 changes: 1 addition & 3 deletions bevy_gltf_kun/src/import/gltf/document.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bevy::render::mesh::skinning::SkinnedMeshInverseBindposes;
use bevy::utils::HashSet;
use bevy::{asset::LoadContext, prelude::*, utils::HashMap};
use gltf_kun::graph::gltf::{Material, Node, Skin};
use gltf_kun::graph::gltf::{Material, Skin};
use gltf_kun::graph::{gltf::GltfDocument, Graph};
use thiserror::Error;

Expand All @@ -10,7 +10,6 @@ use crate::import::extensions::BevyImportExtensions;
use super::skin::import_skin_matrices;
use super::{
animation::{import_animation, paths_recur, AnimationImportError},
node::GltfNode,
scene::import_scene,
texture::{get_linear_textures, load_texture, texture_label, TextureLoadError},
GltfKun,
Expand All @@ -30,7 +29,6 @@ pub struct ImportContext<'a, 'b> {
pub graph: &'a mut Graph,
pub load_context: &'a mut LoadContext<'b>,

pub nodes_handles: HashMap<Node, Handle<GltfNode>>,
pub skin_matrices: HashMap<Skin, Handle<SkinnedMeshInverseBindposes>>,
pub materials: HashMap<(Material, bool), Handle<StandardMaterial>>,
}
Expand Down
1 change: 0 additions & 1 deletion bevy_gltf_kun/src/import/gltf/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ where
load_context,

materials: HashMap::default(),
nodes_handles: HashMap::default(),
skin_matrices: HashMap::default(),
};

Expand Down
6 changes: 5 additions & 1 deletion bevy_gltf_kun/src/import/gltf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use std::marker::PhantomData;
use bevy::{prelude::*, utils::HashMap};
use gltf_kun::{
extensions::ExtensionImport,
graph::{gltf::document::GltfDocument, Graph},
graph::{
gltf::{document::GltfDocument, Node},
Graph,
},
io::format::gltf::GltfFormat,
};

Expand Down Expand Up @@ -65,6 +68,7 @@ where
#[derive(Asset, Debug, Default, TypePath)]
pub struct GltfKun {
pub graph: Graph,
pub node_handles: HashMap<Node, Handle<GltfNode>>,

pub animations: Vec<Handle<AnimationClip>>,
pub default_scene: Option<Handle<GltfScene>>,
Expand Down
4 changes: 2 additions & 2 deletions bevy_gltf_kun/src/import/gltf/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ pub fn import_node<E: BevyImportExtensions<GltfDocument>>(
.load_context
.add_labeled_asset(node_label.clone(), node);

context.gltf.nodes.insert(index, handle.clone());
context.gltf.named_nodes.insert(name, handle.clone());
context.gltf.node_handles.insert(*n, handle.clone());
context.gltf.nodes.insert(index, handle.clone());

node_entities.insert(handle.clone(), ent.id());
context.nodes_handles.insert(*n, handle.clone());
node_primitive_entities.insert(handle.clone(), primitive_entities);

// Load extensions.
Expand Down
4 changes: 2 additions & 2 deletions bevy_gltf_kun/src/import/gltf/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub fn import_scene<E: BevyImportExtensions<GltfDocument>>(
.joints(context.graph)
.iter()
.map(|joint| {
let handle = context.nodes_handles.get(joint).unwrap();
let handle = context.gltf.node_handles.get(joint).unwrap();
*node_entities.get(handle).unwrap()
})
.collect::<Vec<_>>();
Expand All @@ -85,7 +85,7 @@ pub fn import_scene<E: BevyImportExtensions<GltfDocument>>(
);
}

let handle = context.nodes_handles.get(&node).unwrap();
let handle = context.gltf.node_handles.get(&node).unwrap();
let primitive_ents = node_primitive_entities.get(handle).unwrap();

for entity in primitive_ents {
Expand Down

0 comments on commit d2bd3c4

Please sign in to comment.