We recently implemented creating roads along a spline path.
Here is an excerp which should be of help. The texture coordinates are
calculated in this piece
of the code:
/**
* Create the path over the terrain map, along the path nodes specified
* in the constructor.
*/
public GeometryArray getGeometry(HeightMapInterface map, Brush brush) {
GeneralPath gp = getGeneralPath(points);
float[] sPoints = getSpecificPath(gp,density);
// create a triangle strip, which should have
TriangleStripArray geom;
int vertexCounts[] = new int[1];
vertexCounts[0] = sPoints.length;
if (brush.dtexEnable) {
int texMapping[] = {0,1};
geom = new
TriangleStripArray(sPoints.length,GeometryArray.COORDINATES |
GeometryArray.COLOR_4 |
GeometryArray.TEXTURE_COORDINATE_2 |
GeometryArray.NORMALS,2,texMapping,vertexCounts);
} else {
geom = new TriangleStripArray(sPoints.length,
GeometryArray.COORDINATES |
GeometryArray.COLOR_4 |
GeometryArray.TEXTURE_COORDINATE_2 |
GeometryArray.NORMALS,vertexCounts);
}
Point3d curPoint = new Point3d();
Point3d nextPoint = new Point3d();
Vector3d vec = new Vector3d();
Point3f p1 = new Point3f();
Point3f p2 = new Point3f();
Vector3f straightUp = new Vector3f(0,1,0);
int vertex = 0;
TexCoord2f tex = new TexCoord2f();
float length = 0;
// Color4f white = new Color4f(1f,1f,1f,1f);
Color4f white = new Color4f(130f/255f,78f/255f,10f/255f,1f);
// Color4f white = new Color4f(169f/255f,139f/255f,87f/255f,1f);
Color4f invisible = new Color4f(white.x,white.y,white.z,0f);
Random r = new Random(183483);
// some transforms we are going to use
Transform3D rot = new Transform3D();
// step through all the vertices and write them out. For each point
in the sPoints
// we will create 2 points in the geometry
for (int i=0;i<sPoints.length/2-1;i++) {
// create the points then calculate the vector from the current
// point to the next point
curPoint.x = sPoints[i*2];
curPoint.z = sPoints[i*2+1];
nextPoint.x = sPoints[(i+1)*2];
nextPoint.z = sPoints[(i+1)*2+1];
float l = (float)(curPoint.distance(nextPoint));
// build a vector from the current point to the next
// point of length equal to 1/2 the path width
vec.set(curPoint);
vec.sub(nextPoint);
vec.normalize();
vec.scale(width/2);
// rotate the vector right 90 degrees
rot.rotY(90*(3.14/180));
rot.transform(vec);
p2.set(vec);
p2.x += curPoint.x;
p2.z += curPoint.z;
// now reverse it to get the other point
rot.rotY(-180*(3.14/180));
rot.transform(vec);
p1.set(vec);
p1.x += curPoint.x;
p1.z += curPoint.z;
// now we have 2 points straddling the path we need to determine
their
// height
p1.y = map.getY(p1.x,p1.z)+0.3f;
p2.y = map.getY(p2.x,p2.z)+0.3f;
// determine if this is alpha blended
Color4f color = white;
if (brush.hasAlpha) {
if ((i==0) || (i>=sPoints.length/2-2))
color = invisible;
}
// System.out.println("p1:"+p1+", p2:"+p2);
geom.setCoordinate(vertex,p1);
geom.setNormal(vertex,straightUp);
geom.setColor(vertex,color);
tex.x = 0;
tex.y = (length/width)/8;
geom.setTextureCoordinate(0,vertex,tex);
vertex++;
geom.setCoordinate(vertex,p2);
geom.setNormal(vertex,straightUp);
geom.setColor(vertex,color);
tex.x = 1;
geom.setTextureCoordinate(0,vertex,tex);
vertex++;
length += l;
}
return geom;
}
-----Original Message-----
From: Alvaro Zabala [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 06, 2001 12:32 PM
To: [EMAIL PROTECTED]
Subject: [JAVA3D] TexCoords for non regular shapes
I want to apply a texture on a road which I have made with a
triangleStripArray.
The road's shape is very non regular, so compute his TexCoords maybe too
much difficult.
I'm using a TexCoordGenerator, but I don't like the result.
How can I apply a texture over a very non regular shape??
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".