Blender V5.0
hydra_scene_delegate.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
7#include <pxr/base/gf/vec2f.h>
8#include <pxr/imaging/hd/sceneDelegate.h>
9
10#include "DEG_depsgraph.hh"
11
12#include "CLG_log.h"
13
14#include "curves.hh"
15#include "instancer.hh"
16#include "light.hh"
17#include "mesh.hh"
18#include "object.hh"
19#include "volume.hh"
20#include "world.hh"
21
22struct Depsgraph;
23struct Main;
24struct Scene;
25struct View3D;
26
27namespace blender::io::hydra {
28
29extern struct CLG_LogRef *LOG_HYDRA_SCENE;
30
31class Engine;
32class CameraDelegate;
33
34class HydraSceneDelegate : public pxr::HdSceneDelegate {
35 friend ObjectData; /* has access to materials */
36 friend MaterialData; /* has access to objects and instancers */
37
38 public:
40 bool use_scene_lights = true;
41 bool use_scene_world = true;
42 std::string studiolight_name;
45
46 bool operator==(const ShadingSettings &other) const;
47 };
48
49 Depsgraph *depsgraph = nullptr;
50 const View3D *view3d = nullptr;
51 Main *bmain = nullptr;
52 Scene *scene = nullptr;
53
55 bool use_materialx = true;
56
57 private:
58 ObjectDataMap objects_;
59 MaterialDataMap materials_;
60 std::unique_ptr<InstancerData> instancer_data_;
61 std::unique_ptr<WorldData> world_data_;
62
63 CameraDelegate *camera_delegate_ = nullptr;
64
65 public:
66 HydraSceneDelegate(pxr::HdRenderIndex *parent_index,
67 pxr::SdfPath const &delegate_id,
68 CameraDelegate *camera_delegate,
69 bool use_materialx);
70 ~HydraSceneDelegate() override = default;
71
72 /* Delegate methods */
73 pxr::HdMeshTopology GetMeshTopology(pxr::SdfPath const &id) override;
74 pxr::HdBasisCurvesTopology GetBasisCurvesTopology(pxr::SdfPath const &id) override;
75 pxr::GfMatrix4d GetTransform(pxr::SdfPath const &id) override;
76 pxr::VtValue Get(pxr::SdfPath const &id, pxr::TfToken const &key) override;
77 pxr::VtValue GetLightParamValue(pxr::SdfPath const &id, pxr::TfToken const &key) override;
78 pxr::HdPrimvarDescriptorVector GetPrimvarDescriptors(
79 pxr::SdfPath const &id, pxr::HdInterpolation interpolation) override;
80 pxr::SdfPath GetMaterialId(pxr::SdfPath const &rprim_id) override;
81 pxr::VtValue GetMaterialResource(pxr::SdfPath const &material_id) override;
82 bool GetVisible(pxr::SdfPath const &id) override;
83 bool GetDoubleSided(pxr::SdfPath const &id) override;
84 pxr::HdCullStyle GetCullStyle(pxr::SdfPath const &id) override;
85 pxr::SdfPath GetInstancerId(pxr::SdfPath const &prim_id) override;
86 pxr::SdfPathVector GetInstancerPrototypes(pxr::SdfPath const &instancer_id) override;
87 pxr::VtIntArray GetInstanceIndices(pxr::SdfPath const &instancer_id,
88 pxr::SdfPath const &prototype_id) override;
89 pxr::GfMatrix4d GetInstancerTransform(pxr::SdfPath const &instancer_id) override;
90 pxr::HdVolumeFieldDescriptorVector GetVolumeFieldDescriptors(
91 pxr::SdfPath const &volume_id) override;
92
93 void populate(Depsgraph *depsgraph, View3D *v3d);
94 void clear();
95
96 private:
97 pxr::SdfPath prim_id(const ID *id, const char *prefix) const;
98 pxr::SdfPath object_prim_id(const Object *object) const;
99 pxr::SdfPath material_prim_id(const Material *mat) const;
100 pxr::SdfPath hair_prim_id(Object *parent_obj, const ParticleSystem *psys) const;
101 pxr::SdfPath instancer_prim_id() const;
102 pxr::SdfPath world_prim_id() const;
103
104 ObjectData *object_data(pxr::SdfPath const &id) const;
105 MeshData *mesh_data(pxr::SdfPath const &id) const;
106 CurvesData *curves_data(pxr::SdfPath const &id) const;
107 VolumeData *volume_data(pxr::SdfPath const &id) const;
108 LightData *light_data(pxr::SdfPath const &id) const;
109 MaterialData *material_data(pxr::SdfPath const &id) const;
110 HairData *hair_data(pxr::SdfPath const &id) const;
111 InstancerData *instancer_data(pxr::SdfPath const &id, bool child_id = false) const;
112
113 void check_updates();
114 void update_collection();
115 bool set_light_shading_settings();
116 bool set_world_shading_settings();
117};
118
119} // namespace blender::io::hydra
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
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
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
HydraSceneDelegate(pxr::HdRenderIndex *parent_index, pxr::SdfPath const &delegate_id, CameraDelegate *camera_delegate, bool use_materialx)
bool GetDoubleSided(pxr::SdfPath const &id) override
struct CLG_LogRef * LOG_HYDRA_SCENE
Map< pxr::SdfPath, std::unique_ptr< MaterialData > > MaterialDataMap
Definition material.hh:41
Map< pxr::SdfPath, std::unique_ptr< ObjectData > > ObjectDataMap
Definition object.hh:52
Definition DNA_ID.h:414
bool operator==(const ShadingSettings &other) const