forked from AcademySoftwareFoundation/MaterialX
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Datalibrary into seperate h/cpp
- Loading branch information
1 parent
62434e7
commit 8d78fbc
Showing
7 changed files
with
114 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// | ||
// Copyright Contributors to the MaterialX Project | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include <MaterialXCore/Document.h> | ||
#include <MaterialXCore/Datalibrary.h> | ||
|
||
MATERIALX_NAMESPACE_BEGIN | ||
|
||
const DataLibraryPtr standardDataLibrary = DataLibrary::create(); | ||
|
||
DataLibraryPtr DataLibrary::create() | ||
{ | ||
return std::make_shared<DataLibrary>(); | ||
} | ||
|
||
// use loadDocuments to build this vector | ||
void DataLibrary::loadDataLibrary(vector<DocumentPtr>& librarydocuments) | ||
{ | ||
_datalibrary = createDocument(); | ||
|
||
for (auto library : librarydocuments) | ||
{ | ||
for (auto child : library->getChildren()) | ||
{ | ||
if (child->getCategory().empty()) | ||
{ | ||
throw Exception("Trying to import child without a category: " + child->getName()); | ||
} | ||
|
||
const string childName = child->getQualifiedName(child->getName()); | ||
|
||
// Check for duplicate elements. | ||
ConstElementPtr previous = _datalibrary->getChild(childName); | ||
if (previous) | ||
{ | ||
continue; | ||
} | ||
|
||
// Create the imported element. | ||
ElementPtr childCopy = _datalibrary->addChildOfCategory(child->getCategory(), childName); | ||
childCopy->copyContentFrom(child); | ||
if (!childCopy->hasFilePrefix() && library->hasFilePrefix()) | ||
{ | ||
childCopy->setFilePrefix(library->getFilePrefix()); | ||
} | ||
if (!childCopy->hasGeomPrefix() && library->hasGeomPrefix()) | ||
{ | ||
childCopy->setGeomPrefix(library->getGeomPrefix()); | ||
} | ||
if (!childCopy->hasColorSpace() && library->hasColorSpace()) | ||
{ | ||
childCopy->setColorSpace(library->getColorSpace()); | ||
} | ||
if (!childCopy->hasNamespace() && library->hasNamespace()) | ||
{ | ||
childCopy->setNamespace(library->getNamespace()); | ||
} | ||
if (!childCopy->hasSourceUri() && library->hasSourceUri()) | ||
{ | ||
childCopy->setSourceUri(library->getSourceUri()); | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
|
||
MATERIALX_NAMESPACE_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// Copyright Contributors to the MaterialX Project | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#ifndef MATERIALX_DATALIBRARY | ||
#define MATERIALX_DATALIBRARY | ||
|
||
/// @file | ||
/// The top-level DataLibrary class | ||
|
||
#include <MaterialXCore/Document.h> | ||
|
||
MATERIALX_NAMESPACE_BEGIN | ||
|
||
class DataLibrary; | ||
using DataLibraryPtr = shared_ptr<DataLibrary>; | ||
using ConstDataLibraryPtr = shared_ptr<const DataLibrary>; | ||
|
||
class MX_CORE_API DataLibrary | ||
{ | ||
public: | ||
ConstDocumentPtr dataLibrary() | ||
{ | ||
return _datalibrary; | ||
} | ||
|
||
void loadDataLibrary(vector<DocumentPtr>& documents); | ||
|
||
static DataLibraryPtr create(); | ||
|
||
private: | ||
// Shared node library used across documents. | ||
DocumentPtr _datalibrary; | ||
}; | ||
|
||
extern MX_CORE_API const DataLibraryPtr standardDataLibrary; | ||
|
||
MATERIALX_NAMESPACE_END | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters