0032248: Visualization - load "false" deferred glTF data immediately
[occt.git] / src / RWGltf / RWGltf_GltfLatePrimitiveArray.hxx
1 // Author: Kirill Gavrilov
2 // Copyright (c) 2018-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_GltfLatePrimitiveArray_HeaderFile
16 #define _RWGltf_GltfLatePrimitiveArray_HeaderFile
17
18 #include <RWMesh_TriangulationSource.hxx>
19
20 #include <NCollection_Sequence.hxx>
21 #include <RWGltf_GltfArrayType.hxx>
22 #include <RWGltf_GltfPrimitiveMode.hxx>
23 #include <Quantity_ColorRGBA.hxx>
24
25 class RWGltf_GltfPrimArrayData;
26 class RWGltf_MaterialMetallicRoughness;
27 class RWGltf_MaterialCommon;
28
29 //! Mesh data wrapper for delayed primitive array loading from glTF file.
30 class RWGltf_GltfLatePrimitiveArray : public RWMesh_TriangulationSource
31 {
32   DEFINE_STANDARD_RTTIEXT(RWGltf_GltfLatePrimitiveArray, RWMesh_TriangulationSource)
33 public:
34
35   //! Constructor.
36   Standard_EXPORT RWGltf_GltfLatePrimitiveArray (const TCollection_AsciiString& theId,
37                                                  const TCollection_AsciiString& theName);
38
39   //! Destructor.
40   Standard_EXPORT virtual ~RWGltf_GltfLatePrimitiveArray();
41
42   //! Entity id.
43   const TCollection_AsciiString& Id() const { return myId; }
44
45   //! Entity name.
46   const TCollection_AsciiString& Name() const { return myName; }
47
48   //! Assign entity name.
49   void SetName (const TCollection_AsciiString& theName) { myName = theName; }
50
51   //! Return type of primitive array.
52   RWGltf_GltfPrimitiveMode PrimitiveMode() const { return myPrimMode; }
53
54   //! Set type of primitive array.
55   void SetPrimitiveMode (RWGltf_GltfPrimitiveMode theMode) { myPrimMode = theMode; }
56
57   //! Return true if primitive array has assigned material
58   bool HasStyle() const { return !myMaterialPbr.IsNull() || !myMaterialCommon.IsNull(); }
59
60   //! Return base color.
61   Standard_EXPORT Quantity_ColorRGBA BaseColor() const;
62
63   //! Return PBR material definition.
64   const Handle(RWGltf_MaterialMetallicRoughness)& MaterialPbr() const { return myMaterialPbr; }
65
66   //! Set PBR material definition.
67   void SetMaterialPbr (const Handle(RWGltf_MaterialMetallicRoughness)& theMat) { myMaterialPbr = theMat; }
68
69   //! Return common (obsolete) material definition.
70   const Handle(RWGltf_MaterialCommon)& MaterialCommon() const { return myMaterialCommon; }
71
72   //! Set common (obsolete) material definition.
73   void SetMaterialCommon (const Handle(RWGltf_MaterialCommon)& theMat) { myMaterialCommon = theMat; }
74
75   //! Return primitive array data elements.
76   const NCollection_Sequence<RWGltf_GltfPrimArrayData>& Data() const { return myData; }
77
78   //! Add primitive array data element.
79   Standard_EXPORT RWGltf_GltfPrimArrayData& AddPrimArrayData (RWGltf_GltfArrayType theType);
80
81   //! Return TRUE if there is deferred storege and some triangulation data
82   //! that can be loaded using LoadDeferredData().
83   virtual Standard_Boolean HasDeferredData() const Standard_OVERRIDE
84   {
85     return !myData.IsEmpty() && RWMesh_TriangulationSource::HasDeferredData();
86   }
87
88   //! Load primitive array saved as stream buffer to new triangulation object.
89   Standard_EXPORT Handle(Poly_Triangulation) LoadStreamData() const;
90
91 protected:
92
93   NCollection_Sequence<RWGltf_GltfPrimArrayData> myData;
94   Handle(RWGltf_MaterialMetallicRoughness) myMaterialPbr;    //!< PBR material
95   Handle(RWGltf_MaterialCommon)            myMaterialCommon; //!< common (obsolete) material
96   TCollection_AsciiString  myId;         //!< entity id
97   TCollection_AsciiString  myName;       //!< entity name
98   RWGltf_GltfPrimitiveMode myPrimMode;   //!< type of primitive array
99
100 };
101
102 #endif // _RWGltf_GltfLatePrimitiveArray_HeaderFile