码迷,mamicode.com
首页 > 其他好文 > 详细

-OPENGL5-

时间:2020-02-23 18:00:51      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:als   dump   span   stp   class   star   height   aci   signed   

ASSIMP构建大纲:

因为递归的原因有必要把大纲还原,类似katana和maya大纲一样

以maya为例:(输出的时候别导出obj,fbx可以保护层级,abc也可以,但是现在assimp不支持,回头可以用abc api 搞一个)

技术图片

 

所以我在函数原型加入一个pwd

void processNode(aiNode * node, const aiScene* scene,string pwd);
技术图片
#include <iostream>
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
#include <string>
using namespace std;

void processNode(aiNode * node, const aiScene* scene, string pwd);
int main(){
    Assimp::Importer import;
    string path = "maya.fbx";
    const aiScene * scene = import.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs);
    if(!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode)
    {
        cout << "ERROR::ASSIMP::" << import.GetErrorString() << endl;

    }

    string directory = path.substr(0, path.find_last_of(/));
    cout << directory << endl;

    // Get Root Node
    aiNode * node = scene->mRootNode;
    processNode(node,scene,"/");





    return 0;
}

void processNode(aiNode * node, const aiScene* scene,string pwd){

    cout << ">>LOOP At Node:" << pwd <<" WORLD MATRIX:" << endl;
    aiMatrix4x4 mat =  node->mTransformation;
    cout << "{\n";
    cout << "\t" <<mat.a1 << " " << mat.a2 << " " << mat.a3 << " " << mat.a4 << endl;
    cout << "\t" <<mat.b1 << " " << mat.b2 << " " << mat.b3 << " " << mat.b4 << endl;
    cout << "\t" <<mat.c1 << " " << mat.c2 << " " << mat.c3 << " " << mat.c4 << endl;
    cout << "\t" <<mat.d1 << " " << mat.d2 << " " << mat.d3 << " " << mat.d4 << endl;
    cout << "}\n";

    for(unsigned int i = 0; i < node->mNumMeshes; i++)
    {
        aiMesh *mesh = scene->mMeshes[node->mMeshes[i]];

        // mesh points
        cout <<">>Num points:" <<mesh->mNumVertices<< endl;

        // Dump materials infos
        aiMaterial *mat = scene->mMaterials[mesh->mMaterialIndex];
        cout << ">>Get Mesh Name: "<<mesh->mName.C_Str()<< " <->  MaterialName: " << mat->GetName().C_Str()  << endl;
        cout << ">>start dumping the texture:\n";
        cout << "{\n";
        for(unsigned int i = 0; i < mat->GetTextureCount(aiTextureType_DIFFUSE); i++)
        {
            aiString str;
            mat->GetTexture(aiTextureType_DIFFUSE, i, &str);
            cout << "\tdiffuseTexture: "<<str.C_Str() << endl;
        }
        for(unsigned int i = 0; i < mat->GetTextureCount(aiTextureType_NORMALS); i++)
        {
            aiString str;
            mat->GetTexture(aiTextureType_NORMALS, i, &str);
            cout << "\tNormalTexture: "<<str.C_Str() << endl;
        }
        for(unsigned int i = 0; i < mat->GetTextureCount(aiTextureType_AMBIENT); i++)
        {
            aiString str;
            mat->GetTexture(aiTextureType_AMBIENT, i, &str);
            cout << "\tAmbientTexture: "<<str.C_Str() << endl;
        }
        for(unsigned int i = 0; i < mat->GetTextureCount(aiTextureType_OPACITY); i++)
        {
            aiString str;
            mat->GetTexture(aiTextureType_OPACITY, i, &str);
            cout << "\tOpacityTexture: "<<str.C_Str() << endl;
        }
        for(unsigned int i = 0; i < mat->GetTextureCount(aiTextureType_SPECULAR); i++)
        {
            aiString str;
            mat->GetTexture(aiTextureType_SPECULAR, i, &str);
            cout << "\tSpecularTexture: "<<str.C_Str() << endl;
        }
        for(unsigned int i = 0; i < mat->GetTextureCount(aiTextureType_HEIGHT); i++)
        {
            aiString str;
            mat->GetTexture(aiTextureType_HEIGHT, i, &str);
            cout << "\tHeightTexture: "<<str.C_Str() << endl;
        }
        for(unsigned int i = 0; i < mat->GetTextureCount(aiTextureType_UNKNOWN); i++)
        {
            aiString str;
            mat->GetTexture(aiTextureType_HEIGHT, i, &str);
            cout << "\tUnkownTexture: "<<str.C_Str() << endl;
        }
        cout << "}\n";

    }

    for(unsigned int i = 0; i < node->mNumChildren; i++)
    {

        string pathName =  pwd + node->mChildren[i]->mName.C_Str();
        pathName += "/";
        processNode(node->mChildren[i], scene,pathName);
    }


    cout << "\n";

}
main.cpp

 

