dmsurti / AssimpKit

A library (macOS, iOS) that converts the files supported by Assimp to Scene Kit scenes.
http://assimpkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
474 stars 54 forks source link

Error in AssimpImporter when loading DAE model #58

Closed jirisamek closed 6 years ago

jirisamek commented 6 years ago

Hi @dmsurti,

I am trying to load house.dae with AssimpKit but during the loading there is an error. XCode stops in

(SCNGeometrySource *)
makeVertexGeometrySourceForNode:(const struct aiNode *)aiNode
                        inScene:(const struct aiScene *)aiScene
                  withNVertices:(int)nVertices
{
    float scnVertices[nVertices * 3];
    int verticesCounter = 0;
    for (int i = 0; i < aiNode->mNumMeshes; i++)
    {
        int aiMeshIndex = aiNode->mMeshes[i];
        const struct aiMesh *aiMesh = aiScene->mMeshes[aiMeshIndex];
        // create SCNGeometry source for aiMesh vertices, normals, texture
        // coordinates
        for (int j = 0; j < aiMesh->mNumVertices; j++)
        {
            const struct aiVector3D *aiVector3D = &aiMesh->mVertices[j];
            scnVertices[verticesCounter++] = aiVector3D->x;
            scnVertices[verticesCounter++] = aiVector3D->y;
            scnVertices[verticesCounter++] = aiVector3D->z;
        }
    }

in AssimpImporter

On the row scnVertices[verticesCounter++] = aiVector3D->z; with Thread 27: EXC_BAD_ACCESS (code=2, address=0x1700fc000)

During loading, there is also message printed in the console: [SceneKit] Error: C3DMeshElementSetPrimitives invalid index buffer size AssimpKit was compiled with optimization - stepping may behave oddly; variables may not be available.

I am able to open dae in Blender 2.79 and in Cinema4D R18. Command line assimp info can load the dae and give this result house_info.txt.

I would appreciate any kind of clue. What could be wrong and where? Can it be fixed in model file, AssimpKit, or in Assimp library?

dmsurti commented 6 years ago

@jirisamek I am working on a fix for this problem, thanks for reporting this. See PR #59. I think I may have to split the elements into smaller buffers internally, as this fix works for #56, but right now not for #58; but this is the correct fix with more implementation tweaks required for your case.

Are you OK with me using the model you have provided as part of AssimpKit test cases? The AssimpKit licenses explicitly mention the usage of such files only for testing purpose. Let me know. Thanks!

jirisamek commented 6 years ago

@dmsurti thank you very much for quick response. The model is not mine. I have downloaded it from https://free3d.com/3d-model/cyprys-house-23761.html, and the licence tag says: "Commercial use License". I didn't find actual text of license so I don't know if it is possible to use it in open source as model in test cases. Also this specific dae seems to have broken textures/materials.

dmsurti commented 6 years ago

Fixed in #59. In addition to mallocing scene buffers, it also requires ignoring the faces which are not triangulated!

This model contains material colors and/or embedded textures, which is being fixed in #62 and #64.

screenshot 2017-09-01 15 48 41
dmsurti commented 6 years ago

With #64, the house now has textures as well.

Also this specific dae seems to have broken textures/materials.

@jirisamek Actually this file has all colors for material properties, #64 ensure correct texture and colors are applied to material properties.

screenshot 2017-09-02 18 06 24
azolyoung commented 6 years ago

Hi, I've same issue with newest code in master branch .

It's throw exc_bad_access in the makeTangentGeometrySourceForNode: SCNGeometrySource *tangentSource = [SCNGeometrySource geometrySourceWithData:[NSData dataWithBytes:scnTangents length:nVertices * 3 * sizeof(float)] semantic:SCNGeometrySourceSemanticTangent vectorCount:nVertices floatComponents:YES componentsPerVector:3 bytesPerComponent:sizeof(float) dataOffset:0 dataStride:3 * sizeof(float)]; But this crash is only happen on iOS8, if I running it in iOS11, everything work fine

azolyoung commented 6 years ago

I'm using a model by obj+mtl+jpg

azolyoung commented 6 years ago

oh, I found the reason why it would crash on iOS 8, because in , it using a constant that only available after iOS 10, it is SCNGeometrySourceSemanticTangent, here is the define: FOUNDATION_EXTERN SCNGeometrySourceSemantic const SCNGeometrySourceSemanticTangent API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0));

dmsurti commented 6 years ago

@azolyoung AssimpKit minimum iOS requirement is iOS 10.0 or later, which is listed in the README.md and in the project home page.