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

Add and impl Primitives #10580

Merged
merged 22 commits into from
Nov 17, 2023
Merged

Add and impl Primitives #10580

merged 22 commits into from
Nov 17, 2023

Conversation

Aztro-dev
Copy link
Contributor

Add and implement constructors for Primitives

Solution

  • Created new primitives
    • Torus
    • Conical Frustum
    • Cone
    • Ellipse
  • Implemented constructors (Primitive::new) for almost every single other primitive.

Copy link
Contributor

@Jondolf Jondolf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks very nice overall! I left some notes on consistency and docs, and also on frusta.

A viewing frustum would probably be more useful for rendering, feedback from others would be nice. ConicalFrustum also feels somewhat niche, but I have no objection against including it.

crates/bevy_math/src/primitives/dim2.rs Outdated Show resolved Hide resolved
@@ -127,6 +172,13 @@ pub struct Triangle2d {
}
impl Primitive2d for Triangle2d {}

impl Triangle2d {
/// Create a new `Triangle2d` from a list of Vertices
pub fn new(vertices: [Vec2; 3]) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice to have a method that takes points a, b and c instead. Taking an array doesn't feel quite as intuitive in my opinion, although it's almost the same.

Not sure which one of them should be new, but the other method could be either from_points or from_array based on what is chosen.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer this to be the new, and not include from_array at all.

crates/bevy_math/src/primitives/dim3.rs Outdated Show resolved Hide resolved
crates/bevy_math/src/primitives/dim3.rs Outdated Show resolved Hide resolved
crates/bevy_math/src/primitives/dim2.rs Outdated Show resolved Hide resolved
/// A conical frustum can be created
/// by slicing off a section of a cone.
#[derive(Clone, Copy, Debug)]
pub struct ConicalFrustum {
Copy link
Contributor

@Jondolf Jondolf Nov 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also nice to have, but if we also want primitives to be used for rendering, a viewing frustum would be more useful. For rendering, it would be defined by an aspect-ratio, fov and the near and far planes, but maybe that's a bit too rendering-specific for primitives? More opinions on this would be useful.

If we add a viewing frustum though, it should probably be done in a separate PR since it'd touch on rendering code too and be a bit more controversial.

If we want to support different types of frusta, then perhaps a polygonal frustum with a regular polygon as a base could also be useful?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@superdump also briefly touched on this here: #10466 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, we should split rendering frustra into a different PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rendering frustum most likely belongs in the bounding PR. Might be good to create some helper later to create a primitive shape you can render from the 6 plane representation (which is not exactly most convinient way to render them)

crates/bevy_math/src/primitives/dim3.rs Show resolved Hide resolved
@nicopap nicopap added the C-Feature A new feature, making something new possible label Nov 16, 2023
@alice-i-cecile alice-i-cecile added the A-Math Fundamental domain-agnostic mathematical operations label Nov 16, 2023
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New shapes look great! I left some guidance on the parameterization of them.

More constructors is helpful, but we shouldn't have trivial ones, aka those that simply duplicate public fields.

Aztro-dev and others added 3 commits November 16, 2023 10:42
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your patience :) Only a couple more nits left!

Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remaining items:

  1. new constructor Triangle2d that takes points a, b and c.
  2. Same constructor, but for Triangle3d
  3. Iterator-based constructor for Polygon<N>.

@Jondolf
Copy link
Contributor

Jondolf commented Nov 17, 2023

  1. Same constructor, but for Triangle3d

Triangle3d doesn't exist yet because it was unclear if it's needed: #10466 (comment)

But maybe it should be added?

@alice-i-cecile
Copy link
Member

Ah, got it. Let's do that in a different PR!

@Aztro-dev
Copy link
Contributor Author

Aztro-dev commented Nov 17, 2023

  1. new constructor Triangle2d that takes points a, b and c.

Should I still have another constructor that takes a slice of 3 Vec2s?

@Jondolf
Copy link
Contributor

Jondolf commented Nov 17, 2023

I believe not: #10580 (comment)
It would be another trivial constructor equivalent to doing Triangle2d { vertices: [...] }

@Aztro-dev
Copy link
Contributor Author

Remaining Items should be completed 👍

Copy link
Contributor

@Jondolf Jondolf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last comments, just a few small doc things

}
}

/// A cone primitive.
Copy link
Contributor

@Jondolf Jondolf Nov 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @NiseVoid suggested (#10580 (comment)), maybe we should mention where the origin of the cone should be so that different integrations have consistent representations?

If the options are the base and apex (tip), the base is more intuitive for me personally. I view cones like Wikipedia's description:

a three-dimensional geometric shape that tapers smoothly from a flat base (frequently, though not necessarily, circular) to a point called the apex or vertex.

crates/bevy_math/src/primitives/dim3.rs Outdated Show resolved Hide resolved
crates/bevy_math/src/primitives/dim3.rs Outdated Show resolved Hide resolved
Aztro-dev and others added 2 commits November 17, 2023 11:32
Co-authored-by: Joona Aalto <[email protected]>
Co-authored-by: Joona Aalto <[email protected]>
Copy link
Contributor

@Jondolf Jondolf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for your patience! The cone origin thing (#10580 (comment)) would be nice to reach a consensus on, but it's not a blocker for me in terms of this PR.

@alice-i-cecile alice-i-cecile added this pull request to the merge queue Nov 17, 2023
@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Nov 17, 2023
Merged via the queue into bevyengine:main with commit 33cd59f Nov 17, 2023
22 checks passed
@Jondolf Jondolf mentioned this pull request Nov 18, 2023
41 tasks
rdrpenguin04 pushed a commit to rdrpenguin04/bevy that referenced this pull request Jan 9, 2024
# Add and implement constructors for Primitives

- Adds more Primitive types and adds a constructor for almost all of
them
- Works towards finishing bevyengine#10572 

## Solution

- Created new primitives
    - Torus
    - Conical Frustum
    - Cone
    - Ellipse
- Implemented constructors (`Primitive::new`) for almost every single
other primitive.

---------

Co-authored-by: Joona Aalto <[email protected]>
Co-authored-by: Alice Cecile <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Math Fundamental domain-agnostic mathematical operations C-Feature A new feature, making something new possible S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants