1
2 //
3 // This source file is part of appleseed.
4 // Visit https://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-2018 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 #pragma once
31
32 // appleseed.renderer headers.
33 #include "renderer/global/globaltypes.h"
34 #include "renderer/modeling/entity/entity.h"
35 #include "renderer/modeling/scene/basegroup.h"
36 #include "renderer/modeling/scene/containers.h"
37 #include "renderer/modeling/scene/iassemblyfactory.h"
38
39 // appleseed.foundation headers.
40 #include "foundation/platform/compiler.h"
41 #include "foundation/utility/api/apiarray.h"
42 #include "foundation/utility/autoreleaseptr.h"
43 #include "foundation/utility/uid.h"
44
45 // appleseed.main headers.
46 #include "main/dllsymbol.h"
47
48 // Standard headers.
49 #include <cassert>
50 #include <cstddef>
51 #include <utility>
52
53 // Forward declarations.
54 namespace foundation { class Dictionary; }
55 namespace foundation { class DictionaryArray; }
56 namespace foundation { class IAbortSwitch; }
57 namespace foundation { class StringArray; }
58 namespace foundation { class StringDictionary; }
59 namespace renderer { class ObjectInstance; }
60 namespace renderer { class OnFrameBeginRecorder; }
61 namespace renderer { class OnRenderBeginRecorder; }
62 namespace renderer { class ParamArray; }
63 namespace renderer { class Project; }
64
65 namespace renderer
66 {
67
68 //
69 // An array of object instances.
70 //
71
72 typedef std::pair<const ObjectInstance*, size_t> IndexedObjectInstance;
73
74 APPLESEED_DECLARE_APIARRAY(IndexedObjectInstanceArray, IndexedObjectInstance);
75
76
77 //
78 // An assembly is either entirely self-contained, or it references colors,
79 // textures and texture instances defined in the parent scene or assembly.
80 //
81
82 class APPLESEED_DLLSYMBOL Assembly
83 : public Entity
84 , public BaseGroup
85 {
86 public:
87 // Return a string identifying the model of this entity.
88 virtual const char* get_model() const;
89
90 // Return the unique ID of this class of entities.
91 static foundation::UniqueID get_class_uid();
92
93 // Delete this instance.
94 void release() override;
95
96 // Access the BSDFs.
97 BSDFContainer& bsdfs() const;
98
99 // Access the BSSRDFs.
100 BSSRDFContainer& bssrdfs() const;
101
102 // Access the EDFs.
103 EDFContainer& edfs() const;
104
105 // Access the surface shaders.
106 SurfaceShaderContainer& surface_shaders() const;
107
108 // Access the materials.
109 MaterialContainer& materials() const;
110
111 // Access the lights.
112 LightContainer& lights() const;
113
114 // Access the objects.
115 ObjectContainer& objects() const;
116
117 // Access the object instances.
118 ObjectInstanceContainer& object_instances() const;
119
120 // Access the volumes.
121 VolumeContainer& volumes() const;
122
123 // Clear the assembly contents.
124 void clear();
125
126 // Compute the local space bounding box of the assembly, including all child assemblies,
127 // over the shutter interval.
128 GAABB3 compute_local_bbox() const;
129
130 // Compute the local space bounding box of this assembly, excluding all child assemblies,
131 // over the shutter interval.
132 GAABB3 compute_non_hierarchical_local_bbox() const;
133
134 // Expose asset file paths referenced by this entity to the outside.
135 void collect_asset_paths(foundation::StringArray& paths) const override;
136 void update_asset_paths(const foundation::StringDictionary& mappings) override;
137
138 bool on_render_begin(
139 const Project& project,
140 const BaseGroup* parent,
141 OnRenderBeginRecorder& recorder,
142 foundation::IAbortSwitch* abort_switch = nullptr) override;
143
144 bool on_frame_begin(
145 const Project& project,
146 const BaseGroup* parent,
147 OnFrameBeginRecorder& recorder,
148 foundation::IAbortSwitch* abort_switch = nullptr) override;
149
150 void on_frame_end(
151 const Project& project,
152 const BaseGroup* parent) override;
153
154 struct RenderData
155 {
156 IndexedObjectInstanceArray m_procedural_object_instances;
157 };
158
159 // Return whether render-time data are available for this entity.
160 bool has_render_data() const;
161
162 // Return render-time data of this entity.
163 // Render-time data are available between on_frame_begin() and on_frame_end() calls.
164 const RenderData& get_render_data() const;
165
166 protected:
167 bool m_has_render_data;
168 RenderData m_render_data;
169
170 // Constructor.
171 Assembly(
172 const char* name,
173 const ParamArray& params);
174
175 // Destructor.
176 ~Assembly() override;
177
178 private:
179 friend class AssemblyFactory;
180
181 struct Impl;
182 Impl* impl;
183 };
184
185
186 //
187 // Assembly factory.
188 //
189
190
191 class APPLESEED_DLLSYMBOL AssemblyFactory
192 : public IAssemblyFactory
193 {
194 public:
195 // Delete this instance.
196 void release() override;
197
198 // Return a string identifying this assembly model.
199 const char* get_model() const override;
200
201 // Return metadata for this assembly model.
202 foundation::Dictionary get_model_metadata() const override;
203
204 // Return metadata for the inputs of this assembly model.
205 foundation::DictionaryArray get_input_metadata() const override;
206
207 // Create a new assembly.
208 foundation::auto_release_ptr<Assembly> create(
209 const char* name,
210 const ParamArray& params = ParamArray()) const override;
211 };
212
213
214 //
215 // Assembly class implementation.
216 //
217
has_render_data()218 inline bool Assembly::has_render_data() const
219 {
220 return m_has_render_data;
221 }
222
get_render_data()223 inline const Assembly::RenderData& Assembly::get_render_data() const
224 {
225 assert(m_has_render_data);
226 return m_render_data;
227 }
228
229 } // namespace renderer
230