BLEN-367: Fix code style #14

Merged
Bogdan Nagirniak merged 11 commits from BLEN-367 into hydra-render 2023-03-15 09:42:17 +01:00
23 changed files with 453 additions and 499 deletions
Showing only changes of commit 55786efc3a - Show all commits

View File

@ -7,18 +7,16 @@
#include "camera.h" #include "camera.h"
#include "utils.h" #include "utils.h"
using namespace pxr;
namespace blender::render::hydra { namespace blender::render::hydra {
CameraData::CameraData(Object *camera_obj, GfVec2i res, GfVec4f tile) CameraData::CameraData(Object *camera_obj, pxr::GfVec2i res, pxr::GfVec4f tile)
{ {
Camera *camera = (Camera *)camera_obj->data; Camera *camera = (Camera *)camera_obj->data;
float t_pos[2] = {tile[0], tile[1]}; float t_pos[2] = {tile[0], tile[1]};
float t_size[2] = {tile[2], tile[3]}; float t_size[2] = {tile[2], tile[3]};
transform = gf_matrix_from_transform(camera_obj->object_to_world); transform = gf_matrix_from_transform(camera_obj->object_to_world);
clip_range = GfRange1f(camera->clip_start, camera->clip_end); clip_range = pxr::GfRange1f(camera->clip_start, camera->clip_end);
mode = camera->type; mode = camera->type;
if (camera->dof.flag & CAM_DOF_ENABLED) { if (camera->dof.flag & CAM_DOF_ENABLED) {
@ -27,10 +25,10 @@ CameraData::CameraData(Object *camera_obj, GfVec2i res, GfVec4f tile)
focus_distance = camera->dof.focus_distance; focus_distance = camera->dof.focus_distance;
} }
else { else {
GfVec3f obj_pos(camera->dof.focus_object->object_to_world[0][3], pxr::GfVec3f obj_pos(camera->dof.focus_object->object_to_world[0][3],
camera->dof.focus_object->object_to_world[1][3], camera->dof.focus_object->object_to_world[1][3],
camera->dof.focus_object->object_to_world[2][3]); camera->dof.focus_object->object_to_world[2][3]);
GfVec3f cam_pos(transform[0][3], transform[1][3], transform[2][3]); pxr::GfVec3f cam_pos(transform[0][3], transform[1][3], transform[2][3]);
focus_distance = (obj_pos - cam_pos).GetLength(); focus_distance = (obj_pos - cam_pos).GetLength();
} }
@ -42,25 +40,25 @@ CameraData::CameraData(Object *camera_obj, GfVec2i res, GfVec4f tile)
switch (camera->sensor_fit) { switch (camera->sensor_fit) {
case CAMERA_SENSOR_FIT_VERT: case CAMERA_SENSOR_FIT_VERT:
lens_shift = GfVec2f(camera->shiftx / ratio, camera->shifty); lens_shift = pxr::GfVec2f(camera->shiftx / ratio, camera->shifty);
break; break;
case CAMERA_SENSOR_FIT_HOR: case CAMERA_SENSOR_FIT_HOR:
lens_shift = GfVec2f(camera->shiftx, camera->shifty * ratio); lens_shift = pxr::GfVec2f(camera->shiftx, camera->shifty * ratio);
break; break;
case CAMERA_SENSOR_FIT_AUTO: case CAMERA_SENSOR_FIT_AUTO:
if (ratio > 1.0f) { if (ratio > 1.0f) {
lens_shift = GfVec2f(camera->shiftx, camera->shifty * ratio); lens_shift = pxr::GfVec2f(camera->shiftx, camera->shifty * ratio);
} }
else { else {
lens_shift = GfVec2f(camera->shiftx / ratio, camera->shifty); lens_shift = pxr::GfVec2f(camera->shiftx / ratio, camera->shifty);
} }
break; break;
default: default:
lens_shift = GfVec2f(camera->shiftx, camera->shifty); lens_shift = pxr::GfVec2f(camera->shiftx, camera->shifty);
break; break;
} }
lens_shift = GfVec2f(lens_shift[0] / t_size[0] + (t_pos[0] + t_size[0] * 0.5 - 0.5) / t_size[0], lens_shift = pxr::GfVec2f(lens_shift[0] / t_size[0] + (t_pos[0] + t_size[0] * 0.5 - 0.5) / t_size[0],
lens_shift[1] / t_size[1] + (t_pos[1] + t_size[1] * 0.5 - 0.5) / t_size[1]); lens_shift[1] / t_size[1] + (t_pos[1] + t_size[1] * 0.5 - 0.5) / t_size[1]);
switch (camera->type) { switch (camera->type) {
@ -69,48 +67,48 @@ CameraData::CameraData(Object *camera_obj, GfVec2i res, GfVec4f tile)
switch (camera->sensor_fit) { switch (camera->sensor_fit) {
case CAMERA_SENSOR_FIT_VERT: case CAMERA_SENSOR_FIT_VERT:
sensor_size = GfVec2f(camera->sensor_y * ratio, camera->sensor_y); sensor_size = pxr::GfVec2f(camera->sensor_y * ratio, camera->sensor_y);
break; break;
case CAMERA_SENSOR_FIT_HOR: case CAMERA_SENSOR_FIT_HOR:
sensor_size = GfVec2f(camera->sensor_x, camera->sensor_x / ratio); sensor_size = pxr::GfVec2f(camera->sensor_x, camera->sensor_x / ratio);
break; break;
case CAMERA_SENSOR_FIT_AUTO: case CAMERA_SENSOR_FIT_AUTO:
if (ratio > 1.0f) { if (ratio > 1.0f) {
sensor_size = GfVec2f(camera->sensor_x, camera->sensor_x / ratio); sensor_size = pxr::GfVec2f(camera->sensor_x, camera->sensor_x / ratio);
} }
else { else {
sensor_size = GfVec2f(camera->sensor_x * ratio, camera->sensor_x); sensor_size = pxr::GfVec2f(camera->sensor_x * ratio, camera->sensor_x);
} }
break; break;
default: default:
sensor_size = GfVec2f(camera->sensor_x, camera->sensor_y); sensor_size = pxr::GfVec2f(camera->sensor_x, camera->sensor_y);
break; break;
} }
sensor_size = GfVec2f(sensor_size[0] * t_size[0], sensor_size[1] * t_size[1]); sensor_size = pxr::GfVec2f(sensor_size[0] * t_size[0], sensor_size[1] * t_size[1]);
break; break;
case CAM_ORTHO: case CAM_ORTHO:
focal_length = 0.0f; focal_length = 0.0f;
switch (camera->sensor_fit) { switch (camera->sensor_fit) {
case CAMERA_SENSOR_FIT_VERT: case CAMERA_SENSOR_FIT_VERT:
ortho_size = GfVec2f(camera->ortho_scale * ratio, camera->ortho_scale); ortho_size = pxr::GfVec2f(camera->ortho_scale * ratio, camera->ortho_scale);
break; break;
case CAMERA_SENSOR_FIT_HOR: case CAMERA_SENSOR_FIT_HOR:
ortho_size = GfVec2f(camera->ortho_scale, camera->ortho_scale / ratio); ortho_size = pxr::GfVec2f(camera->ortho_scale, camera->ortho_scale / ratio);
break; break;
case CAMERA_SENSOR_FIT_AUTO: case CAMERA_SENSOR_FIT_AUTO:
if (ratio > 1.0f) { if (ratio > 1.0f) {
ortho_size = GfVec2f(camera->ortho_scale, camera->ortho_scale / ratio); ortho_size = pxr::GfVec2f(camera->ortho_scale, camera->ortho_scale / ratio);
} }
else { else {
ortho_size = GfVec2f(camera->ortho_scale * ratio, camera->ortho_scale); ortho_size = pxr::GfVec2f(camera->ortho_scale * ratio, camera->ortho_scale);
} }
break; break;
default: default:
ortho_size = GfVec2f(camera->ortho_scale, camera->ortho_scale); ortho_size = pxr::GfVec2f(camera->ortho_scale, camera->ortho_scale);
break; break;
} }
ortho_size = GfVec2f(ortho_size[0] * t_size[0], ortho_size[1] * t_size[1]); ortho_size = pxr::GfVec2f(ortho_size[0] * t_size[0], ortho_size[1] * t_size[1]);
break; break;
case CAM_PANO: case CAM_PANO:
@ -119,28 +117,28 @@ CameraData::CameraData(Object *camera_obj, GfVec2i res, GfVec4f tile)
switch (camera->sensor_fit) { switch (camera->sensor_fit) {
case CAMERA_SENSOR_FIT_VERT: case CAMERA_SENSOR_FIT_VERT:
sensor_size = GfVec2f(camera->sensor_y * ratio, camera->sensor_y); sensor_size = pxr::GfVec2f(camera->sensor_y * ratio, camera->sensor_y);
break; break;
case CAMERA_SENSOR_FIT_HOR: case CAMERA_SENSOR_FIT_HOR:
sensor_size = GfVec2f(camera->sensor_x, camera->sensor_x / ratio); sensor_size = pxr::GfVec2f(camera->sensor_x, camera->sensor_x / ratio);
break; break;
case CAMERA_SENSOR_FIT_AUTO: case CAMERA_SENSOR_FIT_AUTO:
if (ratio > 1.0f) { if (ratio > 1.0f) {
sensor_size = GfVec2f(camera->sensor_x, camera->sensor_x / ratio); sensor_size = pxr::GfVec2f(camera->sensor_x, camera->sensor_x / ratio);
} }
else { else {
sensor_size = GfVec2f(camera->sensor_x * ratio, camera->sensor_x); sensor_size = pxr::GfVec2f(camera->sensor_x * ratio, camera->sensor_x);
} }
break; break;
default: default:
sensor_size = GfVec2f(camera->sensor_x, camera->sensor_y); sensor_size = pxr::GfVec2f(camera->sensor_x, camera->sensor_y);
break; break;
} }
sensor_size = GfVec2f(sensor_size[0] * t_size[0], sensor_size[1] * t_size[1]); sensor_size = pxr::GfVec2f(sensor_size[0] * t_size[0], sensor_size[1] * t_size[1]);
default: default:
focal_length = camera->lens; focal_length = camera->lens;
sensor_size = GfVec2f(camera->sensor_y * ratio, camera->sensor_y); sensor_size = pxr::GfVec2f(camera->sensor_y * ratio, camera->sensor_y);
} }
} }
@ -154,47 +152,47 @@ CameraData::CameraData(bContext *context)
// context.view3d or context.region_data // context.view3d or context.region_data
float VIEWPORT_SENSOR_SIZE = 72.0; float VIEWPORT_SENSOR_SIZE = 72.0;
GfVec2i res(region->winx, region->winy); pxr::GfVec2i res(region->winx, region->winy);
float ratio = (float)res[0] / res[1]; float ratio = (float)res[0] / res[1];
transform = gf_matrix_from_transform(region_data->viewmat).GetInverse(); transform = gf_matrix_from_transform(region_data->viewmat).GetInverse();
switch (region_data->persp) { switch (region_data->persp) {
case RV3D_PERSP: { case RV3D_PERSP: {
mode = CAM_PERSP; mode = CAM_PERSP;
clip_range = GfRange1f(view3d->clip_start, view3d->clip_end); clip_range = pxr::GfRange1f(view3d->clip_start, view3d->clip_end);
lens_shift = GfVec2f(0.0, 0.0); lens_shift = pxr::GfVec2f(0.0, 0.0);
focal_length = view3d->lens; focal_length = view3d->lens;
if (ratio > 1.0) { if (ratio > 1.0) {
sensor_size = GfVec2f(VIEWPORT_SENSOR_SIZE, VIEWPORT_SENSOR_SIZE / ratio); sensor_size = pxr::GfVec2f(VIEWPORT_SENSOR_SIZE, VIEWPORT_SENSOR_SIZE / ratio);
} }
else { else {
sensor_size = GfVec2f(VIEWPORT_SENSOR_SIZE * ratio, VIEWPORT_SENSOR_SIZE); sensor_size = pxr::GfVec2f(VIEWPORT_SENSOR_SIZE * ratio, VIEWPORT_SENSOR_SIZE);
} }
break; break;
} }
case RV3D_ORTHO: { case RV3D_ORTHO: {
mode = CAM_ORTHO; mode = CAM_ORTHO;
lens_shift = GfVec2f(0.0f, 0.0f); lens_shift = pxr::GfVec2f(0.0f, 0.0f);
float o_size = region_data->dist * VIEWPORT_SENSOR_SIZE / view3d->lens; float o_size = region_data->dist * VIEWPORT_SENSOR_SIZE / view3d->lens;
float o_depth = view3d->clip_end; float o_depth = view3d->clip_end;
clip_range = GfRange1f(-o_depth * 0.5, o_depth * 0.5); clip_range = pxr::GfRange1f(-o_depth * 0.5, o_depth * 0.5);
if (ratio > 1.0f) { if (ratio > 1.0f) {
ortho_size = GfVec2f(o_size, o_size / ratio); ortho_size = pxr::GfVec2f(o_size, o_size / ratio);
} }
else { else {
ortho_size = GfVec2f(o_size * ratio, o_size); ortho_size = pxr::GfVec2f(o_size * ratio, o_size);
} }
break; break;
} }
case RV3D_CAMOB: { case RV3D_CAMOB: {
GfMatrix4d mat = transform; pxr::GfMatrix4d mat = transform;
*this = CameraData(view3d->camera, res, GfVec4f(0, 0, 1, 1)); *this = CameraData(view3d->camera, res, pxr::GfVec4f(0, 0, 1, 1));
transform = mat; transform = mat;
// This formula was taken from previous plugin with corresponded comment // This formula was taken from previous plugin with corresponded comment
@ -204,7 +202,7 @@ CameraData::CameraData(bContext *context)
// Updating l_shift due to viewport zoom and view_camera_offset // Updating l_shift due to viewport zoom and view_camera_offset
// view_camera_offset should be multiplied by 2 // view_camera_offset should be multiplied by 2
lens_shift = GfVec2f((lens_shift[0] + region_data->camdx * 2) / zoom, lens_shift = pxr::GfVec2f((lens_shift[0] + region_data->camdx * 2) / zoom,
(lens_shift[1] + region_data->camdy * 2) / zoom); (lens_shift[1] + region_data->camdy * 2) / zoom);
if (mode == CAM_ORTHO) { if (mode == CAM_ORTHO) {
@ -221,11 +219,11 @@ CameraData::CameraData(bContext *context)
} }
} }
GfCamera CameraData::gf_camera(GfVec4f tile) pxr::GfCamera CameraData::gf_camera(pxr::GfVec4f tile)
{ {
float t_pos[2] = {tile[0], tile[1]}, t_size[2] = {tile[2], tile[3]}; float t_pos[2] = {tile[0], tile[1]}, t_size[2] = {tile[2], tile[3]};
GfCamera gf_camera = GfCamera(); pxr::GfCamera gf_camera = pxr::GfCamera();
gf_camera.SetClippingRange(clip_range); gf_camera.SetClippingRange(clip_range);
@ -236,7 +234,7 @@ GfCamera CameraData::gf_camera(GfVec4f tile)
case CAM_PERSP: case CAM_PERSP:
case CAM_PANO: { case CAM_PANO: {
/* TODO: store panoramic camera settings */ /* TODO: store panoramic camera settings */
gf_camera.SetProjection(GfCamera::Projection::Perspective); gf_camera.SetProjection(pxr::GfCamera::Projection::Perspective);
gf_camera.SetFocalLength(focal_length); gf_camera.SetFocalLength(focal_length);
float s_size[2] = {sensor_size[0] * t_size[0], sensor_size[1] * t_size[1]}; float s_size[2] = {sensor_size[0] * t_size[0], sensor_size[1] * t_size[1]};
@ -249,7 +247,7 @@ GfCamera CameraData::gf_camera(GfVec4f tile)
break; break;
} }
case CAM_ORTHO: { case CAM_ORTHO: {
gf_camera.SetProjection(GfCamera::Projection::Orthographic); gf_camera.SetProjection(pxr::GfCamera::Projection::Orthographic);
// Use tenths of a world unit accorging to USD docs // Use tenths of a world unit accorging to USD docs
// https://graphics.pixar.com/usd/docs/api/class_gf_camera.html // https://graphics.pixar.com/usd/docs/api/class_gf_camera.html
@ -270,9 +268,9 @@ GfCamera CameraData::gf_camera(GfVec4f tile)
return gf_camera; return gf_camera;
} }
GfCamera CameraData::gf_camera() pxr::GfCamera CameraData::gf_camera()
{ {
return gf_camera(GfVec4f(0, 0, 1, 1)); return gf_camera(pxr::GfVec4f(0, 0, 1, 1));
} }
} // namespace blender::render::hydra } // namespace blender::render::hydra

View File

@ -12,37 +12,35 @@
#include "engine.h" #include "engine.h"
using namespace pxr;
namespace blender::render::hydra { namespace blender::render::hydra {
Engine::Engine(RenderEngine *bl_engine, const std::string &delegateId) : bl_engine(bl_engine) Engine::Engine(RenderEngine *bl_engine, const std::string &delegateId) : bl_engine(bl_engine)
{ {
HdRendererPluginRegistry &registry = HdRendererPluginRegistry::GetInstance(); pxr::HdRendererPluginRegistry &registry = pxr::HdRendererPluginRegistry::GetInstance();
TF_PY_ALLOW_THREADS_IN_SCOPE(); //TF_PY_ALLOW_THREADS_IN_SCOPE();
render_delegate = registry.CreateRenderDelegate(TfToken(delegateId)); render_delegate = registry.CreateRenderDelegate(pxr::TfToken(delegateId));
HdDriverVector hd_drivers; pxr::HdDriverVector hd_drivers;
if (bl_engine->type->flag & RE_USE_GPU_CONTEXT) { if (bl_engine->type->flag & RE_USE_GPU_CONTEXT) {
hgi = Hgi::CreatePlatformDefaultHgi(); hgi = pxr::Hgi::CreatePlatformDefaultHgi();
hgi_driver.name = HgiTokens->renderDriver; hgi_driver.name = pxr::HgiTokens->renderDriver;
hgi_driver.driver = VtValue(hgi.get()); hgi_driver.driver = pxr::VtValue(hgi.get());
hd_drivers.push_back(&hgi_driver); hd_drivers.push_back(&hgi_driver);
} }
render_index.reset(HdRenderIndex::New(render_delegate.Get(), hd_drivers)); render_index.reset(pxr::HdRenderIndex::New(render_delegate.Get(), hd_drivers));
free_camera_delegate = std::make_unique<HdxFreeCameraSceneDelegate>( free_camera_delegate = std::make_unique<pxr::HdxFreeCameraSceneDelegate>(
render_index.get(), SdfPath::AbsoluteRootPath().AppendElementString("freeCamera")); render_index.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("freeCamera"));
render_task_delegate = std::make_unique<RenderTaskDelegate>( render_task_delegate = std::make_unique<RenderTaskDelegate>(
render_index.get(), SdfPath::AbsoluteRootPath().AppendElementString("renderTask")); render_index.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("renderTask"));
if (render_delegate->GetRendererDisplayName() == "GL") { if (render_delegate->GetRendererDisplayName() == "GL") {
simple_light_task_delegate = std::make_unique<SimpleLightTaskDelegate>( simple_light_task_delegate = std::make_unique<SimpleLightTaskDelegate>(
render_index.get(), SdfPath::AbsoluteRootPath().AppendElementString("simpleLightTask")); render_index.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("simpleLightTask"));
} }
engine = std::make_unique<HdEngine>(); engine = std::make_unique<pxr::HdEngine>();
} }
Engine::~Engine() Engine::~Engine()
@ -59,7 +57,7 @@ Engine::~Engine()
float Engine::renderer_percent_done() float Engine::renderer_percent_done()
{ {
VtDictionary render_stats = render_delegate->GetRenderStats(); pxr::VtDictionary render_stats = render_delegate->GetRenderStats();
auto it = render_stats.find("percentDone"); auto it = render_stats.find("percentDone");
if (it == render_stats.end()) { if (it == render_stats.end()) {
return 0.0; return 0.0;

View File

@ -37,16 +37,16 @@ class Engine {
protected: protected:
RenderEngine *bl_engine; RenderEngine *bl_engine;
HdPluginRenderDelegateUniqueHandle render_delegate; pxr::HdPluginRenderDelegateUniqueHandle render_delegate;
std::unique_ptr<HdRenderIndex> render_index; std::unique_ptr<pxr::HdRenderIndex> render_index;
std::unique_ptr<BlenderSceneDelegate> scene_delegate; std::unique_ptr<BlenderSceneDelegate> scene_delegate;
std::unique_ptr<RenderTaskDelegate> render_task_delegate; std::unique_ptr<RenderTaskDelegate> render_task_delegate;
std::unique_ptr<HdxFreeCameraSceneDelegate> free_camera_delegate; std::unique_ptr<pxr::HdxFreeCameraSceneDelegate> free_camera_delegate;
std::unique_ptr<SimpleLightTaskDelegate> simple_light_task_delegate; std::unique_ptr<SimpleLightTaskDelegate> simple_light_task_delegate;
std::unique_ptr<HdEngine> engine; std::unique_ptr<pxr::HdEngine> engine;
HgiUniquePtr hgi; pxr::HgiUniquePtr hgi;
HdDriver hgi_driver; pxr::HdDriver hgi_driver;
}; };
} // namespace blender::render::hydra } // namespace blender::render::hydra

View File

@ -12,18 +12,15 @@
#include "final_engine.h" #include "final_engine.h"
#include "utils.h" #include "utils.h"
using namespace std;
using namespace pxr;
namespace blender::render::hydra { namespace blender::render::hydra {
void FinalEngine::sync(Depsgraph *depsgraph, void FinalEngine::sync(Depsgraph *depsgraph,
bContext *context, bContext *context,
HdRenderSettingsMap &renderSettings) pxr::HdRenderSettingsMap &renderSettings)
{ {
scene_delegate = std::make_unique<BlenderSceneDelegate>( scene_delegate = std::make_unique<BlenderSceneDelegate>(
render_index.get(), render_index.get(),
SdfPath::AbsoluteRootPath().AppendElementString("scene"), pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"),
BlenderSceneDelegate::EngineType::Final); BlenderSceneDelegate::EngineType::Final);
scene_delegate->populate(depsgraph, context); scene_delegate->populate(depsgraph, context);
@ -37,48 +34,48 @@ void FinalEngine::render(Depsgraph *depsgraph)
Scene *scene = DEG_get_input_scene(depsgraph); Scene *scene = DEG_get_input_scene(depsgraph);
ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph); ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph);
string scene_name(MAX_ID_FULL_NAME, 0); std::string scene_name(MAX_ID_FULL_NAME, 0);
BKE_id_full_name_get(scene_name.data(), (ID *)scene, 0); BKE_id_full_name_get(scene_name.data(), (ID *)scene, 0);
string layer_name = view_layer->name; std::string layer_name = view_layer->name;
RenderData &r = scene->r; RenderData &r = scene->r;
GfVec4f border(0, 0, 1, 1); pxr::GfVec4f border(0, 0, 1, 1);
if (r.mode & R_BORDER) { if (r.mode & R_BORDER) {
border = GfVec4f(r.border.xmin, border = pxr::GfVec4f(r.border.xmin,
r.border.ymin, r.border.ymin,
r.border.xmax - r.border.xmin, r.border.xmax - r.border.xmin,
r.border.ymax - r.border.ymin); r.border.ymax - r.border.ymin);
} }
GfVec2i image_res(r.xsch * r.size / 100, r.ysch * r.size / 100); pxr::GfVec2i image_res(r.xsch * r.size / 100, r.ysch * r.size / 100);
GfVec2i res(int(image_res[0] * border[2]), int(image_res[1] * border[3])); pxr::GfVec2i res(int(image_res[0] * border[2]), int(image_res[1] * border[3]));
GfCamera camera = CameraData(scene->camera, image_res, GfVec4f(0, 0, 1, 1)).gf_camera(border); pxr::GfCamera camera = CameraData(scene->camera, image_res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(border);
free_camera_delegate->SetCamera(camera); free_camera_delegate->SetCamera(camera);
render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(), render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(),
GfVec4d(0, 0, res[0], res[1])); pxr::GfVec4d(0, 0, res[0], res[1]));
render_task_delegate->SetRendererAov(HdAovTokens->color); render_task_delegate->SetRendererAov(pxr::HdAovTokens->color);
if (simple_light_task_delegate) { if (simple_light_task_delegate) {
simple_light_task_delegate->SetCameraPath(free_camera_delegate->GetCameraId()); simple_light_task_delegate->SetCameraPath(free_camera_delegate->GetCameraId());
} }
HdTaskSharedPtrVector tasks; pxr::HdTaskSharedPtrVector tasks;
if (simple_light_task_delegate) { if (simple_light_task_delegate) {
tasks.push_back(simple_light_task_delegate->GetTask()); tasks.push_back(simple_light_task_delegate->GetTask());
} }
tasks.push_back(render_task_delegate->GetTask()); tasks.push_back(render_task_delegate->GetTask());
chrono::time_point<chrono::steady_clock> timeBegin = chrono::steady_clock::now(), timeCurrent; std::chrono::time_point<std::chrono::steady_clock> timeBegin = std::chrono::steady_clock::now(), timeCurrent;
chrono::milliseconds elapsedTime; std::chrono::milliseconds elapsedTime;
float percentDone = 0.0; float percentDone = 0.0;
map<string, vector<float>> renderImages{ std::map<std::string, std::vector<float>> renderImages{
{"Combined", vector<float>(res[0] * res[1] * 4)}}; // 4 - number of channels {"Combined", std::vector<float>(res[0] * res[1] * 4)}}; // 4 - number of channels
vector<float> &pixels = renderImages["Combined"]; std::vector<float> &pixels = renderImages["Combined"];
{ {
// Release the GIL before calling into hydra, in case any hydra plugins call into python. // Release the GIL before calling into hydra, in case any hydra plugins call into python.
TF_PY_ALLOW_THREADS_IN_SCOPE(); pxr::TF_PY_ALLOW_THREADS_IN_SCOPE();
engine->Execute(render_index.get(), &tasks); engine->Execute(render_index.get(), &tasks);
} }
@ -88,27 +85,27 @@ void FinalEngine::render(Depsgraph *depsgraph)
} }
percentDone = renderer_percent_done(); percentDone = renderer_percent_done();
timeCurrent = chrono::steady_clock::now(); timeCurrent = std::chrono::steady_clock::now();
elapsedTime = chrono::duration_cast<chrono::milliseconds>(timeCurrent - timeBegin); elapsedTime = std::chrono::duration_cast<std::chrono::milliseconds>(timeCurrent - timeBegin);
notify_status(percentDone / 100.0, notify_status(percentDone / 100.0,
scene_name + ": " + layer_name, scene_name + ": " + layer_name,
"Render Time: " + format_duration(elapsedTime) + "Render Time: " + format_duration(elapsedTime) +
" | Done: " + to_string(int(percentDone)) + "%"); " | Done: " + std::to_string(int(percentDone)) + "%");
if (render_task_delegate->IsConverged()) { if (render_task_delegate->IsConverged()) {
break; break;
} }
render_task_delegate->GetRendererAovData(HdAovTokens->color, pixels.data()); render_task_delegate->GetRendererAovData(pxr::HdAovTokens->color, pixels.data());
updateRenderResult(renderImages, layer_name, res[0], res[1]); updateRenderResult(renderImages, layer_name, res[0], res[1]);
} }
render_task_delegate->GetRendererAovData(HdAovTokens->color, pixels.data()); render_task_delegate->GetRendererAovData(pxr::HdAovTokens->color, pixels.data());
updateRenderResult(renderImages, layer_name, res[0], res[1]); updateRenderResult(renderImages, layer_name, res[0], res[1]);
} }
GfVec2i FinalEngine::get_resolution(Scene *scene) pxr::GfVec2i FinalEngine::get_resolution(Scene *scene)
{ {
RenderData &r = scene->r; RenderData &r = scene->r;
float border_w = 1.0, border_h = 1.0; float border_w = 1.0, border_h = 1.0;
@ -116,11 +113,11 @@ GfVec2i FinalEngine::get_resolution(Scene *scene)
border_w = r.border.xmax - r.border.xmin; border_w = r.border.xmax - r.border.xmin;
border_h = r.border.ymax - r.border.ymin; border_h = r.border.ymax - r.border.ymin;
} }
return GfVec2i(int(r.xsch * border_w * r.size / 100), int(r.ysch * border_h * r.size / 100)); return pxr::GfVec2i(int(r.xsch * border_w * r.size / 100), int(r.ysch * border_h * r.size / 100));
} }
void FinalEngine::updateRenderResult(map<string, vector<float>> &renderImages, void FinalEngine::updateRenderResult(std::map<std::string, std::vector<float>> &renderImages,
const string &layerName, const std::string &layerName,
int width, int width,
int height) int height)
{ {
@ -142,7 +139,7 @@ void FinalEngine::updateRenderResult(map<string, vector<float>> &renderImages,
RE_engine_end_result(bl_engine, result, false, false, false); RE_engine_end_result(bl_engine, result, false, false, false);
} }
void FinalEngine::notify_status(float progress, const string &title, const string &info) void FinalEngine::notify_status(float progress, const std::string &title, const std::string &info)
{ {
RE_engine_update_progress(bl_engine, progress); RE_engine_update_progress(bl_engine, progress);
RE_engine_update_stats(bl_engine, title.c_str(), info.c_str()); RE_engine_update_stats(bl_engine, title.c_str(), info.c_str());
@ -153,30 +150,30 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
Scene *scene = DEG_get_input_scene(depsgraph); Scene *scene = DEG_get_input_scene(depsgraph);
ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph); ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph);
string scene_name(MAX_ID_FULL_NAME, 0); std::string scene_name(MAX_ID_FULL_NAME, 0);
BKE_id_full_name_get(scene_name.data(), (ID *)scene, 0); BKE_id_full_name_get(scene_name.data(), (ID *)scene, 0);
string layer_name = view_layer->name; std::string layer_name = view_layer->name;
RenderData &r = scene->r; RenderData &r = scene->r;
GfVec4f border(0, 0, 1, 1); pxr::GfVec4f border(0, 0, 1, 1);
if (r.mode & R_BORDER) { if (r.mode & R_BORDER) {
border = GfVec4f(r.border.xmin, border = pxr::GfVec4f(r.border.xmin,
r.border.ymin, r.border.ymin,
r.border.xmax - r.border.xmin, r.border.xmax - r.border.xmin,
r.border.ymax - r.border.ymin); r.border.ymax - r.border.ymin);
} }
GfVec2i image_res = {r.xsch * r.size / 100, r.ysch * r.size / 100}; pxr::GfVec2i image_res = {r.xsch * r.size / 100, r.ysch * r.size / 100};
GfVec2i res = {int(image_res[0] * border[2]), int(image_res[1] * border[3])}; pxr::GfVec2i res = {int(image_res[0] * border[2]), int(image_res[1] * border[3])};
GfCamera camera = CameraData(scene->camera, image_res, GfVec4f(0, 0, 1, 1)).gf_camera(border); pxr::GfCamera camera = CameraData(scene->camera, image_res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(border);
free_camera_delegate->SetCamera(camera); free_camera_delegate->SetCamera(camera);
render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(), render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(),
GfVec4d(0, 0, res[0], res[1])); pxr::GfVec4d(0, 0, res[0], res[1]));
if (simple_light_task_delegate) { if (simple_light_task_delegate) {
simple_light_task_delegate->SetCameraPath(free_camera_delegate->GetCameraId()); simple_light_task_delegate->SetCameraPath(free_camera_delegate->GetCameraId());
} }
HdTaskSharedPtrVector tasks; pxr::HdTaskSharedPtrVector tasks;
if (simple_light_task_delegate) { if (simple_light_task_delegate) {
/* TODO: Uncomment this and fix GL error: /* TODO: Uncomment this and fix GL error:
invalid operation, reported from void __cdecl invalid operation, reported from void __cdecl
@ -185,14 +182,14 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
} }
tasks.push_back(render_task_delegate->GetTask()); tasks.push_back(render_task_delegate->GetTask());
chrono::time_point<chrono::steady_clock> timeBegin = chrono::steady_clock::now(), timeCurrent; std::chrono::time_point<std::chrono::steady_clock> timeBegin = std::chrono::steady_clock::now(), timeCurrent;
chrono::milliseconds elapsedTime; std::chrono::milliseconds elapsedTime;
float percentDone = 0.0; float percentDone = 0.0;
map<string, vector<float>> renderImages{ std::map<std::string, std::vector<float>> renderImages{
{"Combined", vector<float>(res[0] * res[1] * 4)}}; // 4 - number of channels {"Combined", std::vector<float>(res[0] * res[1] * 4)}}; // 4 - number of channels
vector<float> &pixels = renderImages["Combined"]; std::vector<float> &pixels = renderImages["Combined"];
GLuint FramebufferName = 0; GLuint FramebufferName = 0;
glGenFramebuffers(1, &FramebufferName); glGenFramebuffers(1, &FramebufferName);
@ -222,7 +219,7 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
{ {
// Release the GIL before calling into hydra, in case any hydra plugins call into python. // Release the GIL before calling into hydra, in case any hydra plugins call into python.
TF_PY_ALLOW_THREADS_IN_SCOPE(); pxr::TF_PY_ALLOW_THREADS_IN_SCOPE();
engine->Execute(render_index.get(), &tasks); engine->Execute(render_index.get(), &tasks);
} }
@ -232,13 +229,13 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
} }
percentDone = renderer_percent_done(); percentDone = renderer_percent_done();
timeCurrent = chrono::steady_clock::now(); timeCurrent = std::chrono::steady_clock::now();
elapsedTime = chrono::duration_cast<chrono::milliseconds>(timeCurrent - timeBegin); elapsedTime = std::chrono::duration_cast<std::chrono::milliseconds>(timeCurrent - timeBegin);
notify_status(percentDone / 100.0, notify_status(percentDone / 100.0,
scene_name + ": " + layer_name, scene_name + ": " + layer_name,
"Render Time: " + format_duration(elapsedTime) + "Render Time: " + format_duration(elapsedTime) +
" | Done: " + to_string(int(percentDone)) + "%"); " | Done: " + std::to_string(int(percentDone)) + "%");
if (render_task_delegate->IsConverged()) { if (render_task_delegate->IsConverged()) {
break; break;

View File

@ -26,7 +26,7 @@ class FinalEngine : public Engine {
void notify_status(float progress, const std::string &title, const std::string &info); void notify_status(float progress, const std::string &title, const std::string &info);
protected: protected:
HdRenderSettingsMap renderSettings; pxr::HdRenderSettingsMap renderSettings;
}; };
class FinalEngineGL : public FinalEngine { class FinalEngineGL : public FinalEngine {

View File

@ -6,18 +6,15 @@
#include "camera.h" #include "camera.h"
#include "preview_engine.h" #include "preview_engine.h"
using namespace pxr;
using namespace std;
namespace blender::render::hydra { namespace blender::render::hydra {
void PreviewEngine::sync(Depsgraph *depsgraph, void PreviewEngine::sync(Depsgraph *depsgraph,
bContext *context, bContext *context,
HdRenderSettingsMap &renderSettings) pxr::HdRenderSettingsMap &renderSettings)
{ {
scene_delegate = make_unique<BlenderSceneDelegate>( scene_delegate = std::make_unique<BlenderSceneDelegate>(
render_index.get(), render_index.get(),
SdfPath::AbsoluteRootPath().AppendElementString("scene"), pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"),
BlenderSceneDelegate::EngineType::Preview); BlenderSceneDelegate::EngineType::Preview);
scene_delegate->populate(depsgraph, context); scene_delegate->populate(depsgraph, context);
@ -31,28 +28,28 @@ void PreviewEngine::render(Depsgraph *depsgraph)
Scene *scene = DEG_get_input_scene(depsgraph); Scene *scene = DEG_get_input_scene(depsgraph);
ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph); ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph);
string layerName = view_layer->name; std::string layerName = view_layer->name;
GfVec2i res(scene->r.xsch, scene->r.ysch); pxr::GfVec2i res(scene->r.xsch, scene->r.ysch);
GfCamera camera = pxr::GfCamera camera =
CameraData(scene->camera, res, GfVec4f(0, 0, 1, 1)).gf_camera(GfVec4f(0, 0, 1, 1)); CameraData(scene->camera, res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(pxr::GfVec4f(0, 0, 1, 1));
free_camera_delegate->SetCamera(camera); free_camera_delegate->SetCamera(camera);
render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(), render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(),
GfVec4d(0, 0, res[0], res[1])); pxr::GfVec4d(0, 0, res[0], res[1]));
render_task_delegate->SetRendererAov(HdAovTokens->color); render_task_delegate->SetRendererAov(pxr::HdAovTokens->color);
HdTaskSharedPtrVector tasks; pxr::HdTaskSharedPtrVector tasks;
if (simple_light_task_delegate) { if (simple_light_task_delegate) {
tasks.push_back(simple_light_task_delegate->GetTask()); tasks.push_back(simple_light_task_delegate->GetTask());
} }
tasks.push_back(render_task_delegate->GetTask()); tasks.push_back(render_task_delegate->GetTask());
vector<float> pixels = vector<float>(res[0] * res[1] * 4); // 4 - number of channels std::vector<float> pixels = std::vector<float>(res[0] * res[1] * 4); // 4 - number of channels
{ {
// Release the GIL before calling into hydra, in case any hydra plugins call into python. // Release the GIL before calling into hydra, in case any hydra plugins call into python.
TF_PY_ALLOW_THREADS_IN_SCOPE(); pxr::TF_PY_ALLOW_THREADS_IN_SCOPE();
engine->Execute(render_index.get(), &tasks); engine->Execute(render_index.get(), &tasks);
} }
@ -65,18 +62,18 @@ void PreviewEngine::render(Depsgraph *depsgraph)
break; break;
} }
render_task_delegate->GetRendererAovData(HdAovTokens->color, pixels.data()); render_task_delegate->GetRendererAovData(pxr::HdAovTokens->color, pixels.data());
updateRenderResult(layerName, res[0], res[1], pixels); updateRenderResult(layerName, res[0], res[1], pixels);
} }
render_task_delegate->GetRendererAovData(HdAovTokens->color, pixels.data()); render_task_delegate->GetRendererAovData(pxr::HdAovTokens->color, pixels.data());
updateRenderResult(layerName, res[0], res[1], pixels); updateRenderResult(layerName, res[0], res[1], pixels);
} }
void PreviewEngine::updateRenderResult(const string &layerName, void PreviewEngine::updateRenderResult(const std::string &layerName,
int width, int width,
int height, int height,
vector<float> &pixels) std::vector<float> &pixels)
{ {
RenderResult *result = RE_engine_begin_result( RenderResult *result = RE_engine_begin_result(
bl_engine, 0, 0, width, height, layerName.c_str(), nullptr); bl_engine, 0, 0, width, height, layerName.c_str(), nullptr);

View File

@ -22,7 +22,7 @@ class PreviewEngine : public FinalEngine {
std::vector<float> &pixels); std::vector<float> &pixels);
protected: protected:
HdRenderSettingsMap renderSettings; pxr::HdRenderSettingsMap renderSettings;
}; };
} // namespace blender::render::hydra } // namespace blender::render::hydra

View File

@ -18,8 +18,6 @@
#include "utils.h" #include "utils.h"
#include "viewport_engine.h" #include "viewport_engine.h"
using namespace std;
namespace blender::render::hydra { namespace blender::render::hydra {
void setup_usd_mtlx_environment() void setup_usd_mtlx_environment()
@ -47,7 +45,7 @@ static PyObject *init_func(PyObject * /*self*/, PyObject *args)
{ {
LOG(INFO) << "init_func"; LOG(INFO) << "init_func";
pxr::PlugRegistry::GetInstance().RegisterPlugins(string(BKE_appdir_program_dir()) + pxr::PlugRegistry::GetInstance().RegisterPlugins(std::string(BKE_appdir_program_dir()) +
"/blender.shared/usd"); "/blender.shared/usd");
setup_usd_mtlx_environment(); setup_usd_mtlx_environment();
@ -64,7 +62,7 @@ static PyObject *register_plugins_func(PyObject * /*self*/, PyObject *args)
LOG(INFO) << "register_plugins_func"; LOG(INFO) << "register_plugins_func";
vector<string> plugin_dirs, path_dirs; std::vector<std::string> plugin_dirs, path_dirs;
PyObject *pyiter, *pyitem; PyObject *pyiter, *pyitem;
pyiter = PyObject_GetIter(pyplugin_dirs); pyiter = PyObject_GetIter(pyplugin_dirs);
@ -99,8 +97,8 @@ static PyObject *get_render_plugins_func(PyObject * /*self*/, PyObject *args)
{ {
LOG(INFO) << "get_render_plugins_func"; LOG(INFO) << "get_render_plugins_func";
PlugRegistry &registry = PlugRegistry::GetInstance(); pxr::PlugRegistry &registry = pxr::PlugRegistry::GetInstance();
TfTokenVector plugin_ids = UsdImagingGLEngine::GetRendererPlugins(); pxr::TfTokenVector plugin_ids = pxr::UsdImagingGLEngine::GetRendererPlugins();
PyObject *ret = PyTuple_New(plugin_ids.size()); PyObject *ret = PyTuple_New(plugin_ids.size());
PyObject *val; PyObject *val;
for (int i = 0; i < plugin_ids.size(); ++i) { for (int i = 0; i < plugin_ids.size(); ++i) {
@ -112,14 +110,14 @@ static PyObject *get_render_plugins_func(PyObject * /*self*/, PyObject *args)
PyDict_SetItemString(descr, PyDict_SetItemString(descr,
"name", "name",
val = PyUnicode_FromString( val = PyUnicode_FromString(
UsdImagingGLEngine::GetRendererDisplayName(plugin_ids[i]).c_str())); pxr::UsdImagingGLEngine::GetRendererDisplayName(plugin_ids[i]).c_str()));
Py_DECREF(val); Py_DECREF(val);
string plugin_name = plugin_ids[i]; std::string plugin_name = plugin_ids[i];
plugin_name = plugin_name.substr(0, plugin_name.size() - 6); plugin_name = plugin_name.substr(0, plugin_name.size() - 6);
plugin_name[0] = tolower(plugin_name[0]); plugin_name[0] = tolower(plugin_name[0]);
string path = ""; std::string path = "";
PlugPluginPtr plugin = registry.GetPluginWithName(plugin_name); pxr::PlugPluginPtr plugin = registry.GetPluginWithName(plugin_name);
if (plugin) { if (plugin) {
path = plugin->GetPath(); path = plugin->GetPath();
} }
@ -145,10 +143,10 @@ static PyObject *engine_create_func(PyObject * /*self*/, PyObject *args)
Engine *engine; Engine *engine;
if (string(engineType) == "VIEWPORT") { if (std::string(engineType) == "VIEWPORT") {
engine = new ViewportEngine(bl_engine, render_delegate_id); engine = new ViewportEngine(bl_engine, render_delegate_id);
} }
else if (string(engineType) == "PREVIEW") { else if (std::string(engineType) == "PREVIEW") {
engine = new PreviewEngine(bl_engine, render_delegate_id); engine = new PreviewEngine(bl_engine, render_delegate_id);
} }
else { else {
@ -187,12 +185,12 @@ static PyObject *engine_sync_func(PyObject * /*self*/, PyObject *args)
Depsgraph *depsgraph = (Depsgraph *)PyLong_AsVoidPtr(pydepsgraph); Depsgraph *depsgraph = (Depsgraph *)PyLong_AsVoidPtr(pydepsgraph);
bContext *context = (bContext *)PyLong_AsVoidPtr(pycontext); bContext *context = (bContext *)PyLong_AsVoidPtr(pycontext);
HdRenderSettingsMap settings; pxr::HdRenderSettingsMap settings;
PyObject *pyiter = PyObject_GetIter(pysettings); PyObject *pyiter = PyObject_GetIter(pysettings);
if (pyiter) { if (pyiter) {
PyObject *pykey, *pyval; PyObject *pykey, *pyval;
while (pykey = PyIter_Next(pyiter)) { while (pykey = PyIter_Next(pyiter)) {
TfToken key(PyUnicode_AsUTF8(pykey)); pxr::TfToken key(PyUnicode_AsUTF8(pykey));
pyval = PyDict_GetItem(pysettings, pykey); pyval = PyDict_GetItem(pysettings, pykey);
if (PyLong_Check(pyval)) { if (PyLong_Check(pyval)) {

View File

@ -13,117 +13,117 @@
namespace blender::render::hydra { namespace blender::render::hydra {
RenderTaskDelegate::RenderTaskDelegate(HdRenderIndex *parentIndex, SdfPath const &delegateID) RenderTaskDelegate::RenderTaskDelegate(pxr::HdRenderIndex *parentIndex, pxr::SdfPath const &delegateID)
: HdSceneDelegate(parentIndex, delegateID) : pxr::HdSceneDelegate(parentIndex, delegateID)
{ {
SdfPath renderTaskId = GetTaskID(); pxr::SdfPath renderTaskId = GetTaskID();
GetRenderIndex().InsertTask<HdxRenderTask>(this, renderTaskId); GetRenderIndex().InsertTask<pxr::HdxRenderTask>(this, renderTaskId);
GetRenderIndex().GetChangeTracker().MarkTaskDirty(renderTaskId, GetRenderIndex().GetChangeTracker().MarkTaskDirty(renderTaskId,
HdChangeTracker::DirtyCollection); pxr::HdChangeTracker::DirtyCollection);
GetRenderIndex().GetChangeTracker().MarkTaskDirty(renderTaskId, GetRenderIndex().GetChangeTracker().MarkTaskDirty(renderTaskId,
HdChangeTracker::DirtyRenderTags); pxr::HdChangeTracker::DirtyRenderTags);
taskParams.enableLighting = true; taskParams.enableLighting = true;
taskParams.alphaThreshold = 0.1f; taskParams.alphaThreshold = 0.1f;
} }
SdfPath RenderTaskDelegate::GetTaskID() const pxr::SdfPath RenderTaskDelegate::GetTaskID() const
{ {
return GetDelegateID().AppendElementString("task"); return GetDelegateID().AppendElementString("task");
} }
SdfPath RenderTaskDelegate::GetAovID(TfToken const &aov) const pxr::SdfPath RenderTaskDelegate::GetAovID(pxr::TfToken const &aov) const
{ {
return GetDelegateID().AppendElementString("aov_" + aov.GetString()); return GetDelegateID().AppendElementString("aov_" + aov.GetString());
} }
VtValue RenderTaskDelegate::Get(SdfPath const &id, TfToken const &key) pxr::VtValue RenderTaskDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key)
{ {
LOG(INFO) << "RenderTaskDelegate::Get - " << id.GetAsString() << " " << key.GetString() << "\n"; LOG(INFO) << "RenderTaskDelegate::Get - " << id.GetAsString() << " " << key.GetString() << "\n";
if (key == HdTokens->params) { if (key == pxr::HdTokens->params) {
return VtValue(taskParams); return pxr::VtValue(taskParams);
} }
if (key == HdTokens->collection) { if (key == pxr::HdTokens->collection) {
HdRprimCollection rprimCollection( pxr::HdRprimCollection rprimCollection(
HdTokens->geometry, HdReprSelector(HdReprTokens->smoothHull), false, TfToken()); pxr::HdTokens->geometry, pxr::HdReprSelector(pxr::HdReprTokens->smoothHull), false, pxr::TfToken());
rprimCollection.SetRootPath(SdfPath::AbsoluteRootPath()); rprimCollection.SetRootPath(pxr::SdfPath::AbsoluteRootPath());
return VtValue(rprimCollection); return pxr::VtValue(rprimCollection);
} }
return VtValue(); return pxr::VtValue();
} }
HdRenderBufferDescriptor RenderTaskDelegate::GetRenderBufferDescriptor(SdfPath const &id) pxr::HdRenderBufferDescriptor RenderTaskDelegate::GetRenderBufferDescriptor(pxr::SdfPath const &id)
{ {
LOG(INFO) << "RenderTaskDelegate::GetRenderBufferDescriptor - " << id.GetAsString() << "\n"; LOG(INFO) << "RenderTaskDelegate::GetRenderBufferDescriptor - " << id.GetAsString() << "\n";
return bufferDescriptors[id]; return bufferDescriptors[id];
} }
TfTokenVector RenderTaskDelegate::GetTaskRenderTags(SdfPath const &taskId) pxr::TfTokenVector RenderTaskDelegate::GetTaskRenderTags(pxr::SdfPath const &taskId)
{ {
LOG(INFO) << "RenderTaskDelegate::GetTaskRenderTags - " << taskId.GetAsString() << "\n"; LOG(INFO) << "RenderTaskDelegate::GetTaskRenderTags - " << taskId.GetAsString() << "\n";
return {HdRenderTagTokens->geometry}; return {pxr::HdRenderTagTokens->geometry};
} }
bool RenderTaskDelegate::IsConverged() bool RenderTaskDelegate::IsConverged()
{ {
HdTaskSharedPtr renderTask = GetRenderIndex().GetTask(GetTaskID()); pxr::HdTaskSharedPtr renderTask = GetRenderIndex().GetTask(GetTaskID());
return ((HdxRenderTask &)*renderTask).IsConverged(); return ((pxr::HdxRenderTask &)*renderTask).IsConverged();
} }
void RenderTaskDelegate::SetRendererAov(TfToken const &aov) void RenderTaskDelegate::SetRendererAov(pxr::TfToken const &aov)
{ {
HdAovDescriptor aovDesc = GetRenderIndex().GetRenderDelegate()->GetDefaultAovDescriptor(aov); pxr::HdAovDescriptor aovDesc = GetRenderIndex().GetRenderDelegate()->GetDefaultAovDescriptor(aov);
HdRenderBufferDescriptor desc(GfVec3i(taskParams.viewport[2], taskParams.viewport[3], 1), pxr::HdRenderBufferDescriptor desc(pxr::GfVec3i(taskParams.viewport[2], taskParams.viewport[3], 1),
aovDesc.format, aovDesc.format,
aovDesc.multiSampled); aovDesc.multiSampled);
SdfPath bufferId = GetAovID(aov); pxr::SdfPath bufferId = GetAovID(aov);
if (bufferDescriptors.find(bufferId) == bufferDescriptors.end()) { if (bufferDescriptors.find(bufferId) == bufferDescriptors.end()) {
GetRenderIndex().InsertBprim(HdPrimTypeTokens->renderBuffer, this, bufferId); GetRenderIndex().InsertBprim(pxr::HdPrimTypeTokens->renderBuffer, this, bufferId);
bufferDescriptors[bufferId] = desc; bufferDescriptors[bufferId] = desc;
GetRenderIndex().GetChangeTracker().MarkBprimDirty(bufferId, HdRenderBuffer::DirtyDescription); GetRenderIndex().GetChangeTracker().MarkBprimDirty(bufferId, pxr::HdRenderBuffer::DirtyDescription);
HdRenderPassAovBinding binding; pxr::HdRenderPassAovBinding binding;
binding.aovName = aov; binding.aovName = aov;
binding.renderBufferId = bufferId; binding.renderBufferId = bufferId;
binding.aovSettings = aovDesc.aovSettings; binding.aovSettings = aovDesc.aovSettings;
taskParams.aovBindings.push_back(binding); taskParams.aovBindings.push_back(binding);
GetRenderIndex().GetChangeTracker().MarkTaskDirty(GetTaskID(), HdChangeTracker::DirtyParams); GetRenderIndex().GetChangeTracker().MarkTaskDirty(GetTaskID(), pxr::HdChangeTracker::DirtyParams);
} }
else if (bufferDescriptors[bufferId] != desc) { else if (bufferDescriptors[bufferId] != desc) {
bufferDescriptors[bufferId] = desc; bufferDescriptors[bufferId] = desc;
GetRenderIndex().GetChangeTracker().MarkBprimDirty(bufferId, HdRenderBuffer::DirtyDescription); GetRenderIndex().GetChangeTracker().MarkBprimDirty(bufferId, pxr::HdRenderBuffer::DirtyDescription);
} }
} }
HdRenderBuffer *RenderTaskDelegate::GetRendererAov(TfToken const &aov) pxr::HdRenderBuffer *RenderTaskDelegate::GetRendererAov(pxr::TfToken const &aov)
{ {
return ( return (
HdRenderBuffer *)(GetRenderIndex().GetBprim(HdPrimTypeTokens->renderBuffer, GetAovID(aov))); pxr::HdRenderBuffer *)(GetRenderIndex().GetBprim(pxr::HdPrimTypeTokens->renderBuffer, GetAovID(aov)));
} }
void RenderTaskDelegate::GetRendererAovData(TfToken const &aov, void *data) void RenderTaskDelegate::GetRendererAovData(pxr::TfToken const &aov, void *data)
{ {
HdRenderBuffer *buffer = GetRendererAov(aov); pxr::HdRenderBuffer *buffer = GetRendererAov(aov);
void *bufData = buffer->Map(); void *bufData = buffer->Map();
memcpy(data, memcpy(data,
bufData, bufData,
buffer->GetWidth() * buffer->GetHeight() * HdDataSizeOfFormat(buffer->GetFormat())); buffer->GetWidth() * buffer->GetHeight() * pxr::HdDataSizeOfFormat(buffer->GetFormat()));
buffer->Unmap(); buffer->Unmap();
} }
HdTaskSharedPtr RenderTaskDelegate::GetTask() pxr::HdTaskSharedPtr RenderTaskDelegate::GetTask()
{ {
return GetRenderIndex().GetTask(GetTaskID()); return GetRenderIndex().GetTask(GetTaskID());
} }
void RenderTaskDelegate::SetCameraAndViewport(SdfPath const &cameraId, GfVec4d const &viewport) void RenderTaskDelegate::SetCameraAndViewport(pxr::SdfPath const &cameraId, pxr::GfVec4d const &viewport)
{ {
if (taskParams.viewport != viewport || taskParams.camera != cameraId) { if (taskParams.viewport != viewport || taskParams.camera != cameraId) {
taskParams.viewport = viewport; taskParams.viewport = viewport;
taskParams.camera = cameraId; taskParams.camera = cameraId;
GetRenderIndex().GetChangeTracker().MarkTaskDirty(GetTaskID(), HdChangeTracker::DirtyParams); GetRenderIndex().GetChangeTracker().MarkTaskDirty(GetTaskID(), pxr::HdChangeTracker::DirtyParams);
} }
} }

View File

@ -6,33 +6,31 @@
#include <pxr/imaging/hd/sceneDelegate.h> #include <pxr/imaging/hd/sceneDelegate.h>
#include <pxr/imaging/hdx/renderSetupTask.h> #include <pxr/imaging/hdx/renderSetupTask.h>
using namespace pxr;
namespace blender::render::hydra { namespace blender::render::hydra {
class RenderTaskDelegate : public HdSceneDelegate { class RenderTaskDelegate : public pxr::HdSceneDelegate {
public: public:
RenderTaskDelegate(HdRenderIndex *parentIndex, SdfPath const &delegateID); RenderTaskDelegate(pxr::HdRenderIndex *parentIndex, pxr::SdfPath const &delegateID);
~RenderTaskDelegate() override = default; ~RenderTaskDelegate() override = default;
SdfPath GetTaskID() const; pxr::SdfPath GetTaskID() const;
SdfPath GetAovID(TfToken const &aov) const; pxr::SdfPath GetAovID(pxr::TfToken const &aov) const;
VtValue Get(SdfPath const &id, TfToken const &key) override; pxr::VtValue Get(pxr::SdfPath const &id, pxr::TfToken const &key) override;
HdRenderBufferDescriptor GetRenderBufferDescriptor(SdfPath const &id) override; pxr::HdRenderBufferDescriptor GetRenderBufferDescriptor(pxr::SdfPath const &id) override;
TfTokenVector GetTaskRenderTags(SdfPath const &taskId) override; pxr::TfTokenVector GetTaskRenderTags(pxr::SdfPath const &taskId) override;
bool IsConverged(); bool IsConverged();
void SetRendererAov(TfToken const &aovId); void SetRendererAov(pxr::TfToken const &aovId);
HdRenderBuffer *GetRendererAov(TfToken const &id); pxr::HdRenderBuffer *GetRendererAov(pxr::TfToken const &id);
void GetRendererAovData(TfToken const &id, void *buf); void GetRendererAovData(pxr::TfToken const &id, void *buf);
HdTaskSharedPtr GetTask(); pxr::HdTaskSharedPtr GetTask();
void SetCameraAndViewport(SdfPath const &cameraId, GfVec4d const &viewport); void SetCameraAndViewport(pxr::SdfPath const &cameraId, pxr::GfVec4d const &viewport);
private: private:
HdxRenderTaskParams taskParams; pxr::HdxRenderTaskParams taskParams;
TfHashMap<SdfPath, HdRenderBufferDescriptor, SdfPath::Hash> bufferDescriptors; pxr::TfHashMap<pxr::SdfPath, pxr::HdRenderBufferDescriptor, pxr::SdfPath::Hash> bufferDescriptors;
}; };
} // namespace blender::render::hydra } // namespace blender::render::hydra

View File

@ -8,13 +8,10 @@
#include "blender_scene_delegate.h" #include "blender_scene_delegate.h"
using namespace pxr;
using namespace std;
namespace blender::render::hydra { namespace blender::render::hydra {
BlenderSceneDelegate::BlenderSceneDelegate(HdRenderIndex *parentIndex, BlenderSceneDelegate::BlenderSceneDelegate(pxr::HdRenderIndex *parentIndex,
SdfPath const &delegateID, pxr::SdfPath const &delegateID,
BlenderSceneDelegate::EngineType engine_type) BlenderSceneDelegate::EngineType engine_type)
: HdSceneDelegate(parentIndex, delegateID), : HdSceneDelegate(parentIndex, delegateID),
engine_type(engine_type), engine_type(engine_type),
@ -28,10 +25,10 @@ void BlenderSceneDelegate::set_material(MeshData &mesh_data)
{ {
Material *material = mesh_data.material(); Material *material = mesh_data.material();
if (!material) { if (!material) {
mesh_data.material_id = SdfPath::EmptyPath(); mesh_data.material_id = pxr::SdfPath::EmptyPath();
return; return;
} }
SdfPath id = MaterialData::prim_id(this, material); pxr::SdfPath id = MaterialData::prim_id(this, material);
MaterialData *mat_data = material_data(id); MaterialData *mat_data = material_data(id);
if (!mat_data) { if (!mat_data) {
materials[id] = MaterialData::init(this, material); materials[id] = MaterialData::init(this, material);
@ -73,7 +70,7 @@ void BlenderSceneDelegate::update_world()
} }
} }
bool BlenderSceneDelegate::GetVisible(SdfPath const &id) bool BlenderSceneDelegate::GetVisible(pxr::SdfPath const &id)
{ {
if (id == WorldData::prim_id(this)) { if (id == WorldData::prim_id(this)) {
return true; return true;
@ -82,45 +79,45 @@ bool BlenderSceneDelegate::GetVisible(SdfPath const &id)
return object_data(id)->visible; return object_data(id)->visible;
} }
SdfPath BlenderSceneDelegate::GetInstancerId(SdfPath const &primId) pxr::SdfPath BlenderSceneDelegate::GetInstancerId(pxr::SdfPath const &primId)
{ {
LOG(INFO) << "GetInstancerId: " << primId.GetAsString(); LOG(INFO) << "GetInstancerId: " << primId.GetAsString();
MeshData *m_data = mesh_data(primId); MeshData *m_data = mesh_data(primId);
if (m_data) { if (m_data) {
return m_data->instancer_id; return m_data->instancer_id;
} }
return SdfPath(); return pxr::SdfPath();
} }
SdfPathVector BlenderSceneDelegate::GetInstancerPrototypes(SdfPath const &instancerId) pxr::SdfPathVector BlenderSceneDelegate::GetInstancerPrototypes(pxr::SdfPath const &instancerId)
{ {
LOG(INFO) << "GetInstancerPrototypes: " << instancerId.GetString(); LOG(INFO) << "GetInstancerPrototypes: " << instancerId.GetString();
SdfPathVector paths; pxr::SdfPathVector paths;
paths.push_back(instancerId.GetParentPath()); paths.push_back(instancerId.GetParentPath());
return paths; return paths;
} }
VtIntArray BlenderSceneDelegate::GetInstanceIndices(SdfPath const &instancerId, pxr::VtIntArray BlenderSceneDelegate::GetInstanceIndices(pxr::SdfPath const &instancerId,
SdfPath const &prototypeId) pxr::SdfPath const &prototypeId)
{ {
LOG(INFO) << "GetInstanceIndices: " << instancerId.GetString() << " " << prototypeId.GetString(); LOG(INFO) << "GetInstanceIndices: " << instancerId.GetString() << " " << prototypeId.GetString();
MeshData *m_data = mesh_data(prototypeId); MeshData *m_data = mesh_data(prototypeId);
VtIntArray ret = m_data->instance_indices(); pxr::VtIntArray ret = m_data->instance_indices();
return ret; return ret;
} }
GfMatrix4d BlenderSceneDelegate::GetInstancerTransform(SdfPath const &instancerId) pxr::GfMatrix4d BlenderSceneDelegate::GetInstancerTransform(pxr::SdfPath const &instancerId)
{ {
LOG(INFO) << "GetInstancerTransform: " << instancerId.GetString(); LOG(INFO) << "GetInstancerTransform: " << instancerId.GetString();
// TODO: add a separate object for instancer for cleaner handling code // TODO: add a separate object for instancer for cleaner handling code
// Actual instancer transform is get here // Actual instancer transform is get here
return GfMatrix4d(1.0); return pxr::GfMatrix4d(1.0);
} }
size_t BlenderSceneDelegate::SampleInstancerTransform(SdfPath const &instancerId, size_t BlenderSceneDelegate::SampleInstancerTransform(pxr::SdfPath const &instancerId,
size_t maxSampleCount, size_t maxSampleCount,
float *sampleTimes, float *sampleTimes,
GfMatrix4d *sampleValues) pxr::GfMatrix4d *sampleValues)
{ {
LOG(INFO) << "SampleInstancerTransform: " << instancerId.GetString(); LOG(INFO) << "SampleInstancerTransform: " << instancerId.GetString();
size_t ret = 0; size_t ret = 0;
@ -129,11 +126,11 @@ size_t BlenderSceneDelegate::SampleInstancerTransform(SdfPath const &instancerId
return ret; return ret;
} }
size_t BlenderSceneDelegate::SamplePrimvar(SdfPath const &id, size_t BlenderSceneDelegate::SamplePrimvar(pxr::SdfPath const &id,
TfToken const &key, pxr::TfToken const &key,
size_t maxSampleCount, size_t maxSampleCount,
float *sampleTimes, float *sampleTimes,
VtValue *sampleValues) pxr::VtValue *sampleValues)
{ {
// TODO: add a separate object for instancer for cleaner handling code // TODO: add a separate object for instancer for cleaner handling code
if (id.GetName() == "Instancer") { if (id.GetName() == "Instancer") {
@ -157,8 +154,8 @@ void BlenderSceneDelegate::update_collection(bool remove, bool visibility)
} }
/* Export of new visible objects which were not exported before */ /* Export of new visible objects which were not exported before */
set<SdfPath> available_objects; std::set<pxr::SdfPath> available_objects;
SdfPath id; pxr::SdfPath id;
DEGObjectIterSettings settings = {0}; DEGObjectIterSettings settings = {0};
settings.depsgraph = depsgraph; settings.depsgraph = depsgraph;
@ -207,7 +204,7 @@ void BlenderSceneDelegate::update_collection(bool remove, bool visibility)
} }
/* remove unused materials */ /* remove unused materials */
set<SdfPath> available_materials; std::set<pxr::SdfPath> available_materials;
for (auto &obj : objects) { for (auto &obj : objects) {
MeshData *m_data = dynamic_cast<MeshData *>(obj.second.get()); MeshData *m_data = dynamic_cast<MeshData *>(obj.second.get());
if (m_data && !m_data->material_id.IsEmpty()) { if (m_data && !m_data->material_id.IsEmpty()) {
@ -230,7 +227,7 @@ void BlenderSceneDelegate::add_update_object(Object *object,
bool transform, bool transform,
bool shading) bool shading)
{ {
SdfPath id = ObjectData::prim_id(this, object); pxr::SdfPath id = ObjectData::prim_id(this, object);
ObjectData *obj_data = object_data(id); ObjectData *obj_data = object_data(id);
if (!obj_data) { if (!obj_data) {
objects[id] = ObjectData::init(this, object); objects[id] = ObjectData::init(this, object);
@ -267,7 +264,7 @@ void BlenderSceneDelegate::add_update_object(Object *object,
void BlenderSceneDelegate::add_update_instance(DupliObject *dupli) void BlenderSceneDelegate::add_update_instance(DupliObject *dupli)
{ {
SdfPath id = ObjectData::prim_id(this, dupli->ob); pxr::SdfPath id = ObjectData::prim_id(this, dupli->ob);
if (!object_data(id)) { if (!object_data(id)) {
add_update_object(dupli->ob, true, true, true); add_update_object(dupli->ob, true, true, true);
} }
@ -276,7 +273,7 @@ void BlenderSceneDelegate::add_update_instance(DupliObject *dupli)
m_data->add_instance(dupli); m_data->add_instance(dupli);
} }
ObjectData *BlenderSceneDelegate::object_data(SdfPath const &id) ObjectData *BlenderSceneDelegate::object_data(pxr::SdfPath const &id)
{ {
auto it = objects.find(id); auto it = objects.find(id);
if (it == objects.end()) { if (it == objects.end()) {
@ -285,17 +282,17 @@ ObjectData *BlenderSceneDelegate::object_data(SdfPath const &id)
return it->second.get(); return it->second.get();
} }
MeshData *BlenderSceneDelegate::mesh_data(SdfPath const &id) MeshData *BlenderSceneDelegate::mesh_data(pxr::SdfPath const &id)
{ {
return static_cast<MeshData *>(object_data(id)); return static_cast<MeshData *>(object_data(id));
} }
LightData *BlenderSceneDelegate::light_data(SdfPath const &id) LightData *BlenderSceneDelegate::light_data(pxr::SdfPath const &id)
{ {
return static_cast<LightData *>(object_data(id)); return static_cast<LightData *>(object_data(id));
} }
MaterialData *BlenderSceneDelegate::material_data(SdfPath const &id) MaterialData *BlenderSceneDelegate::material_data(pxr::SdfPath const &id)
{ {
auto it = materials.find(id); auto it = materials.find(id);
if (it == materials.end()) { if (it == materials.end()) {
@ -392,14 +389,14 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont)
} }
} }
HdMeshTopology BlenderSceneDelegate::GetMeshTopology(SdfPath const &id) pxr::HdMeshTopology BlenderSceneDelegate::GetMeshTopology(pxr::SdfPath const &id)
{ {
LOG(INFO) << "GetMeshTopology: " << id.GetString(); LOG(INFO) << "GetMeshTopology: " << id.GetString();
MeshData *m_data = mesh_data(id); MeshData *m_data = mesh_data(id);
return m_data->mesh_topology(); return m_data->mesh_topology();
} }
VtValue BlenderSceneDelegate::Get(SdfPath const &id, TfToken const &key) pxr::VtValue BlenderSceneDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key)
{ {
LOG(INFO) << "Get: " << id.GetString() << " " << key.GetString(); LOG(INFO) << "Get: " << id.GetString() << " " << key.GetString();
ObjectData *obj_data = object_data(id); ObjectData *obj_data = object_data(id);
@ -415,11 +412,11 @@ VtValue BlenderSceneDelegate::Get(SdfPath const &id, TfToken const &key)
if (mat_data) { if (mat_data) {
return mat_data->get_data(key); return mat_data->get_data(key);
} }
return VtValue(); return pxr::VtValue();
} }
HdPrimvarDescriptorVector BlenderSceneDelegate::GetPrimvarDescriptors( pxr::HdPrimvarDescriptorVector BlenderSceneDelegate::GetPrimvarDescriptors(
SdfPath const &id, HdInterpolation interpolation) pxr::SdfPath const &id, pxr::HdInterpolation interpolation)
{ {
LOG(INFO) << "GetPrimvarDescriptors: " << id.GetString() << " " << interpolation; LOG(INFO) << "GetPrimvarDescriptors: " << id.GetString() << " " << interpolation;
if (mesh_data(id)) { if (mesh_data(id)) {
@ -431,25 +428,25 @@ HdPrimvarDescriptorVector BlenderSceneDelegate::GetPrimvarDescriptors(
return data->instancer_primvar_descriptors(interpolation); return data->instancer_primvar_descriptors(interpolation);
} }
} }
HdPrimvarDescriptorVector primvars; pxr::HdPrimvarDescriptorVector primvars;
return primvars; return primvars;
} }
SdfPath BlenderSceneDelegate::GetMaterialId(SdfPath const &rprimId) pxr::SdfPath BlenderSceneDelegate::GetMaterialId(pxr::SdfPath const &rprimId)
{ {
return mesh_data(rprimId)->material_id; return mesh_data(rprimId)->material_id;
} }
VtValue BlenderSceneDelegate::GetMaterialResource(SdfPath const &id) pxr::VtValue BlenderSceneDelegate::GetMaterialResource(pxr::SdfPath const &id)
{ {
MaterialData *mat_data = material_data(id); MaterialData *mat_data = material_data(id);
if (mat_data) { if (mat_data) {
return mat_data->material_resource(); return mat_data->material_resource();
} }
return VtValue(); return pxr::VtValue();
} }
GfMatrix4d BlenderSceneDelegate::GetTransform(SdfPath const &id) pxr::GfMatrix4d BlenderSceneDelegate::GetTransform(pxr::SdfPath const &id)
{ {
LOG(INFO) << "GetTransform: " << id.GetString(); LOG(INFO) << "GetTransform: " << id.GetString();
ObjectData *obj_data = object_data(id); ObjectData *obj_data = object_data(id);
@ -465,10 +462,10 @@ GfMatrix4d BlenderSceneDelegate::GetTransform(SdfPath const &id)
if (id == WorldData::prim_id(this)) { if (id == WorldData::prim_id(this)) {
return world_data->transform(); return world_data->transform();
} }
return GfMatrix4d(); return pxr::GfMatrix4d();
} }
VtValue BlenderSceneDelegate::GetLightParamValue(SdfPath const &id, TfToken const &key) pxr::VtValue BlenderSceneDelegate::GetLightParamValue(pxr::SdfPath const &id, pxr::TfToken const &key)
{ {
LightData *l_data = light_data(id); LightData *l_data = light_data(id);
if (l_data) { if (l_data) {
@ -477,7 +474,7 @@ VtValue BlenderSceneDelegate::GetLightParamValue(SdfPath const &id, TfToken cons
if (id == WorldData::prim_id(this)) { if (id == WorldData::prim_id(this)) {
return world_data->get_data(key); return world_data->get_data(key);
} }
return VtValue(); return pxr::VtValue();
} }
} // namespace blender::render::hydra } // namespace blender::render::hydra

View File

@ -6,8 +6,6 @@
#include "blender_scene_delegate.h" #include "blender_scene_delegate.h"
#include "id.h" #include "id.h"
using namespace pxr;
namespace blender::render::hydra { namespace blender::render::hydra {
IdData::IdData(BlenderSceneDelegate *scene_delegate, ID *id) IdData::IdData(BlenderSceneDelegate *scene_delegate, ID *id)
@ -22,9 +20,9 @@ std::string IdData::name()
return str; return str;
} }
VtValue IdData::get_data(TfToken const &key) pxr::VtValue IdData::get_data(pxr::TfToken const &key)
{ {
return VtValue(); return pxr::VtValue();
} }
} // namespace blender::render::hydra } // namespace blender::render::hydra

View File

@ -15,9 +15,6 @@
#include "blender_scene_delegate.h" #include "blender_scene_delegate.h"
#include "light.h" #include "light.h"
using namespace pxr;
using namespace boost::algorithm;
namespace blender::render::hydra { namespace blender::render::hydra {
LightData::LightData(BlenderSceneDelegate *scene_delegate, Object *object) LightData::LightData(BlenderSceneDelegate *scene_delegate, Object *object)
@ -25,51 +22,51 @@ LightData::LightData(BlenderSceneDelegate *scene_delegate, Object *object)
{ {
Light *light = (Light *)((Object *)id)->data; Light *light = (Light *)((Object *)id)->data;
data[HdLightTokens->intensity] = scene_delegate->engine_type == data[pxr::HdLightTokens->intensity] = scene_delegate->engine_type ==
BlenderSceneDelegate::EngineType::Preview ? BlenderSceneDelegate::EngineType::Preview ?
light->energy / 1000 : light->energy / 1000 :
light->energy; light->energy;
data[HdLightTokens->color] = GfVec3f(light->r, light->g, light->b); data[pxr::HdLightTokens->color] = pxr::GfVec3f(light->r, light->g, light->b);
switch (light->type) { switch (light->type) {
case LA_LOCAL: case LA_LOCAL:
data[HdLightTokens->radius] = light->area_size / 2; data[pxr::HdLightTokens->radius] = light->area_size / 2;
break; break;
case LA_SUN: case LA_SUN:
data[HdLightTokens->angle] = light->sun_angle * 180.0 / M_PI; data[pxr::HdLightTokens->angle] = light->sun_angle * 180.0 / M_PI;
break; break;
case LA_SPOT: case LA_SPOT:
data[HdLightTokens->shapingConeAngle] = light->spotsize / 2; data[pxr::HdLightTokens->shapingConeAngle] = light->spotsize / 2;
data[HdLightTokens->shapingConeSoftness] = light->spotblend; data[pxr::HdLightTokens->shapingConeSoftness] = light->spotblend;
data[UsdLuxTokens->treatAsPoint] = true; data[pxr::UsdLuxTokens->treatAsPoint] = true;
break; break;
case LA_AREA: case LA_AREA:
switch (light->area_shape) { switch (light->area_shape) {
case LA_AREA_SQUARE: case LA_AREA_SQUARE:
data[HdLightTokens->width] = light->area_size; data[pxr::HdLightTokens->width] = light->area_size;
data[HdLightTokens->height] = light->area_size; data[pxr::HdLightTokens->height] = light->area_size;
break; break;
case LA_AREA_RECT: case LA_AREA_RECT:
data[HdLightTokens->width] = light->area_size; data[pxr::HdLightTokens->width] = light->area_size;
data[HdLightTokens->height] = light->area_sizey; data[pxr::HdLightTokens->height] = light->area_sizey;
break; break;
case LA_AREA_DISK: case LA_AREA_DISK:
data[HdLightTokens->radius] = light->area_size / 2; data[pxr::HdLightTokens->radius] = light->area_size / 2;
break; break;
case LA_AREA_ELLIPSE: case LA_AREA_ELLIPSE:
data[HdLightTokens->radius] = (light->area_size + light->area_sizey) / 4; data[pxr::HdLightTokens->radius] = (light->area_size + light->area_sizey) / 4;
break; break;
default: default:
break; break;
} }
data[HdLightTokens->normalize] = true; data[pxr::HdLightTokens->normalize] = true;
break; break;
default: default:
@ -77,59 +74,59 @@ LightData::LightData(BlenderSceneDelegate *scene_delegate, Object *object)
} }
/* TODO: temporary value, it should be delivered through Python UI */ /* TODO: temporary value, it should be delivered through Python UI */
data[HdLightTokens->exposure] = 1.0f; data[pxr::HdLightTokens->exposure] = 1.0f;
} }
pxr::TfToken LightData::prim_type() pxr::TfToken LightData::prim_type()
{ {
Light *light = (Light *)((Object *)id)->data; Light *light = (Light *)((Object *)id)->data;
TfToken ret; pxr::TfToken ret;
switch (light->type) { switch (light->type) {
case LA_LOCAL: case LA_LOCAL:
case LA_SPOT: case LA_SPOT:
ret = HdPrimTypeTokens->sphereLight; ret = pxr::HdPrimTypeTokens->sphereLight;
break; break;
case LA_SUN: case LA_SUN:
ret = HdPrimTypeTokens->distantLight; ret = pxr::HdPrimTypeTokens->distantLight;
break; break;
case LA_AREA: case LA_AREA:
switch (light->area_shape) { switch (light->area_shape) {
case LA_AREA_SQUARE: case LA_AREA_SQUARE:
case LA_AREA_RECT: case LA_AREA_RECT:
ret = HdPrimTypeTokens->rectLight; ret = pxr::HdPrimTypeTokens->rectLight;
break; break;
case LA_AREA_DISK: case LA_AREA_DISK:
case LA_AREA_ELLIPSE: case LA_AREA_ELLIPSE:
ret = HdPrimTypeTokens->diskLight; ret = pxr::HdPrimTypeTokens->diskLight;
break; break;
default: default:
ret = HdPrimTypeTokens->rectLight; ret = pxr::HdPrimTypeTokens->rectLight;
} }
break; break;
default: default:
ret = HdPrimTypeTokens->sphereLight; ret = pxr::HdPrimTypeTokens->sphereLight;
} }
return ret; return ret;
} }
VtValue LightData::get_data(TfToken const &key) pxr::VtValue LightData::get_data(pxr::TfToken const &key)
{ {
LOG(INFO) << "Get data light: " << name() << " [" << key.GetString() << "]"; LOG(INFO) << "Get data light: " << name() << " [" << key.GetString() << "]";
VtValue ret; pxr::VtValue ret;
auto it = data.find(key); auto it = data.find(key);
if (it != data.end()) { if (it != data.end()) {
ret = it->second; ret = it->second;
} }
else { else {
std::string n = key.GetString(); std::string n = key.GetString();
if (contains(n, "object:visibility:")) { if (boost::algorithm::contains(n, "object:visibility:")) {
if (ends_with(n, "camera") || ends_with(n, "shadow")) { if (boost::algorithm::ends_with(n, "camera") || boost::algorithm::ends_with(n, "shadow")) {
ret = false; ret = false;
} }
else { else {
@ -142,14 +139,14 @@ VtValue LightData::get_data(TfToken const &key)
void LightData::insert_prim() void LightData::insert_prim()
{ {
SdfPath p_id = prim_id(scene_delegate, (Object *)id); pxr::SdfPath p_id = prim_id(scene_delegate, (Object *)id);
scene_delegate->GetRenderIndex().InsertSprim(prim_type(), scene_delegate, p_id); scene_delegate->GetRenderIndex().InsertSprim(prim_type(), scene_delegate, p_id);
LOG(INFO) << "Add light: " << name() << " id=" << p_id.GetAsString(); LOG(INFO) << "Add light: " << name() << " id=" << p_id.GetAsString();
} }
void LightData::remove_prim() void LightData::remove_prim()
{ {
SdfPath p_id = prim_id(scene_delegate, (Object *)id); pxr::SdfPath p_id = prim_id(scene_delegate, (Object *)id);
scene_delegate->GetRenderIndex().RemoveSprim(prim_type(), p_id); scene_delegate->GetRenderIndex().RemoveSprim(prim_type(), p_id);
LOG(INFO) << "Remove light: " << name(); LOG(INFO) << "Remove light: " << name();
} }
@ -158,21 +155,21 @@ void LightData::mark_prim_dirty(DirtyBits dirty_bits)
{ {
/* TODO: prim_type was changed we have to do remove..add light */ /* TODO: prim_type was changed we have to do remove..add light */
HdDirtyBits bits = HdLight::Clean; pxr::HdDirtyBits bits = pxr::HdLight::Clean;
switch (dirty_bits) { switch (dirty_bits) {
case DirtyBits::DirtyTransform: case DirtyBits::DirtyTransform:
bits = HdLight::DirtyTransform; bits = pxr::HdLight::DirtyTransform;
break; break;
case DirtyBits::DirtyVisibility: case DirtyBits::DirtyVisibility:
bits = HdLight::DirtyParams; bits = pxr::HdLight::DirtyParams;
break; break;
case DirtyBits::AllDirty: case DirtyBits::AllDirty:
bits = HdLight::AllDirty; bits = pxr::HdLight::AllDirty;
break; break;
default: default:
break; break;
} }
SdfPath p_id = prim_id(scene_delegate, (Object *)id); pxr::SdfPath p_id = prim_id(scene_delegate, (Object *)id);
scene_delegate->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id, bits); scene_delegate->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id, bits);
LOG(INFO) << "Update light: " << name() << " [" << (int)dirty_bits << "]"; LOG(INFO) << "Update light: " << name() << " [" << (int)dirty_bits << "]";
} }

View File

@ -16,8 +16,6 @@
#include "material.h" #include "material.h"
#include "mtlx_hydra_adapter.h" #include "mtlx_hydra_adapter.h"
using namespace pxr;
namespace blender::render::hydra { namespace blender::render::hydra {
std::unique_ptr<MaterialData> MaterialData::init(BlenderSceneDelegate *scene_delegate, std::unique_ptr<MaterialData> MaterialData::init(BlenderSceneDelegate *scene_delegate,
@ -40,9 +38,9 @@ MaterialData::MaterialData(BlenderSceneDelegate *scene_delegate, Material *mater
{ {
} }
VtValue MaterialData::get_data(TfToken const &key) pxr::VtValue MaterialData::get_data(pxr::TfToken const &key)
{ {
VtValue ret; pxr::VtValue ret;
if (key.GetString() == "MaterialXFilename") { if (key.GetString() == "MaterialXFilename") {
if (!mtlx_path.GetResolvedPath().empty()) { if (!mtlx_path.GetResolvedPath().empty()) {
ret = mtlx_path; ret = mtlx_path;
@ -55,14 +53,14 @@ pxr::VtValue MaterialData::material_resource()
{ {
std::string const &path = mtlx_path.GetResolvedPath(); std::string const &path = mtlx_path.GetResolvedPath();
if (!path.empty()) { if (!path.empty()) {
HdRenderDelegate *render_delegate = scene_delegate->GetRenderIndex().GetRenderDelegate(); pxr::HdRenderDelegate *render_delegate = scene_delegate->GetRenderIndex().GetRenderDelegate();
TfTokenVector shader_source_types = render_delegate->GetShaderSourceTypes(); pxr::TfTokenVector shader_source_types = render_delegate->GetShaderSourceTypes();
TfTokenVector render_contexts = render_delegate->GetMaterialRenderContexts(); pxr::TfTokenVector render_contexts = render_delegate->GetMaterialRenderContexts();
HdMaterialNetworkMap material_network_map; pxr::HdMaterialNetworkMap material_network_map;
HdMtlxConvertToMaterialNetworkMap( HdMtlxConvertToMaterialNetworkMap(
path, shader_source_types, render_contexts, &material_network_map); path, shader_source_types, render_contexts, &material_network_map);
return VtValue(material_network_map); return pxr::VtValue(material_network_map);
} }
return pxr::VtValue(); return pxr::VtValue();
@ -88,35 +86,35 @@ void MaterialData::export_mtlx()
PyGILState_Release(gstate); PyGILState_Release(gstate);
mtlx_path = SdfAssetPath(path, path); mtlx_path = pxr::SdfAssetPath(path, path);
LOG(INFO) << "Material export: " << name() << " mtlx=" << mtlx_path.GetResolvedPath(); LOG(INFO) << "Material export: " << name() << " mtlx=" << mtlx_path.GetResolvedPath();
} }
void MaterialData::insert_prim() void MaterialData::insert_prim()
{ {
SdfPath p_id = prim_id(scene_delegate, (Material *)id); pxr::SdfPath p_id = prim_id(scene_delegate, (Material *)id);
scene_delegate->GetRenderIndex().InsertSprim(HdPrimTypeTokens->material, scene_delegate, p_id); scene_delegate->GetRenderIndex().InsertSprim(pxr::HdPrimTypeTokens->material, scene_delegate, p_id);
LOG(INFO) << "Add material: " << name() << " id=" << p_id.GetAsString(); LOG(INFO) << "Add material: " << name() << " id=" << p_id.GetAsString();
} }
void MaterialData::remove_prim() void MaterialData::remove_prim()
{ {
SdfPath p_id = prim_id(scene_delegate, (Material *)id); pxr::SdfPath p_id = prim_id(scene_delegate, (Material *)id);
scene_delegate->GetRenderIndex().RemoveSprim(HdPrimTypeTokens->material, p_id); scene_delegate->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->material, p_id);
LOG(INFO) << "Remove material: " << name(); LOG(INFO) << "Remove material: " << name();
} }
void MaterialData::mark_prim_dirty(DirtyBits dirty_bits) void MaterialData::mark_prim_dirty(DirtyBits dirty_bits)
{ {
HdDirtyBits bits = HdMaterial::Clean; pxr::HdDirtyBits bits = pxr::HdMaterial::Clean;
switch (dirty_bits) { switch (dirty_bits) {
case DirtyBits::AllDirty: case DirtyBits::AllDirty:
bits = HdMaterial::AllDirty; bits = pxr::HdMaterial::AllDirty;
break; break;
default: default:
break; break;
} }
SdfPath p_id = prim_id(scene_delegate, (Material *)id); pxr::SdfPath p_id = prim_id(scene_delegate, (Material *)id);
scene_delegate->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id, bits); scene_delegate->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id, bits);
LOG(INFO) << "Update material: " << name() << ", mtlx=" << mtlx_path.GetResolvedPath(); LOG(INFO) << "Update material: " << name() << ", mtlx=" << mtlx_path.GetResolvedPath();
} }

View File

@ -15,8 +15,6 @@
#include "blender_scene_delegate.h" #include "blender_scene_delegate.h"
#include "mesh.h" #include "mesh.h"
using namespace pxr;
namespace blender::render::hydra { namespace blender::render::hydra {
MeshData::MeshData(BlenderSceneDelegate *scene_delegate, Object *object) MeshData::MeshData(BlenderSceneDelegate *scene_delegate, Object *object)
@ -35,19 +33,19 @@ MeshData::MeshData(BlenderSceneDelegate *scene_delegate, Object *object)
} }
} }
VtValue MeshData::get_data(TfToken const &key) pxr::VtValue MeshData::get_data(pxr::TfToken const &key)
{ {
VtValue ret; pxr::VtValue ret;
if (key == HdTokens->points) { if (key == pxr::HdTokens->points) {
ret = vertices; ret = vertices;
} }
else if (key == HdTokens->normals) { else if (key == pxr::HdTokens->normals) {
ret = normals; ret = normals;
} }
else if (key == HdPrimvarRoleTokens->textureCoordinate) { else if (key == pxr::HdPrimvarRoleTokens->textureCoordinate) {
ret = uvs; ret = uvs;
} }
else if (key == HdInstancerTokens->instanceTransform) { else if (key == pxr::HdInstancerTokens->instanceTransform) {
ret = instances; ret = instances;
} }
return ret; return ret;
@ -62,48 +60,48 @@ Material *MeshData::material()
return BKE_object_material_get_eval(object, object->actcol); return BKE_object_material_get_eval(object, object->actcol);
} }
HdMeshTopology MeshData::mesh_topology() pxr::HdMeshTopology MeshData::mesh_topology()
{ {
return HdMeshTopology(PxOsdOpenSubdivTokens->catmullClark, return pxr::HdMeshTopology(pxr::PxOsdOpenSubdivTokens->catmullClark,
HdTokens->rightHanded, pxr::HdTokens->rightHanded,
face_vertex_counts, face_vertex_counts,
face_vertex_indices); face_vertex_indices);
} }
HdPrimvarDescriptorVector MeshData::primvar_descriptors(HdInterpolation interpolation) pxr::HdPrimvarDescriptorVector MeshData::primvar_descriptors(pxr::HdInterpolation interpolation)
{ {
HdPrimvarDescriptorVector primvars; pxr::HdPrimvarDescriptorVector primvars;
if (interpolation == HdInterpolationVertex) { if (interpolation == pxr::HdInterpolationVertex) {
if (!vertices.empty()) { if (!vertices.empty()) {
primvars.emplace_back(HdTokens->points, interpolation, HdPrimvarRoleTokens->point); primvars.emplace_back(pxr::HdTokens->points, interpolation, pxr::HdPrimvarRoleTokens->point);
} }
} }
else if (interpolation == HdInterpolationFaceVarying) { else if (interpolation == pxr::HdInterpolationFaceVarying) {
if (!normals.empty()) { if (!normals.empty()) {
primvars.emplace_back(HdTokens->normals, interpolation, HdPrimvarRoleTokens->normal); primvars.emplace_back(pxr::HdTokens->normals, interpolation, pxr::HdPrimvarRoleTokens->normal);
} }
if (!uvs.empty()) { if (!uvs.empty()) {
primvars.emplace_back(HdPrimvarRoleTokens->textureCoordinate, primvars.emplace_back(pxr::HdPrimvarRoleTokens->textureCoordinate,
interpolation, interpolation,
HdPrimvarRoleTokens->textureCoordinate); pxr::HdPrimvarRoleTokens->textureCoordinate);
} }
} }
return primvars; return primvars;
} }
HdPrimvarDescriptorVector MeshData::instancer_primvar_descriptors(HdInterpolation interpolation) pxr::HdPrimvarDescriptorVector MeshData::instancer_primvar_descriptors(pxr::HdInterpolation interpolation)
{ {
HdPrimvarDescriptorVector primvars; pxr::HdPrimvarDescriptorVector primvars;
if (interpolation == HdInterpolationInstance) { if (interpolation == pxr::HdInterpolationInstance) {
primvars.emplace_back( primvars.emplace_back(
HdInstancerTokens->instanceTransform, interpolation, HdPrimvarRoleTokens->none); pxr::HdInstancerTokens->instanceTransform, interpolation, pxr::HdPrimvarRoleTokens->none);
} }
return primvars; return primvars;
} }
VtIntArray MeshData::instance_indices() pxr::VtIntArray MeshData::instance_indices()
{ {
VtIntArray ret(instances.size()); pxr::VtIntArray ret(instances.size());
for (size_t i = 0; i < ret.size(); ++i) { for (size_t i = 0; i < ret.size(); ++i) {
ret[i] = i; ret[i] = i;
} }
@ -112,19 +110,19 @@ VtIntArray MeshData::instance_indices()
size_t MeshData::sample_instancer_transform(size_t maxSampleCount, size_t MeshData::sample_instancer_transform(size_t maxSampleCount,
float *sampleTimes, float *sampleTimes,
GfMatrix4d *sampleValues) pxr::GfMatrix4d *sampleValues)
{ {
*sampleTimes = 0.0f; *sampleTimes = 0.0f;
*sampleValues = GfMatrix4d(1.0); *sampleValues = pxr::GfMatrix4d(1.0);
return 1; return 1;
} }
size_t MeshData::sample_instancer_primvar(TfToken const &key, size_t MeshData::sample_instancer_primvar(pxr::TfToken const &key,
size_t maxSampleCount, size_t maxSampleCount,
float *sampleTimes, float *sampleTimes,
VtValue *sampleValues) pxr::VtValue *sampleValues)
{ {
if (key == HdInstancerTokens->instanceTransform) { if (key == pxr::HdInstancerTokens->instanceTransform) {
if (maxSampleCount > 0) { if (maxSampleCount > 0) {
sampleTimes[0] = 0.0f; sampleTimes[0] = 0.0f;
sampleValues[0] = instances; sampleValues[0] = instances;
@ -144,7 +142,7 @@ void MeshData::add_instance(DupliObject *dupli)
if (instances.empty()) { if (instances.empty()) {
// USD hides the prototype mesh when instancing in contrary to the Blender, so we must add it // USD hides the prototype mesh when instancing in contrary to the Blender, so we must add it
// back implicitly // back implicitly
instances.push_back(GfMatrix4d(1.0)); instances.push_back(pxr::GfMatrix4d(1.0));
} }
instances.push_back(transform().GetInverse() * gf_matrix_from_transform(dupli->mat)); instances.push_back(transform().GetInverse() * gf_matrix_from_transform(dupli->mat));
LOG(INFO) << "Add instance: " << instancer_id.GetAsString() << " " << dupli->random_id; LOG(INFO) << "Add instance: " << instancer_id.GetAsString() << " " << dupli->random_id;
@ -161,7 +159,7 @@ void MeshData::set_mesh(Mesh *mesh)
blender::Span<MLoopTri> loopTris = mesh->looptris(); blender::Span<MLoopTri> loopTris = mesh->looptris();
/* face_vertex_counts */ /* face_vertex_counts */
face_vertex_counts = VtIntArray(tris_len, 3); face_vertex_counts = pxr::VtIntArray(tris_len, 3);
/* face_vertex_indices */ /* face_vertex_indices */
blender::Span<MLoop> loops = mesh->loops(); blender::Span<MLoop> loops = mesh->loops();
@ -176,7 +174,7 @@ void MeshData::set_mesh(Mesh *mesh)
vertices.reserve(mesh->totvert); vertices.reserve(mesh->totvert);
blender::Span<blender::float3> verts = mesh->vert_positions(); blender::Span<blender::float3> verts = mesh->vert_positions();
for (blender::float3 v : verts) { for (blender::float3 v : verts) {
vertices.push_back(GfVec3f(v.x, v.y, v.z)); vertices.push_back(pxr::GfVec3f(v.x, v.y, v.z));
} }
/* normals */ /* normals */
@ -184,9 +182,9 @@ void MeshData::set_mesh(Mesh *mesh)
if (lnors) { if (lnors) {
normals.reserve(loopTris.size() * 3); normals.reserve(loopTris.size() * 3);
for (MLoopTri lt : loopTris) { for (MLoopTri lt : loopTris) {
normals.push_back(GfVec3f(lnors[lt.tri[0]])); normals.push_back(pxr::GfVec3f(lnors[lt.tri[0]]));
normals.push_back(GfVec3f(lnors[lt.tri[1]])); normals.push_back(pxr::GfVec3f(lnors[lt.tri[1]]));
normals.push_back(GfVec3f(lnors[lt.tri[2]])); normals.push_back(pxr::GfVec3f(lnors[lt.tri[2]]));
} }
} }
@ -195,9 +193,9 @@ void MeshData::set_mesh(Mesh *mesh)
if (luvs) { if (luvs) {
uvs.reserve(loopTris.size() * 3); uvs.reserve(loopTris.size() * 3);
for (MLoopTri lt : loopTris) { for (MLoopTri lt : loopTris) {
uvs.push_back(GfVec2f(luvs[lt.tri[0]])); uvs.push_back(pxr::GfVec2f(luvs[lt.tri[0]]));
uvs.push_back(GfVec2f(luvs[lt.tri[1]])); uvs.push_back(pxr::GfVec2f(luvs[lt.tri[1]]));
uvs.push_back(GfVec2f(luvs[lt.tri[2]])); uvs.push_back(pxr::GfVec2f(luvs[lt.tri[2]]));
} }
} }
} }
@ -208,14 +206,14 @@ void MeshData::insert_prim()
return; return;
} }
SdfPath p_id = prim_id(scene_delegate, (Object *)id); pxr::SdfPath p_id = prim_id(scene_delegate, (Object *)id);
scene_delegate->GetRenderIndex().InsertRprim(HdPrimTypeTokens->mesh, scene_delegate, p_id); scene_delegate->GetRenderIndex().InsertRprim(pxr::HdPrimTypeTokens->mesh, scene_delegate, p_id);
LOG(INFO) << "Add mesh: " << name() << " id=" << p_id.GetAsString(); LOG(INFO) << "Add mesh: " << name() << " id=" << p_id.GetAsString();
} }
void MeshData::remove_prim() void MeshData::remove_prim()
{ {
SdfPath p_id = prim_id(scene_delegate, (Object *)id); pxr::SdfPath p_id = prim_id(scene_delegate, (Object *)id);
if (!scene_delegate->GetRenderIndex().HasRprim(p_id)) { if (!scene_delegate->GetRenderIndex().HasRprim(p_id)) {
return; return;
} }
@ -226,7 +224,7 @@ void MeshData::remove_prim()
void MeshData::mark_prim_dirty(DirtyBits dirty_bits) void MeshData::mark_prim_dirty(DirtyBits dirty_bits)
{ {
SdfPath p_id = prim_id(scene_delegate, (Object *)id); pxr::SdfPath p_id = prim_id(scene_delegate, (Object *)id);
if (!scene_delegate->GetRenderIndex().HasRprim(p_id)) { if (!scene_delegate->GetRenderIndex().HasRprim(p_id)) {
/* Trying to insert prim */ /* Trying to insert prim */
insert_prim(); insert_prim();
@ -239,19 +237,19 @@ void MeshData::mark_prim_dirty(DirtyBits dirty_bits)
return; return;
} }
HdDirtyBits bits = HdChangeTracker::Clean; pxr::HdDirtyBits bits = pxr::HdChangeTracker::Clean;
switch (dirty_bits) { switch (dirty_bits) {
case DirtyBits::DirtyTransform: case DirtyBits::DirtyTransform:
bits = HdChangeTracker::DirtyTransform; bits = pxr::HdChangeTracker::DirtyTransform;
break; break;
case DirtyBits::DirtyVisibility: case DirtyBits::DirtyVisibility:
bits = HdChangeTracker::DirtyVisibility; bits = pxr::HdChangeTracker::DirtyVisibility;
break; break;
case DirtyBits::DirtyMaterial: case DirtyBits::DirtyMaterial:
bits = HdChangeTracker::DirtyMaterialId; bits = pxr::HdChangeTracker::DirtyMaterialId;
break; break;
case DirtyBits::AllDirty: case DirtyBits::AllDirty:
bits = HdChangeTracker::AllDirty; bits = pxr::HdChangeTracker::AllDirty;
break; break;
default: default:
break; break;

View File

@ -22,56 +22,52 @@
namespace mx = MaterialX; namespace mx = MaterialX;
PXR_NAMESPACE_OPEN_SCOPE
void HdMtlxConvertToMaterialNetworkMap(std::string const &mtlxPath, void HdMtlxConvertToMaterialNetworkMap(std::string const &mtlxPath,
TfTokenVector const &shaderSourceTypes, pxr::TfTokenVector const &shaderSourceTypes,
TfTokenVector const &renderContexts, pxr::TfTokenVector const &renderContexts,
HdMaterialNetworkMap *out) pxr::HdMaterialNetworkMap *out)
{ {
if (mtlxPath.empty()) { if (mtlxPath.empty()) {
return; return;
} }
std::string basePath = TfGetPathName(mtlxPath); std::string basePath = pxr::TfGetPathName(mtlxPath);
ArResolver &resolver = ArGetResolver(); pxr::ArResolver &resolver = pxr::ArGetResolver();
const ArResolverContext context = resolver.CreateDefaultContextForAsset(mtlxPath); const pxr::ArResolverContext context = resolver.CreateDefaultContextForAsset(mtlxPath);
ArResolverContextBinder binder(context); pxr::ArResolverContextBinder binder(context);
ArResolverScopedCache resolverCache; pxr::ArResolverScopedCache resolverCache;
std::string mtlxName = TfGetBaseName(mtlxPath); std::string mtlxName = pxr::TfGetBaseName(mtlxPath);
std::string stageId = TfStringPrintf( std::string stageId = pxr::TfStringPrintf(
"%s%s%s.usda", basePath.c_str(), ARCH_PATH_SEP, mtlxName.c_str()); "%s%s%s.usda", basePath.c_str(), ARCH_PATH_SEP, mtlxName.c_str());
UsdStageRefPtr stage = UsdStage::CreateInMemory(stageId, context); pxr::UsdStageRefPtr stage = pxr::UsdStage::CreateInMemory(stageId, context);
try { try {
mx::DocumentPtr doc = UsdMtlxReadDocument(mtlxPath); mx::DocumentPtr doc = pxr::UsdMtlxReadDocument(mtlxPath);
UsdMtlxRead(doc, stage); pxr::UsdMtlxRead(doc, stage);
} }
catch (mx::ExceptionFoundCycle &x) { catch (mx::ExceptionFoundCycle &x) {
TF_RUNTIME_ERROR("MaterialX cycle found: %s\n", x.what()); Tf_PostErrorHelper(pxr::TF_CALL_CONTEXT, pxr::TF_DIAGNOSTIC_RUNTIME_ERROR_TYPE, "MaterialX cycle found: %s\n", x.what());
return; return;
} }
catch (mx::Exception &x) { catch (mx::Exception &x) {
TF_RUNTIME_ERROR("MaterialX error: %s\n", x.what()); Tf_PostErrorHelper(pxr::TF_CALL_CONTEXT, pxr::TF_DIAGNOSTIC_RUNTIME_ERROR_TYPE, "MaterialX error: %s\n", x.what());
return; return;
} }
if (UsdPrim materials = stage->GetPrimAtPath(SdfPath("/MaterialX/Materials"))) { if (pxr::UsdPrim materials = stage->GetPrimAtPath(pxr::SdfPath("/MaterialX/Materials"))) {
if (UsdPrimSiblingRange children = materials.GetChildren()) { if (pxr::UsdPrimSiblingRange children = materials.GetChildren()) {
if (auto material = UsdShadeMaterial(*children.begin())) { if (auto material = pxr::UsdShadeMaterial(*children.begin())) {
if (UsdShadeShader mtlxSurface = material.ComputeSurfaceSource(renderContexts)) { if (pxr::UsdShadeShader mtlxSurface = material.ComputeSurfaceSource(renderContexts)) {
UsdImagingBuildHdMaterialNetworkFromTerminal(mtlxSurface.GetPrim(), UsdImagingBuildHdMaterialNetworkFromTerminal(mtlxSurface.GetPrim(),
HdMaterialTerminalTokens->surface, pxr::HdMaterialTerminalTokens->surface,
shaderSourceTypes, shaderSourceTypes,
renderContexts, renderContexts,
out, out,
UsdTimeCode::Default()); pxr::UsdTimeCode::Default());
} }
} }
} }
} }
} }
PXR_NAMESPACE_CLOSE_SCOPE

View File

@ -8,13 +8,9 @@
#include <string> #include <string>
PXR_NAMESPACE_OPEN_SCOPE struct pxr::HdMaterialNetworkMap;
struct HdMaterialNetworkMap;
void HdMtlxConvertToMaterialNetworkMap(std::string const &mtlxPath, void HdMtlxConvertToMaterialNetworkMap(std::string const &mtlxPath,
TfTokenVector const &shaderSourceTypes, pxr::TfTokenVector const &shaderSourceTypes,
TfTokenVector const &renderContexts, pxr::TfTokenVector const &renderContexts,
HdMaterialNetworkMap *out); pxr::HdMaterialNetworkMap *out);
PXR_NAMESPACE_CLOSE_SCOPE

View File

@ -9,8 +9,6 @@
#include "mesh.h" #include "mesh.h"
#include "object.h" #include "object.h"
using namespace pxr;
namespace blender::render::hydra { namespace blender::render::hydra {
bool ObjectData::supported(Object *object) bool ObjectData::supported(Object *object)
@ -69,7 +67,7 @@ int ObjectData::type()
return ((Object *)id)->type; return ((Object *)id)->type;
} }
GfMatrix4d ObjectData::transform() pxr::GfMatrix4d ObjectData::transform()
{ {
return gf_matrix_from_transform(((Object *)id)->object_to_world); return gf_matrix_from_transform(((Object *)id)->object_to_world);
} }

View File

@ -28,8 +28,6 @@
/* TODO : add custom tftoken "transparency"? */ /* TODO : add custom tftoken "transparency"? */
using namespace pxr;
namespace blender::render::hydra { namespace blender::render::hydra {
std::unique_ptr<WorldData> WorldData::init(BlenderSceneDelegate *scene_delegate, std::unique_ptr<WorldData> WorldData::init(BlenderSceneDelegate *scene_delegate,
@ -39,7 +37,7 @@ std::unique_ptr<WorldData> WorldData::init(BlenderSceneDelegate *scene_delegate,
return std::make_unique<WorldData>(scene_delegate, world, context); return std::make_unique<WorldData>(scene_delegate, world, context);
} }
SdfPath WorldData::prim_id(BlenderSceneDelegate *scene_delegate) pxr::SdfPath WorldData::prim_id(BlenderSceneDelegate *scene_delegate)
{ {
return scene_delegate->GetDelegateID().AppendElementString("World"); return scene_delegate->GetDelegateID().AppendElementString("World");
} }
@ -47,7 +45,7 @@ SdfPath WorldData::prim_id(BlenderSceneDelegate *scene_delegate)
WorldData::WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContext *context) WorldData::WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContext *context)
: IdData(scene_delegate, (ID *)world) : IdData(scene_delegate, (ID *)world)
{ {
data[UsdLuxTokens->orientToStageUpAxis] = true; data[pxr::UsdLuxTokens->orientToStageUpAxis] = true;
if (world->use_nodes) { if (world->use_nodes) {
/* TODO: Create nodes parsing system */ /* TODO: Create nodes parsing system */
@ -69,9 +67,9 @@ WorldData::WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContex
float const *strength = strength_input.default_value_typed<float>(); float const *strength = strength_input.default_value_typed<float>();
float const *color = color_input.default_value_typed<float>(); float const *color = color_input.default_value_typed<float>();
data[HdLightTokens->intensity] = strength[1]; data[pxr::HdLightTokens->intensity] = strength[1];
data[HdLightTokens->exposure] = 1.0f; data[pxr::HdLightTokens->exposure] = 1.0f;
data[HdLightTokens->color] = GfVec3f(color[0], color[1], color[2]); data[pxr::HdLightTokens->color] = pxr::GfVec3f(color[0], color[1], color[2]);
if (!color_input.directly_linked_links().is_empty()) { if (!color_input.directly_linked_links().is_empty()) {
bNode *color_input_node = color_input.directly_linked_links()[0]->fromnode; bNode *color_input_node = color_input.directly_linked_links()[0]->fromnode;
@ -89,34 +87,34 @@ WorldData::WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContex
std::string image_path = cache_image(bmain, scene, image, &tex->iuser, &opts, &reports); std::string image_path = cache_image(bmain, scene, image, &tex->iuser, &opts, &reports);
if (!image_path.empty()) { if (!image_path.empty()) {
data[HdLightTokens->textureFile] = SdfAssetPath(image_path, image_path); data[pxr::HdLightTokens->textureFile] = pxr::SdfAssetPath(image_path, image_path);
} }
} }
} }
} }
} }
else { else {
data[HdLightTokens->intensity] = 1.0f; data[pxr::HdLightTokens->intensity] = 1.0f;
data[HdLightTokens->exposure] = world->exposure; data[pxr::HdLightTokens->exposure] = world->exposure;
data[HdLightTokens->color] = GfVec3f(world->horr, world->horg, world->horb); data[pxr::HdLightTokens->color] = pxr::GfVec3f(world->horr, world->horg, world->horb);
} }
} }
GfMatrix4d WorldData::transform() pxr::GfMatrix4d WorldData::transform()
{ {
GfMatrix4d transform = GfMatrix4d(GfRotation(GfVec3d(1.0, 0.0, 0.0), -90), GfVec3d()); pxr::GfMatrix4d transform = pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -90), pxr::GfVec3d());
/* TODO : do this check via RenderSettings*/ /* TODO : do this check via RenderSettings*/
if (scene_delegate->GetRenderIndex().GetRenderDelegate()->GetRendererDisplayName() == "RPR") { if (scene_delegate->GetRenderIndex().GetRenderDelegate()->GetRendererDisplayName() == "RPR") {
transform *= GfMatrix4d(GfRotation(GfVec3d(1.0, 0.0, 0.0), -180), GfVec3d()); transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -180), pxr::GfVec3d());
transform *= GfMatrix4d(GfRotation(GfVec3d(0.0, 0.0, 1.0), 90.0), GfVec3d()); transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(0.0, 0.0, 1.0), 90.0), pxr::GfVec3d());
} }
return transform; return transform;
} }
VtValue WorldData::get_data(TfToken const &key) pxr::VtValue WorldData::get_data(pxr::TfToken const &key)
{ {
VtValue ret; pxr::VtValue ret;
auto it = data.find(key); auto it = data.find(key);
if (it != data.end()) { if (it != data.end()) {
ret = it->second; ret = it->second;
@ -126,29 +124,29 @@ VtValue WorldData::get_data(TfToken const &key)
void WorldData::insert_prim() void WorldData::insert_prim()
{ {
SdfPath p_id = prim_id(scene_delegate); pxr::SdfPath p_id = prim_id(scene_delegate);
scene_delegate->GetRenderIndex().InsertSprim(HdPrimTypeTokens->domeLight, scene_delegate, p_id); scene_delegate->GetRenderIndex().InsertSprim(pxr::HdPrimTypeTokens->domeLight, scene_delegate, p_id);
LOG(INFO) << "Add World: id=" << p_id.GetAsString(); LOG(INFO) << "Add World: id=" << p_id.GetAsString();
} }
void WorldData::remove_prim() void WorldData::remove_prim()
{ {
SdfPath p_id = prim_id(scene_delegate); pxr::SdfPath p_id = prim_id(scene_delegate);
scene_delegate->GetRenderIndex().RemoveSprim(HdPrimTypeTokens->domeLight, p_id); scene_delegate->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->domeLight, p_id);
LOG(INFO) << "Remove World"; LOG(INFO) << "Remove World";
} }
void WorldData::mark_prim_dirty(DirtyBits dirty_bits) void WorldData::mark_prim_dirty(DirtyBits dirty_bits)
{ {
HdDirtyBits bits = HdLight::Clean; pxr::HdDirtyBits bits = pxr::HdLight::Clean;
switch (dirty_bits) { switch (dirty_bits) {
case DirtyBits::AllDirty: case DirtyBits::AllDirty:
bits = HdLight::AllDirty; bits = pxr::HdLight::AllDirty;
break; break;
default: default:
break; break;
} }
SdfPath p_id = prim_id(scene_delegate); pxr::SdfPath p_id = prim_id(scene_delegate);
scene_delegate->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id, bits); scene_delegate->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id, bits);
LOG(INFO) << "Update World"; LOG(INFO) << "Update World";
} }

View File

@ -7,35 +7,35 @@
namespace blender::render::hydra { namespace blender::render::hydra {
SimpleLightTaskDelegate::SimpleLightTaskDelegate(HdRenderIndex *parentIndex, SimpleLightTaskDelegate::SimpleLightTaskDelegate(pxr::HdRenderIndex *parentIndex,
SdfPath const &delegateID) pxr::SdfPath const &delegateID)
: HdSceneDelegate(parentIndex, delegateID) : pxr::HdSceneDelegate(parentIndex, delegateID)
{ {
SdfPath taskId = GetTaskID(); pxr::SdfPath taskId = GetTaskID();
GetRenderIndex().InsertTask<HdxSimpleLightTask>(this, taskId); GetRenderIndex().InsertTask<pxr::HdxSimpleLightTask>(this, taskId);
} }
SdfPath SimpleLightTaskDelegate::GetTaskID() const pxr::SdfPath SimpleLightTaskDelegate::GetTaskID() const
{ {
return GetDelegateID().AppendElementString("task"); return GetDelegateID().AppendElementString("task");
} }
HdTaskSharedPtr SimpleLightTaskDelegate::GetTask() pxr::HdTaskSharedPtr SimpleLightTaskDelegate::GetTask()
{ {
return GetRenderIndex().GetTask(GetTaskID()); return GetRenderIndex().GetTask(GetTaskID());
} }
void SimpleLightTaskDelegate::SetCameraPath(SdfPath const &cameraPath) void SimpleLightTaskDelegate::SetCameraPath(pxr::SdfPath const &cameraPath)
{ {
taskParams.cameraPath = cameraPath; taskParams.cameraPath = cameraPath;
} }
VtValue SimpleLightTaskDelegate::Get(SdfPath const &id, TfToken const &key) pxr::VtValue SimpleLightTaskDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key)
{ {
if (key == HdTokens->params) { if (key == pxr::HdTokens->params) {
return VtValue(taskParams); return pxr::VtValue(taskParams);
} }
return VtValue(); return pxr::VtValue();
} }
} // namespace blender::render::hydra } // namespace blender::render::hydra

View File

@ -6,24 +6,22 @@
#include <pxr/imaging/hd/sceneDelegate.h> #include <pxr/imaging/hd/sceneDelegate.h>
#include <pxr/imaging/hdx/simpleLightTask.h> #include <pxr/imaging/hdx/simpleLightTask.h>
using namespace pxr;
namespace blender::render::hydra { namespace blender::render::hydra {
class SimpleLightTaskDelegate : public HdSceneDelegate { class SimpleLightTaskDelegate : public pxr::HdSceneDelegate {
public: public:
SimpleLightTaskDelegate(HdRenderIndex *parentIndex, SdfPath const &delegateID); SimpleLightTaskDelegate(pxr::HdRenderIndex *parentIndex, pxr::SdfPath const &delegateID);
~SimpleLightTaskDelegate() override = default; ~SimpleLightTaskDelegate() override = default;
SdfPath GetTaskID() const; pxr::SdfPath GetTaskID() const;
HdTaskSharedPtr GetTask(); pxr::HdTaskSharedPtr GetTask();
void SetCameraPath(SdfPath const &); void SetCameraPath(pxr::SdfPath const &);
VtValue Get(SdfPath const &id, TfToken const &key) override; pxr::VtValue Get(pxr::SdfPath const &id, pxr::TfToken const &key) override;
private: private:
HdxSimpleLightTaskParams taskParams; pxr::HdxSimpleLightTaskParams taskParams;
}; };
} // namespace blender::render::hydra } // namespace blender::render::hydra

View File

@ -3,6 +3,7 @@
#include <filesystem> #include <filesystem>
#include <sstream> #include <sstream>
#include <chrono>
#include <pxr/base/tf/stringUtils.h> #include <pxr/base/tf/stringUtils.h>
@ -15,14 +16,11 @@
#include "utils.h" #include "utils.h"
using namespace std;
using namespace pxr;
namespace blender::render::hydra { namespace blender::render::hydra {
GfMatrix4d gf_matrix_from_transform(float m[4][4]) pxr::GfMatrix4d gf_matrix_from_transform(float m[4][4])
{ {
return GfMatrix4d(m[0][0], return pxr::GfMatrix4d(m[0][0],
m[0][1], m[0][1],
m[0][2], m[0][2],
m[0][3], m[0][3],
@ -40,43 +38,43 @@ GfMatrix4d gf_matrix_from_transform(float m[4][4])
m[3][3]); m[3][3]);
} }
string format_duration(chrono::milliseconds millisecs) std::string format_duration(std::chrono::milliseconds millisecs)
{ {
stringstream ss; std::stringstream ss;
bool neg = millisecs < 0ms; bool neg = millisecs < std::chrono::milliseconds(0);
if (neg) { if (neg) {
millisecs = -millisecs; millisecs = -millisecs;
} }
auto m = chrono::duration_cast<chrono::minutes>(millisecs); auto m = std::chrono::duration_cast<std::chrono::minutes>(millisecs);
millisecs -= m; millisecs -= m;
auto s = chrono::duration_cast<chrono::seconds>(millisecs); auto s = std::chrono::duration_cast<std::chrono::seconds>(millisecs);
millisecs -= s; millisecs -= s;
if (neg) { if (neg) {
ss << "-"; ss << "-";
} }
if (m < 10min) { if (m < std::chrono::minutes(10)) {
ss << "0"; ss << "0";
} }
ss << to_string(m / 1min) << ":"; ss << std::to_string(m / std::chrono::minutes(1)) << ":";
if (s < 10s) { if (s < std::chrono::seconds(10)) {
ss << "0"; ss << "0";
} }
ss << to_string(s / 1s) << ":"; ss << std::to_string(s / std::chrono::seconds(1)) << ":";
if (millisecs < 10ms) { if (millisecs < std::chrono::milliseconds(10)) {
ss << "0"; ss << "0";
} }
ss << to_string(millisecs / 1ms / 10); ss << std::to_string(millisecs / std::chrono::milliseconds(1) / 10);
return ss.str(); return ss.str();
} }
string cache_image(Main *bmain, std::string cache_image(Main *bmain,
Scene *scene, Scene *scene,
Image *image, Image *image,
ImageUser *iuser, ImageUser *iuser,
ImageSaveOptions *opts, ImageSaveOptions *opts,
ReportList *reports) ReportList *reports)
{ {
const string default_format = ".png"; const std::string default_format = ".png";
char tempfile[FILE_MAX]; char tempfile[FILE_MAX];
@ -85,15 +83,15 @@ string cache_image(Main *bmain,
return ""; return "";
} }
string image_name; std::string image_name;
if (image->source == IMA_SRC_GENERATED) { if (image->source == IMA_SRC_GENERATED) {
image_name = TfMakeValidIdentifier(image_name.append(image->id.name + 2)); image_name = pxr::TfMakeValidIdentifier(image_name.append(image->id.name + 2));
} }
else { else {
image_name = image->filepath == NULL ? image->filepath : image->id.name + 2; image_name = image->filepath == NULL ? image->filepath : image->id.name + 2;
image_name = std::filesystem::path(image_name).filename().replace_extension().string(); image_name = std::filesystem::path(image_name).filename().replace_extension().string();
image_name = TfMakeValidIdentifier(image_name); image_name = pxr::TfMakeValidIdentifier(image_name);
} }
image_name.append(default_format); image_name.append(default_format);
@ -110,13 +108,13 @@ string cache_image(Main *bmain,
return tempfile; return tempfile;
} }
void set_env_paths(string const &name, vector<string> path_dirs) void set_env_paths(std::string const &name, std::vector<std::string> path_dirs)
{ {
const char *env = BLI_getenv(name.c_str()); const char *env = BLI_getenv(name.c_str());
; ;
stringstream ss; std::stringstream ss;
int i = 0; int i = 0;
for (string &s : path_dirs) { for (std::string &s : path_dirs) {
++i; ++i;
ss << s; ss << s;
if (i < path_dirs.size() || env) { if (i < path_dirs.size() || env) {

View File

@ -21,10 +21,6 @@
#include "camera.h" #include "camera.h"
#include "utils.h" #include "utils.h"
using namespace std;
using namespace pxr;
namespace blender::render::hydra { namespace blender::render::hydra {
struct ViewSettings { struct ViewSettings {
@ -33,13 +29,13 @@ struct ViewSettings {
int width(); int width();
int height(); int height();
GfCamera gf_camera(); pxr::GfCamera gf_camera();
CameraData camera_data; CameraData camera_data;
int screen_width; int screen_width;
int screen_height; int screen_height;
GfVec4i border; pxr::GfVec4i border;
}; };
ViewSettings::ViewSettings(bContext *context) : camera_data(context) ViewSettings::ViewSettings(bContext *context) : camera_data(context)
@ -80,13 +76,13 @@ ViewSettings::ViewSettings(bContext *context) : camera_data(context)
} }
// getting camera view region // getting camera view region
float x1_f = min( float x1_f = std::min(
{screen_points[0][0], screen_points[1][0], screen_points[2][0], screen_points[3][0]}); {screen_points[0][0], screen_points[1][0], screen_points[2][0], screen_points[3][0]});
float x2_f = max( float x2_f = std::max(
{screen_points[0][0], screen_points[1][0], screen_points[2][0], screen_points[3][0]}); {screen_points[0][0], screen_points[1][0], screen_points[2][0], screen_points[3][0]});
float y1_f = min( float y1_f = std::min(
{screen_points[0][1], screen_points[1][1], screen_points[2][1], screen_points[3][1]}); {screen_points[0][1], screen_points[1][1], screen_points[2][1], screen_points[3][1]});
float y2_f = max( float y2_f = std::max(
{screen_points[0][1], screen_points[1][1], screen_points[2][1], screen_points[3][1]}); {screen_points[0][1], screen_points[1][1], screen_points[2][1], screen_points[3][1]});
// adjusting region to border // adjusting region to border
@ -99,10 +95,10 @@ ViewSettings::ViewSettings(bContext *context) : camera_data(context)
y2 = y + scene->r.border.ymax * dy; y2 = y + scene->r.border.ymax * dy;
// adjusting to region screen resolution // adjusting to region screen resolution
x1 = max(min(x1, screen_width), 0); x1 = std::max(std::min(x1, screen_width), 0);
x2 = max(min(x2, screen_width), 0); x2 = std::max(std::min(x2, screen_width), 0);
y1 = max(min(y1, screen_height), 0); y1 = std::max(std::min(y1, screen_height), 0);
y2 = max(min(y2, screen_height), 0); y2 = std::max(std::min(y2, screen_height), 0);
} }
} }
else { else {
@ -117,7 +113,7 @@ ViewSettings::ViewSettings(bContext *context) : camera_data(context)
} }
} }
border = GfVec4i(x1, y1, x2 - x1, y2 - y1); border = pxr::GfVec4i(x1, y1, x2 - x1, y2 - y1);
} }
int ViewSettings::width() int ViewSettings::width()
@ -130,9 +126,9 @@ int ViewSettings::height()
return border[3]; return border[3];
} }
GfCamera ViewSettings::gf_camera() pxr::GfCamera ViewSettings::gf_camera()
{ {
return camera_data.gf_camera(GfVec4f((float)border[0] / screen_width, return camera_data.gf_camera(pxr::GfVec4f((float)border[0] / screen_width,
(float)border[1] / screen_height, (float)border[1] / screen_height,
(float)border[2] / screen_width, (float)border[2] / screen_width,
(float)border[3] / screen_height)); (float)border[3] / screen_height));
@ -149,7 +145,7 @@ GLTexture::~GLTexture()
} }
} }
void GLTexture::setBuffer(HdRenderBuffer *buffer) void GLTexture::setBuffer(pxr::HdRenderBuffer *buffer)
{ {
if (!textureId) { if (!textureId) {
create(buffer); create(buffer);
@ -169,11 +165,11 @@ void GLTexture::setBuffer(HdRenderBuffer *buffer)
buffer->Unmap(); buffer->Unmap();
} }
void GLTexture::create(HdRenderBuffer *buffer) void GLTexture::create(pxr::HdRenderBuffer *buffer)
{ {
width = buffer->GetWidth(); width = buffer->GetWidth();
height = buffer->GetHeight(); height = buffer->GetHeight();
channels = HdGetComponentCount(buffer->GetFormat()); channels = pxr::HdGetComponentCount(buffer->GetFormat());
glGenTextures(1, &textureId); glGenTextures(1, &textureId);
glBindTexture(GL_TEXTURE_2D, textureId); glBindTexture(GL_TEXTURE_2D, textureId);
@ -246,12 +242,12 @@ void GLTexture::draw(GLfloat x, GLfloat y)
void ViewportEngine::sync(Depsgraph *depsgraph, void ViewportEngine::sync(Depsgraph *depsgraph,
bContext *context, bContext *context,
HdRenderSettingsMap &renderSettings) pxr::HdRenderSettingsMap &renderSettings)
{ {
if (!scene_delegate) { if (!scene_delegate) {
scene_delegate = std::make_unique<BlenderSceneDelegate>( scene_delegate = std::make_unique<BlenderSceneDelegate>(
render_index.get(), render_index.get(),
SdfPath::AbsoluteRootPath().AppendElementString("scene"), pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"),
BlenderSceneDelegate::EngineType::Viewport); BlenderSceneDelegate::EngineType::Viewport);
} }
scene_delegate->populate(depsgraph, context); scene_delegate->populate(depsgraph, context);
@ -268,10 +264,10 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
return; return;
}; };
GfCamera gfCamera = viewSettings.gf_camera(); pxr::GfCamera gfCamera = viewSettings.gf_camera();
free_camera_delegate->SetCamera(gfCamera); free_camera_delegate->SetCamera(gfCamera);
render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(), render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(),
GfVec4d(viewSettings.border[0], pxr::GfVec4d(viewSettings.border[0],
viewSettings.border[1], viewSettings.border[1],
viewSettings.border[2], viewSettings.border[2],
viewSettings.border[3])); viewSettings.border[3]));
@ -280,17 +276,17 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
} }
if ((bl_engine->type->flag & RE_USE_GPU_CONTEXT) == 0) { if ((bl_engine->type->flag & RE_USE_GPU_CONTEXT) == 0) {
render_task_delegate->SetRendererAov(HdAovTokens->color); render_task_delegate->SetRendererAov(pxr::HdAovTokens->color);
} }
if (renderer_percent_done() == 0.0f) { if (renderer_percent_done() == 0.0f) {
timeBegin = chrono::steady_clock::now(); timeBegin = std::chrono::steady_clock::now();
} }
GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_IMAGE); GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_IMAGE);
GPU_shader_bind(shader); GPU_shader_bind(shader);
HdTaskSharedPtrVector tasks; pxr::HdTaskSharedPtrVector tasks;
if (simple_light_task_delegate) { if (simple_light_task_delegate) {
tasks.push_back(simple_light_task_delegate->GetTask()); tasks.push_back(simple_light_task_delegate->GetTask());
} }
@ -298,26 +294,26 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
{ {
/* Release the GIL before calling into hydra, in case any hydra plugins call into python. */ /* Release the GIL before calling into hydra, in case any hydra plugins call into python. */
TF_PY_ALLOW_THREADS_IN_SCOPE(); pxr::TF_PY_ALLOW_THREADS_IN_SCOPE();
engine->Execute(render_index.get(), &tasks); engine->Execute(render_index.get(), &tasks);
if ((bl_engine->type->flag & RE_USE_GPU_CONTEXT) == 0) { if ((bl_engine->type->flag & RE_USE_GPU_CONTEXT) == 0) {
texture.setBuffer(render_task_delegate->GetRendererAov(HdAovTokens->color)); texture.setBuffer(render_task_delegate->GetRendererAov(pxr::HdAovTokens->color));
texture.draw((GLfloat)viewSettings.border[0], (GLfloat)viewSettings.border[1]); texture.draw((GLfloat)viewSettings.border[0], (GLfloat)viewSettings.border[1]);
} }
} }
GPU_shader_unbind(); GPU_shader_unbind();
chrono::time_point<chrono::steady_clock> timeCurrent = chrono::steady_clock::now(); std::chrono::time_point<std::chrono::steady_clock> timeCurrent = std::chrono::steady_clock::now();
chrono::milliseconds elapsedTime = chrono::duration_cast<chrono::milliseconds>(timeCurrent - std::chrono::milliseconds elapsedTime = std::chrono::duration_cast<std::chrono::milliseconds>(timeCurrent -
timeBegin); timeBegin);
string formattedTime = format_duration(elapsedTime); std::string formattedTime = format_duration(elapsedTime);
if (!render_task_delegate->IsConverged()) { if (!render_task_delegate->IsConverged()) {
notify_status("Time: " + formattedTime + notify_status("Time: " + formattedTime +
" | Done: " + to_string(int(renderer_percent_done())) + "%", " | Done: " + std::to_string(int(renderer_percent_done())) + "%",
"Render"); "Render");
bl_engine->flag |= RE_ENGINE_DO_DRAW; bl_engine->flag |= RE_ENGINE_DO_DRAW;
} }
@ -331,7 +327,7 @@ void ViewportEngine::render(Depsgraph *depsgraph)
/* Empty function */ /* Empty function */
} }
void ViewportEngine::notify_status(const string &info, const string &status) void ViewportEngine::notify_status(const std::string &info, const std::string &status)
{ {
RE_engine_update_stats(bl_engine, status.c_str(), info.c_str()); RE_engine_update_stats(bl_engine, status.c_str(), info.c_str());
} }