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

AssetSchematic: Defining assets inline #47

Closed
MrGVSV opened this issue Aug 3, 2023 · 1 comment · Fixed by #57
Closed

AssetSchematic: Defining assets inline #47

MrGVSV opened this issue Aug 3, 2023 · 1 comment · Fixed by #57
Assignees

Comments

@MrGVSV
Copy link
Owner

MrGVSV commented Aug 3, 2023

Objective

Allow assets to be defined within a prototype file rather than outside of it, using a Schematic-like approach.

While this probably won't be useful for large assets or those that make no sense in a text-based format, it should be great for assets defined in code.

For example, we should be able to define a prototype like:

(
  name: "Sphere",
  schematics: {
    "bevy_proto::custom::MaterialMeshBundle<bevy_pbr::pbr_material::StandardMaterial>": (
      mesh: Asset(UvSphere((
        radius: 1.0,
      ))),
      material: Asset((
        base_color: Green,
      )),
    )
  }
)

In the example above, we define a a prototype, Sphere, which contains a schematic for the MaterialMeshBundle<StandardMaterial> (aka a PbrBundle). This schematic contains the definitions for two assets that are normally defined in code:

  1. We create a primitive UvSphere mesh
  2. We create a StandardMaterial with a given color

This is powerful because it means users can play around with an asset's values without needing to rebuild the entire application.

Implementation

This should be powered by a new trait: AssetSchematic.

The AssetSchematic trait should work very similar to a normal Schematic. It should be derivable (for Asset types) and have convenient attributes for handling common scenarios.

It should also support defining an AssetSchematic to build an asset not owned by the user. The intention here is that users should be able to define their own schemas for Bevy-owned assets (e.g. adding their own primitive shapes for a Mesh asset).

Lastly, an AssetSchematic should properly handle overwriting itself. This is important because it means that existing references to the asset will automatically receive the changes. This is consistent with regular Bevy assets: there cannot be two versions of an asset referred to by the same path/handle. However, this feature should be optional (though, on by default) and configurable via an attribute in the derive macro.

Considerations

While I haven't really looked at the changes proposed in bevyengine/bevy#8624, I understand that it might change how a feature like AssetSchematic works. In fact, there's a possibility that it breaks it completely.

However, that work is still in draft mode and I'm unsure of when it is planned to actually be released. So for the time being, I plan on proceeding with this feature, along with the understanding that it may require refactoring/removal down the line.

@MrGVSV MrGVSV added this to bevy_proto Aug 3, 2023
@MrGVSV MrGVSV self-assigned this Aug 3, 2023
@MrGVSV MrGVSV converted this from a draft issue Aug 3, 2023
@MrGVSV
Copy link
Owner Author

MrGVSV commented Aug 3, 2023

This is currently in progress!

@MrGVSV MrGVSV pinned this issue Aug 3, 2023
@github-project-automation github-project-automation bot moved this from In Progress to Done in bevy_proto Sep 17, 2023
@MrGVSV MrGVSV unpinned this issue Nov 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant