9#include <boost/python/call_method.hpp>
10#include <boost/python/class.hpp>
11#include <boost/python/import.hpp>
12#include <boost/python/return_value_policy.hpp>
13#include <boost/python/to_python_converter.hpp>
22#include "RNA_prototypes.hh"
56 [hook](
const std::unique_ptr<USDHook> &item) {
return item.get() == hook; });
62 if (
hook_list().empty() || (idname ==
nullptr) || (idname[0] == 0)) {
66 USDHookList::iterator hook_iter = std::find_if(
67 hook_list().begin(),
hook_list().end(), [idname](
const std::unique_ptr<USDHook> &item) {
68 return STREQ(item->idname, idname);
71 return (hook_iter ==
hook_list().end()) ?
nullptr : hook_iter->get();
139 static bool registered =
false;
152 PyGILState_STATE gilstate = PyGILState_Ensure();
155 python::import(
"pxr.Usd");
156 python::import(
"pxr.UsdShade");
159 python::to_python_converter<PointerRNA, PointerRNAToPython>();
162 python::class_<USDSceneExportContext>(
"USDSceneExportContext")
164 .def(
"get_depsgraph",
166 python::return_value_policy<python::return_by_value>());
168 python::class_<USDMaterialExportContext>(
"USDMaterialExportContext")
171 python::class_<USDSceneImportContext>(
"USDSceneImportContext")
174 PyGILState_Release(gilstate);
180 if (!PyErr_Occurred()) {
188 "An exception occurred invoking USD hook '%s'. Please see the console for details",
206 PyGILState_STATE gilstate = PyGILState_Ensure();
209 USDHookList::const_iterator hook_iter =
hook_list().begin();
217 USDHook *hook = hook_iter->get();
225 PyObject *hook_obj =
static_cast<PyObject *
>(hook->
rna_ext.
data);
233 catch (python::error_already_set
const &) {
242 PyGILState_Release(gilstate);
277 python::call_method<bool>(hook_obj,
function_name(), ref(hook_context_));
284 pxr::UsdShadeMaterial usd_material_;
290 const pxr::UsdShadeMaterial &usd_material,
292 : hook_context_(
stage), usd_material_(usd_material)
301 return "on_material_export";
306 python::call_method<bool>(
307 hook_obj,
function_name(), ref(hook_context_), material_ptr_, usd_material_);
329 python::call_method<bool>(hook_obj,
function_name(), ref(hook_context_));
345 const pxr::UsdShadeMaterial &usd_material,
353 on_material_export.
call();
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
PyObject * pyrna_struct_CreatePyObject(PointerRNA *ptr)
OnExportInvoker(pxr::UsdStageRefPtr stage, Depsgraph *depsgraph, ReportList *reports)
void call_hook(PyObject *hook_obj) const override
const char * function_name() const override
void call_hook(PyObject *hook_obj) const override
const char * function_name() const override
OnImportInvoker(pxr::UsdStageRefPtr stage, ReportList *reports)
const char * function_name() const override
OnMaterialExportInvoker(pxr::UsdStageRefPtr stage, Material *material, const pxr::UsdShadeMaterial &usd_material, ReportList *reports)
void call_hook(PyObject *hook_obj) const override
virtual const char * function_name() const =0
virtual void call_hook(PyObject *hook_obj) const =0
const Depsgraph * depsgraph
void call_material_export_hooks(pxr::UsdStageRefPtr stage, Material *material, const pxr::UsdShadeMaterial &usd_material, ReportList *reports)
void USD_unregister_hook(USDHook *hook)
void USD_register_hook(std::unique_ptr< USDHook > hook)
static USDHookList & hook_list()
std::list< std::unique_ptr< USDHook > > USDHookList
void call_import_hooks(pxr::UsdStageRefPtr stage, ReportList *reports)
void call_export_hooks(pxr::UsdStageRefPtr stage, Depsgraph *depsgraph, ReportList *reports)
USDHook * USD_find_hook_name(const char idname[])
static void handle_python_error(USDHook *hook, ReportList *reports)
void register_hook_converters()
PointerRNA RNA_pointer_create(ID *id, StructRNA *type, void *data)
static PyObject * convert(PointerRNA ptr)
pxr::UsdStageRefPtr get_stage() const
pxr::UsdStageRefPtr stage
USDMaterialExportContext(pxr::UsdStageRefPtr in_stage)
USDMaterialExportContext()=default
USDSceneExportContext()=default
pxr::UsdStageRefPtr get_stage() const
USDSceneExportContext(pxr::UsdStageRefPtr in_stage, Depsgraph *depsgraph)
const PointerRNA & get_depsgraph() const
pxr::UsdStageRefPtr stage
pxr::UsdStageRefPtr get_stage() const
pxr::UsdStageRefPtr stage
USDSceneImportContext(pxr::UsdStageRefPtr in_stage)
USDSceneImportContext()=default