-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Add ramp primitive #11790
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
Closed
Closed
Add ramp primitive #11790
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
3cca061
Added ramp and tests for ramp
lynn-lumen 1639d0d
Implement `Meshable` and `Default` for `Cone`
lynn-lumen 8a732f9
Implement `Bounded3d` for `Ramp` and added Ramp primitive gizmo
lynn-lumen 3b9047f
Implement reflect for Ramp
lynn-lumen 0be1b66
Update 3d_gizmos example to include ramp
lynn-lumen 93dcc64
Merge branch 'main' into add_ramp_and_cone
lynn-lumen 13d9e67
Ran cargo fmt
lynn-lumen 61b4273
Merge branch 'add_ramp_and_cone' of https://github.com/solis-lumine-v…
lynn-lumen 85fb64c
Truncated floats in tests
lynn-lumen 505cf05
Removed `Meshable` for `Cone``
lynn-lumen c8a642e
Generalize `Ramp` to `Prism`
lynn-lumen 10cf433
Fix prism bounding test
lynn-lumen 3dbe528
Merge remote-tracking branch 'upstream/main' into add_ramp_and_cone
lynn-lumen 748d65d
Fix merge errors
lynn-lumen d8a1078
Revert to ramp
lynn-lumen 8ae6ba5
Fix example
lynn-lumen 9124845
Merge branch 'main' into add_ramp_and_cone
lynn-lumen 5a91157
Fix merge errors
lynn-lumen 3d43bdb
fix CI errors
lynn-lumen 76969df
Merge branch 'main' into add_ramp_and_cone
lynn-lumen 2482ded
Merge branch 'main' into add_ramp_and_cone
lynn-lumen 94fc290
Use `element_product`
lynn-lumen b100632
Use `Vec3A` for bounding
lynn-lumen b8b92af
Don't split halfsize in gizmos
lynn-lumen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use bevy_math::{primitives::Ramp, Vec3}; | ||
use wgpu::PrimitiveTopology; | ||
|
||
use crate::{ | ||
mesh::{Indices, Mesh, Meshable}, | ||
render_asset::RenderAssetUsages, | ||
}; | ||
|
||
impl Meshable for Ramp { | ||
type Output = Mesh; | ||
|
||
fn mesh(&self) -> Self::Output { | ||
let min = -self.half_size; | ||
let max = self.half_size; | ||
|
||
let top_normal = Vec3::new(0.0, min.z, max.y).normalize_or_zero().to_array(); | ||
|
||
// Suppose Y-up right hand, and camera look from +Z to -Z | ||
let vertices = &[ | ||
// Slope | ||
([min.x, max.y, max.z], top_normal, [1.0, 0.0]), | ||
([max.x, max.y, max.z], top_normal, [0.0, 0.0]), | ||
([max.x, min.y, min.z], top_normal, [0.0, 1.0]), | ||
([min.x, min.y, min.z], top_normal, [1.0, 1.0]), | ||
// Right | ||
([max.x, min.y, min.z], [1.0, 0.0, 0.0], [0.0, 0.0]), | ||
([max.x, max.y, max.z], [1.0, 0.0, 0.0], [1.0, 1.0]), | ||
([max.x, min.y, max.z], [1.0, 0.0, 0.0], [0.0, 1.0]), | ||
// Left | ||
([min.x, min.y, max.z], [-1.0, 0.0, 0.0], [1.0, 0.0]), | ||
([min.x, max.y, max.z], [-1.0, 0.0, 0.0], [0.0, 0.0]), | ||
([min.x, min.y, min.z], [-1.0, 0.0, 0.0], [1.0, 1.0]), | ||
// Bottom | ||
([max.x, min.y, max.z], [0.0, -1.0, 0.0], [0.0, 0.0]), | ||
([min.x, min.y, max.z], [0.0, -1.0, 0.0], [1.0, 0.0]), | ||
([min.x, min.y, min.z], [0.0, -1.0, 0.0], [1.0, 1.0]), | ||
([max.x, min.y, min.z], [0.0, -1.0, 0.0], [0.0, 1.0]), | ||
// Front | ||
([min.x, max.y, max.z], [0.0, 0.0, 1.0], [0.0, 1.0]), | ||
([max.x, max.y, max.z], [0.0, 0.0, 1.0], [1.0, 1.0]), | ||
([max.x, min.y, max.z], [0.0, 0.0, 1.0], [1.0, 0.0]), | ||
([min.x, min.y, max.z], [0.0, 0.0, 1.0], [0.0, 0.0]), | ||
]; | ||
|
||
let positions: Vec<_> = vertices.iter().map(|(p, _, _)| *p).collect(); | ||
let normals: Vec<_> = vertices.iter().map(|(_, n, _)| *n).collect(); | ||
let uvs: Vec<_> = vertices.iter().map(|(_, _, uv)| *uv).collect(); | ||
|
||
let indices = Indices::U32(vec![ | ||
0, 1, 2, 2, 3, 0, // slope | ||
4, 5, 6, // right | ||
7, 8, 9, // left | ||
10, 11, 12, 12, 13, 10, // bottom | ||
14, 16, 15, 16, 14, 17, // front | ||
]); | ||
|
||
Mesh::new( | ||
PrimitiveTopology::TriangleList, | ||
RenderAssetUsages::default(), | ||
) | ||
.with_inserted_attribute(Mesh::ATTRIBUTE_POSITION, positions) | ||
.with_inserted_attribute(Mesh::ATTRIBUTE_NORMAL, normals) | ||
.with_inserted_attribute(Mesh::ATTRIBUTE_UV_0, uvs) | ||
.with_inserted_indices(indices) | ||
} | ||
} | ||
|
||
impl From<Ramp> for Mesh { | ||
fn from(ramp: Ramp) -> Self { | ||
ramp.mesh() | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.