OgreMesh.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2012, assimp team
  5. All rights reserved.
  6. Redistribution and use of this software in source and binary forms,
  7. with or without modification, are permitted provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain the above
  10. copyright notice, this list of conditions and the
  11. following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the
  14. following disclaimer in the documentation and/or other
  15. materials provided with the distribution.
  16. * Neither the name of the assimp team, nor the names of its
  17. contributors may be used to endorse or promote products
  18. derived from this software without specific prior
  19. written permission of the assimp team.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ----------------------------------------------------------------------
  32. */
  33. #include "AssimpPCH.h"
  34. #ifndef ASSIMP_BUILD_NO_OGRE_IMPORTER
  35. #include "OgreImporter.hpp"
  36. #include "TinyFormatter.h"
  37. using namespace std;
  38. namespace Assimp
  39. {
  40. namespace Ogre
  41. {
  42. void OgreImporter::ReadSubMesh(SubMesh &theSubMesh, XmlReader *Reader)
  43. {
  44. if(Reader->getAttributeValue("usesharedvertices"))
  45. theSubMesh.SharedData=GetAttribute<bool>(Reader, "usesharedvertices");
  46. XmlRead(Reader);
  47. //TODO: maybe we have alsways just 1 faces and 1 geometry and always in this order. this loop will only work correct, when the order
  48. //of faces and geometry changed, and not if we have more than one of one
  49. while( Reader->getNodeName()==string("faces")
  50. || Reader->getNodeName()==string("geometry")
  51. || Reader->getNodeName()==string("boneassignments"))
  52. {
  53. if(string(Reader->getNodeName())=="faces")//Read the face list
  54. {
  55. //some info logging:
  56. unsigned int NumFaces=GetAttribute<int>(Reader, "count");
  57. ostringstream ss; ss <<"Submesh has " << NumFaces << " Faces.";
  58. DefaultLogger::get()->debug(ss.str());
  59. while(XmlRead(Reader) && Reader->getNodeName()==string("face"))
  60. {
  61. Face NewFace;
  62. NewFace.VertexIndices[0]=GetAttribute<int>(Reader, "v1");
  63. NewFace.VertexIndices[1]=GetAttribute<int>(Reader, "v2");
  64. NewFace.VertexIndices[2]=GetAttribute<int>(Reader, "v3");
  65. if(Reader->getAttributeValue("v4"))//this should be supported in the future
  66. {
  67. DefaultLogger::get()->warn("Submesh has quads, only traingles are supported!");
  68. //throw DeadlyImportError("Submesh has quads, only traingles are supported!");
  69. }
  70. theSubMesh.FaceList.push_back(NewFace);
  71. }
  72. }//end of faces
  73. else if(string(Reader->getNodeName())=="geometry")//Read the vertexdata
  74. {
  75. //some info logging:
  76. unsigned int NumVertices=GetAttribute<int>(Reader, "vertexcount");
  77. ostringstream ss; ss<<"VertexCount: " << NumVertices;
  78. DefaultLogger::get()->debug(ss.str());
  79. //General Informations about vertices
  80. XmlRead(Reader);
  81. while(Reader->getNodeName()==string("vertexbuffer"))
  82. {
  83. ReadVertexBuffer(theSubMesh, Reader, NumVertices);
  84. }
  85. //some error checking on the loaded data
  86. if(!theSubMesh.HasPositions)
  87. throw DeadlyImportError("No positions could be loaded!");
  88. if(theSubMesh.HasNormals && theSubMesh.Normals.size() != NumVertices)
  89. throw DeadlyImportError("Wrong Number of Normals loaded!");
  90. if(theSubMesh.HasTangents && theSubMesh.Tangents.size() != NumVertices)
  91. throw DeadlyImportError("Wrong Number of Tangents loaded!");
  92. for(unsigned int i=0; i<theSubMesh.Uvs.size(); ++i)
  93. {
  94. if(theSubMesh.Uvs[i].size() != NumVertices)
  95. throw DeadlyImportError("Wrong Number of Uvs loaded!");
  96. }
  97. }//end of "geometry
  98. else if(Reader->getNodeName()==string("boneassignments"))
  99. {
  100. ReadBoneWeights(theSubMesh, Reader);
  101. }
  102. }
  103. DefaultLogger::get()->debug((Formatter::format(),
  104. "Positionen: ",theSubMesh.Positions.size(),
  105. " Normale: ",theSubMesh.Normals.size(),
  106. " TexCoords: ",theSubMesh.Uvs.size(),
  107. " Tantents: ",theSubMesh.Tangents.size()
  108. ));
  109. }
  110. void OgreImporter::ReadVertexBuffer(SubMesh &theSubMesh, XmlReader *Reader, unsigned int NumVertices)
  111. {
  112. DefaultLogger::get()->debug("new Vertex Buffer");
  113. bool ReadPositions=false;
  114. bool ReadNormals=false;
  115. bool ReadTangents=false;
  116. unsigned int NumUvs=0;
  117. //-------------------- check, what we need to read: --------------------------------
  118. if(Reader->getAttributeValue("positions") && GetAttribute<bool>(Reader, "positions"))
  119. {
  120. ReadPositions=theSubMesh.HasPositions=true;
  121. theSubMesh.Positions.reserve(NumVertices);
  122. DefaultLogger::get()->debug("reading positions");
  123. }
  124. if(Reader->getAttributeValue("normals") && GetAttribute<bool>(Reader, "normals"))
  125. {
  126. ReadNormals=theSubMesh.HasNormals=true;
  127. theSubMesh.Normals.reserve(NumVertices);
  128. DefaultLogger::get()->debug("reading normals");
  129. }
  130. if(Reader->getAttributeValue("tangents") && GetAttribute<bool>(Reader, "tangents"))
  131. {
  132. ReadTangents=theSubMesh.HasTangents=true;
  133. theSubMesh.Tangents.reserve(NumVertices);
  134. DefaultLogger::get()->debug("reading tangents");
  135. }
  136. if(Reader->getAttributeValue("texture_coords"))
  137. {
  138. NumUvs=GetAttribute<unsigned int>(Reader, "texture_coords");
  139. theSubMesh.Uvs.resize(NumUvs);
  140. for(unsigned int i=0; i<theSubMesh.Uvs.size(); ++i) theSubMesh.Uvs[i].reserve(NumVertices);
  141. DefaultLogger::get()->debug("reading texture coords");
  142. }
  143. //___________________________________________________________________
  144. //check if we will load anything
  145. if(!( ReadPositions || ReadNormals || ReadTangents || (NumUvs>0) ))
  146. DefaultLogger::get()->warn("vertexbuffer seams to be empty!");
  147. //read all the vertices:
  148. XmlRead(Reader);
  149. /*it might happen, that we have more than one attribute per vertex (they are not splitted to different buffers)
  150. so the break condition is a bit tricky (well, IrrXML just sucks :( )*/
  151. while(Reader->getNodeName()==string("vertex")
  152. ||Reader->getNodeName()==string("position")
  153. ||Reader->getNodeName()==string("normal")
  154. ||Reader->getNodeName()==string("tangent")
  155. ||Reader->getNodeName()==string("texcoord")
  156. ||Reader->getNodeName()==string("colour_diffuse"))
  157. {
  158. if(Reader->getNodeName()==string("vertex"))
  159. XmlRead(Reader);//Read an attribute tag
  160. //Position
  161. if(ReadPositions && Reader->getNodeName()==string("position"))
  162. {
  163. aiVector3D NewPos;
  164. NewPos.x=GetAttribute<float>(Reader, "x");
  165. NewPos.y=GetAttribute<float>(Reader, "y");
  166. NewPos.z=GetAttribute<float>(Reader, "z");
  167. theSubMesh.Positions.push_back(NewPos);
  168. }
  169. //Normal
  170. else if(ReadNormals && Reader->getNodeName()==string("normal"))
  171. {
  172. aiVector3D NewNormal;
  173. NewNormal.x=GetAttribute<float>(Reader, "x");
  174. NewNormal.y=GetAttribute<float>(Reader, "y");
  175. NewNormal.z=GetAttribute<float>(Reader, "z");
  176. theSubMesh.Normals.push_back(NewNormal);
  177. }
  178. //Tangent
  179. else if(ReadTangents && Reader->getNodeName()==string("tangent"))
  180. {
  181. aiVector3D NewTangent;
  182. NewTangent.x=GetAttribute<float>(Reader, "x");
  183. NewTangent.y=GetAttribute<float>(Reader, "y");
  184. NewTangent.z=GetAttribute<float>(Reader, "z");
  185. theSubMesh.Tangents.push_back(NewTangent);
  186. }
  187. //Uv:
  188. else if(NumUvs>0 && Reader->getNodeName()==string("texcoord"))
  189. {
  190. for(unsigned int i=0; i<NumUvs; ++i)
  191. {
  192. if(Reader->getNodeName()!=string("texcoord"))
  193. {
  194. DefaultLogger::get()->warn(string("Not enough UVs in Vertex: ")+Reader->getNodeName());
  195. }
  196. aiVector3D NewUv;
  197. NewUv.x=GetAttribute<float>(Reader, "u");
  198. NewUv.y=GetAttribute<float>(Reader, "v")*(-1)+1;//flip the uv vertikal, blender exports them so!
  199. theSubMesh.Uvs[i].push_back(NewUv);
  200. XmlRead(Reader);
  201. }
  202. continue;//because we already read the next node...
  203. }
  204. //Color:
  205. //TODO: actually save this data!
  206. else if(Reader->getNodeName()==string("colour_diffuse"))
  207. {
  208. //do nothing, because we not yet support them
  209. }
  210. //Attribute could not be read
  211. else
  212. {
  213. DefaultLogger::get()->warn(string("Attribute was not read: ")+Reader->getNodeName());
  214. }
  215. XmlRead(Reader);//Read the Vertex tag
  216. }
  217. }
  218. void OgreImporter::ReadBoneWeights(SubMesh &theSubMesh, XmlReader *Reader)
  219. {
  220. theSubMesh.Weights.resize(theSubMesh.Positions.size());
  221. while(XmlRead(Reader) && Reader->getNodeName()==string("vertexboneassignment"))
  222. {
  223. Weight NewWeight;
  224. unsigned int VertexId=GetAttribute<int>(Reader, "vertexindex");
  225. NewWeight.BoneId=GetAttribute<int>(Reader, "boneindex");
  226. NewWeight.Value=GetAttribute<float>(Reader, "weight");
  227. //calculate the number of bones used (this is the highest id +1 becuase bone ids start at 0)
  228. theSubMesh.BonesUsed=max(theSubMesh.BonesUsed, NewWeight.BoneId+1);
  229. theSubMesh.Weights[VertexId].push_back(NewWeight);
  230. }
  231. }
  232. void OgreImporter::ProcessSubMesh(SubMesh &theSubMesh, SubMesh &theSharedGeometry)
  233. {
  234. //---------------Make all Vertexes unique: (this is required by assimp)-----------------------
  235. vector<Face> UniqueFaceList(theSubMesh.FaceList.size());
  236. unsigned int UniqueVertexCount=theSubMesh.FaceList.size()*3;//*3 because each face consists of 3 vertexes, because we only support triangles^^
  237. vector<aiVector3D> UniquePositions(UniqueVertexCount);
  238. vector<aiVector3D> UniqueNormals(UniqueVertexCount);
  239. vector<aiVector3D> UniqueTangents(UniqueVertexCount);
  240. vector< vector<Weight> > UniqueWeights(UniqueVertexCount);
  241. vector< vector<aiVector3D> > UniqueUvs(theSubMesh.Uvs.size());
  242. for(unsigned int i=0; i<UniqueUvs.size(); ++i) UniqueUvs[i].resize(UniqueVertexCount);
  243. //Support for shared data:
  244. /*We can use this loop to copy vertex informations from the shared data pool. In order to do so
  245. we just use a reference to a submodel instead of our submodel itself*/
  246. SubMesh& VertexSource= theSubMesh.SharedData ? theSharedGeometry : theSubMesh;
  247. if(theSubMesh.SharedData)//copy vertexinformations to our mesh:
  248. {
  249. theSubMesh.HasPositions=theSharedGeometry.HasPositions;
  250. theSubMesh.HasNormals=theSharedGeometry.HasNormals;
  251. theSubMesh.HasTangents=theSharedGeometry.HasTangents;
  252. theSubMesh.BonesUsed=theSharedGeometry.BonesUsed;
  253. UniqueUvs.resize(theSharedGeometry.Uvs.size());
  254. for(unsigned int i=0; i<UniqueUvs.size(); ++i) UniqueUvs[i].resize(UniqueVertexCount);
  255. }
  256. for(unsigned int i=0; i<theSubMesh.FaceList.size(); ++i)
  257. {
  258. //We precalculate the index vlaues her, because we need them in all vertex attributes
  259. unsigned int Vertex1=theSubMesh.FaceList[i].VertexIndices[0];
  260. unsigned int Vertex2=theSubMesh.FaceList[i].VertexIndices[1];
  261. unsigned int Vertex3=theSubMesh.FaceList[i].VertexIndices[2];
  262. UniquePositions[3*i+0]=VertexSource.Positions[Vertex1];
  263. UniquePositions[3*i+1]=VertexSource.Positions[Vertex2];
  264. UniquePositions[3*i+2]=VertexSource.Positions[Vertex3];
  265. if(VertexSource.HasNormals)
  266. {
  267. UniqueNormals[3*i+0]=VertexSource.Normals[Vertex1];
  268. UniqueNormals[3*i+1]=VertexSource.Normals[Vertex2];
  269. UniqueNormals[3*i+2]=VertexSource.Normals[Vertex3];
  270. }
  271. if(VertexSource.HasTangents)
  272. {
  273. UniqueTangents[3*i+0]=VertexSource.Tangents[Vertex1];
  274. UniqueTangents[3*i+1]=VertexSource.Tangents[Vertex2];
  275. UniqueTangents[3*i+2]=VertexSource.Tangents[Vertex3];
  276. }
  277. if(UniqueUvs.size()>0)
  278. {
  279. for(unsigned int j=0; j<UniqueUvs.size(); ++j)
  280. {
  281. UniqueUvs[j][3*i+0]=VertexSource.Uvs[j][Vertex1];
  282. UniqueUvs[j][3*i+1]=VertexSource.Uvs[j][Vertex2];
  283. UniqueUvs[j][3*i+2]=VertexSource.Uvs[j][Vertex3];
  284. }
  285. }
  286. if(VertexSource.Weights.size() > 0)
  287. {
  288. UniqueWeights[3*i+0]=VertexSource.Weights[Vertex1];
  289. UniqueWeights[3*i+1]=VertexSource.Weights[Vertex2];
  290. UniqueWeights[3*i+2]=VertexSource.Weights[Vertex3];
  291. }
  292. //The indexvalues a just continuous numbers (0, 1, 2, 3, 4, 5, 6...)
  293. UniqueFaceList[i].VertexIndices[0]=3*i+0;
  294. UniqueFaceList[i].VertexIndices[1]=3*i+1;
  295. UniqueFaceList[i].VertexIndices[2]=3*i+2;
  296. }
  297. //_________________________________________________________________________________________
  298. //now we have the unique datas, but want them in the SubMesh, so we swap all the containers:
  299. //if we don't have one of them, we just swap empty containers, so everything is ok
  300. theSubMesh.FaceList.swap(UniqueFaceList);
  301. theSubMesh.Positions.swap(UniquePositions);
  302. theSubMesh.Normals.swap(UniqueNormals);
  303. theSubMesh.Tangents.swap(UniqueTangents);
  304. theSubMesh.Uvs.swap(UniqueUvs);
  305. theSubMesh.Weights.swap(UniqueWeights);
  306. //------------- normalize weights -----------------------------
  307. //The Blender exporter doesn't care about whether the sum of all boneweights for a single vertex equals 1 or not,
  308. //so we have to make this sure:
  309. for(unsigned int VertexId=0; VertexId<theSubMesh.Weights.size(); ++VertexId)//iterate over all vertices
  310. {
  311. float WeightSum=0.0f;
  312. for(unsigned int BoneId=0; BoneId<theSubMesh.Weights[VertexId].size(); ++BoneId)//iterate over all bones
  313. {
  314. WeightSum+=theSubMesh.Weights[VertexId][BoneId].Value;
  315. }
  316. //check if the sum is too far away from 1
  317. if(WeightSum<1.0f-0.05f || WeightSum>1.0f+0.05f)
  318. {
  319. //normalize all weights:
  320. for(unsigned int BoneId=0; BoneId<theSubMesh.Weights[VertexId].size(); ++BoneId)//iterate over all bones
  321. {
  322. theSubMesh.Weights[VertexId][BoneId].Value/=WeightSum;
  323. }
  324. }
  325. }
  326. //_________________________________________________________
  327. }
  328. aiMesh* OgreImporter::CreateAssimpSubMesh(const SubMesh& theSubMesh, const vector<Bone>& Bones) const
  329. {
  330. const aiScene* const m_CurrentScene=this->m_CurrentScene;//make sure, that we can access but not change the scene
  331. (void)m_CurrentScene;
  332. aiMesh* NewAiMesh=new aiMesh();
  333. //Positions
  334. NewAiMesh->mVertices=new aiVector3D[theSubMesh.Positions.size()];
  335. memcpy(NewAiMesh->mVertices, &theSubMesh.Positions[0], theSubMesh.Positions.size()*sizeof(aiVector3D));
  336. NewAiMesh->mNumVertices=theSubMesh.Positions.size();
  337. //Normals
  338. if(theSubMesh.HasNormals)
  339. {
  340. NewAiMesh->mNormals=new aiVector3D[theSubMesh.Normals.size()];
  341. memcpy(NewAiMesh->mNormals, &theSubMesh.Normals[0], theSubMesh.Normals.size()*sizeof(aiVector3D));
  342. }
  343. //until we have support for bitangents, no tangents will be written
  344. /*
  345. //Tangents
  346. if(theSubMesh.HasTangents)
  347. {
  348. NewAiMesh->mTangents=new aiVector3D[theSubMesh.Tangents.size()];
  349. memcpy(NewAiMesh->mTangents, &theSubMesh.Tangents[0], theSubMesh.Tangents.size()*sizeof(aiVector3D));
  350. }
  351. */
  352. //Uvs
  353. if(theSubMesh.Uvs.size()>0)
  354. {
  355. for(unsigned int i=0; i<theSubMesh.Uvs.size(); ++i)
  356. {
  357. NewAiMesh->mNumUVComponents[i]=2;
  358. NewAiMesh->mTextureCoords[i]=new aiVector3D[theSubMesh.Uvs[i].size()];
  359. memcpy(NewAiMesh->mTextureCoords[i], &(theSubMesh.Uvs[i][0]), theSubMesh.Uvs[i].size()*sizeof(aiVector3D));
  360. }
  361. }
  362. //---------------------------------------- Bones --------------------------------------------
  363. //Copy the weights in in Bone-Vertices Struktur
  364. //(we have them in a Vertex-Bones Structur, this is much easier for making them unique, which is required by assimp
  365. vector< vector<aiVertexWeight> > aiWeights(theSubMesh.BonesUsed);//now the outer list are the bones, and the inner vector the vertices
  366. for(unsigned int VertexId=0; VertexId<theSubMesh.Weights.size(); ++VertexId)//iterate over all vertices
  367. {
  368. for(unsigned int BoneId=0; BoneId<theSubMesh.Weights[VertexId].size(); ++BoneId)//iterate over all bones
  369. {
  370. aiVertexWeight NewWeight;
  371. NewWeight.mVertexId=VertexId;//the current Vertex, we can't use the Id form the submehs weights, because they are bone id's
  372. NewWeight.mWeight=theSubMesh.Weights[VertexId][BoneId].Value;
  373. aiWeights[theSubMesh.Weights[VertexId][BoneId].BoneId].push_back(NewWeight);
  374. }
  375. }
  376. vector<aiBone*> aiBones;
  377. aiBones.reserve(theSubMesh.BonesUsed);//the vector might be smaller, because there might be empty bones (bones that are not attached to any vertex)
  378. //create all the bones and fill them with informations
  379. for(unsigned int i=0; i<theSubMesh.BonesUsed; ++i)
  380. {
  381. if(aiWeights[i].size()>0)
  382. {
  383. aiBone* NewBone=new aiBone();
  384. NewBone->mNumWeights=aiWeights[i].size();
  385. NewBone->mWeights=new aiVertexWeight[aiWeights[i].size()];
  386. memcpy(NewBone->mWeights, &(aiWeights[i][0]), sizeof(aiVertexWeight)*aiWeights[i].size());
  387. NewBone->mName=Bones[i].Name;//The bone list should be sorted after its id's, this was done in LoadSkeleton
  388. NewBone->mOffsetMatrix=Bones[i].BoneToWorldSpace;
  389. aiBones.push_back(NewBone);
  390. }
  391. }
  392. NewAiMesh->mNumBones=aiBones.size();
  393. // mBones must be NULL if mNumBones is non 0 or the validation fails.
  394. if (aiBones.size()) {
  395. NewAiMesh->mBones=new aiBone* [aiBones.size()];
  396. memcpy(NewAiMesh->mBones, &(aiBones[0]), aiBones.size()*sizeof(aiBone*));
  397. }
  398. //______________________________________________________________________________________________________
  399. //Faces
  400. NewAiMesh->mFaces=new aiFace[theSubMesh.FaceList.size()];
  401. for(unsigned int i=0; i<theSubMesh.FaceList.size(); ++i)
  402. {
  403. NewAiMesh->mFaces[i].mNumIndices=3;
  404. NewAiMesh->mFaces[i].mIndices=new unsigned int[3];
  405. NewAiMesh->mFaces[i].mIndices[0]=theSubMesh.FaceList[i].VertexIndices[0];
  406. NewAiMesh->mFaces[i].mIndices[1]=theSubMesh.FaceList[i].VertexIndices[1];
  407. NewAiMesh->mFaces[i].mIndices[2]=theSubMesh.FaceList[i].VertexIndices[2];
  408. }
  409. NewAiMesh->mNumFaces=theSubMesh.FaceList.size();
  410. //Link the material:
  411. NewAiMesh->mMaterialIndex=theSubMesh.MaterialIndex;//the index is set by the function who called ReadSubMesh
  412. return NewAiMesh;
  413. }
  414. }//namespace Ogre
  415. }//namespace Assimp
  416. #endif // !! ASSIMP_BUILD_NO_OGRE_IMPORTER