mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-09 18:50:54 +03:00
0032989: Data Exchange, RWGltf_CafReader - fill in metadata map from asset.extras
This commit is contained in:
parent
812afe4edb
commit
e9c43fee29
@ -188,7 +188,8 @@ RWGltf_GltfJsonParser::RWGltf_GltfJsonParser (TopTools_SequenceOfShape& theRootS
|
|||||||
myToSkipEmptyNodes (true),
|
myToSkipEmptyNodes (true),
|
||||||
myToLoadAllScenes (false),
|
myToLoadAllScenes (false),
|
||||||
myUseMeshNameAsFallback (true),
|
myUseMeshNameAsFallback (true),
|
||||||
myToProbeHeader (false)
|
myToProbeHeader (false),
|
||||||
|
myToReadAssetExtras (true)
|
||||||
{
|
{
|
||||||
myCSTrsf.SetInputLengthUnit (1.0); // meters
|
myCSTrsf.SetInputLengthUnit (1.0); // meters
|
||||||
myCSTrsf.SetInputCoordinateSystem (RWMesh_CoordinateSystem_glTF);
|
myCSTrsf.SetInputCoordinateSystem (RWMesh_CoordinateSystem_glTF);
|
||||||
@ -287,6 +288,27 @@ void RWGltf_GltfJsonParser::gltfParseAsset()
|
|||||||
myMetadata->Add ("copyright", aCopyRight->GetString());
|
myMetadata->Add ("copyright", aCopyRight->GetString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (const RWGltf_JsonValue* anExtras = myToReadAssetExtras ? findObjectMember (*anAsset, "extras") : nullptr)
|
||||||
|
{
|
||||||
|
for (ConstMemberIterator aChildIter = anExtras->MemberBegin(); aChildIter != anExtras->MemberEnd(); ++aChildIter)
|
||||||
|
{
|
||||||
|
if (!aChildIter->name.IsString())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const TCollection_AsciiString aKey (aChildIter->name.GetString());
|
||||||
|
if (aChildIter->value.IsString())
|
||||||
|
{
|
||||||
|
myMetadata->Add (aKey, aChildIter->value.GetString());
|
||||||
|
}
|
||||||
|
if (aChildIter->value.IsNumber())
|
||||||
|
{
|
||||||
|
myMetadata->Add (aKey, aChildIter->value.GetDouble());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
|
@ -94,6 +94,9 @@ public:
|
|||||||
//! Set metadata map.
|
//! Set metadata map.
|
||||||
void SetMetadata (TColStd_IndexedDataMapOfStringString& theMetadata) { myMetadata = &theMetadata; }
|
void SetMetadata (TColStd_IndexedDataMapOfStringString& theMetadata) { myMetadata = &theMetadata; }
|
||||||
|
|
||||||
|
//! Set flag to translate asset.extras into metadata.
|
||||||
|
void SetReadAssetExtras (bool theToRead) { myToReadAssetExtras = theToRead; }
|
||||||
|
|
||||||
//! Return transformation from glTF to OCCT coordinate system.
|
//! Return transformation from glTF to OCCT coordinate system.
|
||||||
const RWMesh_CoordinateSystemConverter& CoordinateSystemConverter() const { return myCSTrsf; }
|
const RWMesh_CoordinateSystemConverter& CoordinateSystemConverter() const { return myCSTrsf; }
|
||||||
|
|
||||||
@ -439,6 +442,7 @@ protected:
|
|||||||
bool myToLoadAllScenes; //!< flag to load all scenes in the document, FALSE by default
|
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 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
|
bool myToProbeHeader; //!< flag to probe header without full reading, FALSE by default
|
||||||
|
bool myToReadAssetExtras; //!< flag to translate asset.extras into metadata, TRUE by default
|
||||||
|
|
||||||
#ifdef HAVE_RAPIDJSON
|
#ifdef HAVE_RAPIDJSON
|
||||||
GltfElementMap myGltfRoots[RWGltf_GltfRootElement_NB]; //!< glTF format root elements
|
GltfElementMap myGltfRoots[RWGltf_GltfRootElement_NB]; //!< glTF format root elements
|
||||||
|
@ -194,6 +194,7 @@ static Standard_Integer ReadGltf (Draw_Interpretor& theDI,
|
|||||||
Standard_Boolean toKeepLateData = Standard_True;
|
Standard_Boolean toKeepLateData = Standard_True;
|
||||||
Standard_Boolean toPrintDebugInfo = Standard_False;
|
Standard_Boolean toPrintDebugInfo = Standard_False;
|
||||||
Standard_Boolean toLoadAllScenes = Standard_False;
|
Standard_Boolean toLoadAllScenes = Standard_False;
|
||||||
|
Standard_Boolean toPrintAssetInfo = Standard_False;
|
||||||
Standard_Boolean isNoDoc = (TCollection_AsciiString(theArgVec[0]) == "readgltf");
|
Standard_Boolean isNoDoc = (TCollection_AsciiString(theArgVec[0]) == "readgltf");
|
||||||
for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
|
for (Standard_Integer anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
|
||||||
{
|
{
|
||||||
@ -203,33 +204,18 @@ static Standard_Integer ReadGltf (Draw_Interpretor& theDI,
|
|||||||
&& (anArgCase == "-nocreate"
|
&& (anArgCase == "-nocreate"
|
||||||
|| anArgCase == "-nocreatedoc"))
|
|| anArgCase == "-nocreatedoc"))
|
||||||
{
|
{
|
||||||
toUseExistingDoc = Standard_True;
|
toUseExistingDoc = Draw::ParseOnOffIterator (theNbArgs, theArgVec, anArgIter);
|
||||||
if (anArgIter + 1 < theNbArgs
|
|
||||||
&& Draw::ParseOnOff (theArgVec[anArgIter + 1], toUseExistingDoc))
|
|
||||||
{
|
|
||||||
++anArgIter;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (anArgCase == "-parallel")
|
else if (anArgCase == "-parallel")
|
||||||
{
|
{
|
||||||
isParallel = Standard_True;
|
isParallel = Draw::ParseOnOffIterator (theNbArgs, theArgVec, anArgIter);
|
||||||
if (anArgIter + 1 < theNbArgs
|
|
||||||
&& Draw::ParseOnOff (theArgVec[anArgIter + 1], isParallel))
|
|
||||||
{
|
|
||||||
++anArgIter;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (anArgCase == "-doubleprec"
|
else if (anArgCase == "-doubleprec"
|
||||||
|| anArgCase == "-doubleprecision"
|
|| anArgCase == "-doubleprecision"
|
||||||
|| anArgCase == "-singleprec"
|
|| anArgCase == "-singleprec"
|
||||||
|| anArgCase == "-singleprecision")
|
|| anArgCase == "-singleprecision")
|
||||||
{
|
{
|
||||||
isDoublePrec = Standard_True;
|
isDoublePrec = Draw::ParseOnOffIterator (theNbArgs, theArgVec, anArgIter);
|
||||||
if (anArgIter + 1 < theNbArgs
|
|
||||||
&& Draw::ParseOnOff (theArgVec[anArgIter + 1], isDoublePrec))
|
|
||||||
{
|
|
||||||
++anArgIter;
|
|
||||||
}
|
|
||||||
if (anArgCase.StartsWith ("-single"))
|
if (anArgCase.StartsWith ("-single"))
|
||||||
{
|
{
|
||||||
isDoublePrec = !isDoublePrec;
|
isDoublePrec = !isDoublePrec;
|
||||||
@ -237,40 +223,20 @@ static Standard_Integer ReadGltf (Draw_Interpretor& theDI,
|
|||||||
}
|
}
|
||||||
else if (anArgCase == "-skiplateloading")
|
else if (anArgCase == "-skiplateloading")
|
||||||
{
|
{
|
||||||
toSkipLateDataLoading = Standard_True;
|
toSkipLateDataLoading = Draw::ParseOnOffIterator (theNbArgs, theArgVec, anArgIter);
|
||||||
if (anArgIter + 1 < theNbArgs
|
|
||||||
&& Draw::ParseOnOff (theArgVec[anArgIter + 1], toSkipLateDataLoading))
|
|
||||||
{
|
|
||||||
++anArgIter;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (anArgCase == "-keeplate")
|
else if (anArgCase == "-keeplate")
|
||||||
{
|
{
|
||||||
toKeepLateData = Standard_True;
|
toKeepLateData = Draw::ParseOnOffIterator (theNbArgs, theArgVec, anArgIter);
|
||||||
if (anArgIter + 1 < theNbArgs
|
|
||||||
&& Draw::ParseOnOff (theArgVec[anArgIter + 1], toKeepLateData))
|
|
||||||
{
|
|
||||||
++anArgIter;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (anArgCase == "-allscenes")
|
else if (anArgCase == "-allscenes")
|
||||||
{
|
{
|
||||||
toLoadAllScenes = Standard_True;
|
toLoadAllScenes = Draw::ParseOnOffIterator (theNbArgs, theArgVec, anArgIter);
|
||||||
if (anArgIter + 1 < theNbArgs
|
|
||||||
&& Draw::ParseOnOff (theArgVec[anArgIter + 1], toLoadAllScenes))
|
|
||||||
{
|
|
||||||
++anArgIter;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (anArgCase == "-toprintinfo"
|
else if (anArgCase == "-toprintinfo"
|
||||||
|| anArgCase == "-toprintdebuginfo")
|
|| anArgCase == "-toprintdebuginfo")
|
||||||
{
|
{
|
||||||
toPrintDebugInfo = Standard_True;
|
toPrintDebugInfo = Draw::ParseOnOffIterator (theNbArgs, theArgVec, anArgIter);
|
||||||
if (anArgIter + 1 < theNbArgs
|
|
||||||
&& Draw::ParseOnOff (theArgVec[anArgIter + 1], toPrintDebugInfo))
|
|
||||||
{
|
|
||||||
++anArgIter;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (anArgCase == "-listexternalfiles"
|
else if (anArgCase == "-listexternalfiles"
|
||||||
|| anArgCase == "-listexternals"
|
|| anArgCase == "-listexternals"
|
||||||
@ -278,7 +244,12 @@ static Standard_Integer ReadGltf (Draw_Interpretor& theDI,
|
|||||||
|| anArgCase == "-external"
|
|| anArgCase == "-external"
|
||||||
|| anArgCase == "-externalfiles")
|
|| anArgCase == "-externalfiles")
|
||||||
{
|
{
|
||||||
toListExternalFiles = Standard_True;
|
toListExternalFiles = Draw::ParseOnOffIterator (theNbArgs, theArgVec, anArgIter);
|
||||||
|
}
|
||||||
|
else if (anArgCase == "-assetinfo"
|
||||||
|
|| anArgCase == "-metadata")
|
||||||
|
{
|
||||||
|
toPrintAssetInfo = Draw::ParseOnOffIterator (theNbArgs, theArgVec, anArgIter);
|
||||||
}
|
}
|
||||||
else if (aDestName.IsEmpty())
|
else if (aDestName.IsEmpty())
|
||||||
{
|
{
|
||||||
@ -294,6 +265,13 @@ static Standard_Integer ReadGltf (Draw_Interpretor& theDI,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (aFilePath.IsEmpty() && !aDestName.IsEmpty())
|
||||||
|
{
|
||||||
|
if (toListExternalFiles || toPrintAssetInfo)
|
||||||
|
{
|
||||||
|
std::swap (aFilePath, aDestName);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (aFilePath.IsEmpty())
|
if (aFilePath.IsEmpty())
|
||||||
{
|
{
|
||||||
Message::SendFail() << "Syntax error: wrong number of arguments";
|
Message::SendFail() << "Syntax error: wrong number of arguments";
|
||||||
@ -302,7 +280,7 @@ static Standard_Integer ReadGltf (Draw_Interpretor& theDI,
|
|||||||
|
|
||||||
Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI, 1);
|
Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (theDI, 1);
|
||||||
Handle(TDocStd_Document) aDoc;
|
Handle(TDocStd_Document) aDoc;
|
||||||
if (!toListExternalFiles
|
if (!aDestName.IsEmpty()
|
||||||
&& !isNoDoc)
|
&& !isNoDoc)
|
||||||
{
|
{
|
||||||
Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
|
Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
|
||||||
@ -323,12 +301,14 @@ static Standard_Integer ReadGltf (Draw_Interpretor& theDI,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Standard_Real aScaleFactorM = 1.;
|
Standard_Real aScaleFactorM = 1.;
|
||||||
if (!XCAFDoc_DocumentTool::GetLengthUnit(aDoc, aScaleFactorM, UnitsMethods_LengthUnit_Meter))
|
if (!XCAFDoc_DocumentTool::GetLengthUnit(aDoc, aScaleFactorM, UnitsMethods_LengthUnit_Meter))
|
||||||
{
|
{
|
||||||
XSAlgo::AlgoContainer()->PrepareForTransfer(); // update unit info
|
XSAlgo::AlgoContainer()->PrepareForTransfer(); // update unit info
|
||||||
aScaleFactorM = UnitsMethods::GetCasCadeLengthUnit(UnitsMethods_LengthUnit_Meter);
|
aScaleFactorM = UnitsMethods::GetCasCadeLengthUnit(UnitsMethods_LengthUnit_Meter);
|
||||||
}
|
}
|
||||||
|
|
||||||
RWGltf_CafReader aReader;
|
RWGltf_CafReader aReader;
|
||||||
aReader.SetSystemLengthUnit (aScaleFactorM);
|
aReader.SetSystemLengthUnit (aScaleFactorM);
|
||||||
aReader.SetSystemCoordinateSystem (RWMesh_CoordinateSystem_Zup);
|
aReader.SetSystemCoordinateSystem (RWMesh_CoordinateSystem_Zup);
|
||||||
@ -339,13 +319,9 @@ static Standard_Integer ReadGltf (Draw_Interpretor& theDI,
|
|||||||
aReader.SetToKeepLateData (toKeepLateData);
|
aReader.SetToKeepLateData (toKeepLateData);
|
||||||
aReader.SetToPrintDebugMessages (toPrintDebugInfo);
|
aReader.SetToPrintDebugMessages (toPrintDebugInfo);
|
||||||
aReader.SetLoadAllScenes (toLoadAllScenes);
|
aReader.SetLoadAllScenes (toLoadAllScenes);
|
||||||
if (toListExternalFiles)
|
if (aDestName.IsEmpty())
|
||||||
{
|
{
|
||||||
aReader.ProbeHeader (aFilePath);
|
aReader.ProbeHeader (aFilePath);
|
||||||
for (NCollection_IndexedMap<TCollection_AsciiString>::Iterator aFileIter (aReader.ExternalFiles()); aFileIter.More(); aFileIter.Next())
|
|
||||||
{
|
|
||||||
theDI << "\"" << aFileIter.Value() << "\" ";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -361,6 +337,32 @@ static Standard_Integer ReadGltf (Draw_Interpretor& theDI,
|
|||||||
Draw::Set (aDestName.ToCString(), aDrawDoc);
|
Draw::Set (aDestName.ToCString(), aDrawDoc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isFirstLine = true;
|
||||||
|
if (toPrintAssetInfo)
|
||||||
|
{
|
||||||
|
for (TColStd_IndexedDataMapOfStringString::Iterator aKeyIter (aReader.Metadata()); aKeyIter.More(); aKeyIter.Next())
|
||||||
|
{
|
||||||
|
if (!isFirstLine)
|
||||||
|
{
|
||||||
|
theDI << "\n";
|
||||||
|
}
|
||||||
|
isFirstLine = false;
|
||||||
|
theDI << aKeyIter.Key() << ": " << aKeyIter.Value();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (toListExternalFiles)
|
||||||
|
{
|
||||||
|
if (!isFirstLine)
|
||||||
|
{
|
||||||
|
theDI << "\n";
|
||||||
|
}
|
||||||
|
for (NCollection_IndexedMap<TCollection_AsciiString>::Iterator aFileIter (aReader.ExternalFiles()); aFileIter.More(); aFileIter.Next())
|
||||||
|
{
|
||||||
|
theDI << "\"" << aFileIter.Value() << "\" ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2338,7 +2340,7 @@ void XSDRAWSTLVRML::InitCommands (Draw_Interpretor& theCommands)
|
|||||||
//XSDRAW::LoadDraw(theCommands);
|
//XSDRAW::LoadDraw(theCommands);
|
||||||
|
|
||||||
theCommands.Add ("ReadGltf",
|
theCommands.Add ("ReadGltf",
|
||||||
"ReadGltf Doc file [-parallel {on|off}] [-listExternalFiles] [-noCreateDoc] [-doublePrecision {on|off}]"
|
"ReadGltf Doc file [-parallel {on|off}] [-listExternalFiles] [-noCreateDoc] [-doublePrecision {on|off}] [-assetInfo]"
|
||||||
"\n\t\t: Read glTF file into XDE document."
|
"\n\t\t: Read glTF file into XDE document."
|
||||||
"\n\t\t: -listExternalFiles do not read mesh and only list external files"
|
"\n\t\t: -listExternalFiles do not read mesh and only list external files"
|
||||||
"\n\t\t: -noCreateDoc read into existing XDE document"
|
"\n\t\t: -noCreateDoc read into existing XDE document"
|
||||||
@ -2347,9 +2349,10 @@ void XSDRAWSTLVRML::InitCommands (Draw_Interpretor& theCommands)
|
|||||||
"\n\t\t: -skipLateLoading data loading is skipped and can be performed later"
|
"\n\t\t: -skipLateLoading data loading is skipped and can be performed later"
|
||||||
"\n\t\t: (false by default)"
|
"\n\t\t: (false by default)"
|
||||||
"\n\t\t: -keepLate data is loaded into itself with preservation of information"
|
"\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: 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: -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"
|
"\n\t\t: -toPrintDebugInfo print additional debug information during data reading"
|
||||||
|
"\n\t\t: -assetInfo print asset information",
|
||||||
__FILE__, ReadGltf, g);
|
__FILE__, ReadGltf, g);
|
||||||
theCommands.Add ("readgltf",
|
theCommands.Add ("readgltf",
|
||||||
"readgltf shape file"
|
"readgltf shape file"
|
||||||
|
@ -3,6 +3,10 @@ puts "0030691: test glTF reader on standard sample models"
|
|||||||
puts "========"
|
puts "========"
|
||||||
|
|
||||||
ReadGltf D [locate_data_file bug30691_DamagedHelmet.gltf]
|
ReadGltf D [locate_data_file bug30691_DamagedHelmet.gltf]
|
||||||
|
|
||||||
|
set anAssetInfo [ReadGltf [locate_data_file bug30691_DamagedHelmet.gltf] -assetInfo]
|
||||||
|
if { "$anAssetInfo" != "generator: Khronos Blender glTF 2.0 exporter" } { puts "Error: unexpected asset info" }
|
||||||
|
|
||||||
XGetOneShape s D
|
XGetOneShape s D
|
||||||
checknbshapes s -face 1 -compound 0
|
checknbshapes s -face 1 -compound 0
|
||||||
checktrinfo s -tri 15452 -nod 14556
|
checktrinfo s -tri 15452 -nod 14556
|
||||||
|
Loading…
x
Reference in New Issue
Block a user