If asset cannot be located, then the loader must replace the asset that was supposed to be used with a placeholder, and raise a WARNING in the log indicating that the asset cannot be located, containing both the name of the dependent asset and the parent asset that is loading it git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8596 75d07b2b-3a1a-0410-a2c5-0572b91ccdca3.0
parent
21809776dc
commit
66127db26d
@ -0,0 +1,72 @@ |
|||||||
|
package com.jme3.util; |
||||||
|
|
||||||
|
import com.jme3.asset.AssetManager; |
||||||
|
import com.jme3.audio.AudioBuffer; |
||||||
|
import com.jme3.audio.AudioData; |
||||||
|
import com.jme3.texture.Image; |
||||||
|
import com.jme3.texture.Image.Format; |
||||||
|
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 java.nio.ByteBuffer; |
||||||
|
|
||||||
|
public class PlaceholderAssets { |
||||||
|
|
||||||
|
/** |
||||||
|
* Checkerboard of white and red squares |
||||||
|
*/ |
||||||
|
private static final byte[] imageData = { |
||||||
|
(byte)0xFF, (byte)0xFF, (byte)0xFF, |
||||||
|
(byte)0xFF, (byte)0x00, (byte)0x00, |
||||||
|
(byte)0xFF, (byte)0xFF, (byte)0xFF, |
||||||
|
(byte)0xFF, (byte)0x00, (byte)0x00, |
||||||
|
|
||||||
|
(byte)0xFF, (byte)0x00, (byte)0x00, |
||||||
|
(byte)0xFF, (byte)0xFF, (byte)0xFF, |
||||||
|
(byte)0xFF, (byte)0x00, (byte)0x00, |
||||||
|
(byte)0xFF, (byte)0xFF, (byte)0xFF, |
||||||
|
|
||||||
|
(byte)0xFF, (byte)0xFF, (byte)0xFF, |
||||||
|
(byte)0xFF, (byte)0x00, (byte)0x00, |
||||||
|
(byte)0xFF, (byte)0xFF, (byte)0xFF, |
||||||
|
(byte)0xFF, (byte)0x00, (byte)0x00, |
||||||
|
|
||||||
|
(byte)0xFF, (byte)0x00, (byte)0x00, |
||||||
|
(byte)0xFF, (byte)0xFF, (byte)0xFF, |
||||||
|
(byte)0xFF, (byte)0x00, (byte)0x00, |
||||||
|
(byte)0xFF, (byte)0xFF, (byte)0xFF, |
||||||
|
}; |
||||||
|
|
||||||
|
public static Image getPlaceholderImage(){ |
||||||
|
ByteBuffer tempData = BufferUtils.createByteBuffer(3 * 4 * 4); |
||||||
|
tempData.put(imageData).flip(); |
||||||
|
return new Image(Format.RGB8, 4, 4, tempData); |
||||||
|
} |
||||||
|
|
||||||
|
public static Material getPlaceholderMaterial(AssetManager assetManager){ |
||||||
|
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); |
||||||
|
mat.setColor("Color", ColorRGBA.Red); |
||||||
|
return mat; |
||||||
|
} |
||||||
|
|
||||||
|
public static Spatial getPlaceholderModel(AssetManager assetManager){ |
||||||
|
// What should be the size? Nobody knows
|
||||||
|
// the user's expected scale...
|
||||||
|
Box box = new Box(1, 1, 1); |
||||||
|
Geometry geom = new Geometry("placeholder", box); |
||||||
|
geom.setMaterial(getPlaceholderMaterial(assetManager)); |
||||||
|
return geom; |
||||||
|
} |
||||||
|
|
||||||
|
public static AudioData getPlaceholderAudio(){ |
||||||
|
AudioBuffer audioBuf = new AudioBuffer(); |
||||||
|
audioBuf.setupFormat(1, 8, 44100); |
||||||
|
ByteBuffer bb = BufferUtils.createByteBuffer(1); |
||||||
|
bb.put((byte)0).flip(); |
||||||
|
audioBuf.updateData(bb); |
||||||
|
return audioBuf; |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue