cr88192

BGBTech3 Engine, updated mesh format 1

Apr 29th, 2025
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.99 KB | Software | 0 0
  1. Mesh Model Format (Possible, for BGBTech3 Engine):
  2. * May contain basic non-animated meshes.
  3. ** May also allow for animated meshes.
  4. ** Single bone only for now.
  5. * Format will be image-like.
  6. ** Will be defined in terms of offsets relative to image base.
  7. ** Structure arrays will have nominal 64-bit alignment.
  8.  
  9. Mesh Vertex (64-bit):
  10. * (63:56): Bone ID (if animated, 0=Base)
  11. * (55:54): Exponent ST
  12. * (53:43): Frac T
  13. * (42:32): Frac S
  14. * (31:27): Exponent XYZ
  15. * (26:18): Frac Z
  16. * (17: 9): Frac Y
  17. * ( 8: 0): Frac X
  18.  
  19. Mesh Vertex (96-bit):
  20. * First Word (64-bit)
  21. ** (63:56): 0xF0 .. FB
  22. ** (55:54): Exponent ST
  23. ** (53:43): Frac T
  24. ** (42:32): Frac S
  25. ** (31:27): Exponent XYZ
  26. ** (26:18): Frac Z
  27. ** (17: 9): Frac Y
  28. ** ( 8: 0): Frac X
  29. * Second Word (32-bit)
  30. ** (31:24): Color/Shade (F8/F9), Bone (FA/FB)
  31. ** (23:16): Normal Z (F8A)
  32. ** (15: 8): Normal Y (F8A)
  33. ** ( 7: 0): Normal X (F8A)
  34.  
  35. Mesh Vertex (128-bit):
  36. * First Word
  37. ** (63:56): 0xFD
  38. ** (55:48): Color/Shade
  39. ** (47:32): Org Z (Binary16)
  40. ** (31:16): Org Y (Binary16)
  41. ** (15: 0): Org X (Binary16)
  42. * Second Word
  43. ** (63:56): Bone ID (if animated, 0=Base)
  44. ** (55:48): Normal Z (F8A)
  45. ** (47:40): Normal Y (F8A)
  46. ** (39:32): Normal X (F8A)
  47. ** (31:28): Exponent ST
  48. ** (27:14): Frac T (Q2.12, -2.0 to 1.999)
  49. ** (13: 0): Frac S (Q2.12, -2.0 to 1.999)
  50.  
  51. S/T coordinates in the 64 and 96 bit formats will be mapped roughly -0.500 to 1.499, with a fixed point accuracy of 1/1024 over the skin texture. Coordinates outside the range of 0.0 to 1.0 are primarily intended to deal with seams.
  52.  
  53. In the F8 and FA formats, 12-bit S/T coords will be used with an accuracy of 1/2048.
  54.  
  55. If F9 or FB tags are used, the S/T coords will be adjusted to use an ST exponent, as in the 64-bit format.
  56. * 0: -0.5 to 1.499
  57. * 1: -2.0 to 5.996
  58. * 2: -8.0 to 23.984
  59. * 3: -32.0 to 95.936
  60.  
  61. For the 128 bit vertices, the ST exponent will be a power of 2 scale.
  62.  
  63.  
  64. Vertex coordinates will be stored relative to the local coordinate space of the bone in question. In the 64-bit vertex format, no normal is encoded. Cheap trick would be to assume that the bone-relative coordinate also implicitly serves as the normal vector.
  65.  
  66.  
  67.  
  68. Mesh Triangle (32 bit format):
  69. * (31:22): V2
  70. * (21:12): V1
  71. * (11: 2): V0
  72. * ( 1: 0): Tag (00)
  73.  
  74. Mesh Quad (32 bit format):
  75. * (31:30): Tag2 (00)
  76. * (29:23): V3
  77. * (22:16): V2
  78. * (15: 9): V1
  79. * ( 8: 2): V0
  80. * ( 1: 0): Tag (01)
  81.  
  82. Mesh Triangle (64 bit format):
  83. * (63:62): Tag2 (00)
  84. * (61:42): V2
  85. * (41:22): V1
  86. * (21: 2): V0
  87. * ( 1: 0): Tag (10)
  88.  
  89. Mesh Quad (64 bit format):
  90. * (63:62): Tag2 (00)
  91. * (61:47): V3
  92. * (46:32): V2
  93. * (31:17): V1
  94. * (16: 2): V0
  95. * ( 1: 0): Tag (11)
  96.  
  97. The 64-bit format will be assumed if more than 1024 vertices are used.
  98. Note that if fewer than 1024 vertices are used, each quad will be counted as 2 triangles, but if more are used, a quad will be a single triangle (or the triangle seen as a degenerate quad).
  99.  
  100.  
  101. Bone Tranform
  102. * (63:56): Rot R (F8A)
  103. * (55:48): Rot K (F8A)
  104. * (47:40): Rot J (F8A)
  105. * (39:32): Rot I (F8A)
  106. * (31:27): Org Exponent
  107. * (26:18): Frac Org Z
  108. * (17: 9): Frac Org Y
  109. * ( 8: 0): Frac Org X
  110.  
  111.  
  112. F8A: S.E3.F4, Unit Range
  113. * For I/J/K/R, these will be interpreted as a unit quaternion.
  114. ** After unpacking, the quaternion is to be normalized.
  115. * Maximum value for F8A will be 1.9375, to allow 1.0 to be encoded.
  116.  
  117. Anim Rotation (32 bit)
  118. * (31:24): Rot R (F8A)
  119. * (23:16): Rot K (F8A)
  120. * (15: 8): Rot J (F8A)
  121. * ( 7: 0): Rot I (F8A)
  122.  
  123. Anim Translation or Scale (32 bit)
  124. * (31:27): Exponent
  125. * (26:18): Frac Z
  126. * (17: 9): Frac Y
  127. * ( 8: 0): Frac X
  128.  
  129. The fraction will be a signed-extended non-normalized value which will be scaled by the exponent.
  130.  
  131.  
  132. Header {
  133. u32 magic1; //00, 'BMD1'
  134. u32 resv1; //04, MBZ
  135. u32 resv2; //08, MBZ
  136. u32 resv3; //0C, MBZ
  137. u32 ofs_meshes; //10, Mesh List
  138. u32 sz_meshes; //14, Size of Mesh List (bytes)
  139. u32 ofs_lods; //18, LODs List
  140. u32 sz_lods; //1C, Size of LODs List (bytes)
  141. u32 ofs_bones; //20, Bone List, MBZ if static
  142. u32 sz_bones; //24, Size of Bones (bytes), MBZ if static
  143. u32 ofs_anims; //28, Anim List, MBZ if static
  144. u32 sz_anims; //2C, Size of Anim List, MBZ if static
  145. }
  146.  
  147. MeshDef {
  148. u32 ofs_vtx; //00, offset of vertices list in image
  149. u32 ofs_tris; //04, offset of triangles list
  150. u32 ofs_mat; //08, material name string
  151. u16 n_vtx; //0C, number of vertices (0..1024)
  152. u16 n_tris; //0E, number of triangles
  153. u32 sz_vtx; //10, size of vertices list
  154. u32 sz_tris; //14, size of triangles list
  155. u32 flags; //18, mesh control flags
  156. u32 resv3; //1C, MBZ
  157. }
  158.  
  159. LodDef {
  160. byte id_mesh; //00, Index of first mesh at LOD level
  161. byte n_mesh; //01, Number of meshes in LOD level
  162. byte ld_sc; //02, Nominal scale (F8A)
  163. byte resv1; //03, MBZ
  164. }
  165.  
  166. BoneDef {
  167. u64 xform; //00, base transform (MBZ for Bone 0)
  168. u32 ofs_name; //08, bone name string (Bones 1+)
  169. byte id_parent; //0C, parent bone (MBZ for 0, 0xFF for Pseudo-Bone)
  170. byte id_solid; //0D, mesh to use for solid def for bone.
  171. byte resv1; //0E, MBZ
  172. byte resv2; //0F, MBZ
  173. }
  174.  
  175. AnimDef {
  176. u32 ofs_name; //00, Offset of animation name
  177. byte n_framees; //04, number of frames in this animation loop
  178. byte fl_hz; //05, (7)=No Loop, (6:0): Anim Hz (in units of 0.25 Hz)
  179. byte resv1; //06, MBZ
  180. byte resv2; //07, MBZ
  181. u32 ofs_frames; //08, Offset of frames list
  182. u32 sz_frames; //0C, Size of frames list.
  183. }
  184.  
  185. If the mesh ofs_mat is 0 (Null String), this mesh nay not be drawn. However, non-drawn meshes may be used for bone solids.
  186.  
  187. The model format will not define materials internally. Instead, these will be the responsibility of the 3D engine. In the simple case though, the material name will be understood as a reasource/relative path to the texture, omitting the file extension. However, the material could instead specify a shader, potentially with additional image maps, rather than just a simple texture image.
  188.  
  189.  
  190. Mesh control flags:
  191. * (1:0): Vertex Subtype
  192. ** 00=64-bit only
  193. ** 01=64/96/128 bit (variable length)
  194. ** 10=128-bit only
  195. ** 11=96-bit only
  196. * (3:2): Triangles Type
  197. ** 00=32-bit, triangles only
  198. ** 01=32/64 bit (variable length), triangles or quads
  199. ** 10=64-bit, triangles only
  200. ** 11=64-bit, triangles or quads
  201. *** Provision for quads, count triangles as degenerate quads.
  202.  
  203. Note that the control flags are primarily intended as a loader hint. If a fixed-length or triangles only encoding is used, only these types are allowed. A reasonable default would be to assume variable length and either triangles or quads as primitives. An encoder may specify triangles only if it is known that the mesh only contains triangles.
  204.  
  205.  
  206. Each LOD will be defined as a range of meshes. Only drawable meshes will be present in a LOD. Nominal scale algo will be defined as 1.0/(dist+1.0) with the distance defined in meters from the viewer.
  207.  
  208. Meshes used for bone solids need not be renderable, but may be renderable. They will be required to be in BREP form (fully enclosed volume, may be non-convex but may not self-intersect). The entire mesh is to be mapped to a single bone (equal to the bone for which the solid is being defined, or to bone 0). The coordinate space will be understood as relavite to the bone they are applied to (regardless of the bone specified for the vertex).
  209.  
  210. Note that if vertices are duplicated for sake of texture seam handling, even if at the same location in 3D space, the mesh will no longer be in BREP form.
  211.  
  212. Renderable meshes with more than 1024 vertices may be subdivided into meshes with fewer than 1024 vertices, which are also by definition not in BREP form. However, this format isn't really indended to be used for high triangle count models.
  213.  
  214. Possible, Pseudo-Bones:
  215. * Will be special bones.
  216. * xform will be understood as 4 bone IDs, and 4 F8A weights.
  217.  
  218. Pseudo bones will follow after any normal bones and their transforms will not be specified in animation frames. Their position in a given animation frame will be calculated based on the weights (after any interpolation for the normal bones). As for mesh vertex transform, they are handled the same as normal bones.
  219.  
  220.  
  221. Animation frames will nominally represent n_frames*n_bones sets of transformations.
  222. These animations will be organized per-bone, and will span the full list of frames for this bone.
  223.  
  224. However, animation frames will be stored in a compacted form, with a tag byte:
  225. * (7): Rotation Present
  226. * (6): Translation Present
  227. * (5): Scale Present
  228. * (4:0): Number of preceding frames to skip during this bone.
  229.  
  230. A tag of 00 will signal the end of the current bone.
  231. * Each tag will be followed by the rotation, translation, and scale, if present.
  232.  
  233. If a value is skipped in the current frame, its value will be interpolated.
  234. * If absent in all frames, it will assume a default (identity) value.
  235.  
  236. The defined interpolation will be to linearly interpolate values, with rotations being renormalized after interpolation. The combination of rotation, translation, and scale, may be used to construct a transformation matrix that may be applied when calculating final mesh vertex positions for a given frame.
  237.  
  238.  
Advertisement
Add Comment
Please, Sign In to add comment