ImageEngine/cortex — pull request #9 by ldmoser (2013-06-19 17:45:34+00:00)
Title: Triangulated cached conversions for IECoreGL::MeshPrimitive

So this solution tries to solve two issues:

A) Our profiles indicate that there's lots of computation going on to the triangulation of meshes when rendering them with IECoreGL. We would like to take advantage of repetitive geometry and cache intermediate results (vertex triangulation, triangulated primVars, generation of normals) as opposed to only get the cache benefits for the entire Mesh (animated geo does not match and have to be reconverted entirely).

B) We envision developing ways to update the GL scene, using a scene edits mechanism. So ideally we would want to convert the IECore primitive to IECoreGL once, and then, replace the whole primitive OR update only a subset of the primitive variables (the ones that were affected), by providing the original non-triangulated prim vars.

I decided to focus the solution on Meshes, since that's the most common geometry in a SceneCache and leave other types of primitives unmodified for now, but the same ideas could be applied for PointsPrimitive and CurvesPrimitive.

Solution adopted: (1) expand the CachedConverter to accept custom converter objects (callable objects with a hash function). Then, (2) adding an additional constructor for IECoreGL::MeshPrimitive where it receives the original non-triangulated topology. And lastly, (3) create converters for each one of the basic operations that happens when converting a Mesh to IECoreGL (including triangulation).

I have some open questions for this approach:

- The concept of the CachedConverter seems pretty useful for other situations. Should we instead create a IECore::CachedResults where it always expect a callable object to be passed (with a hash function) that does the operation? So it could be used on general IECore Ops, such as the Normals, Triangulate, etc. I think the only reason why not, would be that the IECoreGL::CachedConverter cache must be cleared at safe threads.

- The triangulation algorithms are now in IECoreGL::MeshPrimitive. But I left some TODOs to consider unifying the code with the triangulate op in IECore.

- The computation of normals is currently done in the conversion. But the issue (B) would require it to be in the addPrimitiveVariable() every time that "P" is redefined.

- The computation of "st" is currently done in the ToGLMeshConverter (as before). I guess that we would want to support in Cortex V2f UV primVars and deprecate that code eventually.