Babylon file creation from prims - HalcyonGrid/halcyon GitHub Wiki
The babylon file format groups objects together by parent ID. This is usable for multi-prim objects. However, we still have to deal with viewer faces that can have different materials assigned.
Looking at the file structure, exporting for every individual prim is relatively straightforward: For every prim:
- Collect all vertices for all faces
- Collect all indices for all faces
- Collect all normals for all faces
- Collect all UVs for all faces
Then for each prim:
- Create a new entry in meshes
- Give each prim mesh a unique ID
- Calculate the djb2 hash of the shape
- Calculate the djb2 hash of the materials
- Create the ID from those
- Export all vertices (as "positions")
- Export all normals (as "normals")
- Export all UVs (as "uvs")
- Export all indices (as "indices")
- Export all materials (as "materials")
For each face:
- Create a new multimaterial
- Add the material for each face to the multimaterial
- Create a new submesh
- Add the face vertices/indices to the submesh