vrshoot

view libs/assimp/assimp/material.inl @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line source
1 /*
2 ---------------------------------------------------------------------------
3 Open Asset Import Library (assimp)
4 ---------------------------------------------------------------------------
6 Copyright (c) 2006-2012, assimp team
8 All rights reserved.
10 Redistribution and use of this software in source and binary forms,
11 with or without modification, are permitted provided that the following
12 conditions are met:
14 * Redistributions of source code must retain the above
15 copyright notice, this list of conditions and the
16 following disclaimer.
18 * Redistributions in binary form must reproduce the above
19 copyright notice, this list of conditions and the
20 following disclaimer in the documentation and/or other
21 materials provided with the distribution.
23 * Neither the name of the assimp team, nor the names of its
24 contributors may be used to endorse or promote products
25 derived from this software without specific prior
26 written permission of the assimp team.
28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 ---------------------------------------------------------------------------
40 */
42 /** @file aiMaterial.inl
43 * @brief Defines the C++ getters for the material system
44 */
46 #ifndef AI_MATERIAL_INL_INC
47 #define AI_MATERIAL_INL_INC
49 //! @cond never
51 // ---------------------------------------------------------------------------
52 inline aiReturn aiMaterial::GetTexture( aiTextureType type,
53 unsigned int index,
54 C_STRUCT aiString* path,
55 aiTextureMapping* mapping /*= NULL*/,
56 unsigned int* uvindex /*= NULL*/,
57 float* blend /*= NULL*/,
58 aiTextureOp* op /*= NULL*/,
59 aiTextureMapMode* mapmode /*= NULL*/) const
60 {
61 return ::aiGetMaterialTexture(this,type,index,path,mapping,uvindex,blend,op,mapmode);
62 }
64 // ---------------------------------------------------------------------------
65 inline unsigned int aiMaterial::GetTextureCount(aiTextureType type) const
66 {
67 return ::aiGetMaterialTextureCount(this,type);
68 }
70 // ---------------------------------------------------------------------------
71 template <typename Type>
72 inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type,
73 unsigned int idx, Type* pOut,
74 unsigned int* pMax) const
75 {
76 unsigned int iNum = pMax ? *pMax : 1;
78 const aiMaterialProperty* prop;
79 const aiReturn ret = ::aiGetMaterialProperty(this,pKey,type,idx,
80 (const aiMaterialProperty**)&prop);
81 if ( AI_SUCCESS == ret ) {
83 if (prop->mDataLength < sizeof(Type)*iNum) {
84 return AI_FAILURE;
85 }
87 if (prop->mType != aiPTI_Buffer) {
88 return AI_FAILURE;
89 }
91 iNum = std::min((size_t)iNum,prop->mDataLength / sizeof(Type));
92 memcpy(pOut,prop->mData,iNum * sizeof(Type));
93 if (pMax) {
94 *pMax = iNum;
95 }
96 }
97 return ret;
98 }
100 // ---------------------------------------------------------------------------
101 template <typename Type>
102 inline aiReturn aiMaterial::Get(const char* pKey,unsigned int type,
103 unsigned int idx,Type& pOut) const
104 {
105 const aiMaterialProperty* prop;
106 const aiReturn ret = ::aiGetMaterialProperty(this,pKey,type,idx,
107 (const aiMaterialProperty**)&prop);
108 if ( AI_SUCCESS == ret ) {
110 if (prop->mDataLength < sizeof(Type)) {
111 return AI_FAILURE;
112 }
114 if (prop->mType != aiPTI_Buffer) {
115 return AI_FAILURE;
116 }
118 memcpy(&pOut,prop->mData,sizeof(Type));
119 }
120 return ret;
121 }
123 // ---------------------------------------------------------------------------
124 template <>
125 inline aiReturn aiMaterial::Get<float>(const char* pKey,unsigned int type,
126 unsigned int idx,float* pOut,
127 unsigned int* pMax) const
128 {
129 return ::aiGetMaterialFloatArray(this,pKey,type,idx,pOut,pMax);
130 }
131 // ---------------------------------------------------------------------------
132 template <>
133 inline aiReturn aiMaterial::Get<int>(const char* pKey,unsigned int type,
134 unsigned int idx,int* pOut,
135 unsigned int* pMax) const
136 {
137 return ::aiGetMaterialIntegerArray(this,pKey,type,idx,pOut,pMax);
138 }
139 // ---------------------------------------------------------------------------
140 template <>
141 inline aiReturn aiMaterial::Get<float>(const char* pKey,unsigned int type,
142 unsigned int idx,float& pOut) const
143 {
144 return aiGetMaterialFloat(this,pKey,type,idx,&pOut);
145 }
146 // ---------------------------------------------------------------------------
147 template <>
148 inline aiReturn aiMaterial::Get<int>(const char* pKey,unsigned int type,
149 unsigned int idx,int& pOut) const
150 {
151 return aiGetMaterialInteger(this,pKey,type,idx,&pOut);
152 }
153 // ---------------------------------------------------------------------------
154 template <>
155 inline aiReturn aiMaterial::Get<aiColor4D>(const char* pKey,unsigned int type,
156 unsigned int idx,aiColor4D& pOut) const
157 {
158 return aiGetMaterialColor(this,pKey,type,idx,&pOut);
159 }
160 // ---------------------------------------------------------------------------
161 template <>
162 inline aiReturn aiMaterial::Get<aiColor3D>(const char* pKey,unsigned int type,
163 unsigned int idx,aiColor3D& pOut) const
164 {
165 aiColor4D c;
166 const aiReturn ret = aiGetMaterialColor(this,pKey,type,idx,&c);
167 pOut = aiColor3D(c.r,c.g,c.b);
168 return ret;
169 }
170 // ---------------------------------------------------------------------------
171 template <>
172 inline aiReturn aiMaterial::Get<aiString>(const char* pKey,unsigned int type,
173 unsigned int idx,aiString& pOut) const
174 {
175 return aiGetMaterialString(this,pKey,type,idx,&pOut);
176 }
179 // ---------------------------------------------------------------------------
180 template<class TYPE>
181 aiReturn aiMaterial::AddProperty (const TYPE* pInput,
182 const unsigned int pNumValues,
183 const char* pKey,
184 unsigned int type,
185 unsigned int index)
186 {
187 return AddBinaryProperty((const void*)pInput,
188 pNumValues * sizeof(TYPE),
189 pKey,type,index,aiPTI_Buffer);
190 }
192 // ---------------------------------------------------------------------------
193 template<>
194 inline aiReturn aiMaterial::AddProperty<float> (const float* 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(float),
202 pKey,type,index,aiPTI_Float);
203 }
205 // ---------------------------------------------------------------------------
206 template<>
207 inline aiReturn aiMaterial::AddProperty<aiUVTransform> (const aiUVTransform* 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(aiUVTransform),
215 pKey,type,index,aiPTI_Float);
216 }
218 // ---------------------------------------------------------------------------
219 template<>
220 inline aiReturn aiMaterial::AddProperty<aiColor4D> (const aiColor4D* pInput,
221 const unsigned int pNumValues,
222 const char* pKey,
223 unsigned int type,
224 unsigned int index)
225 {
226 return AddBinaryProperty((const void*)pInput,
227 pNumValues * sizeof(aiColor4D),
228 pKey,type,index,aiPTI_Float);
229 }
231 // ---------------------------------------------------------------------------
232 template<>
233 inline aiReturn aiMaterial::AddProperty<aiColor3D> (const aiColor3D* pInput,
234 const unsigned int pNumValues,
235 const char* pKey,
236 unsigned int type,
237 unsigned int index)
238 {
239 return AddBinaryProperty((const void*)pInput,
240 pNumValues * sizeof(aiColor3D),
241 pKey,type,index,aiPTI_Float);
242 }
244 // ---------------------------------------------------------------------------
245 template<>
246 inline aiReturn aiMaterial::AddProperty<aiVector3D> (const aiVector3D* pInput,
247 const unsigned int pNumValues,
248 const char* pKey,
249 unsigned int type,
250 unsigned int index)
251 {
252 return AddBinaryProperty((const void*)pInput,
253 pNumValues * sizeof(aiVector3D),
254 pKey,type,index,aiPTI_Float);
255 }
257 // ---------------------------------------------------------------------------
258 template<>
259 inline aiReturn aiMaterial::AddProperty<int> (const int* pInput,
260 const unsigned int pNumValues,
261 const char* pKey,
262 unsigned int type,
263 unsigned int index)
264 {
265 return AddBinaryProperty((const void*)pInput,
266 pNumValues * sizeof(int),
267 pKey,type,index,aiPTI_Integer);
268 }
270 //! @endcond
272 #endif //! AI_MATERIAL_INL_INC