7#include <pxr/imaging/hd/light.h>
8#include <pxr/imaging/hd/material.h>
9#include <pxr/imaging/hd/renderDelegate.h>
10#include <pxr/imaging/hd/retainedDataSource.h>
11#include <pxr/imaging/hd/tokens.h>
12#include <pxr/imaging/hd/xformSchema.h>
42bool HydraSceneIndex::object_is_supported(
const Object *
object)
const
64bool HydraSceneIndex::object_is_visible(Depsgraph *depsgraph,
77 pxr::HdRenderDelegate *render_delegate,
78 const bool use_materialx)
79 : retained_(pxr::HdRetainedSceneIndex::
New()),
80 root_path_(root_path),
81 render_delegate_(render_delegate),
82 use_materialx_(use_materialx)
84 if (render_delegate_) {
85 material_render_contexts_ = render_delegate_->GetMaterialRenderContexts();
86 shader_source_types_ = render_delegate_->GetShaderSourceTypes();
106 iter_data.
graph = depsgraph;
111 id_recalc.
add(
id,
id->recalc);
115 auto has_recalc = [&](
const ID *
id,
const int flag) {
117 return recalc && (*recalc & flag) != 0;
121 emitted_materials_.remove_if([&](
const auto &item) {
128 for (
const auto &item : instance_geometries_by_object_.items()) {
130 for (
const ID *geom : item.value) {
131 dirty_instance_geometries.
add(geom);
137 emitted_geometry_.
remove_if([&](
const auto &item) {
139 dirty_instance_geometries.
contains(item.key.id);
152 instance_geometries_by_object_,
159 data.settings = &settings;
177 if (updated_geometry && !
data.dupli_object_current) {
178 if (
const EmittedObject *prev = emitted_objects_.lookup_ptr(
object)) {
180 emitted_geometry_.remove(k);
185 if (!
data.dupli_object_current && !updated_geometry) {
186 if (
EmittedObject *cached = emitted_objects_.lookup_ptr(
object)) {
187 if (!updated_transform) {
192 for (
const Material *mat : cached->materials) {
203 object->object_to_world().ptr());
208 const pxr::GfMatrix4d new_xform = item.
geometry_xform * obj_xform;
209 item.
xform_overlay = pxr::HdRetainedContainerDataSource::New(
210 pxr::HdXformSchema::GetSchemaToken(),
211 pxr::HdXformSchema::Builder()
213 pxr::HdRetainedTypedSampledDataSource<pxr::GfMatrix4d>::New(new_xform))
214 .SetResetXformStack(pxr::HdRetainedTypedSampledDataSource<bool>::New(
false))
218 ctx.
to_dirty.push_back({item.
path, pxr::HdXformSchema::GetDefaultLocator()});
220 for (
const Material *mat : cached->materials) {
231 if (
data.dupli_object_current) {
233 Object *source =
data.dupli_object_current->ob;
274 if (!object_is_supported(
object)) {
284 if (!emitted.
prims.is_empty()) {
304 if (!emitted.
prims.is_empty()) {
315 ctx.
emit_prim(instancer_path, pxr::HdPrimTypeTokens->instancer, prim_ds);
319 emitted_materials_.remove_if(
321 emitted_geometry_.remove_if(
323 instance_geometries_by_object_.remove_if(
327 for (
const auto &item : emitted_materials_.items()) {
328 if (item.value.data_source) {
333 const EmittedMaterial *entry = emitted_materials_.lookup_ptr(material);
341 const pxr::SdfPath world_path = root_path_.AppendElementString(
"World");
342 const bool world_shading_changed = scene->
world &&
345 emitted_world_.emit(ctx, bmain, scene, view3d, world_path, world_shading_changed);
349 pxr::HdSceneIndexObserver::RemovedPrimEntries to_remove;
350 for (
const pxr::SdfPath &path : emitted_paths_) {
352 to_remove.push_back({path});
356 if (!to_remove.empty()) {
357 retained_->RemovePrims(to_remove);
359 if (!ctx.
to_add.empty()) {
360 retained_->AddPrims(ctx.
to_add);
363 retained_->DirtyPrims(ctx.
to_dirty);
366 emitted_paths_ = std::move(ctx.
new_paths);
372 if (!emitted_paths_.is_empty()) {
373 pxr::HdSceneIndexObserver::RemovedPrimEntries to_remove;
374 for (
const pxr::SdfPath &path : emitted_paths_) {
375 to_remove.push_back({path});
377 retained_->RemovePrims(to_remove);
378 emitted_paths_.clear();
380 emitted_objects_.clear();
381 emitted_materials_.clear();
382 emitted_geometry_.clear();
383 instance_geometries_by_object_.clear();
384 emitted_world_.clear();
General operations, lookup, etc. for blender objects.
#define ITER_BEGIN(callback_begin, callback_next, callback_end, _data_in, _type, _instance)
#define DEG_OBJECT_ITER_FOR_RENDER_ENGINE_FLAGS
ID and Library types, which are fundamental for SDNA.
Object is a sort of wrapper for general info.
constexpr IndexRange()=default
const Value * lookup_ptr(const Key &key) const
bool add(const Key &key, const Value &value)
bool contains(const Key &key) const
int64_t remove_if(Predicate &&predicate)
void populate(Depsgraph *depsgraph, View3D *view3d)
HydraSceneIndex(const pxr::SdfPath &root_path, pxr::HdRenderDelegate *render_delegate, bool use_materialx)
void emit_hair_proto(PopulateContext &ctx, Object *source)
void emit_hair_for_object(PopulateContext &ctx, Object *object, EmittedObject &emitted)
void emit_mesh_proto(PopulateContext &ctx, const BObjectInfo &info)
void emit_curves_proto(PopulateContext &ctx, const BObjectInfo &info)
void emit_mesh_object(PopulateContext &ctx, const BObjectInfo &info, EmittedObject &emitted)
bool emit_volume_object(PopulateContext &ctx, const Object *object, EmittedObject &emitted)
static bool object_render_as_geometry(const Object *object)
CLG_LOGREF_DECLARE_GLOBAL(LOG_HYDRA_SCENE_INDEX, "hydra.scene_index")
CLG_LogRef * LOG_HYDRA_SCENE_INDEX
void emit_light_dupli(PopulateContext &ctx, const Object *source, const float dupli_mat[4][4])
pxr::GfMatrix4d gf_matrix_from_transform(const float m[4][4])
void emit_volume_dupli(PopulateContext &ctx, const Object *source, const float dupli_mat[4][4])
void emit_light_object(PopulateContext &ctx, const Object *object, EmittedObject &emitted)
pxr::HdContainerDataSourceHandle build_instancer_prim_data_source(Span< pxr::SdfPath > prototypes, Span< pxr::VtIntArray > instance_indices, const pxr::VtMatrix4dArray &transforms)
void emit_curves_object(PopulateContext &ctx, const BObjectInfo &info, EmittedObject &emitted)
void DEG_iterator_ids_end(BLI_Iterator *iter)
void DEG_iterator_objects_next(BLI_Iterator *iter)
Main * DEG_get_bmain(const Depsgraph *graph)
BMesh const char void * data
int BKE_object_visibility(const Object *ob, int dag_eval_mode)
void DEG_iterator_ids_next(BLI_Iterator *iter)
void DEG_iterator_objects_end(BLI_Iterator *iter)
eEvaluationMode DEG_get_mode(const Depsgraph *graph)
bool BKE_object_is_visible_in_viewport(const View3D *v3d, const Object *ob)
bool DEG_iterator_dupli_is_visible(const DupliObject *dupli, eEvaluationMode eval_mode)
void DEG_iterator_ids_begin(BLI_Iterator *iter, DEGIDIterData *data)
void DEG_iterator_objects_begin(BLI_Iterator *iter, DEGObjectIterData *data)
Scene * DEG_get_evaluated_scene(const Depsgraph *graph)
pxr::HdContainerDataSourceHandle data_source
pxr::GfMatrix4d geometry_xform
pxr::HdContainerDataSourceHandle base_data_source
pxr::HdContainerDataSourceHandle compose() const
pxr::HdContainerDataSourceHandle xform_overlay
Vector< EmittedObjectPrim > prims
Set< EmittedGeometryKey > used_emitted_geometry
pxr::SdfPath instancer_prim_id() const
Map< const Object *, EmittedObject > new_emitted_objects
void add_instance(const Object *source, const float dupli_mat[4][4])
Set< const Object * > used_instance_sources
Set< pxr::SdfPath > new_paths
pxr::HdRetainedSceneIndex::AddedPrimEntries to_add
Vector< const Material * > new_emitted_materials
Vector< pxr::SdfPath > all_proto_paths
Vector< pxr::VtIntArray > per_proto_indices
const EmittedMaterial * get_or_create_material(const Material *material)
pxr::VtMatrix4dArray instance_transforms
Map< const Object *, IndexRange > proto_range_by_source
Set< const Material * > used_emitted_materials
pxr::HdSceneIndexObserver::DirtiedPrimEntries to_dirty
void emit_prim(const pxr::SdfPath &path, const pxr::TfToken &type, const pxr::HdContainerDataSourceHandle &ds)