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

[Merged by Bors] - Add a scene viewer tool #4183

Closed
wants to merge 17 commits into from

Conversation

superdump
Copy link
Contributor

@superdump superdump commented Mar 11, 2022

Objective

  • Allow quick and easy testing of scenes

Solution

  • Add a scene-viewer tool based on load_gltf.
    • Run it with e.g. cargo run --release --example scene_viewer --features jpeg -- ../some/path/assets/models/Sponza/glTF/Sponza.gltf#Scene0
  • Configure the asset path as pointing to the repo root for convenience (paths specified relative to current working directory)
  • Copy over the camera controller from the shadow_biases example
  • Support toggling the light animation
  • Support toggling shadows
  • Support adjusting the directional light shadow projection (cascaded shadow maps will remove the need for this later)

I don't want to do too much on it up-front. Rather we can add features over time as we need them.

@github-actions github-actions bot added the S-Needs-Triage This issue needs to be labelled label Mar 11, 2022
@mockersf
Copy link
Member

mockersf commented Mar 11, 2022

It would be nice to be able to spawn a useful default camera when there isn't one in the scene. This would be more useful than a movable camera I think

For example https://gltf-viewer.donmccurdy.com computes a bounding box, then moves the camera to be sure the box is fully visible

@mockersf
Copy link
Member

I think this should be in /examples/tools rather than in /tools

@piaoger
Copy link

piaoger commented Mar 11, 2022

Do you plan to add environments as above gltf-viewer?

@superdump superdump added A-Rendering Drawing game state to the screen C-Examples An addition or correction to our examples A-Assets Load files from disk to use for things like images, models, and sounds C-Usability A targeted quality-of-life change that makes Bevy easier to use C-Testing A change that impacts how we test Bevy or how users test their apps A-Scenes Serialized ECS data stored on the disk A-Utils Utility functions and types and removed S-Needs-Triage This issue needs to be labelled labels Mar 11, 2022
@superdump
Copy link
Contributor Author

I think this should be in /examples/tools rather than in /tools

Done.

@superdump
Copy link
Contributor Author

It would be nice to be able to spawn a useful default camera when there isn't one in the scene. This would be more useful than a movable camera I think

For example https://gltf-viewer.donmccurdy.com computes a bounding box, then moves the camera to be sure the box is fully visible

It depends heavily on the model. All the interesting parts of Sponza are on the inside and if you can't maneuver around to look at it then you're stuck looking at the outside walls. That said, it may absolutely make for a sensible default position in general and would allow configuring any directional light shadow projection automatically. So I'll do it. :)

@superdump
Copy link
Contributor Author

superdump commented Mar 12, 2022

It would be nice to be able to spawn a useful default camera when there isn't one in the scene. This would be more useful than a movable camera I think
For example https://gltf-viewer.donmccurdy.com computes a bounding box, then moves the camera to be sure the box is fully visible

It depends heavily on the model. All the interesting parts of Sponza are on the inside and if you can't maneuver around to look at it then you're stuck looking at the outside walls. That said, it may absolutely make for a sensible default position in general and would allow configuring any directional light shadow projection automatically. So I'll do it. :)

This was very awkward to do. I have to store a Handle<Scene> to wait for the scene to have loaded. Then once it has loaded, I can iterate over all the cameras in the scene world and take the first one I find that is named either of the CameraPlugin::CAMERA_2D or CameraPlugin::CAMERA_3D strings. Then spawn the scene. Then in a separate system, when I see that the scene has loaded, if there was no camera, check whether the meshes have Aabbs (they are added by the calculate_bounds system), if not, return. Otherwise, roughly transform the Aabbs to obtain a new Aabb that contains the entire scene. Use the centre and size of this to focus on the scene and have it fully in-view. Also, that the internal component and resources types are not all registered is a pain. I couldn't register my custom CameraController (from the shadow_biases example) because KeyCode is not registered.

EDIT: Updated on top of main with the camera marker changes.

There is a known issue currently where the scene does not always display. I don't know why. Sometimes it does, sometimes it doesn't. Weird.

@superdump
Copy link
Contributor Author

Do you plan to add environments as above gltf-viewer?

Environment maps and other image-based lighting techniques will likely come in the future and then be added to this example tool, yes. I don’t know when though.

