1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use bevy::prelude::*;
pub fn default_sky_mesh() -> Mesh {
// safety: unwrap is okay, because ico shape only fails
// if there are to many vertices
let mut mesh = Sphere::new(1.0).mesh().ico(6).unwrap();
flip_mesh_normals(&mut mesh);
mesh
}
pub fn flip_mesh_normals(mesh: &mut Mesh) {
if let Some(normals) = mesh.attribute_mut(Mesh::ATTRIBUTE_NORMAL) {
if let bevy::render::mesh::VertexAttributeValues::Float32x3(values) = normals {
for n in values.iter_mut() {
n[0] = -n[0];
n[1] = -n[1];
n[2] = -n[2];
}
}
}
if let Some(indices) = mesh.indices_mut() {
use bevy::render::mesh::Indices;
match indices {
Indices::U16(vec) => {
for i in vec.chunks_exact_mut(3) {
i.swap(1, 2);
}
}
Indices::U32(vec) => {
for i in vec.chunks_exact_mut(3) {
i.swap(1, 2);
}
}
}
}
}
#[cfg(feature = "serde")]
pub fn path_relative_to_bevy_exe(path: &str) -> std::path::PathBuf {
let current_dir = bevy::asset::io::file::FileAssetReader::get_base_path();
let new_path = current_dir.join(path);
new_path
}