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_TriangulationReader_HeaderFile
16 #define _RWGltf_TriangulationReader_HeaderFile
18 #include <RWGltf_PrimitiveArrayReader.hxx>
20 //! RWGltf_PrimitiveArrayReader implementation creating Poly_Triangulation.
21 class RWGltf_TriangulationReader : public RWGltf_PrimitiveArrayReader
23 DEFINE_STANDARD_RTTIEXT(RWGltf_TriangulationReader, RWGltf_PrimitiveArrayReader)
26 //! Empty constructor.
27 Standard_EXPORT RWGltf_TriangulationReader();
31 //! Create Poly_Triangulation from collected data
32 Standard_EXPORT virtual Handle(Poly_Triangulation) result() Standard_OVERRIDE;
34 //! Reset cache before loading primitive array.
35 Standard_EXPORT virtual void reset() Standard_OVERRIDE;
37 //! Fill triangulation data and ignore non-triangulation primitives.
38 //! @param theStream input stream to read from
39 //! @param theName entity name for logging errors
40 //! @param theAccessor buffer accessor
41 //! @param theType array type
42 //! @param theMode primitive mode
43 //! @return FALSE on error
44 Standard_EXPORT virtual bool readBuffer (std::istream& theStream,
45 const TCollection_AsciiString& theName,
46 const RWGltf_GltfAccessor& theAccessor,
47 RWGltf_GltfArrayType theType,
48 RWGltf_GltfPrimitiveMode theMode) Standard_OVERRIDE;
50 protected: //! @name interface for filling triangulation data
52 //! Resize array of position nodes to specified size.
53 virtual bool setNbPositionNodes (Standard_Integer theNbNodes)
59 myTriangulation->ChangeNodes().Resize (1, theNbNodes, false);
63 //! Set node position.
64 //! @param theIndex node index starting from 1
65 //! @param thePnt node position
66 virtual void setNodePosition (Standard_Integer theIndex,
69 myTriangulation->ChangeNode (theIndex) = thePnt;
72 //! Resize array of UV nodes to specified size.
73 virtual bool setNbUVNodes (Standard_Integer theNbNodes)
76 || myTriangulation->NbNodes() != theNbNodes)
80 myTriangulation->ChangeUVNodes().Resize (1, theNbNodes, false);
84 //! Set node UV texture coordinates.
85 //! @param theIndex node index starting from 1
86 //! @param theUV node UV coordinates
87 virtual void setNodeUV (Standard_Integer theIndex,
88 const gp_Pnt2d& theUV)
90 myTriangulation->ChangeUVNode (theIndex) = theUV;
93 //! Resize array of nodes normals to specified size.
94 virtual bool setNbNormalNodes (Standard_Integer theNbNodes)
97 || myTriangulation->NbNodes() != theNbNodes)
101 myTriangulation->SetNormals (new TShort_HArray1OfShortReal (1, theNbNodes * 3));
106 //! @param theIndex node index starting from 1
107 //! @param theNormal node normal
108 virtual void setNodeNormal (Standard_Integer theIndex,
109 const gp_Dir& theNormal)
111 myTriangulation->SetNormal (theIndex, theNormal);
114 //! Resize array of triangles to specified size.
115 virtual bool setNbTriangles (Standard_Integer theNbTris)
119 myTriangulation->ChangeTriangles().Resize (1, theNbTris, false);
125 //! Add triangle element.
126 //! @param theIndex triangle index starting from 1
127 //! @param theTriangle triangle nodes starting from 1
128 //! @return FALSE if node indexes are out of range
129 virtual bool setTriangle (Standard_Integer theIndex,
130 const Poly_Triangle& theTriangle)
132 if (theTriangle.Value (1) < myTriangulation->Nodes().Lower() || theTriangle.Value (1) > myTriangulation->Nodes().Upper()
133 || theTriangle.Value (2) < myTriangulation->Nodes().Lower() || theTriangle.Value (2) > myTriangulation->Nodes().Upper()
134 || theTriangle.Value (3) < myTriangulation->Nodes().Lower() || theTriangle.Value (3) > myTriangulation->Nodes().Upper())
138 myTriangulation->ChangeTriangle (theIndex) = theTriangle;
144 Handle(Poly_Triangulation) myTriangulation;
148 #endif // _RWGltf_TriangulationReader_HeaderFile