Skip to content

Commit

Permalink
Rename CircularShapeUvMode to CircularMeshUvMode.
Browse files Browse the repository at this point in the history
  • Loading branch information
spectria-limina committed Feb 15, 2024
1 parent 41806b7 commit 9240e7e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
22 changes: 11 additions & 11 deletions crates/bevy_render/src/mesh/primitives/dim2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl From<CircleMeshBuilder> for Mesh {

/// Specifies how to generate UV-mappings for [`CircularSector`] and [`CircularSegment`] shapes.
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum CircularShapeUvMode {
pub enum CircularMeshUvMode {
/// Treats the shape as a mask over a circle of equal size and radius,
/// with the center of the circle at the center of the texture.
Mask {
Expand All @@ -93,9 +93,9 @@ pub enum CircularShapeUvMode {
},
}

impl Default for CircularShapeUvMode {
impl Default for CircularMeshUvMode {
fn default() -> Self {
CircularShapeUvMode::Mask { angle: 0.0 }
CircularMeshUvMode::Mask { angle: 0.0 }
}
}

Expand All @@ -112,15 +112,15 @@ pub struct CircularSectorMeshBuilder {
#[doc(alias = "vertices")]
pub resolution: usize,
/// The UV mapping mode
pub uv_mode: CircularShapeUvMode,
pub uv_mode: CircularMeshUvMode,
}

impl Default for CircularSectorMeshBuilder {
fn default() -> Self {
Self {
sector: CircularSector::default(),
resolution: 32,
uv_mode: CircularShapeUvMode::default(),
uv_mode: CircularMeshUvMode::default(),
}
}
}
Expand All @@ -145,7 +145,7 @@ impl CircularSectorMeshBuilder {

/// Sets the uv mode used for the sector mesh
#[inline]
pub const fn uv_mode(mut self, uv_mode: CircularShapeUvMode) -> Self {
pub const fn uv_mode(mut self, uv_mode: CircularMeshUvMode) -> Self {
self.uv_mode = uv_mode;
self
}
Expand All @@ -157,7 +157,7 @@ impl CircularSectorMeshBuilder {
let normals = vec![[0.0, 0.0, 1.0]; self.resolution + 1];
let mut uvs = Vec::with_capacity(self.resolution + 1);

let CircularShapeUvMode::Mask { angle: uv_angle } = self.uv_mode;
let CircularMeshUvMode::Mask { angle: uv_angle } = self.uv_mode;

// Push the center of the circle.
positions.push([0.0; 3]);
Expand Down Expand Up @@ -235,15 +235,15 @@ pub struct CircularSegmentMeshBuilder {
#[doc(alias = "vertices")]
pub resolution: usize,
/// The UV mapping mode
pub uv_mode: CircularShapeUvMode,
pub uv_mode: CircularMeshUvMode,
}

impl Default for CircularSegmentMeshBuilder {
fn default() -> Self {
Self {
segment: CircularSegment::default(),
resolution: 32,
uv_mode: CircularShapeUvMode::default(),
uv_mode: CircularMeshUvMode::default(),
}
}
}
Expand All @@ -268,7 +268,7 @@ impl CircularSegmentMeshBuilder {

/// Sets the uv mode used for the segment mesh
#[inline]
pub const fn uv_mode(mut self, uv_mode: CircularShapeUvMode) -> Self {
pub const fn uv_mode(mut self, uv_mode: CircularMeshUvMode) -> Self {
self.uv_mode = uv_mode;
self
}
Expand All @@ -280,7 +280,7 @@ impl CircularSegmentMeshBuilder {
let normals = vec![[0.0, 0.0, 1.0]; self.resolution + 1];
let mut uvs = Vec::with_capacity(self.resolution + 1);

let CircularShapeUvMode::Mask { angle: uv_angle } = self.uv_mode;
let CircularMeshUvMode::Mask { angle: uv_angle } = self.uv_mode;

// Push the center of the chord.
let midpoint_vertex = self.segment.chord_midpoint();
Expand Down
15 changes: 6 additions & 9 deletions examples/2d/2d_shapes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,12 @@ fn setup(

let shapes = [
Shape::from(meshes.add(Circle { radius: 50.0 })),
{
let sector = CircularSector::from_radians(50.0, 5.0);
Shape::new(
meshes.add(sector),
// A sector is drawn symmetrically from the top.
// To make it face right, we must rotate it to the left by 90 degrees.
Transform::from_rotation(Quat::from_rotation_z(PI / 2.0)),
)
},
Shape::new(
meshes.add(CircularSector::from_radians(50.0, 5.0)),
// A sector is drawn symmetrically from the top.
// To make it face right, we must rotate it to the left by 90 degrees.
Transform::from_rotation(Quat::from_rotation_z(PI / 2.0)),
),
{
let segment = CircularSegment::from_degrees(50.0, 135.0);
Shape::new(
Expand Down
6 changes: 3 additions & 3 deletions examples/2d/mesh2d_circular.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::f32::consts::PI;

use bevy::{prelude::*, sprite::MaterialMesh2dBundle};
use bevy_internal::render::mesh::{
CircularSectorMeshBuilder, CircularSegmentMeshBuilder, CircularShapeUvMode,
CircularMeshUvMode, CircularSectorMeshBuilder, CircularSegmentMeshBuilder,
};

fn main() {
Expand Down Expand Up @@ -46,7 +46,7 @@ fn setup(
// We must rotate it both in the Transform and in the mesh's UV mappings.
let sector_angle = -sector.half_angle();
let sector_mesh =
CircularSectorMeshBuilder::new(sector).uv_mode(CircularShapeUvMode::Mask {
CircularSectorMeshBuilder::new(sector).uv_mode(CircularMeshUvMode::Mask {
angle: sector_angle,
});
commands.spawn(MaterialMesh2dBundle {
Expand All @@ -70,7 +70,7 @@ fn setup(
// so it is the negative of what you might otherwise expect.
let segment_angle = -PI / 2.0;
let segment_mesh =
CircularSegmentMeshBuilder::new(segment).uv_mode(CircularShapeUvMode::Mask {
CircularSegmentMeshBuilder::new(segment).uv_mode(CircularMeshUvMode::Mask {
angle: -segment_angle,
});
commands.spawn(MaterialMesh2dBundle {
Expand Down

0 comments on commit 9240e7e

Please sign in to comment.