Hello Guest

aiImportFile is null

  • 2 Replies
  • 5695 Views
*

Offline begin

  • *
  • 12
aiImportFile is null
« on: October 30, 2018, 20:48:12 »
Okey,  I learning from tutorials (source code https://github.com/lwjglgamedev/lwjglbook name directory chapter28)
But I have problem with load model

Error:

Code: [Select]
java.lang.Exception: Error loading model
at org.lwjglb.engine.loaders.assimp.StaticMeshesLoader.load(StaticMeshesLoader.java:37)
at org.lwjglb.engine.loaders.assimp.StaticMeshesLoader.load(StaticMeshesLoader.java:28)
at org.lwjglb.engine.graph.Renderer.init(Renderer.java:85)
at org.lwjglb.game.DummyGame.init(DummyGame.java:62)
at org.lwjglb.engine.GameEngine.init(GameEngine.java:65)
at org.lwjglb.engine.GameEngine.run(GameEngine.java:52)
at java.lang.Thread.run(Thread.java:748)
Exception in thread "GAME_LOOP_THREAD" java.lang.NullPointerException
at org.lwjglb.game.DummyGame.cleanup(DummyGame.java:210)
at org.lwjglb.engine.GameEngine.cleanup(GameEngine.java:96)
at org.lwjglb.engine.GameEngine.run(GameEngine.java:57)
at java.lang.Thread.run(Thread.java:748)

In the code, I did not change anything when I used it.

Code render:

Code: [Select]
bufferPassModelMatrix =  new Matrix4f();
        bufferPassMesh = StaticMeshesLoader.load("src/main/resources/models/buffer_pass_mess.obj", "src/main/resources/models")[0];

Code with methods:

Code: [Select]
public static Mesh[] load(String resourcePath, String texturesDir) throws Exception {
        System.out.println(resourcePath + " " + texturesDir);
        return load(resourcePath, texturesDir,
                aiProcess_GenSmoothNormals | aiProcess_JoinIdenticalVertices | aiProcess_Triangulate
                        | aiProcess_FixInfacingNormals);
    }

    public static Mesh[] load(String resourcePath, String texturesDir, int flags) throws Exception {
        AIScene aiScene = aiImportFile(resourcePath, flags);
        System.out.println(aiImportFile(resourcePath, flags) + " " + flags);
        if (aiScene == null) {
            throw new Exception("Error loading model");
        }

        int numMaterials = aiScene.mNumMaterials();
        PointerBuffer aiMaterials = aiScene.mMaterials();
        List<Material> materials = new ArrayList<>();
        for (int i = 0; i < numMaterials; i++) {
            AIMaterial aiMaterial = AIMaterial.create(aiMaterials.get(i));
            processMaterial(aiMaterial, materials, texturesDir);
        }

        int numMeshes = aiScene.mNumMeshes();
        PointerBuffer aiMeshes = aiScene.mMeshes();
        Mesh[] meshes = new Mesh[numMeshes];
        for (int i = 0; i < numMeshes; i++) {
            AIMesh aiMesh = AIMesh.create(aiMeshes.get(i));
            Mesh mesh = processMesh(aiMesh, materials);
            meshes[i] = mesh;
        }

        return meshes;
    }

I understand that aiImportFile returned me null
Code: [Select]
AIScene aiScene = aiImportFile(resourcePath, flags);
But I don't know why? Sorry for my toys errors, just I found nothing on the internet



*

Offline KaiHH

  • ****
  • 334
Re: aiImportFile is null
« Reply #1 on: October 30, 2018, 21:06:30 »
Three things:
- aiImportFile() takes in a file system path
- the path it is receiving ("src/main/resources/models/buffer_pass_mess.obj") is a relative path
- the working directory you are running the process with is very likely not <git-project-root>/chapter28 but just <git-project-root>
(where <git-project-root> denotes the directory you cloned the GitHub project into)

Change the working directory (can be changed in the run configuration of whatever IDE you are using) to the chapter28 directory and it will work.

*

Offline begin

  • *
  • 12
Re: aiImportFile is null
« Reply #2 on: October 31, 2018, 04:26:43 »
Thank you, I tried to reinstall the project and change the directory.
It all worked  :)