forked from blender/blender
BLEN-367: Fix code style #14
@ -7,18 +7,16 @@
|
||||
#include "camera.h"
|
||||
#include "utils.h"
|
||||
|
||||
using namespace pxr;
|
||||
|
||||
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;
|
||||
|
||||
float t_pos[2] = {tile[0], tile[1]};
|
||||
float t_size[2] = {tile[2], tile[3]};
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
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[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();
|
||||
}
|
||||
|
||||
@ -42,25 +40,25 @@ CameraData::CameraData(Object *camera_obj, GfVec2i res, GfVec4f tile)
|
||||
|
||||
switch (camera->sensor_fit) {
|
||||
case CAMERA_SENSOR_FIT_VERT:
|
||||
lens_shift = GfVec2f(camera->shiftx / ratio, camera->shifty);
|
||||
lens_shift = pxr::GfVec2f(camera->shiftx / ratio, camera->shifty);
|
||||
break;
|
||||
case CAMERA_SENSOR_FIT_HOR:
|
||||
lens_shift = GfVec2f(camera->shiftx, camera->shifty * ratio);
|
||||
lens_shift = pxr::GfVec2f(camera->shiftx, camera->shifty * ratio);
|
||||
break;
|
||||
case CAMERA_SENSOR_FIT_AUTO:
|
||||
if (ratio > 1.0f) {
|
||||
lens_shift = GfVec2f(camera->shiftx, camera->shifty * ratio);
|
||||
lens_shift = pxr::GfVec2f(camera->shiftx, camera->shifty * ratio);
|
||||
}
|
||||
else {
|
||||
lens_shift = GfVec2f(camera->shiftx / ratio, camera->shifty);
|
||||
lens_shift = pxr::GfVec2f(camera->shiftx / ratio, camera->shifty);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
lens_shift = GfVec2f(camera->shiftx, camera->shifty);
|
||||
lens_shift = pxr::GfVec2f(camera->shiftx, camera->shifty);
|
||||
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]);
|
||||
|
||||
switch (camera->type) {
|
||||
@ -69,48 +67,48 @@ CameraData::CameraData(Object *camera_obj, GfVec2i res, GfVec4f tile)
|
||||
|
||||
switch (camera->sensor_fit) {
|
||||
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;
|
||||
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;
|
||||
case CAMERA_SENSOR_FIT_AUTO:
|
||||
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 {
|
||||
sensor_size = GfVec2f(camera->sensor_x * ratio, camera->sensor_x);
|
||||
sensor_size = pxr::GfVec2f(camera->sensor_x * ratio, camera->sensor_x);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
sensor_size = GfVec2f(camera->sensor_x, camera->sensor_y);
|
||||
sensor_size = pxr::GfVec2f(camera->sensor_x, camera->sensor_y);
|
||||
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;
|
||||
|
||||
case CAM_ORTHO:
|
||||
focal_length = 0.0f;
|
||||
switch (camera->sensor_fit) {
|
||||
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;
|
||||
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;
|
||||
case CAMERA_SENSOR_FIT_AUTO:
|
||||
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 {
|
||||
ortho_size = GfVec2f(camera->ortho_scale * ratio, camera->ortho_scale);
|
||||
ortho_size = pxr::GfVec2f(camera->ortho_scale * ratio, camera->ortho_scale);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ortho_size = GfVec2f(camera->ortho_scale, camera->ortho_scale);
|
||||
ortho_size = pxr::GfVec2f(camera->ortho_scale, camera->ortho_scale);
|
||||
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;
|
||||
|
||||
case CAM_PANO:
|
||||
@ -119,28 +117,28 @@ CameraData::CameraData(Object *camera_obj, GfVec2i res, GfVec4f tile)
|
||||
|
||||
switch (camera->sensor_fit) {
|
||||
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;
|
||||
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;
|
||||
case CAMERA_SENSOR_FIT_AUTO:
|
||||
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 {
|
||||
sensor_size = GfVec2f(camera->sensor_x * ratio, camera->sensor_x);
|
||||
sensor_size = pxr::GfVec2f(camera->sensor_x * ratio, camera->sensor_x);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
sensor_size = GfVec2f(camera->sensor_x, camera->sensor_y);
|
||||
sensor_size = pxr::GfVec2f(camera->sensor_x, camera->sensor_y);
|
||||
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:
|
||||
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
|
||||
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];
|
||||
transform = gf_matrix_from_transform(region_data->viewmat).GetInverse();
|
||||
|
||||
switch (region_data->persp) {
|
||||
case RV3D_PERSP: {
|
||||
mode = CAM_PERSP;
|
||||
clip_range = GfRange1f(view3d->clip_start, view3d->clip_end);
|
||||
lens_shift = GfVec2f(0.0, 0.0);
|
||||
clip_range = pxr::GfRange1f(view3d->clip_start, view3d->clip_end);
|
||||
lens_shift = pxr::GfVec2f(0.0, 0.0);
|
||||
focal_length = view3d->lens;
|
||||
|
||||
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 {
|
||||
sensor_size = GfVec2f(VIEWPORT_SENSOR_SIZE * ratio, VIEWPORT_SENSOR_SIZE);
|
||||
sensor_size = pxr::GfVec2f(VIEWPORT_SENSOR_SIZE * ratio, VIEWPORT_SENSOR_SIZE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case RV3D_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_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) {
|
||||
ortho_size = GfVec2f(o_size, o_size / ratio);
|
||||
ortho_size = pxr::GfVec2f(o_size, o_size / ratio);
|
||||
}
|
||||
else {
|
||||
ortho_size = GfVec2f(o_size * ratio, o_size);
|
||||
ortho_size = pxr::GfVec2f(o_size * ratio, o_size);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case RV3D_CAMOB: {
|
||||
GfMatrix4d mat = transform;
|
||||
*this = CameraData(view3d->camera, res, GfVec4f(0, 0, 1, 1));
|
||||
pxr::GfMatrix4d mat = transform;
|
||||
*this = CameraData(view3d->camera, res, pxr::GfVec4f(0, 0, 1, 1));
|
||||
transform = mat;
|
||||
|
||||
// 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
|
||||
// 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);
|
||||
|
||||
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]};
|
||||
|
||||
GfCamera gf_camera = GfCamera();
|
||||
pxr::GfCamera gf_camera = pxr::GfCamera();
|
||||
|
||||
gf_camera.SetClippingRange(clip_range);
|
||||
|
||||
@ -236,7 +234,7 @@ GfCamera CameraData::gf_camera(GfVec4f tile)
|
||||
case CAM_PERSP:
|
||||
case CAM_PANO: {
|
||||
/* TODO: store panoramic camera settings */
|
||||
gf_camera.SetProjection(GfCamera::Projection::Perspective);
|
||||
gf_camera.SetProjection(pxr::GfCamera::Projection::Perspective);
|
||||
gf_camera.SetFocalLength(focal_length);
|
||||
|
||||
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;
|
||||
}
|
||||
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
|
||||
// https://graphics.pixar.com/usd/docs/api/class_gf_camera.html
|
||||
@ -270,9 +268,9 @@ GfCamera CameraData::gf_camera(GfVec4f tile)
|
||||
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
|
||||
|
@ -12,37 +12,35 @@
|
||||
|
||||
#include "engine.h"
|
||||
|
||||
using namespace pxr;
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
Engine::Engine(RenderEngine *bl_engine, const std::string &delegateId) : bl_engine(bl_engine)
|
||||
{
|
||||
HdRendererPluginRegistry ®istry = HdRendererPluginRegistry::GetInstance();
|
||||
pxr::HdRendererPluginRegistry ®istry = pxr::HdRendererPluginRegistry::GetInstance();
|
||||
|
||||
TF_PY_ALLOW_THREADS_IN_SCOPE();
|
||||
render_delegate = registry.CreateRenderDelegate(TfToken(delegateId));
|
||||
|
||||
HdDriverVector hd_drivers;
|
||||
//TF_PY_ALLOW_THREADS_IN_SCOPE();
|
||||
render_delegate = registry.CreateRenderDelegate(pxr::TfToken(delegateId));
|
||||
|
||||
pxr::HdDriverVector hd_drivers;
|
||||
if (bl_engine->type->flag & RE_USE_GPU_CONTEXT) {
|
||||
hgi = Hgi::CreatePlatformDefaultHgi();
|
||||
hgi_driver.name = HgiTokens->renderDriver;
|
||||
hgi_driver.driver = VtValue(hgi.get());
|
||||
hgi = pxr::Hgi::CreatePlatformDefaultHgi();
|
||||
hgi_driver.name = pxr::HgiTokens->renderDriver;
|
||||
hgi_driver.driver = pxr::VtValue(hgi.get());
|
||||
|
||||
hd_drivers.push_back(&hgi_driver);
|
||||
}
|
||||
|
||||
render_index.reset(HdRenderIndex::New(render_delegate.Get(), hd_drivers));
|
||||
free_camera_delegate = std::make_unique<HdxFreeCameraSceneDelegate>(
|
||||
render_index.get(), SdfPath::AbsoluteRootPath().AppendElementString("freeCamera"));
|
||||
render_index.reset(pxr::HdRenderIndex::New(render_delegate.Get(), hd_drivers));
|
||||
free_camera_delegate = std::make_unique<pxr::HdxFreeCameraSceneDelegate>(
|
||||
render_index.get(), pxr::SdfPath::AbsoluteRootPath().AppendElementString("freeCamera"));
|
||||
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") {
|
||||
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()
|
||||
@ -59,7 +57,7 @@ Engine::~Engine()
|
||||
|
||||
float Engine::renderer_percent_done()
|
||||
{
|
||||
VtDictionary render_stats = render_delegate->GetRenderStats();
|
||||
pxr::VtDictionary render_stats = render_delegate->GetRenderStats();
|
||||
auto it = render_stats.find("percentDone");
|
||||
if (it == render_stats.end()) {
|
||||
return 0.0;
|
||||
|
@ -37,16 +37,16 @@ class Engine {
|
||||
protected:
|
||||
RenderEngine *bl_engine;
|
||||
|
||||
HdPluginRenderDelegateUniqueHandle render_delegate;
|
||||
std::unique_ptr<HdRenderIndex> render_index;
|
||||
pxr::HdPluginRenderDelegateUniqueHandle render_delegate;
|
||||
std::unique_ptr<pxr::HdRenderIndex> render_index;
|
||||
std::unique_ptr<BlenderSceneDelegate> scene_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<HdEngine> engine;
|
||||
std::unique_ptr<pxr::HdEngine> engine;
|
||||
|
||||
HgiUniquePtr hgi;
|
||||
HdDriver hgi_driver;
|
||||
pxr::HgiUniquePtr hgi;
|
||||
pxr::HdDriver hgi_driver;
|
||||
};
|
||||
|
||||
} // namespace blender::render::hydra
|
||||
|
@ -12,18 +12,15 @@
|
||||
#include "final_engine.h"
|
||||
#include "utils.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace pxr;
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
void FinalEngine::sync(Depsgraph *depsgraph,
|
||||
bContext *context,
|
||||
HdRenderSettingsMap &renderSettings)
|
||||
pxr::HdRenderSettingsMap &renderSettings)
|
||||
{
|
||||
scene_delegate = std::make_unique<BlenderSceneDelegate>(
|
||||
render_index.get(),
|
||||
SdfPath::AbsoluteRootPath().AppendElementString("scene"),
|
||||
pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"),
|
||||
BlenderSceneDelegate::EngineType::Final);
|
||||
scene_delegate->populate(depsgraph, context);
|
||||
|
||||
@ -37,48 +34,48 @@ void FinalEngine::render(Depsgraph *depsgraph)
|
||||
Scene *scene = DEG_get_input_scene(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);
|
||||
string layer_name = view_layer->name;
|
||||
std::string layer_name = view_layer->name;
|
||||
|
||||
RenderData &r = scene->r;
|
||||
GfVec4f border(0, 0, 1, 1);
|
||||
pxr::GfVec4f border(0, 0, 1, 1);
|
||||
if (r.mode & R_BORDER) {
|
||||
border = GfVec4f(r.border.xmin,
|
||||
border = pxr::GfVec4f(r.border.xmin,
|
||||
r.border.ymin,
|
||||
r.border.xmax - r.border.xmin,
|
||||
r.border.ymax - r.border.ymin);
|
||||
}
|
||||
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]));
|
||||
GfCamera camera = CameraData(scene->camera, image_res, GfVec4f(0, 0, 1, 1)).gf_camera(border);
|
||||
pxr::GfVec2i image_res(r.xsch * r.size / 100, r.ysch * r.size / 100);
|
||||
pxr::GfVec2i res(int(image_res[0] * border[2]), int(image_res[1] * border[3]));
|
||||
pxr::GfCamera camera = CameraData(scene->camera, image_res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(border);
|
||||
|
||||
free_camera_delegate->SetCamera(camera);
|
||||
render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(),
|
||||
GfVec4d(0, 0, res[0], res[1]));
|
||||
render_task_delegate->SetRendererAov(HdAovTokens->color);
|
||||
pxr::GfVec4d(0, 0, res[0], res[1]));
|
||||
render_task_delegate->SetRendererAov(pxr::HdAovTokens->color);
|
||||
if (simple_light_task_delegate) {
|
||||
simple_light_task_delegate->SetCameraPath(free_camera_delegate->GetCameraId());
|
||||
}
|
||||
|
||||
HdTaskSharedPtrVector tasks;
|
||||
pxr::HdTaskSharedPtrVector tasks;
|
||||
if (simple_light_task_delegate) {
|
||||
tasks.push_back(simple_light_task_delegate->GetTask());
|
||||
}
|
||||
tasks.push_back(render_task_delegate->GetTask());
|
||||
|
||||
chrono::time_point<chrono::steady_clock> timeBegin = chrono::steady_clock::now(), timeCurrent;
|
||||
chrono::milliseconds elapsedTime;
|
||||
std::chrono::time_point<std::chrono::steady_clock> timeBegin = std::chrono::steady_clock::now(), timeCurrent;
|
||||
std::chrono::milliseconds elapsedTime;
|
||||
|
||||
float percentDone = 0.0;
|
||||
|
||||
map<string, vector<float>> renderImages{
|
||||
{"Combined", vector<float>(res[0] * res[1] * 4)}}; // 4 - number of channels
|
||||
vector<float> &pixels = renderImages["Combined"];
|
||||
std::map<std::string, std::vector<float>> renderImages{
|
||||
{"Combined", std::vector<float>(res[0] * res[1] * 4)}}; // 4 - number of channels
|
||||
std::vector<float> &pixels = renderImages["Combined"];
|
||||
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
|
||||
@ -88,27 +85,27 @@ void FinalEngine::render(Depsgraph *depsgraph)
|
||||
}
|
||||
|
||||
percentDone = renderer_percent_done();
|
||||
timeCurrent = chrono::steady_clock::now();
|
||||
elapsedTime = chrono::duration_cast<chrono::milliseconds>(timeCurrent - timeBegin);
|
||||
timeCurrent = std::chrono::steady_clock::now();
|
||||
elapsedTime = std::chrono::duration_cast<std::chrono::milliseconds>(timeCurrent - timeBegin);
|
||||
|
||||
notify_status(percentDone / 100.0,
|
||||
scene_name + ": " + layer_name,
|
||||
"Render Time: " + format_duration(elapsedTime) +
|
||||
" | Done: " + to_string(int(percentDone)) + "%");
|
||||
" | Done: " + std::to_string(int(percentDone)) + "%");
|
||||
|
||||
if (render_task_delegate->IsConverged()) {
|
||||
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]);
|
||||
}
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
GfVec2i FinalEngine::get_resolution(Scene *scene)
|
||||
pxr::GfVec2i FinalEngine::get_resolution(Scene *scene)
|
||||
{
|
||||
RenderData &r = scene->r;
|
||||
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_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,
|
||||
const string &layerName,
|
||||
void FinalEngine::updateRenderResult(std::map<std::string, std::vector<float>> &renderImages,
|
||||
const std::string &layerName,
|
||||
int width,
|
||||
int height)
|
||||
{
|
||||
@ -142,7 +139,7 @@ void FinalEngine::updateRenderResult(map<string, vector<float>> &renderImages,
|
||||
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_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);
|
||||
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);
|
||||
string layer_name = view_layer->name;
|
||||
std::string layer_name = view_layer->name;
|
||||
|
||||
RenderData &r = scene->r;
|
||||
GfVec4f border(0, 0, 1, 1);
|
||||
pxr::GfVec4f border(0, 0, 1, 1);
|
||||
if (r.mode & R_BORDER) {
|
||||
border = GfVec4f(r.border.xmin,
|
||||
border = pxr::GfVec4f(r.border.xmin,
|
||||
r.border.ymin,
|
||||
r.border.xmax - r.border.xmin,
|
||||
r.border.ymax - r.border.ymin);
|
||||
}
|
||||
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])};
|
||||
GfCamera camera = CameraData(scene->camera, image_res, GfVec4f(0, 0, 1, 1)).gf_camera(border);
|
||||
pxr::GfVec2i image_res = {r.xsch * r.size / 100, r.ysch * r.size / 100};
|
||||
pxr::GfVec2i res = {int(image_res[0] * border[2]), int(image_res[1] * border[3])};
|
||||
pxr::GfCamera camera = CameraData(scene->camera, image_res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(border);
|
||||
|
||||
free_camera_delegate->SetCamera(camera);
|
||||
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) {
|
||||
simple_light_task_delegate->SetCameraPath(free_camera_delegate->GetCameraId());
|
||||
}
|
||||
|
||||
HdTaskSharedPtrVector tasks;
|
||||
pxr::HdTaskSharedPtrVector tasks;
|
||||
if (simple_light_task_delegate) {
|
||||
/* TODO: Uncomment this and fix GL error:
|
||||
invalid operation, reported from void __cdecl
|
||||
@ -185,14 +182,14 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
|
||||
}
|
||||
tasks.push_back(render_task_delegate->GetTask());
|
||||
|
||||
chrono::time_point<chrono::steady_clock> timeBegin = chrono::steady_clock::now(), timeCurrent;
|
||||
chrono::milliseconds elapsedTime;
|
||||
std::chrono::time_point<std::chrono::steady_clock> timeBegin = std::chrono::steady_clock::now(), timeCurrent;
|
||||
std::chrono::milliseconds elapsedTime;
|
||||
|
||||
float percentDone = 0.0;
|
||||
|
||||
map<string, vector<float>> renderImages{
|
||||
{"Combined", vector<float>(res[0] * res[1] * 4)}}; // 4 - number of channels
|
||||
vector<float> &pixels = renderImages["Combined"];
|
||||
std::map<std::string, std::vector<float>> renderImages{
|
||||
{"Combined", std::vector<float>(res[0] * res[1] * 4)}}; // 4 - number of channels
|
||||
std::vector<float> &pixels = renderImages["Combined"];
|
||||
|
||||
GLuint FramebufferName = 0;
|
||||
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.
|
||||
TF_PY_ALLOW_THREADS_IN_SCOPE();
|
||||
pxr::TF_PY_ALLOW_THREADS_IN_SCOPE();
|
||||
engine->Execute(render_index.get(), &tasks);
|
||||
}
|
||||
|
||||
@ -232,13 +229,13 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
|
||||
}
|
||||
|
||||
percentDone = renderer_percent_done();
|
||||
timeCurrent = chrono::steady_clock::now();
|
||||
elapsedTime = chrono::duration_cast<chrono::milliseconds>(timeCurrent - timeBegin);
|
||||
timeCurrent = std::chrono::steady_clock::now();
|
||||
elapsedTime = std::chrono::duration_cast<std::chrono::milliseconds>(timeCurrent - timeBegin);
|
||||
|
||||
notify_status(percentDone / 100.0,
|
||||
scene_name + ": " + layer_name,
|
||||
"Render Time: " + format_duration(elapsedTime) +
|
||||
" | Done: " + to_string(int(percentDone)) + "%");
|
||||
" | Done: " + std::to_string(int(percentDone)) + "%");
|
||||
|
||||
if (render_task_delegate->IsConverged()) {
|
||||
break;
|
||||
|
@ -26,7 +26,7 @@ class FinalEngine : public Engine {
|
||||
void notify_status(float progress, const std::string &title, const std::string &info);
|
||||
|
||||
protected:
|
||||
HdRenderSettingsMap renderSettings;
|
||||
pxr::HdRenderSettingsMap renderSettings;
|
||||
};
|
||||
|
||||
class FinalEngineGL : public FinalEngine {
|
||||
|
@ -6,18 +6,15 @@
|
||||
#include "camera.h"
|
||||
#include "preview_engine.h"
|
||||
|
||||
using namespace pxr;
|
||||
using namespace std;
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
void PreviewEngine::sync(Depsgraph *depsgraph,
|
||||
bContext *context,
|
||||
HdRenderSettingsMap &renderSettings)
|
||||
pxr::HdRenderSettingsMap &renderSettings)
|
||||
{
|
||||
scene_delegate = make_unique<BlenderSceneDelegate>(
|
||||
scene_delegate = std::make_unique<BlenderSceneDelegate>(
|
||||
render_index.get(),
|
||||
SdfPath::AbsoluteRootPath().AppendElementString("scene"),
|
||||
pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"),
|
||||
BlenderSceneDelegate::EngineType::Preview);
|
||||
scene_delegate->populate(depsgraph, context);
|
||||
|
||||
@ -31,28 +28,28 @@ void PreviewEngine::render(Depsgraph *depsgraph)
|
||||
Scene *scene = DEG_get_input_scene(depsgraph);
|
||||
ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph);
|
||||
|
||||
string layerName = view_layer->name;
|
||||
GfVec2i res(scene->r.xsch, scene->r.ysch);
|
||||
std::string layerName = view_layer->name;
|
||||
pxr::GfVec2i res(scene->r.xsch, scene->r.ysch);
|
||||
|
||||
GfCamera camera =
|
||||
CameraData(scene->camera, res, GfVec4f(0, 0, 1, 1)).gf_camera(GfVec4f(0, 0, 1, 1));
|
||||
pxr::GfCamera camera =
|
||||
CameraData(scene->camera, res, pxr::GfVec4f(0, 0, 1, 1)).gf_camera(pxr::GfVec4f(0, 0, 1, 1));
|
||||
|
||||
free_camera_delegate->SetCamera(camera);
|
||||
render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(),
|
||||
GfVec4d(0, 0, res[0], res[1]));
|
||||
render_task_delegate->SetRendererAov(HdAovTokens->color);
|
||||
pxr::GfVec4d(0, 0, res[0], res[1]));
|
||||
render_task_delegate->SetRendererAov(pxr::HdAovTokens->color);
|
||||
|
||||
HdTaskSharedPtrVector tasks;
|
||||
pxr::HdTaskSharedPtrVector tasks;
|
||||
if (simple_light_task_delegate) {
|
||||
tasks.push_back(simple_light_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.
|
||||
TF_PY_ALLOW_THREADS_IN_SCOPE();
|
||||
pxr::TF_PY_ALLOW_THREADS_IN_SCOPE();
|
||||
engine->Execute(render_index.get(), &tasks);
|
||||
}
|
||||
|
||||
@ -65,18 +62,18 @@ void PreviewEngine::render(Depsgraph *depsgraph)
|
||||
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);
|
||||
}
|
||||
|
||||
render_task_delegate->GetRendererAovData(HdAovTokens->color, pixels.data());
|
||||
render_task_delegate->GetRendererAovData(pxr::HdAovTokens->color, pixels.data());
|
||||
updateRenderResult(layerName, res[0], res[1], pixels);
|
||||
}
|
||||
|
||||
void PreviewEngine::updateRenderResult(const string &layerName,
|
||||
void PreviewEngine::updateRenderResult(const std::string &layerName,
|
||||
int width,
|
||||
int height,
|
||||
vector<float> &pixels)
|
||||
std::vector<float> &pixels)
|
||||
{
|
||||
RenderResult *result = RE_engine_begin_result(
|
||||
bl_engine, 0, 0, width, height, layerName.c_str(), nullptr);
|
||||
|
@ -22,7 +22,7 @@ class PreviewEngine : public FinalEngine {
|
||||
std::vector<float> &pixels);
|
||||
|
||||
protected:
|
||||
HdRenderSettingsMap renderSettings;
|
||||
pxr::HdRenderSettingsMap renderSettings;
|
||||
};
|
||||
|
||||
} // namespace blender::render::hydra
|
||||
|
@ -18,8 +18,6 @@
|
||||
#include "utils.h"
|
||||
#include "viewport_engine.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
void setup_usd_mtlx_environment()
|
||||
@ -47,7 +45,7 @@ static PyObject *init_func(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
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");
|
||||
|
||||
setup_usd_mtlx_environment();
|
||||
@ -64,7 +62,7 @@ static PyObject *register_plugins_func(PyObject * /*self*/, PyObject *args)
|
||||
|
||||
LOG(INFO) << "register_plugins_func";
|
||||
|
||||
vector<string> plugin_dirs, path_dirs;
|
||||
std::vector<std::string> plugin_dirs, path_dirs;
|
||||
PyObject *pyiter, *pyitem;
|
||||
|
||||
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";
|
||||
|
||||
PlugRegistry ®istry = PlugRegistry::GetInstance();
|
||||
TfTokenVector plugin_ids = UsdImagingGLEngine::GetRendererPlugins();
|
||||
pxr::PlugRegistry ®istry = pxr::PlugRegistry::GetInstance();
|
||||
pxr::TfTokenVector plugin_ids = pxr::UsdImagingGLEngine::GetRendererPlugins();
|
||||
PyObject *ret = PyTuple_New(plugin_ids.size());
|
||||
PyObject *val;
|
||||
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,
|
||||
"name",
|
||||
val = PyUnicode_FromString(
|
||||
UsdImagingGLEngine::GetRendererDisplayName(plugin_ids[i]).c_str()));
|
||||
pxr::UsdImagingGLEngine::GetRendererDisplayName(plugin_ids[i]).c_str()));
|
||||
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[0] = tolower(plugin_name[0]);
|
||||
string path = "";
|
||||
PlugPluginPtr plugin = registry.GetPluginWithName(plugin_name);
|
||||
std::string path = "";
|
||||
pxr::PlugPluginPtr plugin = registry.GetPluginWithName(plugin_name);
|
||||
if (plugin) {
|
||||
path = plugin->GetPath();
|
||||
}
|
||||
@ -145,10 +143,10 @@ static PyObject *engine_create_func(PyObject * /*self*/, PyObject *args)
|
||||
|
||||
Engine *engine;
|
||||
|
||||
if (string(engineType) == "VIEWPORT") {
|
||||
if (std::string(engineType) == "VIEWPORT") {
|
||||
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);
|
||||
}
|
||||
else {
|
||||
@ -187,12 +185,12 @@ static PyObject *engine_sync_func(PyObject * /*self*/, PyObject *args)
|
||||
Depsgraph *depsgraph = (Depsgraph *)PyLong_AsVoidPtr(pydepsgraph);
|
||||
bContext *context = (bContext *)PyLong_AsVoidPtr(pycontext);
|
||||
|
||||
HdRenderSettingsMap settings;
|
||||
pxr::HdRenderSettingsMap settings;
|
||||
PyObject *pyiter = PyObject_GetIter(pysettings);
|
||||
if (pyiter) {
|
||||
PyObject *pykey, *pyval;
|
||||
while (pykey = PyIter_Next(pyiter)) {
|
||||
TfToken key(PyUnicode_AsUTF8(pykey));
|
||||
pxr::TfToken key(PyUnicode_AsUTF8(pykey));
|
||||
pyval = PyDict_GetItem(pysettings, pykey);
|
||||
|
||||
if (PyLong_Check(pyval)) {
|
||||
|
@ -13,117 +13,117 @@
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
RenderTaskDelegate::RenderTaskDelegate(HdRenderIndex *parentIndex, SdfPath const &delegateID)
|
||||
: HdSceneDelegate(parentIndex, delegateID)
|
||||
RenderTaskDelegate::RenderTaskDelegate(pxr::HdRenderIndex *parentIndex, pxr::SdfPath const &delegateID)
|
||||
: pxr::HdSceneDelegate(parentIndex, delegateID)
|
||||
{
|
||||
SdfPath renderTaskId = GetTaskID();
|
||||
GetRenderIndex().InsertTask<HdxRenderTask>(this, renderTaskId);
|
||||
pxr::SdfPath renderTaskId = GetTaskID();
|
||||
GetRenderIndex().InsertTask<pxr::HdxRenderTask>(this, renderTaskId);
|
||||
GetRenderIndex().GetChangeTracker().MarkTaskDirty(renderTaskId,
|
||||
HdChangeTracker::DirtyCollection);
|
||||
pxr::HdChangeTracker::DirtyCollection);
|
||||
GetRenderIndex().GetChangeTracker().MarkTaskDirty(renderTaskId,
|
||||
HdChangeTracker::DirtyRenderTags);
|
||||
pxr::HdChangeTracker::DirtyRenderTags);
|
||||
|
||||
taskParams.enableLighting = true;
|
||||
taskParams.alphaThreshold = 0.1f;
|
||||
}
|
||||
|
||||
SdfPath RenderTaskDelegate::GetTaskID() const
|
||||
pxr::SdfPath RenderTaskDelegate::GetTaskID() const
|
||||
{
|
||||
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());
|
||||
}
|
||||
|
||||
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";
|
||||
if (key == HdTokens->params) {
|
||||
return VtValue(taskParams);
|
||||
if (key == pxr::HdTokens->params) {
|
||||
return pxr::VtValue(taskParams);
|
||||
}
|
||||
if (key == HdTokens->collection) {
|
||||
HdRprimCollection rprimCollection(
|
||||
HdTokens->geometry, HdReprSelector(HdReprTokens->smoothHull), false, TfToken());
|
||||
rprimCollection.SetRootPath(SdfPath::AbsoluteRootPath());
|
||||
return VtValue(rprimCollection);
|
||||
if (key == pxr::HdTokens->collection) {
|
||||
pxr::HdRprimCollection rprimCollection(
|
||||
pxr::HdTokens->geometry, pxr::HdReprSelector(pxr::HdReprTokens->smoothHull), false, pxr::TfToken());
|
||||
rprimCollection.SetRootPath(pxr::SdfPath::AbsoluteRootPath());
|
||||
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";
|
||||
return bufferDescriptors[id];
|
||||
}
|
||||
|
||||
TfTokenVector RenderTaskDelegate::GetTaskRenderTags(SdfPath const &taskId)
|
||||
pxr::TfTokenVector RenderTaskDelegate::GetTaskRenderTags(pxr::SdfPath const &taskId)
|
||||
{
|
||||
LOG(INFO) << "RenderTaskDelegate::GetTaskRenderTags - " << taskId.GetAsString() << "\n";
|
||||
return {HdRenderTagTokens->geometry};
|
||||
return {pxr::HdRenderTagTokens->geometry};
|
||||
}
|
||||
|
||||
bool RenderTaskDelegate::IsConverged()
|
||||
{
|
||||
HdTaskSharedPtr renderTask = GetRenderIndex().GetTask(GetTaskID());
|
||||
return ((HdxRenderTask &)*renderTask).IsConverged();
|
||||
pxr::HdTaskSharedPtr renderTask = GetRenderIndex().GetTask(GetTaskID());
|
||||
return ((pxr::HdxRenderTask &)*renderTask).IsConverged();
|
||||
}
|
||||
|
||||
void RenderTaskDelegate::SetRendererAov(TfToken const &aov)
|
||||
void RenderTaskDelegate::SetRendererAov(pxr::TfToken const &aov)
|
||||
{
|
||||
HdAovDescriptor aovDesc = GetRenderIndex().GetRenderDelegate()->GetDefaultAovDescriptor(aov);
|
||||
HdRenderBufferDescriptor desc(GfVec3i(taskParams.viewport[2], taskParams.viewport[3], 1),
|
||||
pxr::HdAovDescriptor aovDesc = GetRenderIndex().GetRenderDelegate()->GetDefaultAovDescriptor(aov);
|
||||
pxr::HdRenderBufferDescriptor desc(pxr::GfVec3i(taskParams.viewport[2], taskParams.viewport[3], 1),
|
||||
aovDesc.format,
|
||||
aovDesc.multiSampled);
|
||||
SdfPath bufferId = GetAovID(aov);
|
||||
pxr::SdfPath bufferId = GetAovID(aov);
|
||||
|
||||
if (bufferDescriptors.find(bufferId) == bufferDescriptors.end()) {
|
||||
GetRenderIndex().InsertBprim(HdPrimTypeTokens->renderBuffer, this, bufferId);
|
||||
GetRenderIndex().InsertBprim(pxr::HdPrimTypeTokens->renderBuffer, this, bufferId);
|
||||
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.renderBufferId = bufferId;
|
||||
binding.aovSettings = aovDesc.aovSettings;
|
||||
taskParams.aovBindings.push_back(binding);
|
||||
|
||||
GetRenderIndex().GetChangeTracker().MarkTaskDirty(GetTaskID(), HdChangeTracker::DirtyParams);
|
||||
GetRenderIndex().GetChangeTracker().MarkTaskDirty(GetTaskID(), pxr::HdChangeTracker::DirtyParams);
|
||||
}
|
||||
else if (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 (
|
||||
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();
|
||||
memcpy(data,
|
||||
bufData,
|
||||
buffer->GetWidth() * buffer->GetHeight() * HdDataSizeOfFormat(buffer->GetFormat()));
|
||||
buffer->GetWidth() * buffer->GetHeight() * pxr::HdDataSizeOfFormat(buffer->GetFormat()));
|
||||
buffer->Unmap();
|
||||
}
|
||||
|
||||
HdTaskSharedPtr RenderTaskDelegate::GetTask()
|
||||
pxr::HdTaskSharedPtr RenderTaskDelegate::GetTask()
|
||||
{
|
||||
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) {
|
||||
taskParams.viewport = viewport;
|
||||
taskParams.camera = cameraId;
|
||||
GetRenderIndex().GetChangeTracker().MarkTaskDirty(GetTaskID(), HdChangeTracker::DirtyParams);
|
||||
GetRenderIndex().GetChangeTracker().MarkTaskDirty(GetTaskID(), pxr::HdChangeTracker::DirtyParams);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,33 +6,31 @@
|
||||
#include <pxr/imaging/hd/sceneDelegate.h>
|
||||
#include <pxr/imaging/hdx/renderSetupTask.h>
|
||||
|
||||
using namespace pxr;
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
class RenderTaskDelegate : public HdSceneDelegate {
|
||||
class RenderTaskDelegate : public pxr::HdSceneDelegate {
|
||||
public:
|
||||
RenderTaskDelegate(HdRenderIndex *parentIndex, SdfPath const &delegateID);
|
||||
RenderTaskDelegate(pxr::HdRenderIndex *parentIndex, pxr::SdfPath const &delegateID);
|
||||
~RenderTaskDelegate() override = default;
|
||||
|
||||
SdfPath GetTaskID() const;
|
||||
SdfPath GetAovID(TfToken const &aov) const;
|
||||
pxr::SdfPath GetTaskID() const;
|
||||
pxr::SdfPath GetAovID(pxr::TfToken const &aov) const;
|
||||
|
||||
VtValue Get(SdfPath const &id, TfToken const &key) override;
|
||||
HdRenderBufferDescriptor GetRenderBufferDescriptor(SdfPath const &id) override;
|
||||
TfTokenVector GetTaskRenderTags(SdfPath const &taskId) override;
|
||||
pxr::VtValue Get(pxr::SdfPath const &id, pxr::TfToken const &key) override;
|
||||
pxr::HdRenderBufferDescriptor GetRenderBufferDescriptor(pxr::SdfPath const &id) override;
|
||||
pxr::TfTokenVector GetTaskRenderTags(pxr::SdfPath const &taskId) override;
|
||||
|
||||
bool IsConverged();
|
||||
void SetRendererAov(TfToken const &aovId);
|
||||
HdRenderBuffer *GetRendererAov(TfToken const &id);
|
||||
void GetRendererAovData(TfToken const &id, void *buf);
|
||||
void SetRendererAov(pxr::TfToken const &aovId);
|
||||
pxr::HdRenderBuffer *GetRendererAov(pxr::TfToken const &id);
|
||||
void GetRendererAovData(pxr::TfToken const &id, void *buf);
|
||||
|
||||
HdTaskSharedPtr GetTask();
|
||||
void SetCameraAndViewport(SdfPath const &cameraId, GfVec4d const &viewport);
|
||||
pxr::HdTaskSharedPtr GetTask();
|
||||
void SetCameraAndViewport(pxr::SdfPath const &cameraId, pxr::GfVec4d const &viewport);
|
||||
|
||||
private:
|
||||
HdxRenderTaskParams taskParams;
|
||||
TfHashMap<SdfPath, HdRenderBufferDescriptor, SdfPath::Hash> bufferDescriptors;
|
||||
pxr::HdxRenderTaskParams taskParams;
|
||||
pxr::TfHashMap<pxr::SdfPath, pxr::HdRenderBufferDescriptor, pxr::SdfPath::Hash> bufferDescriptors;
|
||||
};
|
||||
|
||||
} // namespace blender::render::hydra
|
||||
|
@ -8,13 +8,10 @@
|
||||
|
||||
#include "blender_scene_delegate.h"
|
||||
|
||||
using namespace pxr;
|
||||
using namespace std;
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
BlenderSceneDelegate::BlenderSceneDelegate(HdRenderIndex *parentIndex,
|
||||
SdfPath const &delegateID,
|
||||
BlenderSceneDelegate::BlenderSceneDelegate(pxr::HdRenderIndex *parentIndex,
|
||||
pxr::SdfPath const &delegateID,
|
||||
BlenderSceneDelegate::EngineType engine_type)
|
||||
: HdSceneDelegate(parentIndex, delegateID),
|
||||
engine_type(engine_type),
|
||||
@ -28,10 +25,10 @@ void BlenderSceneDelegate::set_material(MeshData &mesh_data)
|
||||
{
|
||||
Material *material = mesh_data.material();
|
||||
if (!material) {
|
||||
mesh_data.material_id = SdfPath::EmptyPath();
|
||||
mesh_data.material_id = pxr::SdfPath::EmptyPath();
|
||||
return;
|
||||
}
|
||||
SdfPath id = MaterialData::prim_id(this, material);
|
||||
pxr::SdfPath id = MaterialData::prim_id(this, material);
|
||||
MaterialData *mat_data = material_data(id);
|
||||
if (!mat_data) {
|
||||
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)) {
|
||||
return true;
|
||||
@ -82,45 +79,45 @@ bool BlenderSceneDelegate::GetVisible(SdfPath const &id)
|
||||
return object_data(id)->visible;
|
||||
}
|
||||
|
||||
SdfPath BlenderSceneDelegate::GetInstancerId(SdfPath const &primId)
|
||||
pxr::SdfPath BlenderSceneDelegate::GetInstancerId(pxr::SdfPath const &primId)
|
||||
{
|
||||
LOG(INFO) << "GetInstancerId: " << primId.GetAsString();
|
||||
MeshData *m_data = mesh_data(primId);
|
||||
if (m_data) {
|
||||
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();
|
||||
SdfPathVector paths;
|
||||
pxr::SdfPathVector paths;
|
||||
paths.push_back(instancerId.GetParentPath());
|
||||
return paths;
|
||||
}
|
||||
|
||||
VtIntArray BlenderSceneDelegate::GetInstanceIndices(SdfPath const &instancerId,
|
||||
SdfPath const &prototypeId)
|
||||
pxr::VtIntArray BlenderSceneDelegate::GetInstanceIndices(pxr::SdfPath const &instancerId,
|
||||
pxr::SdfPath const &prototypeId)
|
||||
{
|
||||
LOG(INFO) << "GetInstanceIndices: " << instancerId.GetString() << " " << prototypeId.GetString();
|
||||
MeshData *m_data = mesh_data(prototypeId);
|
||||
VtIntArray ret = m_data->instance_indices();
|
||||
pxr::VtIntArray ret = m_data->instance_indices();
|
||||
return ret;
|
||||
}
|
||||
|
||||
GfMatrix4d BlenderSceneDelegate::GetInstancerTransform(SdfPath const &instancerId)
|
||||
pxr::GfMatrix4d BlenderSceneDelegate::GetInstancerTransform(pxr::SdfPath const &instancerId)
|
||||
{
|
||||
LOG(INFO) << "GetInstancerTransform: " << instancerId.GetString();
|
||||
// TODO: add a separate object for instancer for cleaner handling code
|
||||
// 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,
|
||||
float *sampleTimes,
|
||||
GfMatrix4d *sampleValues)
|
||||
pxr::GfMatrix4d *sampleValues)
|
||||
{
|
||||
LOG(INFO) << "SampleInstancerTransform: " << instancerId.GetString();
|
||||
size_t ret = 0;
|
||||
@ -129,11 +126,11 @@ size_t BlenderSceneDelegate::SampleInstancerTransform(SdfPath const &instancerId
|
||||
return ret;
|
||||
}
|
||||
|
||||
size_t BlenderSceneDelegate::SamplePrimvar(SdfPath const &id,
|
||||
TfToken const &key,
|
||||
size_t BlenderSceneDelegate::SamplePrimvar(pxr::SdfPath const &id,
|
||||
pxr::TfToken const &key,
|
||||
size_t maxSampleCount,
|
||||
float *sampleTimes,
|
||||
VtValue *sampleValues)
|
||||
pxr::VtValue *sampleValues)
|
||||
{
|
||||
// TODO: add a separate object for instancer for cleaner handling code
|
||||
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 */
|
||||
set<SdfPath> available_objects;
|
||||
SdfPath id;
|
||||
std::set<pxr::SdfPath> available_objects;
|
||||
pxr::SdfPath id;
|
||||
|
||||
DEGObjectIterSettings settings = {0};
|
||||
settings.depsgraph = depsgraph;
|
||||
@ -207,7 +204,7 @@ void BlenderSceneDelegate::update_collection(bool remove, bool visibility)
|
||||
}
|
||||
|
||||
/* remove unused materials */
|
||||
set<SdfPath> available_materials;
|
||||
std::set<pxr::SdfPath> available_materials;
|
||||
for (auto &obj : objects) {
|
||||
MeshData *m_data = dynamic_cast<MeshData *>(obj.second.get());
|
||||
if (m_data && !m_data->material_id.IsEmpty()) {
|
||||
@ -230,7 +227,7 @@ void BlenderSceneDelegate::add_update_object(Object *object,
|
||||
bool transform,
|
||||
bool shading)
|
||||
{
|
||||
SdfPath id = ObjectData::prim_id(this, object);
|
||||
pxr::SdfPath id = ObjectData::prim_id(this, object);
|
||||
ObjectData *obj_data = object_data(id);
|
||||
if (!obj_data) {
|
||||
objects[id] = ObjectData::init(this, object);
|
||||
@ -267,7 +264,7 @@ void BlenderSceneDelegate::add_update_object(Object *object,
|
||||
|
||||
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)) {
|
||||
add_update_object(dupli->ob, true, true, true);
|
||||
}
|
||||
@ -276,7 +273,7 @@ void BlenderSceneDelegate::add_update_instance(DupliObject *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);
|
||||
if (it == objects.end()) {
|
||||
@ -285,17 +282,17 @@ ObjectData *BlenderSceneDelegate::object_data(SdfPath const &id)
|
||||
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));
|
||||
}
|
||||
|
||||
LightData *BlenderSceneDelegate::light_data(SdfPath const &id)
|
||||
LightData *BlenderSceneDelegate::light_data(pxr::SdfPath const &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);
|
||||
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();
|
||||
MeshData *m_data = mesh_data(id);
|
||||
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();
|
||||
ObjectData *obj_data = object_data(id);
|
||||
@ -415,11 +412,11 @@ VtValue BlenderSceneDelegate::Get(SdfPath const &id, TfToken const &key)
|
||||
if (mat_data) {
|
||||
return mat_data->get_data(key);
|
||||
}
|
||||
return VtValue();
|
||||
return pxr::VtValue();
|
||||
}
|
||||
|
||||
HdPrimvarDescriptorVector BlenderSceneDelegate::GetPrimvarDescriptors(
|
||||
SdfPath const &id, HdInterpolation interpolation)
|
||||
pxr::HdPrimvarDescriptorVector BlenderSceneDelegate::GetPrimvarDescriptors(
|
||||
pxr::SdfPath const &id, pxr::HdInterpolation interpolation)
|
||||
{
|
||||
LOG(INFO) << "GetPrimvarDescriptors: " << id.GetString() << " " << interpolation;
|
||||
if (mesh_data(id)) {
|
||||
@ -431,25 +428,25 @@ HdPrimvarDescriptorVector BlenderSceneDelegate::GetPrimvarDescriptors(
|
||||
return data->instancer_primvar_descriptors(interpolation);
|
||||
}
|
||||
}
|
||||
HdPrimvarDescriptorVector primvars;
|
||||
pxr::HdPrimvarDescriptorVector primvars;
|
||||
return primvars;
|
||||
}
|
||||
|
||||
SdfPath BlenderSceneDelegate::GetMaterialId(SdfPath const &rprimId)
|
||||
pxr::SdfPath BlenderSceneDelegate::GetMaterialId(pxr::SdfPath const &rprimId)
|
||||
{
|
||||
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);
|
||||
if (mat_data) {
|
||||
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();
|
||||
ObjectData *obj_data = object_data(id);
|
||||
@ -465,10 +462,10 @@ GfMatrix4d BlenderSceneDelegate::GetTransform(SdfPath const &id)
|
||||
if (id == WorldData::prim_id(this)) {
|
||||
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);
|
||||
if (l_data) {
|
||||
@ -477,7 +474,7 @@ VtValue BlenderSceneDelegate::GetLightParamValue(SdfPath const &id, TfToken cons
|
||||
if (id == WorldData::prim_id(this)) {
|
||||
return world_data->get_data(key);
|
||||
}
|
||||
return VtValue();
|
||||
return pxr::VtValue();
|
||||
}
|
||||
|
||||
} // namespace blender::render::hydra
|
||||
|
@ -6,8 +6,6 @@
|
||||
#include "blender_scene_delegate.h"
|
||||
#include "id.h"
|
||||
|
||||
using namespace pxr;
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
IdData::IdData(BlenderSceneDelegate *scene_delegate, ID *id)
|
||||
@ -22,9 +20,9 @@ std::string IdData::name()
|
||||
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
|
||||
|
@ -15,9 +15,6 @@
|
||||
#include "blender_scene_delegate.h"
|
||||
#include "light.h"
|
||||
|
||||
using namespace pxr;
|
||||
using namespace boost::algorithm;
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
LightData::LightData(BlenderSceneDelegate *scene_delegate, Object *object)
|
||||
@ -25,51 +22,51 @@ LightData::LightData(BlenderSceneDelegate *scene_delegate, Object *object)
|
||||
{
|
||||
Light *light = (Light *)((Object *)id)->data;
|
||||
|
||||
data[HdLightTokens->intensity] = scene_delegate->engine_type ==
|
||||
data[pxr::HdLightTokens->intensity] = scene_delegate->engine_type ==
|
||||
BlenderSceneDelegate::EngineType::Preview ?
|
||||
light->energy / 1000 :
|
||||
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) {
|
||||
case LA_LOCAL:
|
||||
data[HdLightTokens->radius] = light->area_size / 2;
|
||||
data[pxr::HdLightTokens->radius] = light->area_size / 2;
|
||||
break;
|
||||
|
||||
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;
|
||||
|
||||
case LA_SPOT:
|
||||
data[HdLightTokens->shapingConeAngle] = light->spotsize / 2;
|
||||
data[HdLightTokens->shapingConeSoftness] = light->spotblend;
|
||||
data[UsdLuxTokens->treatAsPoint] = true;
|
||||
data[pxr::HdLightTokens->shapingConeAngle] = light->spotsize / 2;
|
||||
data[pxr::HdLightTokens->shapingConeSoftness] = light->spotblend;
|
||||
data[pxr::UsdLuxTokens->treatAsPoint] = true;
|
||||
break;
|
||||
|
||||
case LA_AREA:
|
||||
switch (light->area_shape) {
|
||||
case LA_AREA_SQUARE:
|
||||
data[HdLightTokens->width] = light->area_size;
|
||||
data[HdLightTokens->height] = light->area_size;
|
||||
data[pxr::HdLightTokens->width] = light->area_size;
|
||||
data[pxr::HdLightTokens->height] = light->area_size;
|
||||
break;
|
||||
case LA_AREA_RECT:
|
||||
data[HdLightTokens->width] = light->area_size;
|
||||
data[HdLightTokens->height] = light->area_sizey;
|
||||
data[pxr::HdLightTokens->width] = light->area_size;
|
||||
data[pxr::HdLightTokens->height] = light->area_sizey;
|
||||
break;
|
||||
|
||||
case LA_AREA_DISK:
|
||||
data[HdLightTokens->radius] = light->area_size / 2;
|
||||
data[pxr::HdLightTokens->radius] = light->area_size / 2;
|
||||
break;
|
||||
|
||||
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;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
data[HdLightTokens->normalize] = true;
|
||||
data[pxr::HdLightTokens->normalize] = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -77,59 +74,59 @@ LightData::LightData(BlenderSceneDelegate *scene_delegate, Object *object)
|
||||
}
|
||||
|
||||
/* 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()
|
||||
{
|
||||
Light *light = (Light *)((Object *)id)->data;
|
||||
TfToken ret;
|
||||
pxr::TfToken ret;
|
||||
switch (light->type) {
|
||||
case LA_LOCAL:
|
||||
case LA_SPOT:
|
||||
ret = HdPrimTypeTokens->sphereLight;
|
||||
ret = pxr::HdPrimTypeTokens->sphereLight;
|
||||
break;
|
||||
|
||||
case LA_SUN:
|
||||
ret = HdPrimTypeTokens->distantLight;
|
||||
ret = pxr::HdPrimTypeTokens->distantLight;
|
||||
break;
|
||||
|
||||
case LA_AREA:
|
||||
switch (light->area_shape) {
|
||||
case LA_AREA_SQUARE:
|
||||
case LA_AREA_RECT:
|
||||
ret = HdPrimTypeTokens->rectLight;
|
||||
ret = pxr::HdPrimTypeTokens->rectLight;
|
||||
break;
|
||||
|
||||
case LA_AREA_DISK:
|
||||
case LA_AREA_ELLIPSE:
|
||||
ret = HdPrimTypeTokens->diskLight;
|
||||
ret = pxr::HdPrimTypeTokens->diskLight;
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = HdPrimTypeTokens->rectLight;
|
||||
ret = pxr::HdPrimTypeTokens->rectLight;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = HdPrimTypeTokens->sphereLight;
|
||||
ret = pxr::HdPrimTypeTokens->sphereLight;
|
||||
}
|
||||
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() << "]";
|
||||
|
||||
VtValue ret;
|
||||
pxr::VtValue ret;
|
||||
auto it = data.find(key);
|
||||
if (it != data.end()) {
|
||||
ret = it->second;
|
||||
}
|
||||
else {
|
||||
std::string n = key.GetString();
|
||||
if (contains(n, "object:visibility:")) {
|
||||
if (ends_with(n, "camera") || ends_with(n, "shadow")) {
|
||||
if (boost::algorithm::contains(n, "object:visibility:")) {
|
||||
if (boost::algorithm::ends_with(n, "camera") || boost::algorithm::ends_with(n, "shadow")) {
|
||||
ret = false;
|
||||
}
|
||||
else {
|
||||
@ -142,14 +139,14 @@ VtValue LightData::get_data(TfToken const &key)
|
||||
|
||||
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);
|
||||
LOG(INFO) << "Add light: " << name() << " id=" << p_id.GetAsString();
|
||||
}
|
||||
|
||||
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);
|
||||
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 */
|
||||
|
||||
HdDirtyBits bits = HdLight::Clean;
|
||||
pxr::HdDirtyBits bits = pxr::HdLight::Clean;
|
||||
switch (dirty_bits) {
|
||||
case DirtyBits::DirtyTransform:
|
||||
bits = HdLight::DirtyTransform;
|
||||
bits = pxr::HdLight::DirtyTransform;
|
||||
break;
|
||||
case DirtyBits::DirtyVisibility:
|
||||
bits = HdLight::DirtyParams;
|
||||
bits = pxr::HdLight::DirtyParams;
|
||||
break;
|
||||
case DirtyBits::AllDirty:
|
||||
bits = HdLight::AllDirty;
|
||||
bits = pxr::HdLight::AllDirty;
|
||||
break;
|
||||
default:
|
||||
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);
|
||||
LOG(INFO) << "Update light: " << name() << " [" << (int)dirty_bits << "]";
|
||||
}
|
||||
|
@ -16,8 +16,6 @@
|
||||
#include "material.h"
|
||||
#include "mtlx_hydra_adapter.h"
|
||||
|
||||
using namespace pxr;
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
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 (!mtlx_path.GetResolvedPath().empty()) {
|
||||
ret = mtlx_path;
|
||||
@ -55,14 +53,14 @@ pxr::VtValue MaterialData::material_resource()
|
||||
{
|
||||
std::string const &path = mtlx_path.GetResolvedPath();
|
||||
if (!path.empty()) {
|
||||
HdRenderDelegate *render_delegate = scene_delegate->GetRenderIndex().GetRenderDelegate();
|
||||
TfTokenVector shader_source_types = render_delegate->GetShaderSourceTypes();
|
||||
TfTokenVector render_contexts = render_delegate->GetMaterialRenderContexts();
|
||||
pxr::HdRenderDelegate *render_delegate = scene_delegate->GetRenderIndex().GetRenderDelegate();
|
||||
pxr::TfTokenVector shader_source_types = render_delegate->GetShaderSourceTypes();
|
||||
pxr::TfTokenVector render_contexts = render_delegate->GetMaterialRenderContexts();
|
||||
|
||||
HdMaterialNetworkMap material_network_map;
|
||||
pxr::HdMaterialNetworkMap material_network_map;
|
||||
HdMtlxConvertToMaterialNetworkMap(
|
||||
path, shader_source_types, render_contexts, &material_network_map);
|
||||
return VtValue(material_network_map);
|
||||
return pxr::VtValue(material_network_map);
|
||||
}
|
||||
|
||||
return pxr::VtValue();
|
||||
@ -88,35 +86,35 @@ void MaterialData::export_mtlx()
|
||||
|
||||
PyGILState_Release(gstate);
|
||||
|
||||
mtlx_path = SdfAssetPath(path, path);
|
||||
mtlx_path = pxr::SdfAssetPath(path, path);
|
||||
LOG(INFO) << "Material export: " << name() << " mtlx=" << mtlx_path.GetResolvedPath();
|
||||
}
|
||||
|
||||
void MaterialData::insert_prim()
|
||||
{
|
||||
SdfPath p_id = prim_id(scene_delegate, (Material *)id);
|
||||
scene_delegate->GetRenderIndex().InsertSprim(HdPrimTypeTokens->material, scene_delegate, p_id);
|
||||
pxr::SdfPath p_id = prim_id(scene_delegate, (Material *)id);
|
||||
scene_delegate->GetRenderIndex().InsertSprim(pxr::HdPrimTypeTokens->material, scene_delegate, p_id);
|
||||
LOG(INFO) << "Add material: " << name() << " id=" << p_id.GetAsString();
|
||||
}
|
||||
|
||||
void MaterialData::remove_prim()
|
||||
{
|
||||
SdfPath p_id = prim_id(scene_delegate, (Material *)id);
|
||||
scene_delegate->GetRenderIndex().RemoveSprim(HdPrimTypeTokens->material, p_id);
|
||||
pxr::SdfPath p_id = prim_id(scene_delegate, (Material *)id);
|
||||
scene_delegate->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->material, p_id);
|
||||
LOG(INFO) << "Remove material: " << name();
|
||||
}
|
||||
|
||||
void MaterialData::mark_prim_dirty(DirtyBits dirty_bits)
|
||||
{
|
||||
HdDirtyBits bits = HdMaterial::Clean;
|
||||
pxr::HdDirtyBits bits = pxr::HdMaterial::Clean;
|
||||
switch (dirty_bits) {
|
||||
case DirtyBits::AllDirty:
|
||||
bits = HdMaterial::AllDirty;
|
||||
bits = pxr::HdMaterial::AllDirty;
|
||||
break;
|
||||
default:
|
||||
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);
|
||||
LOG(INFO) << "Update material: " << name() << ", mtlx=" << mtlx_path.GetResolvedPath();
|
||||
}
|
||||
|
@ -15,8 +15,6 @@
|
||||
#include "blender_scene_delegate.h"
|
||||
#include "mesh.h"
|
||||
|
||||
using namespace pxr;
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
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;
|
||||
if (key == HdTokens->points) {
|
||||
pxr::VtValue ret;
|
||||
if (key == pxr::HdTokens->points) {
|
||||
ret = vertices;
|
||||
}
|
||||
else if (key == HdTokens->normals) {
|
||||
else if (key == pxr::HdTokens->normals) {
|
||||
ret = normals;
|
||||
}
|
||||
else if (key == HdPrimvarRoleTokens->textureCoordinate) {
|
||||
else if (key == pxr::HdPrimvarRoleTokens->textureCoordinate) {
|
||||
ret = uvs;
|
||||
}
|
||||
else if (key == HdInstancerTokens->instanceTransform) {
|
||||
else if (key == pxr::HdInstancerTokens->instanceTransform) {
|
||||
ret = instances;
|
||||
}
|
||||
return ret;
|
||||
@ -62,48 +60,48 @@ Material *MeshData::material()
|
||||
return BKE_object_material_get_eval(object, object->actcol);
|
||||
}
|
||||
|
||||
HdMeshTopology MeshData::mesh_topology()
|
||||
pxr::HdMeshTopology MeshData::mesh_topology()
|
||||
{
|
||||
return HdMeshTopology(PxOsdOpenSubdivTokens->catmullClark,
|
||||
HdTokens->rightHanded,
|
||||
return pxr::HdMeshTopology(pxr::PxOsdOpenSubdivTokens->catmullClark,
|
||||
pxr::HdTokens->rightHanded,
|
||||
face_vertex_counts,
|
||||
face_vertex_indices);
|
||||
}
|
||||
|
||||
HdPrimvarDescriptorVector MeshData::primvar_descriptors(HdInterpolation interpolation)
|
||||
pxr::HdPrimvarDescriptorVector MeshData::primvar_descriptors(pxr::HdInterpolation interpolation)
|
||||
{
|
||||
HdPrimvarDescriptorVector primvars;
|
||||
if (interpolation == HdInterpolationVertex) {
|
||||
pxr::HdPrimvarDescriptorVector primvars;
|
||||
if (interpolation == pxr::HdInterpolationVertex) {
|
||||
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()) {
|
||||
primvars.emplace_back(HdTokens->normals, interpolation, HdPrimvarRoleTokens->normal);
|
||||
primvars.emplace_back(pxr::HdTokens->normals, interpolation, pxr::HdPrimvarRoleTokens->normal);
|
||||
}
|
||||
if (!uvs.empty()) {
|
||||
primvars.emplace_back(HdPrimvarRoleTokens->textureCoordinate,
|
||||
primvars.emplace_back(pxr::HdPrimvarRoleTokens->textureCoordinate,
|
||||
interpolation,
|
||||
HdPrimvarRoleTokens->textureCoordinate);
|
||||
pxr::HdPrimvarRoleTokens->textureCoordinate);
|
||||
}
|
||||
}
|
||||
return primvars;
|
||||
}
|
||||
|
||||
HdPrimvarDescriptorVector MeshData::instancer_primvar_descriptors(HdInterpolation interpolation)
|
||||
pxr::HdPrimvarDescriptorVector MeshData::instancer_primvar_descriptors(pxr::HdInterpolation interpolation)
|
||||
{
|
||||
HdPrimvarDescriptorVector primvars;
|
||||
if (interpolation == HdInterpolationInstance) {
|
||||
pxr::HdPrimvarDescriptorVector primvars;
|
||||
if (interpolation == pxr::HdInterpolationInstance) {
|
||||
primvars.emplace_back(
|
||||
HdInstancerTokens->instanceTransform, interpolation, HdPrimvarRoleTokens->none);
|
||||
pxr::HdInstancerTokens->instanceTransform, interpolation, pxr::HdPrimvarRoleTokens->none);
|
||||
}
|
||||
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) {
|
||||
ret[i] = i;
|
||||
}
|
||||
@ -112,19 +110,19 @@ VtIntArray MeshData::instance_indices()
|
||||
|
||||
size_t MeshData::sample_instancer_transform(size_t maxSampleCount,
|
||||
float *sampleTimes,
|
||||
GfMatrix4d *sampleValues)
|
||||
pxr::GfMatrix4d *sampleValues)
|
||||
{
|
||||
*sampleTimes = 0.0f;
|
||||
*sampleValues = GfMatrix4d(1.0);
|
||||
*sampleValues = pxr::GfMatrix4d(1.0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t MeshData::sample_instancer_primvar(TfToken const &key,
|
||||
size_t MeshData::sample_instancer_primvar(pxr::TfToken const &key,
|
||||
size_t maxSampleCount,
|
||||
float *sampleTimes,
|
||||
VtValue *sampleValues)
|
||||
pxr::VtValue *sampleValues)
|
||||
{
|
||||
if (key == HdInstancerTokens->instanceTransform) {
|
||||
if (key == pxr::HdInstancerTokens->instanceTransform) {
|
||||
if (maxSampleCount > 0) {
|
||||
sampleTimes[0] = 0.0f;
|
||||
sampleValues[0] = instances;
|
||||
@ -144,7 +142,7 @@ void MeshData::add_instance(DupliObject *dupli)
|
||||
if (instances.empty()) {
|
||||
// USD hides the prototype mesh when instancing in contrary to the Blender, so we must add it
|
||||
// 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));
|
||||
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();
|
||||
|
||||
/* face_vertex_counts */
|
||||
face_vertex_counts = VtIntArray(tris_len, 3);
|
||||
face_vertex_counts = pxr::VtIntArray(tris_len, 3);
|
||||
|
||||
/* face_vertex_indices */
|
||||
blender::Span<MLoop> loops = mesh->loops();
|
||||
@ -176,7 +174,7 @@ void MeshData::set_mesh(Mesh *mesh)
|
||||
vertices.reserve(mesh->totvert);
|
||||
blender::Span<blender::float3> verts = mesh->vert_positions();
|
||||
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 */
|
||||
@ -184,9 +182,9 @@ void MeshData::set_mesh(Mesh *mesh)
|
||||
if (lnors) {
|
||||
normals.reserve(loopTris.size() * 3);
|
||||
for (MLoopTri lt : loopTris) {
|
||||
normals.push_back(GfVec3f(lnors[lt.tri[0]]));
|
||||
normals.push_back(GfVec3f(lnors[lt.tri[1]]));
|
||||
normals.push_back(GfVec3f(lnors[lt.tri[2]]));
|
||||
normals.push_back(pxr::GfVec3f(lnors[lt.tri[0]]));
|
||||
normals.push_back(pxr::GfVec3f(lnors[lt.tri[1]]));
|
||||
normals.push_back(pxr::GfVec3f(lnors[lt.tri[2]]));
|
||||
}
|
||||
}
|
||||
|
||||
@ -195,9 +193,9 @@ void MeshData::set_mesh(Mesh *mesh)
|
||||
if (luvs) {
|
||||
uvs.reserve(loopTris.size() * 3);
|
||||
for (MLoopTri lt : loopTris) {
|
||||
uvs.push_back(GfVec2f(luvs[lt.tri[0]]));
|
||||
uvs.push_back(GfVec2f(luvs[lt.tri[1]]));
|
||||
uvs.push_back(GfVec2f(luvs[lt.tri[2]]));
|
||||
uvs.push_back(pxr::GfVec2f(luvs[lt.tri[0]]));
|
||||
uvs.push_back(pxr::GfVec2f(luvs[lt.tri[1]]));
|
||||
uvs.push_back(pxr::GfVec2f(luvs[lt.tri[2]]));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -208,14 +206,14 @@ void MeshData::insert_prim()
|
||||
return;
|
||||
}
|
||||
|
||||
SdfPath p_id = prim_id(scene_delegate, (Object *)id);
|
||||
scene_delegate->GetRenderIndex().InsertRprim(HdPrimTypeTokens->mesh, scene_delegate, p_id);
|
||||
pxr::SdfPath p_id = prim_id(scene_delegate, (Object *)id);
|
||||
scene_delegate->GetRenderIndex().InsertRprim(pxr::HdPrimTypeTokens->mesh, scene_delegate, p_id);
|
||||
LOG(INFO) << "Add mesh: " << name() << " id=" << p_id.GetAsString();
|
||||
}
|
||||
|
||||
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)) {
|
||||
return;
|
||||
}
|
||||
@ -226,7 +224,7 @@ void MeshData::remove_prim()
|
||||
|
||||
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)) {
|
||||
/* Trying to insert prim */
|
||||
insert_prim();
|
||||
@ -239,19 +237,19 @@ void MeshData::mark_prim_dirty(DirtyBits dirty_bits)
|
||||
return;
|
||||
}
|
||||
|
||||
HdDirtyBits bits = HdChangeTracker::Clean;
|
||||
pxr::HdDirtyBits bits = pxr::HdChangeTracker::Clean;
|
||||
switch (dirty_bits) {
|
||||
case DirtyBits::DirtyTransform:
|
||||
bits = HdChangeTracker::DirtyTransform;
|
||||
bits = pxr::HdChangeTracker::DirtyTransform;
|
||||
break;
|
||||
case DirtyBits::DirtyVisibility:
|
||||
bits = HdChangeTracker::DirtyVisibility;
|
||||
bits = pxr::HdChangeTracker::DirtyVisibility;
|
||||
break;
|
||||
case DirtyBits::DirtyMaterial:
|
||||
bits = HdChangeTracker::DirtyMaterialId;
|
||||
bits = pxr::HdChangeTracker::DirtyMaterialId;
|
||||
break;
|
||||
case DirtyBits::AllDirty:
|
||||
bits = HdChangeTracker::AllDirty;
|
||||
bits = pxr::HdChangeTracker::AllDirty;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -22,56 +22,52 @@
|
||||
|
||||
namespace mx = MaterialX;
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
void HdMtlxConvertToMaterialNetworkMap(std::string const &mtlxPath,
|
||||
TfTokenVector const &shaderSourceTypes,
|
||||
TfTokenVector const &renderContexts,
|
||||
HdMaterialNetworkMap *out)
|
||||
pxr::TfTokenVector const &shaderSourceTypes,
|
||||
pxr::TfTokenVector const &renderContexts,
|
||||
pxr::HdMaterialNetworkMap *out)
|
||||
{
|
||||
if (mtlxPath.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string basePath = TfGetPathName(mtlxPath);
|
||||
std::string basePath = pxr::TfGetPathName(mtlxPath);
|
||||
|
||||
ArResolver &resolver = ArGetResolver();
|
||||
const ArResolverContext context = resolver.CreateDefaultContextForAsset(mtlxPath);
|
||||
ArResolverContextBinder binder(context);
|
||||
ArResolverScopedCache resolverCache;
|
||||
pxr::ArResolver &resolver = pxr::ArGetResolver();
|
||||
const pxr::ArResolverContext context = resolver.CreateDefaultContextForAsset(mtlxPath);
|
||||
pxr::ArResolverContextBinder binder(context);
|
||||
pxr::ArResolverScopedCache resolverCache;
|
||||
|
||||
std::string mtlxName = TfGetBaseName(mtlxPath);
|
||||
std::string stageId = TfStringPrintf(
|
||||
std::string mtlxName = pxr::TfGetBaseName(mtlxPath);
|
||||
std::string stageId = pxr::TfStringPrintf(
|
||||
"%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 {
|
||||
mx::DocumentPtr doc = UsdMtlxReadDocument(mtlxPath);
|
||||
UsdMtlxRead(doc, stage);
|
||||
mx::DocumentPtr doc = pxr::UsdMtlxReadDocument(mtlxPath);
|
||||
pxr::UsdMtlxRead(doc, stage);
|
||||
}
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
if (UsdPrim materials = stage->GetPrimAtPath(SdfPath("/MaterialX/Materials"))) {
|
||||
if (UsdPrimSiblingRange children = materials.GetChildren()) {
|
||||
if (auto material = UsdShadeMaterial(*children.begin())) {
|
||||
if (UsdShadeShader mtlxSurface = material.ComputeSurfaceSource(renderContexts)) {
|
||||
if (pxr::UsdPrim materials = stage->GetPrimAtPath(pxr::SdfPath("/MaterialX/Materials"))) {
|
||||
if (pxr::UsdPrimSiblingRange children = materials.GetChildren()) {
|
||||
if (auto material = pxr::UsdShadeMaterial(*children.begin())) {
|
||||
if (pxr::UsdShadeShader mtlxSurface = material.ComputeSurfaceSource(renderContexts)) {
|
||||
UsdImagingBuildHdMaterialNetworkFromTerminal(mtlxSurface.GetPrim(),
|
||||
HdMaterialTerminalTokens->surface,
|
||||
pxr::HdMaterialTerminalTokens->surface,
|
||||
shaderSourceTypes,
|
||||
renderContexts,
|
||||
out,
|
||||
UsdTimeCode::Default());
|
||||
pxr::UsdTimeCode::Default());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
|
@ -8,13 +8,9 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
PXR_NAMESPACE_OPEN_SCOPE
|
||||
|
||||
struct HdMaterialNetworkMap;
|
||||
struct pxr::HdMaterialNetworkMap;
|
||||
|
||||
void HdMtlxConvertToMaterialNetworkMap(std::string const &mtlxPath,
|
||||
TfTokenVector const &shaderSourceTypes,
|
||||
TfTokenVector const &renderContexts,
|
||||
HdMaterialNetworkMap *out);
|
||||
|
||||
PXR_NAMESPACE_CLOSE_SCOPE
|
||||
pxr::TfTokenVector const &shaderSourceTypes,
|
||||
pxr::TfTokenVector const &renderContexts,
|
||||
pxr::HdMaterialNetworkMap *out);
|
||||
|
@ -9,8 +9,6 @@
|
||||
#include "mesh.h"
|
||||
#include "object.h"
|
||||
|
||||
using namespace pxr;
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
bool ObjectData::supported(Object *object)
|
||||
@ -69,7 +67,7 @@ int ObjectData::type()
|
||||
return ((Object *)id)->type;
|
||||
}
|
||||
|
||||
GfMatrix4d ObjectData::transform()
|
||||
pxr::GfMatrix4d ObjectData::transform()
|
||||
{
|
||||
return gf_matrix_from_transform(((Object *)id)->object_to_world);
|
||||
}
|
||||
|
@ -28,8 +28,6 @@
|
||||
|
||||
/* TODO : add custom tftoken "transparency"? */
|
||||
|
||||
using namespace pxr;
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
SdfPath WorldData::prim_id(BlenderSceneDelegate *scene_delegate)
|
||||
pxr::SdfPath WorldData::prim_id(BlenderSceneDelegate *scene_delegate)
|
||||
{
|
||||
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)
|
||||
: IdData(scene_delegate, (ID *)world)
|
||||
{
|
||||
data[UsdLuxTokens->orientToStageUpAxis] = true;
|
||||
data[pxr::UsdLuxTokens->orientToStageUpAxis] = true;
|
||||
|
||||
if (world->use_nodes) {
|
||||
/* 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 *color = color_input.default_value_typed<float>();
|
||||
data[HdLightTokens->intensity] = strength[1];
|
||||
data[HdLightTokens->exposure] = 1.0f;
|
||||
data[HdLightTokens->color] = GfVec3f(color[0], color[1], color[2]);
|
||||
data[pxr::HdLightTokens->intensity] = strength[1];
|
||||
data[pxr::HdLightTokens->exposure] = 1.0f;
|
||||
data[pxr::HdLightTokens->color] = pxr::GfVec3f(color[0], color[1], color[2]);
|
||||
|
||||
if (!color_input.directly_linked_links().is_empty()) {
|
||||
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);
|
||||
if (!image_path.empty()) {
|
||||
data[HdLightTokens->textureFile] = SdfAssetPath(image_path, image_path);
|
||||
data[pxr::HdLightTokens->textureFile] = pxr::SdfAssetPath(image_path, image_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
data[HdLightTokens->intensity] = 1.0f;
|
||||
data[HdLightTokens->exposure] = world->exposure;
|
||||
data[HdLightTokens->color] = GfVec3f(world->horr, world->horg, world->horb);
|
||||
data[pxr::HdLightTokens->intensity] = 1.0f;
|
||||
data[pxr::HdLightTokens->exposure] = world->exposure;
|
||||
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*/
|
||||
if (scene_delegate->GetRenderIndex().GetRenderDelegate()->GetRendererDisplayName() == "RPR") {
|
||||
transform *= GfMatrix4d(GfRotation(GfVec3d(1.0, 0.0, 0.0), -180), GfVec3d());
|
||||
transform *= GfMatrix4d(GfRotation(GfVec3d(0.0, 0.0, 1.0), 90.0), GfVec3d());
|
||||
transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(1.0, 0.0, 0.0), -180), pxr::GfVec3d());
|
||||
transform *= pxr::GfMatrix4d(pxr::GfRotation(pxr::GfVec3d(0.0, 0.0, 1.0), 90.0), pxr::GfVec3d());
|
||||
}
|
||||
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);
|
||||
if (it != data.end()) {
|
||||
ret = it->second;
|
||||
@ -126,29 +124,29 @@ VtValue WorldData::get_data(TfToken const &key)
|
||||
|
||||
void WorldData::insert_prim()
|
||||
{
|
||||
SdfPath p_id = prim_id(scene_delegate);
|
||||
scene_delegate->GetRenderIndex().InsertSprim(HdPrimTypeTokens->domeLight, scene_delegate, p_id);
|
||||
pxr::SdfPath p_id = prim_id(scene_delegate);
|
||||
scene_delegate->GetRenderIndex().InsertSprim(pxr::HdPrimTypeTokens->domeLight, scene_delegate, p_id);
|
||||
LOG(INFO) << "Add World: id=" << p_id.GetAsString();
|
||||
}
|
||||
|
||||
void WorldData::remove_prim()
|
||||
{
|
||||
SdfPath p_id = prim_id(scene_delegate);
|
||||
scene_delegate->GetRenderIndex().RemoveSprim(HdPrimTypeTokens->domeLight, p_id);
|
||||
pxr::SdfPath p_id = prim_id(scene_delegate);
|
||||
scene_delegate->GetRenderIndex().RemoveSprim(pxr::HdPrimTypeTokens->domeLight, p_id);
|
||||
LOG(INFO) << "Remove World";
|
||||
}
|
||||
|
||||
void WorldData::mark_prim_dirty(DirtyBits dirty_bits)
|
||||
{
|
||||
HdDirtyBits bits = HdLight::Clean;
|
||||
pxr::HdDirtyBits bits = pxr::HdLight::Clean;
|
||||
switch (dirty_bits) {
|
||||
case DirtyBits::AllDirty:
|
||||
bits = HdLight::AllDirty;
|
||||
bits = pxr::HdLight::AllDirty;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
SdfPath p_id = prim_id(scene_delegate);
|
||||
pxr::SdfPath p_id = prim_id(scene_delegate);
|
||||
scene_delegate->GetRenderIndex().GetChangeTracker().MarkSprimDirty(p_id, bits);
|
||||
LOG(INFO) << "Update World";
|
||||
}
|
||||
|
@ -7,35 +7,35 @@
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
SimpleLightTaskDelegate::SimpleLightTaskDelegate(HdRenderIndex *parentIndex,
|
||||
SdfPath const &delegateID)
|
||||
: HdSceneDelegate(parentIndex, delegateID)
|
||||
SimpleLightTaskDelegate::SimpleLightTaskDelegate(pxr::HdRenderIndex *parentIndex,
|
||||
pxr::SdfPath const &delegateID)
|
||||
: pxr::HdSceneDelegate(parentIndex, delegateID)
|
||||
{
|
||||
SdfPath taskId = GetTaskID();
|
||||
GetRenderIndex().InsertTask<HdxSimpleLightTask>(this, taskId);
|
||||
pxr::SdfPath taskId = GetTaskID();
|
||||
GetRenderIndex().InsertTask<pxr::HdxSimpleLightTask>(this, taskId);
|
||||
}
|
||||
|
||||
SdfPath SimpleLightTaskDelegate::GetTaskID() const
|
||||
pxr::SdfPath SimpleLightTaskDelegate::GetTaskID() const
|
||||
{
|
||||
return GetDelegateID().AppendElementString("task");
|
||||
}
|
||||
|
||||
HdTaskSharedPtr SimpleLightTaskDelegate::GetTask()
|
||||
pxr::HdTaskSharedPtr SimpleLightTaskDelegate::GetTask()
|
||||
{
|
||||
return GetRenderIndex().GetTask(GetTaskID());
|
||||
}
|
||||
|
||||
void SimpleLightTaskDelegate::SetCameraPath(SdfPath const &cameraPath)
|
||||
void SimpleLightTaskDelegate::SetCameraPath(pxr::SdfPath const &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) {
|
||||
return VtValue(taskParams);
|
||||
if (key == pxr::HdTokens->params) {
|
||||
return pxr::VtValue(taskParams);
|
||||
}
|
||||
return VtValue();
|
||||
return pxr::VtValue();
|
||||
}
|
||||
|
||||
} // namespace blender::render::hydra
|
||||
|
@ -6,24 +6,22 @@
|
||||
#include <pxr/imaging/hd/sceneDelegate.h>
|
||||
#include <pxr/imaging/hdx/simpleLightTask.h>
|
||||
|
||||
using namespace pxr;
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
class SimpleLightTaskDelegate : public HdSceneDelegate {
|
||||
class SimpleLightTaskDelegate : public pxr::HdSceneDelegate {
|
||||
public:
|
||||
SimpleLightTaskDelegate(HdRenderIndex *parentIndex, SdfPath const &delegateID);
|
||||
SimpleLightTaskDelegate(pxr::HdRenderIndex *parentIndex, pxr::SdfPath const &delegateID);
|
||||
~SimpleLightTaskDelegate() override = default;
|
||||
|
||||
SdfPath GetTaskID() const;
|
||||
pxr::SdfPath GetTaskID() const;
|
||||
|
||||
HdTaskSharedPtr GetTask();
|
||||
void SetCameraPath(SdfPath const &);
|
||||
pxr::HdTaskSharedPtr GetTask();
|
||||
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:
|
||||
HdxSimpleLightTaskParams taskParams;
|
||||
pxr::HdxSimpleLightTaskParams taskParams;
|
||||
};
|
||||
|
||||
} // namespace blender::render::hydra
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <filesystem>
|
||||
#include <sstream>
|
||||
#include <chrono>
|
||||
|
||||
#include <pxr/base/tf/stringUtils.h>
|
||||
|
||||
@ -15,14 +16,11 @@
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace pxr;
|
||||
|
||||
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][2],
|
||||
m[0][3],
|
||||
@ -40,43 +38,43 @@ GfMatrix4d gf_matrix_from_transform(float m[4][4])
|
||||
m[3][3]);
|
||||
}
|
||||
|
||||
string format_duration(chrono::milliseconds millisecs)
|
||||
std::string format_duration(std::chrono::milliseconds millisecs)
|
||||
{
|
||||
stringstream ss;
|
||||
bool neg = millisecs < 0ms;
|
||||
std::stringstream ss;
|
||||
bool neg = millisecs < std::chrono::milliseconds(0);
|
||||
if (neg) {
|
||||
millisecs = -millisecs;
|
||||
}
|
||||
auto m = chrono::duration_cast<chrono::minutes>(millisecs);
|
||||
auto m = std::chrono::duration_cast<std::chrono::minutes>(millisecs);
|
||||
millisecs -= m;
|
||||
auto s = chrono::duration_cast<chrono::seconds>(millisecs);
|
||||
auto s = std::chrono::duration_cast<std::chrono::seconds>(millisecs);
|
||||
millisecs -= s;
|
||||
if (neg) {
|
||||
ss << "-";
|
||||
}
|
||||
if (m < 10min) {
|
||||
if (m < std::chrono::minutes(10)) {
|
||||
ss << "0";
|
||||
}
|
||||
ss << to_string(m / 1min) << ":";
|
||||
if (s < 10s) {
|
||||
ss << std::to_string(m / std::chrono::minutes(1)) << ":";
|
||||
if (s < std::chrono::seconds(10)) {
|
||||
ss << "0";
|
||||
}
|
||||
ss << to_string(s / 1s) << ":";
|
||||
if (millisecs < 10ms) {
|
||||
ss << std::to_string(s / std::chrono::seconds(1)) << ":";
|
||||
if (millisecs < std::chrono::milliseconds(10)) {
|
||||
ss << "0";
|
||||
}
|
||||
ss << to_string(millisecs / 1ms / 10);
|
||||
ss << std::to_string(millisecs / std::chrono::milliseconds(1) / 10);
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
string cache_image(Main *bmain,
|
||||
std::string cache_image(Main *bmain,
|
||||
Scene *scene,
|
||||
Image *image,
|
||||
ImageUser *iuser,
|
||||
ImageSaveOptions *opts,
|
||||
ReportList *reports)
|
||||
{
|
||||
const string default_format = ".png";
|
||||
const std::string default_format = ".png";
|
||||
|
||||
char tempfile[FILE_MAX];
|
||||
|
||||
@ -85,15 +83,15 @@ string cache_image(Main *bmain,
|
||||
return "";
|
||||
}
|
||||
|
||||
string image_name;
|
||||
std::string image_name;
|
||||
|
||||
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 {
|
||||
image_name = image->filepath == NULL ? image->filepath : image->id.name + 2;
|
||||
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);
|
||||
@ -110,13 +108,13 @@ string cache_image(Main *bmain,
|
||||
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());
|
||||
;
|
||||
stringstream ss;
|
||||
std::stringstream ss;
|
||||
int i = 0;
|
||||
for (string &s : path_dirs) {
|
||||
for (std::string &s : path_dirs) {
|
||||
++i;
|
||||
ss << s;
|
||||
if (i < path_dirs.size() || env) {
|
||||
|
@ -21,10 +21,6 @@
|
||||
#include "camera.h"
|
||||
#include "utils.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
using namespace pxr;
|
||||
|
||||
namespace blender::render::hydra {
|
||||
|
||||
struct ViewSettings {
|
||||
@ -33,13 +29,13 @@ struct ViewSettings {
|
||||
int width();
|
||||
int height();
|
||||
|
||||
GfCamera gf_camera();
|
||||
pxr::GfCamera gf_camera();
|
||||
|
||||
CameraData camera_data;
|
||||
|
||||
int screen_width;
|
||||
int screen_height;
|
||||
GfVec4i border;
|
||||
pxr::GfVec4i border;
|
||||
};
|
||||
|
||||
ViewSettings::ViewSettings(bContext *context) : camera_data(context)
|
||||
@ -80,13 +76,13 @@ ViewSettings::ViewSettings(bContext *context) : camera_data(context)
|
||||
}
|
||||
|
||||
// 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]});
|
||||
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]});
|
||||
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]});
|
||||
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]});
|
||||
|
||||
// adjusting region to border
|
||||
@ -99,10 +95,10 @@ ViewSettings::ViewSettings(bContext *context) : camera_data(context)
|
||||
y2 = y + scene->r.border.ymax * dy;
|
||||
|
||||
// adjusting to region screen resolution
|
||||
x1 = max(min(x1, screen_width), 0);
|
||||
x2 = max(min(x2, screen_width), 0);
|
||||
y1 = max(min(y1, screen_height), 0);
|
||||
y2 = max(min(y2, screen_height), 0);
|
||||
x1 = std::max(std::min(x1, screen_width), 0);
|
||||
x2 = std::max(std::min(x2, screen_width), 0);
|
||||
y1 = std::max(std::min(y1, screen_height), 0);
|
||||
y2 = std::max(std::min(y2, screen_height), 0);
|
||||
}
|
||||
}
|
||||
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()
|
||||
@ -130,9 +126,9 @@ int ViewSettings::height()
|
||||
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[2] / screen_width,
|
||||
(float)border[3] / screen_height));
|
||||
@ -149,7 +145,7 @@ GLTexture::~GLTexture()
|
||||
}
|
||||
}
|
||||
|
||||
void GLTexture::setBuffer(HdRenderBuffer *buffer)
|
||||
void GLTexture::setBuffer(pxr::HdRenderBuffer *buffer)
|
||||
{
|
||||
if (!textureId) {
|
||||
create(buffer);
|
||||
@ -169,11 +165,11 @@ void GLTexture::setBuffer(HdRenderBuffer *buffer)
|
||||
buffer->Unmap();
|
||||
}
|
||||
|
||||
void GLTexture::create(HdRenderBuffer *buffer)
|
||||
void GLTexture::create(pxr::HdRenderBuffer *buffer)
|
||||
{
|
||||
width = buffer->GetWidth();
|
||||
height = buffer->GetHeight();
|
||||
channels = HdGetComponentCount(buffer->GetFormat());
|
||||
channels = pxr::HdGetComponentCount(buffer->GetFormat());
|
||||
|
||||
glGenTextures(1, &textureId);
|
||||
glBindTexture(GL_TEXTURE_2D, textureId);
|
||||
@ -246,12 +242,12 @@ void GLTexture::draw(GLfloat x, GLfloat y)
|
||||
|
||||
void ViewportEngine::sync(Depsgraph *depsgraph,
|
||||
bContext *context,
|
||||
HdRenderSettingsMap &renderSettings)
|
||||
pxr::HdRenderSettingsMap &renderSettings)
|
||||
{
|
||||
if (!scene_delegate) {
|
||||
scene_delegate = std::make_unique<BlenderSceneDelegate>(
|
||||
render_index.get(),
|
||||
SdfPath::AbsoluteRootPath().AppendElementString("scene"),
|
||||
pxr::SdfPath::AbsoluteRootPath().AppendElementString("scene"),
|
||||
BlenderSceneDelegate::EngineType::Viewport);
|
||||
}
|
||||
scene_delegate->populate(depsgraph, context);
|
||||
@ -268,10 +264,10 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
|
||||
return;
|
||||
};
|
||||
|
||||
GfCamera gfCamera = viewSettings.gf_camera();
|
||||
pxr::GfCamera gfCamera = viewSettings.gf_camera();
|
||||
free_camera_delegate->SetCamera(gfCamera);
|
||||
render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(),
|
||||
GfVec4d(viewSettings.border[0],
|
||||
pxr::GfVec4d(viewSettings.border[0],
|
||||
viewSettings.border[1],
|
||||
viewSettings.border[2],
|
||||
viewSettings.border[3]));
|
||||
@ -280,17 +276,17 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
|
||||
}
|
||||
|
||||
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) {
|
||||
timeBegin = chrono::steady_clock::now();
|
||||
timeBegin = std::chrono::steady_clock::now();
|
||||
}
|
||||
|
||||
GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_IMAGE);
|
||||
GPU_shader_bind(shader);
|
||||
|
||||
HdTaskSharedPtrVector tasks;
|
||||
pxr::HdTaskSharedPtrVector tasks;
|
||||
if (simple_light_task_delegate) {
|
||||
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. */
|
||||
TF_PY_ALLOW_THREADS_IN_SCOPE();
|
||||
pxr::TF_PY_ALLOW_THREADS_IN_SCOPE();
|
||||
engine->Execute(render_index.get(), &tasks);
|
||||
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
GPU_shader_unbind();
|
||||
|
||||
chrono::time_point<chrono::steady_clock> timeCurrent = chrono::steady_clock::now();
|
||||
chrono::milliseconds elapsedTime = chrono::duration_cast<chrono::milliseconds>(timeCurrent -
|
||||
std::chrono::time_point<std::chrono::steady_clock> timeCurrent = std::chrono::steady_clock::now();
|
||||
std::chrono::milliseconds elapsedTime = std::chrono::duration_cast<std::chrono::milliseconds>(timeCurrent -
|
||||
timeBegin);
|
||||
|
||||
string formattedTime = format_duration(elapsedTime);
|
||||
std::string formattedTime = format_duration(elapsedTime);
|
||||
|
||||
if (!render_task_delegate->IsConverged()) {
|
||||
notify_status("Time: " + formattedTime +
|
||||
" | Done: " + to_string(int(renderer_percent_done())) + "%",
|
||||
" | Done: " + std::to_string(int(renderer_percent_done())) + "%",
|
||||
"Render");
|
||||
bl_engine->flag |= RE_ENGINE_DO_DRAW;
|
||||
}
|
||||
@ -331,7 +327,7 @@ void ViewportEngine::render(Depsgraph *depsgraph)
|
||||
/* 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());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user