【问题标题】:Exporting 3d Models and their color information using Assimp使用 Assimp 导出 3d 模型及其颜色信息
【发布时间】:2015-07-26 10:02:22
【问题描述】:

我们正在开发一个自定义 3d 引擎 (OpenGL),人们可以在其中创建、导入和导出自定义 3d 模型,并且我们正在使用 Assimp 进行导入/导出。此时,导入效果很好,但在导出时,我们无法保存除默认材料以外的任何材料。虽然 Assimp 的网站和其他网站有大量关于导入的信息,但几乎没有关于导出的文档。我们设法完成了大部分导出过程,但似乎没有任何方法可以设置 Assimp 的 aiMaterials 的颜色值。

Assimp 的文档解释了如何从现有材料中获取颜色信息,即..

*aiColor3D 颜色 (0.f,0.f,0.f);

mat->Get(AI_MATKEY_COLOR_DIFFUSE,color);*

http://assimp.sourceforge.net/lib_html/materials.html

但不包括任何关于基于模型材料的设置颜色信息。 (仅供参考,我们所有的模型都是纯色;没有纹理)。如果有人在出口材料/颜色方面有任何经验,我们将不胜感激。这就是我们现在所拥有的......

//Create an Assimp node element to be a container object to hold all graphic information

scene.mRootNode = new aiNode();

scene.mMaterials = new aiMaterial*[ 1 ];
scene.mMaterials[ 0 ] = nullptr;
scene.mNumMaterials = 1;

mAllChildren.clear();
//Get ALL children on the scene (including down the hierarchy)
FindAllChildren(CScriptingUtils::GetDoc()->GetScene());
std::vector<std::weak_ptr<CNode>> children = mAllChildren;
int size = (int)children.size();
scene.mMaterials[ 0 ] = new aiMaterial();

scene.mRootNode->mMeshes = new unsigned int[ size ];
scene.mRootNode->mNumMeshes = size;
scene.mMeshes = new aiMesh*[ size ];
scene.mNumMeshes = size;

//Iterate through all children, retrieve their graphical information and push it into the Assimp structure
for(int i = 0; i < size; i++)
{
    std::shared_ptr<CNode> childNode = children[i].lock();
    scene.mRootNode->mMeshes[ i ] = i;
    scene.mMeshes[ i ] = nullptr;
    scene.mMeshes[ i ] = new aiMesh();
    scene.mMeshes[ i ]->mMaterialIndex = 0;

    aiMaterial* mat = scene.mMaterials[0];

我们需要做一些类似的事情..

    mat.color = childNode.color; 

【问题讨论】:

    标签: opengl 3d export assimp


    【解决方案1】:

    试试看:

    mat->AddProperty<aiColor3D>(color, 1, AI_MATKEY_COLOR_DIFFUSE);
    

    这对我有帮助。另外,我尝试导出纹理

    newMat->AddProperty(matName, AI_MATKEY_NAME);
    newMat->AddProperty(texturePath, AI_MATKEY_TEXTURE_DIFFUSE(0));
    

    其中“matName”和“texturePath”类型是“aiString”。正确显示纹理(因为现在不显示纹理,仅显示颜色)需要哪些附加参数(纹理路径除外)?

    【讨论】:

    • 我明白了。我没有纹理坐标。所以导出纹理也可以。至少对我来说)
    猜你喜欢
    • 2018-03-05
    • 2018-05-11
    • 2019-01-07
    • 2013-07-15
    • 2013-11-19
    • 1970-01-01
    • 2015-02-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多