From d6df196a2a1b9db540c1620c43dfdf09ada40b08 Mon Sep 17 00:00:00 2001 From: "Sha..om" Date: Thu, 28 Apr 2011 20:36:28 +0000 Subject: [PATCH] * J3O embedded textures now supported. All textures without a TextureKey set will have their image data directly saved in the J3O file. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7355 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- engine/src/core/com/jme3/texture/Texture.java | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/engine/src/core/com/jme3/texture/Texture.java b/engine/src/core/com/jme3/texture/Texture.java index 57806cb84..5452262c6 100644 --- a/engine/src/core/com/jme3/texture/Texture.java +++ b/engine/src/core/com/jme3/texture/Texture.java @@ -565,7 +565,14 @@ public abstract class Texture implements Asset, Savable, Cloneable { public void write(JmeExporter e) throws IOException { OutputCapsule capsule = e.getCapsule(this); capsule.write(name, "name", null); - capsule.write(key, "key", null); + + if (key == null){ + // no texture key is set, try to save image instead then + capsule.write(image, "image", null); + }else{ + capsule.write(key, "key", null); + } + capsule.write(anisotropicFilter, "anisotropicFilter", 1); capsule.write(minificationFilter, "minificationFilter", MinFilter.BilinearNoMipMaps); @@ -577,18 +584,26 @@ public abstract class Texture implements Asset, Savable, Cloneable { InputCapsule capsule = e.getCapsule(this); name = capsule.readString("name", null); key = (TextureKey) capsule.readSavable("key", null); - // load texture from key + + // load texture from key, if available if (key != null) { + // key is available, so try the texture from there. Texture loadedTex = e.getAssetManager().loadTexture(key); if (loadedTex == null) { Logger.getLogger(Texture.class.getName()).log(Level.SEVERE, "Could not load texture: {0}", key.toString()); } else { image = loadedTex.getImage(); } + }else{ + // no key is set on the texture. Attempt to load an embedded image + image = (Image) capsule.readSavable("image", null); + if (image == null){ + // TODO: what to print out here? the texture has no key or data, there's no useful information .. + // assume texture.name is set even though the key is null + Logger.getLogger(Texture.class.getName()).log(Level.SEVERE, "Could not load embedded image: {0}", toString() ); + } } -// image = (Image) capsule.readSavable("image", null); -// if (image == null) { -// } + anisotropicFilter = capsule.readInt("anisotropicFilter", 1); minificationFilter = capsule.readEnum("minificationFilter", MinFilter.class,