miniassimp

view include/miniassimp/material.inl @ 0:879c81d94345

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