gpt4 book ai didi

c++ - Assimp导入导出格式错误

转载 作者:太空宇宙 更新时间:2023-11-04 12:55:47 25 4
gpt4 key购买 nike

我有一些我的格式的 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 格式时它是正确的。那么如何以正确的格式导出和导入?

最佳答案

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

你能在 Github/assimp 上创建一个问题报告吗?请?重现该问题的模型真的很棒。

关于c++ - Assimp导入导出格式错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46785365/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com