Closed Weasy666 closed 2 years ago
Just a thought, hope it's welcome from a stranger, an easy and useful first step towards this might be to expose a constructor from bytes rather than from a file.
You are welcome! I haven't had time to take a closer look at Bevy's AssetLoader. Are you somewhat familiar with it? Well...i guess...creating/loading an SVG from bytes could be useful either way, so i will definitely look to implement that.
I haven't done it myself, but looking at the simplest example I know: https://github.com/jamadazi/bevy_asset_ron/blob/master/src/lib.rs#L28 makes it look like bytes are the interface. And like you said, I thought it would be useful either way.
I have implemented from_bytes
and from_reader
functions to SvgBuilder
and will take a stab at the asset loader the next view days, as this is a good diversion after hitting a wall while trying to fix issue #3 😫
If you want to take a look I've implemented an AssetLoader for Svg with an associated Mesh in https://github.com/mdevlamynck/bevy_svg/tree/asset_loader. I forked from the bevy-0.5 branch and refactored the code quite a bit (for instance I removed the Origin type and put the origin in the center of the svg during the construction of the paths) so a PR might be to many changes.
Oh...wow! That really are a load of changes. I will look through it on the weekend and come back to you. Thank you!
Also I might have a clue for #3. I'm not sure yet (I think the abs_transform()
is not used when reading usvg tree).
Just fixed #3 in my fork. I'll try to extract the fix into a PR, do you prefer I target bevy-0.5 or main?
I was looking into this project (hoping to use it). @mdevlamynck, I took a look at the asset-loader branch.
Here's my unsolicited (and hopefully helpful) feedback: 1) you removed the 'prelude' module. For bevy, at least, it seems conventional have one. 2) Instead of using SvgBundleConfig, it seems more conventional to implement Default. See PbrBundle, for example. You'd do:
.insert_bundle(PbrBundle {
mesh: asset_server.load("mymesh.gltf#Mesh0/Primitive0"),
material: asset_server.load("mymesh.gltf#Material0"),
..Default::default()
})
3) The "NeedMeshUpdate" component seems a little hacky. Consider: remove "mesh" from the SvgBundle. In the attach_mesh system, query for Without<Handle
I skipped over a lot of the heavy code, but hopefully that's helpful for getting a PR through.
Thanks for taking a look. I am in the process of updating the crate to the new Bevy renderer and while being at it, i am implementing AssetLoader
too. So...it should be in the next 0.*
release, which is (hopefully) ready when bevy 0.6
will be released.
@bsurmanski
SvgBundleConfig
contains fields not in SvgBundle
so I'm not sure it would work (and SvgBundleConfig
implements Default
). But I agree it would be nice to only use SvgBundle
.In the end I changed the crate too much to be a realistic candidate for a PR. But at least it can be an example.
Ok...i am somewhat stuck and needed a short break from the new renderer, so i've decided to implement AssetLoader
and backported it to bevy-0.5
, so you can test with both branches main
and bevy-0.5
.
I will test it for a few days and if i don't find any serious problems, i will release a breaking change at the end of next week.
@mdevlamynck,
Regarding (2), looks like SvgBundleConfig is the following:
pub struct SvgBundleConfig {
/// SVG to render.
pub svg: Handle<Svg>,
/// Position at which the [`SvgBundle`] will be spawned in Bevy.
/// The center of the SVG will be at this position.will be at this position.
pub position: Vec3,
/// Value by which the SVG will be scaled, default is (1.0, 1.0).
pub scale: Vec2,
}
Looks like svg is in the SvgBundle, and position and scale are represented in the Transform, right?
Regarding (3), there might be other components that would need a deferred insertion too, like Draw or MainPass? Idk.
AssetLoader
is now available in the newly released version 0.4
for Bevy 0.5
.
Updating to the new Bevy renderer (in Bevy 0.6
) will still take a little longer.
Change the file loading from direct loading per
File::open()
to loading by Bevy's AssetLoader.