ObjFileMtlImporter.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2020, assimp team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the following
  9. conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the assimp team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the assimp team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ---------------------------------------------------------------------------
  33. */
  34. #ifndef ASSIMP_BUILD_NO_OBJ_IMPORTER
  35. #include "ObjFileMtlImporter.h"
  36. #include "ObjFileData.h"
  37. #include "ObjTools.h"
  38. #include <assimp/ParsingUtils.h>
  39. #include <assimp/fast_atof.h>
  40. #include <assimp/material.h>
  41. #include <stdlib.h>
  42. #include <assimp/DefaultLogger.hpp>
  43. namespace Assimp {
  44. // Material specific token (case insensitive compare)
  45. static const std::string DiffuseTexture = "map_Kd";
  46. static const std::string AmbientTexture = "map_Ka";
  47. static const std::string SpecularTexture = "map_Ks";
  48. static const std::string OpacityTexture = "map_d";
  49. static const std::string EmissiveTexture1 = "map_emissive";
  50. static const std::string EmissiveTexture2 = "map_Ke";
  51. static const std::string BumpTexture1 = "map_bump";
  52. static const std::string BumpTexture2 = "bump";
  53. static const std::string NormalTextureV1 = "map_Kn";
  54. static const std::string NormalTextureV2 = "norm";
  55. static const std::string ReflectionTexture = "refl";
  56. static const std::string DisplacementTexture1 = "map_disp";
  57. static const std::string DisplacementTexture2 = "disp";
  58. static const std::string SpecularityTexture = "map_ns";
  59. static const std::string RoughnessTexture = "map_Pr";
  60. static const std::string MetallicTexture = "map_Pm";
  61. static const std::string SheenTexture = "map_Ps";
  62. static const std::string RMATexture = "map_Ps";
  63. // texture option specific token
  64. static const std::string BlendUOption = "-blendu";
  65. static const std::string BlendVOption = "-blendv";
  66. static const std::string BoostOption = "-boost";
  67. static const std::string ModifyMapOption = "-mm";
  68. static const std::string OffsetOption = "-o";
  69. static const std::string ScaleOption = "-s";
  70. static const std::string TurbulenceOption = "-t";
  71. static const std::string ResolutionOption = "-texres";
  72. static const std::string ClampOption = "-clamp";
  73. static const std::string BumpOption = "-bm";
  74. static const std::string ChannelOption = "-imfchan";
  75. static const std::string TypeOption = "-type";
  76. // -------------------------------------------------------------------
  77. // Constructor
  78. ObjFileMtlImporter::ObjFileMtlImporter(std::vector<char> &buffer,
  79. const std::string &,
  80. ObjFile::Model *pModel) :
  81. m_DataIt(buffer.begin()),
  82. m_DataItEnd(buffer.end()),
  83. m_pModel(pModel),
  84. m_uiLine(0),
  85. m_buffer() {
  86. ai_assert(nullptr != m_pModel);
  87. m_buffer.resize(BUFFERSIZE);
  88. std::fill(m_buffer.begin(), m_buffer.end(), '\0');
  89. if (nullptr == m_pModel->m_pDefaultMaterial) {
  90. m_pModel->m_pDefaultMaterial = new ObjFile::Material;
  91. m_pModel->m_pDefaultMaterial->MaterialName.Set("default");
  92. }
  93. load();
  94. }
  95. // -------------------------------------------------------------------
  96. // Destructor
  97. ObjFileMtlImporter::~ObjFileMtlImporter() {
  98. // empty
  99. }
  100. // -------------------------------------------------------------------
  101. // Loads the material description
  102. void ObjFileMtlImporter::load() {
  103. if (m_DataIt == m_DataItEnd)
  104. return;
  105. while (m_DataIt != m_DataItEnd) {
  106. switch (*m_DataIt) {
  107. case 'k':
  108. case 'K': {
  109. ++m_DataIt;
  110. if (*m_DataIt == 'a') // Ambient color
  111. {
  112. ++m_DataIt;
  113. if (m_pModel->m_pCurrentMaterial != nullptr)
  114. getColorRGBA(&m_pModel->m_pCurrentMaterial->ambient);
  115. } else if (*m_DataIt == 'd') {
  116. // Diffuse color
  117. ++m_DataIt;
  118. if (m_pModel->m_pCurrentMaterial != nullptr)
  119. getColorRGBA(&m_pModel->m_pCurrentMaterial->diffuse);
  120. } else if (*m_DataIt == 's') {
  121. ++m_DataIt;
  122. if (m_pModel->m_pCurrentMaterial != nullptr)
  123. getColorRGBA(&m_pModel->m_pCurrentMaterial->specular);
  124. } else if (*m_DataIt == 'e') {
  125. ++m_DataIt;
  126. if (m_pModel->m_pCurrentMaterial != nullptr)
  127. getColorRGBA(&m_pModel->m_pCurrentMaterial->emissive);
  128. }
  129. m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
  130. } break;
  131. case 'T': {
  132. ++m_DataIt;
  133. // Material transmission color
  134. if (*m_DataIt == 'f') {
  135. ++m_DataIt;
  136. if (m_pModel->m_pCurrentMaterial != nullptr)
  137. getColorRGBA(&m_pModel->m_pCurrentMaterial->transparent);
  138. } else if (*m_DataIt == 'r') {
  139. // Material transmission alpha value
  140. ++m_DataIt;
  141. ai_real d;
  142. getFloatValue(d);
  143. if (m_pModel->m_pCurrentMaterial != nullptr)
  144. m_pModel->m_pCurrentMaterial->alpha = static_cast<ai_real>(1.0) - d;
  145. }
  146. m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
  147. } break;
  148. case 'd': {
  149. if (*(m_DataIt + 1) == 'i' && *(m_DataIt + 2) == 's' && *(m_DataIt + 3) == 'p') {
  150. // A displacement map
  151. getTexture();
  152. } else {
  153. // Alpha value
  154. ++m_DataIt;
  155. if (m_pModel->m_pCurrentMaterial != nullptr)
  156. getFloatValue(m_pModel->m_pCurrentMaterial->alpha);
  157. m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
  158. }
  159. } break;
  160. case 'N':
  161. case 'n': {
  162. ++m_DataIt;
  163. switch (*m_DataIt) {
  164. case 's': // Specular exponent
  165. ++m_DataIt;
  166. if (m_pModel->m_pCurrentMaterial != nullptr)
  167. getFloatValue(m_pModel->m_pCurrentMaterial->shineness);
  168. break;
  169. case 'i': // Index Of refraction
  170. ++m_DataIt;
  171. if (m_pModel->m_pCurrentMaterial != nullptr)
  172. getFloatValue(m_pModel->m_pCurrentMaterial->ior);
  173. break;
  174. case 'e': // New material
  175. createMaterial();
  176. break;
  177. case 'o': // Norm texture
  178. --m_DataIt;
  179. getTexture();
  180. break;
  181. }
  182. m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
  183. } break;
  184. case 'P':
  185. {
  186. ++m_DataIt;
  187. switch(*m_DataIt)
  188. {
  189. case 'r':
  190. ++m_DataIt;
  191. if (m_pModel->m_pCurrentMaterial != nullptr)
  192. getFloatValue(m_pModel->m_pCurrentMaterial->roughness);
  193. break;
  194. case 'm':
  195. ++m_DataIt;
  196. if (m_pModel->m_pCurrentMaterial != nullptr)
  197. getFloatValue(m_pModel->m_pCurrentMaterial->metallic);
  198. break;
  199. case 's':
  200. ++m_DataIt;
  201. if (m_pModel->m_pCurrentMaterial != nullptr)
  202. getColorRGBA(m_pModel->m_pCurrentMaterial->sheen);
  203. break;
  204. case 'c':
  205. ++m_DataIt;
  206. if (*m_DataIt == 'r') {
  207. ++m_DataIt;
  208. if (m_pModel->m_pCurrentMaterial != nullptr)
  209. getFloatValue(m_pModel->m_pCurrentMaterial->clearcoat_roughness);
  210. } else {
  211. if (m_pModel->m_pCurrentMaterial != nullptr)
  212. getFloatValue(m_pModel->m_pCurrentMaterial->clearcoat_thickness);
  213. }
  214. break;
  215. }
  216. m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
  217. }
  218. break;
  219. case 'm': // Texture
  220. case 'b': // quick'n'dirty - for 'bump' sections
  221. case 'r': // quick'n'dirty - for 'refl' sections
  222. {
  223. getTexture();
  224. m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
  225. } break;
  226. case 'i': // Illumination model
  227. {
  228. m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
  229. if (m_pModel->m_pCurrentMaterial != nullptr)
  230. getIlluminationModel(m_pModel->m_pCurrentMaterial->illumination_model);
  231. m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
  232. } break;
  233. case 'a': // Anisotropy
  234. {
  235. ++m_DataIt;
  236. getFloatValue(m_pModel->m_pCurrentMaterial->anisotropy);
  237. if (m_pModel->m_pCurrentMaterial != nullptr)
  238. m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
  239. } break;
  240. default: {
  241. m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
  242. } break;
  243. }
  244. }
  245. }
  246. // -------------------------------------------------------------------
  247. // Loads a color definition
  248. void ObjFileMtlImporter::getColorRGBA(aiColor3D *pColor) {
  249. ai_assert(nullptr != pColor);
  250. ai_real r(0.0), g(0.0), b(0.0);
  251. m_DataIt = getFloat<DataArrayIt>(m_DataIt, m_DataItEnd, r);
  252. pColor->r = r;
  253. // we have to check if color is default 0 with only one token
  254. if (!IsLineEnd(*m_DataIt)) {
  255. m_DataIt = getFloat<DataArrayIt>(m_DataIt, m_DataItEnd, g);
  256. m_DataIt = getFloat<DataArrayIt>(m_DataIt, m_DataItEnd, b);
  257. }
  258. pColor->g = g;
  259. pColor->b = b;
  260. }
  261. void ObjFileMtlImporter::getColorRGBA(Maybe<aiColor3D> &value) {
  262. aiColor3D v;
  263. getColorRGBA(&v);
  264. value = Maybe<aiColor3D>(v);
  265. }
  266. // -------------------------------------------------------------------
  267. // Loads the kind of illumination model.
  268. void ObjFileMtlImporter::getIlluminationModel(int &illum_model) {
  269. m_DataIt = CopyNextWord<DataArrayIt>(m_DataIt, m_DataItEnd, &m_buffer[0], BUFFERSIZE);
  270. illum_model = atoi(&m_buffer[0]);
  271. }
  272. // -------------------------------------------------------------------
  273. // Loads a single float value.
  274. void ObjFileMtlImporter::getFloatValue(ai_real &value) {
  275. m_DataIt = CopyNextWord<DataArrayIt>(m_DataIt, m_DataItEnd, &m_buffer[0], BUFFERSIZE);
  276. size_t len = std::strlen(&m_buffer[0]);
  277. if (0 == len) {
  278. value = 0.0f;
  279. return;
  280. }
  281. value = (ai_real)fast_atof(&m_buffer[0]);
  282. }
  283. void ObjFileMtlImporter::getFloatValue(Maybe<ai_real> &value) {
  284. m_DataIt = CopyNextWord<DataArrayIt>(m_DataIt, m_DataItEnd, &m_buffer[0], BUFFERSIZE);
  285. size_t len = std::strlen(&m_buffer[0]);
  286. if (len)
  287. value = Maybe<ai_real>(fast_atof(&m_buffer[0]));
  288. else
  289. value = Maybe<ai_real>();
  290. }
  291. // -------------------------------------------------------------------
  292. // Creates a material from loaded data.
  293. void ObjFileMtlImporter::createMaterial() {
  294. std::string line;
  295. while (!IsLineEnd(*m_DataIt)) {
  296. line += *m_DataIt;
  297. ++m_DataIt;
  298. }
  299. std::vector<std::string> token;
  300. const unsigned int numToken = tokenize<std::string>(line, token, " \t");
  301. std::string name;
  302. if (numToken == 1) {
  303. name = AI_DEFAULT_MATERIAL_NAME;
  304. } else {
  305. // skip newmtl and all following white spaces
  306. std::size_t first_ws_pos = line.find_first_of(" \t");
  307. std::size_t first_non_ws_pos = line.find_first_not_of(" \t", first_ws_pos);
  308. if (first_non_ws_pos != std::string::npos) {
  309. name = line.substr(first_non_ws_pos);
  310. }
  311. }
  312. name = trim_whitespaces(name);
  313. std::map<std::string, ObjFile::Material *>::iterator it = m_pModel->m_MaterialMap.find(name);
  314. if (m_pModel->m_MaterialMap.end() == it) {
  315. // New Material created
  316. m_pModel->m_pCurrentMaterial = new ObjFile::Material();
  317. m_pModel->m_pCurrentMaterial->MaterialName.Set(name);
  318. m_pModel->m_MaterialLib.push_back(name);
  319. m_pModel->m_MaterialMap[name] = m_pModel->m_pCurrentMaterial;
  320. if (m_pModel->m_pCurrentMesh) {
  321. m_pModel->m_pCurrentMesh->m_uiMaterialIndex = static_cast<unsigned int>(m_pModel->m_MaterialLib.size() - 1);
  322. }
  323. } else {
  324. // Use older material
  325. m_pModel->m_pCurrentMaterial = (*it).second;
  326. }
  327. }
  328. // -------------------------------------------------------------------
  329. // Gets a texture name from data.
  330. void ObjFileMtlImporter::getTexture() {
  331. aiString *out(nullptr);
  332. int clampIndex = -1;
  333. const char *pPtr(&(*m_DataIt));
  334. if (!ASSIMP_strincmp(pPtr, DiffuseTexture.c_str(), static_cast<unsigned int>(DiffuseTexture.size()))) {
  335. // Diffuse texture
  336. out = &m_pModel->m_pCurrentMaterial->texture;
  337. clampIndex = ObjFile::Material::TextureDiffuseType;
  338. } else if (!ASSIMP_strincmp(pPtr, AmbientTexture.c_str(), static_cast<unsigned int>(AmbientTexture.size()))) {
  339. // Ambient texture
  340. out = &m_pModel->m_pCurrentMaterial->textureAmbient;
  341. clampIndex = ObjFile::Material::TextureAmbientType;
  342. } else if (!ASSIMP_strincmp(pPtr, SpecularTexture.c_str(), static_cast<unsigned int>(SpecularTexture.size()))) {
  343. // Specular texture
  344. out = &m_pModel->m_pCurrentMaterial->textureSpecular;
  345. clampIndex = ObjFile::Material::TextureSpecularType;
  346. } else if (!ASSIMP_strincmp(pPtr, DisplacementTexture1.c_str(), static_cast<unsigned int>(DisplacementTexture1.size())) ||
  347. !ASSIMP_strincmp(pPtr, DisplacementTexture2.c_str(), static_cast<unsigned int>(DisplacementTexture2.size()))) {
  348. // Displacement texture
  349. out = &m_pModel->m_pCurrentMaterial->textureDisp;
  350. clampIndex = ObjFile::Material::TextureDispType;
  351. } else if (!ASSIMP_strincmp(pPtr, OpacityTexture.c_str(), static_cast<unsigned int>(OpacityTexture.size()))) {
  352. // Opacity texture
  353. out = &m_pModel->m_pCurrentMaterial->textureOpacity;
  354. clampIndex = ObjFile::Material::TextureOpacityType;
  355. } else if (!ASSIMP_strincmp(pPtr, EmissiveTexture1.c_str(), static_cast<unsigned int>(EmissiveTexture1.size())) ||
  356. !ASSIMP_strincmp(pPtr, EmissiveTexture2.c_str(), static_cast<unsigned int>(EmissiveTexture2.size()))) {
  357. // Emissive texture
  358. out = &m_pModel->m_pCurrentMaterial->textureEmissive;
  359. clampIndex = ObjFile::Material::TextureEmissiveType;
  360. } else if (!ASSIMP_strincmp(pPtr, BumpTexture1.c_str(), static_cast<unsigned int>(BumpTexture1.size())) ||
  361. !ASSIMP_strincmp(pPtr, BumpTexture2.c_str(), static_cast<unsigned int>(BumpTexture2.size()))) {
  362. // Bump texture
  363. out = &m_pModel->m_pCurrentMaterial->textureBump;
  364. clampIndex = ObjFile::Material::TextureBumpType;
  365. } else if (!ASSIMP_strincmp(pPtr, NormalTextureV1.c_str(), static_cast<unsigned int>(NormalTextureV1.size())) || !ASSIMP_strincmp(pPtr, NormalTextureV2.c_str(), static_cast<unsigned int>(NormalTextureV2.size()))) {
  366. // Normal map
  367. out = &m_pModel->m_pCurrentMaterial->textureNormal;
  368. clampIndex = ObjFile::Material::TextureNormalType;
  369. } else if (!ASSIMP_strincmp(pPtr, ReflectionTexture.c_str(), static_cast<unsigned int>(ReflectionTexture.size()))) {
  370. // Reflection texture(s)
  371. //Do nothing here
  372. return;
  373. } else if (!ASSIMP_strincmp(pPtr, SpecularityTexture.c_str(), static_cast<unsigned int>(SpecularityTexture.size()))) {
  374. // Specularity scaling (glossiness)
  375. out = &m_pModel->m_pCurrentMaterial->textureSpecularity;
  376. clampIndex = ObjFile::Material::TextureSpecularityType;
  377. } else if ( !ASSIMP_strincmp( pPtr, RoughnessTexture.c_str(), static_cast<unsigned int>(RoughnessTexture.size()))) {
  378. // PBR Roughness texture
  379. out = & m_pModel->m_pCurrentMaterial->textureRoughness;
  380. clampIndex = ObjFile::Material::TextureRoughnessType;
  381. } else if ( !ASSIMP_strincmp( pPtr, MetallicTexture.c_str(), static_cast<unsigned int>(MetallicTexture.size()))) {
  382. // PBR Metallic texture
  383. out = & m_pModel->m_pCurrentMaterial->textureMetallic;
  384. clampIndex = ObjFile::Material::TextureMetallicType;
  385. } else if (!ASSIMP_strincmp( pPtr, SheenTexture.c_str(), static_cast<unsigned int>(SheenTexture.size()))) {
  386. // PBR Sheen (reflectance) texture
  387. out = & m_pModel->m_pCurrentMaterial->textureSheen;
  388. clampIndex = ObjFile::Material::TextureSheenType;
  389. } else if (!ASSIMP_strincmp( pPtr, RMATexture.c_str(), static_cast<unsigned int>(RMATexture.size()))) {
  390. // PBR Rough/Metal/AO texture
  391. out = & m_pModel->m_pCurrentMaterial->textureRMA;
  392. clampIndex = ObjFile::Material::TextureRMAType;
  393. } else {
  394. ASSIMP_LOG_ERROR("OBJ/MTL: Encountered unknown texture type");
  395. return;
  396. }
  397. bool clamp = false;
  398. getTextureOption(clamp, clampIndex, out);
  399. m_pModel->m_pCurrentMaterial->clamp[clampIndex] = clamp;
  400. std::string texture;
  401. m_DataIt = getName<DataArrayIt>(m_DataIt, m_DataItEnd, texture);
  402. if (nullptr != out) {
  403. out->Set(texture);
  404. }
  405. }
  406. /* /////////////////////////////////////////////////////////////////////////////
  407. * Texture Option
  408. * /////////////////////////////////////////////////////////////////////////////
  409. * According to http://en.wikipedia.org/wiki/Wavefront_.obj_file#Texture_options
  410. * Texture map statement can contains various texture option, for example:
  411. *
  412. * map_Ka -o 1 1 1 some.png
  413. * map_Kd -clamp on some.png
  414. *
  415. * So we need to parse and skip these options, and leave the last part which is
  416. * the url of image, otherwise we will get a wrong url like "-clamp on some.png".
  417. *
  418. * Because aiMaterial supports clamp option, so we also want to return it
  419. * /////////////////////////////////////////////////////////////////////////////
  420. */
  421. void ObjFileMtlImporter::getTextureOption(bool &clamp, int &clampIndex, aiString *&out) {
  422. m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
  423. // If there is any more texture option
  424. while (!isEndOfBuffer(m_DataIt, m_DataItEnd) && *m_DataIt == '-') {
  425. const char *pPtr(&(*m_DataIt));
  426. //skip option key and value
  427. int skipToken = 1;
  428. if (!ASSIMP_strincmp(pPtr, ClampOption.c_str(), static_cast<unsigned int>(ClampOption.size()))) {
  429. DataArrayIt it = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
  430. char value[3];
  431. CopyNextWord(it, m_DataItEnd, value, sizeof(value) / sizeof(*value));
  432. if (!ASSIMP_strincmp(value, "on", 2)) {
  433. clamp = true;
  434. }
  435. skipToken = 2;
  436. } else if (!ASSIMP_strincmp(pPtr, TypeOption.c_str(), static_cast<unsigned int>(TypeOption.size()))) {
  437. DataArrayIt it = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
  438. char value[12];
  439. CopyNextWord(it, m_DataItEnd, value, sizeof(value) / sizeof(*value));
  440. if (!ASSIMP_strincmp(value, "cube_top", 8)) {
  441. clampIndex = ObjFile::Material::TextureReflectionCubeTopType;
  442. out = &m_pModel->m_pCurrentMaterial->textureReflection[0];
  443. } else if (!ASSIMP_strincmp(value, "cube_bottom", 11)) {
  444. clampIndex = ObjFile::Material::TextureReflectionCubeBottomType;
  445. out = &m_pModel->m_pCurrentMaterial->textureReflection[1];
  446. } else if (!ASSIMP_strincmp(value, "cube_front", 10)) {
  447. clampIndex = ObjFile::Material::TextureReflectionCubeFrontType;
  448. out = &m_pModel->m_pCurrentMaterial->textureReflection[2];
  449. } else if (!ASSIMP_strincmp(value, "cube_back", 9)) {
  450. clampIndex = ObjFile::Material::TextureReflectionCubeBackType;
  451. out = &m_pModel->m_pCurrentMaterial->textureReflection[3];
  452. } else if (!ASSIMP_strincmp(value, "cube_left", 9)) {
  453. clampIndex = ObjFile::Material::TextureReflectionCubeLeftType;
  454. out = &m_pModel->m_pCurrentMaterial->textureReflection[4];
  455. } else if (!ASSIMP_strincmp(value, "cube_right", 10)) {
  456. clampIndex = ObjFile::Material::TextureReflectionCubeRightType;
  457. out = &m_pModel->m_pCurrentMaterial->textureReflection[5];
  458. } else if (!ASSIMP_strincmp(value, "sphere", 6)) {
  459. clampIndex = ObjFile::Material::TextureReflectionSphereType;
  460. out = &m_pModel->m_pCurrentMaterial->textureReflection[0];
  461. }
  462. skipToken = 2;
  463. } else if (!ASSIMP_strincmp(pPtr, BumpOption.c_str(), static_cast<unsigned int>(BumpOption.size()))) {
  464. DataArrayIt it = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
  465. getFloat(it, m_DataItEnd, m_pModel->m_pCurrentMaterial->bump_multiplier);
  466. skipToken = 2;
  467. } else if (!ASSIMP_strincmp(pPtr, BlendUOption.c_str(), static_cast<unsigned int>(BlendUOption.size())) || !ASSIMP_strincmp(pPtr, BlendVOption.c_str(), static_cast<unsigned int>(BlendVOption.size())) || !ASSIMP_strincmp(pPtr, BoostOption.c_str(), static_cast<unsigned int>(BoostOption.size())) || !ASSIMP_strincmp(pPtr, ResolutionOption.c_str(), static_cast<unsigned int>(ResolutionOption.size())) || !ASSIMP_strincmp(pPtr, ChannelOption.c_str(), static_cast<unsigned int>(ChannelOption.size()))) {
  468. skipToken = 2;
  469. } else if (!ASSIMP_strincmp(pPtr, ModifyMapOption.c_str(), static_cast<unsigned int>(ModifyMapOption.size()))) {
  470. skipToken = 3;
  471. } else if (!ASSIMP_strincmp(pPtr, OffsetOption.c_str(), static_cast<unsigned int>(OffsetOption.size())) || !ASSIMP_strincmp(pPtr, ScaleOption.c_str(), static_cast<unsigned int>(ScaleOption.size())) || !ASSIMP_strincmp(pPtr, TurbulenceOption.c_str(), static_cast<unsigned int>(TurbulenceOption.size()))) {
  472. skipToken = 4;
  473. }
  474. for (int i = 0; i < skipToken; ++i) {
  475. m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
  476. }
  477. }
  478. }
  479. // -------------------------------------------------------------------
  480. } // Namespace Assimp
  481. #endif // !! ASSIMP_BUILD_NO_OBJ_IMPORTER