MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / deserializeObjectTreeFromFolder

Function deserializeObjectTreeFromFolder

source/MRMesh/MRObjectLoad.cpp:565–661  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

563}
564
565Expected<LoadedObject> deserializeObjectTreeFromFolder( const std::filesystem::path& folder,
566 const ProgressCallback& progressCb )
567{
568 MR_TIMER;
569
570 std::error_code ec;
571 std::filesystem::path jsonFile;
572 for ( auto entry : Directory{ folder, ec } )
573 {
574 // unlike extension() this works even if full file name is simply ".json"
575 if ( entry.path().u8string().ends_with( u8".json" ) )
576 {
577 jsonFile = entry.path();
578 break;
579 }
580 }
581
582 auto readRes = deserializeJsonValue( jsonFile );
583 if( !readRes.has_value() )
584 {
585 return unexpected( readRes.error() );
586 }
587 auto root = readRes.value();
588 if ( auto formatVersion = root["FormatVersion"]; formatVersion.isNumeric() && formatVersion.asDouble() >= 2 )
589 {
590 return unexpected( "Unsupported version of scene file. Please update your application." );
591 }
592
593 LoadedObject res;
594 if ( auto lengthUnits = root["LengthUnits"]; lengthUnits.isString() )
595 {
596 auto lengthUnitsStr = lengthUnits.asString();
597 for ( int i = 0; i < (int)LengthUnit::_count; ++i )
598 if ( lengthUnitsStr == getUnitInfo( (LengthUnit)i ).prettyName )
599 {
600 res.lengthUnit = (LengthUnit)i;
601 break;
602 }
603 }
604
605 auto typeTreeSize = root["Type"].size();
606 for (int i = typeTreeSize-1;i>=0;--i)
607 {
608 const auto& type = root["Type"][unsigned( i )];
609 if ( type.isString() )
610 res.obj = createObject( type.asString() );
611 if ( res.obj )
612 break;
613 }
614 if ( !res.obj )
615 return unexpected( "Unknown root object type" );
616
617 int modelNumber{ 0 };
618 int modelCounter{ 0 };
619 auto cb = progressCb;
620 if ( progressCb )
621 {
622 std::function<int( const Json::Value& )> calculateModelNum = [&calculateModelNum] ( const Json::Value& root )

Callers 1

deserializeObjectTreeFunction · 0.85

Calls 8

deserializeJsonValueFunction · 0.85
createObjectFunction · 0.85
maxFunction · 0.85
errorMethod · 0.80
deserializeRecursiveMethod · 0.80
unexpectedFunction · 0.70
valueMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected