【发布时间】: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);*
但不包括任何关于基于模型材料的设置颜色信息。 (仅供参考,我们所有的模型都是纯色;没有纹理)。如果有人在出口材料/颜色方面有任何经验,我们将不胜感激。这就是我们现在所拥有的......
//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;
【问题讨论】: