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) 2016-2018 Esteban Tovagliari, The appleseedhq Organization
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining a copy
11 // of this software and associated documentation files (the "Software"), to deal
12 // in the Software without restriction, including without limitation the rights
13 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 // copies of the Software, and to permit persons to whom the Software is
15 // furnished to do so, subject to the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be included in
18 // all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 // THE SOFTWARE.
27 //
28 
29 // Interface header.
30 #include "proceduralassembly.h"
31 
32 // appleseed.renderer headers.
33 #include "renderer/global/globallogger.h"
34 
35 // appleseed.foundation headers.
36 #include "foundation/platform/types.h"
37 #include "foundation/utility/api/apistring.h"
38 #include "foundation/utility/string.h"
39 
40 using namespace foundation;
41 
42 namespace renderer
43 {
44 
45 //
46 // ProceduralAssembly class implementation.
47 //
48 
ProceduralAssembly(const char * name,const ParamArray & params)49 ProceduralAssembly::ProceduralAssembly(
50     const char*         name,
51     const ParamArray&   params)
52   : Assembly(name, params)
53   , m_expanded(false)
54 {
55 }
56 
expand_contents(const Project & project,const Assembly * parent,IAbortSwitch * abort_switch)57 bool ProceduralAssembly::expand_contents(
58     const Project&      project,
59     const Assembly*     parent,
60     IAbortSwitch*       abort_switch)
61 {
62     if (m_expanded)
63         return true;
64 
65     RENDERER_LOG_INFO("expanding procedural assembly \"%s\"...", get_path().c_str());
66 
67     if (!do_expand_contents(project, parent, abort_switch))
68         return false;
69 
70     RENDERER_LOG_INFO(
71         "procedural assembly \"%s\" expanded to the following entities:\n"
72         "  assemblies                    %s\n"
73         "  assembly instances            %s\n"
74         "  bsdfs                         %s\n"
75         "  bssrdfs                       %s\n"
76         "  colors                        %s\n"
77         "  edfs                          %s\n"
78         "  lights                        %s\n"
79         "  materials                     %s\n"
80         "  objects                       %s\n"
81         "  object instances              %s\n"
82         "  shader groups                 %s\n"
83         "  surface shaders               %s\n"
84         "  textures                      %s\n"
85         "  texture instances             %s\n"
86         "  volumes                       %s",
87         get_path().c_str(),
88         pretty_uint(assemblies().size()).c_str(),
89         pretty_uint(assembly_instances().size()).c_str(),
90         pretty_uint(bsdfs().size()).c_str(),
91         pretty_uint(bssrdfs().size()).c_str(),
92         pretty_uint(colors().size()).c_str(),
93         pretty_uint(edfs().size()).c_str(),
94         pretty_uint(lights().size()).c_str(),
95         pretty_uint(materials().size()).c_str(),
96         pretty_uint(objects().size()).c_str(),
97         pretty_uint(object_instances().size()).c_str(),
98         pretty_uint(shader_groups().size()).c_str(),
99         pretty_uint(surface_shaders().size()).c_str(),
100         pretty_uint(textures().size()).c_str(),
101         pretty_uint(texture_instances().size()).c_str(),
102         pretty_uint(volumes().size()).c_str());
103 
104     m_expanded = true;
105 
106     return true;
107 }
108 
swap_contents(Assembly & assembly)109 void ProceduralAssembly::swap_contents(Assembly& assembly)
110 {
111     assemblies().swap(assembly.assemblies());
112     assembly_instances().swap(assembly.assembly_instances());
113     bsdfs().swap(assembly.bsdfs());
114     bssrdfs().swap(assembly.bssrdfs());
115     colors().swap(assembly.colors());
116     edfs().swap(assembly.edfs());
117     lights().swap(assembly.lights());
118     materials().swap(assembly.materials());
119     objects().swap(assembly.objects());
120     object_instances().swap(assembly.object_instances());
121     shader_groups().swap(assembly.shader_groups());
122     surface_shaders().swap(assembly.surface_shaders());
123     textures().swap(assembly.textures());
124     texture_instances().swap(assembly.texture_instances());
125     volumes().swap(assembly.volumes());
126 }
127 
128 }   // namespace renderer
129