Tube projection support for objects containing many meshes.

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8230 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
Kae..pl 13 years ago
parent f9f25813d0
commit 76d9fd3a15
  1. 97
      engine/src/blender/com/jme3/scene/plugins/blender/textures/UVCoordinatesGenerator.java

@ -158,7 +158,7 @@ public class UVCoordinatesGenerator {
inputData = UVProjectionGenerator.cubeProjection(mesh, bb);
break;
case PROJECTION_TUBE:
BoundingTube bt = UVCoordinatesGenerator.getBoundingTube(mesh);
BoundingTube bt = UVCoordinatesGenerator.getBoundingTube(geometries);
inputData = UVProjectionGenerator.tubeProjection(mesh, bt);
break;
case PROJECTION_SPHERE:
@ -234,7 +234,7 @@ public class UVCoordinatesGenerator {
* This method returns the bounding sphere of the given geometries.
* @param geometries
* the list of geometries
* @return bounding spheres of the given geometries
* @return bounding sphere of the given geometries
*/
/* package */static BoundingSphere getBoundingSphere(List<Geometry> geometries) {
BoundingSphere result = null;
@ -302,6 +302,25 @@ public class UVCoordinatesGenerator {
return new BoundingTube(radius, maxz - minz, center);
}
/**
* This method returns the bounding tube of the given geometries.
* @param geometries
* the list of geometries
* @return bounding tube of the given geometries
*/
/* package */static BoundingTube getBoundingTube(List<Geometry> geometries) {
BoundingTube result = null;
for (Geometry geometry : geometries) {
BoundingTube bt = UVCoordinatesGenerator.getBoundingTube(geometry.getMesh());
if (result == null) {
result = bt;
} else {
result.merge(bt);
}
}
return result;
}
/**
* A very simple bounding tube. Id holds only the basic data bout the bounding tube
* and does not provide full functionality of a BoundingVolume.
@ -313,13 +332,28 @@ public class UVCoordinatesGenerator {
private float height;
private Vector3f center;
/**
* Constructor creates the tube with the given params.
* @param radius
* the radius of the tube
* @param height
* the height of the tube
* @param center
* the center of the tube
*/
public BoundingTube(float radius, float height, Vector3f center) {
this.radius = radius;
this.height = height;
this.center = center;
}
public void merge(BoundingTube boundingTube) {
/**
* This method merges two bounding tubes.
* @param boundingTube
* bounding tube to be merged woth the current one
* @return new instance of bounding tube representing the tubes' merge
*/
public BoundingTube merge(BoundingTube boundingTube) {
// get tubes (tube1.radius >= tube2.radius)
BoundingTube tube1, tube2;
if (this.radius >= boundingTube.radius) {
@ -332,52 +366,39 @@ public class UVCoordinatesGenerator {
float r1 = tube1.radius;
float r2 = tube2.radius;
//get the distance between tubes projected on XY plane
Vector3f distance = boundingTube.center.subtract(this.center);
distance.z = 0;
float minZ = Math.min(tube1.center.z - tube1.height * 0.5f, tube2.center.z - tube2.height * 0.5f);
float maxZ = Math.max(tube1.center.z + tube1.height * 0.5f, tube2.center.z + tube2.height * 0.5f);
float height = maxZ - minZ;
Vector3f distance = tube2.center.subtract(tube1.center);
Vector3f center = tube1.center.add(distance.mult(0.5f));
distance.z = 0;// projecting this vector on XY plane
float d = distance.length();
//calculate union depending on tubes location
if(d>=r1+r2) {//tube2 is outside or touches tube1
} else if(d<r1+r2 && d>r1-r2) {//tube2 crosses tube1
} else {//tube2 is inside tube1
}
if(d >= this.radius + boundingTube.radius ||
(d < this.radius + boundingTube.radius && d > this.radius - boundingTube.radius)) {
}
float centerZ = distance.z;
float maxz = this.center.z + height*0.5f;
float minz = this.center.z - height*0.5f;
distance.z = this.center.z = 0;
Vector3f distanceNormal = distance.normalize();
Vector3f start = this.center.subtract(distanceNormal.multLocal(this.radius));
distanceNormal.normalizeLocal();
Vector3f stop = start.add(distance).addLocal(distanceNormal.multLocal(this.radius+boundingTube.radius));
this.center = start.add(stop.subtractLocal(start)).multLocal(0.5f);
this.center.z = centerZ;
this.radius = this.center.subtract(start).length();
maxz = Math.max(maxz, boundingTube.center.z + boundingTube.height*0.5f);
minz = Math.min(minz, boundingTube.center.z - boundingTube.height*0.5f);
this.height = maxz - minz;
// d <= r1 - r2: tube2 is inside tube1 or touches tube1 from the inside
// d > r1 - r2: tube2 is outside or touches tube1 or crosses tube1
float radius = d <= r1 - r2 ? tube1.radius : (d + r1 + r2) * 0.5f;
return new BoundingTube(radius, height, center);
}
/**
* This method returns the radius of the tube.
* @return the radius of the tube
*/
public float getRadius() {
return radius;
}
/**
* This method returns the height of the tube.
* @return the height of the tube
*/
public float getHeight() {
return height;
}
/**
* This method returns the center of the tube.
* @return the center of the tube
*/
public Vector3f getCenter() {
return center;
}

Loading…
Cancel
Save