forked from blender/blender
BLEN-367: Fix code style #14
@ -1,9 +1,9 @@
|
|||||||
/* SPDX-License-Identifier: Apache-2.0
|
/* SPDX-License-Identifier: Apache-2.0
|
||||||
* Copyright 2011-2022 Blender Foundation */
|
* Copyright 2011-2022 Blender Foundation */
|
||||||
|
|
||||||
|
#include "BKE_context.h"
|
||||||
#include "DNA_camera_types.h"
|
#include "DNA_camera_types.h"
|
||||||
#include "DNA_screen_types.h"
|
#include "DNA_screen_types.h"
|
||||||
#include "BKE_context.h"
|
|
||||||
|
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
@ -35,9 +35,8 @@ CameraData::CameraData(Object *camera_obj, GfVec2i res, GfVec4f tile)
|
|||||||
focus_distance = (obj_pos - cam_pos).GetLength();
|
focus_distance = (obj_pos - cam_pos).GetLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
dof_data = std::tuple(std::max(focus_distance, 0.001f),
|
dof_data = std::tuple(
|
||||||
camera->dof.aperture_fstop,
|
std::max(focus_distance, 0.001f), camera->dof.aperture_fstop, camera->dof.aperture_blades);
|
||||||
camera->dof.aperture_blades);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float ratio = (float)res[0] / res[1];
|
float ratio = (float)res[0] / res[1];
|
||||||
@ -277,4 +276,4 @@ GfCamera CameraData::gf_camera()
|
|||||||
return gf_camera(GfVec4f(0, 0, 1, 1));
|
return gf_camera(GfVec4f(0, 0, 1, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -13,14 +13,14 @@
|
|||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
class CameraData {
|
class CameraData {
|
||||||
public:
|
public:
|
||||||
CameraData(bContext *context);
|
CameraData(bContext *context);
|
||||||
CameraData(Object *camera_obj, pxr::GfVec2i res, pxr::GfVec4f tile);
|
CameraData(Object *camera_obj, pxr::GfVec2i res, pxr::GfVec4f tile);
|
||||||
|
|
||||||
pxr::GfCamera gf_camera();
|
pxr::GfCamera gf_camera();
|
||||||
pxr::GfCamera gf_camera(pxr::GfVec4f tile);
|
pxr::GfCamera gf_camera(pxr::GfVec4f tile);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int mode;
|
int mode;
|
||||||
pxr::GfRange1f clip_range;
|
pxr::GfRange1f clip_range;
|
||||||
float focal_length;
|
float focal_length;
|
||||||
@ -31,4 +31,4 @@ private:
|
|||||||
std::tuple<float, float, int> dof_data;
|
std::tuple<float, float, int> dof_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
/* SPDX-License-Identifier: Apache-2.0
|
/* SPDX-License-Identifier: Apache-2.0
|
||||||
* Copyright 2011-2022 Blender Foundation */
|
* Copyright 2011-2022 Blender Foundation */
|
||||||
|
|
||||||
|
#include <pxr/base/plug/plugin.h>
|
||||||
|
#include <pxr/base/plug/registry.h>
|
||||||
#include <pxr/imaging/hd/rendererPluginRegistry.h>
|
#include <pxr/imaging/hd/rendererPluginRegistry.h>
|
||||||
#include <pxr/imaging/hdSt/renderDelegate.h>
|
#include <pxr/imaging/hdSt/renderDelegate.h>
|
||||||
#include <pxr/imaging/hgi/tokens.h>
|
#include <pxr/imaging/hgi/tokens.h>
|
||||||
#include <pxr/base/plug/plugin.h>
|
|
||||||
#include <pxr/base/plug/registry.h>
|
|
||||||
#include <pxr/usd/usdGeom/tokens.h>
|
#include <pxr/usd/usdGeom/tokens.h>
|
||||||
|
|
||||||
#include "glog/logging.h"
|
#include "glog/logging.h"
|
||||||
@ -16,10 +16,9 @@ using namespace pxr;
|
|||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
Engine::Engine(RenderEngine *bl_engine, const std::string &delegateId)
|
Engine::Engine(RenderEngine *bl_engine, const std::string &delegateId) : bl_engine(bl_engine)
|
||||||
: bl_engine(bl_engine)
|
|
||||||
{
|
{
|
||||||
HdRendererPluginRegistry& registry = HdRendererPluginRegistry::GetInstance();
|
HdRendererPluginRegistry ®istry = HdRendererPluginRegistry::GetInstance();
|
||||||
|
|
||||||
TF_PY_ALLOW_THREADS_IN_SCOPE();
|
TF_PY_ALLOW_THREADS_IN_SCOPE();
|
||||||
render_delegate = registry.CreateRenderDelegate(TfToken(delegateId));
|
render_delegate = registry.CreateRenderDelegate(TfToken(delegateId));
|
||||||
@ -35,9 +34,9 @@ Engine::Engine(RenderEngine *bl_engine, const std::string &delegateId)
|
|||||||
|
|
||||||
render_index.reset(HdRenderIndex::New(render_delegate.Get(), hd_drivers));
|
render_index.reset(HdRenderIndex::New(render_delegate.Get(), hd_drivers));
|
||||||
free_camera_delegate = std::make_unique<HdxFreeCameraSceneDelegate>(
|
free_camera_delegate = std::make_unique<HdxFreeCameraSceneDelegate>(
|
||||||
render_index.get(), SdfPath::AbsoluteRootPath().AppendElementString("freeCamera"));
|
render_index.get(), SdfPath::AbsoluteRootPath().AppendElementString("freeCamera"));
|
||||||
render_task_delegate = std::make_unique<RenderTaskDelegate>(
|
render_task_delegate = std::make_unique<RenderTaskDelegate>(
|
||||||
render_index.get(), SdfPath::AbsoluteRootPath().AppendElementString("renderTask"));
|
render_index.get(), SdfPath::AbsoluteRootPath().AppendElementString("renderTask"));
|
||||||
if (render_delegate->GetRendererDisplayName() == "GL") {
|
if (render_delegate->GetRendererDisplayName() == "GL") {
|
||||||
simple_light_task_delegate = std::make_unique<SimpleLightTaskDelegate>(
|
simple_light_task_delegate = std::make_unique<SimpleLightTaskDelegate>(
|
||||||
render_index.get(), SdfPath::AbsoluteRootPath().AppendElementString("simpleLightTask"));
|
render_index.get(), SdfPath::AbsoluteRootPath().AppendElementString("simpleLightTask"));
|
||||||
@ -68,4 +67,4 @@ float Engine::renderer_percent_done()
|
|||||||
return (float)it->second.UncheckedGet<double>();
|
return (float)it->second.UncheckedGet<double>();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -7,32 +7,34 @@
|
|||||||
|
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
|
|
||||||
|
#include <pxr/imaging/hd/driver.h>
|
||||||
#include <pxr/imaging/hd/engine.h>
|
#include <pxr/imaging/hd/engine.h>
|
||||||
#include <pxr/imaging/hd/pluginRenderDelegateUniqueHandle.h>
|
#include <pxr/imaging/hd/pluginRenderDelegateUniqueHandle.h>
|
||||||
#include <pxr/imaging/hd/driver.h>
|
|
||||||
#include <pxr/imaging/hdx/freeCameraSceneDelegate.h>
|
#include <pxr/imaging/hdx/freeCameraSceneDelegate.h>
|
||||||
#include <pxr/imaging/hgi/hgi.h>
|
#include <pxr/imaging/hgi/hgi.h>
|
||||||
|
|
||||||
#include "RE_engine.h"
|
#include "RE_engine.h"
|
||||||
|
|
||||||
#include "sceneDelegate/blenderSceneDelegate.h"
|
|
||||||
#include "renderTaskDelegate.h"
|
#include "renderTaskDelegate.h"
|
||||||
|
#include "sceneDelegate/blenderSceneDelegate.h"
|
||||||
#include "simpleLightTaskDelegate.h"
|
#include "simpleLightTaskDelegate.h"
|
||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
class Engine {
|
class Engine {
|
||||||
public:
|
public:
|
||||||
Engine(RenderEngine *bl_engine, const std::string &render_delegate_id);
|
Engine(RenderEngine *bl_engine, const std::string &render_delegate_id);
|
||||||
virtual ~Engine();
|
virtual ~Engine();
|
||||||
|
|
||||||
virtual void sync(Depsgraph *depsgraph, bContext *context, pxr::HdRenderSettingsMap &renderSettings) = 0;
|
virtual void sync(Depsgraph *depsgraph,
|
||||||
|
bContext *context,
|
||||||
|
pxr::HdRenderSettingsMap &renderSettings) = 0;
|
||||||
virtual void render(Depsgraph *depsgraph) = 0;
|
virtual void render(Depsgraph *depsgraph) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
float renderer_percent_done();
|
float renderer_percent_done();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
RenderEngine *bl_engine;
|
RenderEngine *bl_engine;
|
||||||
|
|
||||||
HdPluginRenderDelegateUniqueHandle render_delegate;
|
HdPluginRenderDelegateUniqueHandle render_delegate;
|
||||||
@ -47,4 +49,4 @@ protected:
|
|||||||
HdDriver hgi_driver;
|
HdDriver hgi_driver;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -3,13 +3,13 @@
|
|||||||
|
|
||||||
#include <pxr/imaging/glf/drawTarget.h>
|
#include <pxr/imaging/glf/drawTarget.h>
|
||||||
|
|
||||||
#include "DEG_depsgraph_query.h"
|
|
||||||
#include "BKE_lib_id.h"
|
#include "BKE_lib_id.h"
|
||||||
|
#include "DEG_depsgraph_query.h"
|
||||||
|
|
||||||
#include "glog/logging.h"
|
#include "glog/logging.h"
|
||||||
|
|
||||||
#include "finalEngine.h"
|
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
|
#include "finalEngine.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@ -17,13 +17,17 @@ using namespace pxr;
|
|||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
void FinalEngine::sync(Depsgraph *depsgraph, bContext *context, HdRenderSettingsMap &renderSettings)
|
void FinalEngine::sync(Depsgraph *depsgraph,
|
||||||
|
bContext *context,
|
||||||
|
HdRenderSettingsMap &renderSettings)
|
||||||
{
|
{
|
||||||
scene_delegate = std::make_unique<BlenderSceneDelegate>(render_index.get(),
|
scene_delegate = std::make_unique<BlenderSceneDelegate>(
|
||||||
SdfPath::AbsoluteRootPath().AppendElementString("scene"), BlenderSceneDelegate::EngineType::Final);
|
render_index.get(),
|
||||||
|
SdfPath::AbsoluteRootPath().AppendElementString("scene"),
|
||||||
|
BlenderSceneDelegate::EngineType::Final);
|
||||||
scene_delegate->populate(depsgraph, context);
|
scene_delegate->populate(depsgraph, context);
|
||||||
|
|
||||||
for (auto const& setting : renderSettings) {
|
for (auto const &setting : renderSettings) {
|
||||||
render_delegate->SetRenderSetting(setting.first, setting.second);
|
render_delegate->SetRenderSetting(setting.first, setting.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -40,15 +44,18 @@ void FinalEngine::render(Depsgraph *depsgraph)
|
|||||||
RenderData &r = scene->r;
|
RenderData &r = scene->r;
|
||||||
GfVec4f border(0, 0, 1, 1);
|
GfVec4f border(0, 0, 1, 1);
|
||||||
if (r.mode & R_BORDER) {
|
if (r.mode & R_BORDER) {
|
||||||
border = GfVec4f(r.border.xmin, r.border.ymin,
|
border = GfVec4f(r.border.xmin,
|
||||||
r.border.xmax - r.border.xmin, r.border.ymax - r.border.ymin);
|
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 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]));
|
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);
|
GfCamera camera = CameraData(scene->camera, image_res, GfVec4f(0, 0, 1, 1)).gf_camera(border);
|
||||||
|
|
||||||
free_camera_delegate->SetCamera(camera);
|
free_camera_delegate->SetCamera(camera);
|
||||||
render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(), GfVec4d(0, 0, res[0], res[1]));
|
render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(),
|
||||||
|
GfVec4d(0, 0, res[0], res[1]));
|
||||||
render_task_delegate->SetRendererAov(HdAovTokens->color);
|
render_task_delegate->SetRendererAov(HdAovTokens->color);
|
||||||
if (simple_light_task_delegate) {
|
if (simple_light_task_delegate) {
|
||||||
simple_light_task_delegate->SetCameraPath(free_camera_delegate->GetCameraId());
|
simple_light_task_delegate->SetCameraPath(free_camera_delegate->GetCameraId());
|
||||||
@ -66,7 +73,7 @@ void FinalEngine::render(Depsgraph *depsgraph)
|
|||||||
float percentDone = 0.0;
|
float percentDone = 0.0;
|
||||||
|
|
||||||
map<string, vector<float>> renderImages{
|
map<string, vector<float>> renderImages{
|
||||||
{"Combined", vector<float>(res[0] * res[1] * 4)}}; // 4 - number of channels
|
{"Combined", vector<float>(res[0] * res[1] * 4)}}; // 4 - number of channels
|
||||||
vector<float> &pixels = renderImages["Combined"];
|
vector<float> &pixels = renderImages["Combined"];
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -84,8 +91,10 @@ void FinalEngine::render(Depsgraph *depsgraph)
|
|||||||
timeCurrent = chrono::steady_clock::now();
|
timeCurrent = chrono::steady_clock::now();
|
||||||
elapsedTime = chrono::duration_cast<chrono::milliseconds>(timeCurrent - timeBegin);
|
elapsedTime = chrono::duration_cast<chrono::milliseconds>(timeCurrent - timeBegin);
|
||||||
|
|
||||||
notify_status(percentDone / 100.0, scene_name + ": " + layer_name,
|
notify_status(percentDone / 100.0,
|
||||||
"Render Time: " + format_duration(elapsedTime) + " | Done: " + to_string(int(percentDone)) + "%");
|
scene_name + ": " + layer_name,
|
||||||
|
"Render Time: " + format_duration(elapsedTime) +
|
||||||
|
" | Done: " + to_string(int(percentDone)) + "%");
|
||||||
|
|
||||||
if (render_task_delegate->IsConverged()) {
|
if (render_task_delegate->IsConverged()) {
|
||||||
break;
|
break;
|
||||||
@ -110,9 +119,13 @@ GfVec2i FinalEngine::get_resolution(Scene *scene)
|
|||||||
return GfVec2i(int(r.xsch * border_w * r.size / 100), int(r.ysch * border_h * r.size / 100));
|
return 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, int width, int height)
|
void FinalEngine::updateRenderResult(map<string, vector<float>> &renderImages,
|
||||||
|
const string &layerName,
|
||||||
|
int width,
|
||||||
|
int height)
|
||||||
{
|
{
|
||||||
RenderResult *result = RE_engine_begin_result(bl_engine, 0, 0, width, height, layerName.c_str(), nullptr);
|
RenderResult *result = RE_engine_begin_result(
|
||||||
|
bl_engine, 0, 0, width, height, layerName.c_str(), nullptr);
|
||||||
|
|
||||||
/* TODO: only for the first render layer */
|
/* TODO: only for the first render layer */
|
||||||
RenderLayer *layer = (RenderLayer *)result->layers.first;
|
RenderLayer *layer = (RenderLayer *)result->layers.first;
|
||||||
@ -121,7 +134,8 @@ void FinalEngine::updateRenderResult(map<string, vector<float>>& renderImages, c
|
|||||||
if (it_image == renderImages.end()) {
|
if (it_image == renderImages.end()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
memcpy(pass->rect, it_image->second.data(),
|
memcpy(pass->rect,
|
||||||
|
it_image->second.data(),
|
||||||
sizeof(float) * pass->rectx * pass->recty * pass->channels);
|
sizeof(float) * pass->rectx * pass->recty * pass->channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,17 +160,18 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
|
|||||||
RenderData &r = scene->r;
|
RenderData &r = scene->r;
|
||||||
GfVec4f border(0, 0, 1, 1);
|
GfVec4f border(0, 0, 1, 1);
|
||||||
if (r.mode & R_BORDER) {
|
if (r.mode & R_BORDER) {
|
||||||
border = GfVec4f(r.border.xmin, r.border.ymin,
|
border = GfVec4f(r.border.xmin,
|
||||||
r.border.xmax - r.border.xmin, r.border.ymax - r.border.ymin);
|
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 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])};
|
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);
|
GfCamera camera = CameraData(scene->camera, image_res, GfVec4f(0, 0, 1, 1)).gf_camera(border);
|
||||||
|
|
||||||
|
|
||||||
free_camera_delegate->SetCamera(camera);
|
free_camera_delegate->SetCamera(camera);
|
||||||
render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(),
|
render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(),
|
||||||
GfVec4d(0, 0, res[0], res[1]));
|
GfVec4d(0, 0, res[0], res[1]));
|
||||||
if (simple_light_task_delegate) {
|
if (simple_light_task_delegate) {
|
||||||
simple_light_task_delegate->SetCameraPath(free_camera_delegate->GetCameraId());
|
simple_light_task_delegate->SetCameraPath(free_camera_delegate->GetCameraId());
|
||||||
}
|
}
|
||||||
@ -164,7 +179,8 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
|
|||||||
HdTaskSharedPtrVector tasks;
|
HdTaskSharedPtrVector tasks;
|
||||||
if (simple_light_task_delegate) {
|
if (simple_light_task_delegate) {
|
||||||
/* TODO: Uncomment this and fix GL error:
|
/* TODO: Uncomment this and fix GL error:
|
||||||
invalid operation, reported from void __cdecl pxrInternal_v0_22__pxrReserved__::HgiGLResourceBindings::BindResources(void) */
|
invalid operation, reported from void __cdecl
|
||||||
|
pxrInternal_v0_22__pxrReserved__::HgiGLResourceBindings::BindResources(void) */
|
||||||
// tasks.push_back(simple_light_task_delegate->GetTask());
|
// tasks.push_back(simple_light_task_delegate->GetTask());
|
||||||
}
|
}
|
||||||
tasks.push_back(render_task_delegate->GetTask());
|
tasks.push_back(render_task_delegate->GetTask());
|
||||||
@ -220,9 +236,9 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
|
|||||||
elapsedTime = chrono::duration_cast<chrono::milliseconds>(timeCurrent - timeBegin);
|
elapsedTime = chrono::duration_cast<chrono::milliseconds>(timeCurrent - timeBegin);
|
||||||
|
|
||||||
notify_status(percentDone / 100.0,
|
notify_status(percentDone / 100.0,
|
||||||
scene_name + ": " + layer_name,
|
scene_name + ": " + layer_name,
|
||||||
"Render Time: " + format_duration(elapsedTime) +
|
"Render Time: " + format_duration(elapsedTime) +
|
||||||
" | Done: " + to_string(int(percentDone)) + "%");
|
" | Done: " + to_string(int(percentDone)) + "%");
|
||||||
|
|
||||||
if (render_task_delegate->IsConverged()) {
|
if (render_task_delegate->IsConverged()) {
|
||||||
break;
|
break;
|
||||||
@ -236,4 +252,4 @@ void FinalEngineGL::render(Depsgraph *depsgraph)
|
|||||||
updateRenderResult(renderImages, layer_name, res[0], res[1]);
|
updateRenderResult(renderImages, layer_name, res[0], res[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -10,17 +10,22 @@
|
|||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
class FinalEngine : public Engine {
|
class FinalEngine : public Engine {
|
||||||
public:
|
public:
|
||||||
using Engine::Engine;
|
using Engine::Engine;
|
||||||
virtual void sync(Depsgraph *depsgraph, bContext *context, pxr::HdRenderSettingsMap &renderSettings) override;
|
virtual void sync(Depsgraph *depsgraph,
|
||||||
|
bContext *context,
|
||||||
|
pxr::HdRenderSettingsMap &renderSettings) override;
|
||||||
virtual void render(Depsgraph *b_depsgraph) override;
|
virtual void render(Depsgraph *b_depsgraph) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
pxr::GfVec2i get_resolution(Scene *scene);
|
pxr::GfVec2i get_resolution(Scene *scene);
|
||||||
void updateRenderResult(std::map<std::string, std::vector<float>> &render_images, const std::string &layerName, int width, int height);
|
void updateRenderResult(std::map<std::string, std::vector<float>> &render_images,
|
||||||
|
const std::string &layerName,
|
||||||
|
int width,
|
||||||
|
int height);
|
||||||
void notify_status(float progress, const std::string &title, const std::string &info);
|
void notify_status(float progress, const std::string &title, const std::string &info);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
HdRenderSettingsMap renderSettings;
|
HdRenderSettingsMap renderSettings;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -30,4 +35,4 @@ class FinalEngineGL : public FinalEngine {
|
|||||||
void render(Depsgraph *depsgraph) override;
|
void render(Depsgraph *depsgraph) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -1,23 +1,27 @@
|
|||||||
/* SPDX-License-Identifier: Apache-2.0
|
/* SPDX-License-Identifier: Apache-2.0
|
||||||
* Copyright 2011-2022 Blender Foundation */
|
* Copyright 2011-2022 Blender Foundation */
|
||||||
|
|
||||||
#include "DEG_depsgraph_query.h"
|
#include "DEG_depsgraph_query.h"
|
||||||
|
|
||||||
#include "previewEngine.h"
|
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
|
#include "previewEngine.h"
|
||||||
|
|
||||||
using namespace pxr;
|
using namespace pxr;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
void PreviewEngine::sync(Depsgraph *depsgraph, bContext *context, HdRenderSettingsMap &renderSettings)
|
void PreviewEngine::sync(Depsgraph *depsgraph,
|
||||||
|
bContext *context,
|
||||||
|
HdRenderSettingsMap &renderSettings)
|
||||||
{
|
{
|
||||||
scene_delegate = make_unique<BlenderSceneDelegate>(render_index.get(),
|
scene_delegate = make_unique<BlenderSceneDelegate>(
|
||||||
SdfPath::AbsoluteRootPath().AppendElementString("scene"), BlenderSceneDelegate::EngineType::Preview);
|
render_index.get(),
|
||||||
|
SdfPath::AbsoluteRootPath().AppendElementString("scene"),
|
||||||
|
BlenderSceneDelegate::EngineType::Preview);
|
||||||
scene_delegate->populate(depsgraph, context);
|
scene_delegate->populate(depsgraph, context);
|
||||||
|
|
||||||
for (auto const& setting : renderSettings) {
|
for (auto const &setting : renderSettings) {
|
||||||
render_delegate->SetRenderSetting(setting.first, setting.second);
|
render_delegate->SetRenderSetting(setting.first, setting.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -30,10 +34,12 @@ void PreviewEngine::render(Depsgraph *depsgraph)
|
|||||||
string layerName = view_layer->name;
|
string layerName = view_layer->name;
|
||||||
GfVec2i res(scene->r.xsch, scene->r.ysch);
|
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));
|
GfCamera camera =
|
||||||
|
CameraData(scene->camera, res, GfVec4f(0, 0, 1, 1)).gf_camera(GfVec4f(0, 0, 1, 1));
|
||||||
|
|
||||||
free_camera_delegate->SetCamera(camera);
|
free_camera_delegate->SetCamera(camera);
|
||||||
render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(), GfVec4d(0, 0, res[0], res[1]));
|
render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(),
|
||||||
|
GfVec4d(0, 0, res[0], res[1]));
|
||||||
render_task_delegate->SetRendererAov(HdAovTokens->color);
|
render_task_delegate->SetRendererAov(HdAovTokens->color);
|
||||||
|
|
||||||
HdTaskSharedPtrVector tasks;
|
HdTaskSharedPtrVector tasks;
|
||||||
@ -67,9 +73,13 @@ void PreviewEngine::render(Depsgraph *depsgraph)
|
|||||||
updateRenderResult(layerName, res[0], res[1], pixels);
|
updateRenderResult(layerName, res[0], res[1], pixels);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreviewEngine::updateRenderResult(const string &layerName, int width, int height, vector<float> &pixels)
|
void PreviewEngine::updateRenderResult(const string &layerName,
|
||||||
|
int width,
|
||||||
|
int height,
|
||||||
|
vector<float> &pixels)
|
||||||
{
|
{
|
||||||
RenderResult *result = RE_engine_begin_result(bl_engine, 0, 0, width, height, layerName.c_str(), nullptr);
|
RenderResult *result = RE_engine_begin_result(
|
||||||
|
bl_engine, 0, 0, width, height, layerName.c_str(), nullptr);
|
||||||
|
|
||||||
RenderLayer *layer = (RenderLayer *)result->layers.first;
|
RenderLayer *layer = (RenderLayer *)result->layers.first;
|
||||||
RenderPass *pass = (RenderPass *)layer->passes.first;
|
RenderPass *pass = (RenderPass *)layer->passes.first;
|
||||||
@ -78,4 +88,4 @@ void PreviewEngine::updateRenderResult(const string &layerName, int width, int h
|
|||||||
RE_engine_end_result(bl_engine, result, false, false, false);
|
RE_engine_end_result(bl_engine, result, false, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/* SPDX-License-Identifier: Apache-2.0
|
/* SPDX-License-Identifier: Apache-2.0
|
||||||
* Copyright 2011-2022 Blender Foundation */
|
* Copyright 2011-2022 Blender Foundation */
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
@ -7,17 +7,22 @@
|
|||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
class PreviewEngine : public FinalEngine {
|
class PreviewEngine : public FinalEngine {
|
||||||
public:
|
public:
|
||||||
using FinalEngine::FinalEngine;
|
using FinalEngine::FinalEngine;
|
||||||
void sync(Depsgraph *depsgraph, bContext *context, pxr::HdRenderSettingsMap &renderSettings) override;
|
void sync(Depsgraph *depsgraph,
|
||||||
void render(Depsgraph *depsgraph) override;
|
bContext *context,
|
||||||
|
pxr::HdRenderSettingsMap &renderSettings) override;
|
||||||
|
void render(Depsgraph *depsgraph) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void updateRenderResult(const std::string &layerName, int width, int height, std::vector<float> &pixels);
|
void updateRenderResult(const std::string &layerName,
|
||||||
|
int width,
|
||||||
|
int height,
|
||||||
|
std::vector<float> &pixels);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
HdRenderSettingsMap renderSettings;
|
HdRenderSettingsMap renderSettings;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -14,9 +14,9 @@
|
|||||||
#include "glog/logging.h"
|
#include "glog/logging.h"
|
||||||
|
|
||||||
#include "finalEngine.h"
|
#include "finalEngine.h"
|
||||||
#include "viewportEngine.h"
|
|
||||||
#include "previewEngine.h"
|
#include "previewEngine.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "viewportEngine.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -47,7 +47,8 @@ static PyObject *init_func(PyObject * /*self*/, PyObject *args)
|
|||||||
{
|
{
|
||||||
LOG(INFO) << "init_func";
|
LOG(INFO) << "init_func";
|
||||||
|
|
||||||
pxr::PlugRegistry::GetInstance().RegisterPlugins(string(BKE_appdir_program_dir()) + "/blender.shared/usd");
|
pxr::PlugRegistry::GetInstance().RegisterPlugins(string(BKE_appdir_program_dir()) +
|
||||||
|
"/blender.shared/usd");
|
||||||
|
|
||||||
setup_usd_mtlx_environment();
|
setup_usd_mtlx_environment();
|
||||||
|
|
||||||
@ -108,8 +109,10 @@ static PyObject *get_render_plugins_func(PyObject * /*self*/, PyObject *args)
|
|||||||
PyDict_SetItemString(descr, "id", val = PyUnicode_FromString(plugin_ids[i].GetText()));
|
PyDict_SetItemString(descr, "id", val = PyUnicode_FromString(plugin_ids[i].GetText()));
|
||||||
Py_DECREF(val);
|
Py_DECREF(val);
|
||||||
|
|
||||||
PyDict_SetItemString(descr, "name",
|
PyDict_SetItemString(descr,
|
||||||
val = PyUnicode_FromString(UsdImagingGLEngine::GetRendererDisplayName(plugin_ids[i]).c_str()));
|
"name",
|
||||||
|
val = PyUnicode_FromString(
|
||||||
|
UsdImagingGLEngine::GetRendererDisplayName(plugin_ids[i]).c_str()));
|
||||||
Py_DECREF(val);
|
Py_DECREF(val);
|
||||||
|
|
||||||
string plugin_name = plugin_ids[i];
|
string plugin_name = plugin_ids[i];
|
||||||
@ -222,11 +225,10 @@ static PyObject *engine_render_func(PyObject * /*self*/, PyObject *args)
|
|||||||
Depsgraph *depsgraph = (Depsgraph *)PyLong_AsVoidPtr(pydepsgraph);
|
Depsgraph *depsgraph = (Depsgraph *)PyLong_AsVoidPtr(pydepsgraph);
|
||||||
|
|
||||||
/* Allow Blender to execute other Python scripts. */
|
/* Allow Blender to execute other Python scripts. */
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS engine->render(depsgraph);
|
||||||
engine->render(depsgraph);
|
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
|
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *engine_view_draw_func(PyObject * /*self*/, PyObject *args)
|
static PyObject *engine_view_draw_func(PyObject * /*self*/, PyObject *args)
|
||||||
@ -241,40 +243,39 @@ static PyObject *engine_view_draw_func(PyObject * /*self*/, PyObject *args)
|
|||||||
bContext *context = (bContext *)PyLong_AsVoidPtr(pycontext);
|
bContext *context = (bContext *)PyLong_AsVoidPtr(pycontext);
|
||||||
|
|
||||||
/* Allow Blender to execute other Python scripts. */
|
/* Allow Blender to execute other Python scripts. */
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS engine->render(depsgraph, context);
|
||||||
engine->render(depsgraph, context);
|
|
||||||
Py_END_ALLOW_THREADS
|
Py_END_ALLOW_THREADS
|
||||||
|
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyMethodDef methods[] = {
|
static PyMethodDef methods[] = {
|
||||||
{"init", init_func, METH_VARARGS, ""},
|
{"init", init_func, METH_VARARGS, ""},
|
||||||
{"register_plugins", register_plugins_func, METH_VARARGS, ""},
|
{"register_plugins", register_plugins_func, METH_VARARGS, ""},
|
||||||
{"get_render_plugins", get_render_plugins_func, METH_VARARGS, ""},
|
{"get_render_plugins", get_render_plugins_func, METH_VARARGS, ""},
|
||||||
|
|
||||||
{"engine_create", engine_create_func, METH_VARARGS, ""},
|
{"engine_create", engine_create_func, METH_VARARGS, ""},
|
||||||
{"engine_free", engine_free_func, METH_VARARGS, ""},
|
{"engine_free", engine_free_func, METH_VARARGS, ""},
|
||||||
{"engine_render", engine_render_func, METH_VARARGS, ""},
|
{"engine_render", engine_render_func, METH_VARARGS, ""},
|
||||||
{"engine_sync", engine_sync_func, METH_VARARGS, ""},
|
{"engine_sync", engine_sync_func, METH_VARARGS, ""},
|
||||||
{"engine_view_draw", engine_view_draw_func, METH_VARARGS, ""},
|
{"engine_view_draw", engine_view_draw_func, METH_VARARGS, ""},
|
||||||
|
|
||||||
{NULL, NULL, 0, NULL},
|
{NULL, NULL, 0, NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct PyModuleDef module = {
|
static struct PyModuleDef module = {
|
||||||
PyModuleDef_HEAD_INIT,
|
PyModuleDef_HEAD_INIT,
|
||||||
"_hydra",
|
"_hydra",
|
||||||
"Hydra render API",
|
"Hydra render API",
|
||||||
-1,
|
-1,
|
||||||
methods,
|
methods,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -13,13 +13,15 @@
|
|||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
RenderTaskDelegate::RenderTaskDelegate(HdRenderIndex* parentIndex, SdfPath const& delegateID)
|
RenderTaskDelegate::RenderTaskDelegate(HdRenderIndex *parentIndex, SdfPath const &delegateID)
|
||||||
: HdSceneDelegate(parentIndex, delegateID)
|
: HdSceneDelegate(parentIndex, delegateID)
|
||||||
{
|
{
|
||||||
SdfPath renderTaskId = GetTaskID();
|
SdfPath renderTaskId = GetTaskID();
|
||||||
GetRenderIndex().InsertTask<HdxRenderTask>(this, renderTaskId);
|
GetRenderIndex().InsertTask<HdxRenderTask>(this, renderTaskId);
|
||||||
GetRenderIndex().GetChangeTracker().MarkTaskDirty(renderTaskId, HdChangeTracker::DirtyCollection);
|
GetRenderIndex().GetChangeTracker().MarkTaskDirty(renderTaskId,
|
||||||
GetRenderIndex().GetChangeTracker().MarkTaskDirty(renderTaskId, HdChangeTracker::DirtyRenderTags);
|
HdChangeTracker::DirtyCollection);
|
||||||
|
GetRenderIndex().GetChangeTracker().MarkTaskDirty(renderTaskId,
|
||||||
|
HdChangeTracker::DirtyRenderTags);
|
||||||
|
|
||||||
taskParams.enableLighting = true;
|
taskParams.enableLighting = true;
|
||||||
taskParams.alphaThreshold = 0.1f;
|
taskParams.alphaThreshold = 0.1f;
|
||||||
@ -35,14 +37,15 @@ SdfPath RenderTaskDelegate::GetAovID(TfToken const &aov) const
|
|||||||
return GetDelegateID().AppendElementString("aov_" + aov.GetString());
|
return GetDelegateID().AppendElementString("aov_" + aov.GetString());
|
||||||
}
|
}
|
||||||
|
|
||||||
VtValue RenderTaskDelegate::Get(SdfPath const& id, TfToken const& key)
|
VtValue RenderTaskDelegate::Get(SdfPath const &id, TfToken const &key)
|
||||||
{
|
{
|
||||||
LOG(INFO) << "RenderTaskDelegate::Get - " << id.GetAsString() << " " << key.GetString() << "\n";
|
LOG(INFO) << "RenderTaskDelegate::Get - " << id.GetAsString() << " " << key.GetString() << "\n";
|
||||||
if (key == HdTokens->params) {
|
if (key == HdTokens->params) {
|
||||||
return VtValue(taskParams);
|
return VtValue(taskParams);
|
||||||
}
|
}
|
||||||
if (key == HdTokens->collection) {
|
if (key == HdTokens->collection) {
|
||||||
HdRprimCollection rprimCollection(HdTokens->geometry, HdReprSelector(HdReprTokens->smoothHull), false, TfToken());
|
HdRprimCollection rprimCollection(
|
||||||
|
HdTokens->geometry, HdReprSelector(HdReprTokens->smoothHull), false, TfToken());
|
||||||
rprimCollection.SetRootPath(SdfPath::AbsoluteRootPath());
|
rprimCollection.SetRootPath(SdfPath::AbsoluteRootPath());
|
||||||
return VtValue(rprimCollection);
|
return VtValue(rprimCollection);
|
||||||
}
|
}
|
||||||
@ -58,7 +61,7 @@ HdRenderBufferDescriptor RenderTaskDelegate::GetRenderBufferDescriptor(SdfPath c
|
|||||||
TfTokenVector RenderTaskDelegate::GetTaskRenderTags(SdfPath const &taskId)
|
TfTokenVector RenderTaskDelegate::GetTaskRenderTags(SdfPath const &taskId)
|
||||||
{
|
{
|
||||||
LOG(INFO) << "RenderTaskDelegate::GetTaskRenderTags - " << taskId.GetAsString() << "\n";
|
LOG(INFO) << "RenderTaskDelegate::GetTaskRenderTags - " << taskId.GetAsString() << "\n";
|
||||||
return { HdRenderTagTokens->geometry };
|
return {HdRenderTagTokens->geometry};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RenderTaskDelegate::IsConverged()
|
bool RenderTaskDelegate::IsConverged()
|
||||||
@ -71,7 +74,8 @@ void RenderTaskDelegate::SetRendererAov(TfToken const &aov)
|
|||||||
{
|
{
|
||||||
HdAovDescriptor aovDesc = GetRenderIndex().GetRenderDelegate()->GetDefaultAovDescriptor(aov);
|
HdAovDescriptor aovDesc = GetRenderIndex().GetRenderDelegate()->GetDefaultAovDescriptor(aov);
|
||||||
HdRenderBufferDescriptor desc(GfVec3i(taskParams.viewport[2], taskParams.viewport[3], 1),
|
HdRenderBufferDescriptor desc(GfVec3i(taskParams.viewport[2], taskParams.viewport[3], 1),
|
||||||
aovDesc.format, aovDesc.multiSampled);
|
aovDesc.format,
|
||||||
|
aovDesc.multiSampled);
|
||||||
SdfPath bufferId = GetAovID(aov);
|
SdfPath bufferId = GetAovID(aov);
|
||||||
|
|
||||||
if (bufferDescriptors.find(bufferId) == bufferDescriptors.end()) {
|
if (bufferDescriptors.find(bufferId) == bufferDescriptors.end()) {
|
||||||
@ -95,14 +99,17 @@ void RenderTaskDelegate::SetRendererAov(TfToken const &aov)
|
|||||||
|
|
||||||
HdRenderBuffer *RenderTaskDelegate::GetRendererAov(TfToken const &aov)
|
HdRenderBuffer *RenderTaskDelegate::GetRendererAov(TfToken const &aov)
|
||||||
{
|
{
|
||||||
return (HdRenderBuffer *)(GetRenderIndex().GetBprim(HdPrimTypeTokens->renderBuffer, GetAovID(aov)));
|
return (
|
||||||
|
HdRenderBuffer *)(GetRenderIndex().GetBprim(HdPrimTypeTokens->renderBuffer, GetAovID(aov)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderTaskDelegate::GetRendererAovData(TfToken const &aov, void *data)
|
void RenderTaskDelegate::GetRendererAovData(TfToken const &aov, void *data)
|
||||||
{
|
{
|
||||||
HdRenderBuffer *buffer = GetRendererAov(aov);
|
HdRenderBuffer *buffer = GetRendererAov(aov);
|
||||||
void *bufData = buffer->Map();
|
void *bufData = buffer->Map();
|
||||||
memcpy(data, bufData, buffer->GetWidth() * buffer->GetHeight() * HdDataSizeOfFormat(buffer->GetFormat()));
|
memcpy(data,
|
||||||
|
bufData,
|
||||||
|
buffer->GetWidth() * buffer->GetHeight() * HdDataSizeOfFormat(buffer->GetFormat()));
|
||||||
buffer->Unmap();
|
buffer->Unmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,5 +127,4 @@ void RenderTaskDelegate::SetCameraAndViewport(SdfPath const &cameraId, GfVec4d c
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace blender::render::hydra
|
||||||
} // namespace blender::render::hydra
|
|
||||||
|
@ -3,17 +3,16 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <pxr/imaging/hdx/renderSetupTask.h>
|
|
||||||
#include <pxr/imaging/hd/sceneDelegate.h>
|
#include <pxr/imaging/hd/sceneDelegate.h>
|
||||||
|
#include <pxr/imaging/hdx/renderSetupTask.h>
|
||||||
|
|
||||||
using namespace pxr;
|
using namespace pxr;
|
||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
class RenderTaskDelegate : public HdSceneDelegate
|
class RenderTaskDelegate : public HdSceneDelegate {
|
||||||
{
|
public:
|
||||||
public:
|
RenderTaskDelegate(HdRenderIndex *parentIndex, SdfPath const &delegateID);
|
||||||
RenderTaskDelegate(HdRenderIndex* parentIndex, SdfPath const &delegateID);
|
|
||||||
~RenderTaskDelegate() override = default;
|
~RenderTaskDelegate() override = default;
|
||||||
|
|
||||||
SdfPath GetTaskID() const;
|
SdfPath GetTaskID() const;
|
||||||
@ -31,9 +30,9 @@ public:
|
|||||||
HdTaskSharedPtr GetTask();
|
HdTaskSharedPtr GetTask();
|
||||||
void SetCameraAndViewport(SdfPath const &cameraId, GfVec4d const &viewport);
|
void SetCameraAndViewport(SdfPath const &cameraId, GfVec4d const &viewport);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HdxRenderTaskParams taskParams;
|
HdxRenderTaskParams taskParams;
|
||||||
TfHashMap<SdfPath, HdRenderBufferDescriptor, SdfPath::Hash> bufferDescriptors;
|
TfHashMap<SdfPath, HdRenderBufferDescriptor, SdfPath::Hash> bufferDescriptors;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -13,12 +13,14 @@ using namespace std;
|
|||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
BlenderSceneDelegate::BlenderSceneDelegate(HdRenderIndex* parentIndex, SdfPath const& delegateID, BlenderSceneDelegate::EngineType engine_type)
|
BlenderSceneDelegate::BlenderSceneDelegate(HdRenderIndex *parentIndex,
|
||||||
: HdSceneDelegate(parentIndex, delegateID)
|
SdfPath const &delegateID,
|
||||||
, engine_type(engine_type)
|
BlenderSceneDelegate::EngineType engine_type)
|
||||||
, depsgraph(nullptr)
|
: HdSceneDelegate(parentIndex, delegateID),
|
||||||
, context(nullptr)
|
engine_type(engine_type),
|
||||||
, view3d(nullptr)
|
depsgraph(nullptr),
|
||||||
|
context(nullptr),
|
||||||
|
view3d(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,8 +117,10 @@ GfMatrix4d BlenderSceneDelegate::GetInstancerTransform(SdfPath const &instancerI
|
|||||||
return GfMatrix4d(1.0);
|
return GfMatrix4d(1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t BlenderSceneDelegate::SampleInstancerTransform(SdfPath const &instancerId, size_t maxSampleCount,
|
size_t BlenderSceneDelegate::SampleInstancerTransform(SdfPath const &instancerId,
|
||||||
float *sampleTimes, GfMatrix4d *sampleValues)
|
size_t maxSampleCount,
|
||||||
|
float *sampleTimes,
|
||||||
|
GfMatrix4d *sampleValues)
|
||||||
{
|
{
|
||||||
LOG(INFO) << "SampleInstancerTransform: " << instancerId.GetString();
|
LOG(INFO) << "SampleInstancerTransform: " << instancerId.GetString();
|
||||||
size_t ret = 0;
|
size_t ret = 0;
|
||||||
@ -125,8 +129,11 @@ size_t BlenderSceneDelegate::SampleInstancerTransform(SdfPath const &instancerId
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t BlenderSceneDelegate::SamplePrimvar(SdfPath const &id, TfToken const &key, size_t maxSampleCount,
|
size_t BlenderSceneDelegate::SamplePrimvar(SdfPath const &id,
|
||||||
float *sampleTimes, VtValue *sampleValues)
|
TfToken const &key,
|
||||||
|
size_t maxSampleCount,
|
||||||
|
float *sampleTimes,
|
||||||
|
VtValue *sampleValues)
|
||||||
{
|
{
|
||||||
// TODO: add a separate object for instancer for cleaner handling code
|
// TODO: add a separate object for instancer for cleaner handling code
|
||||||
if (id.GetName() == "Instancer") {
|
if (id.GetName() == "Instancer") {
|
||||||
@ -164,7 +171,9 @@ void BlenderSceneDelegate::update_collection(bool remove, bool visibility)
|
|||||||
ITER_BEGIN (DEG_iterator_objects_begin,
|
ITER_BEGIN (DEG_iterator_objects_begin,
|
||||||
DEG_iterator_objects_next,
|
DEG_iterator_objects_next,
|
||||||
DEG_iterator_objects_end,
|
DEG_iterator_objects_end,
|
||||||
&data, Object *, object) {
|
&data,
|
||||||
|
Object *,
|
||||||
|
object) {
|
||||||
|
|
||||||
if (!ObjectData::supported(object)) {
|
if (!ObjectData::supported(object)) {
|
||||||
continue;
|
continue;
|
||||||
@ -216,7 +225,10 @@ void BlenderSceneDelegate::update_collection(bool remove, bool visibility)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlenderSceneDelegate::add_update_object(Object *object, bool geometry, bool transform, bool shading)
|
void BlenderSceneDelegate::add_update_object(Object *object,
|
||||||
|
bool geometry,
|
||||||
|
bool transform,
|
||||||
|
bool shading)
|
||||||
{
|
{
|
||||||
SdfPath id = ObjectData::prim_id(this, object);
|
SdfPath id = ObjectData::prim_id(this, object);
|
||||||
ObjectData *obj_data = object_data(id);
|
ObjectData *obj_data = object_data(id);
|
||||||
@ -317,10 +329,8 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont)
|
|||||||
DEGIDIterData data = {0};
|
DEGIDIterData data = {0};
|
||||||
data.graph = depsgraph;
|
data.graph = depsgraph;
|
||||||
data.only_updated = true;
|
data.only_updated = true;
|
||||||
ITER_BEGIN (DEG_iterator_ids_begin,
|
ITER_BEGIN (
|
||||||
DEG_iterator_ids_next,
|
DEG_iterator_ids_begin, DEG_iterator_ids_next, DEG_iterator_ids_end, &data, ID *, id) {
|
||||||
DEG_iterator_ids_end,
|
|
||||||
&data, ID *, id) {
|
|
||||||
|
|
||||||
transform = (id->recalc & ID_RECALC_TRANSFORM) != 0;
|
transform = (id->recalc & ID_RECALC_TRANSFORM) != 0;
|
||||||
shading = (id->recalc & (ID_RECALC_SHADING | ID_RECALC_ANIMATION)) != 0;
|
shading = (id->recalc & (ID_RECALC_SHADING | ID_RECALC_ANIMATION)) != 0;
|
||||||
@ -330,14 +340,13 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont)
|
|||||||
|
|
||||||
switch (GS(id->name)) {
|
switch (GS(id->name)) {
|
||||||
case ID_OB: {
|
case ID_OB: {
|
||||||
Object *object = (Object *)id;
|
Object *object = (Object *)id;
|
||||||
if (!ObjectData::supported(object)) {
|
if (!ObjectData::supported(object)) {
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
geometry |= (((ID *)object->data)->recalc & ID_RECALC_GEOMETRY) != 0;
|
|
||||||
add_update_object(object, geometry, transform, shading);
|
|
||||||
}
|
}
|
||||||
break;
|
geometry |= (((ID *)object->data)->recalc & ID_RECALC_GEOMETRY) != 0;
|
||||||
|
add_update_object(object, geometry, transform, shading);
|
||||||
|
} break;
|
||||||
|
|
||||||
case ID_MA:
|
case ID_MA:
|
||||||
if (shading) {
|
if (shading) {
|
||||||
@ -383,14 +392,14 @@ void BlenderSceneDelegate::populate(Depsgraph *deps, bContext *cont)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HdMeshTopology BlenderSceneDelegate::GetMeshTopology(SdfPath const& id)
|
HdMeshTopology BlenderSceneDelegate::GetMeshTopology(SdfPath const &id)
|
||||||
{
|
{
|
||||||
LOG(INFO) << "GetMeshTopology: " << id.GetString();
|
LOG(INFO) << "GetMeshTopology: " << id.GetString();
|
||||||
MeshData *m_data = mesh_data(id);
|
MeshData *m_data = mesh_data(id);
|
||||||
return m_data->mesh_topology();
|
return m_data->mesh_topology();
|
||||||
}
|
}
|
||||||
|
|
||||||
VtValue BlenderSceneDelegate::Get(SdfPath const& id, TfToken const& key)
|
VtValue BlenderSceneDelegate::Get(SdfPath const &id, TfToken const &key)
|
||||||
{
|
{
|
||||||
LOG(INFO) << "Get: " << id.GetString() << " " << key.GetString();
|
LOG(INFO) << "Get: " << id.GetString() << " " << key.GetString();
|
||||||
ObjectData *obj_data = object_data(id);
|
ObjectData *obj_data = object_data(id);
|
||||||
@ -409,7 +418,8 @@ VtValue BlenderSceneDelegate::Get(SdfPath const& id, TfToken const& key)
|
|||||||
return VtValue();
|
return VtValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
HdPrimvarDescriptorVector BlenderSceneDelegate::GetPrimvarDescriptors(SdfPath const& id, HdInterpolation interpolation)
|
HdPrimvarDescriptorVector BlenderSceneDelegate::GetPrimvarDescriptors(
|
||||||
|
SdfPath const &id, HdInterpolation interpolation)
|
||||||
{
|
{
|
||||||
LOG(INFO) << "GetPrimvarDescriptors: " << id.GetString() << " " << interpolation;
|
LOG(INFO) << "GetPrimvarDescriptors: " << id.GetString() << " " << interpolation;
|
||||||
if (mesh_data(id)) {
|
if (mesh_data(id)) {
|
||||||
@ -425,12 +435,12 @@ HdPrimvarDescriptorVector BlenderSceneDelegate::GetPrimvarDescriptors(SdfPath co
|
|||||||
return primvars;
|
return primvars;
|
||||||
}
|
}
|
||||||
|
|
||||||
SdfPath BlenderSceneDelegate::GetMaterialId(SdfPath const & rprimId)
|
SdfPath BlenderSceneDelegate::GetMaterialId(SdfPath const &rprimId)
|
||||||
{
|
{
|
||||||
return mesh_data(rprimId)->material_id;
|
return mesh_data(rprimId)->material_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
VtValue BlenderSceneDelegate::GetMaterialResource(SdfPath const& id)
|
VtValue BlenderSceneDelegate::GetMaterialResource(SdfPath const &id)
|
||||||
{
|
{
|
||||||
MaterialData *mat_data = material_data(id);
|
MaterialData *mat_data = material_data(id);
|
||||||
if (mat_data) {
|
if (mat_data) {
|
||||||
@ -439,7 +449,7 @@ VtValue BlenderSceneDelegate::GetMaterialResource(SdfPath const& id)
|
|||||||
return VtValue();
|
return VtValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
GfMatrix4d BlenderSceneDelegate::GetTransform(SdfPath const& id)
|
GfMatrix4d BlenderSceneDelegate::GetTransform(SdfPath const &id)
|
||||||
{
|
{
|
||||||
LOG(INFO) << "GetTransform: " << id.GetString();
|
LOG(INFO) << "GetTransform: " << id.GetString();
|
||||||
ObjectData *obj_data = object_data(id);
|
ObjectData *obj_data = object_data(id);
|
||||||
@ -458,7 +468,7 @@ GfMatrix4d BlenderSceneDelegate::GetTransform(SdfPath const& id)
|
|||||||
return GfMatrix4d();
|
return GfMatrix4d();
|
||||||
}
|
}
|
||||||
|
|
||||||
VtValue BlenderSceneDelegate::GetLightParamValue(SdfPath const& id, TfToken const& key)
|
VtValue BlenderSceneDelegate::GetLightParamValue(SdfPath const &id, TfToken const &key)
|
||||||
{
|
{
|
||||||
LightData *l_data = light_data(id);
|
LightData *l_data = light_data(id);
|
||||||
if (l_data) {
|
if (l_data) {
|
||||||
@ -470,4 +480,4 @@ VtValue BlenderSceneDelegate::GetLightParamValue(SdfPath const& id, TfToken cons
|
|||||||
return VtValue();
|
return VtValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -8,22 +8,20 @@
|
|||||||
#include "BKE_context.h"
|
#include "BKE_context.h"
|
||||||
#include "DEG_depsgraph.h"
|
#include "DEG_depsgraph.h"
|
||||||
|
|
||||||
#include "object.h"
|
|
||||||
#include "mesh.h"
|
|
||||||
#include "light.h"
|
#include "light.h"
|
||||||
|
#include "mesh.h"
|
||||||
|
#include "object.h"
|
||||||
#include "world.h"
|
#include "world.h"
|
||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
class BlenderSceneDelegate : public pxr::HdSceneDelegate {
|
||||||
public:
|
public:
|
||||||
enum class EngineType {
|
enum class EngineType { Viewport = 1, Final, Preview };
|
||||||
Viewport = 1,
|
|
||||||
Final,
|
|
||||||
Preview
|
|
||||||
};
|
|
||||||
|
|
||||||
BlenderSceneDelegate(pxr::HdRenderIndex *render_index, pxr::SdfPath const &delegateId, BlenderSceneDelegate::EngineType engine_type);
|
BlenderSceneDelegate(pxr::HdRenderIndex *render_index,
|
||||||
|
pxr::SdfPath const &delegateId,
|
||||||
|
BlenderSceneDelegate::EngineType engine_type);
|
||||||
~BlenderSceneDelegate() override = default;
|
~BlenderSceneDelegate() override = default;
|
||||||
|
|
||||||
void populate(Depsgraph *depsgraph, bContext *context);
|
void populate(Depsgraph *depsgraph, bContext *context);
|
||||||
@ -33,22 +31,29 @@ public:
|
|||||||
pxr::GfMatrix4d GetTransform(pxr::SdfPath const &id) override;
|
pxr::GfMatrix4d GetTransform(pxr::SdfPath const &id) override;
|
||||||
pxr::VtValue Get(pxr::SdfPath const &id, pxr::TfToken const &key) override;
|
pxr::VtValue Get(pxr::SdfPath const &id, pxr::TfToken const &key) override;
|
||||||
pxr::VtValue GetLightParamValue(pxr::SdfPath const &id, pxr::TfToken const &key) override;
|
pxr::VtValue GetLightParamValue(pxr::SdfPath const &id, pxr::TfToken const &key) override;
|
||||||
pxr::HdPrimvarDescriptorVector GetPrimvarDescriptors(pxr::SdfPath const &id, pxr::HdInterpolation interpolation) override;
|
pxr::HdPrimvarDescriptorVector GetPrimvarDescriptors(
|
||||||
|
pxr::SdfPath const &id, pxr::HdInterpolation interpolation) override;
|
||||||
pxr::SdfPath GetMaterialId(pxr::SdfPath const &rprimId) override;
|
pxr::SdfPath GetMaterialId(pxr::SdfPath const &rprimId) override;
|
||||||
pxr::VtValue GetMaterialResource(pxr::SdfPath const &materialId) override;
|
pxr::VtValue GetMaterialResource(pxr::SdfPath const &materialId) override;
|
||||||
bool GetVisible(pxr::SdfPath const &id) override;
|
bool GetVisible(pxr::SdfPath const &id) override;
|
||||||
pxr::SdfPath GetInstancerId(pxr::SdfPath const &primId) override;
|
pxr::SdfPath GetInstancerId(pxr::SdfPath const &primId) override;
|
||||||
pxr::SdfPathVector GetInstancerPrototypes(pxr::SdfPath const &instancerId) override;
|
pxr::SdfPathVector GetInstancerPrototypes(pxr::SdfPath const &instancerId) override;
|
||||||
pxr::VtIntArray GetInstanceIndices(pxr::SdfPath const &instancerId, pxr::SdfPath const &prototypeId) override;
|
pxr::VtIntArray GetInstanceIndices(pxr::SdfPath const &instancerId,
|
||||||
|
pxr::SdfPath const &prototypeId) override;
|
||||||
pxr::GfMatrix4d GetInstancerTransform(pxr::SdfPath const &instancerId);
|
pxr::GfMatrix4d GetInstancerTransform(pxr::SdfPath const &instancerId);
|
||||||
size_t SampleInstancerTransform(pxr::SdfPath const &instancerId, size_t maxSampleCount,
|
size_t SampleInstancerTransform(pxr::SdfPath const &instancerId,
|
||||||
float *sampleTimes, pxr::GfMatrix4d *sampleValues) override;
|
size_t maxSampleCount,
|
||||||
size_t SamplePrimvar(pxr::SdfPath const &id, pxr::TfToken const &key, size_t maxSampleCount,
|
float *sampleTimes,
|
||||||
float *sampleTimes, pxr::VtValue *sampleValues) override;
|
pxr::GfMatrix4d *sampleValues) override;
|
||||||
|
size_t SamplePrimvar(pxr::SdfPath const &id,
|
||||||
|
pxr::TfToken const &key,
|
||||||
|
size_t maxSampleCount,
|
||||||
|
float *sampleTimes,
|
||||||
|
pxr::VtValue *sampleValues) override;
|
||||||
|
|
||||||
EngineType engine_type;
|
EngineType engine_type;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ObjectData *object_data(pxr::SdfPath const &id);
|
ObjectData *object_data(pxr::SdfPath const &id);
|
||||||
MeshData *mesh_data(pxr::SdfPath const &id);
|
MeshData *mesh_data(pxr::SdfPath const &id);
|
||||||
LightData *light_data(pxr::SdfPath const &id);
|
LightData *light_data(pxr::SdfPath const &id);
|
||||||
@ -61,7 +66,7 @@ private:
|
|||||||
void update_world();
|
void update_world();
|
||||||
void update_collection(bool remove, bool visibility);
|
void update_collection(bool remove, bool visibility);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Depsgraph *depsgraph;
|
Depsgraph *depsgraph;
|
||||||
bContext *context;
|
bContext *context;
|
||||||
View3D *view3d;
|
View3D *view3d;
|
||||||
@ -71,4 +76,4 @@ private:
|
|||||||
std::unique_ptr<WorldData> world_data;
|
std::unique_ptr<WorldData> world_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -11,8 +11,7 @@ using namespace pxr;
|
|||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
IdData::IdData(BlenderSceneDelegate *scene_delegate, ID *id)
|
IdData::IdData(BlenderSceneDelegate *scene_delegate, ID *id)
|
||||||
: scene_delegate(scene_delegate)
|
: scene_delegate(scene_delegate), id(id)
|
||||||
, id(id)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,4 +27,4 @@ VtValue IdData::get_data(TfToken const &key)
|
|||||||
return VtValue();
|
return VtValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <pxr/base/vt/value.h>
|
|
||||||
#include <pxr/base/tf/token.h>
|
#include <pxr/base/tf/token.h>
|
||||||
|
#include <pxr/base/vt/value.h>
|
||||||
#include <pxr/imaging/hd/sceneDelegate.h>
|
#include <pxr/imaging/hd/sceneDelegate.h>
|
||||||
|
|
||||||
#include "DNA_ID.h"
|
#include "DNA_ID.h"
|
||||||
@ -22,12 +22,7 @@ class IdData {
|
|||||||
virtual pxr::VtValue get_data(pxr::TfToken const &key);
|
virtual pxr::VtValue get_data(pxr::TfToken const &key);
|
||||||
template<class T> const T get_data(pxr::TfToken const &key);
|
template<class T> const T get_data(pxr::TfToken const &key);
|
||||||
|
|
||||||
enum class DirtyBits {
|
enum class DirtyBits { DirtyTransform = 1, DirtyVisibility, DirtyMaterial, AllDirty };
|
||||||
DirtyTransform = 1,
|
|
||||||
DirtyVisibility,
|
|
||||||
DirtyMaterial,
|
|
||||||
AllDirty
|
|
||||||
};
|
|
||||||
|
|
||||||
virtual void insert_prim() = 0;
|
virtual void insert_prim() = 0;
|
||||||
virtual void remove_prim() = 0;
|
virtual void remove_prim() = 0;
|
||||||
@ -43,4 +38,4 @@ template<class T> const T IdData::get_data(pxr::TfToken const &key)
|
|||||||
return get_data(key).Get<T>();
|
return get_data(key).Get<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -21,13 +21,14 @@ using namespace boost::algorithm;
|
|||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
LightData::LightData(BlenderSceneDelegate *scene_delegate, Object *object)
|
LightData::LightData(BlenderSceneDelegate *scene_delegate, Object *object)
|
||||||
: ObjectData(scene_delegate, object)
|
: ObjectData(scene_delegate, object)
|
||||||
{
|
{
|
||||||
Light *light = (Light *)((Object *)id)->data;
|
Light *light = (Light *)((Object *)id)->data;
|
||||||
|
|
||||||
data[HdLightTokens->intensity] = scene_delegate->engine_type == BlenderSceneDelegate::EngineType::Preview
|
data[HdLightTokens->intensity] = scene_delegate->engine_type ==
|
||||||
? light->energy / 1000
|
BlenderSceneDelegate::EngineType::Preview ?
|
||||||
: light->energy;
|
light->energy / 1000 :
|
||||||
|
light->energy;
|
||||||
|
|
||||||
data[HdLightTokens->color] = GfVec3f(light->r, light->g, light->b);
|
data[HdLightTokens->color] = GfVec3f(light->r, light->g, light->b);
|
||||||
|
|
||||||
@ -176,4 +177,4 @@ void LightData::mark_prim_dirty(DirtyBits dirty_bits)
|
|||||||
LOG(INFO) << "Update light: " << name() << " [" << (int)dirty_bits << "]";
|
LOG(INFO) << "Update light: " << name() << " [" << (int)dirty_bits << "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -3,15 +3,15 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "pxr/base/tf/hashmap.h"
|
||||||
#include <pxr/usd/sdf/assetPath.h>
|
#include <pxr/usd/sdf/assetPath.h>
|
||||||
#include <pxr/usd/sdf/path.h>
|
#include <pxr/usd/sdf/path.h>
|
||||||
#include "pxr/base/tf/hashmap.h"
|
|
||||||
|
|
||||||
#include "object.h"
|
#include "object.h"
|
||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
class LightData: public ObjectData {
|
class LightData : public ObjectData {
|
||||||
public:
|
public:
|
||||||
LightData(BlenderSceneDelegate *scene_delegate, Object *object);
|
LightData(BlenderSceneDelegate *scene_delegate, Object *object);
|
||||||
|
|
||||||
@ -25,4 +25,4 @@ class LightData: public ObjectData {
|
|||||||
pxr::TfToken prim_type();
|
pxr::TfToken prim_type();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -3,14 +3,14 @@
|
|||||||
|
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
|
|
||||||
#include <pxr/imaging/hd/tokens.h>
|
|
||||||
#include <pxr/imaging/hd/material.h>
|
#include <pxr/imaging/hd/material.h>
|
||||||
#include <pxr/imaging/hd/renderDelegate.h>
|
#include <pxr/imaging/hd/renderDelegate.h>
|
||||||
|
#include <pxr/imaging/hd/tokens.h>
|
||||||
|
|
||||||
#include "glog/logging.h"
|
#include "glog/logging.h"
|
||||||
|
|
||||||
#include "BKE_material.h"
|
|
||||||
#include "BKE_lib_id.h"
|
#include "BKE_lib_id.h"
|
||||||
|
#include "BKE_material.h"
|
||||||
|
|
||||||
#include "blenderSceneDelegate.h"
|
#include "blenderSceneDelegate.h"
|
||||||
#include "material.h"
|
#include "material.h"
|
||||||
@ -20,7 +20,8 @@ using namespace pxr;
|
|||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
std::unique_ptr<MaterialData> MaterialData::init(BlenderSceneDelegate *scene_delegate, Material *material)
|
std::unique_ptr<MaterialData> MaterialData::init(BlenderSceneDelegate *scene_delegate,
|
||||||
|
Material *material)
|
||||||
{
|
{
|
||||||
return std::make_unique<MaterialData>(scene_delegate, material);
|
return std::make_unique<MaterialData>(scene_delegate, material);
|
||||||
}
|
}
|
||||||
@ -35,7 +36,7 @@ pxr::SdfPath MaterialData::prim_id(BlenderSceneDelegate *scene_delegate, Materia
|
|||||||
}
|
}
|
||||||
|
|
||||||
MaterialData::MaterialData(BlenderSceneDelegate *scene_delegate, Material *material)
|
MaterialData::MaterialData(BlenderSceneDelegate *scene_delegate, Material *material)
|
||||||
: IdData(scene_delegate, (ID *)material)
|
: IdData(scene_delegate, (ID *)material)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,4 +121,4 @@ void MaterialData::mark_prim_dirty(DirtyBits dirty_bits)
|
|||||||
LOG(INFO) << "Update material: " << name() << ", mtlx=" << mtlx_path.GetResolvedPath();
|
LOG(INFO) << "Update material: " << name() << ", mtlx=" << mtlx_path.GetResolvedPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "pxr/base/tf/hashmap.h"
|
||||||
#include <pxr/usd/sdf/assetPath.h>
|
#include <pxr/usd/sdf/assetPath.h>
|
||||||
#include <pxr/usd/sdf/path.h>
|
#include <pxr/usd/sdf/path.h>
|
||||||
#include "pxr/base/tf/hashmap.h"
|
|
||||||
|
|
||||||
#include "DNA_material_types.h"
|
#include "DNA_material_types.h"
|
||||||
|
|
||||||
@ -13,9 +13,10 @@
|
|||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
class MaterialData: IdData {
|
class MaterialData : IdData {
|
||||||
public:
|
public:
|
||||||
static std::unique_ptr<MaterialData> init(BlenderSceneDelegate *scene_delegate, Material *material);
|
static std::unique_ptr<MaterialData> init(BlenderSceneDelegate *scene_delegate,
|
||||||
|
Material *material);
|
||||||
static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate, Material *material);
|
static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate, Material *material);
|
||||||
|
|
||||||
MaterialData(BlenderSceneDelegate *scene_delegate, Material *material);
|
MaterialData(BlenderSceneDelegate *scene_delegate, Material *material);
|
||||||
@ -28,10 +29,11 @@ class MaterialData: IdData {
|
|||||||
pxr::VtValue material_resource();
|
pxr::VtValue material_resource();
|
||||||
void export_mtlx();
|
void export_mtlx();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
pxr::SdfAssetPath mtlx_path;
|
pxr::SdfAssetPath mtlx_path;
|
||||||
};
|
};
|
||||||
|
|
||||||
using MaterialDataMap = pxr::TfHashMap<pxr::SdfPath, std::unique_ptr<MaterialData>, pxr::SdfPath::Hash>;
|
using MaterialDataMap =
|
||||||
|
pxr::TfHashMap<pxr::SdfPath, std::unique_ptr<MaterialData>, pxr::SdfPath::Hash>;
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -6,21 +6,21 @@
|
|||||||
|
|
||||||
#include "glog/logging.h"
|
#include "glog/logging.h"
|
||||||
|
|
||||||
|
#include "BKE_material.h"
|
||||||
#include "BKE_mesh.h"
|
#include "BKE_mesh.h"
|
||||||
#include "BKE_mesh_runtime.h"
|
#include "BKE_mesh_runtime.h"
|
||||||
#include "BKE_object.h"
|
#include "BKE_object.h"
|
||||||
#include "BKE_material.h"
|
|
||||||
|
|
||||||
|
#include "../utils.h"
|
||||||
#include "blenderSceneDelegate.h"
|
#include "blenderSceneDelegate.h"
|
||||||
#include "mesh.h"
|
#include "mesh.h"
|
||||||
#include "../utils.h"
|
|
||||||
|
|
||||||
using namespace pxr;
|
using namespace pxr;
|
||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
MeshData::MeshData(BlenderSceneDelegate *scene_delegate, Object *object)
|
MeshData::MeshData(BlenderSceneDelegate *scene_delegate, Object *object)
|
||||||
: ObjectData(scene_delegate, object)
|
: ObjectData(scene_delegate, object)
|
||||||
{
|
{
|
||||||
if (object->type == OB_MESH && object->mode == OB_MODE_OBJECT &&
|
if (object->type == OB_MESH && object->mode == OB_MODE_OBJECT &&
|
||||||
BLI_listbase_is_empty(&object->modifiers)) {
|
BLI_listbase_is_empty(&object->modifiers)) {
|
||||||
@ -64,8 +64,10 @@ Material *MeshData::material()
|
|||||||
|
|
||||||
HdMeshTopology MeshData::mesh_topology()
|
HdMeshTopology MeshData::mesh_topology()
|
||||||
{
|
{
|
||||||
return HdMeshTopology(PxOsdOpenSubdivTokens->catmullClark, HdTokens->rightHanded,
|
return HdMeshTopology(PxOsdOpenSubdivTokens->catmullClark,
|
||||||
face_vertex_counts, face_vertex_indices);
|
HdTokens->rightHanded,
|
||||||
|
face_vertex_counts,
|
||||||
|
face_vertex_indices);
|
||||||
}
|
}
|
||||||
|
|
||||||
HdPrimvarDescriptorVector MeshData::primvar_descriptors(HdInterpolation interpolation)
|
HdPrimvarDescriptorVector MeshData::primvar_descriptors(HdInterpolation interpolation)
|
||||||
@ -81,7 +83,8 @@ HdPrimvarDescriptorVector MeshData::primvar_descriptors(HdInterpolation interpol
|
|||||||
primvars.emplace_back(HdTokens->normals, interpolation, HdPrimvarRoleTokens->normal);
|
primvars.emplace_back(HdTokens->normals, interpolation, HdPrimvarRoleTokens->normal);
|
||||||
}
|
}
|
||||||
if (!uvs.empty()) {
|
if (!uvs.empty()) {
|
||||||
primvars.emplace_back(HdPrimvarRoleTokens->textureCoordinate, interpolation,
|
primvars.emplace_back(HdPrimvarRoleTokens->textureCoordinate,
|
||||||
|
interpolation,
|
||||||
HdPrimvarRoleTokens->textureCoordinate);
|
HdPrimvarRoleTokens->textureCoordinate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,8 +95,8 @@ HdPrimvarDescriptorVector MeshData::instancer_primvar_descriptors(HdInterpolatio
|
|||||||
{
|
{
|
||||||
HdPrimvarDescriptorVector primvars;
|
HdPrimvarDescriptorVector primvars;
|
||||||
if (interpolation == HdInterpolationInstance) {
|
if (interpolation == HdInterpolationInstance) {
|
||||||
primvars.emplace_back(HdInstancerTokens->instanceTransform, interpolation,
|
primvars.emplace_back(
|
||||||
HdPrimvarRoleTokens->none);
|
HdInstancerTokens->instanceTransform, interpolation, HdPrimvarRoleTokens->none);
|
||||||
}
|
}
|
||||||
return primvars;
|
return primvars;
|
||||||
}
|
}
|
||||||
@ -107,14 +110,19 @@ VtIntArray MeshData::instance_indices()
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t MeshData::sample_instancer_transform(size_t maxSampleCount, float *sampleTimes, GfMatrix4d *sampleValues)
|
size_t MeshData::sample_instancer_transform(size_t maxSampleCount,
|
||||||
|
float *sampleTimes,
|
||||||
|
GfMatrix4d *sampleValues)
|
||||||
{
|
{
|
||||||
*sampleTimes = 0.0f;
|
*sampleTimes = 0.0f;
|
||||||
*sampleValues = GfMatrix4d(1.0);
|
*sampleValues = GfMatrix4d(1.0);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t MeshData::sample_instancer_primvar(TfToken const &key, size_t maxSampleCount, float *sampleTimes, VtValue *sampleValues)
|
size_t MeshData::sample_instancer_primvar(TfToken const &key,
|
||||||
|
size_t maxSampleCount,
|
||||||
|
float *sampleTimes,
|
||||||
|
VtValue *sampleValues)
|
||||||
{
|
{
|
||||||
if (key == HdInstancerTokens->instanceTransform) {
|
if (key == HdInstancerTokens->instanceTransform) {
|
||||||
if (maxSampleCount > 0) {
|
if (maxSampleCount > 0) {
|
||||||
@ -134,7 +142,8 @@ void MeshData::add_instance(DupliObject *dupli)
|
|||||||
LOG(INFO) << "Add instancer: " << name() << " id=" << instancer_id.GetAsString();
|
LOG(INFO) << "Add instancer: " << name() << " id=" << instancer_id.GetAsString();
|
||||||
}
|
}
|
||||||
if (instances.empty()) {
|
if (instances.empty()) {
|
||||||
// USD hides the prototype mesh when instancing in contrary to the Blender, so we must add it back implicitly
|
// 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(GfMatrix4d(1.0));
|
||||||
}
|
}
|
||||||
instances.push_back(transform().GetInverse() * gf_matrix_from_transform(dupli->mat));
|
instances.push_back(transform().GetInverse() * gf_matrix_from_transform(dupli->mat));
|
||||||
|
@ -12,8 +12,8 @@
|
|||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
class MeshData: public ObjectData {
|
class MeshData : public ObjectData {
|
||||||
public:
|
public:
|
||||||
MeshData(BlenderSceneDelegate *scene_delegate, Object *object);
|
MeshData(BlenderSceneDelegate *scene_delegate, Object *object);
|
||||||
|
|
||||||
pxr::VtValue get_data(pxr::TfToken const &key) override;
|
pxr::VtValue get_data(pxr::TfToken const &key) override;
|
||||||
@ -27,8 +27,13 @@ public:
|
|||||||
pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation);
|
pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation);
|
||||||
pxr::HdPrimvarDescriptorVector instancer_primvar_descriptors(pxr::HdInterpolation interpolation);
|
pxr::HdPrimvarDescriptorVector instancer_primvar_descriptors(pxr::HdInterpolation interpolation);
|
||||||
pxr::VtIntArray instance_indices();
|
pxr::VtIntArray instance_indices();
|
||||||
size_t sample_instancer_transform(size_t maxSampleCount, float *sampleTimes, pxr::GfMatrix4d *sampleValues);
|
size_t sample_instancer_transform(size_t maxSampleCount,
|
||||||
size_t sample_instancer_primvar(pxr::TfToken const &key, size_t maxSampleCount, float *sampleTimes, pxr::VtValue *sampleValues);
|
float *sampleTimes,
|
||||||
|
pxr::GfMatrix4d *sampleValues);
|
||||||
|
size_t sample_instancer_primvar(pxr::TfToken const &key,
|
||||||
|
size_t maxSampleCount,
|
||||||
|
float *sampleTimes,
|
||||||
|
pxr::VtValue *sampleValues);
|
||||||
|
|
||||||
void add_instance(DupliObject *dupli);
|
void add_instance(DupliObject *dupli);
|
||||||
|
|
||||||
@ -47,6 +52,4 @@ public:
|
|||||||
pxr::VtMatrix4dArray instances;
|
pxr::VtMatrix4dArray instances;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace blender::render::hydra
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
|
||||||
|
@ -3,11 +3,11 @@
|
|||||||
|
|
||||||
#include "BKE_object.h"
|
#include "BKE_object.h"
|
||||||
|
|
||||||
#include "blenderSceneDelegate.h"
|
|
||||||
#include "object.h"
|
|
||||||
#include "mesh.h"
|
|
||||||
#include "light.h"
|
|
||||||
#include "../utils.h"
|
#include "../utils.h"
|
||||||
|
#include "blenderSceneDelegate.h"
|
||||||
|
#include "light.h"
|
||||||
|
#include "mesh.h"
|
||||||
|
#include "object.h"
|
||||||
|
|
||||||
using namespace pxr;
|
using namespace pxr;
|
||||||
|
|
||||||
@ -60,8 +60,7 @@ pxr::SdfPath ObjectData::prim_id(BlenderSceneDelegate *scene_delegate, Object *o
|
|||||||
}
|
}
|
||||||
|
|
||||||
ObjectData::ObjectData(BlenderSceneDelegate *scene_delegate, Object *object)
|
ObjectData::ObjectData(BlenderSceneDelegate *scene_delegate, Object *object)
|
||||||
: IdData(scene_delegate, (ID *)object)
|
: IdData(scene_delegate, (ID *)object), visible(true)
|
||||||
, visible(true)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,19 +3,19 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <pxr/base/gf/matrix4d.h>
|
|
||||||
#include "pxr/base/tf/hashmap.h"
|
#include "pxr/base/tf/hashmap.h"
|
||||||
|
#include <pxr/base/gf/matrix4d.h>
|
||||||
|
|
||||||
#include "DNA_object_types.h"
|
|
||||||
#include "BKE_layer.h"
|
#include "BKE_layer.h"
|
||||||
|
#include "DNA_object_types.h"
|
||||||
|
|
||||||
#include "id.h"
|
#include "id.h"
|
||||||
#include "material.h"
|
#include "material.h"
|
||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
class ObjectData: public IdData {
|
class ObjectData : public IdData {
|
||||||
public:
|
public:
|
||||||
static bool supported(Object *object);
|
static bool supported(Object *object);
|
||||||
static std::unique_ptr<ObjectData> init(BlenderSceneDelegate *scene_delegate, Object *object);
|
static std::unique_ptr<ObjectData> init(BlenderSceneDelegate *scene_delegate, Object *object);
|
||||||
static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate, Object *object);
|
static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate, Object *object);
|
||||||
@ -29,6 +29,7 @@ public:
|
|||||||
bool visible;
|
bool visible;
|
||||||
};
|
};
|
||||||
|
|
||||||
using ObjectDataMap = pxr::TfHashMap<pxr::SdfPath, std::unique_ptr<ObjectData>, pxr::SdfPath::Hash>;
|
using ObjectDataMap =
|
||||||
|
pxr::TfHashMap<pxr::SdfPath, std::unique_ptr<ObjectData>, pxr::SdfPath::Hash>;
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -3,28 +3,28 @@
|
|||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
||||||
#include <pxr/base/vt/array.h>
|
|
||||||
#include <pxr/base/gf/vec2f.h>
|
|
||||||
#include <pxr/base/gf/rotation.h>
|
#include <pxr/base/gf/rotation.h>
|
||||||
|
#include <pxr/base/gf/vec2f.h>
|
||||||
|
#include <pxr/base/vt/array.h>
|
||||||
#include <pxr/imaging/hd/light.h>
|
#include <pxr/imaging/hd/light.h>
|
||||||
#include <pxr/imaging/hd/tokens.h>
|
|
||||||
#include <pxr/imaging/hd/renderDelegate.h>
|
#include <pxr/imaging/hd/renderDelegate.h>
|
||||||
|
#include <pxr/imaging/hd/tokens.h>
|
||||||
#include <pxr/usd/usdLux/tokens.h>
|
#include <pxr/usd/usdLux/tokens.h>
|
||||||
|
|
||||||
#include "BKE_context.h"
|
#include "BKE_context.h"
|
||||||
#include "DNA_node_types.h"
|
#include "DNA_node_types.h"
|
||||||
#include "DNA_windowmanager_types.h"
|
#include "DNA_windowmanager_types.h"
|
||||||
|
|
||||||
|
#include "BKE_image.h"
|
||||||
#include "BKE_node.h"
|
#include "BKE_node.h"
|
||||||
#include "BKE_node_runtime.hh"
|
#include "BKE_node_runtime.hh"
|
||||||
#include "BKE_image.h"
|
|
||||||
#include "NOD_shader.h"
|
#include "NOD_shader.h"
|
||||||
|
|
||||||
#include "glog/logging.h"
|
#include "glog/logging.h"
|
||||||
|
|
||||||
|
#include "../utils.h"
|
||||||
#include "blenderSceneDelegate.h"
|
#include "blenderSceneDelegate.h"
|
||||||
#include "world.h"
|
#include "world.h"
|
||||||
#include "../utils.h"
|
|
||||||
|
|
||||||
/* TODO : add custom tftoken "transparency"? */
|
/* TODO : add custom tftoken "transparency"? */
|
||||||
|
|
||||||
@ -33,7 +33,8 @@ using namespace pxr;
|
|||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
std::unique_ptr<WorldData> WorldData::init(BlenderSceneDelegate *scene_delegate,
|
std::unique_ptr<WorldData> WorldData::init(BlenderSceneDelegate *scene_delegate,
|
||||||
World *world, bContext *context)
|
World *world,
|
||||||
|
bContext *context)
|
||||||
{
|
{
|
||||||
return std::make_unique<WorldData>(scene_delegate, world, context);
|
return std::make_unique<WorldData>(scene_delegate, world, context);
|
||||||
}
|
}
|
||||||
@ -44,7 +45,7 @@ SdfPath WorldData::prim_id(BlenderSceneDelegate *scene_delegate)
|
|||||||
}
|
}
|
||||||
|
|
||||||
WorldData::WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContext *context)
|
WorldData::WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContext *context)
|
||||||
: IdData(scene_delegate, (ID *)world)
|
: IdData(scene_delegate, (ID *)world)
|
||||||
{
|
{
|
||||||
data[UsdLuxTokens->orientToStageUpAxis] = true;
|
data[UsdLuxTokens->orientToStageUpAxis] = true;
|
||||||
|
|
||||||
|
@ -5,11 +5,11 @@
|
|||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
#include "pxr/base/tf/staticTokens.h"
|
||||||
#include <pxr/base/gf/matrix4d.h>
|
#include <pxr/base/gf/matrix4d.h>
|
||||||
|
#include <pxr/base/vt/value.h>
|
||||||
#include <pxr/usd/sdf/assetPath.h>
|
#include <pxr/usd/sdf/assetPath.h>
|
||||||
#include <pxr/usd/sdf/path.h>
|
#include <pxr/usd/sdf/path.h>
|
||||||
#include <pxr/base/vt/value.h>
|
|
||||||
#include "pxr/base/tf/staticTokens.h"
|
|
||||||
|
|
||||||
#include "DNA_view3d_types.h"
|
#include "DNA_view3d_types.h"
|
||||||
#include "DNA_world_types.h"
|
#include "DNA_world_types.h"
|
||||||
@ -18,9 +18,11 @@
|
|||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
class WorldData: public IdData {
|
class WorldData : public IdData {
|
||||||
public:
|
public:
|
||||||
static std::unique_ptr<WorldData> init(BlenderSceneDelegate *scene_delegate, World *world, bContext *context);
|
static std::unique_ptr<WorldData> init(BlenderSceneDelegate *scene_delegate,
|
||||||
|
World *world,
|
||||||
|
bContext *context);
|
||||||
static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate);
|
static pxr::SdfPath prim_id(BlenderSceneDelegate *scene_delegate);
|
||||||
|
|
||||||
WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContext *context);
|
WorldData(BlenderSceneDelegate *scene_delegate, World *world, bContext *context);
|
||||||
@ -36,4 +38,4 @@ public:
|
|||||||
std::map<pxr::TfToken, pxr::VtValue> data;
|
std::map<pxr::TfToken, pxr::VtValue> data;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
/* SPDX-License-Identifier: Apache-2.0
|
/* SPDX-License-Identifier: Apache-2.0
|
||||||
* Copyright 2011-2022 Blender Foundation */
|
* Copyright 2011-2022 Blender Foundation */
|
||||||
|
|
||||||
#include <sstream>
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include <pxr/base/tf/stringUtils.h>
|
#include <pxr/base/tf/stringUtils.h>
|
||||||
|
|
||||||
#include "BKE_appdir.h"
|
#include "BKE_appdir.h"
|
||||||
#include "BKE_image_save.h"
|
#include "BKE_image_save.h"
|
||||||
#include "BLI_string.h"
|
|
||||||
#include "BLI_path_util.h"
|
#include "BLI_path_util.h"
|
||||||
|
#include "BLI_string.h"
|
||||||
|
|
||||||
#include "DNA_camera_types.h"
|
#include "DNA_camera_types.h"
|
||||||
|
|
||||||
@ -22,11 +22,22 @@ namespace blender::render::hydra {
|
|||||||
|
|
||||||
GfMatrix4d gf_matrix_from_transform(float m[4][4])
|
GfMatrix4d gf_matrix_from_transform(float m[4][4])
|
||||||
{
|
{
|
||||||
return GfMatrix4d(
|
return GfMatrix4d(m[0][0],
|
||||||
m[0][0], m[0][1], m[0][2], m[0][3],
|
m[0][1],
|
||||||
m[1][0], m[1][1], m[1][2], m[1][3],
|
m[0][2],
|
||||||
m[2][0], m[2][1], m[2][2], m[2][3],
|
m[0][3],
|
||||||
m[3][0], m[3][1], m[3][2], m[3][3]);
|
m[1][0],
|
||||||
|
m[1][1],
|
||||||
|
m[1][2],
|
||||||
|
m[1][3],
|
||||||
|
m[2][0],
|
||||||
|
m[2][1],
|
||||||
|
m[2][2],
|
||||||
|
m[2][3],
|
||||||
|
m[3][0],
|
||||||
|
m[3][1],
|
||||||
|
m[3][2],
|
||||||
|
m[3][3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
string format_duration(chrono::milliseconds millisecs)
|
string format_duration(chrono::milliseconds millisecs)
|
||||||
@ -101,18 +112,19 @@ string cache_image(Main *bmain,
|
|||||||
|
|
||||||
void set_env_paths(string const &name, vector<string> path_dirs)
|
void set_env_paths(string const &name, vector<string> path_dirs)
|
||||||
{
|
{
|
||||||
const char *env = BLI_getenv(name.c_str());;
|
const char *env = BLI_getenv(name.c_str());
|
||||||
|
;
|
||||||
stringstream ss;
|
stringstream ss;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (string &s : path_dirs) {
|
for (string &s : path_dirs) {
|
||||||
++i;
|
++i;
|
||||||
ss << s;
|
ss << s;
|
||||||
if (i < path_dirs.size() || env) {
|
if (i < path_dirs.size() || env) {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
ss << ";";
|
ss << ";";
|
||||||
#else
|
#else
|
||||||
ss << ":";
|
ss << ":";
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (env) {
|
if (env) {
|
||||||
|
@ -23,4 +23,4 @@ std::string cache_image(Main *bmain,
|
|||||||
ReportList *reports);
|
ReportList *reports);
|
||||||
void set_env_paths(std::string const &name, std::vector<std::string> path_dirs);
|
void set_env_paths(std::string const &name, std::vector<std::string> path_dirs);
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -7,18 +7,18 @@
|
|||||||
#include <pxr/imaging/glf/drawTarget.h>
|
#include <pxr/imaging/glf/drawTarget.h>
|
||||||
#include <pxr/usd/usdGeom/camera.h>
|
#include <pxr/usd/usdGeom/camera.h>
|
||||||
|
|
||||||
#include "DEG_depsgraph_query.h"
|
#include "BKE_camera.h"
|
||||||
#include "BLI_math_matrix.h"
|
#include "BLI_math_matrix.h"
|
||||||
|
#include "DEG_depsgraph_query.h"
|
||||||
#include "DNA_camera_types.h"
|
#include "DNA_camera_types.h"
|
||||||
#include "DNA_screen_types.h"
|
#include "DNA_screen_types.h"
|
||||||
#include "BKE_camera.h"
|
|
||||||
#include "GPU_shader.h"
|
#include "GPU_shader.h"
|
||||||
|
|
||||||
#include "glog/logging.h"
|
#include "glog/logging.h"
|
||||||
|
|
||||||
#include "viewportEngine.h"
|
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "viewportEngine.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace pxr;
|
using namespace pxr;
|
||||||
@ -40,8 +40,7 @@ struct ViewSettings {
|
|||||||
GfVec4i border;
|
GfVec4i border;
|
||||||
};
|
};
|
||||||
|
|
||||||
ViewSettings::ViewSettings(bContext *context)
|
ViewSettings::ViewSettings(bContext *context) : camera_data(context)
|
||||||
: camera_data(context)
|
|
||||||
{
|
{
|
||||||
View3D *view3d = CTX_wm_view3d(context);
|
View3D *view3d = CTX_wm_view3d(context);
|
||||||
RegionView3D *region_data = (RegionView3D *)CTX_wm_region_data(context);
|
RegionView3D *region_data = (RegionView3D *)CTX_wm_region_data(context);
|
||||||
@ -52,7 +51,7 @@ ViewSettings::ViewSettings(bContext *context)
|
|||||||
|
|
||||||
Scene *scene = CTX_data_scene(context);
|
Scene *scene = CTX_data_scene(context);
|
||||||
|
|
||||||
//getting render border
|
// getting render border
|
||||||
int x1 = 0, y1 = 0;
|
int x1 = 0, y1 = 0;
|
||||||
int x2 = screen_width, y2 = screen_height;
|
int x2 = screen_width, y2 = screen_height;
|
||||||
|
|
||||||
@ -64,22 +63,29 @@ ViewSettings::ViewSettings(bContext *context)
|
|||||||
BKE_camera_view_frame(scene, (Camera *)camera_obj->data, camera_points);
|
BKE_camera_view_frame(scene, (Camera *)camera_obj->data, camera_points);
|
||||||
|
|
||||||
float screen_points[4][2];
|
float screen_points[4][2];
|
||||||
for (int i = 0 ; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
float world_location[] = {camera_points[i][0], camera_points[i][1], camera_points[i][2], 1.0f};
|
float world_location[] = {
|
||||||
|
camera_points[i][0], camera_points[i][1], camera_points[i][2], 1.0f};
|
||||||
mul_m4_v4(camera_obj->object_to_world, world_location);
|
mul_m4_v4(camera_obj->object_to_world, world_location);
|
||||||
mul_m4_v4(region_data->persmat, world_location);
|
mul_m4_v4(region_data->persmat, world_location);
|
||||||
|
|
||||||
if (world_location[3] > 0.0) {
|
if (world_location[3] > 0.0) {
|
||||||
screen_points[i][0] = screen_width * 0.5f + screen_width * 0.5f * (world_location[0] / world_location[3]);
|
screen_points[i][0] = screen_width * 0.5f +
|
||||||
screen_points[i][1] = screen_height * 0.5f + screen_height * 0.5f * (world_location[1] / world_location[3]);
|
screen_width * 0.5f * (world_location[0] / world_location[3]);
|
||||||
|
screen_points[i][1] = screen_height * 0.5f +
|
||||||
|
screen_height * 0.5f * (world_location[1] / world_location[3]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// getting camera view region
|
// getting camera view region
|
||||||
float x1_f = min({screen_points[0][0], screen_points[1][0], screen_points[2][0], screen_points[3][0]});
|
float x1_f = min(
|
||||||
float x2_f = max({screen_points[0][0], screen_points[1][0], screen_points[2][0], screen_points[3][0]});
|
{screen_points[0][0], screen_points[1][0], screen_points[2][0], screen_points[3][0]});
|
||||||
float y1_f = min({screen_points[0][1], screen_points[1][1], screen_points[2][1], screen_points[3][1]});
|
float x2_f = max(
|
||||||
float y2_f = max({screen_points[0][1], screen_points[1][1], screen_points[2][1], screen_points[3][1]});
|
{screen_points[0][0], screen_points[1][0], screen_points[2][0], screen_points[3][0]});
|
||||||
|
float y1_f = min(
|
||||||
|
{screen_points[0][1], screen_points[1][1], screen_points[2][1], screen_points[3][1]});
|
||||||
|
float y2_f = max(
|
||||||
|
{screen_points[0][1], screen_points[1][1], screen_points[2][1], screen_points[3][1]});
|
||||||
|
|
||||||
// adjusting region to border
|
// adjusting region to border
|
||||||
float x = x1_f, y = y1_f;
|
float x = x1_f, y = y1_f;
|
||||||
@ -124,16 +130,13 @@ int ViewSettings::height()
|
|||||||
|
|
||||||
GfCamera ViewSettings::gf_camera()
|
GfCamera ViewSettings::gf_camera()
|
||||||
{
|
{
|
||||||
return camera_data.gf_camera(GfVec4f(
|
return camera_data.gf_camera(GfVec4f((float)border[0] / screen_width,
|
||||||
(float)border[0] / screen_width, (float)border[1] / screen_height,
|
(float)border[1] / screen_height,
|
||||||
(float)border[2] / screen_width, (float)border[3] / screen_height));
|
(float)border[2] / screen_width,
|
||||||
|
(float)border[3] / screen_height));
|
||||||
}
|
}
|
||||||
|
|
||||||
GLTexture::GLTexture()
|
GLTexture::GLTexture() : textureId(0), width(0), height(0), channels(4)
|
||||||
: textureId(0)
|
|
||||||
, width(0)
|
|
||||||
, height(0)
|
|
||||||
, channels(4)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,7 +207,7 @@ void GLTexture::draw(GLfloat x, GLfloat y)
|
|||||||
GLint position_location = glGetAttribLocation(shader_program, "pos");
|
GLint position_location = glGetAttribLocation(shader_program, "pos");
|
||||||
|
|
||||||
// Generate geometry buffers for drawing textured quad
|
// Generate geometry buffers for drawing textured quad
|
||||||
GLfloat position[8] = { x, y, x + width, y, x + width, y + height, x, y + height };
|
GLfloat position[8] = {x, y, x + width, y, x + width, y + height, x, y + height};
|
||||||
GLfloat texcoord[8] = {0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0};
|
GLfloat texcoord[8] = {0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0};
|
||||||
|
|
||||||
GLuint vertex_buffer[2];
|
GLuint vertex_buffer[2];
|
||||||
@ -239,15 +242,19 @@ void GLTexture::draw(GLfloat x, GLfloat y)
|
|||||||
glDeleteVertexArrays(1, &vertex_array);
|
glDeleteVertexArrays(1, &vertex_array);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewportEngine::sync(Depsgraph *depsgraph, bContext *context, HdRenderSettingsMap &renderSettings)
|
void ViewportEngine::sync(Depsgraph *depsgraph,
|
||||||
|
bContext *context,
|
||||||
|
HdRenderSettingsMap &renderSettings)
|
||||||
{
|
{
|
||||||
if (!scene_delegate) {
|
if (!scene_delegate) {
|
||||||
scene_delegate = std::make_unique<BlenderSceneDelegate>(render_index.get(),
|
scene_delegate = std::make_unique<BlenderSceneDelegate>(
|
||||||
SdfPath::AbsoluteRootPath().AppendElementString("scene"), BlenderSceneDelegate::EngineType::Viewport);
|
render_index.get(),
|
||||||
|
SdfPath::AbsoluteRootPath().AppendElementString("scene"),
|
||||||
|
BlenderSceneDelegate::EngineType::Viewport);
|
||||||
}
|
}
|
||||||
scene_delegate->populate(depsgraph, context);
|
scene_delegate->populate(depsgraph, context);
|
||||||
|
|
||||||
for (auto const& setting : renderSettings) {
|
for (auto const &setting : renderSettings) {
|
||||||
render_delegate->SetRenderSetting(setting.first, setting.second);
|
render_delegate->SetRenderSetting(setting.first, setting.second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -262,7 +269,10 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
|
|||||||
GfCamera gfCamera = viewSettings.gf_camera();
|
GfCamera gfCamera = viewSettings.gf_camera();
|
||||||
free_camera_delegate->SetCamera(gfCamera);
|
free_camera_delegate->SetCamera(gfCamera);
|
||||||
render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(),
|
render_task_delegate->SetCameraAndViewport(free_camera_delegate->GetCameraId(),
|
||||||
GfVec4d(viewSettings.border[0], viewSettings.border[1], viewSettings.border[2], viewSettings.border[3]));
|
GfVec4d(viewSettings.border[0],
|
||||||
|
viewSettings.border[1],
|
||||||
|
viewSettings.border[2],
|
||||||
|
viewSettings.border[3]));
|
||||||
if (simple_light_task_delegate) {
|
if (simple_light_task_delegate) {
|
||||||
simple_light_task_delegate->SetCameraPath(free_camera_delegate->GetCameraId());
|
simple_light_task_delegate->SetCameraPath(free_camera_delegate->GetCameraId());
|
||||||
}
|
}
|
||||||
@ -298,12 +308,15 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
|
|||||||
GPU_shader_unbind();
|
GPU_shader_unbind();
|
||||||
|
|
||||||
chrono::time_point<chrono::steady_clock> timeCurrent = chrono::steady_clock::now();
|
chrono::time_point<chrono::steady_clock> timeCurrent = chrono::steady_clock::now();
|
||||||
chrono::milliseconds elapsedTime = chrono::duration_cast<chrono::milliseconds>(timeCurrent - timeBegin);
|
chrono::milliseconds elapsedTime = chrono::duration_cast<chrono::milliseconds>(timeCurrent -
|
||||||
|
timeBegin);
|
||||||
|
|
||||||
string formattedTime = format_duration(elapsedTime);
|
string formattedTime = format_duration(elapsedTime);
|
||||||
|
|
||||||
if (!render_task_delegate->IsConverged()) {
|
if (!render_task_delegate->IsConverged()) {
|
||||||
notify_status("Time: " + formattedTime + " | Done: " + to_string(int(renderer_percent_done())) + "%", "Render");
|
notify_status("Time: " + formattedTime +
|
||||||
|
" | Done: " + to_string(int(renderer_percent_done())) + "%",
|
||||||
|
"Render");
|
||||||
bl_engine->flag |= RE_ENGINE_DO_DRAW;
|
bl_engine->flag |= RE_ENGINE_DO_DRAW;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -321,4 +334,4 @@ void ViewportEngine::notify_status(const string &info, const string &status)
|
|||||||
RE_engine_update_stats(bl_engine, status.c_str(), info.c_str());
|
RE_engine_update_stats(bl_engine, status.c_str(), info.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
@ -13,15 +13,14 @@
|
|||||||
|
|
||||||
namespace blender::render::hydra {
|
namespace blender::render::hydra {
|
||||||
|
|
||||||
class GLTexture
|
class GLTexture {
|
||||||
{
|
public:
|
||||||
public:
|
|
||||||
GLTexture();
|
GLTexture();
|
||||||
~GLTexture();
|
~GLTexture();
|
||||||
void setBuffer(pxr::HdRenderBuffer *buffer);
|
void setBuffer(pxr::HdRenderBuffer *buffer);
|
||||||
void draw(GLfloat x, GLfloat y);
|
void draw(GLfloat x, GLfloat y);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void create(pxr::HdRenderBuffer *buffer);
|
void create(pxr::HdRenderBuffer *buffer);
|
||||||
void free();
|
void free();
|
||||||
|
|
||||||
@ -30,19 +29,21 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
class ViewportEngine : public Engine {
|
class ViewportEngine : public Engine {
|
||||||
public:
|
public:
|
||||||
using Engine::Engine;
|
using Engine::Engine;
|
||||||
void sync(Depsgraph *depsgraph, bContext *context, pxr::HdRenderSettingsMap &renderSettings) override;
|
void sync(Depsgraph *depsgraph,
|
||||||
|
bContext *context,
|
||||||
|
pxr::HdRenderSettingsMap &renderSettings) override;
|
||||||
void render(Depsgraph *depsgraph) override;
|
void render(Depsgraph *depsgraph) override;
|
||||||
void render(Depsgraph *depsgraph, bContext *context);
|
void render(Depsgraph *depsgraph, bContext *context);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void notify_status(const std::string &title, const std::string &info);
|
void notify_status(const std::string &title, const std::string &info);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::chrono::time_point<std::chrono::steady_clock> timeBegin;
|
std::chrono::time_point<std::chrono::steady_clock> timeBegin;
|
||||||
|
|
||||||
GLTexture texture;
|
GLTexture texture;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace blender::render::hydra
|
} // namespace blender::render::hydra
|
||||||
|
Loading…
Reference in New Issue
Block a user