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 #include "render/scene.h" 22 23 #include "util/util_array.h" 24 #include "util/util_boundbox.h" 25 #include "util/util_param.h" 26 #include "util/util_thread.h" 27 #include "util/util_transform.h" 28 #include "util/util_types.h" 29 #include "util/util_vector.h" 30 31 CCL_NAMESPACE_BEGIN 32 33 class Device; 34 class DeviceScene; 35 class Geometry; 36 class ParticleSystem; 37 class Progress; 38 class Scene; 39 struct Transform; 40 struct UpdateObjectTransformState; 41 class ObjectManager; 42 43 /* Object */ 44 45 class Object : public Node { 46 public: 47 NODE_DECLARE 48 49 Geometry *geometry; 50 Transform tfm; 51 BoundBox bounds; 52 uint random_id; 53 int pass_id; 54 float3 color; 55 ustring asset_name; 56 vector<ParamValue> attributes; 57 uint visibility; 58 array<Transform> motion; 59 bool hide_on_missing_motion; 60 bool use_holdout; 61 bool is_shadow_catcher; 62 float shadow_terminator_offset; 63 64 float3 dupli_generated; 65 float2 dupli_uv; 66 67 ParticleSystem *particle_system; 68 int particle_index; 69 70 Object(); 71 ~Object(); 72 73 void tag_update(Scene *scene); 74 75 void compute_bounds(bool motion_blur); 76 void apply_transform(bool apply_to_motion); 77 78 /* Convert between normalized -1..1 motion time and index 79 * in the motion array. */ 80 bool use_motion() const; 81 float motion_time(int step) const; 82 int motion_step(float time) const; 83 void update_motion(); 84 85 /* Maximum number of motion steps supported (due to Embree). */ 86 static const uint MAX_MOTION_STEPS = 129; 87 88 /* Check whether object is traceable and it worth adding it to 89 * kernel scene. 90 */ 91 bool is_traceable() const; 92 93 /* Combine object's visibility with all possible internal run-time 94 * determined flags which denotes trace-time visibility. 95 */ 96 uint visibility_for_tracing() const; 97 98 /* Returns the index that is used in the kernel for this object. */ 99 int get_device_index() const; 100 101 /* Compute step size from attributes, shaders, transforms. */ 102 float compute_volume_step_size() const; 103 104 protected: 105 /* Specifies the position of the object in scene->objects and 106 * in the device vectors. Gets set in device_update. */ 107 int index; 108 109 friend class ObjectManager; 110 }; 111 112 /* Object Manager */ 113 114 class ObjectManager { 115 public: 116 bool need_update; 117 bool need_flags_update; 118 119 ObjectManager(); 120 ~ObjectManager(); 121 122 void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress); 123 void device_update_transforms(DeviceScene *dscene, Scene *scene, Progress &progress); 124 125 void device_update_flags(Device *device, 126 DeviceScene *dscene, 127 Scene *scene, 128 Progress &progress, 129 bool bounds_valid = true); 130 void device_update_mesh_offsets(Device *device, DeviceScene *dscene, Scene *scene); 131 132 void device_free(Device *device, DeviceScene *dscene); 133 134 void tag_update(Scene *scene); 135 136 void apply_static_transforms(DeviceScene *dscene, Scene *scene, Progress &progress); 137 138 string get_cryptomatte_objects(Scene *scene); 139 string get_cryptomatte_assets(Scene *scene); 140 141 protected: 142 void device_update_object_transform(UpdateObjectTransformState *state, Object *ob); 143 void device_update_object_transform_task(UpdateObjectTransformState *state); 144 bool device_update_object_transform_pop_work(UpdateObjectTransformState *state, 145 int *start_index, 146 int *num_objects); 147 }; 148 149 CCL_NAMESPACE_END 150 151 #endif /* __OBJECT_H__ */ 152