KittyCAD / twenty-twenty

Visual regression testing of H264 frames and images.
https://docs.rs/twenty-twenty
MIT License
6 stars 0 forks source link

Build twenty-twenty for GLTF #30

Open adamchalmers opened 2 months ago

adamchalmers commented 2 months ago

We use the 20/20 crate to do visual regression testing on our frontend, our CLI, and our backend. 20/20 works by comparing two PNGs or two h264 frames, and checking their visual similarity is above some configurable threshold (e.g. 99% similar).

This crate works very well, especially because when it detects a change, it's easy for a programmer to visually compare the images and see what's gone wrong. But it has some problems:

We have many concrete examples of the former (everyone has a story about "oh the engine changed rendering slightly, someone needs to update all the frontend snapshots"). An example of the latter just happened, where @benjamaan476 wants to test an engine change which adds internal edges to a model. Because the edges are internal, they can't be seen by the camera and 20/20 is useless. But the edges matter for future applications, and their existence should be tested.

Proposed solution 20/20 checks our model geometry, rendered visually. I think we need a second library for checking model geometry, rendered textually. We could export the model in some text format (e.g. our GLTF) and check it against the expected GLTF.

This approach has a few problems:

We could call the library "xray_specs" because they let you see internal geometry that not even 20/20 vision can :)

lf94 commented 2 months ago

100%. I've always asserted that any visual check of our models should be of the actual rendered geometry due to various factors. I would never compare the textual representations as there are unimaginable ways to represent the same model.

Unfortunately I don't believe this is a task to focus on at the moment. We have higher priority items like making modeling-app able to pump KCL to the backend even faster than we do now.

A short term solution would be to use better computer vision techniques, such as not basing our comparisons on raw pixel colors, but instead their "color distance" https://en.wikipedia.org/wiki/Color_difference (preferably something from the CIE color space), and downscaling to reduce comparing minute details (which is what neural networks do). We can get "half way there" for the internal geometry models with transparency.

adamchalmers commented 2 months ago

Yeah, not saying we need to do it now, clearly 20/20 works well enough for most cases. But I wanted to write it down for the future. I really like the idea of making 2020 smarter with CV! And having an option to set models to transparent, so you can see the internal edges, would be really helpful too.