Temporary fix to UVS loading. If no texture is applied and UV coordinates are - then they are applied to the model. At this moment user defined UVS are only applied but future implementation will take the UVS type into account.

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9526 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
Kae..pl 13 years ago
parent 7beebfc4c0
commit 4a596c8082
  1. 104
      engine/src/blender/com/jme3/scene/plugins/blender/materials/MaterialContext.java

@ -1,5 +1,21 @@
package com.jme3.scene.plugins.blender.materials; package com.jme3.scene.plugins.blender.materials;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import jme3tools.converters.ImageToAwt;
import com.jme3.material.Material; import com.jme3.material.Material;
import com.jme3.material.RenderState.BlendMode; import com.jme3.material.RenderState.BlendMode;
import com.jme3.material.RenderState.FaceCullMode; import com.jme3.material.RenderState.FaceCullMode;
@ -21,14 +37,9 @@ import com.jme3.scene.plugins.blender.textures.CombinedTexture;
import com.jme3.scene.plugins.blender.textures.TextureHelper; import com.jme3.scene.plugins.blender.textures.TextureHelper;
import com.jme3.scene.plugins.blender.textures.blending.TextureBlender; import com.jme3.scene.plugins.blender.textures.blending.TextureBlender;
import com.jme3.scene.plugins.blender.textures.blending.TextureBlenderFactory; import com.jme3.scene.plugins.blender.textures.blending.TextureBlenderFactory;
import com.jme3.texture.Image;
import com.jme3.texture.Texture; import com.jme3.texture.Texture;
import com.jme3.util.BufferUtils; import com.jme3.util.BufferUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.Logger;
/** /**
* This class holds the data about the material. * This class holds the data about the material.
@ -195,44 +206,51 @@ public final class MaterialContext {
} }
//applying textures //applying textures
for(Entry<Number, CombinedTexture> entry : loadedTextures.entrySet()) { if(loadedTextures != null && loadedTextures.size() > 0) {
CombinedTexture combinedTexture = entry.getValue(); for(Entry<Number, CombinedTexture> entry : loadedTextures.entrySet()) {
combinedTexture.flatten(geometry, geometriesOMA, userDefinedUVCoordinates, blenderContext); CombinedTexture combinedTexture = entry.getValue();
VertexBuffer.Type uvCoordinatesType = null; combinedTexture.flatten(geometry, geometriesOMA, userDefinedUVCoordinates, blenderContext);
VertexBuffer.Type uvCoordinatesType = null;
switch(entry.getKey().intValue()) {
case MTEX_COL: switch(entry.getKey().intValue()) {
uvCoordinatesType = VertexBuffer.Type.TexCoord; case MTEX_COL:
material.setTexture(shadeless ? MaterialHelper.TEXTURE_TYPE_COLOR : MaterialHelper.TEXTURE_TYPE_DIFFUSE, uvCoordinatesType = VertexBuffer.Type.TexCoord;
combinedTexture.getResultTexture()); material.setTexture(shadeless ? MaterialHelper.TEXTURE_TYPE_COLOR : MaterialHelper.TEXTURE_TYPE_DIFFUSE,
break; combinedTexture.getResultTexture());
case MTEX_NOR: break;
uvCoordinatesType = VertexBuffer.Type.TexCoord2; case MTEX_NOR:
material.setTexture(MaterialHelper.TEXTURE_TYPE_NORMAL, combinedTexture.getResultTexture()); uvCoordinatesType = VertexBuffer.Type.TexCoord2;
break; material.setTexture(MaterialHelper.TEXTURE_TYPE_NORMAL, combinedTexture.getResultTexture());
case MTEX_SPEC: break;
uvCoordinatesType = VertexBuffer.Type.TexCoord3; case MTEX_SPEC:
material.setTexture(MaterialHelper.TEXTURE_TYPE_SPECULAR, combinedTexture.getResultTexture()); uvCoordinatesType = VertexBuffer.Type.TexCoord3;
break; material.setTexture(MaterialHelper.TEXTURE_TYPE_SPECULAR, combinedTexture.getResultTexture());
case MTEX_EMIT: break;
uvCoordinatesType = VertexBuffer.Type.TexCoord4; case MTEX_EMIT:
material.setTexture(MaterialHelper.TEXTURE_TYPE_GLOW, combinedTexture.getResultTexture()); uvCoordinatesType = VertexBuffer.Type.TexCoord4;
break; material.setTexture(MaterialHelper.TEXTURE_TYPE_GLOW, combinedTexture.getResultTexture());
case MTEX_ALPHA: break;
uvCoordinatesType = VertexBuffer.Type.TexCoord5; case MTEX_ALPHA:
material.setTexture(MaterialHelper.TEXTURE_TYPE_ALPHA, combinedTexture.getResultTexture()); uvCoordinatesType = VertexBuffer.Type.TexCoord5;
break; material.setTexture(MaterialHelper.TEXTURE_TYPE_ALPHA, combinedTexture.getResultTexture());
default: break;
LOGGER.severe("Unknown mapping type: " + entry.getKey().intValue()); default:
} LOGGER.severe("Unknown mapping type: " + entry.getKey().intValue());
}
//applying texture coordinates
if(uvCoordinatesType != null) { //applying texture coordinates
VertexBuffer uvCoordsBuffer = new VertexBuffer(uvCoordinatesType); if(uvCoordinatesType != null) {
uvCoordsBuffer.setupData(Usage.Static, 2, Format.Float, VertexBuffer uvCoordsBuffer = new VertexBuffer(uvCoordinatesType);
BufferUtils.createFloatBuffer(combinedTexture.getResultUVS().toArray(new Vector2f[combinedTexture.getResultUVS().size()]))); uvCoordsBuffer.setupData(Usage.Static, 2, Format.Float,
geometry.getMesh().setBuffer(uvCoordsBuffer); BufferUtils.createFloatBuffer(combinedTexture.getResultUVS().toArray(new Vector2f[combinedTexture.getResultUVS().size()])));
geometry.getMesh().setBuffer(uvCoordsBuffer);
}
} }
} else if(userDefinedUVCoordinates != null && userDefinedUVCoordinates.size() > 0) {
VertexBuffer uvCoordsBuffer = new VertexBuffer(VertexBuffer.Type.TexCoord);
uvCoordsBuffer.setupData(Usage.Static, 2, Format.Float,
BufferUtils.createFloatBuffer(userDefinedUVCoordinates.toArray(new Vector2f[userDefinedUVCoordinates.size()])));
geometry.getMesh().setBuffer(uvCoordsBuffer);
} }
//applying additional data //applying additional data

Loading…
Cancel
Save