BLEN-343: Create PreviewEngine #8

Merged
Bogdan Nagirniak merged 5 commits from BLEN-343 into hydra-render 2023-03-03 14:55:28 +01:00
7 changed files with 11 additions and 29 deletions
Showing only changes of commit 2fcd7a4713 - Show all commits

View File

@ -46,7 +46,7 @@ class HydraRenderEngine(bpy.types.RenderEngine):
delegate_settings = self.get_delegate_settings(engine_type) delegate_settings = self.get_delegate_settings(engine_type)
_hydra.engine_sync(self.engine_ptr, depsgraph.as_pointer(), bpy.context.as_pointer(), delegate_settings) _hydra.engine_sync(self.engine_ptr, depsgraph.as_pointer(), bpy.context.as_pointer(), delegate_settings)
_hydra.engine_render(self.engine_ptr, depsgraph.as_pointer(), engine_type) _hydra.engine_render(self.engine_ptr, depsgraph.as_pointer())
Review

revert this

revert this
# viewport render # viewport render
def view_update(self, context, depsgraph): def view_update(self, context, depsgraph):

View File

@ -12,7 +12,7 @@ namespace blender::render::hydra {
class FinalEngine : public Engine { class FinalEngine : public Engine {
public: public:
using Engine::Engine; using Engine::Engine;
void sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, pxr::HdRenderSettingsMap &renderSettings) override; virtual void sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, pxr::HdRenderSettingsMap &renderSettings) override;
virtual void render(BL::Depsgraph &b_depsgraph) override; virtual void render(BL::Depsgraph &b_depsgraph) override;
protected: protected:

View File

@ -3,20 +3,18 @@
#pragma once #pragma once
#include "engine.h" #include "finalEngine.h"
namespace blender::render::hydra { namespace blender::render::hydra {
class PreviewEngine : public Engine { class PreviewEngine : public FinalEngine {
DagerD marked this conversation as resolved
Review

Maybe inherit from FinalEngine?

Maybe inherit from FinalEngine?
public: public:
using Engine::Engine; using FinalEngine::FinalEngine;
void sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, pxr::HdRenderSettingsMap &renderSettings) override; void sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, pxr::HdRenderSettingsMap &renderSettings) override;
void render(BL::Depsgraph &b_depsgraph) override; void render(BL::Depsgraph &b_depsgraph) override;
protected: protected:
pxr::GfVec2i get_resolution(BL::RenderSettings b_render);
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);
void notifyStatus(float progress, const std::string &title, const std::string &info);
protected: protected:
HdRenderSettingsMap renderSettings; HdRenderSettingsMap renderSettings;

View File

@ -209,20 +209,12 @@ static PyObject *engine_sync_func(PyObject * /*self*/, PyObject *args)
static PyObject *engine_render_func(PyObject * /*self*/, PyObject *args) static PyObject *engine_render_func(PyObject * /*self*/, PyObject *args)
{ {
PyObject *pyengine, *pydepsgraph; PyObject *pyengine, *pydepsgraph;
char *engineType;
if (!PyArg_ParseTuple(args, "OOs", &pyengine, &pydepsgraph, &engineType)) { if (!PyArg_ParseTuple(args, "OO", &pyengine, &pydepsgraph)) {
Py_RETURN_NONE; Py_RETURN_NONE;
} }
Engine *engine; Engine *engine = (Engine *)PyLong_AsVoidPtr(pyengine);
if (string(engineType) == "PREVIEW") {
engine = (PreviewEngine *)PyLong_AsVoidPtr(pyengine);
}
else {
engine = (FinalEngine *)PyLong_AsVoidPtr(pyengine);
}
PointerRNA depsgraphptr; PointerRNA depsgraphptr;
RNA_pointer_create(NULL, &RNA_Depsgraph, (ID *)PyLong_AsVoidPtr(pydepsgraph), &depsgraphptr); RNA_pointer_create(NULL, &RNA_Depsgraph, (ID *)PyLong_AsVoidPtr(pydepsgraph), &depsgraphptr);
@ -255,7 +247,7 @@ static PyObject *engine_view_draw_func(PyObject * /*self*/, PyObject *args)
/* Allow Blender to execute other Python scripts. */ /* Allow Blender to execute other Python scripts. */
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
engine->viewDraw(b_depsgraph, b_context); engine->render(b_depsgraph, b_context);
Py_END_ALLOW_THREADS Py_END_ALLOW_THREADS
Py_RETURN_NONE; Py_RETURN_NONE;

View File

@ -27,14 +27,6 @@ void BlenderSceneDelegate::set_material(MeshData &mesh_data)
mesh_data.material_id = SdfPath::EmptyPath(); mesh_data.material_id = SdfPath::EmptyPath();
return; return;
} }
/**
* Haven't found any description about this flag. It disables some materials
* that don't exist for preview render
*/
if (!material->flag) {
mesh_data.material_id = SdfPath::EmptyPath();
return;
}
SdfPath id = MaterialData::prim_id(this, material); SdfPath id = MaterialData::prim_id(this, material);
MaterialData *mat_data = material_data(id); MaterialData *mat_data = material_data(id);
if (!mat_data) { if (!mat_data) {

View File

@ -253,7 +253,7 @@ void ViewportEngine::sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, Hd
} }
} }
void ViewportEngine::viewDraw(BL::Depsgraph &b_depsgraph, BL::Context &b_context) void ViewportEngine::render(BL::Depsgraph &b_depsgraph, BL::Context &b_context)
{ {
ViewSettings viewSettings(b_context); ViewSettings viewSettings(b_context);
if (viewSettings.width() * viewSettings.height() == 0) { if (viewSettings.width() * viewSettings.height() == 0) {

View File

@ -33,8 +33,8 @@ class ViewportEngine : public Engine {
public: public:
using Engine::Engine; using Engine::Engine;
void sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, pxr::HdRenderSettingsMap &renderSettings) override; void sync(BL::Depsgraph &b_depsgraph, BL::Context &b_context, pxr::HdRenderSettingsMap &renderSettings) override;
void viewDraw(BL::Depsgraph &b_depsgraph, BL::Context &b_context);
void render(BL::Depsgraph &b_depsgraph) override; void render(BL::Depsgraph &b_depsgraph) override;
void render(BL::Depsgraph &b_depsgraph, BL::Context &b_context);
private: private:
void notifyStatus(const std::string &title, const std::string &info); void notifyStatus(const std::string &title, const std::string &info);