Visulize mesh outside of build volume

This commit is contained in:
Connor Slade
2025-02-15 11:42:28 -05:00
parent 8f73af1e5a
commit 376735ac20
4 changed files with 16 additions and 1 deletions

View File

@@ -93,3 +93,4 @@
- [ ] Dont fail to load an stl without normals
- [ ] GPU accalration for post processing effect?
- [ ] Fix requiring viewport to be visible to render preview image
- [x] Visulize mesh outside of bounging box

View File

@@ -32,6 +32,7 @@ pub struct ModelPipeline {
struct ModelUniforms {
transform: Matrix4<f32>,
model_transform: Matrix4<f32>,
build_volume: Vector3<f32>,
model_color: Vector4<f32>,
camera_position: Vector3<f32>,
camera_target: Vector3<f32>,
@@ -111,6 +112,7 @@ impl ModelPipeline {
let uniforms = ModelUniforms {
transform: resources.transform * model_transform,
model_transform,
build_volume: resources.bed_size,
model_color: model.color.to_normalized_gamma_f32().into(),
camera_position: resources.camera.position(),
camera_target: resources.camera.target,

View File

@@ -3,6 +3,7 @@
struct Context {
transform: mat4x4<f32>,
model_transform: mat4x4<f32>,
build_volume: vec3<f32>,
model_color: vec4<f32>,
camera_position: vec3<f32>,
camera_target: vec3<f32>,
@@ -35,6 +36,10 @@ fn frag(in: VertexOutput) -> @location(0) vec4<f32> {
let dx = dpdx(in.world_position);
let normal = normalize(cross(dy, dx));
if outside_build_volume(in.world_position) {
return vec4<f32>(1.0, 0.0, 0.0, 1.0);
}
if context.render_style == 0 {
return vec4<f32>(normal, 1.0);
} else {
@@ -49,3 +54,10 @@ fn frag(in: VertexOutput) -> @location(0) vec4<f32> {
return vec4<f32>(intensity, context.model_color.a);
}
}
fn outside_build_volume(pos: vec3<f32>) -> bool {
let build = context.build_volume / 2.0;
return pos.x < -build.x || pos.x > build.x
|| pos.y < -build.y || pos.y > build.y
|| pos.z < 0.0 || pos.x > context.build_volume.z;
}