doc.odin 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. Eskil Steenberg's `HxA` 3D asset interchange format.
  3. HxA is a interchangeable graphics asset format.
  4. Designed by Eskil Steenberg. @quelsolaar / eskil 'at' obsession 'dot' se / www.quelsolaar.com
  5. Author of this Odin package: Ginger Bill
  6. Following comment is copied from the original C-implementation
  7. ---------
  8. - Does the world need another Graphics file format?
  9. Unfortunately, Yes. All existing formats are either too large and complicated to be implemented from
  10. scratch, or don't have some basic features needed in modern computer graphics.
  11. - Who is this format for?
  12. For people who want a capable open Graphics format that can be implemented from scratch in
  13. a few hours. It is ideal for graphics researchers, game developers or other people who
  14. wants to build custom graphics pipelines. Given how easy it is to parse and write, it
  15. should be easy to write utilities that process assets to preform tasks like: generating
  16. normals, light-maps, tangent spaces, Error detection, GPU optimization, LOD generation,
  17. and UV mapping.
  18. - Why store images in the format when there are so many good image formats already?
  19. Yes there are, but only for 2D RGB/RGBA images. A lot of computer graphics rendering rely
  20. on 1D, 3D, cube, multilayer, multi channel, floating point bitmap buffers. There almost no
  21. formats for this kind of data. Also 3D files that reference separate image files rely on
  22. file paths, and this often creates issues when the assets are moved. By including the
  23. texture data in the files directly the assets become self contained.
  24. - Why doesn't the format support <insert whatever>?
  25. Because the entire point is to make a format that can be implemented. Features like NURBSs,
  26. Construction history, or BSP trees would make the format too large to serve its purpose.
  27. The facilities of the formats to store meta data should make the format flexible enough
  28. for most uses. Adding HxA support should be something anyone can do in a days work.
  29. Structure:
  30. ----------
  31. HxA is designed to be extremely simple to parse, and is therefore based around conventions. It has
  32. a few basic structures, and depending on how they are used they mean different things. This means
  33. that you can implement a tool that loads the entire file, modifies the parts it cares about and
  34. leaves the rest intact. It is also possible to write a tool that makes all data in the file
  35. editable without the need to understand its use. It is also possible for anyone to use the format
  36. to store data axillary data. Anyone who wants to store data not covered by a convention can submit
  37. a convention to extend the format. There should never be a convention for storing the same data in
  38. two differed ways.
  39. The data is story in a number of nodes that are stored in an array. Each node stores an array of
  40. meta data. Meta data can describe anything you want, and a lot of conventions will use meta data
  41. to store additional information, for things like transforms, lights, shaders and animation.
  42. Data for Vertices, Corners, Faces, and Pixels are stored in named layer stacks. Each stack consists
  43. of a number of named layers. All layers in the stack have the same number of elements. Each layer
  44. describes one property of the primitive. Each layer can have multiple channels and each layer can
  45. store data of a different type.
  46. HaX stores 3 kinds of nodes
  47. - Pixel data.
  48. - Polygon geometry data.
  49. - Meta data only.
  50. Pixel Nodes stores pixels in a layer stack. A layer may store things like Albedo, Roughness,
  51. Reflectance, Light maps, Masks, Normal maps, and Displacement. Layers use the channels of the
  52. layers to store things like color.
  53. The length of the layer stack is determined by the type and dimensions stored in the Geometry data
  54. is stored in 3 separate layer stacks for: vertex data, corner data and face data. The
  55. vertex data stores things like verities, blend shapes, weight maps, and vertex colors. The first
  56. layer in a vertex stack has to be a 3 channel layer named "position" describing the base position
  57. of the vertices. The corner stack describes data per corner or edge of the polygons. It can be used
  58. for things like UV, normals, and adjacency. The first layer in a corner stack has to be a 1 channel
  59. integer layer named "index" describing the vertices used to form polygons. The last value in each
  60. polygon has a negative - 1 index to indicate the end of the polygon.
  61. For Example:
  62. A quad and a tri with the vertex index:
  63. [0, 1, 2, 3] [1, 4, 2]
  64. is stored:
  65. [0, 1, 2, -4, 1, 4, -3]
  66. The face stack stores values per face. the length of the face stack has to match the number of
  67. negative values in the index layer in the corner stack. The face stack can be used to store things
  68. like material index.
  69. Storage:
  70. -------
  71. All data is stored in little endian byte order with no padding. The layout mirrors the structs
  72. defined below with a few exceptions. All names are stored as a 8-bit unsigned integer indicating
  73. the length of the name followed by that many characters. Termination is not stored in the file.
  74. Text strings stored in meta data are stored the same way as names, but instead of a 8-bit unsigned
  75. integer a 32-bit unsigned integer is used.
  76. */
  77. package encoding_hxa