kulkalkul / bevy_mod_billboard Goto Github PK
View Code? Open in Web Editor NEWBillboard text and texture support for bevy
License: Apache License 2.0
Billboard text and texture support for bevy
License: Apache License 2.0
I (and other bevy developers) would love to have this functionality in bevy itself. If you're up to it, please do open a PR!
When experimenting with this crate for information visualization, I found that recomputing text was incredibly slow. Actually rendering it was fine, but changing it crashed my performance from 100 FPS to 10 FPS.
Swapping to icons (using this crate as well) in Leafwing-Studios/Emergence#756 resolved the performance problems completely.
A reader had a suggestion for better optimization:
[Is the gold standard not still to render the font to an atlas texture and draw with that?] ( https://elk.zone/tech.lgbt/@[email protected]/110259520099233824)
Even though basic, this is a breaking change from API standpoint (breaks imports). So I'll keep this around as a reminder until I implement it with another breaking change.
when i used a BillboardTextBundle
together with a bevy-builtin TextBundle
i get :
thread 'Compute Task Pool (7)' panicked at 'wgpu error: Validation Error
Caused by:
In Device::create_bind_group
note: label = `ui_material_bind_group`
texture usage is COPY_SRC | COPY_DST which does not contain required usage TEXTURE_BINDING
i can replicate this by adding the line :
commands.spawn(TextBundle::from_section("ui text", TextStyle { font: fira_sans_regular_handle.clone(), font_size: 60.0, color: Color::BLACK }));
to the text.rs
example at the end of the setup function.
it only occurs when the TextStyle
matches exactly on font and size (so my easy workaround for now is to use a billboard font size that isn't used by my ui).
windows / nvidia / vulkan / bevy 0.10.1/ bevy_mod_billboard 0.3.0
thanks!
Billboard textures seem to have weird behavior when the camera is rotated on the y-axis. The weirdness happens after a sprite is scaled. (Scaling translation.x
when the bullet hits the hitbox)
Initialing camera with Y rotation
let mut camera_transform = Transform::from_translation(Vec3::new(3.3, 1.0, 9.5));
camera_transform.rotate_axis(Vec3::X, deg_to_rad(-45.0));
camera_transform.rotate_axis(Vec3::Y, deg_to_rad(-45.0));
// main camera
commands.spawn((
Camera3dBundle {
transform: camera_transform,
projection: OrthographicProjection {
far: 100.0,
near: -100.0,
// this is how far the camera is away from the focus
scale: 6.0,
scaling_mode: ScalingMode::FixedVertical(2.0),
..default()
}.into(),
..default()
},
MainCamera,
));
Spawning Billboard Sprite
commands
.spawn(BillboardTextureBundle {
texture: BillboardTextureHandle(scene_assets.health_bar.clone()),
mesh: BillboardMeshHandle(meshes.add(Quad::new(value_shape_size * 2.0).into())),
transform: Transform::from_xyz(0.0, npc_info.info.height / 2., 0.0),
..default()
})
.insert(HealthBar)
.insert(NpcIdentification {
id: npc_info.identification.id.clone(),
})
.id();
Weird behavior (video)
I need a possibility to track hover and press events on a billboard.
I tried to achieve it using bevy_mod_picking
crate and exposing the meshes like this:
fn add_billboard_mesh(
mut commands: Commands,
billboards: Query<(Entity, &BillboardMeshHandle), Added<BillboardMeshHandle>>,
) {
for (entity, mesh_handle) in billboards.iter() {
let handle = mesh_handle.0.clone();
commands.entity(entity).insert(handle);
}
}
but meshes from BillboardMeshHandle are positioned on screen differently from where the billboard would be rendered, and raycasting triggers in a wrong screen area:
Hello!
I would like to know if there is a way to do sprite animation on billboarded texture or if it's not possible at the moment.
let layout = TextureAtlas::from_grid(
goblin_sheet.clone(),
Vec2::new(33., 36.),
4,
1,
None,
None,
);
let atlas_handle = texture_atlases.add(layout);
let sprite = TextureAtlasSprite::new(0);
commands.spawn(monster_bundle).with_children(|b| {
b.spawn(BillboardTextureBundle {
transform: Transform::from_translation(Vec3::Y * 2.),
texture: BillboardTextureHandle(goblin_sheet.clone()),
mesh: BillboardMeshHandle(
meshes.add(shape::Quad::new(Vec2::new(2., 2.)).into()),
),
..default()
})
.insert((sprite, atlas_handle));
});
If I understand correctly, the crate is only for Texture and not for Sprite so the above code only render the whole atlas instead of the cropped sprite.
Thanks for the hardwork!
With the 0.13
we know have 2d primitives, it would be useful if these were billboard-able with this package.
When working on Leafwing-Studios/Emergence#613, I encountered a memory leak, which ultimately led to a panic due to my GPU running out of memory.
This was the commit in question: Leafwing-Studios/Emergence@0f60c50
Here's what my system monitor looked like, before and after toggling on the billboarded text via the F2 key.
The drop is when the game crashed ๐
I'm using this in a simple immediate mode way for now, as seen here, but I am being careful to reuse assets and despawn my entities each frame.
Hi,
Has there been some change to the way billboards are spawned and their translation is set? It used to be that if you do commands.entity(parent_entity).push_children(&[billboard_entity]) the billboard transform would be the same as that of the parent object, i.e. if you gave it a translation, that would be relative to the parent. But what I see now is that the child billboard spawns at 0/0/0 world coordinates and is no longer following the parent.
Is that on purpose or an unintentional change?
This requires changes on text mesh building logic because of the changes to the bevy (mainly Anchor component). I'll tackle this same time I upgrade my own game into 0.10, which is blocked by some crates I use right now.
I want to reuse a png for both UI icons and a billboarded status display. Because this plugin requires Handle<BillBoardTexture>
rather than a Handle<Image>
, I have to store two separate collections.
Options:
Handle<Image>
everywhere (and do the same for Mesh
).impl From<Handle<Image>> for Handle<BillboardTexture>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.