This commit is contained in:
1 parent
9f95ba3082
commit
fcd34f9079
12 files changed
+570
-1
No files matched your search
@@ -426,6 +426,49 @@ impl BrushDesc {
|
||||
receive_shadows: true,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn extruded_prism(base_vertices: &[Vec3], height: f32) -> Option<Self> {
|
||||
if crate::brush_math::validate_floor_polygon(base_vertices).is_err() {
|
||||
return None;
|
||||
}
|
||||
let height = height.max(0.001);
|
||||
let mut base = base_vertices.to_vec();
|
||||
if crate::brush_math::signed_area_xz(&base) < 0.0 {
|
||||
base.reverse();
|
||||
}
|
||||
let top: Vec<Vec3> = base
|
||||
.iter()
|
||||
.map(|vertex| *vertex + Vec3::Y * height)
|
||||
.collect();
|
||||
let mut bottom = base.clone();
|
||||
bottom.reverse();
|
||||
|
||||
let mut faces = Vec::with_capacity(base.len() + 2);
|
||||
faces.push(brush_face("face:+y", Vec3::Y, top));
|
||||
faces.push(brush_face("face:-y", Vec3::NEG_Y, bottom));
|
||||
for index in 0..base.len() {
|
||||
let next = (index + 1) % base.len();
|
||||
let a = base[index];
|
||||
let b = base[next];
|
||||
let edge = b - a;
|
||||
let normal = Vec3::new(edge.z, 0.0, -edge.x).normalize_or_zero();
|
||||
if normal.length_squared() <= f32::EPSILON {
|
||||
return None;
|
||||
}
|
||||
faces.push(brush_face(
|
||||
&format!("face:side:{index}"),
|
||||
normal,
|
||||
vec![a, a + Vec3::Y * height, b + Vec3::Y * height, b],
|
||||
));
|
||||
}
|
||||
|
||||
Some(Self {
|
||||
kind: BrushKind::Additive,
|
||||
faces,
|
||||
cast_shadows: true,
|
||||
receive_shadows: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for BrushDesc {
|
||||
|
||||
Reference in new issue
Block a user