Skip to content

Commit

Permalink
remove node_primitive_entities from import context
Browse files Browse the repository at this point in the history
  • Loading branch information
kayhhh committed Mar 15, 2024
1 parent 6b64106 commit 9578926
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
1 change: 0 additions & 1 deletion bevy_gltf_kun/src/import/gltf/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ pub struct ImportContext<'a, 'b> {
pub graph: &'a mut Graph,
pub load_context: &'a mut LoadContext<'b>,

pub node_primitive_entities: HashMap<Handle<GltfNode>, Vec<Entity>>,
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(),
node_primitive_entities: HashMap::default(),
nodes_handles: HashMap::default(),
skin_matrices: HashMap::default(),
};
Expand Down
14 changes: 10 additions & 4 deletions bevy_gltf_kun/src/import/gltf/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub enum ImportNodeError {
pub fn import_node<E: BevyImportExtensions<GltfDocument>>(
context: &mut ImportContext<'_, '_>,
node_entities: &mut HashMap<Handle<GltfNode>, Entity>,
node_primitive_entities: &mut HashMap<Handle<GltfNode>, Vec<Entity>>,
builder: &mut WorldChildBuilder,
parent_world_transform: &Transform,
n: &mut Node,
Expand Down Expand Up @@ -81,7 +82,14 @@ pub fn import_node<E: BevyImportExtensions<GltfDocument>>(

ent.with_children(|parent| {
for c in n.children(context.graph).iter_mut() {
match import_node::<E>(context, node_entities, parent, &world_transform, c) {
match import_node::<E>(
context,
node_entities,
node_primitive_entities,
parent,
&world_transform,
c,
) {
Ok(handle) => children.push(handle),
Err(e) => {
warn!("Failed to import node: {}", e);
Expand All @@ -108,9 +116,7 @@ pub fn import_node<E: BevyImportExtensions<GltfDocument>>(

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

// Load extensions.
E::import_node(context, &mut ent, *n);
Expand Down
4 changes: 3 additions & 1 deletion bevy_gltf_kun/src/import/gltf/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub fn import_scene<E: BevyImportExtensions<GltfDocument>>(
let mut world = World::default();

let mut node_entities = HashMap::<Handle<GltfNode>, Entity>::default();
let mut node_primitive_entities = HashMap::<Handle<GltfNode>, Vec<Entity>>::default();
let mut root_nodes = Vec::new();

world
Expand All @@ -40,6 +41,7 @@ pub fn import_scene<E: BevyImportExtensions<GltfDocument>>(
match import_node::<E>(
context,
&mut node_entities,
&mut node_primitive_entities,
parent,
&Transform::default(),
&mut node,
Expand Down Expand Up @@ -84,7 +86,7 @@ pub fn import_scene<E: BevyImportExtensions<GltfDocument>>(
}

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

for entity in primitive_ents {
let mut entity = world.entity_mut(*entity);
Expand Down

0 comments on commit 9578926

Please sign in to comment.