forked from blender/blender
Create parsing system that converts supported nodes and ignores unsupported #2
@ -52,7 +52,9 @@ class HydraSceneDelegate : public pxr::HdSceneDelegate {
|
|||||||
const View3D *view3d = nullptr;
|
const View3D *view3d = nullptr;
|
||||||
Main *bmain = nullptr;
|
Main *bmain = nullptr;
|
||||||
Scene *scene = nullptr;
|
Scene *scene = nullptr;
|
||||||
|
|
||||||
ShadingSettings shading_settings;
|
ShadingSettings shading_settings;
|
||||||
|
bool use_materialx = true;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ObjectDataMap objects_;
|
ObjectDataMap objects_;
|
||||||
|
@ -70,9 +70,21 @@ void MaterialData::init()
|
|||||||
time,
|
time,
|
||||||
export_params,
|
export_params,
|
||||||
image_cache_file_path()};
|
image_cache_file_path()};
|
||||||
|
|
||||||
/* Create USD material. */
|
/* Create USD material. */
|
||||||
//pxr::UsdShadeMaterial usd_material = usd::create_usd_material(export_context, material_path, (Material *)id, "st");
|
pxr::UsdShadeMaterial usd_material;
|
||||||
|
if (scene_delegate_->use_materialx) {
|
||||||
|
MaterialX::DocumentPtr doc = blender::nodes::materialx::export_to_materialx(scene_delegate_->depsgraph, (Material *)id);
|
||||||
|
pxr::UsdMtlxRead(doc, stage);
|
||||||
|
if (pxr::UsdPrim materials = stage->GetPrimAtPath(pxr::SdfPath("/MaterialX/Materials"))) {
|
||||||
|
pxr::UsdPrimSiblingRange children = materials.GetChildren();
|
||||||
|
if (!children.empty()) {
|
||||||
|
usd_material = pxr::UsdShadeMaterial(*children.begin());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
usd_material = usd::create_usd_material(export_context, material_path, (Material *)id, "st");
|
||||||
|
}
|
||||||
|
|
||||||
/* Convert USD material to Hydra material network map, adapted for render delegate. */
|
/* Convert USD material to Hydra material network map, adapted for render delegate. */
|
||||||
const pxr::HdRenderDelegate *render_delegate = scene_delegate_->GetRenderIndex().GetRenderDelegate();
|
const pxr::HdRenderDelegate *render_delegate = scene_delegate_->GetRenderIndex().GetRenderDelegate();
|
||||||
@ -81,23 +93,13 @@ void MaterialData::init()
|
|||||||
|
|
||||||
pxr::HdMaterialNetworkMap network_map;
|
pxr::HdMaterialNetworkMap network_map;
|
||||||
|
|
||||||
MaterialX::DocumentPtr doc = blender::nodes::materialx::export_to_materialx(scene_delegate_->depsgraph, (Material *)id);
|
if (pxr::UsdShadeShader mtlx_surface = usd_material.ComputeSurfaceSource(contextVector)) {
|
||||||
pxr::UsdMtlxRead(doc, stage);
|
pxr::UsdImagingBuildHdMaterialNetworkFromTerminal(mtlx_surface.GetPrim(),
|
||||||
|
pxr::HdMaterialTerminalTokens->surface,
|
||||||
if (pxr::UsdPrim materials = stage->GetPrimAtPath(pxr::SdfPath("/MaterialX/Materials"))) {
|
shaderSourceTypes,
|
||||||
if (pxr::UsdPrimSiblingRange children = materials.GetChildren()) {
|
contextVector,
|
||||||
if (auto usd_material = pxr::UsdShadeMaterial(*children.begin())) {
|
&network_map,
|
||||||
if (pxr::UsdShadeShader mtlx_surface = usd_material.ComputeSurfaceSource(contextVector))
|
time);
|
||||||
{
|
|
||||||
UsdImagingBuildHdMaterialNetworkFromTerminal(mtlx_surface.GetPrim(),
|
|
||||||
pxr::HdMaterialTerminalTokens->surface,
|
|
||||||
shaderSourceTypes,
|
|
||||||
contextVector,
|
|
||||||
&network_map,
|
|
||||||
time);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
material_network_map_ = pxr::VtValue(network_map);
|
material_network_map_ = pxr::VtValue(network_map);
|
||||||
|
@ -50,14 +50,6 @@ MaterialX::DocumentPtr export_to_materialx(Depsgraph *depsgraph, Material *mater
|
|||||||
else {
|
else {
|
||||||
create_standard_surface(doc, material);
|
create_standard_surface(doc, material);
|
||||||
}
|
}
|
||||||
|
|
||||||
char dir_path[FILE_MAX], file_path[FILE_MAX], file_name[32];
|
|
||||||
BLI_path_join(dir_path, sizeof(dir_path), BKE_tempdir_session(), "hydra", "materialx");
|
|
||||||
BLI_dir_create_recursive(dir_path);
|
|
||||||
SNPRINTF(file_name, "mat_%p.mtlx", material);
|
|
||||||
BLI_path_join(file_path, sizeof(file_path), dir_path, file_name);
|
|
||||||
MaterialX::writeToXmlFile(doc, MaterialX::FilePath(file_path));
|
|
||||||
|
|
||||||
return doc;
|
return doc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,6 +89,7 @@ void Engine::sync(Depsgraph *depsgraph, bContext *context)
|
|||||||
pxr::SdfPath scene_path = pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene");
|
pxr::SdfPath scene_path = pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene");
|
||||||
hydra_scene_delegate_ = std::make_unique<io::hydra::HydraSceneDelegate>(render_index_.get(),
|
hydra_scene_delegate_ = std::make_unique<io::hydra::HydraSceneDelegate>(render_index_.get(),
|
||||||
scene_path);
|
scene_path);
|
||||||
|
hydra_scene_delegate_->use_materialx = bl_engine_->type->flag & RE_USE_MATERIALX;
|
||||||
}
|
}
|
||||||
hydra_scene_delegate_->populate(depsgraph, context ? CTX_wm_view3d(context) : nullptr);
|
hydra_scene_delegate_->populate(depsgraph, context ? CTX_wm_view3d(context) : nullptr);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user