ASSIMPを使用してWavefront objモデルを読み込もうとしています。ただし、mtl マテリアルの色が機能しません。ロード方法は知っていますが、各頂点に対応する色を取得する方法がわかりません。(Kd rgb)
usemtl material_11
f 7//1 8//1 9//2
f 10//1 11//1 12//2
たとえば、上記の Wavefront obj スニペットは、これらの頂点が material_11 を使用することを意味します。
Q:各頂点に対応するマテリアルを取得するにはどうすればよいですか?
エラー
Wavefront objマテリアルが正しい頂点にありません:
元のモデル (ASSIMP モデル ビューアーでレンダリング):
私のコードでレンダリングされたモデル:
コード:
mtl マテリアルの色をロードするために使用するコード:
std::vector<color4<float>> colors = std::vector<color4<float>>();
...
for (unsigned int i = 0; i < scene->mNumMeshes; i++)
{
const aiMesh* model = scene->mMeshes[i];
const aiMaterial *mtl = scene->mMaterials[model->mMaterialIndex];
color4<float> color = color4<float>(1.0f, 1.0f, 1.0f, 1.0f);
aiColor4D diffuse;
if (AI_SUCCESS == aiGetMaterialColor(mtl, AI_MATKEY_COLOR_DIFFUSE, &diffuse))
color = color4<float>(diffuse.r, diffuse.g, diffuse.b, diffuse.a);
colors.push_back(color);
...
}
頂点を作成するコード:
vertex* vertices_arr = new vertex[positions.size()];
for (unsigned int i = 0; i < positions.size(); i++)
{
vertices_arr[i].SetPosition(positions.at(i));
vertices_arr[i].SetTextureCoordinate(texcoords.at(i));
}
// Code for setting vertices colors (I'm just setting it in ASSIMP vertices order, since I don't know how to set it in the correct order).
for (unsigned int i = 0; i < scene->mNumMeshes; i++)
{
const unsigned int vertices_size = scene->mMeshes[i]->mNumVertices;
for (unsigned int k = 0; k < vertices_size; k++)
{
vertices_arr[k].SetColor(colors.at(i));
}
}
編集:
モデルの頂点の位置も正しく読み込まれていないようです。顔カリングを無効にして背景色を変更しても。