DUMP:

maya.fbx
>>LOOP At Node:/ WORLD MATRIX:
{
    1 0 0 0
    0 1 0 0
    0 0 1 0
    0 0 0 1
}
>>LOOP At Node:/Geometry/ WORLD MATRIX:
{
    1 0 0 0
    0 1 0 0
    0 0 1 0
    0 0 0 1
}
>>LOOP At Node:/Geometry/part1/ WORLD MATRIX:
{
    1 0 0 0
    0 1 0 0
    0 0 1 0
    0 0 0 1
}
>>LOOP At Node:/Geometry/part1/pSphere1/ WORLD MATRIX:
{
    1 0 0 0
    0 1 0 0
    0 0 1 0
    0 0 0 1
}
>>Num points:1560
>>Get Mesh Name: pSphere1 <->  MaterialName: lambert1
>>start dumping the texture:
{
}

>>LOOP At Node:/Geometry/part1/pSphere2/ WORLD MATRIX:
{
    1 0 0 0
    0 1 0 2.17013
    0 0 1 0
    0 0 0 1
}
>>Num points:1560
>>Get Mesh Name: pSphere2 <->  MaterialName: lambert1
>>start dumping the texture:
{
}

>>LOOP At Node:/Geometry/part1/pSphere3/ WORLD MATRIX:
{
    1 0 0 0
    0 1 0 4.34026
    0 0 1 0
    0 0 0 1
}
>>Num points:1560
>>Get Mesh Name: pSphere3 <->  MaterialName: lambert1
>>start dumping the texture:
{
}

>>LOOP At Node:/Geometry/part1/pSphere4/ WORLD MATRIX:
{
    1 0 0 0
    0 1 0 6.51039
    0 0 1 0
    0 0 0 1
}
>>Num points:1560
>>Get Mesh Name: pSphere4 <->  MaterialName: lambert1
>>start dumping the texture:
{
}


>>LOOP At Node:/Geometry/part2/ WORLD MATRIX:
{
    1 0 0 0
    0 1 0 0
    0 0 1 0
    0 0 0 1
}
>>LOOP At Node:/Geometry/part2/pSphere5/ WORLD MATRIX:
{
    1 0 0 0
    0 1 0 8.68052
    0 0 1 0
    0 0 0 1
}
>>Num points:1560
>>Get Mesh Name: pSphere5 <->  MaterialName: lambert1
>>start dumping the texture:
{
}

>>LOOP At Node:/Geometry/part2/pSphere6/ WORLD MATRIX:
{
    1 0 0 0
    0 1 0 10.8507
    0 0 1 0
    0 0 0 1
}
>>Num points:1560
>>Get Mesh Name: pSphere6 <->  MaterialName: lambert1
>>start dumping the texture:
{
}

>>LOOP At Node:/Geometry/part2/pSphere7/ WORLD MATRIX:
{
    1 0 0 0
    0 1 0 13.0208
    0 0 1 0
    0 0 0 1
}
>>Num points:1560
>>Get Mesh Name: pSphere7 <->  MaterialName: lambert1
>>start dumping the texture:
{
}

 

-OPENGL5-

标签:als   dump   span   stp   class   star   height   aci   signed   

原文地址:https://www.cnblogs.com/gearslogy/p/12350580.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!