Attempt improve UV conversion
TODO: still not right, also normals completely messed uppull/5522/head
parent
d890384452
commit
2767cc8e95
|
@ -146,18 +146,27 @@ void USDImporterImplTinyusdz::uvsForMesh(
|
|||
const tinyusdz::tydra::RenderScene &render_scene,
|
||||
aiScene *pScene,
|
||||
size_t meshIdx) {
|
||||
if (render_scene.meshes[meshIdx].facevaryingTexcoords.size() < 1) {
|
||||
const size_t uvSlotsCount = render_scene.meshes[meshIdx].facevaryingTexcoords.size();
|
||||
if (uvSlotsCount < 1) {
|
||||
return;
|
||||
}
|
||||
const auto uvsForSlot0 = render_scene.meshes[meshIdx].facevaryingTexcoords.at(0);
|
||||
if (render_scene.meshes[meshIdx].points.size() != uvsForSlot0.size()) {
|
||||
return;
|
||||
}
|
||||
pScene->mMeshes[meshIdx]->mNumUVComponents[0] = uvSlotsCount;
|
||||
pScene->mMeshes[meshIdx]->mTextureCoords[0] = new aiVector3D[pScene->mMeshes[meshIdx]->mNumVertices];
|
||||
for (size_t j = 0; j < pScene->mMeshes[meshIdx]->mNumVertices; ++j) {
|
||||
pScene->mMeshes[meshIdx]->mTextureCoords[0][j].x = uvsForSlot0[j][0];
|
||||
pScene->mMeshes[meshIdx]->mTextureCoords[0][j].y = uvsForSlot0[j][1];
|
||||
for (size_t uvSlotIdx = 0; uvSlotIdx < pScene->mMeshes[meshIdx]->mNumUVComponents[0]; ++uvSlotIdx) {
|
||||
const auto uvsForSlot = render_scene.meshes[meshIdx].facevaryingTexcoords.at(uvSlotIdx);
|
||||
size_t faceVertIdxOffset = 0;
|
||||
for (size_t faceIdx = 0; faceIdx < pScene->mMeshes[meshIdx]->mNumFaces; ++faceIdx) {
|
||||
for (size_t j = 0; j < pScene->mMeshes[meshIdx]->mFaces[faceIdx].mNumIndices; ++j) {
|
||||
size_t vertIdx = pScene->mMeshes[meshIdx]->mFaces[faceIdx].mIndices[j];
|
||||
pScene->mMeshes[meshIdx]->mTextureCoords[uvSlotIdx][vertIdx].x = uvsForSlot[faceVertIdxOffset + j][0];
|
||||
pScene->mMeshes[meshIdx]->mTextureCoords[uvSlotIdx][vertIdx].y = uvsForSlot[faceVertIdxOffset + j][1];
|
||||
}
|
||||
faceVertIdxOffset += pScene->mMeshes[meshIdx]->mFaces[faceIdx].mNumIndices;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Assimp
|
||||
|
||||
#endif // !! ASSIMP_BUILD_NO_USD_IMPORTER
|
||||
|
|
Loading…
Reference in New Issue