]> OCCT Git - occt.git/commitdiff
Add stream to json parser to read lines and points
authorsshutina <svetlana.shutina@opencascade.com>
Thu, 10 Apr 2025 22:23:10 +0000 (23:23 +0100)
committersshutina <svetlana.shutina@opencascade.com>
Fri, 11 Apr 2025 07:55:15 +0000 (08:55 +0100)
src/DataExchange/TKDEGLTF/RWGltf/RWGltf_GltfJsonParser.cxx
src/DataExchange/TKDEGLTF/RWGltf/RWGltf_GltfJsonParser.hxx
src/DataExchange/TKDEGLTF/RWGltf/RWGltf_TriangulationReader.cxx
src/DataExchange/TKDEGLTF/RWGltf/RWGltf_TriangulationReader.hxx

index 292cadbd48cda825cbbe9314a7ff70ba246b15c4..52cbc1072fbdd976daf39932aeb03f83a848a3df 100644 (file)
@@ -1932,10 +1932,7 @@ bool RWGltf_GltfJsonParser::gltfParsePrimArray(TopoDS_Shape&                  th
     {
       Message::SendWarning("Deferred loading is available only for triangulations. Other elements "
                            "will be loaded immediately.");
-      Handle(RWGltf_TriangulationReader) aReader = new RWGltf_TriangulationReader();
-      aReader->SetCoordinateSystemConverter(myCSTrsf);
-      aMeshData->SetReader(aReader);
-      aMeshData->LoadDeferredData();
+      fillMeshData(aMeshData);
     }
 
     TopoDS_Shape aShape;
@@ -2457,6 +2454,32 @@ void RWGltf_GltfJsonParser::bindNamedShape(TopoDS_Shape&                     the
   }
   myShapeMap[theGroup].Bind(theId, theShape);
 }
+
+//=================================================================================================
+
+bool RWGltf_GltfJsonParser::fillMeshData(
+  const Handle(RWGltf_GltfLatePrimitiveArray)& theMeshData) const
+{
+  for (NCollection_Sequence<RWGltf_GltfPrimArrayData>::Iterator aDataIter(theMeshData->Data());
+       aDataIter.More();
+       aDataIter.Next())
+  {
+    const RWGltf_GltfPrimArrayData& aData = aDataIter.Value();
+
+    Handle(RWGltf_TriangulationReader) aReader = new RWGltf_TriangulationReader();
+    aReader->SetCoordinateSystemConverter(myCSTrsf);
+    std::shared_ptr<std::istream> aNewStream = myStream;
+    aNewStream->seekg(aData.StreamOffset);
+
+    if (!aReader
+           ->ReadStream(theMeshData, theMeshData, *aNewStream.get(), aData.Accessor, aData.Type))
+    {
+      return false;
+    }
+  }
+
+  return true;
+}
 #endif
 
 //=================================================================================================
index ea0843eb2b6558b20c7172ef4efc488ed22121f4..e897d5bfaf1a1eb4d6e0ffe087717a85140cff2c 100644 (file)
@@ -126,6 +126,9 @@ public:
   //! Return face list for loading triangulation.
   NCollection_Vector<TopoDS_Face>& FaceList() { return myFaceList; }
 
+  //! Set inpit stream.
+  void SetStream(std::shared_ptr<std::istream>& theStream) { myStream = theStream; }
+
 protected:
 #ifdef HAVE_RAPIDJSON
   //! Search mandatory root elements in the document.
@@ -421,6 +424,11 @@ private:
                                      const RWGltf_JsonValue*        theScaleVal,
                                      const RWGltf_JsonValue*        theTranslationVal,
                                      TopLoc_Location&               theResult) const;
+
+  //! Fill lines and points data not deferred.
+  //! @param theMeshData source glTF triangulation
+  Standard_EXPORT bool fillMeshData(const Handle(RWGltf_GltfLatePrimitiveArray)& theMeshData) const;
+
 #endif
 protected:
   //! Print message about invalid glTF syntax.
@@ -437,6 +445,8 @@ protected:
                                                     // clang-format on
   TColStd_IndexedDataMapOfStringString* myMetadata; //!< file metadata
 
+  std::shared_ptr<std::istream> myStream; //!< input stream
+
   NCollection_DataMap<TCollection_AsciiString, Handle(RWGltf_MaterialMetallicRoughness)>
                                                                               myMaterialsPbr;
   NCollection_DataMap<TCollection_AsciiString, Handle(RWGltf_MaterialCommon)> myMaterialsCommon;
index 445e315b66f7330c2f71594f338eeb3f15bfb387..77dfdf4a3a95a130b84ae508e0dcbcc8c88da1c1 100644 (file)
@@ -562,6 +562,19 @@ bool RWGltf_TriangulationReader::readBuffer(
   const RWGltf_GltfAccessor&                   theAccessor,
   RWGltf_GltfArrayType                         theType) const
 
+{
+  return ReadStream(theSourceMesh, theDestMesh, theStream, theAccessor, theType);
+}
+
+//=================================================================================================
+
+bool RWGltf_TriangulationReader::ReadStream(
+  const Handle(RWGltf_GltfLatePrimitiveArray)& theSourceMesh,
+  const Handle(Poly_Triangulation)&            theDestMesh,
+  std::istream&                                theStream,
+  const RWGltf_GltfAccessor&                   theAccessor,
+  RWGltf_GltfArrayType                         theType) const
+
 {
   const TCollection_AsciiString& aName     = theSourceMesh->Id();
   const RWGltf_GltfPrimitiveMode aPrimMode = theSourceMesh->PrimitiveMode();
index d3331388dc02d91777eaf53b63381fd869e031da..d61c336e0c497371a7b7e7fbb81356b6c3a936dd 100644 (file)
@@ -36,6 +36,19 @@ public:
   Standard_EXPORT bool LoadStreamData(const Handle(RWMesh_TriangulationSource)& theSourceMesh,
                                       const Handle(Poly_Triangulation)&         theDestMesh) const;
 
+  //! Fills triangulation, lines and points data.
+  //! @param theSourceGltfMesh source glTF triangulation
+  //! @param theDestMesh       triangulation to be modified
+  //! @param theStream         input stream to read from
+  //! @param theAccessor       buffer accessor
+  //! @param theType           array type
+  //! @return FALSE on error
+  Standard_EXPORT bool ReadStream(const Handle(RWGltf_GltfLatePrimitiveArray)& theSourceMesh,
+                                  const Handle(Poly_Triangulation)&            theDestMesh,
+                                  std::istream&                                theStream,
+                                  const RWGltf_GltfAccessor&                   theAccessor,
+                                  RWGltf_GltfArrayType                         theType) const;
+
 protected:
   //! Reports error.
   Standard_EXPORT virtual void reportError(const TCollection_AsciiString& theText) const;