ObjFileMtlImporter.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  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 constexpr char DiffuseTexture[] = "map_Kd";
  46. static constexpr char AmbientTexture[] = "map_Ka";
  47. static constexpr char SpecularTexture[] = "map_Ks";
  48. static constexpr char OpacityTexture[] = "map_d";
  49. static constexpr char EmissiveTexture1[] = "map_emissive";
  50. static constexpr char EmissiveTexture2[] = "map_Ke";
  51. static constexpr char BumpTexture1[] = "map_bump";
  52. static constexpr char BumpTexture2[] = "bump";
  53. static constexpr char NormalTextureV1[] = "map_Kn";
  54. static constexpr char NormalTextureV2[] = "norm";
  55. static constexpr char ReflectionTexture[] = "refl";
  56. static constexpr char DisplacementTexture1[] = "map_disp";
  57. static constexpr char DisplacementTexture2[] = "disp";
  58. static constexpr char SpecularityTexture[] = "map_ns";
  59. static constexpr char RoughnessTexture[] = "map_Pr";
  60. static constexpr char MetallicTexture[] = "map_Pm";
  61. static constexpr char SheenTexture[] = "map_Ps";
  62. static constexpr char RMATexture[] = "map_Ps";
  63. // texture option specific token
  64. static constexpr char BlendUOption[] = "-blendu";
  65. static constexpr char BlendVOption[] = "-blendv";
  66. static constexpr char BoostOption[] = "-boost";
  67. static constexpr char ModifyMapOption[] = "-mm";
  68. static constexpr char OffsetOption[] = "-o";
  69. static constexpr char ScaleOption[] = "-s";
  70. static constexpr char TurbulenceOption[] = "-t";
  71. static constexpr char ResolutionOption[] = "-texres";
  72. static constexpr char ClampOption[] = "-clamp";
  73. static constexpr char BumpOption[] = "-bm";
  74. static constexpr char ChannelOption[] = "-imfchan";
  75. static constexpr char 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->mDefaultMaterial) {
  90. m_pModel->mDefaultMaterial = new ObjFile::Material;
  91. m_pModel->mDefaultMaterial->MaterialName.Set("default");
  92. }
  93. load();
  94. }
  95. // -------------------------------------------------------------------
  96. // Destructor
  97. ObjFileMtlImporter::~ObjFileMtlImporter() = default;
  98. // -------------------------------------------------------------------
  99. // Loads the material description
  100. void ObjFileMtlImporter::load() {
  101. if (m_DataIt == m_DataItEnd)
  102. return;
  103. while (m_DataIt != m_DataItEnd) {
  104. switch (*m_DataIt) {
  105. case 'k':
  106. case 'K': {
  107. ++m_DataIt;
  108. if (*m_DataIt == 'a') // Ambient color
  109. {
  110. ++m_DataIt;
  111. if (m_pModel->mCurrentMaterial != nullptr)
  112. getColorRGBA(&m_pModel->mCurrentMaterial->ambient);
  113. } else if (*m_DataIt == 'd') {
  114. // Diffuse color
  115. ++m_DataIt;
  116. if (m_pModel->mCurrentMaterial != nullptr)
  117. getColorRGBA(&m_pModel->mCurrentMaterial->diffuse);
  118. } else if (*m_DataIt == 's') {
  119. ++m_DataIt;
  120. if (m_pModel->mCurrentMaterial != nullptr)
  121. getColorRGBA(&m_pModel->mCurrentMaterial->specular);
  122. } else if (*m_DataIt == 'e') {
  123. ++m_DataIt;
  124. if (m_pModel->mCurrentMaterial != nullptr)
  125. getColorRGBA(&m_pModel->mCurrentMaterial->emissive);
  126. }
  127. m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
  128. } break;
  129. case 'T': {
  130. ++m_DataIt;
  131. // Material transmission color
  132. if (*m_DataIt == 'f') {
  133. ++m_DataIt;
  134. if (m_pModel->mCurrentMaterial != nullptr)
  135. getColorRGBA(&m_pModel->mCurrentMaterial->transparent);
  136. } else if (*m_DataIt == 'r') {
  137. // Material transmission alpha value
  138. ++m_DataIt;
  139. ai_real d;
  140. getFloatValue(d);
  141. if (m_pModel->mCurrentMaterial != nullptr)
  142. m_pModel->mCurrentMaterial->alpha = static_cast<ai_real>(1.0) - d;
  143. }
  144. m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
  145. } break;
  146. case 'd': {
  147. if (*(m_DataIt + 1) == 'i' && *(m_DataIt + 2) == 's' && *(m_DataIt + 3) == 'p') {
  148. // A displacement map
  149. getTexture();
  150. } else {
  151. // Alpha value
  152. ++m_DataIt;
  153. if (m_pModel->mCurrentMaterial != nullptr)
  154. getFloatValue(m_pModel->mCurrentMaterial->alpha);
  155. m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
  156. }
  157. } break;
  158. case 'N':
  159. case 'n': {
  160. ++m_DataIt;
  161. switch (*m_DataIt) {
  162. case 's': // Specular exponent
  163. ++m_DataIt;
  164. if (m_pModel->mCurrentMaterial != nullptr)
  165. getFloatValue(m_pModel->mCurrentMaterial->shineness);
  166. break;
  167. case 'i': // Index Of refraction
  168. ++m_DataIt;
  169. if (m_pModel->mCurrentMaterial != nullptr)
  170. getFloatValue(m_pModel->mCurrentMaterial->ior);
  171. break;
  172. case 'e': // New material
  173. createMaterial();
  174. break;
  175. case 'o': // Norm texture
  176. --m_DataIt;
  177. getTexture();
  178. break;
  179. }
  180. m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
  181. } break;
  182. case 'P':
  183. {
  184. ++m_DataIt;
  185. switch(*m_DataIt)
  186. {
  187. case 'r':
  188. ++m_DataIt;
  189. if (m_pModel->mCurrentMaterial != nullptr)
  190. getFloatValue(m_pModel->mCurrentMaterial->roughness);
  191. break;
  192. case 'm':
  193. ++m_DataIt;
  194. if (m_pModel->mCurrentMaterial != nullptr)
  195. getFloatValue(m_pModel->mCurrentMaterial->metallic);
  196. break;
  197. case 's':
  198. ++m_DataIt;
  199. if (m_pModel->mCurrentMaterial != nullptr)
  200. getColorRGBA(m_pModel->mCurrentMaterial->sheen);
  201. break;
  202. case 'c':
  203. ++m_DataIt;
  204. if (*m_DataIt == 'r') {
  205. ++m_DataIt;
  206. if (m_pModel->mCurrentMaterial != nullptr)
  207. getFloatValue(m_pModel->mCurrentMaterial->clearcoat_roughness);
  208. } else {
  209. if (m_pModel->mCurrentMaterial != nullptr)
  210. getFloatValue(m_pModel->mCurrentMaterial->clearcoat_thickness);
  211. }
  212. break;
  213. }
  214. m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
  215. }
  216. break;
  217. case 'm': // Texture
  218. case 'b': // quick'n'dirty - for 'bump' sections
  219. case 'r': // quick'n'dirty - for 'refl' sections
  220. {
  221. getTexture();
  222. m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
  223. } break;
  224. case 'i': // Illumination model
  225. {
  226. m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
  227. if (m_pModel->mCurrentMaterial != nullptr)
  228. getIlluminationModel(m_pModel->mCurrentMaterial->illumination_model);
  229. m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
  230. } break;
  231. case 'a': // Anisotropy
  232. {
  233. ++m_DataIt;
  234. if (m_pModel->mCurrentMaterial != nullptr)
  235. getFloatValue(m_pModel->mCurrentMaterial->anisotropy);
  236. m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
  237. } break;
  238. default: {
  239. m_DataIt = skipLine<DataArrayIt>(m_DataIt, m_DataItEnd, m_uiLine);
  240. } break;
  241. }
  242. }
  243. }
  244. // -------------------------------------------------------------------
  245. // Loads a color definition
  246. void ObjFileMtlImporter::getColorRGBA(aiColor3D *pColor) {
  247. ai_assert(nullptr != pColor);
  248. ai_real r(0.0), g(0.0), b(0.0);
  249. m_DataIt = getFloat<DataArrayIt>(m_DataIt, m_DataItEnd, r);
  250. pColor->r = r;
  251. // we have to check if color is default 0 with only one token
  252. if (!IsLineEnd(*m_DataIt)) {
  253. m_DataIt = getFloat<DataArrayIt>(m_DataIt, m_DataItEnd, g);
  254. m_DataIt = getFloat<DataArrayIt>(m_DataIt, m_DataItEnd, b);
  255. }
  256. pColor->g = g;
  257. pColor->b = b;
  258. }
  259. // -------------------------------------------------------------------
  260. void ObjFileMtlImporter::getColorRGBA(Maybe<aiColor3D> &value) {
  261. aiColor3D v;
  262. getColorRGBA(&v);
  263. value = Maybe<aiColor3D>(v);
  264. }
  265. // -------------------------------------------------------------------
  266. // Loads the kind of illumination model.
  267. void ObjFileMtlImporter::getIlluminationModel(int &illum_model) {
  268. m_DataIt = CopyNextWord<DataArrayIt>(m_DataIt, m_DataItEnd, &m_buffer[0], BUFFERSIZE);
  269. illum_model = atoi(&m_buffer[0]);
  270. }
  271. // -------------------------------------------------------------------
  272. // Loads a single float value.
  273. void ObjFileMtlImporter::getFloatValue(ai_real &value) {
  274. m_DataIt = CopyNextWord<DataArrayIt>(m_DataIt, m_DataItEnd, &m_buffer[0], BUFFERSIZE);
  275. size_t len = std::strlen(&m_buffer[0]);
  276. if (0 == len) {
  277. value = 0.0f;
  278. return;
  279. }
  280. value = (ai_real)fast_atof(&m_buffer[0]);
  281. }
  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 = ai_trim(name);
  313. std::map<std::string, ObjFile::Material *>::iterator it = m_pModel->mMaterialMap.find(name);
  314. if (m_pModel->mMaterialMap.end() == it) {
  315. // New Material created
  316. m_pModel->mCurrentMaterial = new ObjFile::Material();
  317. m_pModel->mCurrentMaterial->MaterialName.Set(name);
  318. m_pModel->mMaterialLib.push_back(name);
  319. m_pModel->mMaterialMap[name] = m_pModel->mCurrentMaterial;
  320. if (m_pModel->mCurrentMesh) {
  321. m_pModel->mCurrentMesh->m_uiMaterialIndex = static_cast<unsigned int>(m_pModel->mMaterialLib.size() - 1);
  322. }
  323. } else {
  324. // Use older material
  325. m_pModel->mCurrentMaterial = 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. if (m_pModel->mCurrentMaterial == nullptr) {
  334. m_pModel->mCurrentMaterial = new ObjFile::Material();
  335. m_pModel->mCurrentMaterial->MaterialName.Set("Empty_Material");
  336. m_pModel->mMaterialMap["Empty_Material"] = m_pModel->mCurrentMaterial;
  337. }
  338. const char *pPtr(&(*m_DataIt));
  339. if (!ASSIMP_strincmp(pPtr, DiffuseTexture, static_cast<unsigned int>(strlen(DiffuseTexture)))) {
  340. // Diffuse texture
  341. out = &m_pModel->mCurrentMaterial->texture;
  342. clampIndex = ObjFile::Material::TextureDiffuseType;
  343. } else if (!ASSIMP_strincmp(pPtr, AmbientTexture, static_cast<unsigned int>(strlen(AmbientTexture)))) {
  344. // Ambient texture
  345. out = &m_pModel->mCurrentMaterial->textureAmbient;
  346. clampIndex = ObjFile::Material::TextureAmbientType;
  347. } else if (!ASSIMP_strincmp(pPtr, SpecularTexture, static_cast<unsigned int>(strlen(SpecularTexture)))) {
  348. // Specular texture
  349. out = &m_pModel->mCurrentMaterial->textureSpecular;
  350. clampIndex = ObjFile::Material::TextureSpecularType;
  351. } else if (!ASSIMP_strincmp(pPtr, DisplacementTexture1, static_cast<unsigned int>(strlen(DisplacementTexture1))) ||
  352. !ASSIMP_strincmp(pPtr, DisplacementTexture2, static_cast<unsigned int>(strlen(DisplacementTexture2)))) {
  353. // Displacement texture
  354. out = &m_pModel->mCurrentMaterial->textureDisp;
  355. clampIndex = ObjFile::Material::TextureDispType;
  356. } else if (!ASSIMP_strincmp(pPtr, OpacityTexture, static_cast<unsigned int>(strlen(OpacityTexture)))) {
  357. // Opacity texture
  358. out = &m_pModel->mCurrentMaterial->textureOpacity;
  359. clampIndex = ObjFile::Material::TextureOpacityType;
  360. } else if (!ASSIMP_strincmp(pPtr, EmissiveTexture1, static_cast<unsigned int>(strlen(EmissiveTexture1))) ||
  361. !ASSIMP_strincmp(pPtr, EmissiveTexture2, static_cast<unsigned int>(strlen(EmissiveTexture2)))) {
  362. // Emissive texture
  363. out = &m_pModel->mCurrentMaterial->textureEmissive;
  364. clampIndex = ObjFile::Material::TextureEmissiveType;
  365. } else if (!ASSIMP_strincmp(pPtr, BumpTexture1, static_cast<unsigned int>(strlen(BumpTexture1))) ||
  366. !ASSIMP_strincmp(pPtr, BumpTexture2, static_cast<unsigned int>(strlen(BumpTexture2)))) {
  367. // Bump texture
  368. out = &m_pModel->mCurrentMaterial->textureBump;
  369. clampIndex = ObjFile::Material::TextureBumpType;
  370. } else if (!ASSIMP_strincmp(pPtr, NormalTextureV1, static_cast<unsigned int>(strlen(NormalTextureV1))) || !ASSIMP_strincmp(pPtr, NormalTextureV2, static_cast<unsigned int>(strlen(NormalTextureV2)))) {
  371. // Normal map
  372. out = &m_pModel->mCurrentMaterial->textureNormal;
  373. clampIndex = ObjFile::Material::TextureNormalType;
  374. } else if (!ASSIMP_strincmp(pPtr, ReflectionTexture, static_cast<unsigned int>(strlen(ReflectionTexture)))) {
  375. // Reflection texture(s)
  376. //Do nothing here
  377. return;
  378. } else if (!ASSIMP_strincmp(pPtr, SpecularityTexture, static_cast<unsigned int>(strlen(SpecularityTexture)))) {
  379. // Specularity scaling (glossiness)
  380. out = &m_pModel->mCurrentMaterial->textureSpecularity;
  381. clampIndex = ObjFile::Material::TextureSpecularityType;
  382. } else if ( !ASSIMP_strincmp( pPtr, RoughnessTexture, static_cast<unsigned int>(strlen(RoughnessTexture)))) {
  383. // PBR Roughness texture
  384. out = & m_pModel->mCurrentMaterial->textureRoughness;
  385. clampIndex = ObjFile::Material::TextureRoughnessType;
  386. } else if ( !ASSIMP_strincmp( pPtr, MetallicTexture, static_cast<unsigned int>(strlen(MetallicTexture)))) {
  387. // PBR Metallic texture
  388. out = & m_pModel->mCurrentMaterial->textureMetallic;
  389. clampIndex = ObjFile::Material::TextureMetallicType;
  390. } else if (!ASSIMP_strincmp( pPtr, SheenTexture, static_cast<unsigned int>(strlen(SheenTexture)))) {
  391. // PBR Sheen (reflectance) texture
  392. out = & m_pModel->mCurrentMaterial->textureSheen;
  393. clampIndex = ObjFile::Material::TextureSheenType;
  394. } else if (!ASSIMP_strincmp( pPtr, RMATexture, static_cast<unsigned int>(strlen(RMATexture)))) {
  395. // PBR Rough/Metal/AO texture
  396. out = & m_pModel->mCurrentMaterial->textureRMA;
  397. clampIndex = ObjFile::Material::TextureRMAType;
  398. } else {
  399. ASSIMP_LOG_ERROR("OBJ/MTL: Encountered unknown texture type");
  400. return;
  401. }
  402. bool clamp = false;
  403. getTextureOption(clamp, clampIndex, out);
  404. m_pModel->mCurrentMaterial->clamp[clampIndex] = clamp;
  405. std::string texture;
  406. m_DataIt = getName<DataArrayIt>(m_DataIt, m_DataItEnd, texture);
  407. if (nullptr != out) {
  408. out->Set(texture);
  409. }
  410. }
  411. /* /////////////////////////////////////////////////////////////////////////////
  412. * Texture Option
  413. * /////////////////////////////////////////////////////////////////////////////
  414. * According to http://en.wikipedia.org/wiki/Wavefront_.obj_file#Texture_options
  415. * Texture map statement can contains various texture option, for example:
  416. *
  417. * map_Ka -o 1 1 1 some.png
  418. * map_Kd -clamp on some.png
  419. *
  420. * So we need to parse and skip these options, and leave the last part which is
  421. * the url of image, otherwise we will get a wrong url like "-clamp on some.png".
  422. *
  423. * Because aiMaterial supports clamp option, so we also want to return it
  424. * /////////////////////////////////////////////////////////////////////////////
  425. */
  426. void ObjFileMtlImporter::getTextureOption(bool &clamp, int &clampIndex, aiString *&out) {
  427. m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
  428. // If there is any more texture option
  429. while (!isEndOfBuffer(m_DataIt, m_DataItEnd) && *m_DataIt == '-') {
  430. const char *pPtr(&(*m_DataIt));
  431. //skip option key and value
  432. int skipToken = 1;
  433. if (!ASSIMP_strincmp(pPtr, ClampOption, static_cast<unsigned int>(strlen(ClampOption)))) {
  434. DataArrayIt it = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
  435. char value[3];
  436. CopyNextWord(it, m_DataItEnd, value, sizeof(value) / sizeof(*value));
  437. if (!ASSIMP_strincmp(value, "on", 2)) {
  438. clamp = true;
  439. }
  440. skipToken = 2;
  441. } else if (!ASSIMP_strincmp(pPtr, TypeOption, static_cast<unsigned int>(strlen(TypeOption)))) {
  442. DataArrayIt it = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
  443. char value[12];
  444. CopyNextWord(it, m_DataItEnd, value, sizeof(value) / sizeof(*value));
  445. if (!ASSIMP_strincmp(value, "cube_top", 8)) {
  446. clampIndex = ObjFile::Material::TextureReflectionCubeTopType;
  447. out = &m_pModel->mCurrentMaterial->textureReflection[0];
  448. } else if (!ASSIMP_strincmp(value, "cube_bottom", 11)) {
  449. clampIndex = ObjFile::Material::TextureReflectionCubeBottomType;
  450. out = &m_pModel->mCurrentMaterial->textureReflection[1];
  451. } else if (!ASSIMP_strincmp(value, "cube_front", 10)) {
  452. clampIndex = ObjFile::Material::TextureReflectionCubeFrontType;
  453. out = &m_pModel->mCurrentMaterial->textureReflection[2];
  454. } else if (!ASSIMP_strincmp(value, "cube_back", 9)) {
  455. clampIndex = ObjFile::Material::TextureReflectionCubeBackType;
  456. out = &m_pModel->mCurrentMaterial->textureReflection[3];
  457. } else if (!ASSIMP_strincmp(value, "cube_left", 9)) {
  458. clampIndex = ObjFile::Material::TextureReflectionCubeLeftType;
  459. out = &m_pModel->mCurrentMaterial->textureReflection[4];
  460. } else if (!ASSIMP_strincmp(value, "cube_right", 10)) {
  461. clampIndex = ObjFile::Material::TextureReflectionCubeRightType;
  462. out = &m_pModel->mCurrentMaterial->textureReflection[5];
  463. } else if (!ASSIMP_strincmp(value, "sphere", 6)) {
  464. clampIndex = ObjFile::Material::TextureReflectionSphereType;
  465. out = &m_pModel->mCurrentMaterial->textureReflection[0];
  466. }
  467. skipToken = 2;
  468. } else if (!ASSIMP_strincmp(pPtr, BumpOption, static_cast<unsigned int>(strlen(BumpOption)))) {
  469. DataArrayIt it = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
  470. getFloat(it, m_DataItEnd, m_pModel->mCurrentMaterial->bump_multiplier);
  471. skipToken = 2;
  472. } else if (!ASSIMP_strincmp(pPtr, BlendUOption, static_cast<unsigned int>(strlen(BlendUOption))) ||
  473. !ASSIMP_strincmp(pPtr, BlendVOption, static_cast<unsigned int>(strlen(BlendVOption))) ||
  474. !ASSIMP_strincmp(pPtr, BoostOption, static_cast<unsigned int>(strlen(BoostOption))) ||
  475. !ASSIMP_strincmp(pPtr, ResolutionOption, static_cast<unsigned int>(strlen(ResolutionOption))) ||
  476. !ASSIMP_strincmp(pPtr, ChannelOption, static_cast<unsigned int>(strlen(ChannelOption)))) {
  477. skipToken = 2;
  478. } else if (!ASSIMP_strincmp(pPtr, ModifyMapOption, static_cast<unsigned int>(strlen(ModifyMapOption)))) {
  479. skipToken = 3;
  480. } else if (!ASSIMP_strincmp(pPtr, OffsetOption, static_cast<unsigned int>(strlen(OffsetOption))) ||
  481. !ASSIMP_strincmp(pPtr, ScaleOption, static_cast<unsigned int>(strlen(ScaleOption))) ||
  482. !ASSIMP_strincmp(pPtr, TurbulenceOption, static_cast<unsigned int>(strlen(TurbulenceOption)))) {
  483. skipToken = 4;
  484. }
  485. for (int i = 0; i < skipToken; ++i) {
  486. m_DataIt = getNextToken<DataArrayIt>(m_DataIt, m_DataItEnd);
  487. }
  488. }
  489. }
  490. // -------------------------------------------------------------------
  491. } // Namespace Assimp
  492. #endif // !! ASSIMP_BUILD_NO_OBJ_IMPORTER