2015-05-14 74 views
0

我們正在開發一個可以創建,導入和導出自定義3D模型的自定義3D引擎(OpenGL),並且我們正在使用Assimp導入/導出。此時,導入效果很好,但在導出時,我們無法儲存除默認值以外的任何材料。雖然Assimp的網站和其他網站有大量的關於進口的信息,但很少有沒有關於出口的文件。我們設法解決了大部分出口流程,但似乎沒有任何方法可以設定Assimp的aiMaterials的顏色值。使用Assimp導出3D模型及其顏色信息

Assimp的文檔解釋瞭如何從現有的材料中的顏色信息,即..

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

mat->獲取(AI_MATKEY_COLOR_DIFFUSE,顏色); *

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; 

回答

0

嘗試:

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'。正確顯示紋理所需的額外參數(除紋理路徑外)(因爲現在紋理不顯示,只有顏色)?

+0

我明白了。我沒有紋理coords。所以出口紋理也起作用。至少對我來說) – Letos