From ac113eac9f645309ef1347ffc2eca5f139abaecc Mon Sep 17 00:00:00 2001 From: "Kaelthas_Spellsinger@o2.pl" Date: Thu, 25 Aug 2011 18:18:32 +0000 Subject: [PATCH] Support for image sphere projection on a mesh. git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@8092 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../blender/textures/UVCoordinatesGenerator.java | 5 +- .../blender/textures/UVProjectionGenerator.java | 101 +++++++++++---------- 2 files changed, 54 insertions(+), 52 deletions(-) diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/textures/UVCoordinatesGenerator.java b/engine/src/blender/com/jme3/scene/plugins/blender/textures/UVCoordinatesGenerator.java index 221d799b3..fe6c36d0e 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/textures/UVCoordinatesGenerator.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/textures/UVCoordinatesGenerator.java @@ -101,7 +101,7 @@ public class UVCoordinatesGenerator { VertexBuffer result = new VertexBuffer(VertexBuffer.Type.TexCoord); Mesh mesh = geometries.get(0).getMesh(); BoundingBox bb = UVCoordinatesGenerator.getBoundingBox(geometries); - + switch (texco) { case TEXCO_ORCO: float[] uvCoordinates = null; @@ -118,7 +118,8 @@ public class UVCoordinatesGenerator { uvCoordinates = UVProjectionGenerator.tubeProjection(mesh, bt); break; case PROJECTION_SPHERE: - uvCoordinates = UVProjectionGenerator.sphereProjection(mesh, bb); + BoundingSphere bs = UVCoordinatesGenerator.getBoundingSphere(geometries); + uvCoordinates = UVProjectionGenerator.sphereProjection(mesh, bs); break; default: throw new IllegalStateException("Unknown projection type: " + projection); diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/textures/UVProjectionGenerator.java b/engine/src/blender/com/jme3/scene/plugins/blender/textures/UVProjectionGenerator.java index 3d860ff9d..00615574d 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/textures/UVProjectionGenerator.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/textures/UVProjectionGenerator.java @@ -3,6 +3,7 @@ package com.jme3.scene.plugins.blender.textures; import java.nio.FloatBuffer; import com.jme3.bounding.BoundingBox; +import com.jme3.bounding.BoundingSphere; import com.jme3.math.FastMath; import com.jme3.math.Triangle; import com.jme3.math.Vector3f; @@ -172,55 +173,55 @@ import com.jme3.scene.plugins.blender.textures.UVCoordinatesGenerator.BoundingTu * the bounding box for projecting * @return UV coordinates after the projection */ - public static float[] sphereProjection(Mesh mesh, BoundingBox bb) { - return null;// TODO: implement - // 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-3 || xSideFactor<3) && ySideFactor<0) {//the triangle is on the splitting plane + //indexOfUcoord = (indexOfTriangle*3 + indexOfTrianglesVertex)*2 + if(sgn1==1.0f) { + uvCoordinates[i*3*2] += 1.0f; + } + if(sgn2==1.0f) { + uvCoordinates[(i*3+1)*2] += 1.0f; + } + if(sgn3==1.0f) { + uvCoordinates[(i*3+2)*2] += 1.0f; + } + } + } + return uvCoordinates; } } -- 2.11.0