PlaceholderAssets: when assets fail to load, try to make the error appear visually

experimental
shadowislord 10 years ago
parent 0ebb3acb16
commit 8ae04fd1fb
  1. 2
      jme3-core/src/main/java/com/jme3/texture/Texture.java
  2. 17
      jme3-core/src/main/java/com/jme3/util/PlaceholderAssets.java
  3. BIN
      jme3-core/src/main/resources/Common/Textures/MissingMaterial.png
  4. BIN
      jme3-core/src/main/resources/Common/Textures/MissingModel.png
  5. BIN
      jme3-core/src/main/resources/Common/Textures/MissingTexture.png
  6. 2
      jme3-core/src/plugins/java/com/jme3/material/plugins/J3MLoader.java
  7. 2
      jme3-core/src/plugins/java/com/jme3/scene/plugins/MTLLoader.java

@ -620,7 +620,7 @@ public abstract class Texture implements CloneableSmartAsset, Savable, Cloneable
image = loadedTex.getImage(); image = loadedTex.getImage();
} catch (AssetNotFoundException ex){ } catch (AssetNotFoundException ex){
Logger.getLogger(Texture.class.getName()).log(Level.SEVERE, "Cannot locate texture {0}", key); Logger.getLogger(Texture.class.getName()).log(Level.SEVERE, "Cannot locate texture {0}", key);
image = PlaceholderAssets.getPlaceholderImage(); image = PlaceholderAssets.getPlaceholderImage(e.getAssetManager());
} }
}else{ }else{
// no key is set on the texture. Attempt to load an embedded image // no key is set on the texture. Attempt to load an embedded image

@ -35,12 +35,12 @@ import com.jme3.asset.AssetManager;
import com.jme3.audio.AudioBuffer; import com.jme3.audio.AudioBuffer;
import com.jme3.audio.AudioData; import com.jme3.audio.AudioData;
import com.jme3.material.Material; import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry; import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial; import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box; import com.jme3.scene.shape.Box;
import com.jme3.texture.Image; import com.jme3.texture.Image;
import com.jme3.texture.Image.Format; import com.jme3.texture.Image.Format;
import com.jme3.texture.Texture;
import com.jme3.texture.image.ColorSpace; import com.jme3.texture.image.ColorSpace;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -71,15 +71,22 @@ public class PlaceholderAssets {
(byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF,
}; };
@Deprecated
public static Image getPlaceholderImage(){ public static Image getPlaceholderImage(){
ByteBuffer tempData = BufferUtils.createByteBuffer(3 * 4 * 4); ByteBuffer tempData = BufferUtils.createByteBuffer(3 * 4 * 4);
tempData.put(imageData).flip(); tempData.put(imageData).flip();
return new Image(Format.RGB8, 4, 4, tempData, null, ColorSpace.Linear); return new Image(Format.RGB8, 4, 4, tempData, null, ColorSpace.Linear);
} }
public static Image getPlaceholderImage(AssetManager assetManager){
return assetManager.loadTexture("Common/Textures/MissingTexture.png").getImage();
}
public static Material getPlaceholderMaterial(AssetManager assetManager){ public static Material getPlaceholderMaterial(AssetManager assetManager){
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Red); Texture tex = assetManager.loadTexture("Common/Textures/MissingMaterial.png");
tex.setWrap(Texture.WrapMode.Repeat);
mat.setTexture("ColorMap", tex);
return mat; return mat;
} }
@ -88,7 +95,11 @@ public class PlaceholderAssets {
// the user's expected scale... // the user's expected scale...
Box box = new Box(1, 1, 1); Box box = new Box(1, 1, 1);
Geometry geom = new Geometry("placeholder", box); Geometry geom = new Geometry("placeholder", box);
geom.setMaterial(getPlaceholderMaterial(assetManager)); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
Texture tex = assetManager.loadTexture("Common/Textures/MissingModel.png");
tex.setWrap(Texture.WrapMode.Repeat);
mat.setTexture("ColorMap", tex);
geom.setMaterial(mat);
return geom; return geom;
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

@ -165,7 +165,7 @@ public class J3MLoader implements AssetLoader {
tex.setWrap(WrapMode.Repeat); tex.setWrap(WrapMode.Repeat);
} }
}else{ }else{
tex = new Texture2D(PlaceholderAssets.getPlaceholderImage()); tex = new Texture2D(PlaceholderAssets.getPlaceholderImage(assetManager));
if (repeat){ if (repeat){
tex.setWrap(WrapMode.Repeat); tex.setWrap(WrapMode.Repeat);
} }

@ -182,7 +182,7 @@ public class MTLLoader implements AssetLoader {
texture.setWrap(WrapMode.Repeat); texture.setWrap(WrapMode.Repeat);
} catch (AssetNotFoundException ex){ } catch (AssetNotFoundException ex){
logger.log(Level.WARNING, "Cannot locate {0} for material {1}", new Object[]{texKey, key}); logger.log(Level.WARNING, "Cannot locate {0} for material {1}", new Object[]{texKey, key});
texture = new Texture2D(PlaceholderAssets.getPlaceholderImage()); texture = new Texture2D(PlaceholderAssets.getPlaceholderImage(assetManager));
texture.setWrap(WrapMode.Repeat); texture.setWrap(WrapMode.Repeat);
texture.setKey(key); texture.setKey(key);
} }

Loading…
Cancel
Save