From 0e13b1ca5ee9f256983cc45647032de5ddb479bd Mon Sep 17 00:00:00 2001 From: Steve Frampton <40193522+FarmingtonS9@users.noreply.github.com> Date: Tue, 16 Jul 2024 22:59:26 +1000 Subject: [PATCH] Added `new` method to Cone 3D primitive (#14325) Reference to #14299. # Objective - Ensuring consistent practice of instantiating 3D primitive shapes in Bevy. ## Solution - Add `new` method, containing `radius` and `height` arguments, to Cone 3D primitive shape. ## Testing - Instantiated cone using same values (radius is `2.` and height is `5.`), using the current method and the added `new` method. - Basic setup of Bevy Default Plugins and `3DCameraBundle`. --- ## Showcase
Click to view showcase ```rust use bevy::prelude::*; fn main() { App::new() .add_plugins(DefaultPlugins) .add_systems(Startup, setup) .run(); } fn setup( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, ) { let new_cone = meshes.add(Cone::new(2., 5.)); commands.spawn(PbrBundle { mesh: new_cone, ..default() }); let old_cone = meshes.add(Cone { radius: 2., height: 5., }); commands.spawn(PbrBundle { mesh: old_cone, material: materials.add(Color::WHITE), transform: Transform::from_xyz(10., 0., 0.), ..default() }); commands.spawn(Camera3dBundle { transform: Transform::from_xyz(20., 20., 20.).looking_at(Vec3::ZERO, Dir3::Y), ..default() }); } ```
![image](https://github.com/user-attachments/assets/267f8124-8734-4c20-8840-fcf35375a778) - Pink Cone is created using the `new` method. - Black Cone is created using the existing method. ## Migration Guide - Addition of `new` method to the 3D primitive Cone struct. --- crates/bevy_math/src/primitives/dim3.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/bevy_math/src/primitives/dim3.rs b/crates/bevy_math/src/primitives/dim3.rs index 5eb456f37c..9c21b9ee4a 100644 --- a/crates/bevy_math/src/primitives/dim3.rs +++ b/crates/bevy_math/src/primitives/dim3.rs @@ -625,6 +625,10 @@ impl Default for Cone { } impl Cone { + /// Create a new [`Cone`] from a radius and height. + pub fn new(radius: f32, height: f32) -> Self { + Self { radius, height } + } /// Get the base of the cone as a [`Circle`] #[inline(always)] pub fn base(&self) -> Circle {