From 9a193c7784a1f9ff3ab2f7fa5688c17d681aae50 Mon Sep 17 00:00:00 2001 From: Julien Gouesse Date: Sun, 13 Jul 2014 01:56:27 +0200 Subject: 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 --- .../ardor3d/extension/model/md2/Md2Importer.java | 40 ++++++++++++++-------- 1 file changed, 25 insertions(+), 15 deletions(-) (limited to 'ardor3d-extras') 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()); } -- cgit v1.2.3