ccMaterialSet.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #pragma once
  2. //##########################################################################
  3. //# #
  4. //# CLOUDCOMPARE #
  5. //# #
  6. //# This program is free software; you can redistribute it and/or modify #
  7. //# it under the terms of the GNU General Public License as published by #
  8. //# the Free Software Foundation; version 2 or later of the License. #
  9. //# #
  10. //# This program is distributed in the hope that it will be useful, #
  11. //# but WITHOUT ANY WARRANTY; without even the implied warranty of #
  12. //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  13. //# GNU General Public License for more details. #
  14. //# #
  15. //# COPYRIGHT: EDF R&D / TELECOM ParisTech (ENST-TSI) #
  16. //# #
  17. //##########################################################################
  18. //Local
  19. #include "ccHObject.h"
  20. #include "CCShareable.h"
  21. class ccGenericGLDisplay;
  22. //! Mesh (triangle) material
  23. class QCC_DB_LIB_API ccMaterialSet : public std::vector<ccMaterial::CShared>, public CCShareable, public ccHObject
  24. {
  25. public:
  26. //! Default constructor
  27. ccMaterialSet(const QString& name = QString());
  28. //inherited from ccHObject
  29. CC_CLASS_ENUM getClassID() const override { return CC_TYPES::MATERIAL_SET; }
  30. bool isShareable() const override { return true; }
  31. //! Finds material by name
  32. /** \return material index or -1 if not found
  33. **/
  34. int findMaterialByName(const QString& mtlName);
  35. //! Finds material by unique identifier
  36. /** \return material index or -1 if not found
  37. **/
  38. int findMaterialByUniqueID(const QString& uniqueID);
  39. //! Adds a material
  40. /** Ensures unicity of material names.
  41. \param mat material
  42. \param allowDuplicateNames whether to allow duplicate names for materials or not (in which case the returned index is the one of the material with the same name)
  43. \return material index
  44. **/
  45. int addMaterial(ccMaterial::CShared mat, bool allowDuplicateNames = false);
  46. //! MTL (material) file parser
  47. /** Inspired from KIXOR.NET "objloader" (http://www.kixor.net/dev/objloader/)
  48. **/
  49. static bool ParseMTL(const QString& path, const QString& filename, ccMaterialSet& materials, QStringList& errors);
  50. //! Saves to an MTL file (+ associated texture images)
  51. bool saveAsMTL(const QString& path, const QString& baseFilename, QStringList& errors) const;
  52. //! Clones materials set
  53. ccMaterialSet* clone() const;
  54. //! Appends materials from another set
  55. bool append(const ccMaterialSet& source);
  56. //inherited from ccSerializableObject
  57. bool isSerializable() const override { return true; }
  58. protected:
  59. //inherited from ccHObject
  60. bool toFile_MeOnly(QFile& out, short dataVersion) const override;
  61. bool fromFile_MeOnly(QFile& in, short dataVersion, int flags, LoadedIDMap& oldToNewIDMap) override;
  62. short minimumFileVersion_MeOnly() const override;
  63. //! Default destructor (protected: use 'release' instead)
  64. ~ccMaterialSet() override = default;
  65. };