asny / three-d

2D/3D renderer - makes it simple to draw stuff across platforms (including web)
MIT License
1.24k stars 105 forks source link

panics when I try to pick & mesh glitch #395

Closed GodGotzi closed 9 months ago

GodGotzi commented 9 months ago

I display some custom meshes with Trimesh from three-d-assets crate.

    let trimesh = TriMesh {
        positions: Positions::F64(positions),
        colors: Some(colors),
        normals: Some(normals),
        ..Default::default()
    };

create my model

    let model = Gm {
        geometry: Mesh::new(context, &trimesh),
        material: construct_filament_material(),
    };
pub fn construct_filament_material() -> PhysicalMaterial {
    PhysicalMaterial {
        name: "default".to_string(),
        ..Default::default()
    }
}

The rendering works just fine:. At the time I call the function pick with this geometry I got this panic

image thanks for your help

asny commented 9 months ago

Thanks for reporting 🙏 Just wanted to let you know that I'm looking at it. However, I can't reproduce (it's probably a difference in shader compilers, some compilers are more aggressive to remove unused variables), but it sort of makes sense. The color attribute is not used when picking, so it shouldn't be sent.

asny commented 9 months ago

@GodGotzi Can I get you to test if https://github.com/asny/three-d/pull/398 fixes the issue?

GodGotzi commented 9 months ago

@GodGotzi Can I get you to test if #398 fixes the issue?

works

Thank you for quickly resolving this issue; it now works smoothly. However, I have another question that is not related to the issue at hand. Parts of my meshes occasionally glitch, and I'm not sure what could be causing it. Once again, thanks for promptly fixing the problem.

glitch:

https://github.com/asny/three-d/assets/95647640/8fb7aebe-c755-4d85-851b-6a9f66ca21ad

I am building my own slicer for 3d printing to display gcode. What I think is happening is that some layers get transparent and now I am able to see the purple infill. Is this some sort of mechanism to get more performance for the renderer or is that something else?

GodGotzi commented 9 months ago

So I started to change my depth buffer values from the default of 24, but with any other bit value the application crashes. For example with 32

asny commented 9 months ago

Thank you for quickly resolving this issue; it now works smoothly.

Great, thanks for testing 👍 I'll make a new release with the fix.

Parts of my meshes occasionally glitch, and I'm not sure what could be causing it.

Could it be that the triangles that you're trying to render are smaller than a pixel when you zoom out? If they are, then some of them will not be covering the center of a pixel and will not be drawn and it then looks like there's holes in the mesh. You could try to use MSAA (see the multisample example) but I'm not sure that will solve all issues. I think the good solution would be to adjust your triangle mesh.

So I started to change my depth buffer values from the default of 24, but with any other bit value the application crashes. For example with 32

What did you change exactly, this value? It works for me, so I need more information to be able to debug that. Also please make sure that your system support 32 bit depth buffers.