소스 검색

* Deprecate usage of TextureKey.setAsCube() and TextureKey.setAsTexture3D() - this is now handled by the TextureKey.setTextureTypeHint() method instead

shadowislord 11 년 전
부모
커밋
99af4d9bd5

+ 0 - 2
jme3-blender/src/main/java/com/jme3/scene/plugins/blender/textures/TextureHelper.java

@@ -464,7 +464,6 @@ public class TextureHelper extends AbstractBlenderHelper {
             // Directly try to load texture so AssetManager can report missing textures
             try {
                 TextureKey key = new TextureKey(absoluteName);
-                key.setAsCube(false);
                 key.setFlipY(true);
                 key.setGenerateMips(generateMipmaps);
                 result = assetManager.loadTexture(key);
@@ -494,7 +493,6 @@ public class TextureHelper extends AbstractBlenderHelper {
             for (String assetName : assetNames) {
                 try {
                     TextureKey key = new TextureKey(assetName);
-                    key.setAsCube(false);
                     key.setFlipY(true);
                     key.setGenerateMips(generateMipmaps);
                     AssetInfo info = assetManager.locateAsset(key);

+ 67 - 19
jme3-core/src/main/java/com/jme3/asset/TextureKey.java

@@ -31,6 +31,7 @@
  */
 package com.jme3.asset;
 
+import com.jme3.texture.Texture.Type;
 import com.jme3.asset.cache.AssetCache;
 import com.jme3.asset.cache.WeakRefCloneAssetCache;
 import com.jme3.export.InputCapsule;
@@ -39,7 +40,6 @@ import com.jme3.export.JmeImporter;
 import com.jme3.export.OutputCapsule;
 import com.jme3.texture.Image;
 import com.jme3.texture.Texture;
-import com.jme3.texture.Texture.Type;
 import com.jme3.texture.TextureProcessor;
 import java.io.IOException;
 
@@ -58,8 +58,6 @@ public class TextureKey extends AssetKey<Texture> {
 
     private boolean generateMips;
     private boolean flipY;
-    private boolean asCube;
-    private boolean asTexture3D;
     private int anisotropy;
     private Texture.Type textureTypeHint = Texture.Type.TwoDimensional;
 
@@ -78,7 +76,25 @@ public class TextureKey extends AssetKey<Texture> {
 
     @Override
     public String toString() {
-        return name + (flipY ? " (Flipped)" : "") + (asCube ? " (Cube)" : "") + (generateMips ? " (Mipmapped)" : "");
+        String type;
+        switch (textureTypeHint) {
+            case CubeMap:
+                type = " (Cube)";
+                break;
+            case ThreeDimensional:
+                type = " (3D)";
+                break;
+            case TwoDimensionalArray:
+                type = " (Array)";
+                break;
+            case TwoDimensional:
+                type = "";
+                break;
+            default:
+                type = " (" + textureTypeHint.toString() + ")";
+                break;
+        }
+        return name + (flipY ? " (Flipped)" : "") + type + (generateMips ? " (Mipmapped)" : "");
     }
     
     @Override
@@ -107,12 +123,22 @@ public class TextureKey extends AssetKey<Texture> {
         this.anisotropy = anisotropy;
     }
 
+    /**
+     * @deprecated Use {@link #setTextureTypeHint(com.jme3.texture.Texture.Type) }
+     * instead.
+     */
+    @Deprecated
     public boolean isAsCube() {
-        return asCube;
+        return textureTypeHint == Type.CubeMap;
     }
 
+    /**
+     * @deprecated Use {@link #setTextureTypeHint(com.jme3.texture.Texture.Type) }
+     * instead.
+     */
+    @Deprecated
     public void setAsCube(boolean asCube) {
-        this.asCube = asCube;
+        textureTypeHint = asCube ? Type.CubeMap : Type.TwoDimensional;
     }
 
     public boolean isGenerateMips() {
@@ -123,21 +149,41 @@ public class TextureKey extends AssetKey<Texture> {
         this.generateMips = generateMips;
     }
 
+    /**
+     * @deprecated Use {@link #setTextureTypeHint(com.jme3.texture.Texture.Type) }
+     * instead.
+     */
+    @Deprecated
     public boolean isAsTexture3D() {
-        return asTexture3D;
+        return textureTypeHint == Type.ThreeDimensional;
     }
 
+    /**
+     * @deprecated Use {@link #setTextureTypeHint(com.jme3.texture.Texture.Type) }
+     * instead.
+     */
+    @Deprecated
     public void setAsTexture3D(boolean asTexture3D) {
-        this.asTexture3D = asTexture3D;
+        textureTypeHint = asTexture3D ? Type.ThreeDimensional : Type.TwoDimensional;
     }
 
+    /**
+     * The type of texture expected to be returned.
+     * 
+     * @return type of texture expected to be returned.
+     */
     public Type getTextureTypeHint() {
         return textureTypeHint;
     }
 
+    /**
+     * Hints the loader as to which type of texture is expected.
+     * 
+     * @param textureTypeHint The type of texture expected to be loaded.
+     */
     public void setTextureTypeHint(Type textureTypeHint) {
         this.textureTypeHint = textureTypeHint;
-    }   
+    }
     
     @Override
     public boolean equals(Object obj) {
@@ -157,12 +203,6 @@ public class TextureKey extends AssetKey<Texture> {
         if (this.flipY != other.flipY) {
             return false;
         }
-        if (this.asCube != other.asCube) {
-            return false;
-        }
-        if (this.asTexture3D != other.asTexture3D) {
-            return false;
-        }
         if (this.anisotropy != other.anisotropy) {
             return false;
         }
@@ -178,8 +218,6 @@ public class TextureKey extends AssetKey<Texture> {
         hash = 17 * hash + (super.hashCode());
         hash = 17 * hash + (this.generateMips ? 1 : 0);
         hash = 17 * hash + (this.flipY ? 1 : 0);
-        hash = 17 * hash + (this.asCube ? 1 : 0);
-        hash = 17 * hash + (this.asTexture3D ? 1 : 0);
         hash = 17 * hash + this.anisotropy;
         hash = 17 * hash + (this.textureTypeHint != null ? this.textureTypeHint.hashCode() : 0);
         return hash;
@@ -191,8 +229,11 @@ public class TextureKey extends AssetKey<Texture> {
         OutputCapsule oc = ex.getCapsule(this);
         oc.write(flipY, "flip_y", false);
         oc.write(generateMips, "generate_mips", false);
-        oc.write(asCube, "as_cubemap", false);
         oc.write(anisotropy, "anisotropy", 0);
+        oc.write(textureTypeHint, "tex_type", Type.TwoDimensional);
+        
+        // Backwards compat
+        oc.write(textureTypeHint == Type.CubeMap, "as_cubemap", false);
     }
 
     @Override
@@ -201,7 +242,14 @@ public class TextureKey extends AssetKey<Texture> {
         InputCapsule ic = im.getCapsule(this);
         flipY = ic.readBoolean("flip_y", false);
         generateMips = ic.readBoolean("generate_mips", false);
-        asCube = ic.readBoolean("as_cubemap", false);
         anisotropy = ic.readInt("anisotropy", 0);
+        boolean asCube = ic.readBoolean("as_cubemap", false);
+        
+        if (asCube) {
+            // Backwards compat
+            textureTypeHint = Type.CubeMap;
+        } else {
+            textureTypeHint = ic.readEnum("tex_type", Texture.Type.class, Type.TwoDimensional);
+        }
     }
 }

+ 3 - 2
jme3-core/src/main/java/com/jme3/texture/TextureProcessor.java

@@ -38,6 +38,7 @@ import java.nio.ByteBuffer;
 
 public class TextureProcessor implements AssetProcessor {
 
+    @Override
     public Object postProcess(AssetKey key, Object obj) {
         TextureKey texKey = (TextureKey) key;
         Image img = (Image) obj;
@@ -46,7 +47,7 @@ public class TextureProcessor implements AssetProcessor {
         }
 
         Texture tex;
-        if (texKey.isAsCube()) {
+        if (texKey.getTextureTypeHint() == Texture.Type.CubeMap) {
             if (texKey.isFlipY()) {
                 // also flip -y and +y image in cubemap
                 ByteBuffer pos_y = img.getData(2);
@@ -54,7 +55,7 @@ public class TextureProcessor implements AssetProcessor {
                 img.setData(3, pos_y);
             }
             tex = new TextureCubeMap();
-        } else if (texKey.isAsTexture3D()) {
+        } else if (texKey.getTextureTypeHint() == Texture.Type.ThreeDimensional) {
             tex = new Texture3D();
         } else {
             tex = new Texture2D();

+ 11 - 1
jme3-core/src/plugins/java/com/jme3/material/plugins/J3MLoader.java

@@ -140,7 +140,17 @@ public class J3MLoader implements AssetLoader {
             }
 
             TextureKey texKey = new TextureKey(texturePath, flipY);
-            texKey.setAsCube(type == VarType.TextureCubeMap);
+            switch (type) {
+                case Texture3D:
+                    texKey.setTextureTypeHint(Texture.Type.ThreeDimensional);
+                    break;
+                case TextureArray:
+                    texKey.setTextureTypeHint(Texture.Type.TwoDimensionalArray);
+                    break;
+                case TextureCubeMap:
+                    texKey.setTextureTypeHint(Texture.Type.CubeMap);
+                    break;
+            }
             texKey.setGenerateMips(true);
 
             Texture tex;

+ 3 - 3
jme3-core/src/plugins/java/com/jme3/texture/plugins/DDSLoader.java

@@ -36,7 +36,7 @@ import com.jme3.asset.AssetLoader;
 import com.jme3.asset.TextureKey;
 import com.jme3.texture.Image;
 import com.jme3.texture.Image.Format;
-import com.jme3.texture.Texture.Type;
+import com.jme3.texture.Texture;
 import com.jme3.texture.image.ColorSpace;
 import com.jme3.util.BufferUtils;
 import com.jme3.util.LittleEndien;
@@ -128,9 +128,9 @@ public class DDSLoader implements AssetLoader {
             in = new LittleEndien(stream);
             loadHeader();
             if (texture3D) {
-                ((TextureKey) info.getKey()).setTextureTypeHint(Type.ThreeDimensional);
+                ((TextureKey) info.getKey()).setTextureTypeHint(Texture.Type.ThreeDimensional);
             } else if (depth > 1) {
-                ((TextureKey) info.getKey()).setTextureTypeHint(Type.CubeMap);
+                ((TextureKey) info.getKey()).setTextureTypeHint(Texture.Type.CubeMap);
             }
             ArrayList<ByteBuffer> data = readData(((TextureKey) info.getKey()).isFlipY());
             return new Image(pixelFormat, width, height, depth, data, sizes, ColorSpace.sRGB);

+ 1 - 1
jme3-examples/src/main/java/jme3test/light/TestEnvironmentMapping.java

@@ -31,7 +31,7 @@ public class TestEnvironmentMapping extends SimpleApplication {
 
         TextureKey key = new TextureKey("Textures/Sky/Bright/BrightSky.dds", true);
         key.setGenerateMips(true);
-        key.setAsCube(true);
+        key.setTextureTypeHint(Texture.Type.CubeMap);
         final Texture tex = assetManager.loadTexture(key);
 
         for (Spatial geom : buggy.getChildren()) {

+ 1 - 1
jme3-examples/src/main/java/jme3test/texture/TestTexture3DLoading.java

@@ -60,7 +60,7 @@ public class TestTexture3DLoading extends SimpleApplication {
         Material material = new Material(assetManager, "jme3test/texture/tex3DThumb.j3md");
         TextureKey key = new TextureKey("Textures/3D/flame.dds");
         key.setGenerateMips(true);
-        key.setAsTexture3D(true);
+        key.setTextureTypeHint(Texture.Type.ThreeDimensional);
 
         Texture t = assetManager.loadTexture(key);
 

+ 0 - 1
jme3-niftygui/src/main/java/com/jme3/niftygui/JmeBatchRenderBackend.java

@@ -193,7 +193,6 @@ public class JmeBatchRenderBackend implements BatchRenderBackend {
   public Image loadImage(final String filename) {
     TextureKey key = new TextureKey(filename, false);
     key.setAnisotropy(0);
-    key.setAsCube(false);
     key.setGenerateMips(false);
 
     Texture2D texture = (Texture2D) display.getAssetManager().loadTexture(key);

+ 0 - 1
jme3-niftygui/src/main/java/com/jme3/niftygui/RenderImageJme.java

@@ -49,7 +49,6 @@ public class RenderImageJme implements RenderImage {
         TextureKey key = new TextureKey(filename, true);
 
         key.setAnisotropy(0);
-        key.setAsCube(false);
         key.setGenerateMips(false);
         
         texture = (Texture2D) display.getAssetManager().loadTexture(key);

+ 3 - 1
jme3-plugins/src/ogre/java/com/jme3/scene/plugins/ogre/MaterialLoader.java

@@ -130,7 +130,9 @@ public class MaterialLoader implements AssetLoader {
 
         TextureKey texKey = new TextureKey(folderName + path, false);
         texKey.setGenerateMips(genMips);
-        texKey.setAsCube(cubic);
+        if (cubic) {
+            texKey.setTextureTypeHint(Texture.Type.CubeMap);
+        }
 
         try {
             Texture loadedTexture = assetManager.loadTexture(texKey);

+ 0 - 1
jme3-plugins/src/ogre/java/com/jme3/scene/plugins/ogre/matext/MaterialExtensionLoader.java

@@ -74,7 +74,6 @@ public class MaterialExtensionLoader {
 
             TextureKey texKey = new TextureKey(texturePath, false);
             texKey.setGenerateMips(true);
-            texKey.setAsCube(false);
             Texture tex;
             
             try {

+ 0 - 2
sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/RenameTerrainAction.java

@@ -193,8 +193,6 @@ public class RenameTerrainAction extends AbstractToolWizardAction {
     private TextureKey cloneKeyParams(TextureKey tkOrig, String path) {
         TextureKey tk = new TextureKey(path, false);
         tk.setAnisotropy(tkOrig.getAnisotropy());
-        tk.setAsCube(tkOrig.isAsCube());
-        tk.setAsTexture3D(tkOrig.isAsTexture3D());
         tk.setGenerateMips(tkOrig.isGenerateMips());
         tk.setTextureTypeHint(tkOrig.getTextureTypeHint());
         return tk;