Convert a MaterialX document object to a Protobuf MaterialXDocument message.
29 def convert(self, doc):
30 """
31 @brief Convert a MaterialX document object to a Protobuf MaterialXDocument message.
32 @param doc The MaterialX document object to convert.
33 @return The resulting Protobuf MaterialXDocument message.
34 """
35 pb_doc = pb.MaterialXDocument()
36
37
38 pb_doc.schema_version.major = SCHEMA_VERSION_MAJOR
39 pb_doc.schema_version.minor = SCHEMA_VERSION_MINOR
40 pb_doc.schema_version.patch = SCHEMA_VERSION_PATCH
41
42
43 try:
44 import MaterialX as mx
45 except:
46 pass
47
48 for name in doc.getAttributeNames():
49 attr = pb_doc.attributes.add()
50 attr.key = name
51 attr.value = doc.getAttribute(name)
52
53
54 for child in doc.getChildren():
55 pb_element = self._convert_element(child)
56 pb_doc.elements.append(pb_element)
57
58 return pb_doc
59