From 21142bf84655c3d2b5f6d04e361336afe7ca8078 Mon Sep 17 00:00:00 2001 From: Jan Hohenheim Date: Tue, 10 Sep 2024 10:39:10 +0200 Subject: [PATCH] Improve global transform initialization --- .../src/blueprints/spawn_from_blueprints.rs | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/crates/blenvy/src/blueprints/spawn_from_blueprints.rs b/crates/blenvy/src/blueprints/spawn_from_blueprints.rs index fdaa411..427e5bd 100644 --- a/crates/blenvy/src/blueprints/spawn_from_blueprints.rs +++ b/crates/blenvy/src/blueprints/spawn_from_blueprints.rs @@ -440,7 +440,12 @@ pub(crate) fn blueprints_check_assets_loading( pub(crate) fn blueprints_assets_loaded( spawn_placeholders: Query< - (Entity, &BlueprintInfo, Option<&Transform>, Option<&Name>), + ( + Entity, + &BlueprintInfo, + Option<(&Transform, &GlobalTransform)>, + Option<&Name>, + ), ( Added, Without, @@ -454,7 +459,7 @@ pub(crate) fn blueprints_assets_loaded( mut commands: Commands, ) { - for (entity, blueprint_info, transform, name) in spawn_placeholders.iter() { + for (entity, blueprint_info, maybe_transform, name) in spawn_placeholders.iter() { /*info!( "BLUEPRINT: all assets loaded, attempting to spawn blueprint SCENE {:?} for entity {:?}, id: {:}, parent:{:?}", blueprint_info.name, name, entity, original_parent @@ -485,10 +490,10 @@ pub(crate) fn blueprints_assets_loaded( let scene = &blueprint_gltf.named_scenes[main_scene_name]; // transforms are optional, but still deal with them correctly - let mut transforms: Transform = Transform::default(); - if transform.is_some() { - transforms = *transform.unwrap(); - } + let (transform, global_transform) = match maybe_transform { + Some((transform, global_transform)) => (*transform, *global_transform), + None => (Transform::default(), GlobalTransform::default()), + }; let mut original_children: Vec = vec![]; if let Ok(c) = all_children.get(entity) { @@ -516,7 +521,8 @@ pub(crate) fn blueprints_assets_loaded( commands.entity(entity).insert(( SceneBundle { scene: scene.clone(), - transform: transforms, + transform, + global_transform, ..Default::default() }, OriginalChildren(original_children),