Skip to content

Commit

Permalink
disable LODs since they are broken and never used
Browse files Browse the repository at this point in the history
- JME's LodControl is not suitable, even with lowered thresholds
- also sets levels independently for each submesh
- a mesh split among subgroups due to number of triangles isn't handled
  • Loading branch information
Trass3r committed Jan 28, 2025
1 parent c7527e5 commit 6e16bfb
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/toniarts/openkeeper/tools/convert/KmfModelLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import com.jme3.scene.Node;
import com.jme3.scene.VertexBuffer;
import com.jme3.scene.VertexBuffer.Type;
import com.jme3.scene.control.LodControl;
import com.jme3.texture.Texture;
import com.jme3.util.BufferUtils;
import com.jme3.util.mikktspace.MikktspaceTangentGenerator;
Expand Down Expand Up @@ -220,7 +219,8 @@ private Node handleMesh(toniarts.openkeeper.tools.convert.kmf.Mesh sourceMesh, M
//Set the buffers
mesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
mesh.setBuffer(lodLevels[0]);
mesh.setLodLevels(lodLevels);
// LODs are broken
//mesh.setLodLevels(lodLevels); // the documentation is wrong, the renderer uses LOD 0 instead of IB
mesh.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));
mesh.setBuffer(Type.Normal, 3, BufferUtils.createFloatBuffer(normals));
mesh.setStatic();
Expand Down Expand Up @@ -429,14 +429,18 @@ private Node handleAnim(Anim anim, Map<Integer, List<Material>> materials) {
var lodLevels = createIndices(subMesh.getTriangles());

//Set the buffers
mesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
mesh.setBuffer(Type.BindPosePosition, 3, BufferUtils.createFloatBuffer(vertices));
mesh.setBuffer(lodLevels[0]);
mesh.setLodLevels(lodLevels);
// LODs are broken
//mesh.setLodLevels(lodLevels); // the documentation is wrong, the renderer uses LOD 0 instead of IB
mesh.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));
mesh.setBuffer(Type.Normal, 3, BufferUtils.createFloatBuffer(normals));
mesh.setBuffer(Type.BindPoseNormal, 3, BufferUtils.createFloatBuffer(normals));
mesh.setStreamed();
var normalsBuffer = BufferUtils.createFloatBuffer(normals);
mesh.setBuffer(Type.Normal, 3, normalsBuffer);
mesh.setBuffer(Type.BindPoseNormal, 3, normalsBuffer);

// only position buffer is dynamic
mesh.setStatic();
mesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));

// Create geometry
Geometry geom = createGeometry(subMeshIndex, anim.getName(), mesh, materials, subMesh.getMaterialIndex());
Expand Down Expand Up @@ -515,9 +519,9 @@ private Geometry createGeometry(int subMeshIndex, String meshName, Mesh mesh, Ma
//Create geometry
var geom = new Geometry(meshName + '_' + subMeshIndex, mesh);

//Add LOD control
LodControl lc = new LodControl();
geom.addControl(lc);
// LODs are broken
//var lc = new LodControl();
//geom.addControl(lc);

// Material, set the first
geom.setMaterial(materials.get(materialIndex).get(0));
Expand Down

0 comments on commit 6e16bfb

Please sign in to comment.