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

experimental
shadowislord 11 years ago
parent f31911f039
commit 99af4d9bd5
  1. 2
      jme3-blender/src/main/java/com/jme3/scene/plugins/blender/textures/TextureHelper.java
  2. 86
      jme3-core/src/main/java/com/jme3/asset/TextureKey.java
  3. 5
      jme3-core/src/main/java/com/jme3/texture/TextureProcessor.java
  4. 12
      jme3-core/src/plugins/java/com/jme3/material/plugins/J3MLoader.java
  5. 6
      jme3-core/src/plugins/java/com/jme3/texture/plugins/DDSLoader.java
  6. 2
      jme3-examples/src/main/java/jme3test/light/TestEnvironmentMapping.java
  7. 2
      jme3-examples/src/main/java/jme3test/texture/TestTexture3DLoading.java
  8. 1
      jme3-niftygui/src/main/java/com/jme3/niftygui/JmeBatchRenderBackend.java
  9. 1
      jme3-niftygui/src/main/java/com/jme3/niftygui/RenderImageJme.java
  10. 4
      jme3-plugins/src/ogre/java/com/jme3/scene/plugins/ogre/MaterialLoader.java
  11. 1
      jme3-plugins/src/ogre/java/com/jme3/scene/plugins/ogre/matext/MaterialExtensionLoader.java
  12. 2
      sdk/jme3-terrain-editor/src/com/jme3/gde/terraineditor/RenameTerrainAction.java

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

@ -31,6 +31,7 @@
*/ */
package com.jme3.asset; package com.jme3.asset;
import com.jme3.texture.Texture.Type;
import com.jme3.asset.cache.AssetCache; import com.jme3.asset.cache.AssetCache;
import com.jme3.asset.cache.WeakRefCloneAssetCache; import com.jme3.asset.cache.WeakRefCloneAssetCache;
import com.jme3.export.InputCapsule; import com.jme3.export.InputCapsule;
@ -39,7 +40,6 @@ import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule; import com.jme3.export.OutputCapsule;
import com.jme3.texture.Image; import com.jme3.texture.Image;
import com.jme3.texture.Texture; import com.jme3.texture.Texture;
import com.jme3.texture.Texture.Type;
import com.jme3.texture.TextureProcessor; import com.jme3.texture.TextureProcessor;
import java.io.IOException; import java.io.IOException;
@ -58,8 +58,6 @@ public class TextureKey extends AssetKey<Texture> {
private boolean generateMips; private boolean generateMips;
private boolean flipY; private boolean flipY;
private boolean asCube;
private boolean asTexture3D;
private int anisotropy; private int anisotropy;
private Texture.Type textureTypeHint = Texture.Type.TwoDimensional; private Texture.Type textureTypeHint = Texture.Type.TwoDimensional;
@ -78,7 +76,25 @@ public class TextureKey extends AssetKey<Texture> {
@Override @Override
public String toString() { 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 @Override
@ -107,12 +123,22 @@ public class TextureKey extends AssetKey<Texture> {
this.anisotropy = anisotropy; this.anisotropy = anisotropy;
} }
/**
* @deprecated Use {@link #setTextureTypeHint(com.jme3.texture.Texture.Type) }
* instead.
*/
@Deprecated
public boolean isAsCube() { 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) { public void setAsCube(boolean asCube) {
this.asCube = asCube; textureTypeHint = asCube ? Type.CubeMap : Type.TwoDimensional;
} }
public boolean isGenerateMips() { public boolean isGenerateMips() {
@ -123,21 +149,41 @@ public class TextureKey extends AssetKey<Texture> {
this.generateMips = generateMips; this.generateMips = generateMips;
} }
/**
* @deprecated Use {@link #setTextureTypeHint(com.jme3.texture.Texture.Type) }
* instead.
*/
@Deprecated
public boolean isAsTexture3D() { 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) { 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() { public Type getTextureTypeHint() {
return textureTypeHint; 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) { public void setTextureTypeHint(Type textureTypeHint) {
this.textureTypeHint = textureTypeHint; this.textureTypeHint = textureTypeHint;
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
@ -157,12 +203,6 @@ public class TextureKey extends AssetKey<Texture> {
if (this.flipY != other.flipY) { if (this.flipY != other.flipY) {
return false; return false;
} }
if (this.asCube != other.asCube) {
return false;
}
if (this.asTexture3D != other.asTexture3D) {
return false;
}
if (this.anisotropy != other.anisotropy) { if (this.anisotropy != other.anisotropy) {
return false; return false;
} }
@ -178,8 +218,6 @@ public class TextureKey extends AssetKey<Texture> {
hash = 17 * hash + (super.hashCode()); hash = 17 * hash + (super.hashCode());
hash = 17 * hash + (this.generateMips ? 1 : 0); hash = 17 * hash + (this.generateMips ? 1 : 0);
hash = 17 * hash + (this.flipY ? 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.anisotropy;
hash = 17 * hash + (this.textureTypeHint != null ? this.textureTypeHint.hashCode() : 0); hash = 17 * hash + (this.textureTypeHint != null ? this.textureTypeHint.hashCode() : 0);
return hash; return hash;
@ -191,8 +229,11 @@ public class TextureKey extends AssetKey<Texture> {
OutputCapsule oc = ex.getCapsule(this); OutputCapsule oc = ex.getCapsule(this);
oc.write(flipY, "flip_y", false); oc.write(flipY, "flip_y", false);
oc.write(generateMips, "generate_mips", false); oc.write(generateMips, "generate_mips", false);
oc.write(asCube, "as_cubemap", false);
oc.write(anisotropy, "anisotropy", 0); oc.write(anisotropy, "anisotropy", 0);
oc.write(textureTypeHint, "tex_type", Type.TwoDimensional);
// Backwards compat
oc.write(textureTypeHint == Type.CubeMap, "as_cubemap", false);
} }
@Override @Override
@ -201,7 +242,14 @@ public class TextureKey extends AssetKey<Texture> {
InputCapsule ic = im.getCapsule(this); InputCapsule ic = im.getCapsule(this);
flipY = ic.readBoolean("flip_y", false); flipY = ic.readBoolean("flip_y", false);
generateMips = ic.readBoolean("generate_mips", false); generateMips = ic.readBoolean("generate_mips", false);
asCube = ic.readBoolean("as_cubemap", false);
anisotropy = ic.readInt("anisotropy", 0); 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);
}
} }
} }

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

@ -140,7 +140,17 @@ public class J3MLoader implements AssetLoader {
} }
TextureKey texKey = new TextureKey(texturePath, flipY); 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); texKey.setGenerateMips(true);
Texture tex; Texture tex;

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

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

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

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

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

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

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

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

Loading…
Cancel
Save