1 // Author: Kirill Gavrilov
2 // Copyright (c) 2019 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #ifndef _RWGltf_PrimitiveArrayReader_HeaderFile
16 #define _RWGltf_PrimitiveArrayReader_HeaderFile
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>
25 class RWGltf_GltfLatePrimitiveArray;
27 //! The interface for shared file.
28 struct RWGltf_GltfSharedIStream
30 std::ifstream Stream; //!< shared file
31 TCollection_AsciiString Path; //!< path to currently opened stream
34 //! Interface for reading primitive array from glTF buffer.
35 class RWGltf_PrimitiveArrayReader : public Standard_Transient
37 DEFINE_STANDARD_RTTIEXT(RWGltf_PrimitiveArrayReader, Standard_Transient)
41 RWGltf_PrimitiveArrayReader() {}
43 //! Return prefix for reporting issues.
44 const TCollection_AsciiString& ErrorPrefix() const { return myErrorPrefix; }
46 //! Set prefix for reporting issues.
47 void SetErrorPrefix (const TCollection_AsciiString& theErrPrefix) { myErrorPrefix = theErrPrefix; }
49 //! Return transformation from glTF to OCCT coordinate system.
50 const RWMesh_CoordinateSystemConverter& CoordinateSystemConverter() const { return myCoordSysConverter; }
52 //! Set transformation from glTF to OCCT coordinate system.
53 void SetCoordinateSystemConverter (const RWMesh_CoordinateSystemConverter& theConverter) { myCoordSysConverter = theConverter; }
55 //! Load primitive array.
56 Handle(Poly_Triangulation) Load (const Handle(RWGltf_GltfLatePrimitiveArray)& theMesh)
62 return Handle(Poly_Triangulation)();
67 //! Reset cache before loading primitive array.
68 Standard_EXPORT virtual void reset() = 0;
70 //! Load primitive array.
71 Standard_EXPORT virtual bool load (const Handle(RWGltf_GltfLatePrimitiveArray)& theMesh);
73 //! Return result primitive array.
74 Standard_EXPORT virtual Handle(Poly_Triangulation) result() = 0;
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;
90 Standard_EXPORT virtual void reportError (const TCollection_AsciiString& theText);
94 TCollection_AsciiString myErrorPrefix;
95 RWGltf_GltfSharedIStream mySharedStream;
96 RWMesh_CoordinateSystemConverter myCoordSysConverter;
100 #endif // _RWGltf_PrimitiveArrayReader_HeaderFile