Hi shirsoft,
I am interested in creating a vector of 2d float values which represent mesh's y-axis height for a given (x,z) coordinate. I came up with an approach (shown below); however, I think there may be a better way of doing it.
public ArrayList CalculateHeight(Mesh mesh, int meshLength)
{
float maxHeight = 20000.0f;
float distance = 0.0f;
ArrayList heightMap = new ArrayList();
IntersectInformation tmp = new IntersectInformation();
for (int z=0; z < meshLength; z++)
for (int x=-512; x < meshLength; x++)
{
mesh.Intersect(new Vector3(x, maxHeight, z), new Vector3(0.0f, -1.0f, 0.0f), ref tmp);
distance = tmp.Dist - maxHeight;
heightMap.Add(distance);
}
return heightMap;
}
Main Topics
Browse All Topics





by: shirsoftPosted on 2004-07-22 at 00:39:57ID: 11609946
Do u want to create a 2d grayscale image from a 3d mesh? if so go on and read.
Its been ages since i programmed in dx still i can give u my algo.
Iam assuming that the mesh is a axis aligned though it can be done w/o that too
Say the mesh has the height val in the z coord.
First find the bounds of the 3d mesh in the x,y plane
Also find the min z and max z value of the mesh
Also the dim of the image is known to you. And the color value of the image can be from 0-255
Now u have to do a linear scaling + translation of the x,y,z coords of the mesh to the image
Note: Only processing the vertices is sufficeient, no need to do this for the every triangle.