1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
4 
5 Copyright (c) 2006-2017, assimp team
6 
7 All rights reserved.
8 
9 Redistribution and use of this software in source and binary forms,
10 with or without modification, are permitted provided that the
11 following conditions are met:
12 
13 * Redistributions of source code must retain the above
14   copyright notice, this list of conditions and the
15   following disclaimer.
16 
17 * Redistributions in binary form must reproduce the above
18   copyright notice, this list of conditions and the
19   following disclaimer in the documentation and/or other
20   materials provided with the distribution.
21 
22 * Neither the name of the assimp team, nor the names of its
23   contributors may be used to endorse or promote products
24   derived from this software without specific prior
25   written permission of the assimp team.
26 
27 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 
39 ----------------------------------------------------------------------
40 */
41 
42 /** @file  BlenderIntermediate.h
43  *  @brief Internal utility structures for the BlenderLoader. It also serves
44  *    as master include file for the whole (internal) Blender subsystem.
45  */
46 #ifndef INCLUDED_AI_BLEND_INTERMEDIATE_H
47 #define INCLUDED_AI_BLEND_INTERMEDIATE_H
48 
49 #include "BlenderLoader.h"
50 #include "BlenderDNA.h"
51 #include "BlenderScene.h"
52 #include <deque>
53 #include <assimp/material.h>
54 
55 struct aiTexture;
56 
57 namespace Assimp {
58 namespace Blender {
59 
60     // --------------------------------------------------------------------
61     /** Mini smart-array to avoid pulling in even more boost stuff. usable with vector and deque */
62     // --------------------------------------------------------------------
63     template <template <typename,typename> class TCLASS, typename T>
64     struct TempArray    {
65         typedef TCLASS< T*,std::allocator<T*> > mywrap;
66 
TempArrayTempArray67         TempArray() {
68         }
69 
~TempArrayTempArray70         ~TempArray () {
71             for(T* elem : arr) {
72                 delete elem;
73             }
74         }
75 
dismissTempArray76         void dismiss() {
77             arr.clear();
78         }
79 
80         mywrap* operator -> () {
81             return &arr;
82         }
83 
84         operator mywrap& () {
85             return arr;
86         }
87 
88         operator const mywrap& () const {
89             return arr;
90         }
91 
getTempArray92         mywrap& get () {
93             return arr;
94         }
95 
getTempArray96         const mywrap& get () const {
97             return arr;
98         }
99 
100         T* operator[] (size_t idx) const {
101             return arr[idx];
102         }
103 
104         T*& operator[] (size_t idx) {
105             return arr[idx];
106         }
107 
108     private:
109         // no copy semantics
110         void operator= (const TempArray&)  {
111         }
112 
TempArrayTempArray113         TempArray(const TempArray& /*arr*/) {
114         }
115 
116     private:
117         mywrap arr;
118     };
119 
120 #ifdef _MSC_VER
121 #   pragma warning(disable:4351)
122 #endif
123 
124     struct ObjectCompare {
operatorObjectCompare125         bool operator() (const Object* left, const Object* right) const {
126             return ::strncmp(left->id.name, right->id.name, strlen( left->id.name ) ) == 0;
127         }
128     };
129 
130     // When keeping objects in sets, sort them by their name.
131     typedef std::set<const Object*, ObjectCompare> ObjectSet;
132 
133     // --------------------------------------------------------------------
134     /** ConversionData acts as intermediate storage location for
135      *  the various ConvertXXX routines in BlenderImporter.*/
136     // --------------------------------------------------------------------
137     struct ConversionData
138     {
ConversionDataConversionData139         ConversionData(const FileDatabase& db)
140             : sentinel_cnt()
141             , next_texture()
142             , db(db)
143         {}
144 
145         struct ObjectCompare {
operatorConversionData::ObjectCompare146             bool operator() (const Object* left, const Object* right) const {
147                 return ::strncmp( left->id.name, right->id.name, strlen( left->id.name ) ) == 0;
148             }
149         };
150 
151         ObjectSet objects;
152 
153         TempArray <std::vector, aiMesh> meshes;
154         TempArray <std::vector, aiCamera> cameras;
155         TempArray <std::vector, aiLight> lights;
156         TempArray <std::vector, aiMaterial> materials;
157         TempArray <std::vector, aiTexture> textures;
158 
159         // set of all materials referenced by at least one mesh in the scene
160         std::deque< std::shared_ptr< Material > > materials_raw;
161 
162         // counter to name sentinel textures inserted as substitutes for procedural textures.
163         unsigned int sentinel_cnt;
164 
165         // next texture ID for each texture type, respectively
166         unsigned int next_texture[aiTextureType_UNKNOWN+1];
167 
168         // original file data
169         const FileDatabase& db;
170     };
171 #ifdef _MSC_VER
172 #   pragma warning(default:4351)
173 #endif
174 
175 // ------------------------------------------------------------------------------------------------
GetTextureTypeDisplayString(Tex::Type t)176 inline const char* GetTextureTypeDisplayString(Tex::Type t)
177 {
178     switch (t)  {
179     case Tex::Type_CLOUDS       :  return  "Clouds";
180     case Tex::Type_WOOD         :  return  "Wood";
181     case Tex::Type_MARBLE       :  return  "Marble";
182     case Tex::Type_MAGIC        :  return  "Magic";
183     case Tex::Type_BLEND        :  return  "Blend";
184     case Tex::Type_STUCCI       :  return  "Stucci";
185     case Tex::Type_NOISE        :  return  "Noise";
186     case Tex::Type_PLUGIN       :  return  "Plugin";
187     case Tex::Type_MUSGRAVE     :  return  "Musgrave";
188     case Tex::Type_VORONOI      :  return  "Voronoi";
189     case Tex::Type_DISTNOISE    :  return  "DistortedNoise";
190     case Tex::Type_ENVMAP       :  return  "EnvMap";
191     case Tex::Type_IMAGE        :  return  "Image";
192     default:
193         break;
194     }
195     return "<Unknown>";
196 }
197 
198 } // ! Blender
199 } // ! Assimp
200 
201 #endif // ! INCLUDED_AI_BLEND_INTERMEDIATE_H
202