-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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 sprite and mesh alteration examples #15298
base: main
Are you sure you want to change the base?
Add sprite and mesh alteration examples #15298
Conversation
The generated |
// Now we can directly manipulate vertices on the mesh. Here, we're just scaling in and out | ||
// for demonstration purposes. This will affect all entities currently using the asset. | ||
if let Some(VertexAttributeValues::Float32x3(positions)) = | ||
mesh.attribute_mut(Mesh::ATTRIBUTE_POSITION) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will freely admit this took quite a lot of getting to a "working" state, so if there's a more sensible way to do it let me know! Much head-scratching involved 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, our mesh modification API is not particularly ergonomic: it's a very rare operation to do in code!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure this this is the only way to do this, yeah
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect: this demonstrates the point really nicely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! The alter_mesh
example could mayyyybe be turned into procedural_mesh
, as that is what most people using this API will probably end up doing. Not sure, your choice.
The rest of the comments are just about how to make the examples a bit easier to understand for outsiders. Comments are mostly valid for both examples.
Good job with the examples, they're pretty nicely written!
#[derive(Default)] | ||
struct IsMeshScaled(bool); | ||
|
||
fn keyboard_controls( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you split this into two systems so that they can have meaningful names?
Doing so also allows you to completely skip the keyboard_input
param by using a input_just_pressed
run condition :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, that's a thing? Nice!
GltfAssetLabel::Primitive { | ||
mesh: 0, | ||
primitive: 0, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a very quick explanation as to what a "primitive" is in this context would be good
)); | ||
} | ||
|
||
fn instructions(mut commands: Commands) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is usually called spawn_text
or similar in other examples. Can we keep them consistent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, TIL. Can do!
|
||
fn keyboard_controls( | ||
asset_server: Res<AssetServer>, | ||
mut is_mesh_scaled: Local<IsMeshScaled>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be simpler if we just use a Local<bool>
, imo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, yeah 🤦
if let Some(VertexAttributeValues::Float32x3(positions)) = | ||
mesh.attribute_mut(Mesh::ATTRIBUTE_POSITION) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a comment about what Float32x3
and ATTRIBUTE_POSITION
mean would be nice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, that'll mean understanding what they mean 😆 OK, on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know if you need a primer, I can weite something up tomorrow if you want :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it's better for me if I figure it out!
Objective
Add examples for manipulating sprites and meshes by either mutating the handle or direct manipulation of the asset, as described in #15056.
Closes #3130.
(The previous PR suffered a Git-tastrophe, and was unceremoniously closed, sry! 😅 )