Bugfix: mipmap generation once again dependant on the blender settings and on blender key settings :)

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10394 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
Kae..pl 12 years ago
parent 0ec18dca80
commit 04998a07c0
  1. 35
      engine/src/blender/com/jme3/scene/plugins/blender/textures/TextureHelper.java

@ -135,13 +135,14 @@ public class TextureHelper extends AbstractBlenderHelper {
return result; return result;
} }
int type = ((Number) tex.getFieldValue("type")).intValue(); int type = ((Number) tex.getFieldValue("type")).intValue();
int imaflag = ((Number) tex.getFieldValue("imaflag")).intValue();
switch (type) { switch (type) {
case TEX_IMAGE:// (it is first because probably this will be most commonly used) case TEX_IMAGE:// (it is first because probably this will be most commonly used)
Pointer pImage = (Pointer) tex.getFieldValue("ima"); Pointer pImage = (Pointer) tex.getFieldValue("ima");
if (pImage.isNotNull()) { if (pImage.isNotNull()) {
Structure image = pImage.fetchData(blenderContext.getInputStream()).get(0); Structure image = pImage.fetchData(blenderContext.getInputStream()).get(0);
Texture loadedTexture = this.loadTexture(image, blenderContext); Texture loadedTexture = this.loadTexture(image, imaflag, blenderContext);
if(loadedTexture != null) { if(loadedTexture != null) {
result = loadedTexture; result = loadedTexture;
this.applyColorbandAndColorFactors(tex, result.getImage(), blenderContext); this.applyColorbandAndColorFactors(tex, result.getImage(), blenderContext);
@ -183,7 +184,6 @@ public class TextureHelper extends AbstractBlenderHelper {
case NEVER_GENERATE: case NEVER_GENERATE:
break; break;
case GENERATE_WHEN_NEEDED: case GENERATE_WHEN_NEEDED:
int imaflag = ((Number) tex.getFieldValue("imaflag")).intValue();
if((imaflag & 0x04) != 0) { if((imaflag & 0x04) != 0) {
result.setMinFilter(MinFilter.Trilinear); result.setMinFilter(MinFilter.Trilinear);
} }
@ -486,6 +486,8 @@ public class TextureHelper extends AbstractBlenderHelper {
* *
* @param imageStructure * @param imageStructure
* image structure filled with data * image structure filled with data
* @param imaflag
* the image flag
* @param blenderContext * @param blenderContext
* the blender context * the blender context
* @return the texture that can be used by JME engine * @return the texture that can be used by JME engine
@ -493,7 +495,7 @@ public class TextureHelper extends AbstractBlenderHelper {
* this exception is thrown when the blend file structure is * this exception is thrown when the blend file structure is
* somehow invalid or corrupted * somehow invalid or corrupted
*/ */
protected Texture loadTexture(Structure imageStructure, BlenderContext blenderContext) throws BlenderFileException { protected Texture loadTexture(Structure imageStructure, int imaflag, BlenderContext blenderContext) throws BlenderFileException {
LOGGER.log(Level.FINE, "Fetching texture with OMA = {0}", imageStructure.getOldMemoryAddress()); LOGGER.log(Level.FINE, "Fetching texture with OMA = {0}", imageStructure.getOldMemoryAddress());
Texture result = null; Texture result = null;
Image im = (Image) blenderContext.getLoadedFeature(imageStructure.getOldMemoryAddress(), LoadedFeatureDataType.LOADED_FEATURE); Image im = (Image) blenderContext.getLoadedFeature(imageStructure.getOldMemoryAddress(), LoadedFeatureDataType.LOADED_FEATURE);
@ -502,7 +504,7 @@ public class TextureHelper extends AbstractBlenderHelper {
Pointer pPackedFile = (Pointer) imageStructure.getFieldValue("packedfile"); Pointer pPackedFile = (Pointer) imageStructure.getFieldValue("packedfile");
if (pPackedFile.isNull()) { if (pPackedFile.isNull()) {
LOGGER.log(Level.FINE, "Reading texture from file: {0}", texturePath); LOGGER.log(Level.FINE, "Reading texture from file: {0}", texturePath);
result = this.loadImageFromFile(texturePath, blenderContext); result = this.loadImageFromFile(texturePath, imaflag, blenderContext);
} else { } else {
LOGGER.fine("Packed texture. Reading directly from the blend file!"); LOGGER.fine("Packed texture. Reading directly from the blend file!");
Structure packedFile = pPackedFile.fetchData(blenderContext.getInputStream()).get(0); Structure packedFile = pPackedFile.fetchData(blenderContext.getInputStream()).get(0);
@ -695,10 +697,11 @@ public class TextureHelper extends AbstractBlenderHelper {
* failed assets. * failed assets.
* *
* @param name the path to the image * @param name the path to the image
* @param imaflag the image flag
* @param blenderContext the blender context * @param blenderContext the blender context
* @return the loaded image or null if the image cannot be found * @return the loaded image or null if the image cannot be found
*/ */
protected Texture loadImageFromFile(String name, BlenderContext blenderContext) { protected Texture loadImageFromFile(String name, int imaflag, BlenderContext blenderContext) {
// @Marcin: please, please disable the use of "TAB" // @Marcin: please, please disable the use of "TAB"
// in your IDE in favor of four spaces. // in your IDE in favor of four spaces.
// All your code looks like this for us: http://i.imgur.com/sGcBv6Q.png // All your code looks like this for us: http://i.imgur.com/sGcBv6Q.png
@ -707,6 +710,22 @@ public class TextureHelper extends AbstractBlenderHelper {
return null; // no extension means not a valid image return null; // no extension means not a valid image
} }
//decide if the mipmaps will be generated
boolean generateMipmaps = false;
switch(blenderContext.getBlenderKey().getMipmapGenerationMethod()) {
case ALWAYS_GENERATE:
generateMipmaps = true;
break;
case NEVER_GENERATE:
break;
case GENERATE_WHEN_NEEDED:
generateMipmaps = (imaflag & 0x04) != 0;
break;
default:
throw new IllegalStateException("Unknown mipmap generation method: " +
blenderContext.getBlenderKey().getMipmapGenerationMethod());
}
AssetManager assetManager = blenderContext.getAssetManager(); AssetManager assetManager = blenderContext.getAssetManager();
name = name.replace('\\', '/'); name = name.replace('\\', '/');
Texture result = null; Texture result = null;
@ -722,10 +741,9 @@ 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);
//TODO: gather from blender data
key.setAsCube(false); key.setAsCube(false);
key.setFlipY(true); key.setFlipY(true);
key.setGenerateMips(true); key.setGenerateMips(generateMipmaps);
result = assetManager.loadTexture(key); result = assetManager.loadTexture(key);
result.setKey(key); result.setKey(key);
} catch (AssetNotFoundException e) { } catch (AssetNotFoundException e) {
@ -753,10 +771,9 @@ 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);
//TODO: gather from blender data
key.setAsCube(false); key.setAsCube(false);
key.setFlipY(true); key.setFlipY(true);
key.setGenerateMips(true); key.setGenerateMips(generateMipmaps);
AssetInfo info = assetManager.locateAsset(key); AssetInfo info = assetManager.locateAsset(key);
if (info != null) { if (info != null) {
Texture texture = assetManager.loadTexture(key); Texture texture = assetManager.loadTexture(key);

Loading…
Cancel
Save