/////////////////////////////////////////////////////////////////////////////// // 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 GLTF2VISUALIZE_H #define GLTF2VISUALIZE_H #include "TD_PackPush.h" #define STL_USING_MAP #define STL_USING_LIST #define STL_USING_STRING #include "OdaSTL.h" #include "RxDispatchImpl.h" #include "TvVisualizeFiler.h" #include "GLTFJsonStructure.h" #include "../../../Drawing/Include/DbObjectId.h" void odrxSetMemberConstructor(OdRxClass* pClass, OdRxMemberCollectionConstructorPtr pc, void* data = 0); namespace GLTF2Visualize { /** \details This class implements the properties of the glTF loader */ class OdTvVisualizeGltfFilerProperties : public OdRxDispatchImpl<> { public: OdTvVisualizeGltfFilerProperties(); virtual ~OdTvVisualizeGltfFilerProperties() {} ODRX_DECLARE_DYNAMIC_PROPERTY_MAP(OdTvVizualizeGltfFilerProperties); static OdRxDictionaryPtr createObject(); void setDefaultColor(OdIntPtr pDefColor); OdIntPtr getDefaultColor() const; void setAppendTransform(OdIntPtr pTransform); OdIntPtr getAppendTransform() const; void setDefaultUnits(OdUInt8 units) { m_defaultUnits = units; } OdUInt8 getDefaultUnits() const { return m_defaultUnits; } void setNeedCDATree(bool bSet) { m_bNeedCDATree = bSet; } bool getNeedCDATree() const { return m_bNeedCDATree; } void setNeedCollectPropertiesInCDA(bool bSet) { m_bNeedCollectPropertiesInCDA = bSet; } bool getNeedCollectPropertiesInCDA() const { return m_bNeedCollectPropertiesInCDA; } protected: ODCOLORREF m_defaultColor; // default color which is set to the entity OdTvMatrix m_appendTransform; // Transform for the append OdUInt8 m_defaultUnits; // default units bool m_bNeedCDATree; // Need build CDA tree bool m_bNeedCollectPropertiesInCDA; // Need collect native properties in CDA nodes }; typedef OdSmartPtr OdTvVisualizeGltfFilerPropertiesPtr; } struct Color { Color() = default; Color(OdUInt8 r, OdUInt8 g, OdUInt8 b, OdUInt8 a = 1) : r(r), g(g), b(b), a(a) {} OdUInt32 r; OdUInt32 g; OdUInt32 b; float a = 1.f; Color& operator+=(const Color& other) { this->r += other.r; this->g += other.g; this->b += other.b; this->a += other.a; return *this; } friend Color operator+(const Color& lhs, const Color& rhs) { Color cmn = lhs; return cmn += rhs; } Color& operator/=(OdInt32 divider) { this->r /= divider; this->g /= divider; this->b /= divider; this->a /= divider; return *this; } friend Color operator/(const Color& color, OdInt32 divider) { Color newColor = color; return newColor /= divider; } }; /** \details This class is rcs loader (to the Visualize database) */ class OdTvVisualizeGltfFiler : public OdTvVisualizeFiler { public: OdTvVisualizeGltfFiler(); virtual OdRxDictionaryPtr properties() { return m_properties; } virtual OdTvDatabaseId loadFrom(OdDbBaseDatabase* pDatabase, OdTvFilerTimeProfiling* pProfileRes = NULL, OdTvResult* rc = NULL) const; virtual OdTvDatabaseId loadFrom(OdStreamBuf* pBuffer, OdTvFilerTimeProfiling* pProfileRes = NULL, OdTvResult* rc = NULL) const; virtual OdTvDatabaseId loadFrom(const OdString& filePath, OdTvFilerTimeProfiling* pProfileRes = NULL, OdTvResult* rc = NULL) const; virtual OdTvDatabaseId generate(OdTvFilerTimeProfiling* pProfileRes = NULL) const; virtual OdTvModelId appendFrom(const OdTvDatabaseId& databaseId, OdDbBaseDatabase* pDatabase, OdTvFilerTimeProfiling* pProfileRes = NULL, OdTvResult* rc = NULL) const; virtual OdTvModelId appendFrom(const OdTvDatabaseId& databaseId, OdStreamBuf* pBuffer, OdTvFilerTimeProfiling* pProfileRes = NULL, OdTvResult* rc = NULL) const; virtual OdTvModelId appendFrom(const OdTvDatabaseId& databaseId, const OdString& filePath, OdTvFilerTimeProfiling* pProfileRes = NULL, OdTvResult* rc = NULL) const; struct LoadGltfOptions { enum Type { kFilePath, kBuffer }; OdString m_filePath; OdStreamBuf* m_pBuffer; Type m_type; LoadGltfOptions(const OdString& filePath) : m_filePath(filePath), m_type(kFilePath), m_pBuffer(NULL) {} LoadGltfOptions(OdStreamBuf* pBuffer) : m_pBuffer(pBuffer), m_type(kBuffer) {} }; private: struct OdSkinData { OdArray skeleton; OdArray invBindMatrices; OdArray joints; OdArray weights; }; void createCommonDataAccessTree(const OdTvDatabaseId& tvDbId, const OdString& strTreeName) const; OdTvModelId kernelGltf2Visualize(OdTvDatabaseId databaseId, const LoadGltfOptions& opt, OdBool& isThereBump, OdTvFilerTimeProfiling* pProfileRes = NULL, OdTvResult* rc = NULL) const; OdTvDatabaseId loadGltf(const LoadGltfOptions& opt, OdTvFilerTimeProfiling* pProfileRes = NULL, OdTvResult* rc = NULL) const; OdTvModelId appendGltf(const OdTvDatabaseId& databaseId, const LoadGltfOptions& opt, OdTvFilerTimeProfiling* pProfileRes = NULL, OdTvResult* rc = NULL) const; OdSharedPtr loadGltfContent(const LoadGltfOptions& opt, OdTvFilerTimeProfiling* pProfileRes = NULL, OdTvResult* rc = NULL) const; void loadModelFromGltfScene(OdTvModelPtr& pTvModel, OdTvDatabasePtr& pDb, const GLTFFileImport::JSON::OdJsonContent& rJsonContent, OdTvFilerTimeProfiling* pProfileRes = NULL, OdTvResult* rc = NULL) const; //Interpretation Json data to Visualize void collectShellFromMesh(const GLTFFileImport::JSON::OdMeshContent::OdPrimitive& primitive, const GLTFFileImport::JSON::OdJsonContent& rJsonContent, OdTvPointArray& vertices, OdInt32Array& faces, OdTvResult* rc = NULL) const; void processNode(OdTvModelPtr& pTvModel, OdTvDatabasePtr& pDb, OdUInt32 nodeIdx, const GLTFFileImport::JSON::OdJsonContent& rJsonContent, OdTvGroupPtr pParentGroup = OdTvGroupPtr()) const; OdTvMaterialId createMaterialFromJson(OdTvDatabasePtr& pDb, OdTvShellDataPtr& shellPtr, OdInt32 meshIdx, const GLTFFileImport::JSON::OdMeshContent::OdPrimitive& primitive, const GLTFFileImport::JSON::OdJsonContent& rJsonContent) const; void applyShellSpecifiedParameters(OdTvDatabasePtr& pDb, OdTvShellDataPtr& shellPtr, const GLTFFileImport::JSON::OdMeshContent::OdPrimitive& primitive, const GLTFFileImport::JSON::OdJsonContent& rJsonContent, const OdSharedPtr& skinData) const; OdArray formTextureBuffer(OdTvDatabasePtr& pDb, const GLTFFileImport::JSON::OdTextureContent& rTexture, const GLTFFileImport::JSON::OdMeshContent::OdPrimitive& primitive, const GLTFFileImport::JSON::OdJsonContent& rJsonContent, const GLTFFileImport::JSON::ColorFactor& colorFactor = GLTFFileImport::JSON::ColorFactor()) const; OdString strDefaultMaterialName = OD_T("GLTF_DEFAULT_MATERIAL"); GLTF2Visualize::OdTvVisualizeGltfFilerPropertiesPtr m_properties; }; /** \details This class is gltf loader module implementation */ class OdTvVisualizeGltfFilerModule : public OdTvVisualizeFilerModule { public: virtual OdTvVisualizeFilerPtr getVisualizeFiler() const; static OdArray properties; static void constructOdGltfImportProperties(OdRxMemberCollectionBuilder& b, void*); void initApp(); void uninitApp(); private: OdRxObjectPtr m_pModule; }; #include "TD_PackPop.h" #endif