FBXExportProperty.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2025, assimp team
  5. All rights reserved.
  6. Redistribution and use of this software in source and binary forms,
  7. with or without modification, are permitted provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain the above
  10. copyright notice, this list of conditions and the
  11. following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the
  14. following disclaimer in the documentation and/or other
  15. materials provided with the distribution.
  16. * Neither the name of the assimp team, nor the names of its
  17. contributors may be used to endorse or promote products
  18. derived from this software without specific prior
  19. written permission of the assimp team.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ----------------------------------------------------------------------
  32. */
  33. /** @file FBXExportProperty.h
  34. * Declares the FBX::Property helper class for fbx export.
  35. */
  36. #ifndef AI_FBXEXPORTPROPERTY_H_INC
  37. #define AI_FBXEXPORTPROPERTY_H_INC
  38. #ifndef ASSIMP_BUILD_NO_FBX_EXPORTER
  39. #include <assimp/types.h> // aiMatrix4x4
  40. #include <assimp/StreamWriter.h> // StreamWriterLE
  41. #include <string>
  42. #include <vector>
  43. #include <ostream>
  44. #include <type_traits> // is_void
  45. namespace Assimp {
  46. namespace FBX {
  47. /** @brief FBX::Property
  48. *
  49. * Holds a value of any of FBX's recognized types,
  50. * each represented by a particular one-character code.
  51. * C : 1-byte uint8, usually 0x00 or 0x01 to represent boolean false and true
  52. * Y : 2-byte int16
  53. * I : 4-byte int32
  54. * F : 4-byte float
  55. * D : 8-byte double
  56. * L : 8-byte int64
  57. * i : array of int32
  58. * f : array of float
  59. * d : array of double
  60. * l : array of int64
  61. * b : array of 1-byte booleans (0x00 or 0x01)
  62. * S : string (array of 1-byte char)
  63. * R : raw data (array of bytes)
  64. */
  65. class FBXExportProperty {
  66. public:
  67. // constructors for basic types.
  68. // all explicit to avoid accidental typecasting
  69. explicit FBXExportProperty(bool v);
  70. // TODO: determine if there is actually a byte type,
  71. // or if this always means <bool>. 'C' seems to imply <char>,
  72. // so possibly the above was intended to represent both.
  73. explicit FBXExportProperty(int16_t v);
  74. explicit FBXExportProperty(int32_t v);
  75. explicit FBXExportProperty(float v);
  76. explicit FBXExportProperty(double v);
  77. explicit FBXExportProperty(int64_t v);
  78. // strings can either be stored as 'R' (raw) or 'S' (string) type
  79. explicit FBXExportProperty(const char* c, bool raw = false);
  80. explicit FBXExportProperty(const std::string& s, bool raw = false);
  81. explicit FBXExportProperty(const std::vector<uint8_t>& r);
  82. explicit FBXExportProperty(const std::vector<int32_t>& va);
  83. explicit FBXExportProperty(const std::vector<int64_t>& va);
  84. explicit FBXExportProperty(const std::vector<double>& va);
  85. explicit FBXExportProperty(const std::vector<float>& va);
  86. explicit FBXExportProperty(const aiMatrix4x4& vm);
  87. // this will catch any type not defined above,
  88. // so that we don't accidentally convert something we don't want.
  89. // for example (const char*) --> (bool)... seriously wtf C++
  90. template <class T>
  91. explicit FBXExportProperty(T v) : type('X') {
  92. static_assert(std::is_void<T>::value, "TRIED TO CREATE FBX PROPERTY WITH UNSUPPORTED TYPE, CHECK YOUR PROPERTY INSTANTIATION");
  93. } // note: no line wrap so it appears verbatim on the compiler error
  94. // the size of this property node in a binary file, in bytes
  95. size_t size();
  96. // write this property node as binary data to the given stream
  97. void DumpBinary(Assimp::StreamWriterLE& s);
  98. void DumpAscii(Assimp::StreamWriterLE& s, int indent = 0);
  99. void DumpAscii(std::ostream& s, int indent = 0);
  100. // note: make sure the ostream is in classic "C" locale
  101. private:
  102. char type;
  103. std::vector<uint8_t> data;
  104. };
  105. } // Namespace FBX
  106. } // Namespace Assimp
  107. #endif // ASSIMP_BUILD_NO_FBX_EXPORTER
  108. #endif // AI_FBXEXPORTPROPERTY_H_INC