Skip to content

Commit

Permalink
Merge branch 'fix_issue_joinIdenticalVertices_notNeeded' of https://g…
Browse files Browse the repository at this point in the history
…ithub.com/thomasbiang/assimp into thomasbiang-fix_issue_joinIdenticalVertices_notNeeded
  • Loading branch information
kimkulling committed Sep 7, 2019
2 parents 812397d + 3d0775e commit 336ae0e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 36 deletions.
5 changes: 4 additions & 1 deletion code/Common/Exporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,10 @@ aiReturn Exporter::Export( const aiScene* pScene, const char* pFormatId, const c
}

ExportProperties emptyProperties; // Never pass NULL ExportProperties so Exporters don't have to worry.
exp.mExportFunction(pPath,pimpl->mIOSystem.get(),scenecopy.get(), pProperties ? pProperties : &emptyProperties);
ExportProperties* pProp = pProperties ? (ExportProperties*)pProperties : &emptyProperties;
pProp->SetPropertyBool("bJoinIdenticalVertices", must_join_again);
exp.mExportFunction(pPath,pimpl->mIOSystem.get(),scenecopy.get(), pProp);
exp.mExportFunction(pPath,pimpl->mIOSystem.get(),scenecopy.get(), pProp);

pimpl->mProgressHandler->UpdateFileWrite(4, 4);
} catch (DeadlyExportError& err) {
Expand Down
68 changes: 33 additions & 35 deletions code/FBX/FBXExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <vector>
#include <array>
#include <unordered_set>
#include <numeric>

// RESOURCES:
// https://code.blender.org/2013/08/fbx-binary-file-format-specification/
Expand Down Expand Up @@ -1005,6 +1006,9 @@ void FBXExporter::WriteObjects ()
object_node.EndProperties(outstream, binary, indent);
object_node.BeginChildren(outstream, binary, indent);

bool bJoinIdenticalVertices = mProperties->GetPropertyBool("bJoinIdenticalVertices", true);
std::vector<std::vector<int32_t>> vVertexIndice;//save vertex_indices as it is needed later

// geometry (aiMesh)
mesh_uids.clear();
indent = 1;
Expand All @@ -1031,21 +1035,35 @@ void FBXExporter::WriteObjects ()
std::vector<int32_t> vertex_indices;
// map of vertex value to its index in the data vector
std::map<aiVector3D,size_t> index_by_vertex_value;
int32_t index = 0;
for (size_t vi = 0; vi < m->mNumVertices; ++vi) {
aiVector3D vtx = m->mVertices[vi];
auto elem = index_by_vertex_value.find(vtx);
if (elem == index_by_vertex_value.end()) {
vertex_indices.push_back(index);
index_by_vertex_value[vtx] = index;
flattened_vertices.push_back(vtx[0]);
flattened_vertices.push_back(vtx[1]);
flattened_vertices.push_back(vtx[2]);
++index;
} else {
vertex_indices.push_back(int32_t(elem->second));
if(bJoinIdenticalVertices){
int32_t index = 0;
for (size_t vi = 0; vi < m->mNumVertices; ++vi) {
aiVector3D vtx = m->mVertices[vi];
auto elem = index_by_vertex_value.find(vtx);
if (elem == index_by_vertex_value.end()) {
vertex_indices.push_back(index);
index_by_vertex_value[vtx] = index;
flattened_vertices.push_back(vtx[0]);
flattened_vertices.push_back(vtx[1]);
flattened_vertices.push_back(vtx[2]);
++index;
} else {
vertex_indices.push_back(int32_t(elem->second));
}
}
}
else { // do not join vertex, respect the export flag
vertex_indices.resize(m->mNumVertices);
std::iota(vertex_indices.begin(), vertex_indices.end(), 0);
for(unsigned int v = 0; v < m->mNumVertices; ++ v) {
aiVector3D vtx = m->mVertices[v];
flattened_vertices.push_back(vtx.x);
flattened_vertices.push_back(vtx.y);
flattened_vertices.push_back(vtx.z);
}
}
vVertexIndice.push_back(vertex_indices);

FBX::Node::WritePropertyNode(
"Vertices", flattened_vertices, outstream, binary, indent
);
Expand Down Expand Up @@ -1748,28 +1766,8 @@ void FBXExporter::WriteObjects ()
// connect it
connections.emplace_back("C", "OO", deformer_uid, mesh_uids[mi]);

// we will be indexing by vertex...
// but there might be a different number of "vertices"
// between assimp and our output FBX.
// this code is cut-and-pasted from the geometry section above...
// ideally this should not be so.
// ---
// index of original vertex in vertex data vector
std::vector<int32_t> vertex_indices;
// map of vertex value to its index in the data vector
std::map<aiVector3D,size_t> index_by_vertex_value;
int32_t index = 0;
for (size_t vi = 0; vi < m->mNumVertices; ++vi) {
aiVector3D vtx = m->mVertices[vi];
auto elem = index_by_vertex_value.find(vtx);
if (elem == index_by_vertex_value.end()) {
vertex_indices.push_back(index);
index_by_vertex_value[vtx] = index;
++index;
} else {
vertex_indices.push_back(int32_t(elem->second));
}
}
//computed before
std::vector<int32_t>& vertex_indices = vVertexIndice[mi];

// TODO, FIXME: this won't work if anything is not in the bind pose.
// for now if such a situation is detected, we throw an exception.
Expand Down

0 comments on commit 336ae0e

Please sign in to comment.