Cannot generate LOD for model

Hello,
I would like to use the built in jme LOD generator, but am running into issues on several models.

Generating LOD for KB3D_NTT_BldgMD_J_BuildingA_0
Generating LOD level percentages: [0.25, 0.5, 0.75]
[2021-02-27 12:17:46] [SEVERE ] Failed to import model 
java.lang.IllegalArgumentException: Vertex 16582 : (-30.119263, -4.94582, -26.513035)is not part of triangleTriangle{
16507 : 16507 : (-30.126923, -4.9177284, -26.502926)
16583 : 16583 : (-30.10904, -4.9356003, -26.513035)
16518 : 16518 : (-30.13353, -4.931549, -26.502632)
}
	at jme3tools.optimize.LodGenerator$Triangle.getVertexIndex(LodGenerator.java:225)
	at jme3tools.optimize.LodGenerator.collapse(LodGenerator.java:911)
	at jme3tools.optimize.LodGenerator.computeLods(LodGenerator.java:571)
	at jme3tools.optimize.LodGenerator.bakeLods(LodGenerator.java:619)
	at io.tlf.outside.client.gm.GMModelData.genLodLevels(GMModelData.java:521)

I am using the following code to generate the LOD levels:

public void genLod(int levels) {
        if (levels <= 0) {
            return;
        }
        for (Geometry geo : this.meshes) {
            genLodLevels(geo, levels);
        }
    }

    private void genLodLevels(Geometry geo, int levels) {
        System.out.println("Generating LOD for " + geo.getName());
        LodGenerator.TriangleReductionMethod method = LodGenerator.TriangleReductionMethod.PROPORTIONAL;
        LodGenerator lod = new LodGenerator(geo);
        float[] levelPercents = new float[levels];
        for (int i = 0; i < levels; i++) {
            levelPercents[i] = (((float) i) + 1f) / (((float) levels) + 1f);
        }
        System.out.println("Generating LOD level percentages: " + Arrays.toString(levelPercents));
        try {
            lod.bakeLods(method, levelPercents);
        } catch (Exception ex) {
            LOGGER.log(Level.WARNING, "Failed to generate LOD for geo: " + geo.getName(), ex);
        }
    }

Is there something I am doing wrong? It works for some simple models, but not complex ones. Mostly testing with Kitbash buildings.

just a Guess, but looks like for some reason, when it try create triangle, there was some vertex that was “alone” without triangle. Maybe its issue for models that have vertex that is Line/point but not triangle.

In your place i would also just write Utility for now to just remove “line/point” verts before creating LODs

Also you can try with Blender’s “Delete Loose” and “Merge by Distance” options to clean up model before exporting to JME.

3 Likes

The cleanup advice above is good. I had a lot of fun playing with various kitbash model sets a long time ago and almost universally they seemed to be poorly crafted at the mesh level. They almost always required some cleanup.

…I don’t know the psychology of why that is. And maybe I was just lucky in the few I tried.

1 Like

I’m not sure. It seems like it is the person who makes them. Some of the new kitbash kits have great meshes, others seemingly need a lot of work. Still great kits, especially if you can get them on sale.

I will try the cleanup in blender. When I get some time I may look into the LOD generator and see if there is anything that can be done to make that a warning and still make a usable reduced mesh.

1 Like