1 | /* |
2 | --------------------------------------------------------------------------- |
3 | Open Asset Import Library (assimp) |
4 | --------------------------------------------------------------------------- |
5 | |
6 | Copyright (c) 2006-2017, assimp team |
7 | |
8 | |
9 | All rights reserved. |
10 | |
11 | Redistribution and use of this software in source and binary forms, |
12 | with or without modification, are permitted provided that the following |
13 | conditions are met: |
14 | |
15 | * Redistributions of source code must retain the above |
16 | copyright notice, this list of conditions and the |
17 | following disclaimer. |
18 | |
19 | * Redistributions in binary form must reproduce the above |
20 | copyright notice, this list of conditions and the |
21 | following disclaimer in the documentation and/or other |
22 | materials provided with the distribution. |
23 | |
24 | * Neither the name of the assimp team, nor the names of its |
25 | contributors may be used to endorse or promote products |
26 | derived from this software without specific prior |
27 | written permission of the assimp team. |
28 | |
29 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
30 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
31 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
32 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
33 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
34 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
35 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
36 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
37 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
38 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
39 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
40 | --------------------------------------------------------------------------- |
41 | */ |
42 | |
43 | /** @file material.inl |
44 | * @brief Defines the C++ getters for the material system |
45 | */ |
46 | |
47 | #pragma once |
48 | #ifndef AI_MATERIAL_INL_INC |
49 | #define AI_MATERIAL_INL_INC |
50 | |
51 | // --------------------------------------------------------------------------- |
52 | inline aiPropertyTypeInfo ai_real_to_property_type_info(float) |
53 | { |
54 | return aiPTI_Float; |
55 | } |
56 | |
57 | inline aiPropertyTypeInfo ai_real_to_property_type_info(double) |
58 | { |
59 | return aiPTI_Double; |
60 | } |
61 | // --------------------------------------------------------------------------- |
62 | |
63 | //! @cond never |
64 | |
65 | // --------------------------------------------------------------------------- |
66 | inline aiReturn aiMaterial::GetTexture( aiTextureType type, |
67 | unsigned int index, |
68 | C_STRUCT aiString* path, |
69 | aiTextureMapping* mapping /*= NULL*/, |
70 | unsigned int* uvindex /*= NULL*/, |
71 | ai_real* blend /*= NULL*/, |
72 | aiTextureOp* op /*= NULL*/, |
73 | aiTextureMapMode* mapmode /*= NULL*/) const |
74 | { |
75 | return ::aiGetMaterialTexture(this,type,index,path,mapping,uvindex,blend,op,mapmode); |
76 | } |
77 | |
78 | // --------------------------------------------------------------------------- |
79 | inline unsigned int aiMaterial::GetTextureCount(aiTextureType type) const |
80 | { |
81 | return ::aiGetMaterialTextureCount(this,type); |
82 | } |
83 | |
84 | // --------------------------------------------------------------------------- |
85 | template <typename Type> |
86 | inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type, |
87 | unsigned int idx, Type* pOut, |
88 | unsigned int* pMax) const |
89 | { |
90 | unsigned int iNum = pMax ? *pMax : 1; |
91 | |
92 | const aiMaterialProperty* prop; |
93 | const aiReturn ret = ::aiGetMaterialProperty(this,pKey,type,idx, |
94 | (const aiMaterialProperty**)&prop); |
95 | if ( AI_SUCCESS == ret ) { |
96 | |
97 | if (prop->mDataLength < sizeof(Type)*iNum) { |
98 | return AI_FAILURE; |
99 | } |
100 | |
101 | if (prop->mType != aiPTI_Buffer) { |
102 | return AI_FAILURE; |
103 | } |
104 | |
105 | iNum = std::min((size_t)iNum,prop->mDataLength / sizeof(Type)); |
106 | ::memcpy(pOut,prop->mData,iNum * sizeof(Type)); |
107 | if (pMax) { |
108 | *pMax = iNum; |
109 | } |
110 | } |
111 | return ret; |
112 | } |
113 | |
114 | // --------------------------------------------------------------------------- |
115 | template <typename Type> |
116 | inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type, |
117 | unsigned int idx,Type& pOut) const |
118 | { |
119 | const aiMaterialProperty* prop; |
120 | const aiReturn ret = ::aiGetMaterialProperty(this,pKey,type,idx, |
121 | (const aiMaterialProperty**)&prop); |
122 | if ( AI_SUCCESS == ret ) { |
123 | |
124 | if (prop->mDataLength < sizeof(Type)) { |
125 | return AI_FAILURE; |
126 | } |
127 | |
128 | if (prop->mType != aiPTI_Buffer) { |
129 | return AI_FAILURE; |
130 | } |
131 | |
132 | ::memcpy(&pOut,prop->mData,sizeof(Type)); |
133 | } |
134 | return ret; |
135 | } |
136 | |
137 | // --------------------------------------------------------------------------- |
138 | inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type, |
139 | unsigned int idx,ai_real* pOut, |
140 | unsigned int* pMax) const |
141 | { |
142 | return ::aiGetMaterialFloatArray(this,pKey,type,idx,pOut,pMax); |
143 | } |
144 | // --------------------------------------------------------------------------- |
145 | inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type, |
146 | unsigned int idx,int* pOut, |
147 | unsigned int* pMax) const |
148 | { |
149 | return ::aiGetMaterialIntegerArray(this,pKey,type,idx,pOut,pMax); |
150 | } |
151 | // --------------------------------------------------------------------------- |
152 | inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type, |
153 | unsigned int idx,ai_real& pOut) const |
154 | { |
155 | return aiGetMaterialFloat(this,pKey,type,idx,&pOut); |
156 | } |
157 | // --------------------------------------------------------------------------- |
158 | inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type, |
159 | unsigned int idx,int& pOut) const |
160 | { |
161 | return aiGetMaterialInteger(this,pKey,type,idx,&pOut); |
162 | } |
163 | // --------------------------------------------------------------------------- |
164 | inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type, |
165 | unsigned int idx,aiColor4D& pOut) const |
166 | { |
167 | return aiGetMaterialColor(this,pKey,type,idx,&pOut); |
168 | } |
169 | // --------------------------------------------------------------------------- |
170 | inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type, |
171 | unsigned int idx,aiColor3D& pOut) const |
172 | { |
173 | aiColor4D c; |
174 | const aiReturn ret = aiGetMaterialColor(this,pKey,type,idx,&c); |
175 | pOut = aiColor3D(c.r,c.g,c.b); |
176 | return ret; |
177 | } |
178 | // --------------------------------------------------------------------------- |
179 | inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type, |
180 | unsigned int idx,aiString& pOut) const |
181 | { |
182 | return aiGetMaterialString(this,pKey,type,idx,&pOut); |
183 | } |
184 | // --------------------------------------------------------------------------- |
185 | inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type, |
186 | unsigned int idx,aiUVTransform& pOut) const |
187 | { |
188 | return aiGetMaterialUVTransform(this,pKey,type,idx,&pOut); |
189 | } |
190 | |
191 | |
192 | // --------------------------------------------------------------------------- |
193 | template<class TYPE> |
194 | aiReturn aiMaterial::AddProperty (const TYPE* pInput, |
195 | const unsigned int pNumValues, |
196 | const char* pKey, |
197 | unsigned int type, |
198 | unsigned int index) |
199 | { |
200 | return AddBinaryProperty((const void*)pInput, |
201 | pNumValues * sizeof(TYPE), |
202 | pKey,type,index,aiPTI_Buffer); |
203 | } |
204 | |
205 | // --------------------------------------------------------------------------- |
206 | inline aiReturn aiMaterial::AddProperty(const float* pInput, |
207 | const unsigned int pNumValues, |
208 | const char* pKey, |
209 | unsigned int type, |
210 | unsigned int index) |
211 | { |
212 | return AddBinaryProperty((const void*)pInput, |
213 | pNumValues * sizeof(float), |
214 | pKey,type,index,aiPTI_Float); |
215 | } |
216 | |
217 | // --------------------------------------------------------------------------- |
218 | inline aiReturn aiMaterial::AddProperty(const double* pInput, |
219 | const unsigned int pNumValues, |
220 | const char* pKey, |
221 | unsigned int type, |
222 | unsigned int index) |
223 | { |
224 | return AddBinaryProperty((const void*)pInput, |
225 | pNumValues * sizeof(double), |
226 | pKey,type,index,aiPTI_Double); |
227 | } |
228 | |
229 | // --------------------------------------------------------------------------- |
230 | inline aiReturn aiMaterial::AddProperty(const aiUVTransform* pInput, |
231 | const unsigned int pNumValues, |
232 | const char* pKey, |
233 | unsigned int type, |
234 | unsigned int index) |
235 | { |
236 | return AddBinaryProperty((const void*)pInput, |
237 | pNumValues * sizeof(aiUVTransform), |
238 | pKey,type,index,ai_real_to_property_type_info(pInput->mRotation)); |
239 | } |
240 | |
241 | // --------------------------------------------------------------------------- |
242 | inline aiReturn aiMaterial::AddProperty(const aiColor4D* pInput, |
243 | const unsigned int pNumValues, |
244 | const char* pKey, |
245 | unsigned int type, |
246 | unsigned int index) |
247 | { |
248 | return AddBinaryProperty((const void*)pInput, |
249 | pNumValues * sizeof(aiColor4D), |
250 | pKey,type,index,ai_real_to_property_type_info(pInput->a)); |
251 | } |
252 | |
253 | // --------------------------------------------------------------------------- |
254 | inline aiReturn aiMaterial::AddProperty(const aiColor3D* pInput, |
255 | const unsigned int pNumValues, |
256 | const char* pKey, |
257 | unsigned int type, |
258 | unsigned int index) |
259 | { |
260 | return AddBinaryProperty((const void*)pInput, |
261 | pNumValues * sizeof(aiColor3D), |
262 | pKey,type,index,ai_real_to_property_type_info(pInput->b)); |
263 | } |
264 | |
265 | // --------------------------------------------------------------------------- |
266 | inline aiReturn aiMaterial::AddProperty(const aiVector3D* pInput, |
267 | const unsigned int pNumValues, |
268 | const char* pKey, |
269 | unsigned int type, |
270 | unsigned int index) |
271 | { |
272 | return AddBinaryProperty((const void*)pInput, |
273 | pNumValues * sizeof(aiVector3D), |
274 | pKey,type,index,ai_real_to_property_type_info(pInput->x)); |
275 | } |
276 | |
277 | // --------------------------------------------------------------------------- |
278 | inline aiReturn aiMaterial::AddProperty(const int* pInput, |
279 | const unsigned int pNumValues, |
280 | const char* pKey, |
281 | unsigned int type, |
282 | unsigned int index) |
283 | { |
284 | return AddBinaryProperty((const void*)pInput, |
285 | pNumValues * sizeof(int), |
286 | pKey,type,index,aiPTI_Integer); |
287 | } |
288 | |
289 | |
290 | // --------------------------------------------------------------------------- |
291 | // The template specializations below are for backwards compatibility. |
292 | // The recommended way to add material properties is using the non-template |
293 | // overloads. |
294 | // --------------------------------------------------------------------------- |
295 | |
296 | // --------------------------------------------------------------------------- |
297 | template<> |
298 | inline aiReturn aiMaterial::AddProperty<float>(const float* pInput, |
299 | const unsigned int pNumValues, |
300 | const char* pKey, |
301 | unsigned int type, |
302 | unsigned int index) |
303 | { |
304 | return AddBinaryProperty((const void*)pInput, |
305 | pNumValues * sizeof(float), |
306 | pKey,type,index,aiPTI_Float); |
307 | } |
308 | |
309 | // --------------------------------------------------------------------------- |
310 | template<> |
311 | inline aiReturn aiMaterial::AddProperty<double>(const double* pInput, |
312 | const unsigned int pNumValues, |
313 | const char* pKey, |
314 | unsigned int type, |
315 | unsigned int index) |
316 | { |
317 | return AddBinaryProperty((const void*)pInput, |
318 | pNumValues * sizeof(double), |
319 | pKey,type,index,aiPTI_Double); |
320 | } |
321 | |
322 | // --------------------------------------------------------------------------- |
323 | template<> |
324 | inline aiReturn aiMaterial::AddProperty<aiUVTransform>(const aiUVTransform* pInput, |
325 | const unsigned int pNumValues, |
326 | const char* pKey, |
327 | unsigned int type, |
328 | unsigned int index) |
329 | { |
330 | return AddBinaryProperty((const void*)pInput, |
331 | pNumValues * sizeof(aiUVTransform), |
332 | pKey,type,index,aiPTI_Float); |
333 | } |
334 | |
335 | // --------------------------------------------------------------------------- |
336 | template<> |
337 | inline aiReturn aiMaterial::AddProperty<aiColor4D>(const aiColor4D* pInput, |
338 | const unsigned int pNumValues, |
339 | const char* pKey, |
340 | unsigned int type, |
341 | unsigned int index) |
342 | { |
343 | return AddBinaryProperty((const void*)pInput, |
344 | pNumValues * sizeof(aiColor4D), |
345 | pKey,type,index,aiPTI_Float); |
346 | } |
347 | |
348 | // --------------------------------------------------------------------------- |
349 | template<> |
350 | inline aiReturn aiMaterial::AddProperty<aiColor3D>(const aiColor3D* pInput, |
351 | const unsigned int pNumValues, |
352 | const char* pKey, |
353 | unsigned int type, |
354 | unsigned int index) |
355 | { |
356 | return AddBinaryProperty((const void*)pInput, |
357 | pNumValues * sizeof(aiColor3D), |
358 | pKey,type,index,aiPTI_Float); |
359 | } |
360 | |
361 | // --------------------------------------------------------------------------- |
362 | template<> |
363 | inline aiReturn aiMaterial::AddProperty<aiVector3D>(const aiVector3D* pInput, |
364 | const unsigned int pNumValues, |
365 | const char* pKey, |
366 | unsigned int type, |
367 | unsigned int index) |
368 | { |
369 | return AddBinaryProperty((const void*)pInput, |
370 | pNumValues * sizeof(aiVector3D), |
371 | pKey,type,index,aiPTI_Float); |
372 | } |
373 | |
374 | // --------------------------------------------------------------------------- |
375 | template<> |
376 | inline aiReturn aiMaterial::AddProperty<int>(const int* pInput, |
377 | const unsigned int pNumValues, |
378 | const char* pKey, |
379 | unsigned int type, |
380 | unsigned int index) |
381 | { |
382 | return AddBinaryProperty((const void*)pInput, |
383 | pNumValues * sizeof(int), |
384 | pKey,type,index,aiPTI_Integer); |
385 | } |
386 | |
387 | //! @endcond |
388 | |
389 | #endif //! AI_MATERIAL_INL_INC |
390 | |