diff options
author | Julien Gouesse <[email protected]> | 2014-07-13 01:56:27 +0200 |
---|---|---|
committer | Julien Gouesse <[email protected]> | 2014-07-13 01:56:27 +0200 |
commit | 9a193c7784a1f9ff3ab2f7fa5688c17d681aae50 (patch) | |
tree | aaa1ebe6dafad68f165695c1f598bffa035344e5 /ardor3d-extras | |
parent | edbfbc733dd7b08c833246562814074721aa1c1d (diff) |
Uses a temporary dirty kludge to prevent the import of a MD2 model from failing when Ardor3D fails to load the default texture which is not supported yet by JOGL because of its bug 982
Diffstat (limited to 'ardor3d-extras')
-rw-r--r-- | ardor3d-extras/src/main/java/com/ardor3d/extension/model/md2/Md2Importer.java | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/ardor3d-extras/src/main/java/com/ardor3d/extension/model/md2/Md2Importer.java b/ardor3d-extras/src/main/java/com/ardor3d/extension/model/md2/Md2Importer.java index 6270b66..065a8fc 100644 --- a/ardor3d-extras/src/main/java/com/ardor3d/extension/model/md2/Md2Importer.java +++ b/ardor3d-extras/src/main/java/com/ardor3d/extension/model/md2/Md2Importer.java @@ -10,14 +10,15 @@ package com.ardor3d.extension.model.md2; +import java.io.IOException; import java.io.InputStream; import java.util.List; import com.ardor3d.bounding.BoundingBox; import com.ardor3d.extension.model.util.KeyframeController; import com.ardor3d.image.Texture; -import com.ardor3d.image.TextureStoreFormat; import com.ardor3d.image.Texture.MinificationFilter; +import com.ardor3d.image.TextureStoreFormat; import com.ardor3d.math.Vector3; import com.ardor3d.renderer.IndexMode; import com.ardor3d.renderer.state.TextureState; @@ -112,10 +113,10 @@ public class Md2Importer { final LittleEndianRandomAccessDataInput bis = new LittleEndianRandomAccessDataInput(md2Stream); // parse the header - final Md2Header header = new Md2Header(bis.readInt(), bis.readInt(), bis.readInt(), bis.readInt(), bis - .readInt(), bis.readInt(), bis.readInt(), bis.readInt(), bis.readInt(), bis.readInt(), bis - .readInt(), bis.readInt(), bis.readInt(), bis.readInt(), bis.readInt(), bis.readInt(), bis - .readInt()); + final Md2Header header = new Md2Header(bis.readInt(), bis.readInt(), bis.readInt(), bis.readInt(), + bis.readInt(), bis.readInt(), bis.readInt(), bis.readInt(), bis.readInt(), bis.readInt(), + bis.readInt(), bis.readInt(), bis.readInt(), bis.readInt(), bis.readInt(), bis.readInt(), + bis.readInt()); // Check magic word and version if (header.magic != ('2' << 24) + ('P' << 16) + ('D' << 8) + 'I') { @@ -352,16 +353,26 @@ public class Md2Importer { private Texture loadTexture(final String name) { Texture tex = null; - if (_textureLocator == null) { - tex = TextureManager.load(name, getMinificationFilter(), - isUseCompression() ? TextureStoreFormat.GuessCompressedFormat - : TextureStoreFormat.GuessNoCompressedFormat, isFlipTextureVertically()); - } else { - final ResourceSource source = _textureLocator.locateResource(name); - if (source != null) { - tex = TextureManager.load(source, getMinificationFilter(), + try { + if (_textureLocator == null) { + tex = TextureManager.load(name, getMinificationFilter(), isUseCompression() ? TextureStoreFormat.GuessCompressedFormat : TextureStoreFormat.GuessNoCompressedFormat, isFlipTextureVertically()); + } else { + final ResourceSource source = _textureLocator.locateResource(name); + if (source != null) { + tex = TextureManager.load(source, getMinificationFilter(), + isUseCompression() ? TextureStoreFormat.GuessCompressedFormat + : TextureStoreFormat.GuessNoCompressedFormat, isFlipTextureVertically()); + } + } + } catch (final Throwable t) { + if (t instanceof IOException + && ((IOException) t).getMessage().equalsIgnoreCase("No suitable reader for given stream")) { + // silently ignores this case, the bug 982 of JOGL hasn't been fixed yet + return null; + } else { + throw new RuntimeException("Unable to load the texture from name: " + name, t); } } return tex; @@ -378,8 +389,7 @@ public class Md2Importer { private void addVert(final Md2GlCommand cmd, final Md2Frame frame, final int vertIndex, final FloatBufferData verts) { final int index = cmd.vertIndices[vertIndex]; final byte[] vertData = frame.vertData; - calcVert.set((vertData[index * 4 + 0] & 0xFF), (vertData[index * 4 + 1] & 0xFF), - (vertData[index * 4 + 2] & 0xFF)); + calcVert.set(vertData[index * 4 + 0] & 0xFF, vertData[index * 4 + 1] & 0xFF, vertData[index * 4 + 2] & 0xFF); calcVert.multiplyLocal(frame.scale).addLocal(frame.translate); verts.getBuffer().put(calcVert.getXf()).put(calcVert.getYf()).put(calcVert.getZf()); } |