@superdump
Copy link
Contributor Author

Well, I'm not sure why the gltf scenes sometimes load and sometimes not, but it doesn't look like it's the fault of this example tool to me. :/ bevy_gltf loads all the textures itself within its LoadContext, and I see no errors. Very confusing.

@superdump
Copy link
Contributor Author

Help welcome for figuring out the "sometimes doesn't display the model" bug. It seems to be that the AssetServer indicates that the Handle<Scene> is loaded but the Handle<Scene> does not exist in Assets<Scene>.

@superdump
Copy link
Contributor Author

Help welcome for figuring out the "sometimes doesn't display the model" bug. It seems to be that the AssetServer indicates that the Handle<Scene> is loaded but the Handle<Scene> does not exist in Assets<Scene>.

That wasn't it. Using commands.spawn_scene() gives really poor visibility of when the scene has actually been spawned and so when I can do things that require the scene to have been fully spawned. I had to change to using SceneSpawner::spawn(...) -> InstanceId and SceneSpawner::instance_is_ready(id: InstanceId) -> bool. Now it spawns Sponza reliably.

@mockersf
Copy link
Member

self plug for #2424 to remove the spawn_scene command 😄

@mockersf
Copy link
Member

Very nice to be able to quickly view any gltf file 👍

Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nits, but I think this should exist. Seems quite useful, and the code itself may end up being useful to some beginners.

@alice-i-cecile alice-i-cecile removed the A-Utils Utility functions and types label Mar 19, 2022
@alice-i-cecile
Copy link
Member

bors r+

bors bot pushed a commit that referenced this pull request Mar 19, 2022
# Objective

- Allow quick and easy testing of scenes

## Solution

- Add a `scene-viewer` tool based on `load_gltf`.
  - Run it with e.g. `cargo run --release --example scene_viewer --features jpeg -- ../some/path/assets/models/Sponza/glTF/Sponza.gltf#Scene0`
- Configure the asset path as pointing to the repo root for convenience (paths specified relative to current working directory)
- Copy over the camera controller from the `shadow_biases` example
- Support toggling the light animation
- Support toggling shadows
- Support adjusting the directional light shadow projection (cascaded shadow maps will remove the need for this later)

I don't want to do too much on it up-front. Rather we can add features over time as we need them.
@bors bors bot changed the title Add a scene viewer tool [Merged by Bors] - Add a scene viewer tool Mar 19, 2022
@bors bors bot closed this Mar 19, 2022
aevyrie pushed a commit to aevyrie/bevy that referenced this pull request Jun 7, 2022
# Objective

- Allow quick and easy testing of scenes

## Solution

- Add a `scene-viewer` tool based on `load_gltf`.
  - Run it with e.g. `cargo run --release --example scene_viewer --features jpeg -- ../some/path/assets/models/Sponza/glTF/Sponza.gltf#Scene0`
- Configure the asset path as pointing to the repo root for convenience (paths specified relative to current working directory)
- Copy over the camera controller from the `shadow_biases` example
- Support toggling the light animation
- Support toggling shadows
- Support adjusting the directional light shadow projection (cascaded shadow maps will remove the need for this later)

I don't want to do too much on it up-front. Rather we can add features over time as we need them.
ItsDoot pushed a commit to ItsDoot/bevy that referenced this pull request Feb 1, 2023
# Objective

- Allow quick and easy testing of scenes

## Solution

- Add a `scene-viewer` tool based on `load_gltf`.
  - Run it with e.g. `cargo run --release --example scene_viewer --features jpeg -- ../some/path/assets/models/Sponza/glTF/Sponza.gltf#Scene0`
- Configure the asset path as pointing to the repo root for convenience (paths specified relative to current working directory)
- Copy over the camera controller from the `shadow_biases` example
- Support toggling the light animation
- Support toggling shadows
- Support adjusting the directional light shadow projection (cascaded shadow maps will remove the need for this later)

I don't want to do too much on it up-front. Rather we can add features over time as we need them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Assets Load files from disk to use for things like images, models, and sounds A-Rendering Drawing game state to the screen A-Scenes Serialized ECS data stored on the disk C-Examples An addition or correction to our examples C-Testing A change that impacts how we test Bevy or how users test their apps C-Usability A targeted quality-of-life change that makes Bevy easier to use
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants