You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
shear_x(), shear_y() and apply_matrix() draw the wrong shape #269
Shapes drawn under a shear come out as a rotated rectangle instead of a parallelogram. The same thing happens when a non-uniform scale() is followed by rotate().
A parallelogram leaning to the right, same as in Processing.
Actual behavior
A rotated rectangle.
In the screenshot, blue is what libprocessing draws. Green is the correct shape. Red dots are what screen_x() / screen_y() return for the corners. They match the green shape, not the drawn one. The last panel (rotate, then scale) is drawn correctly.
It happens in 3D too. Here is scale(1.6, 0.6, 1) followed by rotate_y() on a box:
Cause
Before each draw, the current matrix is turned into a Bevy Transform using to_scale_rotation_translation(). This happens in spawn_mesh in render/mod.rs and in TransformStack::to_bevy_transform. A Transform can only hold translation, rotation and scale. A shear doesn't fit, so it gets lost.
compute_global_transform in gltf.rs does the same thing, so glTF scenes with a non-uniformly scaled parent are probably affected too.
Proposed fix
When the matrix fits in a Transform keep the current path. When it doesn't, apply the matrix to the mesh vertices and normals and use a translation-only Transform. Existing sketches would render exactly the same. I would add unit tests and a visual test case.
I would like to work on this if the approach sounds good.
Activity