use of com.jme3.asset.AssetInfo in project jmonkeyengine by jMonkeyEngine.
the class OGGLoader method load.
public Object load(AssetInfo info) throws IOException {
if (!(info.getKey() instanceof AudioKey)) {
throw new IllegalArgumentException("Audio assets must be loaded using an AudioKey");
}
AudioKey key = (AudioKey) info.getKey();
boolean readStream = key.isStream();
boolean streamCache = key.useStreamCache();
InputStream in = null;
try {
in = info.openStream();
AudioData data = load(in, readStream, streamCache);
if (readStream && !streamCache) {
// we still need the stream in this case ..
in = null;
}
return data;
} finally {
if (in != null) {
in.close();
}
}
}
use of com.jme3.asset.AssetInfo in project jmonkeyengine by jMonkeyEngine.
the class AndroidBufferImageLoader method load.
public Object load(AssetInfo assetInfo) throws IOException {
Bitmap bitmap = null;
Image.Format format;
InputStream in = null;
int bpp;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferQualityOverSpeed = false;
options.inPreferredConfig = Bitmap.Config.RGB_565;
options.inTempStorage = tempData;
options.inScaled = false;
options.inDither = false;
options.inInputShareable = true;
options.inPurgeable = true;
options.inSampleSize = 1;
try {
in = assetInfo.openStream();
bitmap = BitmapFactory.decodeStream(in, null, options);
if (bitmap == null) {
throw new IOException("Failed to load image: " + assetInfo.getKey().getName());
}
} finally {
if (in != null) {
in.close();
}
}
switch(bitmap.getConfig()) {
case ALPHA_8:
format = Image.Format.Alpha8;
bpp = 1;
break;
case ARGB_8888:
format = Image.Format.RGBA8;
bpp = 4;
break;
case RGB_565:
format = Image.Format.RGB565;
bpp = 2;
break;
default:
throw new UnsupportedOperationException("Unrecognized Android bitmap format: " + bitmap.getConfig());
}
TextureKey texKey = (TextureKey) assetInfo.getKey();
int width = bitmap.getWidth();
int height = bitmap.getHeight();
ByteBuffer data = BufferUtils.createByteBuffer(bitmap.getWidth() * bitmap.getHeight() * bpp);
if (format == Image.Format.RGBA8) {
int[] pixelData = new int[width * height];
bitmap.getPixels(pixelData, 0, width, 0, 0, width, height);
if (texKey.isFlipY()) {
int[] sln = new int[width];
int y2;
for (int y1 = 0; y1 < height / 2; y1++) {
y2 = height - y1 - 1;
convertARGBtoABGR(pixelData, y1 * width, sln, 0, width);
convertARGBtoABGR(pixelData, y2 * width, pixelData, y1 * width, width);
System.arraycopy(sln, 0, pixelData, y2 * width, width);
}
} else {
convertARGBtoABGR(pixelData, 0, pixelData, 0, pixelData.length);
}
data.asIntBuffer().put(pixelData);
} else {
if (texKey.isFlipY()) {
// Flip the image, then delete the old one.
Matrix flipMat = new Matrix();
flipMat.preScale(1.0f, -1.0f);
Bitmap newBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), flipMat, false);
bitmap.recycle();
bitmap = newBitmap;
if (bitmap == null) {
throw new IOException("Failed to flip image: " + texKey);
}
}
bitmap.copyPixelsToBuffer(data);
}
data.flip();
bitmap.recycle();
Image image = new Image(format, width, height, data, ColorSpace.sRGB);
return image;
}
use of com.jme3.asset.AssetInfo in project jmonkeyengine by jMonkeyEngine.
the class AndroidNativeImageLoader method load.
public Image load(AssetInfo info) throws IOException {
boolean flip = ((TextureKey) info.getKey()).isFlipY();
InputStream in = null;
try {
in = info.openStream();
return load(info.openStream(), flip, tmpArray);
} finally {
if (in != null) {
in.close();
}
}
}
use of com.jme3.asset.AssetInfo in project jmonkeyengine by jMonkeyEngine.
the class BlenderLoader method setup.
/**
* This method sets up the loader.
* @param assetInfo
* the asset info
* @throws BlenderFileException
* an exception is throw when something wrong happens with blender file
*/
protected BlenderContext setup(AssetInfo assetInfo) throws BlenderFileException {
// registering loaders
ModelKey modelKey = (ModelKey) assetInfo.getKey();
BlenderKey blenderKey;
if (modelKey instanceof BlenderKey) {
blenderKey = (BlenderKey) modelKey;
} else {
blenderKey = new BlenderKey(modelKey.getName());
}
// opening stream
BlenderInputStream inputStream = new BlenderInputStream(assetInfo.openStream());
// reading blocks
List<FileBlockHeader> blocks = new ArrayList<FileBlockHeader>();
FileBlockHeader fileBlock;
BlenderContext blenderContext = new BlenderContext();
blenderContext.setBlenderVersion(inputStream.getVersionNumber());
blenderContext.setAssetManager(assetInfo.getManager());
blenderContext.setInputStream(inputStream);
blenderContext.setBlenderKey(blenderKey);
// creating helpers
blenderContext.putHelper(AnimationHelper.class, new AnimationHelper(inputStream.getVersionNumber(), blenderContext));
blenderContext.putHelper(TextureHelper.class, new TextureHelper(inputStream.getVersionNumber(), blenderContext));
blenderContext.putHelper(MeshHelper.class, new MeshHelper(inputStream.getVersionNumber(), blenderContext));
blenderContext.putHelper(ObjectHelper.class, new ObjectHelper(inputStream.getVersionNumber(), blenderContext));
blenderContext.putHelper(CurvesHelper.class, new CurvesHelper(inputStream.getVersionNumber(), blenderContext));
blenderContext.putHelper(LightHelper.class, new LightHelper(inputStream.getVersionNumber(), blenderContext));
blenderContext.putHelper(CameraHelper.class, new CameraHelper(inputStream.getVersionNumber(), blenderContext));
blenderContext.putHelper(ModifierHelper.class, new ModifierHelper(inputStream.getVersionNumber(), blenderContext));
blenderContext.putHelper(MaterialHelper.class, new MaterialHelper(inputStream.getVersionNumber(), blenderContext));
blenderContext.putHelper(ConstraintHelper.class, new ConstraintHelper(inputStream.getVersionNumber(), blenderContext));
blenderContext.putHelper(ParticlesHelper.class, new ParticlesHelper(inputStream.getVersionNumber(), blenderContext));
blenderContext.putHelper(LandscapeHelper.class, new LandscapeHelper(inputStream.getVersionNumber(), blenderContext));
// reading the blocks (dna block is automatically saved in the blender context when found)
FileBlockHeader sceneFileBlock = null;
do {
fileBlock = new FileBlockHeader(inputStream, blenderContext);
if (!fileBlock.isDnaBlock()) {
blocks.add(fileBlock);
// save the scene's file block
if (fileBlock.getCode() == BlockCode.BLOCK_SC00) {
sceneFileBlock = fileBlock;
}
}
} while (!fileBlock.isLastBlock());
if (sceneFileBlock != null) {
blenderContext.setSceneStructure(sceneFileBlock.getStructure(blenderContext));
}
// adding locator for linked content
assetInfo.getManager().registerLocator(assetInfo.getKey().getName(), LinkedContentLocator.class);
return blenderContext;
}
use of com.jme3.asset.AssetInfo in project jmonkeyengine by jMonkeyEngine.
the class AndroidAudioLoader method load.
@Override
public Object load(AssetInfo assetInfo) throws IOException {
AndroidAudioData result = new AndroidAudioData();
result.setAssetKey(assetInfo.getKey());
return result;
}
Aggregations