object.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. #ifndef __OBJECT_H__
  17. #define __OBJECT_H__
  18. #include "graph/node.h"
  19. #include "render/scene.h"
  20. #include "util/util_array.h"
  21. #include "util/util_boundbox.h"
  22. #include "util/util_param.h"
  23. #include "util/util_transform.h"
  24. #include "util/util_thread.h"
  25. #include "util/util_types.h"
  26. #include "util/util_vector.h"
  27. CCL_NAMESPACE_BEGIN
  28. class Device;
  29. class DeviceScene;
  30. class Mesh;
  31. class ParticleSystem;
  32. class Progress;
  33. class Scene;
  34. struct Transform;
  35. struct UpdateObjectTransformState;
  36. class ObjectManager;
  37. /* Object */
  38. class Object : public Node {
  39. public:
  40. NODE_DECLARE
  41. Mesh *mesh;
  42. Transform tfm;
  43. BoundBox bounds;
  44. uint random_id;
  45. int pass_id;
  46. ustring asset_name;
  47. vector<ParamValue> attributes;
  48. uint visibility;
  49. array<Transform> motion;
  50. bool hide_on_missing_motion;
  51. bool use_holdout;
  52. bool is_shadow_catcher;
  53. float3 dupli_generated;
  54. float2 dupli_uv;
  55. ParticleSystem *particle_system;
  56. int particle_index;
  57. Object();
  58. ~Object();
  59. void tag_update(Scene *scene);
  60. void compute_bounds(bool motion_blur);
  61. void apply_transform(bool apply_to_motion);
  62. /* Convert between normalized -1..1 motion time and index
  63. * in the motion array. */
  64. bool use_motion() const;
  65. float motion_time(int step) const;
  66. int motion_step(float time) const;
  67. void update_motion();
  68. /* Check whether object is traceable and it worth adding it to
  69. * kernel scene.
  70. */
  71. bool is_traceable() const;
  72. /* Combine object's visibility with all possible internal run-time
  73. * determined flags which denotes trace-time visibility.
  74. */
  75. uint visibility_for_tracing() const;
  76. /* Returns the index that is used in the kernel for this object. */
  77. int get_device_index() const;
  78. protected:
  79. /* Specifies the position of the object in scene->objects and
  80. * in the device vectors. Gets set in device_update. */
  81. int index;
  82. friend class ObjectManager;
  83. };
  84. /* Object Manager */
  85. class ObjectManager {
  86. public:
  87. bool need_update;
  88. bool need_flags_update;
  89. ObjectManager();
  90. ~ObjectManager();
  91. void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress);
  92. void device_update_transforms(DeviceScene *dscene, Scene *scene, Progress &progress);
  93. void device_update_flags(Device *device,
  94. DeviceScene *dscene,
  95. Scene *scene,
  96. Progress &progress,
  97. bool bounds_valid = true);
  98. void device_update_mesh_offsets(Device *device, DeviceScene *dscene, Scene *scene);
  99. void device_free(Device *device, DeviceScene *dscene);
  100. void tag_update(Scene *scene);
  101. void apply_static_transforms(DeviceScene *dscene, Scene *scene, Progress &progress);
  102. string get_cryptomatte_objects(Scene *scene);
  103. string get_cryptomatte_assets(Scene *scene);
  104. protected:
  105. void device_update_object_transform(UpdateObjectTransformState *state, Object *ob);
  106. void device_update_object_transform_task(UpdateObjectTransformState *state);
  107. bool device_update_object_transform_pop_work(UpdateObjectTransformState *state,
  108. int *start_index,
  109. int *num_objects);
  110. };
  111. CCL_NAMESPACE_END
  112. #endif /* __OBJECT_H__ */