homotopy-io / homotopy-webclient

https://homotopy.io
27 stars 5 forks source link

Bezier surfaces for 3d geometries #68

Closed jamievicary closed 5 years ago

jamievicary commented 5 years ago

At the moment we render 3d models using Catmull-Clark subdivision. The results are really nice. However, it has the following drawbacks:

The first point here could cause a performance issue when we move to doing smooth surface animations, since the subdivision would have to be done for each frame; note that the frames of a smooth movie are not just obtained by linear interpolation, as that would cause velocities of parts of the diagram to change discontinuously. The second point here puts a limitation on the aesthetic appeal of the diagrams we can produce.

I propose that we move to Bezier surface animation. This uses 16 control points to define a smooth quadrilateral embedded in R^3. These have the following advantages:

This should be fast enough to allow real-time smooth 3d animations, with all the hard work shifted to the graphics card. All that the browser needs to do is re-compute the control point positions for each animation frame, which is fast, since this just involves performing some simple linear algebra at each point of the logical mesh.

Here is an example in-browser 3d Bezier surface, which can be smoothly animated by dragging the control points.

jamievicary commented 5 years ago

To be clear, this isn't a completely new idea; it's something Lukas and I discussed a while ago, and decided it wasn't right for this project at that time. I think that was the right decision at the time, but now it should be reconsidered.

jamievicary commented 5 years ago

On further investigation of that example, and other examples on the web, it seems I misunderstood; the graphics card is not rendering the ideal surface. Instead, the bezier surface patch is being interpolated with a grid, and rendered as a family of triangles. So now it's less clear that we would get the improvement in aesthetic appeal that I was hoping for. However, I still think there would be a speed benefit (although not as much as I had hoped), since recomputing the interpolation points for each animation frame should be much cheaper than doing re-doing the Catmull-Clark subdivision.

jamievicary commented 5 years ago

This approach was harder than anticipated, due to the difficulty of identifying the correct normals, and generating the appropriate surface. The current update to the 3d rendering code uses Loop subdivision.

The predicted difficulties with 3d animation are confirmed: while the individual 3d frames look good, linearly interpolating between adjacent 3d models looks terrible. So we maybe need some sort of 4d tetrahedral smoothing algorithm for that. It seems this is a hard problem. That can be discussed as another issue.