63 Initialize the Flask application and the MaterialX loader.
70 if len(ocioVersion) < 2:
71 print(
'> OCIO version is not in the expected format.')
72 if int(ocioVersion[0]) < 2
or int(ocioVersion[1]) < 2:
73 print(
'> OCIO version 2.2 or greater is required.')
80 self.
generator = mxocio.OCIOMaterialaxGenerator()
85 Emit a status message to the client.
87 emit(
'status_message', {
'message': message }, broadcast=
True)
91 Handle event and send back server information
93 event_data = data.get(
'message',
'Message')
97 emit(
'server_message_get_config_info', {
'message': self.
config_info }, broadcast=
True)
99 def get_materialx_info(self, targetColorSpace, createGraphs):
100 configs, aconfig = self.
generator.getBuiltinConfigs()
107 nodedef_doc = mx.createDocument()
109 impl_doc = mx.createDocument()
112 config = configs[c][0]
113 for colorSpace
in config.getColorSpaces():
114 aliases = colorSpace.getAliases()
116 for alias
in aliases:
121 trySource = colorSpace.getName()
123 sourceColorSpace = trySource
126 if sourceColorSpace == targetColorSpace:
129 print(
'--- Generate transform for source color space:', trySource,
'---')
133 definitionDoc = mx.createDocument()
134 implDoc = mx.createDocument()
136 definition, transformName, code, extension, target = generator.generateOCIO(aconfig, definitionDoc, implDoc, sourceColorSpace, targetColorSpace,
'color4')
144 nodedef_doc.copyContentFrom(definitionDoc)
149 nodedef_doc.copyContentFrom(implDoc)
154 source_string += code
157 outputType =
'color3'
158 graphDoc = generator.generateOCIOGraph(aconfig, sourceColorSpace, targetColorSpace, outputType)
160 nodedef_doc.copyContentFrom(graphDoc)
162 transformName = generator.createTransformName(sourceColorSpace, targetColorSpace, outputType,
'mxgraph_')
168 print(
'Could not find suitable color space name to use: ' + colorSpace.getName())
170 nodedef_string = mx.writeToXmlString(nodedef_doc)
171 if len(impl_doc.getChildren()) > 0:
172 impl_string = mx.writeToXmlString(impl_doc)
175 return nodedef_string, impl_string, source_string
179 Handle event and send back server message 2
181 createGraphs = data.get(
'nodegraphs',
'Node Graphs')
183 targetColorSpace =
'lin_rec709'
185 nodedef_string, impl_string, source_string = self.
get_materialx_info(targetColorSpace, createGraphs)
187 print(
'> Generatated MaterialX', nodedef_string !=
None)
190 emit(
'server_message_get_mtlx_info',
191 {
'nodedef_string': nodedef_string,
192 'impl_string': impl_string,
193 'source_string': source_string
196 def handle_get_version_info(self, data):
197 print(
'> Get version information')
198 emit(
'server_message_version_info',
207 Set up dictionary of mapping event names to their handlers
219 parser.add_argument(
'--port', type=int, default=5002, help=
"Port to run the server on (default: 5002)")