/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a license // agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// #ifndef NWMATERIALIMPORT_H #define NWMATERIALIMPORT_H #include "TD_PackPush.h" #define STL_USING_MAP #define STL_USING_FUNCTIONAL #include "OdaSTL.h" #include //nw #include "NwObject.h" #include "NwModelUnits.h" //tv #include "TvDatabase.h" //tv class OdTvMaterialId; class OdTvColorDef; //nw class OdNwMaterialAttribute; class OdNwGraphicMaterialAttribute; class OdNwTexture; namespace NwMaterialImport { //class for key in unordered map between simple material traits(diffuse,ambient and etc) and already created tvmaterial struct Nw2TvSimpleMatCache { explicit Nw2TvSimpleMatCache(const OdNwObjectId& nwMaterialId); explicit Nw2TvSimpleMatCache(const OdNwMaterialAttribute* pMaterialAttr); ~Nw2TvSimpleMatCache() = default; //for correct work with unorored map as key there are needed: //1 - equal operator //2 - template specialization of std::hash bool operator==(const Nw2TvSimpleMatCache& other) const; OdUInt32 getAmbient() const; OdUInt32 getDiffuse() const; OdUInt32 getEmissive() const; OdUInt32 getSpecular() const; float getShininess() const; float getTransparency() const; private: bool m_bIsAttr; union NwMaterialWrapper { OdNwObjectId m_nwMaterialId; const OdNwMaterialAttribute* m_pMaterialAttr; explicit NwMaterialWrapper(const OdNwObjectId& nwMaterialId) : m_nwMaterialId(nwMaterialId) { } NwMaterialWrapper& operator=(const OdNwObjectId& nwMaterialId) { new(&m_nwMaterialId) OdNwObjectId(nwMaterialId); return *this; } explicit NwMaterialWrapper(const OdNwMaterialAttribute* pMaterialAttr) : m_pMaterialAttr(pMaterialAttr) { } NwMaterialWrapper& operator=(const OdNwMaterialAttribute* pMaterialAttr) { m_pMaterialAttr = pMaterialAttr; return *this; } ~NwMaterialWrapper() {} } m_material; }; //class for key in unordered map between pair of material attributes and already created tvmaterial struct Nw2TvMatAttributes { Nw2TvMatAttributes(const OdNwMaterialAttribute* pNwMatAttr, const OdNwGraphicMaterialAttribute* pNwGrMatAttr); ~Nw2TvMatAttributes() = default; //for correct work with unorored map as key there are needed: //1 - equal operator //2 - template specialization of std::hash bool operator==(const Nw2TvMatAttributes& other) const; inline const OdNwMaterialAttribute* getNwMatAttr() const { return m_pNwMatAttr; } inline const OdNwGraphicMaterialAttribute* getNwGrMatAttr() const { return m_pNwGrMatAttr; } private: const OdNwMaterialAttribute* m_pNwMatAttr; const OdNwGraphicMaterialAttribute* m_pNwGrMatAttr; }; } namespace std { //template specialization of std::hash for Nw2TvSimpleMatCache template <> struct hash { size_t operator()(const NwMaterialImport::Nw2TvSimpleMatCache& p) const { size_t h1 = hash()(p.getAmbient()); size_t h2 = hash()(p.getDiffuse()); size_t h3 = hash()(p.getSpecular()); size_t h4 = hash()(p.getEmissive()); size_t h5 = hash()(p.getShininess()); size_t h6 = hash()(p.getTransparency()); return h1 ^ (h2 << 1) ^ (h3 << 2) ^ (h4 << 3) ^ (h5 << 4) ^ (h6 << 5); // Combine the hash values } }; //template specialization of std::hash for Nw2TvMatAttributes template <> struct hash { size_t operator()(const NwMaterialImport::Nw2TvMatAttributes& p) const { size_t h1 = hash()(p.getNwMatAttr()); size_t h2 = hash()(p.getNwGrMatAttr()); return h1 ^ (h2 << 1); // Combine the hash values } }; } namespace NwMaterialImport { bool compareMaterial(const OdNwObjectId& nwShadedMtlId, const OdNwMaterialAttribute* pNwMatAttr); class OdNw2TvMaterialImport { public: OdNw2TvMaterialImport(const OdTvDatabaseId& tvDatabaseId, const OdNwObjectId& nwMatElId, NwModelUnits::Enum nwCurPartUnits, const OdTvColorDef& tvDefClr, const OdString& sReflEnv, std::function getTempFilePath); ~OdNw2TvMaterialImport() = default; public: inline const OdTvColorDef& getDefaultEntClr() const { return m_defaultEntColor; } bool checkAdvancedMaterialGUID(const OdNwGraphicMaterialAttribute* pGrMat); OdTvMaterialId getMaterial(const OdNwObjectId& nwShadedMtlId, OdTvColorDef& entClr); OdTvMaterialId getMaterial(const OdNwObjectId& nwRealisticMtlId, const OdNwObjectId& nwShadedMtlId, OdTvColorDef& entClr); OdTvMaterialId getMaterial(const OdNwMaterialAttribute* pNwMatAttr, const OdNwGraphicMaterialAttribute* pNwGraphMatAttr); public: enum NwMatCompareState { kIsNotEqual = 0, kIsEqual = 1, kIsEqaulWithOverrides = 2 }; NwMatCompareState isEqual(const OdNwObjectId& nwShadedMtlId, const OdNwMaterialAttribute* pNwMatAttr, OdTvColorDef& tvEntClr, OdTvTransparencyDef& tvEntTrcy); bool isEqual(const OdNwObjectId& nwMatId, const OdNwGraphicMaterialAttribute* pNwGraphMatAttr); bool isEqual(const OdNwGraphicMaterialAttribute* pGrMat1, const OdNwGraphicMaterialAttribute* pGrMat2); protected: OdTvMaterialId createTvMaterial(const OdString& sMatName); template OdTvMaterialId createTvMaterial(const T* pNwMat); OdTvMaterialId importByAdvancedMaterial(const OdNwTexture* pTxt, OdNwDatabase* pNwDb); OdTvMaterialId importMaterial(const OdNwObjectId& nwRealisticMtlId, const OdNwObjectId& nwShadedMtlId, OdTvColorDef& entClr); template OdTvMaterialId importMaterial(const T* pNwSimpleMat, OdTvColorDef& entClr); void importMaterialElement(); template OdTvMaterialId copyAndSetMaterialShadded(const OdTvMaterialId& tvMatId, const T* pNwSimpleMat); OdTvMaterialId copyAndSetDefaultShadded(const OdTvMaterialId& tvMat); OdTvMaterialId copyMaterial(const OdTvMaterialId& tvMat); template void setSimpleMaterialAsShadded(const OdTvMaterialId& tvMatId, const T* pNwSimpleMat); //optimization function for getting bundle guid from graphic material //in first time it's get method from object and cache it to map for further requests OdGUID getGUIDFromGraphMatAttr(const OdNwGraphicMaterialAttribute* pGrMat); private: OdTvDatabaseId m_tvDatabaseId; //object id for material element from BimNv OdNwObjectId m_nwMatElId; //nw partition units of the nearest partition NwModelUnits::Enum m_nwCurPartUnits; //default color from append properties OdTvColorDef m_defaultEntColor; //path ro refl env texture OdString m_sReflectionEnvPath; //link between nwmaterial attributes and tv material std::unordered_map m_mNwMatAttr2TvMat; //link between nwmaterial/nwtexture and tv material std::map m_mNwMatCache2TvMat; //link between simple material OdNwMaterial/OdNwMaterialAttribute and tv material //it will generate hash function for Nw2TvSimpleMatCache std::unordered_map m_mNwSimplMatCache; struct NwAdvMat2TvMat { bool m_bIsTvMatDefault; OdTvMaterialId m_tvMatId; std::unordered_map m_mNwSimplMatCache; }; //link between advanced material OdNwGraphicBundle->guid and tv material std::unordered_map m_mNwAdvMatCache; //already used tv material names in this run of nw2visualize std::set m_mPossibleMatNames; std::unordered_map m_mAdvMatAttrIds; //lambda to generate temp file paths std::function m_getTempFilePath; }; } #include "TD_PackPop.h" #endif // NWMATERIALIMPORT_H