setzer22 / blackjack

A procedural, node-based modelling tool, made in rust 🦀
Mozilla Public License 2.0
1.42k stars 64 forks source link

Filled circle and Catenary primitives #64

Closed HenryWConklin closed 2 years ago

HenryWConklin commented 2 years ago

For #60

HenryWConklin commented 2 years ago

Screenshot from 2022-11-10 07-30-54 Screenshot from 2022-11-10 07-35-02

HenryWConklin commented 2 years ago

Screenshot from 2022-11-11 08-47-23

HenryWConklin commented 2 years ago

Had some git issues, but I think this PR is good to go now.

Also, I'll comment that there's a mismatch in the defaults for circle and extrude along curve. The circle needs to be rotated first and the faces flipped on the extrude node to get what you expect. May be a larger issue so I didn't want to mess with it too much.

setzer22 commented 2 years ago

Hmm :thinking: I just tested this locally and while it works well, there's an annoying glitch when extruding: image

The normals look right (not shifted in the Z direction), so this could be a bug in "Extrude Along Curve". Need to investigate further, but unless you have an idea of what's going on there, I think we can merge this PR and convert this into an issue so we can tackle it later. The catenary node is super useful and I don't want to drag this more than necessary :smile:

Also, I'll comment that there's a mismatch in the defaults for circle and extrude along curve. The circle needs to be rotated first and the faces flipped on the extrude node to get what you expect. May be a larger issue so I didn't want to mess with it too much.

Yes, I'm aware of this. I wonder what the most user-friendly solution would be. The problem seems to be the "Extrude Along Curve" node assuming the cross section is looking in the X direction, while most primitives like Circle or Quad are constructed looking up. Maybe I should just add an extra rotation matrix there to correct for this :thinking:.

setzer22 commented 2 years ago

After further exploration, I think there's something fishy with those normals :thinking:. See how there's this unwanted rotation at the start that moves forward as I extend the curve?

https://user-images.githubusercontent.com/7241990/201473309-58d51fc2-41c1-44fe-888e-baaec3d5dacb.mp4

This is the code that extrude along curve uses to rotate the cross section at edit_ops:1572 (that dbg! was added by me during debugging):

            let normal = normal_ch[v];
            let tangent = tangent_ch[v];
            dbg!(normal.dot(tangent));
            let cotangent = normal.cross(tangent);
            let (_, rotate, _) = glam::Affine3A::from_cols(
                cotangent.into(),
                normal.into(),
                tangent.into(),
                glam::Vec3A::ZERO,
            )

When using a regular Line, the dot is zero as expected (normal and tangent should be orthogonal). But with the catenary, I'm getting different non-zero values depending on the endpoints. Looks like the computation for the normals might be a bit off?

Now that we have gizmos, I'm going to work on some API that lets us do some debug drawing to better see what's going on, I've been meaning to do that for a while.

HenryWConklin commented 2 years ago

Yeah, that looks like the tangent is wrong, I was getting that earlier but thought it was better.

Fixed with some simpler code that I should have tried first. Also added a fix for when the endpoints line up vertically and the math stops working.

https://user-images.githubusercontent.com/3664988/201475860-9b59ed49-b927-4429-912c-38fafe5ceb6e.mp4

Screenshot from 2022-11-12 05-12-55

Let me know if you spot anything else weird.

setzer22 commented 2 years ago

Amazing! Thanks for the hard work :smile: