Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to load a Prefab programmatically #71

Open
philpax opened this issue Feb 13, 2023 · 6 comments
Open

Add function to load a Prefab programmatically #71

philpax opened this issue Feb 13, 2023 · 6 comments
Labels
topic:api API functionality, including both host and guest topic:assets Asset loading, streaming, etc

Comments

@philpax
Copy link
Contributor

philpax commented Feb 13, 2023

let world = World::load_from_url("assets/Cube.glb/objects/main.json").await?;
// world.objects contains a dict of entityids to components
assert_eq!(world.objects.iter().next(), Some((EntityId(...), Components::new()...)));
/// can spawn individual objects, or spawn the entire world
let id = world.objects.get(&EntityId(...)).unwrap().spawn();
let id = world.spawn();
@philpax philpax added topic:api API functionality, including both host and guest topic:assets Asset loading, streaming, etc labels Feb 13, 2023
@FredrikNoren
Copy link
Contributor

entity::spawn_template has been removed

@philpax
Copy link
Contributor Author

philpax commented Feb 14, 2023

Just realised this needs infrastructure on the guest side for the host to notify it of async events (unless we reuse event::ENTITY_SPAWN) for this. Maybe define another event like event::WORLD_SPAWN?

(What does object_from_url do for multiple entities in an object, anyway?)

@FredrikNoren
Copy link
Contributor

@philpax So there are two different things here; loading and spawning worlds has more to do with maps and other stuff. I think that probably has it's own flow, maybe something like let map = World::load("url").await; map.spawn(); or something.

Then on the other hand we have object_from_url; this is for hot-reloading assets etc. In that case, the "base entity" is already created by the user, so to be notified when the rest of the entity is loaded we'd have to wait for some object_loaded component to be added to that entity (doesn't exist yet).

object_from_url doesn't handle multiple-entity objects right now, but it should handle it the same way as model_from_url does in the future; if it's one object it should attach the components to the entity; if it's multiple they should be created as children to it.

@philpax
Copy link
Contributor Author

philpax commented Feb 14, 2023

Makes sense; I was using World to mean "a collection of entities that could be spawned in" (e.g. what happens when you currently request a multiple-entity object to be spawned). I think there's a good chance people will want to spawn in multiple-entity objects and directly manipulate them outside of map-loading, so I'm thinking we offer all three:

  1. Spawning in an entire World : for map loading
  2. Loading a World from somewhere, tweaking its constituent Components, and then spawning it
  3. Just using object_from_url and having it do all the work for you

Perhaps we should call it something other than World on the guest side?

@philpax
Copy link
Contributor Author

philpax commented Feb 23, 2023

Prefab is the term we use for a world being spawned in and updating/creating an entity or multiple entities. In line with that, we'd call this Prefab::load_from_url("url") and offer both the ability to spawn it immediately and the ability to poke around in its hierarchy before spawning it.

@philpax philpax changed the title Add function to load a World with objects and remove entity::spawn_template Add function to load a Prefab programmatically Feb 23, 2023
@philpax
Copy link
Contributor Author

philpax commented Feb 23, 2023

A future extension of this could also be used to save entities for later loading. I'm leaving that as a future development as it'll have to tie in to our story around persistence and general I/O access.

@philpax philpax mentioned this issue Aug 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic:api API functionality, including both host and guest topic:assets Asset loading, streaming, etc
Projects
None yet
Development

No branches or pull requests

2 participants