Fix issue #1197: ClassCastException in LODGeomap.createMesh() (#1198)

fix-openal-soft-deadlink
Ali-RS 5 years ago committed by Stephen Gold
parent f312608725
commit b1db497a00
  1. 24
      jme3-terrain/src/main/java/com/jme3/terrain/geomipmap/LODGeomap.java

@ -45,8 +45,8 @@ import com.jme3.terrain.GeoMap;
import com.jme3.util.BufferUtils; import com.jme3.util.BufferUtils;
import com.jme3.util.TempVars; import com.jme3.util.TempVars;
import java.io.IOException; import java.io.IOException;
import java.nio.Buffer;
import java.nio.BufferUnderflowException; import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer; import java.nio.FloatBuffer;
import java.nio.IntBuffer; import java.nio.IntBuffer;
import java.nio.ShortBuffer; import java.nio.ShortBuffer;
@ -81,12 +81,7 @@ public class LODGeomap extends GeoMap {
FloatBuffer pb = writeVertexArray(null, scale, center); FloatBuffer pb = writeVertexArray(null, scale, center);
FloatBuffer texb = writeTexCoordArray(null, tcOffset, tcScale, offsetAmount, totalSize); FloatBuffer texb = writeTexCoordArray(null, tcOffset, tcScale, offsetAmount, totalSize);
FloatBuffer nb = writeNormalArray(null, scale); FloatBuffer nb = writeNormalArray(null, scale);
Buffer ib; IndexBuffer ib = writeIndexArrayLodDiff(lod, rightLod, topLod, leftLod, bottomLod, totalSize);
IndexBuffer idxB = writeIndexArrayLodDiff(lod, rightLod, topLod, leftLod, bottomLod, totalSize);
if (idxB.getBuffer() instanceof IntBuffer)
ib = (IntBuffer)idxB.getBuffer();
else
ib = (ShortBuffer)idxB.getBuffer();
FloatBuffer bb = BufferUtils.createFloatBuffer(getWidth() * getHeight() * 3); FloatBuffer bb = BufferUtils.createFloatBuffer(getWidth() * getHeight() * 3);
FloatBuffer tanb = BufferUtils.createFloatBuffer(getWidth() * getHeight() * 3); FloatBuffer tanb = BufferUtils.createFloatBuffer(getWidth() * getHeight() * 3);
writeTangentArray(nb, tanb, bb, texb, scale); writeTangentArray(nb, tanb, bb, texb, scale);
@ -97,10 +92,17 @@ public class LODGeomap extends GeoMap {
m.setBuffer(Type.Tangent, 3, tanb); m.setBuffer(Type.Tangent, 3, tanb);
m.setBuffer(Type.Binormal, 3, bb); m.setBuffer(Type.Binormal, 3, bb);
m.setBuffer(Type.TexCoord, 2, texb); m.setBuffer(Type.TexCoord, 2, texb);
if (ib instanceof IntBuffer) switch (ib.getFormat()) {
m.setBuffer(Type.Index, 3, (IntBuffer)ib); case UnsignedInt:
else if (ib instanceof ShortBuffer) m.setBuffer(Type.Index, 3, (IntBuffer) ib.getBuffer());
m.setBuffer(Type.Index, 3, (ShortBuffer)ib); break;
case UnsignedShort:
m.setBuffer(Type.Index, 3, (ShortBuffer) ib.getBuffer());
break;
case UnsignedByte:
m.setBuffer(Type.Index, 3, (ByteBuffer) ib.getBuffer());
break;
}
m.setStatic(); m.setStatic();
m.updateBound(); m.updateBound();
return m; return m;

Loading…
Cancel
Save