doc.odin 5.2 KB

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