Skip to content

Commit

Permalink
closes #1894: use mesh name to name exported obj node.
Browse files Browse the repository at this point in the history
  • Loading branch information
kimkulling committed Apr 11, 2018
1 parent 6a0dc07 commit 9ca32b2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 32 deletions.
8 changes: 7 additions & 1 deletion code/ObjExporter.cpp
Expand Up @@ -439,8 +439,14 @@ void ObjExporter::AddMesh(const aiString& name, const aiMesh* m, const aiMatrix4
void ObjExporter::AddNode(const aiNode* nd, const aiMatrix4x4& mParent) {
const aiMatrix4x4& mAbs = mParent * nd->mTransformation;

aiMesh *cm( nullptr );
for(unsigned int i = 0; i < nd->mNumMeshes; ++i) {
AddMesh(nd->mName, pScene->mMeshes[nd->mMeshes[i]], mAbs);
cm = pScene->mMeshes[nd->mMeshes[i]];
if (nullptr != cm) {
AddMesh(cm->mName, pScene->mMeshes[nd->mMeshes[i]], mAbs);
} else {
AddMesh(nd->mName, pScene->mMeshes[nd->mMeshes[i]], mAbs);
}
}

for(unsigned int i = 0; i < nd->mNumChildren; ++i) {
Expand Down
54 changes: 23 additions & 31 deletions code/OptimizeGraph.cpp
Expand Up @@ -73,45 +73,43 @@ using namespace Assimp;
// ------------------------------------------------------------------------------------------------
// Constructor to be privately used by Importer
OptimizeGraphProcess::OptimizeGraphProcess()
: mScene()
, nodes_in()
, nodes_out()
, count_merged()
{}
: mScene()
, nodes_in()
, nodes_out()
, count_merged() {
// empty
}

// ------------------------------------------------------------------------------------------------
// Destructor, private as well
OptimizeGraphProcess::~OptimizeGraphProcess()
{}
OptimizeGraphProcess::~OptimizeGraphProcess() {
// empty
}

// ------------------------------------------------------------------------------------------------
// Returns whether the processing step is present in the given flag field.
bool OptimizeGraphProcess::IsActive( unsigned int pFlags) const
{
bool OptimizeGraphProcess::IsActive( unsigned int pFlags) const {
return (0 != (pFlags & aiProcess_OptimizeGraph));
}

// ------------------------------------------------------------------------------------------------
// Setup properties for the postprocessing step
void OptimizeGraphProcess::SetupProperties(const Importer* pImp)
{
// Setup properties for the post-processing step
void OptimizeGraphProcess::SetupProperties(const Importer* pImp) {
// Get value of AI_CONFIG_PP_OG_EXCLUDE_LIST
std::string tmp = pImp->GetPropertyString(AI_CONFIG_PP_OG_EXCLUDE_LIST,"");
AddLockedNodeList(tmp);
}

// ------------------------------------------------------------------------------------------------
// Collect new children
void OptimizeGraphProcess::CollectNewChildren(aiNode* nd, std::list<aiNode*>& nodes)
{
void OptimizeGraphProcess::CollectNewChildren(aiNode* nd, std::list<aiNode*>& nodes) {
nodes_in += nd->mNumChildren;

// Process children
std::list<aiNode*> child_nodes;
for (unsigned int i = 0; i < nd->mNumChildren; ++i) {

CollectNewChildren(nd->mChildren[i],child_nodes);
nd->mChildren[i] = NULL;
nd->mChildren[i] = nullptr;
}

// Check whether we need this node; if not we can replace it by our own children (warn, danger of incest).
Expand All @@ -130,13 +128,11 @@ void OptimizeGraphProcess::CollectNewChildren(aiNode* nd, std::list<aiNode*>& no

if (nd->mNumMeshes || !child_nodes.empty()) {
nodes.push_back(nd);
}
else {
} else {
delete nd; /* bye, node */
return;
}
}
else {
} else {

// Retain our current position in the hierarchy
nodes.push_back(nd);
Expand All @@ -160,14 +156,11 @@ void OptimizeGraphProcess::CollectNewChildren(aiNode* nd, std::list<aiNode*>& no
}
}
if (n == child->mNumMeshes) {

if (!join_master) {
join_master = child;
inv = join_master->mTransformation;
inv.Inverse();
}
else {

} else {
child->mTransformation = inv * child->mTransformation ;

join.push_back(child);
Expand Down Expand Up @@ -227,9 +220,10 @@ void OptimizeGraphProcess::CollectNewChildren(aiNode* nd, std::list<aiNode*>& no

delete[] nd->mChildren;

if (!child_nodes.empty())
if (!child_nodes.empty()) {
nd->mChildren = new aiNode*[child_nodes.size()];
else nd->mChildren = NULL;
}
else nd->mChildren = nullptr;
}

nd->mNumChildren = static_cast<unsigned int>(child_nodes.size());
Expand All @@ -246,9 +240,8 @@ void OptimizeGraphProcess::CollectNewChildren(aiNode* nd, std::list<aiNode*>& no
}

// ------------------------------------------------------------------------------------------------
// Execute the postprocessing step on the given scene
void OptimizeGraphProcess::Execute( aiScene* pScene)
{
// Execute the post-processing step on the given scene
void OptimizeGraphProcess::Execute( aiScene* pScene) {
DefaultLogger::get()->debug("OptimizeGraphProcess begin");
nodes_in = nodes_out = count_merged = 0;
mScene = pScene;
Expand All @@ -268,7 +261,6 @@ void OptimizeGraphProcess::Execute( aiScene* pScene)

for (unsigned int i = 0; i < pScene->mNumAnimations; ++i) {
for (unsigned int a = 0; a < pScene->mAnimations[i]->mNumChannels; ++a) {

aiNodeAnim* anim = pScene->mAnimations[i]->mChannels[a];
locked.insert(AI_OG_GETKEY(anim->mNodeName));
}
Expand Down Expand Up @@ -349,7 +341,7 @@ void OptimizeGraphProcess::Execute( aiScene* pScene)
}

// ------------------------------------------------------------------------------------------------
// Buidl a LUT of all instanced meshes
// Build a LUT of all instanced meshes
void OptimizeGraphProcess::FindInstancedMeshes (aiNode* pNode)
{
for (unsigned int i = 0; i < pNode->mNumMeshes;++i) {
Expand Down

0 comments on commit 9ca32b2

Please sign in to comment.