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

This commit is contained in:
shadowislord 2015-02-10 20:10:43 -05:00
parent 0ebb3acb16
commit 8ae04fd1fb
7 changed files with 17 additions and 6 deletions

View File

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

View File

@ -35,12 +35,12 @@ import com.jme3.asset.AssetManager;
import com.jme3.audio.AudioBuffer;
import com.jme3.audio.AudioData;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.jme3.texture.Image;
import com.jme3.texture.Image.Format;
import com.jme3.texture.Texture;
import com.jme3.texture.image.ColorSpace;
import java.nio.ByteBuffer;
@ -71,15 +71,22 @@ public class PlaceholderAssets {
(byte)0xFF, (byte)0xFF, (byte)0xFF,
};
@Deprecated
public static Image getPlaceholderImage(){
ByteBuffer tempData = BufferUtils.createByteBuffer(3 * 4 * 4);
tempData.put(imageData).flip();
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){
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;
}
@ -88,7 +95,11 @@ public class PlaceholderAssets {
// the user's expected scale...
Box box = new Box(1, 1, 1);
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;
}

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

View File

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

View File

@ -182,7 +182,7 @@ public class MTLLoader implements AssetLoader {
texture.setWrap(WrapMode.Repeat);
} catch (AssetNotFoundException ex){
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.setKey(key);
}