Blender  V3.3
scene/object.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 #ifndef __OBJECT_H__
5 #define __OBJECT_H__
6 
7 #include "graph/node.h"
8 
9 /* included as Object::set_particle_system defined through NODE_SOCKET_API does
10  * not select the right Node::set overload as it does not know that ParticleSystem
11  * is a Node */
12 #include "scene/particles.h"
13 #include "scene/scene.h"
14 
15 #include "util/array.h"
16 #include "util/boundbox.h"
17 #include "util/param.h"
18 #include "util/thread.h"
19 #include "util/transform.h"
20 #include "util/types.h"
21 #include "util/vector.h"
22 
24 
25 class Device;
26 class DeviceScene;
27 class Geometry;
28 class ParticleSystem;
29 class Progress;
30 class Scene;
31 struct Transform;
33 class ObjectManager;
34 
35 /* Object */
36 
37 class Object : public Node {
38  public:
40 
41  NODE_SOCKET_API(Geometry *, geometry)
44  NODE_SOCKET_API(uint, random_id)
45  NODE_SOCKET_API(int, pass_id)
47  NODE_SOCKET_API(float, alpha)
48  NODE_SOCKET_API(ustring, asset_name)
49  vector<ParamValue> attributes;
50  NODE_SOCKET_API(uint, visibility)
52  NODE_SOCKET_API(bool, hide_on_missing_motion)
53  NODE_SOCKET_API(bool, use_holdout)
54  NODE_SOCKET_API(bool, is_shadow_catcher)
55  NODE_SOCKET_API(float, shadow_terminator_shading_offset)
56  NODE_SOCKET_API(float, shadow_terminator_geometry_offset)
57 
58  NODE_SOCKET_API(bool, is_caustics_caster)
59  NODE_SOCKET_API(bool, is_caustics_receiver)
60 
61  NODE_SOCKET_API(float3, dupli_generated)
62  NODE_SOCKET_API(float2, dupli_uv)
63 
64  NODE_SOCKET_API(ParticleSystem *, particle_system);
66 
67  NODE_SOCKET_API(float, ao_distance)
68 
69  NODE_SOCKET_API(ustring, lightgroup)
70 
71  /* Set during device update. */
73 
74  Object();
75  ~Object();
76 
77  void tag_update(Scene *scene);
78 
79  void compute_bounds(bool motion_blur);
80  void apply_transform(bool apply_to_motion);
81 
82  /* Convert between normalized -1..1 motion time and index
83  * in the motion array. */
84  bool use_motion() const;
85  float motion_time(int step) const;
86  int motion_step(float time) const;
87  void update_motion();
88 
89  /* Maximum number of motion steps supported (due to Embree). */
90  static const uint MAX_MOTION_STEPS = 129;
91 
92  /* Check whether object is traceable and it worth adding it to
93  * kernel scene.
94  */
95  bool is_traceable() const;
96 
97  /* Combine object's visibility with all possible internal run-time
98  * determined flags which denotes trace-time visibility.
99  */
101 
102  /* Returns the index that is used in the kernel for this object. */
103  int get_device_index() const;
104 
105  /* Compute step size from attributes, shaders, transforms. */
106  float compute_volume_step_size() const;
107 
108  protected:
109  /* Specifies the position of the object in scene->objects and
110  * in the device vectors. Gets set in device_update. */
111  int index;
112 
113  /* Reference to the attribute map with object attributes,
114  * or 0 if none. Set in update_svm_attributes. */
116 
117  friend class ObjectManager;
118  friend class GeometryManager;
119 };
120 
121 /* Object Manager */
122 
124  uint32_t update_flags;
125 
126  public:
127  enum : uint32_t {
128  PARTICLE_MODIFIED = (1 << 0),
129  GEOMETRY_MANAGER = (1 << 1),
130  MOTION_BLUR_MODIFIED = (1 << 2),
131  OBJECT_ADDED = (1 << 3),
132  OBJECT_REMOVED = (1 << 4),
133  OBJECT_MODIFIED = (1 << 5),
134  HOLDOUT_MODIFIED = (1 << 6),
135  TRANSFORM_MODIFIED = (1 << 7),
136  VISIBILITY_MODIFIED = (1 << 8),
137 
138  /* tag everything in the manager for an update */
139  UPDATE_ALL = ~0u,
140 
141  UPDATE_NONE = 0u,
142  };
143 
145 
146  ObjectManager();
147  ~ObjectManager();
148 
149  void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress);
150  void device_update_transforms(DeviceScene *dscene, Scene *scene, Progress &progress);
151  void device_update_prim_offsets(Device *device, DeviceScene *dscene, Scene *scene);
152 
153  void device_update_flags(Device *device,
154  DeviceScene *dscene,
155  Scene *scene,
156  Progress &progress,
157  bool bounds_valid = true);
158  void device_update_geom_offsets(Device *device, DeviceScene *dscene, Scene *scene);
159 
160  void device_free(Device *device, DeviceScene *dscene, bool force_free);
161 
163 
164  bool need_update() const;
165 
166  void apply_static_transforms(DeviceScene *dscene, Scene *scene, Progress &progress);
167 
168  string get_cryptomatte_objects(Scene *scene);
169  string get_cryptomatte_assets(Scene *scene);
170 
171  protected:
172  void device_update_object_transform(UpdateObjectTransformState *state,
173  Object *ob,
174  bool update_all,
175  const Scene *scene);
178  int *start_index,
179  int *num_objects);
180 };
181 
183 
184 #endif /* __OBJECT_H__ */
unsigned int uint
Definition: BLI_sys_types.h:67
void device_update_object_transform_task(UpdateObjectTransformState *state)
bool device_update_object_transform_pop_work(UpdateObjectTransformState *state, int *start_index, int *num_objects)
bool need_flags_update
Definition: scene/object.h:144
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
double time
Scene scene
#define NODE_SOCKET_API_ARRAY(type_, name)
Definition: graph/node.h:62
const int state
ccl_device_inline uint particle_index(KernelGlobals kg, int particle)
#define NODE_DECLARE
Definition: node_type.h:135
unsigned int uint32_t
Definition: stdint.h:80
void compute_bounds(bool motion_blur)
int motion_step(float time) const
bool use_motion() const
NODE_DECLARE BoundBox bounds
Definition: scene/object.h:43
size_t attr_map_offset
Definition: scene/object.h:115
NODE_SOCKET_API(ParticleSystem *, particle_system)
vector< ParamValue > attributes
Definition: scene/object.h:49
void update_motion()
int get_device_index() const
void apply_transform(bool apply_to_motion)
friend class ObjectManager
Definition: scene/object.h:117
float compute_volume_step_size() const
static const uint MAX_MOTION_STEPS
Definition: scene/object.h:90
bool is_traceable() const
uint visibility_for_tracing() const
void tag_update(Scene *scene)
float color[4]
float motion_time(int step) const
struct LightgroupMembership * lightgroup
bool intersects_volume
Definition: scene/object.h:72