Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:43

0001 // Copyright (c) 2017-2019 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _RWMesh_MaterialMap_HeaderFile
0015 #define _RWMesh_MaterialMap_HeaderFile
0016 
0017 #include <NCollection_DoubleMap.hxx>
0018 #include <NCollection_Map.hxx>
0019 #include <XCAFPrs_Style.hxx>
0020 
0021 //! Material manager.
0022 //! Provides an interface for collecting all materials within the document before writing it into file,
0023 //! and for copying associated image files (textures) into sub-folder near by exported model.
0024 class RWMesh_MaterialMap : public Standard_Transient
0025 {
0026   DEFINE_STANDARD_RTTIEXT(RWMesh_MaterialMap, Standard_Transient)
0027 public:
0028 
0029   //! Main constructor.
0030   Standard_EXPORT RWMesh_MaterialMap (const TCollection_AsciiString& theFile);
0031 
0032   //! Destructor.
0033   Standard_EXPORT virtual ~RWMesh_MaterialMap();
0034 
0035   //! Return default material definition to be used for nodes with only color defined.
0036   const XCAFPrs_Style& DefaultStyle() const { return myDefaultStyle; }
0037 
0038   //! Set default material definition to be used for nodes with only color defined.
0039   void SetDefaultStyle (const XCAFPrs_Style& theStyle) { myDefaultStyle = theStyle; }
0040 
0041   //! Find already registered material
0042   TCollection_AsciiString FindMaterial (const XCAFPrs_Style& theStyle) const
0043   {
0044     if (myStyles.IsBound1 (theStyle))
0045     {
0046       return myStyles.Find1 (theStyle);
0047     }
0048     return TCollection_AsciiString();
0049   }
0050 
0051   //! Register material and return its name identifier.
0052   Standard_EXPORT virtual TCollection_AsciiString AddMaterial (const XCAFPrs_Style& theStyle);
0053 
0054   //! Create texture folder "modelName/textures"; for example:
0055   //! MODEL:  Path/ModelName.gltf
0056   //! IMAGES: Path/ModelName/textures/
0057   //! Warning! Output folder is NOT cleared.
0058   Standard_EXPORT virtual bool CreateTextureFolder();
0059 
0060   //! Copy and rename texture file to the new location.
0061   //! @param theResTexture [out] result texture file path (relative to the model)
0062   //! @param theTexture [in] original texture
0063   //! @param theKey [in] material key
0064   Standard_EXPORT virtual bool CopyTexture (TCollection_AsciiString& theResTexture,
0065                                             const Handle(Image_Texture)& theTexture,
0066                                             const TCollection_AsciiString& theKey);
0067 
0068   //! Virtual method actually defining the material (e.g. export to the file).
0069   virtual void DefineMaterial (const XCAFPrs_Style& theStyle,
0070                                const TCollection_AsciiString& theKey,
0071                                const TCollection_AsciiString& theName) = 0;
0072 
0073   //! Return failed flag.
0074   bool IsFailed() const { return myIsFailed; }
0075 
0076 protected:
0077 
0078   //! Copy file to another place.
0079   Standard_EXPORT static bool copyFileTo (const TCollection_AsciiString& theFileSrc,
0080                                           const TCollection_AsciiString& theFileDst);
0081 
0082 protected:
0083 
0084   TCollection_AsciiString myFolder;            //!< output folder for glTF file
0085   TCollection_AsciiString myTexFolder;         //!< output folder for images (full  path)
0086   TCollection_AsciiString myTexFolderShort;    //!< output folder for images (short path)
0087   TCollection_AsciiString myFileName;          //!< output glTF file path
0088   TCollection_AsciiString myShortFileNameBase; //!< output glTF file name without extension
0089   TCollection_AsciiString myKeyPrefix;         //!< prefix for generated keys
0090   NCollection_DoubleMap<XCAFPrs_Style, TCollection_AsciiString>
0091                           myStyles;            //!< map of processed styles
0092   NCollection_Map<Handle(Image_Texture)>
0093                           myImageFailMap;      //!< map of images failed to be copied
0094   XCAFPrs_Style           myDefaultStyle;      //!< default material definition to be used for nodes with only color defined
0095   Standard_Integer        myNbMaterials;       //!< number of registered materials
0096   Standard_Boolean        myIsFailed;          //!< flag indicating failure
0097   Standard_Boolean        myMatNameAsKey;      //!< flag indicating usage of material name as key
0098 
0099 };
0100 
0101 #endif // _RWMesh_MaterialMap_HeaderFile