Back to home page

EIC code displayed by LXR

 
 

    


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

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 _RWGltf_GltfMaterialMap_HeaderFile
0015 #define _RWGltf_GltfMaterialMap_HeaderFile
0016 
0017 #include <RWMesh_MaterialMap.hxx>
0018 #include <RWGltf_GltfBufferView.hxx>
0019 
0020 class RWGltf_GltfOStreamWriter;
0021 
0022 //! Material manager for exporting into glTF format.
0023 class RWGltf_GltfMaterialMap : public RWMesh_MaterialMap
0024 {
0025   DEFINE_STANDARD_RTTIEXT(RWGltf_GltfMaterialMap, RWMesh_MaterialMap)
0026 public:
0027 
0028   //! Main constructor.
0029   Standard_EXPORT RWGltf_GltfMaterialMap (const TCollection_AsciiString& theFile,
0030                                           const Standard_Integer theDefSamplerId);
0031 
0032   //! Destructor.
0033   Standard_EXPORT virtual ~RWGltf_GltfMaterialMap();
0034 
0035 public:
0036 
0037   //! Add material images into GLB stream.
0038   //! @param theBinFile [in] [out] output file stream
0039   //! @param theStyle   [in] material images to add
0040   Standard_EXPORT void AddGlbImages (std::ostream& theBinFile,
0041                                      const XCAFPrs_Style& theStyle);
0042 
0043   //! Add bufferView's into RWGltf_GltfRootElement_BufferViews section with images collected by AddImagesToGlb().
0044   Standard_EXPORT void FlushGlbBufferViews (RWGltf_GltfOStreamWriter* theWriter,
0045                                             const Standard_Integer theBinDataBufferId,
0046                                             Standard_Integer& theBuffViewId);
0047 
0048   //! Write RWGltf_GltfRootElement_Images section with images collected by AddImagesToGlb().
0049   Standard_EXPORT void FlushGlbImages (RWGltf_GltfOStreamWriter* theWriter);
0050 
0051 public:
0052 
0053   //! Add material images in case of non-GLB file
0054   //! (an alternative to AddImagesToGlb() + FlushBufferViews() + FlushImagesGlb()).
0055   Standard_EXPORT void AddImages (RWGltf_GltfOStreamWriter* theWriter,
0056                                   const XCAFPrs_Style& theStyle,
0057                                   Standard_Boolean& theIsStarted);
0058 
0059   //! Add material.
0060   Standard_EXPORT void AddMaterial (RWGltf_GltfOStreamWriter* theWriter,
0061                                     const XCAFPrs_Style& theStyle,
0062                                     Standard_Boolean& theIsStarted);
0063   //! Add material textures.
0064   Standard_EXPORT void AddTextures (RWGltf_GltfOStreamWriter* theWriter,
0065                                     const XCAFPrs_Style& theStyle,
0066                                     Standard_Boolean& theIsStarted);
0067 
0068   //! Return extent of images map.
0069   Standard_Integer NbImages() const { return myImageMap.Extent(); }
0070 
0071   //! Return extent of textures map.
0072   Standard_Integer NbTextures() const { return myTextureMap.Extent(); }
0073 
0074 public:
0075 
0076   //! Return base color texture.
0077   Standard_EXPORT static const Handle(Image_Texture)& baseColorTexture (const Handle(XCAFDoc_VisMaterial)& theMat);
0078 
0079 protected:
0080 
0081   //! Add texture image.
0082   Standard_EXPORT void addImage (RWGltf_GltfOStreamWriter* theWriter,
0083                                  const Handle(Image_Texture)& theTexture,
0084                                  Standard_Boolean& theIsStarted);
0085 
0086   //! Add texture image into GLB stream.
0087   //! @param theBinFile [in] [out] output file stream
0088   //! @param theTexture [in] texture image to add
0089   Standard_EXPORT void addGlbImage (std::ostream& theBinFile,
0090                                     const Handle(Image_Texture)& theTexture);
0091 
0092   //! Add texture.
0093   Standard_EXPORT void addTexture (RWGltf_GltfOStreamWriter* theWriter,
0094                                    const Handle(Image_Texture)& theTexture,
0095                                    Standard_Boolean& theIsStarted);
0096 
0097   //! Add material
0098   Standard_EXPORT virtual TCollection_AsciiString AddMaterial (const XCAFPrs_Style& theStyle) Standard_OVERRIDE;
0099 
0100   //! Virtual method actually defining the material (e.g. export to the file).
0101   Standard_EXPORT virtual void DefineMaterial (const XCAFPrs_Style& theStyle,
0102                                                const TCollection_AsciiString& theKey,
0103                                                const TCollection_AsciiString& theName) Standard_OVERRIDE;
0104 
0105 protected:
0106 
0107   RWGltf_GltfOStreamWriter* myWriter;
0108   NCollection_IndexedDataMap<Handle(Image_Texture), RWGltf_GltfBufferView> myImageMap;
0109   NCollection_Map<Handle(Image_Texture)> myTextureMap;
0110 
0111   Standard_Integer myDefSamplerId;
0112 
0113 };
0114 
0115 #endif // _RWGltf_GltfMaterialMap_HeaderFile