I am working on an export / import addon for a custom model file format which stores its geometry in the so-called "render batches", the structures aimed at optimizing geometry for effecient live OpenGL rendering. I am trying to convert "raw" geometry data from Blender to that system.
If you don't want to read the detailed explanation, skip to 'individual steps I need to do' part.
In short, each render batch is a sequence of faces (only vert and face index information is required) which are:
1) A loose separate part of geometry (island).
2) Share one material.
3) Represent the same batch type (3 batch types A, B and C are used for internal rendering purposes, I store them as vertex groups in Blender. C = no vertex group, B = vertex group Batch B (if not in A), A = vertex group Batch A.
UV map is handled per-vertex because there are essentially no loops.
My current workflow is using tons of operators and is roughly this:
1) Create a temporary object in python 2) Triangulate 3) Cut mesh by materials using an operator. 4) Cut mesh by UV islands (Seams From Islands (+ mark sharp) -> Edge Split) 5) Cut mesh by vertex groups.
There are two issues resulting from the fact that mesh is actually being cut:
Normals become sharp, where they are supposed to be smooth due to the cutting seam.
I am treating a piece of geometry with one material as one single batch. So, distant islands using the same material are becoming one batch, which kills the benefits of render batch optimization for rendering.
a) Is there a way to either separate the mesh correctly based on the rules I have specified above, and somehow preserve the original normals on export? b) Or, alternatively, is there a way to non-intrusively create a list of these batches, again based on the said rules, without altering the mesh, and thus preserving the correct normals?
I know that the explanation may be ambiguous, so I created a visualization for the render batch system:
(1) Pieces of geometry are sharing the same material, but are not connected to each other. Should result into multiple batches for each island.
(2) Piece of geometry is sharing the same material (there is a little mistake on the picture. Mat2_Batch1 on the left instead), but is separated by different batch type vertex groups. Thus, 2 separate batches.
(3) Piece of geometry is sharing the same same material, geometry is connected, no batch vertex groups (assumed it is type C). Thus, 1 batch.
Individual steps I need to do
1) Get faces sharing same material (easy, done)
2) From the result of a previous step, find groups of faces separated by UV islands
3) Then same with different vertex group (we assume face is in vertex group if all 3 verts of it are in.)
4) Find individual (loose) groups of faces in the resulted sorted chunks of geometry.
Any help would be greatly appreciated, I am completely stuck on this.