36 pxr::SdfPath
const &delegate_id,
40 instancer_data_ = std::make_unique<InstancerData>(
this, instancer_prim_id());
41 world_data_ = std::make_unique<WorldData>(
this, world_prim_id());
48 return m_data->topology(
id);
69 return pxr::GfMatrix4d();
87 return pxr::VtValue();
91 pxr::TfToken
const &key)
98 return pxr::VtValue();
102 pxr::SdfPath
const &
id, pxr::HdInterpolation interpolation)
107 return m_data->primvar_descriptors(interpolation);
117 return pxr::HdPrimvarDescriptorVector();
127 return pxr::SdfPath();
137 return pxr::VtValue();
143 if (
id == world_prim_id()) {
150 return object_data(
id)->
visible;
169 if (i_data && mesh_data(prim_id)) {
172 return pxr::SdfPath();
183 pxr::SdfPath
const &prototype_id)
187 return i_data->
indices(prototype_id);
198 pxr::SdfPath
const &volume_id)
207 bool is_populated =
depsgraph !=
nullptr;
218 set_light_shading_settings();
219 set_world_shading_settings();
221 world_data_->update();
227 for (
auto &obj_data : objects_.
values()) {
231 instancer_data_->remove();
232 for (
auto &mat_data : materials_.
values()) {
243pxr::SdfPath HydraSceneDelegate::prim_id(
const ID *
id,
const char *prefix)
const
247 SNPRINTF(name,
"%s_%p", prefix,
id);
248 return GetDelegateID().AppendElementString(name);
251pxr::SdfPath HydraSceneDelegate::object_prim_id(
const Object *
object)
const
253 return prim_id((
ID *)
object,
"O");
256pxr::SdfPath HydraSceneDelegate::material_prim_id(
const Material *mat)
const
258 return prim_id((
ID *)mat,
"M");
261pxr::SdfPath HydraSceneDelegate::hair_prim_id(
Object *parent_obj,
const ParticleSystem *psys)
const
266 object_prim_id(parent_obj).GetName().c_str(),
267 prim_id((
ID *)psys,
"PS").GetName().c_str());
268 return GetDelegateID().AppendElementString(name);
271pxr::SdfPath HydraSceneDelegate::instancer_prim_id()
const
273 return GetDelegateID().AppendElementString(
"Instancer");
276pxr::SdfPath HydraSceneDelegate::world_prim_id()
const
278 return GetDelegateID().AppendElementString(
"World");
281ObjectData *HydraSceneDelegate::object_data(pxr::SdfPath
const &
id)
const
283 if (
id == world_prim_id()) {
284 return world_data_.get();
286 auto name =
id.GetName();
287 pxr::SdfPath p_id = (
STRPREFIX(name.c_str(),
"SM_") ||
STRPREFIX(name.c_str(),
"VF_")) ?
292 return obj_data->get();
294 InstancerData *i_data = instancer_data(p_id,
true);
296 return i_data->object_data(
id);
301MeshData *HydraSceneDelegate::mesh_data(pxr::SdfPath
const &
id)
const
303 return dynamic_cast<MeshData *
>(object_data(
id));
306CurvesData *HydraSceneDelegate::curves_data(pxr::SdfPath
const &
id)
const
308 return dynamic_cast<CurvesData *
>(object_data(
id));
311VolumeData *HydraSceneDelegate::volume_data(pxr::SdfPath
const &
id)
const
313 return dynamic_cast<VolumeData *
>(object_data(
id));
316LightData *HydraSceneDelegate::light_data(pxr::SdfPath
const &
id)
const
318 return dynamic_cast<LightData *
>(object_data(
id));
321MaterialData *HydraSceneDelegate::material_data(pxr::SdfPath
const &
id)
const
327 return mat_data->get();
330HairData *HydraSceneDelegate::hair_data(pxr::SdfPath
const &
id)
const
332 return dynamic_cast<HairData *
>(object_data(
id));
335InstancerData *HydraSceneDelegate::instancer_data(pxr::SdfPath
const &
id,
bool child_id)
const
341 int n =
id.GetPathElementCount();
343 p_id =
id.GetParentPath();
346 p_id =
id.GetParentPath().GetParentPath();
353 if (instancer_data_ && p_id == instancer_data_->prim_id) {
354 return instancer_data_.get();
359void HydraSceneDelegate::check_updates()
361 bool do_update_collection =
false;
362 bool do_update_world =
false;
364 if (set_world_shading_settings()) {
365 do_update_world =
true;
368 if (set_light_shading_settings()) {
369 do_update_collection =
true;
374 data.only_updated =
true;
381 std::bitset<32>(id->recalc).to_string().c_str());
383 switch (
GS(id->name)) {
385 do_update_collection =
true;
389 MaterialData *mat_data = material_data(material_prim_id((
Material *)
id));
397 do_update_world =
true;
405 do_update_collection =
true;
408 do_update_world =
true;
419 if (do_update_world) {
420 world_data_->update();
422 if (do_update_collection) {
427void HydraSceneDelegate::update_collection()
429 Set<std::string> available_objects;
437 data.flag = settings.flags;
439 instancer_data_->pre_update();
441 auto update_psys = [
this, &available_objects](
Object *object) {
447 pxr::SdfPath
id = hair_prim_id(
object, psys);
448 HairData *h_data = hair_data(
id);
453 h_data =
dynamic_cast<HairData *
>(
454 objects_.
lookup_or_add(
id, std::make_unique<HairData>(
this,
object,
id, psys))
459 available_objects.add(
id.GetName());
464 auto update_object = [
this, &available_objects](
Object *object) {
471 available_objects.add(object_prim_id(
object).GetName());
473 pxr::SdfPath
id = object_prim_id(
object);
474 ObjectData *obj_data = object_data(
id);
491 if (data.dupli_object_current) {
500 instancer_data_->update_instance(dupli);
505 update_object(
object);
509 instancer_data_->post_update();
513 bool ret = !available_objects.contains(item.key.GetName());
515 item.value->remove();
521 Set<pxr::SdfPath> available_materials;
522 for (
auto &val : objects_.values()) {
523 MeshData *
m_data =
dynamic_cast<MeshData *
>(val.get());
525 m_data->available_materials(available_materials);
527 CurvesData *c_data =
dynamic_cast<CurvesData *
>(val.get());
529 c_data->available_materials(available_materials);
531 VolumeData *v_data =
dynamic_cast<VolumeData *
>(val.get());
533 v_data->available_materials(available_materials);
536 instancer_data_->available_materials(available_materials);
539 bool ret = !available_materials.contains(item.key);
541 item.value->remove();
547bool HydraSceneDelegate::set_light_shading_settings()
557bool HydraSceneDelegate::set_world_shading_settings()
bool psys_in_edit_mode(struct Depsgraph *depsgraph, const struct ParticleSystem *psys)
#define ITER_BEGIN(callback_begin, callback_next, callback_end, _data_in, _type, _instance)
#define LISTBASE_FOREACH(type, var, list)
#define SNPRINTF(dst, format,...)
#define CLG_LOGREF_DECLARE_GLOBAL(var, id)
#define CLOG_INFO(clg_ref, level,...)
void DEG_iterator_ids_begin(BLI_Iterator *iter, DEGIDIterData *data)
void DEG_iterator_objects_begin(BLI_Iterator *iter, DEGObjectIterData *data)
void DEG_iterator_objects_end(BLI_Iterator *iter)
void DEG_iterator_ids_end(BLI_Iterator *iter)
Main * DEG_get_bmain(const Depsgraph *graph)
#define DEG_OBJECT_ITER_FOR_RENDER_ENGINE_FLAGS
void DEG_iterator_objects_next(BLI_Iterator *iter)
void DEG_iterator_ids_next(BLI_Iterator *iter)
Scene * DEG_get_input_scene(const Depsgraph *graph)
#define V3D_USES_SCENE_WORLD(v3d)
#define V3D_USES_SCENE_LIGHTS(v3d)
btAlignedObjectArray< btScalar > m_data
const Value * lookup_ptr(const Key &key) const
ValueIterator values() const
int64_t remove_if(Predicate &&predicate)
Value & lookup_or_add(const Key &key, const Value &value)
pxr::HdBasisCurvesTopology topology() const
pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation) const
static bool is_supported(const ParticleSystem *particle_system)
static bool is_visible(HydraSceneDelegate *scene_delegate, Object *object, ParticleSystem *particle_system)
pxr::VtValue GetMaterialResource(pxr::SdfPath const &material_id) override
bool GetVisible(pxr::SdfPath const &id) override
pxr::VtIntArray GetInstanceIndices(pxr::SdfPath const &instancer_id, pxr::SdfPath const &prototype_id) override
pxr::HdPrimvarDescriptorVector GetPrimvarDescriptors(pxr::SdfPath const &id, pxr::HdInterpolation interpolation) override
pxr::VtValue GetLightParamValue(pxr::SdfPath const &id, pxr::TfToken const &key) override
HydraSceneDelegate(pxr::HdRenderIndex *parent_index, pxr::SdfPath const &delegate_id, bool use_materialx)
pxr::HdVolumeFieldDescriptorVector GetVolumeFieldDescriptors(pxr::SdfPath const &volume_id) override
pxr::HdCullStyle GetCullStyle(pxr::SdfPath const &id) override
pxr::VtValue Get(pxr::SdfPath const &id, pxr::TfToken const &key) override
void populate(Depsgraph *depsgraph, View3D *v3d)
pxr::SdfPath GetMaterialId(pxr::SdfPath const &rprim_id) override
pxr::GfMatrix4d GetInstancerTransform(pxr::SdfPath const &instancer_id) override
pxr::HdBasisCurvesTopology GetBasisCurvesTopology(pxr::SdfPath const &id) override
pxr::GfMatrix4d GetTransform(pxr::SdfPath const &id) override
ShadingSettings shading_settings
pxr::SdfPath GetInstancerId(pxr::SdfPath const &prim_id) override
pxr::SdfPathVector GetInstancerPrototypes(pxr::SdfPath const &instancer_id) override
pxr::HdMeshTopology GetMeshTopology(pxr::SdfPath const &id) override
bool GetDoubleSided(pxr::SdfPath const &id) override
pxr::GfMatrix4d transform(pxr::SdfPath const &id) const
pxr::VtIntArray indices(pxr::SdfPath const &id) const
pxr::HdPrimvarDescriptorVector primvar_descriptors(pxr::HdInterpolation interpolation) const
pxr::VtValue get_data(pxr::TfToken const &key) const override
pxr::SdfPathVector prototypes() const
pxr::VtValue get_data(pxr::TfToken const &key) const override
pxr::VtValue get_material_resource() const
pxr::VtValue get_data(pxr::TfToken const &key) const override
pxr::HdCullStyle cull_style(pxr::SdfPath const &id) const
bool double_sided(pxr::SdfPath const &id) const
pxr::GfMatrix4d transform
virtual pxr::SdfPath material_id() const
static bool is_visible(HydraSceneDelegate *scene_delegate, const Object *object, int mode=OB_VISIBLE_SELF)
static std::unique_ptr< ObjectData > create(HydraSceneDelegate *scene_delegate, const Object *object, pxr::SdfPath const &prim_id)
static bool is_supported(const Object *object)
virtual pxr::VtValue get_data(pxr::SdfPath const &id, pxr::TfToken const &key) const
pxr::HdVolumeFieldDescriptorVector field_descriptors() const
struct CLG_LogRef * LOG_HYDRA_SCENE
DEGObjectIterSettings * settings
float studiolight_intensity
std::string studiolight_name
float studiolight_rotation
float studiolight_intensity
bool operator==(const ShadingSettings &other) const