diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/helpers/v249/MaterialHelper.java b/engine/src/blender/com/jme3/scene/plugins/blender/helpers/v249/MaterialHelper.java index 14dd2d385..e95360ae6 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/helpers/v249/MaterialHelper.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/helpers/v249/MaterialHelper.java @@ -410,6 +410,37 @@ public class MaterialHelper extends AbstractBlenderHelper { } return result; } + + /** + * This method indicates if the material has any kind of texture. + * + * @param material + * the material + * @return true if the texture exists in the material and false otherwise + */ + public boolean hasTexture(Material material) { + if (material != null) { + if(material.getTextureParam(TEXTURE_TYPE_ALPHA) != null) { + return true; + } + if(material.getTextureParam(TEXTURE_TYPE_COLOR) != null) { + return true; + } + if(material.getTextureParam(TEXTURE_TYPE_DIFFUSE) != null) { + return true; + } + if(material.getTextureParam(TEXTURE_TYPE_GLOW) != null) { + return true; + } + if(material.getTextureParam(TEXTURE_TYPE_NORMAL) != null) { + return true; + } + if(material.getTextureParam(TEXTURE_TYPE_SPECULAR) != null) { + return true; + } + } + return false; + } /** * This method indicates if the material has a texture of a specified type. @@ -426,7 +457,7 @@ public class MaterialHelper extends AbstractBlenderHelper { } return false; } - + /** * This method returns the diffuse color * diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/helpers/v249/MeshHelper.java b/engine/src/blender/com/jme3/scene/plugins/blender/helpers/v249/MeshHelper.java index aacec0570..7029b999b 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/helpers/v249/MeshHelper.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/helpers/v249/MeshHelper.java @@ -41,8 +41,13 @@ import java.util.Map; import java.util.Map.Entry; import com.jme3.asset.BlenderKey.FeaturesToLoad; +import com.jme3.bounding.BoundingBox; +import com.jme3.bounding.BoundingSphere; +import com.jme3.bounding.BoundingVolume; +import com.jme3.collision.CollisionResults; import com.jme3.material.Material; import com.jme3.math.FastMath; +import com.jme3.math.Ray; import com.jme3.math.Vector2f; import com.jme3.math.Vector3f; import com.jme3.renderer.queue.RenderQueue.Bucket; @@ -301,7 +306,7 @@ public class MeshHelper extends AbstractBlenderHelper { FloatBuffer verticesColorsBuffer = this.createFloatBuffer(verticesColors); for (Entry> meshEntry : meshesMap.entrySet()) { Mesh mesh = new Mesh(); - + // creating vertices indices for this mesh List indexList = meshEntry.getValue(); int[] indices = new int[indexList.size()]; @@ -330,11 +335,6 @@ public class MeshHelper extends AbstractBlenderHelper { mesh.setBuffer(normalsBuffer); mesh.setBuffer(normalsBind); - // setting uvCoords - if (uvCoordsBuffer != null) { - mesh.setBuffer(uvCoordsBuffer); - } - // creating the result Geometry geometry = new Geometry(name + (geometries.size() + 1), mesh); if (materials != null) { @@ -377,9 +377,81 @@ public class MeshHelper extends AbstractBlenderHelper { } geometries.add(geometry); } + + //applying uvCoordinates for all the meshes + if (uvCoordsBuffer != null) { + for(Geometry geom : geometries) { + geom.getMesh().setBuffer(uvCoordsBuffer); + } + } else { + Vector2f[] uvTable = new Vector2f[vertexList.size()]; + Ray ray = new Ray(); + CollisionResults cr = new CollisionResults(); + Vector3f yVec = new Vector3f(); + Vector3f zVec = new Vector3f(); + for(Geometry geom : geometries) { + if(materialHelper.hasTexture(geom.getMaterial())) {//generate only when material has a texture + geom.getMesh().updateBound(); + BoundingSphere bs = this.getBoundingSphere(geom.getMesh()); + float r2 = bs.getRadius() * bs.getRadius(); + yVec.set(0, -bs.getRadius(), 0); + zVec.set(0, 0, -bs.getRadius()); + Vector3f center = bs.getCenter(); + ray.setOrigin(center); + //we cast each vertex of the current mesh on the bounding box to determine the UV-coordinates + for(int i=0;i