You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to save and load a scene containing two .glb PBRBundle models and one LightBundle. I'm positioning the models with a parent component. I can save the scene to a file, but when I load the scene nothing appears and there are no warnings or errors. This is the code I'm using to save the scene:
fnsave_scene_system(world:&mutWorld){let earth_transform = Transform{translation:Vec3::new(550.0, -300.0, -775.0),scale:Vec3::new(450.0,450.0,450.0),rotation:Quat::from_rotation_z(0.41),};let sun_transform = Transform{translation:Vec3::new(-1150.0, -300.0, -2000.0),scale:Vec3::new(70.0,70.0,70.0),
..Default::default()};letmut scene_world = World::new();let asset_server = world.get_resource::<AssetServer>().unwrap();let earth_mesh = asset_server.load("models/earth.glb#Mesh0/Primitive0");let earth_mat = asset_server.load("models/earth.glb#Material0");let sun_mesh = asset_server.load("models/sun.glb#Mesh0/Primitive0");let sun_mat = asset_server.load("models/sun.glb#Material0");// add earth entity
scene_world
.spawn().insert_bundle((earth_transform,GlobalTransform::identity())).with_children(|parent| {
parent.spawn_bundle(PbrBundle{mesh: earth_mesh,material: earth_mat,
..Default::default()});}).insert(background::PlanetComponent{rotation_speed:0.0002,});
scene_world
.spawn().insert_bundle((sun_transform,GlobalTransform::identity())).with_children(|parent| {
parent.spawn_bundle(PbrBundle{mesh: sun_mesh,material: sun_mat,
..Default::default()});}).insert(background::PlanetComponent{rotation_speed:0.00005,});
scene_world.spawn().insert_bundle(LightBundle{light:Light{color:Color::ORANGE_RED,intensity:20000000.0,range:10000000.0,
..Default::default()},transform: sun_transform,
..Default::default()});// The TypeRegistry resource contains information about all registered types (including// components). This is used to construct scenes.let type_registry = world.get_resource::<TypeRegistry>().unwrap();let scene = DynamicScene::from_world(&scene_world,&type_registry);letmut file = File::create("assets/scenes/earth_sun.scn.ron").unwrap();
file.write_all(scene.serialize_ron(&type_registry).unwrap().as_bytes()).unwrap();// Scenes can be serialized like this://info!("{}", scene.serialize_ron(&type_registry).unwrap());}
I uncomment .add_startup_system(save_scene_system.exclusive_system().at_end()) to create the scene file, then when I want to load the scene file I uncomment .add_startup_system(background::load_background_scene_system.system().after("init")) and comment out the save scene system.
Any ideas of what could be causing them not to appear loaded? I have searched through other Bevy projects and I haven't been able to find another public project trying to load GLTF models through scene files, so maybe I'm misunderstanding the purpose of scenes and applying them to something they aren't meant for?
The only other thing I could think of is that maybe you aren't meant to save entities to a scene that you use the AssetServer to load?
Let me know if you have any ideas as to why they aren't appearing to load!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm trying to save and load a scene containing two .glb PBRBundle models and one LightBundle. I'm positioning the models with a parent component. I can save the scene to a file, but when I load the scene nothing appears and there are no warnings or errors. This is the code I'm using to save the scene:
And this is the code I'm using to load the scene:
This is my how I build and run the App:
I uncomment
.add_startup_system(save_scene_system.exclusive_system().at_end())
to create the scene file, then when I want to load the scene file I uncomment.add_startup_system(background::load_background_scene_system.system().after("init"))
and comment out the save scene system.Any ideas of what could be causing them not to appear loaded? I have searched through other Bevy projects and I haven't been able to find another public project trying to load GLTF models through scene files, so maybe I'm misunderstanding the purpose of scenes and applying them to something they aren't meant for?
The only other thing I could think of is that maybe you aren't meant to save entities to a scene that you use the
AssetServer
to load?Let me know if you have any ideas as to why they aren't appearing to load!
Beta Was this translation helpful? Give feedback.
All reactions