fix(spatial): fix model nodes not despawning properly
Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
@@ -261,6 +261,7 @@ fn gen_model_parts(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
_ = model.parts.set(parts);
|
_ = model.parts.set(parts);
|
||||||
|
model.spatial.set_entity(model.bevy_scene_entity.get().unwrap().0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ impl Plugin for SpatialNodePlugin {
|
|||||||
PostUpdate,
|
PostUpdate,
|
||||||
(
|
(
|
||||||
spawn_spatial_nodes,
|
spawn_spatial_nodes,
|
||||||
despawn_unneeded_spatial_nodes,
|
|
||||||
update_spatial_node_parenting,
|
update_spatial_node_parenting,
|
||||||
|
despawn_unneeded_spatial_nodes,
|
||||||
update_spatial_nodes,
|
update_spatial_nodes,
|
||||||
)
|
)
|
||||||
.chain()
|
.chain()
|
||||||
@@ -72,7 +72,6 @@ fn update_spatial_node_parenting(
|
|||||||
if parent.map(|v| v.0) == parent_entity {
|
if parent.map(|v| v.0) == parent_entity {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
info!("changing bevy parent: {:?} to {:?}", parent.map(|v| v.0), parent_entity);
|
|
||||||
match parent_entity {
|
match parent_entity {
|
||||||
Some(e) => cmds.entity(entity).insert(ChildOf(e)),
|
Some(e) => cmds.entity(entity).insert(ChildOf(e)),
|
||||||
None => cmds.entity(entity).remove::<ChildOf>(),
|
None => cmds.entity(entity).remove::<ChildOf>(),
|
||||||
@@ -83,7 +82,6 @@ fn update_spatial_node_parenting(
|
|||||||
fn despawn_unneeded_spatial_nodes(query: Query<(Entity, &SpatialNode)>, cmds: ParallelCommands) {
|
fn despawn_unneeded_spatial_nodes(query: Query<(Entity, &SpatialNode)>, cmds: ParallelCommands) {
|
||||||
query.par_iter().for_each(|(entity, spatial_node)| {
|
query.par_iter().for_each(|(entity, spatial_node)| {
|
||||||
if spatial_node.0.upgrade().is_none() {
|
if spatial_node.0.upgrade().is_none() {
|
||||||
info!("despawn {entity}");
|
|
||||||
cmds.command_scope(|mut cmds| cmds.entity(entity).despawn());
|
cmds.command_scope(|mut cmds| cmds.entity(entity).despawn());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -93,14 +91,12 @@ fn update_spatial_nodes(
|
|||||||
mut query: Query<(
|
mut query: Query<(
|
||||||
&mut BevyTransform,
|
&mut BevyTransform,
|
||||||
&SpatialNode,
|
&SpatialNode,
|
||||||
Option<&ChildOf>,
|
|
||||||
&mut Visibility,
|
&mut Visibility,
|
||||||
)>,
|
)>,
|
||||||
parent_query: Query<&GlobalTransform>,
|
|
||||||
) {
|
) {
|
||||||
query
|
query
|
||||||
.par_iter_mut()
|
.par_iter_mut()
|
||||||
.for_each(|(mut transform, spatial_node, child_of, mut vis)| {
|
.for_each(|(mut transform, spatial_node, mut vis)| {
|
||||||
let _span = debug_span!("updating spatial node").entered();
|
let _span = debug_span!("updating spatial node").entered();
|
||||||
let Some(spatial) = spatial_node.0.upgrade() else {
|
let Some(spatial) = spatial_node.0.upgrade() else {
|
||||||
return;
|
return;
|
||||||
@@ -127,19 +123,6 @@ fn update_spatial_nodes(
|
|||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
*transform = BevyTransform::from_matrix(spatial.local_transform());
|
*transform = BevyTransform::from_matrix(spatial.local_transform());
|
||||||
// match child_of {
|
|
||||||
// Some(child_of) => {
|
|
||||||
// let Ok(parent) = parent_query.get(child_of.0) else {
|
|
||||||
// warn!("SpatialNode bevy Parent doesn't have global transform");
|
|
||||||
// return;
|
|
||||||
// };
|
|
||||||
// *transform =
|
|
||||||
// BevyTransform::from_matrix(parent.compute_matrix().inverse() * mat4);
|
|
||||||
// }
|
|
||||||
// None => {
|
|
||||||
// *transform = BevyTransform::from_matrix(mat4);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,7 +319,6 @@ impl Spatial {
|
|||||||
self.parent.lock().clone()
|
self.parent.lock().clone()
|
||||||
}
|
}
|
||||||
fn set_parent(self: &Arc<Self>, new_parent: &Arc<Spatial>) {
|
fn set_parent(self: &Arc<Self>, new_parent: &Arc<Spatial>) {
|
||||||
info!("setting parent for {:?}", self.node().map(|v| v.id));
|
|
||||||
if let Some(parent) = self.get_parent() {
|
if let Some(parent) = self.get_parent() {
|
||||||
parent.children.remove(self);
|
parent.children.remove(self);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user