0029528: Visualization, TKOpenGl - allow defining sRGB textures
[occt.git] / src / RWGltf / RWGltf_PrimitiveArrayReader.hxx
1 // Author: Kirill Gavrilov
2 // Copyright (c) 2019 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #ifndef _RWGltf_PrimitiveArrayReader_HeaderFile
16 #define _RWGltf_PrimitiveArrayReader_HeaderFile
17
18 #include <Poly_Triangulation.hxx>
19 #include <RWMesh_CoordinateSystemConverter.hxx>
20 #include <RWGltf_GltfAccessor.hxx>
21 #include <RWGltf_GltfArrayType.hxx>
22 #include <RWGltf_GltfPrimitiveMode.hxx>
23 #include <TCollection_AsciiString.hxx>
24
25 class RWGltf_GltfLatePrimitiveArray;
26
27 //! The interface for shared file.
28 struct RWGltf_GltfSharedIStream
29 {
30   std::ifstream           Stream; //!< shared file
31   TCollection_AsciiString Path;   //!< path to currently opened stream
32 };
33
34 //! Interface for reading primitive array from glTF buffer.
35 class RWGltf_PrimitiveArrayReader : public Standard_Transient
36 {
37   DEFINE_STANDARD_RTTIEXT(RWGltf_PrimitiveArrayReader, Standard_Transient)
38 public:
39
40   //! Constructor.
41   RWGltf_PrimitiveArrayReader() {}
42
43   //! Return prefix for reporting issues.
44   const TCollection_AsciiString& ErrorPrefix() const { return myErrorPrefix; }
45
46   //! Set prefix for reporting issues.
47   void SetErrorPrefix (const TCollection_AsciiString& theErrPrefix) { myErrorPrefix = theErrPrefix; }
48
49   //! Return transformation from glTF to OCCT coordinate system.
50   const RWMesh_CoordinateSystemConverter& CoordinateSystemConverter() const { return myCoordSysConverter; }
51
52   //! Set transformation from glTF to OCCT coordinate system.
53   void SetCoordinateSystemConverter (const RWMesh_CoordinateSystemConverter& theConverter) { myCoordSysConverter = theConverter; }
54
55   //! Load primitive array.
56   Handle(Poly_Triangulation) Load (const Handle(RWGltf_GltfLatePrimitiveArray)& theMesh)
57   {
58     if (load (theMesh))
59     {
60       return result();
61     }
62     return Handle(Poly_Triangulation)();
63   }
64
65 protected:
66
67   //! Reset cache before loading primitive array.
68   Standard_EXPORT virtual void reset() = 0;
69
70   //! Load primitive array.
71   Standard_EXPORT virtual bool load (const Handle(RWGltf_GltfLatePrimitiveArray)& theMesh);
72
73   //! Return result primitive array.
74   Standard_EXPORT virtual Handle(Poly_Triangulation) result() = 0;
75
76   //! Read primitive array data.
77   //! @param theStream   input stream to read from
78   //! @param theName     entity name for logging errors
79   //! @param theAccessor buffer accessor
80   //! @param theType     array type
81   //! @param theMode     primitive mode
82   //! @return FALSE on error
83   Standard_EXPORT virtual bool readBuffer (std::istream& theStream,
84                                            const TCollection_AsciiString& theName,
85                                            const RWGltf_GltfAccessor& theAccessor,
86                                            RWGltf_GltfArrayType theType,
87                                            RWGltf_GltfPrimitiveMode theMode) = 0;
88
89   //! Report error.
90   Standard_EXPORT virtual void reportError (const TCollection_AsciiString& theText);
91
92 protected:
93
94   TCollection_AsciiString          myErrorPrefix;
95   RWGltf_GltfSharedIStream         mySharedStream;
96   RWMesh_CoordinateSystemConverter myCoordSysConverter;
97
98 };
99
100 #endif // _RWGltf_PrimitiveArrayReader_HeaderFile