-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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,49 @@ | ||
use glam::vec3; | ||
|
||
use crate::prelude::*; | ||
|
||
pub struct Cube { | ||
pub subdivisions: usize, | ||
} | ||
|
||
pub struct CubeData { | ||
pub front_bottom_left_vertex: VertexId, | ||
} | ||
|
||
impl Cube { | ||
pub fn generate(self) -> SMeshResult<(SMesh, CubeData)> { | ||
// Construct SMesh | ||
let mut smesh = SMesh::new(); | ||
let half_extent = 0.5; | ||
let v0 = smesh.add_vertex(vec3(-half_extent, -half_extent, half_extent)); | ||
let v1 = smesh.add_vertex(vec3(half_extent, -half_extent, half_extent)); | ||
let v2 = smesh.add_vertex(vec3(half_extent, half_extent, half_extent)); | ||
let v3 = smesh.add_vertex(vec3(-half_extent, half_extent, half_extent)); | ||
|
||
let v4 = smesh.add_vertex(vec3(-half_extent, -half_extent, -half_extent)); | ||
let v5 = smesh.add_vertex(vec3(half_extent, -half_extent, -half_extent)); | ||
let v6 = smesh.add_vertex(vec3(half_extent, half_extent, -half_extent)); | ||
let v7 = smesh.add_vertex(vec3(-half_extent, half_extent, -half_extent)); | ||
|
||
// Front | ||
smesh.make_face(vec![v0, v1, v2, v3])?; | ||
// Right | ||
smesh.make_face(vec![v1, v5, v6, v2])?; | ||
// Back | ||
smesh.make_face(vec![v5, v4, v7, v6])?; | ||
// Left | ||
smesh.make_face(vec![v4, v0, v3, v7])?; | ||
// Top | ||
smesh.make_face(vec![v3, v2, v6, v7])?; | ||
// Bottom | ||
smesh.make_face(vec![v4, v5, v1, v0])?; | ||
|
||
smesh.recalculate_normals()?; | ||
Ok(( | ||
smesh, | ||
CubeData { | ||
front_bottom_left_vertex: v0, | ||
}, | ||
)) | ||
} | ||
} |