Assimp导入导出格式错误

Posted

技术标签:

【中文标题】Assimp导入导出格式错误【英文标题】:Assimp import export format error 【发布时间】:2018-03-28 20:42:49 【问题描述】:

我的格式中有一些 3D 模型,想将它们更改为标准格式并在我的项目中使用它们,所以我开始使用 Assimp 库。我创建aiScene 的代码是:

const aiScene* GenerateScene(int NumberOftexture, float *texture, int NumberOfVertex, double *verftex, int NumberOftri, double *tri) 

MATFile *pmat;
const char **dir;
const char *name;
int   ndir;
int   i;
aiScene* scene=new aiScene();

scene->mRootNode = new aiNode();


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

scene->mMaterials[0] = new aiMaterial();

scene->mMeshes = new aiMesh*[1];
scene->mMeshes[0] = nullptr;
scene->mNumMeshes = 1;
scene->mMeshes[0] = new aiMesh();
scene->mMeshes[0]->mMaterialIndex = 0;
scene->mRootNode->mMeshes = new unsigned int[1];
scene->mRootNode->mMeshes[0] = 0;
scene->mRootNode->mNumMeshes = 1;

auto pMesh = scene->mMeshes[0];

pMesh->mTextureCoords[0] = new aiVector3D[NumberOftexture];
pMesh->mNumUVComponents[0] = NumberOftexture;
for (int i = 0; i < NumberOftexture; i++)
    pMesh->mTextureCoords[0][i] = aiVector3D(texture[i], (float)texture[i + NumberOftexture], (float)texture[i + 2 * NumberOftexture]);

pMesh->mVertices = new aiVector3D[NumberOfVertex];
pMesh->mNumVertices = NumberOfVertex;
for (int i = 0; i < NumberOfVertex; i++)
    pMesh->mVertices[i] = aiVector3D((float)verftex[i], (float)verftex[i + NumberOfVertex], (float)verftex[i + 2 * NumberOfVertex]);

pMesh->mFaces = new aiFace[NumberOftri];
pMesh->mNumFaces = NumberOftri;

for (int i = 0; i < NumberOftri;i++) 
    aiFace& face = pMesh->mFaces[i];
    face.mIndices = new unsigned int[3];
    face.mNumIndices = 3;
    face.mIndices[0] = (int)tri[i];
    face.mIndices[1] = (int)tri[i + NumberOftri];
    face.mIndices[2] = (int)tri[i + 2* NumberOftri];


aiExportScene(scene, "collada", "D:\\myColladaFile.dae", 0);

return scene;

它运行正常,但是当我要使用 Assimp 库打开文件时出现错误。我的导入代码是

scene = aiImportFile(path, aiProcessPreset_TargetRealtime_MaxQuality);

我得到了错误:

Info,  T10040: Load D:\myColladaFile.dae
Info,  T10040: Found a matching importer for this file format: Collada Importer.
Info,  T10040: Import root directory is 'D:\'
Error, T10040: Collada: D:\myColladaFile.dae - Invalid data index (32500/32500) in primitive specification
Info,  T10040: Load D:\myColladaFile.dae
Info,  T10040: Found a matching importer for this file format: Collada Importer.
Info,  T10040: Import root directory is 'D:\'
Error, T10040: Collada: D:\myColladaFile.dae - Invalid data index (32500/32500) in primitive specification
Info,  T10040: Load D:\myColladaFile.dae
Info,  T10040: Found a matching importer for this file format: Collada Importer.
Info,  T10040: Import root directory is 'D:\'
Error, T10040: Collada: D:\myColladaFile.dae - Invalid data index (32500/32500) in primitive specification

但是当我以GLTF 格式导出时,它是正确的。那么如何以正确的格式导出和导入?

【问题讨论】:

【参考方案1】:

对我来说,这听起来像是 Asset-Importer-Lib 的一个错误。当 glTF-exporter 能够导出场景时,它应该是有效的。 作为一种解决方法,您可以尝试将其导出为 glFT 文件,使用搅拌器将其导入,然后将其导出为 collada 文件。

您能在Github/assimp 上创建问题报告吗?重现该问题的模型将非常棒。

【讨论】:

以上是关于Assimp导入导出格式错误的主要内容,如果未能解决你的问题,请参考以下文章

SQL Server 2005导入数据时出错,导入的是TXT文本格式

镜像网格和错误的 UV 贴图运行时导出

Allegro中导入&导出DXF文件

OBIEE 导出 csv 并导入 Access 时出现错误

DBF文件数据怎么导出为EXCEL?

oracle数据库的导入与导出