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