Visulize mesh outside of build volume
This commit is contained in:
1
TODO.md
1
TODO.md
@@ -93,3 +93,4 @@
|
|||||||
- [ ] Dont fail to load an stl without normals
|
- [ ] Dont fail to load an stl without normals
|
||||||
- [ ] GPU accalration for post processing effect?
|
- [ ] GPU accalration for post processing effect?
|
||||||
- [ ] Fix requiring viewport to be visible to render preview image
|
- [ ] Fix requiring viewport to be visible to render preview image
|
||||||
|
- [x] Visulize mesh outside of bounging box
|
||||||
|
@@ -32,6 +32,7 @@ pub struct ModelPipeline {
|
|||||||
struct ModelUniforms {
|
struct ModelUniforms {
|
||||||
transform: Matrix4<f32>,
|
transform: Matrix4<f32>,
|
||||||
model_transform: Matrix4<f32>,
|
model_transform: Matrix4<f32>,
|
||||||
|
build_volume: Vector3<f32>,
|
||||||
model_color: Vector4<f32>,
|
model_color: Vector4<f32>,
|
||||||
camera_position: Vector3<f32>,
|
camera_position: Vector3<f32>,
|
||||||
camera_target: Vector3<f32>,
|
camera_target: Vector3<f32>,
|
||||||
@@ -111,6 +112,7 @@ impl ModelPipeline {
|
|||||||
let uniforms = ModelUniforms {
|
let uniforms = ModelUniforms {
|
||||||
transform: resources.transform * model_transform,
|
transform: resources.transform * model_transform,
|
||||||
model_transform,
|
model_transform,
|
||||||
|
build_volume: resources.bed_size,
|
||||||
model_color: model.color.to_normalized_gamma_f32().into(),
|
model_color: model.color.to_normalized_gamma_f32().into(),
|
||||||
camera_position: resources.camera.position(),
|
camera_position: resources.camera.position(),
|
||||||
camera_target: resources.camera.target,
|
camera_target: resources.camera.target,
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
struct Context {
|
struct Context {
|
||||||
transform: mat4x4<f32>,
|
transform: mat4x4<f32>,
|
||||||
model_transform: mat4x4<f32>,
|
model_transform: mat4x4<f32>,
|
||||||
|
build_volume: vec3<f32>,
|
||||||
model_color: vec4<f32>,
|
model_color: vec4<f32>,
|
||||||
camera_position: vec3<f32>,
|
camera_position: vec3<f32>,
|
||||||
camera_target: 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 dx = dpdx(in.world_position);
|
||||||
let normal = normalize(cross(dy, dx));
|
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 {
|
if context.render_style == 0 {
|
||||||
return vec4<f32>(normal, 1.0);
|
return vec4<f32>(normal, 1.0);
|
||||||
} else {
|
} else {
|
||||||
@@ -49,3 +54,10 @@ fn frag(in: VertexOutput) -> @location(0) vec4<f32> {
|
|||||||
return vec4<f32>(intensity, context.model_color.a);
|
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;
|
||||||
|
}
|
||||||
|
@@ -34,7 +34,7 @@ fn index(x: u32, y: u32) -> f32 {
|
|||||||
|
|
||||||
@fragment
|
@fragment
|
||||||
fn frag(in: VertexOutput) -> @location(0) vec4<f32> {
|
fn frag(in: VertexOutput) -> @location(0) vec4<f32> {
|
||||||
let aspect = context.aspect * f32(context.dimensions.y) / f32(context.dimensions.x);
|
let aspect = context.aspect * f32(context.dimensions.y) / f32(context.dimensions.x);
|
||||||
let pos = vec2(
|
let pos = vec2(
|
||||||
in.position.x * context.scale * aspect,
|
in.position.x * context.scale * aspect,
|
||||||
in.position.y * context.scale
|
in.position.y * context.scale
|
||||||
|
Reference in New Issue
Block a user