1 | |
2 | // |
3 | // This source file is part of appleseed. |
4 | // Visit http://appleseedhq.net/ for additional information and resources. |
5 | // |
6 | // This software is released under the MIT license. |
7 | // |
8 | // Copyright (c) 2010-2013 Francois Beaune, Jupiter Jazz Limited |
9 | // Copyright (c) 2014-2017 Francois Beaune, The appleseedhq Organization |
10 | // |
11 | // Permission is hereby granted, free of charge, to any person obtaining a copy |
12 | // of this software and associated documentation files (the "Software"), to deal |
13 | // in the Software without restriction, including without limitation the rights |
14 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
15 | // copies of the Software, and to permit persons to whom the Software is |
16 | // furnished to do so, subject to the following conditions: |
17 | // |
18 | // The above copyright notice and this permission notice shall be included in |
19 | // all copies or substantial portions of the Software. |
20 | // |
21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
27 | // THE SOFTWARE. |
28 | // |
29 | |
30 | #ifndef APPLESEED_RENDERER_MODELING_ENTITY_ENTITY_H |
31 | #define APPLESEED_RENDERER_MODELING_ENTITY_ENTITY_H |
32 | |
33 | // appleseed.renderer headers. |
34 | #include "renderer/utility/paramarray.h" |
35 | |
36 | // appleseed.foundation headers. |
37 | #include "foundation/core/concepts/iunknown.h" |
38 | #include "foundation/platform/types.h" |
39 | #include "foundation/utility/siphash.h" |
40 | #include "foundation/utility/uid.h" |
41 | #include "foundation/utility/version.h" |
42 | |
43 | // appleseed.main headers. |
44 | #include "main/dllsymbol.h" |
45 | |
46 | // Standard headers. |
47 | #include <cstddef> |
48 | #include <string> |
49 | |
50 | // Forward declarations. |
51 | namespace foundation { class APIString; } |
52 | namespace foundation { class IAbortSwitch; } |
53 | namespace foundation { class StringArray; } |
54 | namespace foundation { class StringDictionary; } |
55 | namespace renderer { class BaseGroup; } |
56 | namespace renderer { class OnFrameBeginRecorder; } |
57 | namespace renderer { class Project; } |
58 | |
59 | namespace renderer |
60 | { |
61 | |
62 | // |
63 | // Base class for all entities in the scene. |
64 | // |
65 | |
66 | class APPLESEED_DLLSYMBOL Entity |
67 | : public foundation::Identifiable |
68 | , public foundation::Versionable |
69 | , public foundation::IUnknown |
70 | { |
71 | public: |
72 | // Constructors. |
73 | explicit Entity( |
74 | const foundation::UniqueID class_uid); |
75 | Entity( |
76 | const foundation::UniqueID class_uid, |
77 | Entity* parent); |
78 | Entity( |
79 | const foundation::UniqueID class_uid, |
80 | const ParamArray& params); |
81 | Entity( |
82 | const foundation::UniqueID class_uid, |
83 | Entity* parent, |
84 | const ParamArray& params); |
85 | |
86 | // Return the unique ID of this class of entities. |
87 | foundation::UniqueID get_class_uid() const; |
88 | |
89 | // Compute and return the unique signature of this entity instance. |
90 | virtual foundation::uint64 compute_signature() const; |
91 | |
92 | // Combine two entity signatures. |
93 | static foundation::uint64 combine_signatures( |
94 | const foundation::uint64 s1, |
95 | const foundation::uint64 s2); |
96 | |
97 | // Set/get the parent of this entity. |
98 | void set_parent(Entity* parent); |
99 | Entity* get_parent() const; |
100 | |
101 | // Set/get the name of this entity. |
102 | void set_name(const char* name); |
103 | const char* get_name() const; |
104 | |
105 | // Get the full path from the scene entity to this entity in a human-readable format. |
106 | foundation::APIString get_path() const; |
107 | |
108 | // Return the parameters of this entity. |
109 | ParamArray& get_parameters(); |
110 | const ParamArray& get_parameters() const; |
111 | |
112 | // Expose asset file paths referenced by this entity to the outside. |
113 | virtual void collect_asset_paths(foundation::StringArray& paths) const; |
114 | virtual void update_asset_paths(const foundation::StringDictionary& mappings); |
115 | |
116 | // Set/get the index of the render layer for this entity. |
117 | // Use ~0 to disable render layer assignment. |
118 | void set_render_layer_index(const size_t render_layer); |
119 | size_t get_render_layer_index() const; |
120 | |
121 | // This method is called once before rendering each frame. |
122 | // Returns true on success, false otherwise. |
123 | virtual bool on_frame_begin( |
124 | const Project& project, |
125 | const BaseGroup* parent, |
126 | OnFrameBeginRecorder& recorder, |
127 | foundation::IAbortSwitch* abort_switch = 0); |
128 | |
129 | // This method is called once after rendering each frame (only if on_frame_begin() was called). |
130 | virtual void on_frame_end( |
131 | const Project& project, |
132 | const BaseGroup* parent); |
133 | |
134 | protected: |
135 | struct Impl; |
136 | Impl* impl; |
137 | |
138 | const foundation::UniqueID m_class_uid; |
139 | Entity* m_parent; |
140 | ParamArray m_params; |
141 | size_t m_render_layer; |
142 | |
143 | // Destructor. |
144 | ~Entity(); |
145 | }; |
146 | |
147 | |
148 | // |
149 | // Entity class implementation. |
150 | // |
151 | |
152 | inline foundation::UniqueID Entity::get_class_uid() const |
153 | { |
154 | return m_class_uid; |
155 | } |
156 | |
157 | inline foundation::uint64 Entity::compute_signature() const |
158 | { |
159 | return foundation::siphash24(get_uid(), get_version_id()); |
160 | } |
161 | |
162 | inline foundation::uint64 Entity::combine_signatures( |
163 | const foundation::uint64 s1, |
164 | const foundation::uint64 s2) |
165 | { |
166 | return foundation::siphash24(s1, s2); |
167 | } |
168 | |
169 | inline void Entity::set_parent(Entity* parent) |
170 | { |
171 | m_parent = parent; |
172 | } |
173 | |
174 | inline Entity* Entity::get_parent() const |
175 | { |
176 | return m_parent; |
177 | } |
178 | |
179 | inline ParamArray& Entity::get_parameters() |
180 | { |
181 | return m_params; |
182 | } |
183 | |
184 | inline const ParamArray& Entity::get_parameters() const |
185 | { |
186 | return m_params; |
187 | } |
188 | |
189 | inline void Entity::set_render_layer_index(const size_t render_layer) |
190 | { |
191 | m_render_layer = render_layer; |
192 | } |
193 | |
194 | inline size_t Entity::get_render_layer_index() const |
195 | { |
196 | return m_render_layer; |
197 | } |
198 | |
199 | } // namespace renderer |
200 | |
201 | #endif // !APPLESEED_RENDERER_MODELING_ENTITY_ENTITY_H |
202 | |