Fix #137973: Add MaterialX version info on USD export
This change adds MaterialX version information to the exported MaterialX USD materials. Details: In USD 25.02, the MaterialXConfigAPI schema was introduced to allow recording the MaterialX version used to author a material. When loading MaterialX documents into USD, this schema is automatically applied and the associated version attribute is created on the material. Due to how the MaterialX export works (via copying the composed MaterialX spec from a temporary stage), the MaterialXConfigAPI needs to be explicitly applied to the final material being exported. This change applies this MaterialXConfigAPI schema and copies the version attribute from the temporary MaterialX stage to the final stage. Authored by Apple: Dan Knowlton Co-authored-by: Dan Knowlton <d_knowlton@apple.com> Pull Request: https://projects.blender.org/blender/blender/pulls/137974
This commit is contained in:
committed by
Jesse Yurkovich
parent
2c99edbffa
commit
79c318f692
@@ -42,6 +42,7 @@
|
||||
#ifdef WITH_MATERIALX
|
||||
# include "shader/materialx/material.h"
|
||||
# include <pxr/usd/sdf/copyUtils.h>
|
||||
# include <pxr/usd/usdMtlx/materialXConfigAPI.h>
|
||||
# include <pxr/usd/usdMtlx/reader.h>
|
||||
#endif
|
||||
|
||||
@@ -1467,6 +1468,18 @@ static void create_usd_materialx_material(const USDExporterContext &usd_export_c
|
||||
return;
|
||||
}
|
||||
|
||||
/* Copy over the MateralXConfigAPI schema and associated attribute. */
|
||||
pxr::UsdMtlxMaterialXConfigAPI temp_config_api{temp_material_prim};
|
||||
if (temp_config_api) {
|
||||
pxr::UsdMtlxMaterialXConfigAPI materialx_config_api = pxr::UsdMtlxMaterialXConfigAPI::Apply(
|
||||
material_prim);
|
||||
pxr::UsdAttribute temp_mtlx_version_attr = temp_config_api.GetConfigMtlxVersionAttr();
|
||||
pxr::VtValue mtlx_version;
|
||||
if (temp_mtlx_version_attr && temp_mtlx_version_attr.Get(&mtlx_version)) {
|
||||
materialx_config_api.CreateConfigMtlxVersionAttr(mtlx_version);
|
||||
}
|
||||
}
|
||||
|
||||
/* Once we have the material, we need to prepare for renaming any conflicts.
|
||||
* However, we must make sure any new names don't conflict with names in the temp stage either */
|
||||
Set<std::string> temp_used_names;
|
||||
|
||||
@@ -9,7 +9,7 @@ import pprint
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from pxr import Gf, Sdf, Usd, UsdGeom, UsdShade, UsdSkel, UsdUtils, UsdVol
|
||||
from pxr import Gf, Sdf, Usd, UsdGeom, UsdMtlx, UsdShade, UsdSkel, UsdUtils, UsdVol
|
||||
|
||||
import bpy
|
||||
|
||||
@@ -1132,6 +1132,11 @@ class USDExportTest(AbstractUSDTest):
|
||||
material_prim = stage.GetPrimAtPath("/root/_materials/Material")
|
||||
self.assertTrue(material_prim, "Could not find Material prim")
|
||||
|
||||
self.assertTrue(material_prim.HasAPI(UsdMtlx.MaterialXConfigAPI))
|
||||
mtlx_config_api = UsdMtlx.MaterialXConfigAPI(material_prim)
|
||||
mtlx_version_attr = mtlx_config_api.GetConfigMtlxVersionAttr()
|
||||
self.assertTrue(mtlx_version_attr, "Could not find mtlx config version attribute")
|
||||
|
||||
material = UsdShade.Material(material_prim)
|
||||
mtlx_output = material.GetOutput("mtlx:surface")
|
||||
self.assertTrue(mtlx_output, "Could not find mtlx output")
|
||||
|
||||
Reference in New Issue
Block a user