Skip to content

Commit

Permalink
Master to dev merge (Aug 13-26, 2019) (#603)
Browse files Browse the repository at this point in the history
* Value construction from C-style strings

This changelist adds support for value construction from C-style strings and string literals.  Previously, it was only possible to construct a value of string type from a standard string.

(cherry picked from commit a122074)

* Move shading model to property editor

Move the new shading model display from the main viewer to the property editor, and refactor a few smaller details within the editor source file.

* Fixes for static analysis warnings

* 02b0dc8

* Added python bindings for TypeDesc (#284)

Fixed missing base class for DefaultColorManagement python binding

* Align includes and formatting in MaterialXRender

This changelist adjusts the includes and formatting in MaterialXRender for consistency with other MaterialX modules.

Specific changes include:

- Merged the ExceptionShaderValidationError class into the ShaderValidator source files.
- Adjusted header includes for consistency.
- Adjusted comments and whitespace for consistency.
- Minor const correctness fixes.

* Merge fixes.

* More merge fixes.
  • Loading branch information
bernardkwok authored Aug 26, 2019
1 parent 78f3923 commit 6f2e412
Show file tree
Hide file tree
Showing 79 changed files with 657 additions and 645 deletions.
Binary file not shown.
Binary file added documents/Specification/MaterialX.v1.37.Spec.pdf
Binary file not shown.
Binary file not shown.
Binary file removed documents/Specification/ShaderX.Draft.pdf
Binary file not shown.
21 changes: 17 additions & 4 deletions source/MaterialXContrib/MaterialXMaya/ShadingNodeOverrides.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,25 @@ MStatus bindFileTexture(MHWRender::MShaderInstance& shader,
mTilePositions.append(udimCoordinates[i][0]);
mTilePositions.append(udimCoordinates[i][1]);
}
const unsigned int UDIM_BAKE_WIDTH = 4096;
const unsigned int UDIM_BAKE_HEIGHT = 4096;
mx::Vector2 scaleUV;
mx::Vector2 offsetUV;
mx::getUdimScaleAndOffset(udimCoordinates, scaleUV, offsetUV);

unsigned int udimBakeWidth = 4096;
unsigned int udimBakeHeight = 4096;
float ratio = scaleUV[1] / scaleUV[0];
if (ratio > 1.0)
{
udimBakeHeight = static_cast<unsigned int>(std::truncf(static_cast<float>(udimBakeHeight) * ratio));
}
else
{
udimBakeWidth = static_cast<unsigned int>(std::truncf(static_cast<float>(udimBakeWidth) * ratio));
}
// Note: we do not use the uv scale and offset. Ideally this should be used for the texture lookup code
// but at this point the shader code has already been generated.
texturePtr.reset(textureManager->acquireTiledTexture(fileName.c_str(), mTilePaths, mTilePositions,
undefinedColor, UDIM_BAKE_WIDTH, UDIM_BAKE_HEIGHT,
undefinedColor, udimBakeWidth, udimBakeHeight,
failedTilePaths, uvScaleOffset));
}
else
Expand Down Expand Up @@ -246,7 +259,7 @@ void ShadingNodeOverride<BASE>::updateShader(MHWRender::MShaderInstance& shader,

// Set up image file name search path.
mx::FilePath documentPath(node->getDocumentFilePath().asChar());
documentPath.pop();
documentPath = documentPath.getParentPath();
mx::FileSearchPath imageSearchPath = Plugin::instance().getResourceSearchPath();
imageSearchPath.prepend(documentPath);

Expand Down
13 changes: 13 additions & 0 deletions source/MaterialXCore/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,19 @@ void Document::importLibrary(const ConstDocumentPtr& library, const CopyOptions*
}
}

StringSet Document::getReferencedSourceUris() const
{
StringSet sourceUris;
for (ElementPtr elem : traverseTree())
{
if (elem->hasSourceUri())
{
sourceUris.insert(elem->getSourceUri());
}
}
return sourceUris;
}

std::pair<int, int> Document::getVersionIntegers() const
{
if (!hasVersionString())
Expand Down
3 changes: 3 additions & 0 deletions source/MaterialXCore/Document.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ class Document : public GraphElement
/// import function. Defaults to a null pointer.
void importLibrary(const ConstDocumentPtr& library, const CopyOptions* copyOptions = nullptr);

/// Get a list of source URI's referenced by the document
StringSet getReferencedSourceUris() const;

/// @}
/// @name NodeGraph Elements
/// @{
Expand Down
23 changes: 11 additions & 12 deletions source/MaterialXCore/Element.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class Element : public std::enable_shared_from_this<Element>
}
public:
virtual ~Element() { }
Element(const Element&) = delete;
Element& operator=(const Element&) = delete;

protected:
using DocumentPtr = shared_ptr<Document>;
Expand Down Expand Up @@ -447,10 +449,7 @@ class Element : public std::enable_shared_from_this<Element>
ElementPtr getChild(const string& name) const
{
ElementMap::const_iterator it = _childMap.find(name);
if (it == _childMap.end())
return ElementPtr();
else
return it->second;
return (it != _childMap.end()) ? it->second : ElementPtr();
}

/// Return the child element, if any, with the given name and subclass.
Expand Down Expand Up @@ -525,10 +524,7 @@ class Element : public std::enable_shared_from_this<Element>
const string& getAttribute(const string& attrib) const
{
StringMap::const_iterator it = _attributeMap.find(attrib);
if (it == _attributeMap.end())
return EMPTY_STRING;
else
return it->second;
return (it != _attributeMap.end()) ? it->second : EMPTY_STRING;
}

/// Return a vector of stored attribute names, in the order they were set.
Expand All @@ -548,7 +544,7 @@ class Element : public std::enable_shared_from_this<Element>
/// Return the the value of an implicitly typed attribute. If the given
/// attribute is not present, or cannot be converted to the given data
/// type, then the zero value for the data type is returned.
template<class T> const T getTypedAttribute(const string& attrib) const
template<class T> T getTypedAttribute(const string& attrib) const
{
try
{
Expand Down Expand Up @@ -870,9 +866,6 @@ class Element : public std::enable_shared_from_this<Element>
weak_ptr<Element> _root;

private:
Element(const Element&) = delete;
Element& operator=(const Element&) = delete;

template <class T> static ElementPtr createElement(ElementPtr parent, const string& name)
{
return std::make_shared<T>(parent, name);
Expand Down Expand Up @@ -1037,6 +1030,12 @@ class ValueElement : public TypedElement
setValueString(toValueString(value));
}

/// Set the typed value of an element from a C-style string.
void setValue(const char* value, const string& type = EMPTY_STRING)
{
setValue(value ? string(value) : EMPTY_STRING, type);
}

/// Return true if the element possesses a typed value.
bool hasValue() const
{
Expand Down
2 changes: 0 additions & 2 deletions source/MaterialXCore/Library.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,11 @@ class Exception : public std::exception
{
public:
explicit Exception(const string& msg) :
std::exception(),
_msg(msg)
{
}

Exception(const Exception& e) :
std::exception(),
_msg(e._msg)
{
}
Expand Down
6 changes: 3 additions & 3 deletions source/MaterialXCore/Value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ template <class T> class is_std_vector< vector<T> > : public std::true_type { };
template <class T> using enable_if_std_vector_t =
typename std::enable_if<is_std_vector<T>::value, T>::type;

template <class T> void stringToData(const string& value, T& data)
template <class T> void stringToData(const string& str, T& data)
{
std::stringstream ss(value);
std::stringstream ss(str);
if (!(ss >> data))
{
throw ExceptionTypeError("Type mismatch in generic stringToData: " + value);
throw ExceptionTypeError("Type mismatch in generic stringToData: " + str);
}
}

Expand Down
7 changes: 7 additions & 0 deletions source/MaterialXCore/Value.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <MaterialXCore/Library.h>

#include <MaterialXCore/Types.h>
#include <MaterialXCore/Util.h>

namespace MaterialX
{
Expand Down Expand Up @@ -49,6 +50,12 @@ class Value
return std::make_shared< TypedValue<T> >(data);
}

// Create a new value from a C-style string.
static ValuePtr createValue(const char* data)
{
return createValue(data ? string(data) : EMPTY_STRING);
}

/// Create a new value instance from value and type strings.
/// @return A shared pointer to a typed value, or an empty shared pointer
/// if the conversion to the given data type cannot be performed.
Expand Down
36 changes: 9 additions & 27 deletions source/MaterialXFormat/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
namespace MaterialX
{

const string VALID_SEPARATORS_WINDOWS = "/\\";
const string VALID_SEPARATORS_POSIX = "/";
const string VALID_SEPARATORS = "/\\";

const char PREFERRED_SEPARATOR_WINDOWS = '\\';
const char PREFERRED_SEPARATOR_POSIX = '/';
Expand All @@ -42,13 +41,17 @@ const string MATERIALX_SEARCH_PATH_ENV_VAR = "MATERIALX_SEARCH_PATH";
// FilePath methods
//

void FilePath::assign(const string& str, Format format)
void FilePath::assign(const string& str)
{
_type = TypeRelative;
if (format == FormatWindows)
_vec = splitString(str, VALID_SEPARATORS);
if (!str.empty())
{
_vec = splitString(str, VALID_SEPARATORS_WINDOWS);
if (str.size() >= 2)
if (str[0] == PREFERRED_SEPARATOR_POSIX)
{
_type = TypeAbsolute;
}
else if (str.size() >= 2)
{
if (std::isalpha(str[0]) && str[1] == ':')
{
Expand All @@ -60,15 +63,6 @@ void FilePath::assign(const string& str, Format format)
}
}
}
else
{
_vec = splitString(str, VALID_SEPARATORS_POSIX);
if (!str.empty() && str[0] == PREFERRED_SEPARATOR_POSIX)
{
_type = TypeAbsolute;
}
}
_format = format;
}

string FilePath::asString(Format format) const
Expand Down Expand Up @@ -109,10 +103,6 @@ FilePath FilePath::operator/(const FilePath& rhs) const
{
throw Exception("Appended path must be relative.");
}
if (_format != rhs._format)
{
throw Exception("Appended path must have the same format.");
}

FilePath combined(*this);
for (const string& str : rhs._vec)
Expand All @@ -122,14 +112,6 @@ FilePath FilePath::operator/(const FilePath& rhs) const
return combined;
}

void FilePath::pop()
{
if (!isEmpty())
{
_vec.pop_back();
}
}

bool FilePath::exists() const
{
#if defined(_WIN32)
Expand Down
Loading

0 comments on commit 6f2e412

Please sign in to comment.