M3DWrapper.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #pragma once
  2. /*
  3. Open Asset Import Library (assimp)
  4. ----------------------------------------------------------------------
  5. Copyright (c) 2006-2020, assimp team
  6. Copyright (c) 2019 bzt
  7. All rights reserved.
  8. Redistribution and use of this software in source and binary forms,
  9. with or without modification, are permitted provided that the
  10. following conditions are met:
  11. * Redistributions of source code must retain the above
  12. copyright notice, this list of conditions and the
  13. following disclaimer.
  14. * Redistributions in binary form must reproduce the above
  15. copyright notice, this list of conditions and the
  16. following disclaimer in the documentation and/or other
  17. materials provided with the distribution.
  18. * Neither the name of the assimp team, nor the names of its
  19. contributors may be used to endorse or promote products
  20. derived from this software without specific prior
  21. written permission of the assimp team.
  22. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  25. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  26. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  27. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  28. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  29. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  30. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  32. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. ----------------------------------------------------------------------
  34. */
  35. /** @file M3DWrapper.h
  36. * @brief Declares a class to wrap the C m3d SDK
  37. */
  38. #ifndef AI_M3DWRAPPER_H_INC
  39. #define AI_M3DWRAPPER_H_INC
  40. #if !(ASSIMP_BUILD_NO_EXPORT || ASSIMP_BUILD_NO_M3D_EXPORTER) || !ASSIMP_BUILD_NO_M3D_IMPORTER
  41. #include <memory>
  42. #include <vector>
  43. #include <string>
  44. // Assimp specific M3D configuration. Comment out these defines to remove functionality
  45. //#define ASSIMP_USE_M3D_READFILECB
  46. //#define M3D_ASCII
  47. #include "m3d.h"
  48. namespace Assimp {
  49. class IOSystem;
  50. class M3DWrapper {
  51. m3d_t *m3d_ = nullptr;
  52. unsigned char *saved_output_ = nullptr;
  53. public:
  54. // Construct an empty M3D model
  55. explicit M3DWrapper();
  56. // Construct an M3D model from provided buffer
  57. // NOTE: The m3d.h SDK function does not mark the data as const. Have assumed it does not write.
  58. // BUG: SECURITY: The m3d.h SDK cannot be informed of the buffer size. BUFFER OVERFLOW IS CERTAIN
  59. explicit M3DWrapper(IOSystem *pIOHandler, const std::vector<unsigned char> &buffer);
  60. ~M3DWrapper();
  61. void reset();
  62. // Name
  63. inline std::string Name() const {
  64. if (m3d_) return std::string(m3d_->name);
  65. return std::string();
  66. }
  67. // Execute a save
  68. unsigned char *Save(int quality, int flags, unsigned int &size);
  69. void ClearSave();
  70. inline explicit operator bool() const { return m3d_ != nullptr; }
  71. // Allow direct access to M3D API
  72. inline m3d_t *operator->() const { return m3d_; }
  73. inline m3d_t *M3D() const { return m3d_; }
  74. };
  75. } // namespace Assimp
  76. #endif
  77. #endif // AI_M3DWRAPPER_H_INC