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 _RWObj_TriangulationReader_HeaderFile
16 #define _RWObj_TriangulationReader_HeaderFile
18 #include <RWObj_Reader.hxx>
20 #include <Poly_Triangulation.hxx>
21 #include <TopoDS_Compound.hxx>
23 //! Interface to store shape attributes into document.
24 class RWObj_IShapeReceiver
27 //! @param theShape shape to register
28 //! @param theName shape name
29 //! @param theMaterial shape material
30 //! @param theIsRootShape indicates that this is a root object (free shape)
31 virtual void BindNamedShape (const TopoDS_Shape& theShape,
32 const TCollection_AsciiString& theName,
33 const RWObj_Material* theMaterial,
34 const Standard_Boolean theIsRootShape) = 0;
37 //! RWObj_Reader implementation dumping OBJ file into Poly_Triangulation.
38 class RWObj_TriangulationReader : public RWObj_Reader
40 DEFINE_STANDARD_RTTIEXT(RWObj_TriangulationReader, RWObj_Reader)
44 RWObj_TriangulationReader() : myShapeReceiver (NULL), myToCreateShapes (Standard_True) {}
46 //! Set flag to create shapes.
47 void SetCreateShapes (Standard_Boolean theToCreateShapes) { myToCreateShapes = theToCreateShapes; }
49 //! Set shape receiver callback.
50 void SetShapeReceiver (RWObj_IShapeReceiver* theReceiver) { myShapeReceiver = theReceiver; }
52 //! Create Poly_Triangulation from collected data
53 Standard_EXPORT virtual Handle(Poly_Triangulation) GetTriangulation();
55 //! Return result shape.
56 Standard_EXPORT TopoDS_Shape ResultShape();
60 //! Flush active sub-mesh.
61 Standard_EXPORT virtual Standard_Boolean addMesh (const RWObj_SubMesh& theMesh,
62 const RWObj_SubMeshReason theReason) Standard_OVERRIDE;
64 //! Retrieve sub-mesh node position.
65 virtual gp_Pnt getNode (Standard_Integer theIndex) const Standard_OVERRIDE
67 return myNodes.Value (theIndex - 1);
71 virtual Standard_Integer addNode (const gp_Pnt& thePnt) Standard_OVERRIDE
73 myNodes.Append (thePnt);
74 return myNodes.Size();
78 virtual void setNodeNormal (const Standard_Integer theIndex,
79 const Graphic3d_Vec3& theNormal) Standard_OVERRIDE
81 myNormals.SetValue (theIndex - 1, theNormal);
84 //! Ignore texture coordinates.
85 virtual void setNodeUV (const Standard_Integer theIndex,
86 const Graphic3d_Vec2& theUV) Standard_OVERRIDE
88 myNodesUV.SetValue (theIndex - 1, theUV);
92 virtual void addElement (Standard_Integer theN1, Standard_Integer theN2, Standard_Integer theN3, Standard_Integer theN4) Standard_OVERRIDE
94 myTriangles.Append (Poly_Triangle (theN1, theN2, theN3));
97 myTriangles.Append (Poly_Triangle (theN1, theN3, theN4));
103 //! Add sub-shape into specified shape
104 Standard_EXPORT Standard_Boolean addSubShape (TopoDS_Shape& theParent,
105 const TopoDS_Shape& theSubShape,
106 const Standard_Boolean theToExpandCompound);
110 NCollection_Vector<gp_Pnt> myNodes; //!< nodes of currently filled triangulation
111 NCollection_Vector<Graphic3d_Vec3> myNormals; //!< normals of currently filled triangulation
112 NCollection_Vector<Graphic3d_Vec2> myNodesUV; //!< UVs of currently filled triangulation
113 NCollection_Vector<Poly_Triangle> myTriangles; //!< indexes of currently filled triangulation
115 RWObj_IShapeReceiver* myShapeReceiver; //!< optional shape receiver
116 TopoDS_Compound myResultShape; //!< result shape as Compound of objects
117 TopoDS_Compound myLastObjectShape; //!< Compound containing current object groups
118 TopoDS_Shape myLastGroupShape; //!< current group shape - either a single Face or Compound of Faces
119 TCollection_AsciiString myLastGroupName; //!< current group name
120 TCollection_AsciiString myLastFaceMaterial;//!< last face material name
121 Standard_Boolean myToCreateShapes; //!< create a single triangulation
125 #endif // _RWObj_TriangulationReader_HeaderFile