Merge branch 'dev' into bevy_for_real_this_time
This commit is contained in:
@@ -47,7 +47,7 @@ impl Root {
|
|||||||
|
|
||||||
pub fn set_transform(&self, transform: Mat4) {
|
pub fn set_transform(&self, transform: Mat4) {
|
||||||
let spatial = self.node.get_aspect::<Spatial>().unwrap();
|
let spatial = self.node.get_aspect::<Spatial>().unwrap();
|
||||||
spatial.set_spatial_parent(None).unwrap();
|
// spatial.set_spatial_parent(None).unwrap();
|
||||||
spatial.set_local_transform(transform);
|
spatial.set_local_transform(transform);
|
||||||
}
|
}
|
||||||
pub async fn save_state(&self) -> Result<ClientState> {
|
pub async fn save_state(&self) -> Result<ClientState> {
|
||||||
|
|||||||
@@ -270,45 +270,29 @@ impl Spatial {
|
|||||||
fn get_parent(&self) -> Option<Arc<Spatial>> {
|
fn get_parent(&self) -> Option<Arc<Spatial>> {
|
||||||
self.parent.lock().clone()
|
self.parent.lock().clone()
|
||||||
}
|
}
|
||||||
fn set_parent(self: &Arc<Self>, new_parent: Option<&Arc<Spatial>>) {
|
fn set_parent(self: &Arc<Self>, new_parent: &Arc<Spatial>) {
|
||||||
if let Some(parent) = self.get_parent() {
|
if let Some(parent) = self.get_parent() {
|
||||||
parent.children.remove(self);
|
parent.children.remove(self);
|
||||||
}
|
}
|
||||||
if let Some(new_parent) = &new_parent {
|
new_parent.children.add_raw(self);
|
||||||
new_parent.children.add_raw(self);
|
|
||||||
}
|
|
||||||
|
|
||||||
*self.parent.lock() = new_parent.cloned();
|
*self.parent.lock() = Some(new_parent.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_spatial_parent(self: &Arc<Self>, parent: Option<&Arc<Spatial>>) -> Result<()> {
|
pub fn set_spatial_parent(self: &Arc<Self>, parent: &Arc<Spatial>) -> Result<()> {
|
||||||
let is_ancestor = parent
|
if self.is_ancestor_of(parent.clone()) {
|
||||||
.as_ref()
|
|
||||||
.map(|parent| self.is_ancestor_of((*parent).clone()))
|
|
||||||
.unwrap_or(false);
|
|
||||||
if is_ancestor {
|
|
||||||
bail!("Setting spatial parent would cause a loop");
|
bail!("Setting spatial parent would cause a loop");
|
||||||
}
|
}
|
||||||
self.set_parent(parent);
|
self.set_parent(parent);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
pub fn set_spatial_parent_in_place(
|
pub fn set_spatial_parent_in_place(self: &Arc<Self>, parent: &Arc<Spatial>) -> Result<()> {
|
||||||
self: &Arc<Self>,
|
if self.is_ancestor_of(parent.clone()) {
|
||||||
parent: Option<&Arc<Spatial>>,
|
|
||||||
) -> Result<()> {
|
|
||||||
let is_ancestor = parent
|
|
||||||
.as_ref()
|
|
||||||
.map(|parent| self.is_ancestor_of((*parent).clone()))
|
|
||||||
.unwrap_or(false);
|
|
||||||
if is_ancestor {
|
|
||||||
bail!("Setting spatial parent would cause a loop");
|
bail!("Setting spatial parent would cause a loop");
|
||||||
}
|
}
|
||||||
|
|
||||||
self.set_local_transform(Spatial::space_to_space_matrix(
|
self.set_local_transform(Spatial::space_to_space_matrix(Some(self), Some(parent)));
|
||||||
Some(self),
|
|
||||||
parent.map(AsRef::as_ref),
|
|
||||||
));
|
|
||||||
self.set_parent(parent);
|
self.set_parent(parent);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -360,7 +344,7 @@ impl SpatialAspect for Spatial {
|
|||||||
let this_spatial = node.get_aspect::<Spatial>()?;
|
let this_spatial = node.get_aspect::<Spatial>()?;
|
||||||
let parent = parent.get_aspect::<Spatial>()?;
|
let parent = parent.get_aspect::<Spatial>()?;
|
||||||
|
|
||||||
this_spatial.set_spatial_parent(Some(&parent))?;
|
this_spatial.set_spatial_parent(&parent)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -372,7 +356,7 @@ impl SpatialAspect for Spatial {
|
|||||||
let this_spatial = node.get_aspect::<Spatial>()?;
|
let this_spatial = node.get_aspect::<Spatial>()?;
|
||||||
let parent = parent.get_aspect::<Spatial>()?;
|
let parent = parent.get_aspect::<Spatial>()?;
|
||||||
|
|
||||||
this_spatial.set_spatial_parent_in_place(Some(&parent))?;
|
this_spatial.set_spatial_parent_in_place(&parent)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,10 @@ pub fn release(spatial: &Spatial) {
|
|||||||
};
|
};
|
||||||
let spatial = spatial_node.get_aspect::<Spatial>().unwrap();
|
let spatial = spatial_node.get_aspect::<Spatial>().unwrap();
|
||||||
|
|
||||||
let _ = spatial.set_spatial_parent_in_place(spatial.old_parent.lock().take().as_ref());
|
let Some(old_parent) = spatial.old_parent.lock().take() else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let _ = spatial.set_spatial_parent_in_place(&old_parent);
|
||||||
let mut spatial_zone = spatial.zone.lock();
|
let mut spatial_zone = spatial.zone.lock();
|
||||||
|
|
||||||
if let Some(spatial_zone) = spatial_zone.upgrade() {
|
if let Some(spatial_zone) = spatial_zone.upgrade() {
|
||||||
|
|||||||
Reference in New Issue
Block a user