我的格式有一些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 Library打开文件时,我收到了错误。我的导入代码是
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
格式导出时,它是正确的。那么如何以正确的格式导出和导入?
答案 0 :(得分:0)
这对我来说听起来像是Asset-Importer-Lib的错误。当glTF导出器能够导出场景时,它应该是有效的。 作为一种解决方法,您可以尝试将其导出为glFT文件,使用blender导入它并将其导出为collada文件。
您能否在Github/assimp创建问题报告?重现这个问题的模型真的很棒。