From c30bc66f76e24d9253d20fc0c6add19e23357a74 Mon Sep 17 00:00:00 2001 From: "Sha..rd" <ShadowIsLord@gmail.com> Date: Mon, 9 Jan 2012 04:39:21 +0000 Subject: [PATCH] * Fixed crash in MeshLoader when loading LOD levels git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9012 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../jme3/scene/plugins/ogre/MeshLoader.java | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/engine/src/ogre/com/jme3/scene/plugins/ogre/MeshLoader.java b/engine/src/ogre/com/jme3/scene/plugins/ogre/MeshLoader.java index 34ee32f27..c8297a33b 100644 --- a/engine/src/ogre/com/jme3/scene/plugins/ogre/MeshLoader.java +++ b/engine/src/ogre/com/jme3/scene/plugins/ogre/MeshLoader.java @@ -513,21 +513,31 @@ public class MeshLoader extends DefaultHandler implements AssetLoader { private void startLodFaceList(String submeshindex, String numfaces) { int index = Integer.parseInt(submeshindex); + mesh = geoms.get(index).getMesh(); int faceCount = Integer.parseInt(numfaces); - + + VertexBuffer originalIndexBuffer = mesh.getBuffer(Type.Index); vb = new VertexBuffer(VertexBuffer.Type.Index); - sb = BufferUtils.createShortBuffer(faceCount * 3); - ib = null; - vb.setupData(Usage.Static, 3, Format.UnsignedShort, sb); + if (originalIndexBuffer.getFormat() == Format.UnsignedInt){ + // LOD buffer should also be integer + ib = BufferUtils.createIntBuffer(faceCount * 3); + sb = null; + vb.setupData(Usage.Static, 3, Format.UnsignedInt, ib); + }else{ + sb = BufferUtils.createShortBuffer(faceCount * 3); + ib = null; + vb.setupData(Usage.Static, 3, Format.UnsignedShort, sb); + } List<VertexBuffer> levels = lodLevels.get(index); if (levels == null) { + // Create the LOD levels list levels = new ArrayList<VertexBuffer>(); - Mesh submesh = geoms.get(index).getMesh(); - levels.add(submesh.getBuffer(Type.Index)); + + // Add the first LOD level (always the original index buffer) + levels.add(originalIndexBuffer); lodLevels.put(index, levels); } - levels.add(vb); }