diff --git a/code/OgreImporter.cpp b/code/OgreImporter.cpp index e11c5b0f1..7886a36d9 100644 --- a/code/OgreImporter.cpp +++ b/code/OgreImporter.cpp @@ -200,9 +200,9 @@ void OgreImporter::InternReadFile(const std::string &pFile, aiScene *pScene, Ass ReadBoneWeights(m_SharedGeometry, reader.get()); // -------------------- Process Results -------------------- - BOOST_FOREACH(boost::shared_ptr theSubMesh, subMeshes) + BOOST_FOREACH(boost::shared_ptr submesh, subMeshes) { - ProcessSubMesh(*theSubMesh, m_SharedGeometry); + ProcessSubMesh(*submesh.get(), m_SharedGeometry); } // -------------------- Apply to aiScene -------------------- diff --git a/code/OgreMesh.cpp b/code/OgreMesh.cpp index 4fa29f9ff..0ce01f4d4 100644 --- a/code/OgreMesh.cpp +++ b/code/OgreMesh.cpp @@ -324,122 +324,107 @@ void OgreImporter::ReadBoneWeights(SubMesh &submesh, XmlReader *reader) void OgreImporter::ProcessSubMesh(SubMesh &submesh, SubMesh &sharedGeometry) { - //---------------Make all Vertexes unique: (this is required by assimp)----------------------- - vector UniqueFaceList(submesh.Faces.size()); - unsigned int UniqueVertexCount=submesh.Faces.size()*3;//*3 because each face consists of 3 vertexes, because we only support triangles^^ + // Make all vertexes unique. Required by Assimp. + vector uniqueFaceList(submesh.Faces.size()); + unsigned int uniqueVertexCount = submesh.Faces.size() * 3; - vector UniquePositions(UniqueVertexCount); + vector uniquePositions(uniqueVertexCount); + vector uniqueNormals(uniqueVertexCount); + vector uniqueTangents(uniqueVertexCount); - vector UniqueNormals(UniqueVertexCount); + vector > uniqueWeights(uniqueVertexCount); + vector > uniqueUvs(submesh.UseSharedGeometry ? sharedGeometry.Uvs.size() : submesh.Uvs.size()); - vector UniqueTangents(UniqueVertexCount); + for(size_t uvi=0; uvi > UniqueWeights(UniqueVertexCount); - - vector< vector > UniqueUvs(submesh.Uvs.size()); - for(unsigned int i=0; i0) + for(size_t uvi=0; uvi &uv = vertexSource.Uvs[uvi]; + uniqueUvs[uvi][pos] = uv[v1]; + uniqueUvs[uvi][pos+1] = uv[v2]; + uniqueUvs[uvi][pos+2] = uv[v3]; } - if(VertexSource.Weights.size() > 0) + if (!vertexSource.Weights.empty()) { - UniqueWeights[3*i+0]=VertexSource.Weights[Vertex1]; - UniqueWeights[3*i+1]=VertexSource.Weights[Vertex2]; - UniqueWeights[3*i+2]=VertexSource.Weights[Vertex3]; + uniqueWeights[pos] = vertexSource.Weights[v1]; + uniqueWeights[pos+1] = vertexSource.Weights[v2]; + uniqueWeights[pos+2] = vertexSource.Weights[v3]; } - - //The indexvalues a just continuous numbers (0, 1, 2, 3, 4, 5, 6...) - UniqueFaceList[i].VertexIndices[0]=3*i+0; - UniqueFaceList[i].VertexIndices[1]=3*i+1; - UniqueFaceList[i].VertexIndices[2]=3*i+2; } - //_________________________________________________________________________________________ - //now we have the unique datas, but want them in the SubMesh, so we swap all the containers: - //if we don't have one of them, we just swap empty containers, so everything is ok - submesh.Faces.swap(UniqueFaceList); - submesh.Positions.swap(UniquePositions); - submesh.Normals.swap(UniqueNormals); - submesh.Tangents.swap(UniqueTangents); - submesh.Uvs.swap(UniqueUvs); - submesh.Weights.swap(UniqueWeights); + // Now we have the unique data, but want them in the SubMesh, so we swap all the containers. + // If we don't have one of them, we just swap empty containers, so everything is ok. + submesh.Faces.swap(uniqueFaceList); + submesh.Positions.swap(uniquePositions); + submesh.Normals.swap(uniqueNormals); + submesh.Tangents.swap(uniqueTangents); + submesh.Uvs.swap(uniqueUvs); + submesh.Weights.swap(uniqueWeights); - - - //------------- normalize weights ----------------------------- - //The Blender exporter doesn't care about whether the sum of all boneweights for a single vertex equals 1 or not, - //so we have to make this sure: - for(unsigned int VertexId=0; VertexId &weights = submesh.Weights[vertexId]; + + float sum = 0.0f; + for(size_t boneId=0, blen=weights.size(); boneId1.0f+0.05f) - { - //normalize all weights: - for(unsigned int BoneId=0; BoneId (1.0f + 0.05f))) + for(size_t boneId=0, blen=weights.size(); boneId& bones) const