dmurdoch / rgl

rgl is a 3D visualization system based on OpenGL. It provides a medium to high level interface for use in R, currently modelled on classic R graphics, with extensions to allow for interaction.
https://dmurdoch.github.io/rgl/
GNU General Public License v2.0
85 stars 20 forks source link

Record original face information in subdivision3d() and clipMesh3d(). #365

Closed dmurdoch closed 1 year ago

dmurdoch commented 1 year ago

This is a first draft of a solution to #364 . It needs more testing; I'm also not sure the names are right: recordOrig is an argument in subdivision3d() and clipMesh3d() and some functions they use such as as.tmesh3d(); if recordOrig = TRUE, then another element named "orig" is added to the resulting mesh. It encodes the relation between the new faces of the mesh and the old ones.

The encoding is very simple. Meshes may contain points, segments, triangles and quads. These are numbered in one sequence in that order. For example, if there are 8 triangles and 8 quads and none of the others, the triangles are considered to be numbered 1:8 and the quads 9:16.

If clipping results in triangles 1:4 being dropped, there will be 4 triangles and 8 quads, and orig (if requested) will hold 5:16, i.e. 5:8 for the triangles and 9:16 for the quads.

If the mesh is now converted to a pure triangular mesh using as.tmesh3d(..., recordOrig = TRUE), the quads will each become two triangles, and the orig member will become c(5:8, rep(9:16, each = 2)).

As long as the orig member is set to a vector of the appropriate length on input, it will be propagated through these operations into the output mesh. At least, if there are no bugs!

If anyone has any suggestions for better names than recordOrig and orig I'd like to hear them.