Blender  V2.93
object.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __OBJECT_H__
18 #define __OBJECT_H__
19 
20 #include "graph/node.h"
21 
22 /* included as Object::set_particle_system defined through NODE_SOCKET_API does
23  * not select the right Node::set overload as it does not know that ParticleSystem
24  * is a Node */
25 #include "render/particles.h"
26 #include "render/scene.h"
27 
28 #include "util/util_array.h"
29 #include "util/util_boundbox.h"
30 #include "util/util_param.h"
31 #include "util/util_thread.h"
32 #include "util/util_transform.h"
33 #include "util/util_types.h"
34 #include "util/util_vector.h"
35 
37 
38 class Device;
39 class DeviceScene;
40 class Geometry;
41 class ParticleSystem;
42 class Progress;
43 class Scene;
44 struct Transform;
46 class ObjectManager;
47 
48 /* Object */
49 
50 class Object : public Node {
51  public:
53 
54  NODE_SOCKET_API(Geometry *, geometry)
57  NODE_SOCKET_API(uint, random_id)
58  NODE_SOCKET_API(int, pass_id)
60  NODE_SOCKET_API(ustring, asset_name)
61  vector<ParamValue> attributes;
62  NODE_SOCKET_API(uint, visibility)
64  NODE_SOCKET_API(bool, hide_on_missing_motion)
65  NODE_SOCKET_API(bool, use_holdout)
66  NODE_SOCKET_API(bool, is_shadow_catcher)
67  NODE_SOCKET_API(float, shadow_terminator_offset)
68 
69  NODE_SOCKET_API(float3, dupli_generated)
70  NODE_SOCKET_API(float2, dupli_uv)
71 
72  NODE_SOCKET_API(ParticleSystem *, particle_system);
74 
75  Object();
76  ~Object();
77 
78  void tag_update(Scene *scene);
79 
80  void compute_bounds(bool motion_blur);
81  void apply_transform(bool apply_to_motion);
82 
83  /* Convert between normalized -1..1 motion time and index
84  * in the motion array. */
85  bool use_motion() const;
86  float motion_time(int step) const;
87  int motion_step(float time) const;
88  void update_motion();
89 
90  /* Maximum number of motion steps supported (due to Embree). */
91  static const uint MAX_MOTION_STEPS = 129;
92 
93  /* Check whether object is traceable and it worth adding it to
94  * kernel scene.
95  */
96  bool is_traceable() const;
97 
98  /* Combine object's visibility with all possible internal run-time
99  * determined flags which denotes trace-time visibility.
100  */
102 
103  /* Returns the index that is used in the kernel for this object. */
104  int get_device_index() const;
105 
106  /* Compute step size from attributes, shaders, transforms. */
107  float compute_volume_step_size() const;
108 
109  protected:
110  /* Specifies the position of the object in scene->objects and
111  * in the device vectors. Gets set in device_update. */
112  int index;
113 
114  /* Reference to the attribute map with object attributes,
115  * or 0 if none. Set in update_svm_attributes. */
117 
118  friend class ObjectManager;
119  friend class GeometryManager;
120 };
121 
122 /* Object Manager */
123 
125  uint32_t update_flags;
126 
127  public:
128  enum : uint32_t {
129  PARTICLE_MODIFIED = (1 << 0),
130  GEOMETRY_MANAGER = (1 << 1),
131  MOTION_BLUR_MODIFIED = (1 << 2),
132  OBJECT_ADDED = (1 << 3),
133  OBJECT_REMOVED = (1 << 4),
134  OBJECT_MODIFIED = (1 << 5),
135  HOLDOUT_MODIFIED = (1 << 6),
136  TRANSFORM_MODIFIED = (1 << 7),
137  VISIBILITY_MODIFIED = (1 << 8),
138 
139  /* tag everything in the manager for an update */
140  UPDATE_ALL = ~0u,
141 
142  UPDATE_NONE = 0u,
143  };
144 
146 
147  ObjectManager();
148  ~ObjectManager();
149 
150  void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress);
151  void device_update_transforms(DeviceScene *dscene, Scene *scene, Progress &progress);
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_mesh_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);
177  int *start_index,
178  int *num_objects);
179 };
180 
182 
183 #endif /* __OBJECT_H__ */
unsigned int uint
Definition: BLI_sys_types.h:83
Definition: device.h:293
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: object.h:145
double time
Scene scene
ccl_device_inline uint particle_index(KernelGlobals *kg, int particle)
Definition: geom_object.h:363
#define CCL_NAMESPACE_END
static ulong state[N]
#define NODE_SOCKET_API_ARRAY(type_, name)
Definition: node.h:71
#define NODE_DECLARE
Definition: node_type.h:148
unsigned int uint32_t
Definition: stdint.h:83
Definition: node.h:98
void compute_bounds(bool motion_blur)
Definition: object.cpp:154
int motion_step(float time) const
Definition: object.cpp:248
bool use_motion() const
Definition: object.cpp:238
NODE_DECLARE BoundBox bounds
Definition: object.h:56
size_t attr_map_offset
Definition: object.h:116
NODE_SOCKET_API(ParticleSystem *, particle_system)
vector< ParamValue > attributes
Definition: object.h:61
void update_motion()
Definition: object.cpp:119
int get_device_index() const
Definition: object.cpp:369
void apply_transform(bool apply_to_motion)
Definition: object.cpp:185
friend class ObjectManager
Definition: object.h:118
float compute_volume_step_size() const
Definition: object.cpp:283
static const uint MAX_MOTION_STEPS
Definition: object.h:91
bool is_traceable() const
Definition: object.cpp:261
uint visibility_for_tracing() const
Definition: object.cpp:271
void tag_update(Scene *scene)
Definition: object.cpp:206
float color[4]
float motion_time(int step) const
Definition: object.cpp:243