First scene is now loaded when default one is undefined.
RWGltf_CafReader::RWGltf_CafReader()
: myToParallel (false),
myToSkipEmptyNodes (true),
+ myToLoadAllScenes (false),
myUseMeshNameAsFallback (true),
myIsDoublePrecision (false),
myToSkipLateDataLoading (false),
aDoc.SetErrorPrefix (anErrPrefix);
aDoc.SetCoordinateSystemConverter (myCoordSysConverter);
aDoc.SetSkipEmptyNodes (myToSkipEmptyNodes);
+ aDoc.SetLoadAllScenes (myToLoadAllScenes);
aDoc.SetMeshNameAsFallback (myUseMeshNameAsFallback);
if (!theToProbe)
{
//! Set flag to ignore nodes without Geometry.
void SetSkipEmptyNodes (bool theToSkip) { myToSkipEmptyNodes = theToSkip; }
+ //! Return TRUE if all scenes in the document should be loaded, FALSE by default which means only main (default) scene will be loaded.
+ bool ToLoadAllScenes() const { return myToLoadAllScenes; }
+
+ //! Set flag to flag to load all scenes in the document, FALSE by default which means only main (default) scene will be loaded.
+ void SetLoadAllScenes (bool theToLoadAll) { myToLoadAllScenes = theToLoadAll; }
+
//! Set flag to use Mesh name in case if Node name is empty, TRUE by default.
bool ToUseMeshNameAsFallback() { return myUseMeshNameAsFallback; }
Standard_Boolean myToParallel; //!< flag to use multithreading; FALSE by default
Standard_Boolean myToSkipEmptyNodes; //!< ignore nodes without Geometry; TRUE by default
+ Standard_Boolean myToLoadAllScenes; //!< flag to load all scenes in the document, FALSE by default
Standard_Boolean myUseMeshNameAsFallback; //!< flag to use Mesh name in case if Node name is empty, TRUE by default
Standard_Boolean myIsDoublePrecision; //!< flag to fill in triangulation using single or double precision
Standard_Boolean myToSkipLateDataLoading; //!< flag to skip triangulation loading
myIsBinary (false),
myIsGltf1 (false),
myToSkipEmptyNodes (true),
+ myToLoadAllScenes (false),
myUseMeshNameAsFallback (true),
myToProbeHeader (false)
{
for (int aRootNameIter = 0; aRootNameIter < RWGltf_GltfRootElement_NB_MANDATORY; ++aRootNameIter)
{
- if (myGltfRoots[aRootNameIter].IsNull())
+ if (myGltfRoots[aRootNameIter].IsNull()
+ && aRootNameIter != RWGltf_GltfRootElement_Scene)
{
reportGltfError ("Member '" + RWGltf_GltfRootElementName ((RWGltf_GltfRootElement )aRootNameIter) + "' is not found.");
return false;
// =======================================================================
bool RWGltf_GltfJsonParser::gltfParseScene (const Message_ProgressRange& theProgress)
{
+ const RWGltf_JsonValue* aScenes = myGltfRoots[RWGltf_GltfRootElement_Scenes].Root();
+ if (myToLoadAllScenes
+ && !myIsGltf1
+ && aScenes->IsArray()
+ && aScenes->Size() > 1)
+ {
+ Message_ProgressScope aPS (theProgress, "Parsing scenes", aScenes->Size());
+ for (rapidjson::Value::ConstValueIterator aSceneIter = aScenes->Begin(); aSceneIter != aScenes->End(); ++aSceneIter)
+ {
+ if (!aPS.More())
+ {
+ return false;
+ }
+ Message_ProgressRange aRange = aPS.Next();
+ const RWGltf_JsonValue* aSceneNodes = findObjectMember (*aSceneIter, "nodes");
+ if (aSceneNodes == NULL
+ || !aSceneNodes->IsArray())
+ {
+ reportGltfWarning ("Empty scene '" + getKeyString (*aSceneIter) + "'.");
+ }
+ if (!gltfParseSceneNodes (*myRootShapes, *aSceneNodes, aRange))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
// search default scene
- const RWGltf_JsonValue* aDefScene = myGltfRoots[RWGltf_GltfRootElement_Scenes].FindChild (*myGltfRoots[RWGltf_GltfRootElement_Scene].Root());
+ const RWGltf_JsonValue* aDefScene = NULL;
+ if (!myGltfRoots[RWGltf_GltfRootElement_Scene].IsNull())
+ {
+ aDefScene = myGltfRoots[RWGltf_GltfRootElement_Scenes].FindChild (*myGltfRoots[RWGltf_GltfRootElement_Scene].Root());
+ }
+ else if (!myIsGltf1)
+ {
+ rapidjson::Value::ConstValueIterator aSceneIter = aScenes->Begin();
+ if (aSceneIter != aScenes->End())
+ {
+ aDefScene = aSceneIter;
+ reportGltfWarning ("Default scene is undefined, the first one will be loaded.");
+ }
+ }
if (aDefScene == NULL)
{
reportGltfError ("Default scene is not found.");
//! Set flag to ignore nodes without Geometry, TRUE by default.
void SetSkipEmptyNodes (bool theToSkip) { myToSkipEmptyNodes = theToSkip; }
+ //! Set flag to flag to load all scenes in the document, FALSE by default which means only main (default) scene will be loaded.
+ void SetLoadAllScenes (bool theToLoadAll) { myToLoadAllScenes = theToLoadAll; }
+
//! Set flag to use Mesh name in case if Node name is empty, TRUE by default.
void SetMeshNameAsFallback (bool theToFallback) { myUseMeshNameAsFallback = theToFallback; }
bool myIsBinary; //!< binary document
bool myIsGltf1; //!< obsolete glTF 1.0 version format
bool myToSkipEmptyNodes; //!< ignore nodes without Geometry
+ bool myToLoadAllScenes; //!< flag to load all scenes in the document, FALSE by default
bool myUseMeshNameAsFallback; //!< flag to use Mesh name in case if Node name is empty, TRUE by default
bool myToProbeHeader; //!< flag to probe header without full reading, FALSE by default
{
RWGltf_GltfRootElement_Asset, //!< "asset" element, mandatory
RWGltf_GltfRootElement_Scenes, //!< "scenes" element, mandatory
- RWGltf_GltfRootElement_Scene, //!< "scene" element, mandatory
+ RWGltf_GltfRootElement_Scene, //!< "scene" element, optional
RWGltf_GltfRootElement_Nodes, //!< "nodes" element, mandatory
RWGltf_GltfRootElement_Meshes, //!< "meshes" element, mandatory
RWGltf_GltfRootElement_Accessors, //!< "accessors" element, mandatory
Standard_Boolean toSkipLateDataLoading = Standard_False;
Standard_Boolean toKeepLateData = Standard_True;
Standard_Boolean toPrintDebugInfo = Standard_False;
+ Standard_Boolean toLoadAllScenes = Standard_False;
Standard_Boolean isNoDoc = (TCollection_AsciiString(theArgVec[0]) == "readgltf");
for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
{
++anArgIter;
}
}
+ else if (anArgCase == "-allscenes")
+ {
+ toLoadAllScenes = Standard_True;
+ if (anArgIter + 1 < theNbArgs
+ && Draw::ParseOnOff (theArgVec[anArgIter + 1], toLoadAllScenes))
+ {
+ ++anArgIter;
+ }
+ }
else if (anArgCase == "-toprintinfo"
|| anArgCase == "-toprintdebuginfo")
{
aReader.SetToSkipLateDataLoading (toSkipLateDataLoading);
aReader.SetToKeepLateData (toKeepLateData);
aReader.SetToPrintDebugMessages (toPrintDebugInfo);
+ aReader.SetLoadAllScenes (toLoadAllScenes);
if (toListExternalFiles)
{
aReader.ProbeHeader (aFilePath);
"\n\t\t: (false by default)"
"\n\t\t: -keepLate data is loaded into itself with preservation of information"
"\n\t\t: about deferred storage to load/unload this data later.",
+ "\n\t\t: -allScenes load all scenes defined in the document instead of default one (false by default)"
"\n\t\t: -toPrintDebugInfo print additional debug information during data reading"
__FILE__, ReadGltf, g);
theCommands.Add ("readgltf",