Blender V5.3
scene_index.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
7#include <memory>
8
9#include <pxr/base/tf/declarePtrs.h>
10#include <pxr/base/tf/token.h>
11#include <pxr/imaging/hd/dataSource.h>
12#include <pxr/imaging/hd/retainedSceneIndex.h>
13#include <pxr/usd/sdf/path.h>
14#include <pxr/usd/usd/stage.h>
15
16PXR_NAMESPACE_OPEN_SCOPE
17class HdRenderDelegate;
18PXR_NAMESPACE_CLOSE_SCOPE
19
20#include "BLI_map.hh"
21#include "BLI_set.hh"
22#include "BLI_vector.hh"
23
24#include "CLG_log.h"
25
26#include "util.hh"
27#include "world.hh"
28
29namespace blender {
30
31struct Depsgraph;
32struct ID;
33struct Main;
34struct Material;
35struct Object;
36struct Scene;
37struct View3D;
38
39namespace io::hydra {
40
41extern CLG_LogRef *LOG_HYDRA_SCENE_INDEX;
42
43/* Distinguishes different geometry types emitted from the same ID. */
45 const ID *id;
46 pxr::TfToken type;
47
48 uint64_t hash() const;
49 friend bool operator==(const EmittedGeometryKey &a, const EmittedGeometryKey &b)
50 {
51 return a.id == b.id && a.type == b.type;
52 }
53};
54
55/* Prim emitted by geometry. */
57 pxr::TfToken schema_token;
58 pxr::HdContainerDataSourceHandle geometry;
59 pxr::HdContainerDataSourceHandle primvars;
60 pxr::HdContainerDataSourceHandle bindings;
61};
62
63/* Emitted geometry, potentially with multiple prims for e.g. submeshes. */
68
69/* Prim emitted by an object. */
71 pxr::SdfPath path;
72 pxr::TfToken type;
73 /* Geometry and material data source. */
74 pxr::HdContainerDataSourceHandle base_data_source;
75 /* Transform overlay that handles the object transform. */
76 pxr::HdContainerDataSourceHandle xform_overlay;
77 /* Transforms that comes from the geometry. Stored separately so
78 * we can efficiently update just the object transform. */
79 pxr::GfMatrix4d geometry_xform = pxr::GfMatrix4d(1.0);
80
81 pxr::HdContainerDataSourceHandle compose() const;
82};
83
84/* Emitted object, potentially producing multiple prims. Also tracks
85 * materials and geometry keys so we know what's in use for cleanup. */
91
92/* Emitted material. */
94 pxr::SdfPath path;
95 pxr::HdContainerDataSourceHandle data_source;
96 bool double_sided = true;
97};
98
99/* #HydraSceneIndex holds the Hydra scene built from the evaluated
100 * Blender scene. Note this is not a subclass of pxr::HdRetainedSceneIndex
101 * as builds with assert have an incompatible ABI on Windows and this
102 * causes a crash when the destructor destroys STL containers. */
104 public:
105 HydraSceneIndex(const pxr::SdfPath &root_path,
106 pxr::HdRenderDelegate *render_delegate,
107 bool use_materialx);
109
110 pxr::HdRetainedSceneIndexRefPtr retained() const
111 {
112 return retained_;
113 }
114
115 /* Walks the depsgraph and publishes the scene to Hydra as a tree of
116 * #HdSceneIndexPrim with typed data sources. */
117 void populate(Depsgraph *depsgraph, View3D *view3d);
118 void clear();
119
120 private:
121 pxr::HdRetainedSceneIndexRefPtr retained_;
122
123 pxr::SdfPath root_path_;
124 pxr::HdRenderDelegate *render_delegate_ = nullptr;
125 bool use_materialx_ = true;
126 std::vector<pxr::TfToken> material_render_contexts_;
127 std::vector<pxr::TfToken> shader_source_types_;
128
129 /* Prim paths currently published, for diffing on each populate(). */
130 Set<pxr::SdfPath> emitted_paths_;
131
132 /* Emitted objects. */
133 Map<const Object *, EmittedObject> emitted_objects_;
134
135 /* Cache of material data sources, keyed by Blender material. */
137
138 /* Cache of geometry data sources shared between objects, composed with
139 * per-Object xform and visibility at emit time. */
141
142 /* Instance geometry for each object, to detect geometry set updates. */
143 Map<const Object *, Vector<const ID *>> instance_geometries_by_object_;
144
145 EmittedWorld emitted_world_;
146
147 bool object_is_supported(const Object *object) const;
148 bool object_is_visible(Depsgraph *depsgraph,
149 const View3D *view3d,
150 const Object *object,
151 int mode) const;
152};
153
154} // namespace io::hydra
155} // namespace blender
pxr::HdRetainedSceneIndexRefPtr retained() const
void populate(Depsgraph *depsgraph, View3D *view3d)
HydraSceneIndex(const pxr::SdfPath &root_path, pxr::HdRenderDelegate *render_delegate, bool use_materialx)
CLG_LogRef * LOG_HYDRA_SCENE_INDEX
BMesh Iterators.
unsigned __int64 uint64_t
Definition BKE_text.h:91
friend bool operator==(const EmittedGeometryKey &a, const EmittedGeometryKey &b)
pxr::HdContainerDataSourceHandle geometry
pxr::HdContainerDataSourceHandle bindings
pxr::HdContainerDataSourceHandle primvars
Vector< EmittedGeometryPrim > prims
Vector< const Material * > materials
pxr::HdContainerDataSourceHandle data_source
pxr::HdContainerDataSourceHandle base_data_source
pxr::HdContainerDataSourceHandle compose() const
pxr::HdContainerDataSourceHandle xform_overlay
Vector< EmittedObjectPrim > prims
Vector< const Material * > materials
Vector< EmittedGeometryKey > geometry_keys