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) 2014-2018 Srinath Ravichandran, 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 #pragma once
30 
31 // appleseed.renderer headers.
32 #include "renderer/global/globaltypes.h"
33 #include "renderer/kernel/intersection/intersectionsettings.h"
34 #include "renderer/modeling/object/iobjectfactory.h"
35 #include "renderer/modeling/object/object.h"
36 
37 // appleseed.foundation headers.
38 #include "foundation/curve/curvebasis.h"
39 #include "foundation/platform/compiler.h"
40 #include "foundation/utility/autoreleaseptr.h"
41 
42 // appleseed.main headers.
43 #include "main/dllsymbol.h"
44 
45 // Standard headers.
46 #include <cstddef>
47 
48 // Forward declarations.
49 namespace foundation    { class Dictionary; }
50 namespace foundation    { class DictionaryArray; }
51 namespace foundation    { class SearchPaths; }
52 namespace foundation    { class StringArray; }
53 namespace foundation    { class StringDictionary; }
54 namespace renderer      { class ParamArray; }
55 
56 namespace renderer
57 {
58 
59 //
60 // Curve object (source geometry).
61 //
62 
63 class APPLESEED_DLLSYMBOL CurveObject
64   : public Object
65 {
66   public:
67     // Delete this instance.
68     void release() override;
69 
70     // Return a string identifying the model of this object.
71     const char* get_model() const override;
72 
73     // Compute the local space bounding box of the object over the shutter interval.
74     GAABB3 compute_local_bbox() const override;
75 
76     // Insert and access curve basis.
77     void push_basis(const foundation::CurveBasis basis);
78     foundation::CurveBasis get_basis() const;
79 
80     // Insert and access total number of curves.
81     void push_curve_count(const size_t count);
82     size_t get_curve_count() const;
83 
84     // Insert and access curves.
85     void reserve_curves1(const size_t count);
86     void reserve_curves3(const size_t count);
87     size_t push_curve1(const Curve1Type& curve);
88     size_t push_curve3(const Curve3Type& curve);
89     size_t get_curve1_count() const;
90     size_t get_curve3_count() const;
91     const Curve1Type& get_curve1(const size_t index) const;
92     const Curve3Type& get_curve3(const size_t index) const;
93 
94     // Insert and access material slots.
95     size_t get_material_slot_count() const override;
96     const char* get_material_slot(const size_t index) const override;
97 
98     // Expose asset file paths referenced by this entity to the outside.
99     void collect_asset_paths(foundation::StringArray& paths) const override;
100     void update_asset_paths(const foundation::StringDictionary& mappings) override;
101 
102   private:
103     friend class CurveObjectFactory;
104 
105     struct Impl;
106     Impl* impl;
107 
108     // Constructor.
109     CurveObject(
110         const char*         name,
111         const ParamArray&   params);
112 
113     // Destructor.
114     ~CurveObject() override;
115 };
116 
117 
118 //
119 // Curve object factory.
120 //
121 
122 class APPLESEED_DLLSYMBOL CurveObjectFactory
123   : public IObjectFactory
124 {
125   public:
126     // Delete this instance.
127     void release() override;
128 
129     // Return a string identifying this object model.
130     const char* get_model() const override;
131 
132     // Return metadata for this object model.
133     foundation::Dictionary get_model_metadata() const override;
134 
135     // Return metadata for the inputs of this object model.
136     foundation::DictionaryArray get_input_metadata() const override;
137 
138     // Create a new single empty object.
139     foundation::auto_release_ptr<Object> create(
140         const char*                     name,
141         const ParamArray&               params) const override;
142 
143     // Create objects, potentially from external assets.
144     bool create(
145         const char*                     name,
146         const ParamArray&               params,
147         const foundation::SearchPaths&  search_paths,
148         const bool                      omit_loading_assets,
149         ObjectArray&                    objects) const override;
150 };
151 
152 }   // namespace renderer
153