summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/classes/share/com/sun/j3d/utils/geometry/Box.java2
-rw-r--r--src/classes/share/com/sun/j3d/utils/geometry/Cone.java2
-rw-r--r--src/classes/share/com/sun/j3d/utils/geometry/Cylinder.java2
-rw-r--r--src/classes/share/com/sun/j3d/utils/geometry/GeomBuffer.java5
-rw-r--r--src/classes/share/com/sun/j3d/utils/geometry/Primitive.java7
-rw-r--r--src/classes/share/com/sun/j3d/utils/geometry/Sphere.java107
6 files changed, 51 insertions, 74 deletions
diff --git a/src/classes/share/com/sun/j3d/utils/geometry/Box.java b/src/classes/share/com/sun/j3d/utils/geometry/Box.java
index 04dac4d..561446c 100644
--- a/src/classes/share/com/sun/j3d/utils/geometry/Box.java
+++ b/src/classes/share/com/sun/j3d/utils/geometry/Box.java
@@ -167,7 +167,7 @@ public class Box extends Primitive {
zDim = zdim;
flags = primflags;
numTexUnit = numTexUnit;
- boolean texCoordYUp = (flags & GENERATE_TEXTURE_COORDS_YUP) != 0;
+ boolean texCoordYUp = (flags & GENERATE_TEXTURE_COORDS_Y_UP) != 0;
//Depending on whether normal inward bit is set.
if ((flags & GENERATE_NORMALS_INWARD) != 0)
diff --git a/src/classes/share/com/sun/j3d/utils/geometry/Cone.java b/src/classes/share/com/sun/j3d/utils/geometry/Cone.java
index c98cae9..c438a80 100644
--- a/src/classes/share/com/sun/j3d/utils/geometry/Cone.java
+++ b/src/classes/share/com/sun/j3d/utils/geometry/Cone.java
@@ -211,7 +211,7 @@ public class Cone extends Primitive {
ydivisions = ydivision;
flags = primflags;
boolean outside = (flags & GENERATE_NORMALS_INWARD) == 0;
- boolean texCoordYUp = (flags & GENERATE_TEXTURE_COORDS_YUP) != 0;
+ boolean texCoordYUp = (flags & GENERATE_TEXTURE_COORDS_Y_UP) != 0;
Quadrics q = new Quadrics();
GeomBuffer gbuf = null;
diff --git a/src/classes/share/com/sun/j3d/utils/geometry/Cylinder.java b/src/classes/share/com/sun/j3d/utils/geometry/Cylinder.java
index 26b0cec..76f6cf9 100644
--- a/src/classes/share/com/sun/j3d/utils/geometry/Cylinder.java
+++ b/src/classes/share/com/sun/j3d/utils/geometry/Cylinder.java
@@ -212,7 +212,7 @@ public class Cylinder extends Primitive{
this.ydivisions = ydivision;
flags = primflags;
boolean outside = (flags & GENERATE_NORMALS_INWARD) == 0;
- boolean texCoordYUp = (flags & GENERATE_TEXTURE_COORDS_YUP) != 0;
+ boolean texCoordYUp = (flags & GENERATE_TEXTURE_COORDS_Y_UP) != 0;
// Create many body of the cylinder.
Quadrics q = new Quadrics();
GeomBuffer gbuf = null;
diff --git a/src/classes/share/com/sun/j3d/utils/geometry/GeomBuffer.java b/src/classes/share/com/sun/j3d/utils/geometry/GeomBuffer.java
index 890f989..a68b8b8 100644
--- a/src/classes/share/com/sun/j3d/utils/geometry/GeomBuffer.java
+++ b/src/classes/share/com/sun/j3d/utils/geometry/GeomBuffer.java
@@ -246,6 +246,11 @@ class GeomBuffer extends Object{
tcoords[currVertCnt] = new TexCoord2f((float)s, (float)t);
}
+ // Return a reference to the texture coordinates of this geom buffer.
+ TexCoord2f[] getTexCoords() {
+ return tcoords;
+ }
+
/**
* Returns the Java 3D geometry gotten from calling getGeom.
*
diff --git a/src/classes/share/com/sun/j3d/utils/geometry/Primitive.java b/src/classes/share/com/sun/j3d/utils/geometry/Primitive.java
index 4ba8094..f564c5f 100644
--- a/src/classes/share/com/sun/j3d/utils/geometry/Primitive.java
+++ b/src/classes/share/com/sun/j3d/utils/geometry/Primitive.java
@@ -81,9 +81,12 @@ public abstract class Primitive extends Group {
public static final int GENERATE_NORMALS_INWARD = 0x04;
/**
- * Specifies that texture coordinates are to be Y up.
+ * Specifies that texture coordinates are to be Y up.
+ *
+ * @since Java 3D 1.5.1
*/
- public static final int GENERATE_TEXTURE_COORDS_YUP = 0x08;
+ // Fix to Issue 411. Java 3D prefers images used for texture mapping to be Y-up
+ public static final int GENERATE_TEXTURE_COORDS_Y_UP = 0x08;
/**
diff --git a/src/classes/share/com/sun/j3d/utils/geometry/Sphere.java b/src/classes/share/com/sun/j3d/utils/geometry/Sphere.java
index 95327e4..770d9e4 100644
--- a/src/classes/share/com/sun/j3d/utils/geometry/Sphere.java
+++ b/src/classes/share/com/sun/j3d/utils/geometry/Sphere.java
@@ -206,7 +206,7 @@ public class Sphere extends Primitive {
*/
flags = primflags;
- boolean texCoordYUp = (flags & GENERATE_TEXTURE_COORDS_YUP) != 0;
+ boolean texCoordYUp = (flags & GENERATE_TEXTURE_COORDS_Y_UP) != 0;
//Depending on whether normal inward bit is set.
if ((flags & GENERATE_NORMALS_INWARD) != 0) {
@@ -245,13 +245,24 @@ public class Sphere extends Primitive {
GeomBuffer gbuf = new GeomBuffer(8*nstep*(nstep+2));
for (int i=0; i < 4; i++) {
- buildQuadrant(gbuf, i*Math.PI/2, (i+1)*Math.PI/2, sign, texCoordYUp, nstep, n, true);
- buildQuadrant(gbuf, i*Math.PI/2, (i+1)*Math.PI/2, sign, texCoordYUp, nstep, n, false);
+ buildQuadrant(gbuf, i*Math.PI/2, (i+1)*Math.PI/2, sign, nstep, n, true);
+ buildQuadrant(gbuf, i*Math.PI/2, (i+1)*Math.PI/2, sign, nstep, n, false);
}
+ // Fix to Issue 411. Java 3D prefers images used for texture mapping to be Y-up
+ if (texCoordYUp) {
+ TexCoord2f[] texCoords = gbuf.getTexCoords();
+ if (texCoords != null) {
+ for (int ii=0; ii<texCoords.length; ii++) {
+ texCoords[ii].y = 1.0f - texCoords[ii].y;
+ }
+ }
+ }
+
shape = new Shape3D(gbuf.getGeom(flags));
numVerts = gbuf.getNumVerts();
- numTris = gbuf.getNumTris();
+ numTris = gbuf.getNumTris();
+
if ((primflags & Primitive.GEOMETRY_NOT_SHARED) == 0) {
cacheGeometry(Primitive.SPHERE,
radius, 0.0f, 0.0f,
@@ -355,7 +366,7 @@ public class Sphere extends Primitive {
}
void buildQuadrant(GeomBuffer gbuf, double startDelta, double endDelta,
- int sign, boolean texCoordYUp, int nstep, int n, boolean upperSphere)
+ int sign, int nstep, int n, boolean upperSphere)
{
double ds, dt, theta, delta;
@@ -416,32 +427,17 @@ public class Sphere extends Primitive {
texCoord = gbuf.tcoords[index];
// connect with correspondent vertices from previous row
gbuf.normal3d(norm.x, norm.y, norm.z);
- if(texCoordYUp) {
- gbuf.texCoord2d(texCoord.x, 1.0 - texCoord.y);
- }
- else {
- gbuf.texCoord2d(texCoord.x, texCoord.y);
- }
+ gbuf.texCoord2d(texCoord.x, texCoord.y);
gbuf.vertex3d(pt.x, pt.y, pt.z);
} else {
gbuf.normal3d(0, sign*starth, 0);
- if (sign > 0) {
- if (texCoordYUp) {
- gbuf.texCoord2d(0.75 - (startDelta + endDelta)/(4*Math.PI),
- (theta - dt)/Math.PI);
- } else {
- gbuf.texCoord2d(0.75 - (startDelta + endDelta)/(4*Math.PI),
- 1.0 - (theta - dt)/Math.PI);
- }
- } else {
- if (texCoordYUp) {
- gbuf.texCoord2d(0.75 - (startDelta + endDelta)/(4*Math.PI),
- 1.0 - (theta - dt)/Math.PI);
- } else {
- gbuf.texCoord2d(0.75 - (startDelta + endDelta)/(4*Math.PI),
- (theta - dt)/Math.PI);
- }
- }
+ if (sign > 0) {
+ gbuf.texCoord2d(0.75 - (startDelta + endDelta)/(4*Math.PI),
+ 1.0 - (theta - dt)/Math.PI);
+ } else {
+ gbuf.texCoord2d(0.75 - (startDelta + endDelta)/(4*Math.PI),
+ (theta - dt)/Math.PI);
+ }
gbuf.vertex3d( 0, starth*radius, 0);
}
@@ -455,12 +451,7 @@ public class Sphere extends Primitive {
vx = r*Math.cos(delta);
vz = r*Math.sin(delta);
gbuf.normal3d( vx*sign, h*sign, vz*sign );
- if(texCoordYUp) {
- gbuf.texCoord2d(0.75 - delta/(2*Math.PI), 1.0 - t);
- }
- else {
- gbuf.texCoord2d(0.75 - delta/(2*Math.PI), t);
- }
+ gbuf.texCoord2d(0.75 - delta/(2*Math.PI), t);
gbuf.vertex3d( vx*radius, h*radius, vz*radius);
} else {
delta = endDelta;
@@ -472,11 +463,7 @@ public class Sphere extends Primitive {
gbuf.normal3d( vx*sign, h*sign, vz*sign );
// Convert texture coordinate back to one
// set in previous version
- if(texCoordYUp) {
- gbuf.texCoord2d(0.75 - delta/(2*Math.PI), 1.0 - t);
- } else {
- gbuf.texCoord2d(0.75 - delta/(2*Math.PI), t);
- }
+ gbuf.texCoord2d(0.75 - delta/(2*Math.PI), t);
gbuf.vertex3d( vx*radius, h*radius, vz*radius );
if (i > 1) {
// get previous vertex from buffer
@@ -485,31 +472,17 @@ public class Sphere extends Primitive {
norm = gbuf.normals[index];
texCoord = gbuf.tcoords[index];
gbuf.normal3d(norm.x, norm.y, norm.z);
- if(texCoordYUp) {
- gbuf.texCoord2d(texCoord.x, 1.0 - texCoord.y);
- } else {
- gbuf.texCoord2d(texCoord.x, texCoord.y);
- }
+ gbuf.texCoord2d(texCoord.x, texCoord.y);
gbuf.vertex3d(pt.x, pt.y, pt.z);
} else {
gbuf.normal3d(0, sign*starth, 0);
if (sign > 0) {
- if (texCoordYUp) {
- gbuf.texCoord2d(0.75 - (startDelta + endDelta)/(4*Math.PI),
- (theta - dt)/Math.PI);
- } else {
- gbuf.texCoord2d(0.75 - (startDelta + endDelta)/(4*Math.PI),
- 1.0 - (theta - dt)/Math.PI);
- }
- } else {
- if (texCoordYUp) {
- gbuf.texCoord2d(0.75 - (startDelta + endDelta)/(4*Math.PI),
- 1.0 - (theta - dt)/Math.PI);
- } else {
- gbuf.texCoord2d(0.75 - (startDelta + endDelta)/(4*Math.PI),
- (theta - dt)/Math.PI);
- }
- }
+ gbuf.texCoord2d(0.75 - (startDelta + endDelta)/(4*Math.PI),
+ 1.0 - (theta - dt)/Math.PI);
+ } else {
+ gbuf.texCoord2d(0.75 - (startDelta + endDelta)/(4*Math.PI),
+ (theta - dt)/Math.PI);
+ }
gbuf.vertex3d( 0, starth*radius, 0);
}
@@ -520,15 +493,11 @@ public class Sphere extends Primitive {
// for numerical accuracy we don't use delta
// compute from above.
delta = startDelta;
- vx = r*Math.cos(delta);
- vz = r*Math.sin(delta);
- gbuf.normal3d( vx*sign, h*sign, vz*sign );
- if(texCoordYUp) {
- gbuf.texCoord2d(0.75 - delta/(2*Math.PI), 1.0 - t);
- } else {
- gbuf.texCoord2d(0.75 - delta/(2*Math.PI), t);
- }
- gbuf.vertex3d( vx*radius, h*radius, vz*radius );
+ vx = r*Math.cos(delta);
+ vz = r*Math.sin(delta);
+ gbuf.normal3d( vx*sign, h*sign, vz*sign );
+ gbuf.texCoord2d(0.75 - delta/(2*Math.PI), t);
+ gbuf.vertex3d( vx*radius, h*radius, vz*radius );
}