mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-21 10:13:43 +03:00
Data Exchange, GLTF Reader - Add stream to json parser to read lines and points #489
Reorganize GLTF mesh reader to work with streams. The updated scenario is impact on Edge and Vertex reading, which were rely on postponed loading operation, which re-create stream by file name.
This commit is contained in:
parent
15ec314a87
commit
db33e7a43f
@ -20,6 +20,7 @@
|
|||||||
#include <Message_Messenger.hxx>
|
#include <Message_Messenger.hxx>
|
||||||
#include <Message_ProgressScope.hxx>
|
#include <Message_ProgressScope.hxx>
|
||||||
#include <OSD_File.hxx>
|
#include <OSD_File.hxx>
|
||||||
|
#include <OSD_FileSystem.hxx>
|
||||||
#include <OSD_OpenFile.hxx>
|
#include <OSD_OpenFile.hxx>
|
||||||
#include <OSD_Path.hxx>
|
#include <OSD_Path.hxx>
|
||||||
#include <OSD_ThreadPool.hxx>
|
#include <OSD_ThreadPool.hxx>
|
||||||
@ -1932,10 +1933,7 @@ bool RWGltf_GltfJsonParser::gltfParsePrimArray(TopoDS_Shape& th
|
|||||||
{
|
{
|
||||||
Message::SendWarning("Deferred loading is available only for triangulations. Other elements "
|
Message::SendWarning("Deferred loading is available only for triangulations. Other elements "
|
||||||
"will be loaded immediately.");
|
"will be loaded immediately.");
|
||||||
Handle(RWGltf_TriangulationReader) aReader = new RWGltf_TriangulationReader();
|
fillMeshData(aMeshData);
|
||||||
aReader->SetCoordinateSystemConverter(myCSTrsf);
|
|
||||||
aMeshData->SetReader(aReader);
|
|
||||||
aMeshData->LoadDeferredData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TopoDS_Shape aShape;
|
TopoDS_Shape aShape;
|
||||||
@ -2457,6 +2455,49 @@ void RWGltf_GltfJsonParser::bindNamedShape(TopoDS_Shape& the
|
|||||||
}
|
}
|
||||||
myShapeMap[theGroup].Bind(theId, theShape);
|
myShapeMap[theGroup].Bind(theId, theShape);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//=================================================================================================
|
||||||
|
|
||||||
|
bool RWGltf_GltfJsonParser::fillMeshData(
|
||||||
|
const Handle(RWGltf_GltfLatePrimitiveArray)& theMeshData) const
|
||||||
|
{
|
||||||
|
const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
|
||||||
|
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;
|
||||||
|
if (myStream != nullptr)
|
||||||
|
{
|
||||||
|
aNewStream = myStream;
|
||||||
|
aNewStream->seekg(aData.StreamOffset);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
aNewStream = aFileSystem->OpenIStream(aData.StreamUri,
|
||||||
|
std::ios::in | std::ios::binary,
|
||||||
|
aData.StreamOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (aNewStream == nullptr)
|
||||||
|
{
|
||||||
|
reportGltfError("Buffer '" + aData.StreamUri + "' isn't defined.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!aReader
|
||||||
|
->ReadStream(theMeshData, theMeshData, *aNewStream.get(), aData.Accessor, aData.Type))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//=================================================================================================
|
//=================================================================================================
|
||||||
|
@ -126,6 +126,9 @@ public:
|
|||||||
//! Return face list for loading triangulation.
|
//! Return face list for loading triangulation.
|
||||||
NCollection_Vector<TopoDS_Face>& FaceList() { return myFaceList; }
|
NCollection_Vector<TopoDS_Face>& FaceList() { return myFaceList; }
|
||||||
|
|
||||||
|
//! Set inpit stream.
|
||||||
|
void SetStream(std::shared_ptr<std::istream>& theStream) { myStream = theStream; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
#ifdef HAVE_RAPIDJSON
|
#ifdef HAVE_RAPIDJSON
|
||||||
//! Search mandatory root elements in the document.
|
//! Search mandatory root elements in the document.
|
||||||
@ -421,6 +424,11 @@ private:
|
|||||||
const RWGltf_JsonValue* theScaleVal,
|
const RWGltf_JsonValue* theScaleVal,
|
||||||
const RWGltf_JsonValue* theTranslationVal,
|
const RWGltf_JsonValue* theTranslationVal,
|
||||||
TopLoc_Location& theResult) const;
|
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
|
#endif
|
||||||
protected:
|
protected:
|
||||||
//! Print message about invalid glTF syntax.
|
//! Print message about invalid glTF syntax.
|
||||||
@ -437,6 +445,8 @@ protected:
|
|||||||
// clang-format on
|
// clang-format on
|
||||||
TColStd_IndexedDataMapOfStringString* myMetadata; //!< file metadata
|
TColStd_IndexedDataMapOfStringString* myMetadata; //!< file metadata
|
||||||
|
|
||||||
|
mutable std::shared_ptr<std::istream> myStream; //!< input stream
|
||||||
|
|
||||||
NCollection_DataMap<TCollection_AsciiString, Handle(RWGltf_MaterialMetallicRoughness)>
|
NCollection_DataMap<TCollection_AsciiString, Handle(RWGltf_MaterialMetallicRoughness)>
|
||||||
myMaterialsPbr;
|
myMaterialsPbr;
|
||||||
NCollection_DataMap<TCollection_AsciiString, Handle(RWGltf_MaterialCommon)> myMaterialsCommon;
|
NCollection_DataMap<TCollection_AsciiString, Handle(RWGltf_MaterialCommon)> myMaterialsCommon;
|
||||||
|
@ -562,6 +562,19 @@ bool RWGltf_TriangulationReader::readBuffer(
|
|||||||
const RWGltf_GltfAccessor& theAccessor,
|
const RWGltf_GltfAccessor& theAccessor,
|
||||||
RWGltf_GltfArrayType theType) const
|
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 TCollection_AsciiString& aName = theSourceMesh->Id();
|
||||||
const RWGltf_GltfPrimitiveMode aPrimMode = theSourceMesh->PrimitiveMode();
|
const RWGltf_GltfPrimitiveMode aPrimMode = theSourceMesh->PrimitiveMode();
|
||||||
|
@ -36,6 +36,19 @@ public:
|
|||||||
Standard_EXPORT bool LoadStreamData(const Handle(RWMesh_TriangulationSource)& theSourceMesh,
|
Standard_EXPORT bool LoadStreamData(const Handle(RWMesh_TriangulationSource)& theSourceMesh,
|
||||||
const Handle(Poly_Triangulation)& theDestMesh) const;
|
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:
|
protected:
|
||||||
//! Reports error.
|
//! Reports error.
|
||||||
Standard_EXPORT virtual void reportError(const TCollection_AsciiString& theText) const;
|
Standard_EXPORT virtual void reportError(const TCollection_AsciiString& theText) const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user