Sign in to follow this  
SymLinked

[3D Studio MAX SDK]: Why does it export non-precise vertices?

Recommended Posts

We've developed a tile system which is pretty useless now that we've brought assets into it instead of boxes. When we're asking the SDK for verts, we get numbers like 1.000001 or 0.9999999 instead of 1.0f like it says in the model coordinate edit boxes in MAX. I've set floating point resolution to Precise, but it has no effect. I've now tried to round the values and that gets rid of the jaggies between tiles but that produces more jaggies on some models, and less on others. I'm really hitting my head against a wall here. Is this inprecision to be expected?

Share this post


Link to post
Share on other sites
Yes, that is the nature of floating point operations. Generally speaking your whole numbers should be accurate but some values can't be exactly represented in floating point numbers so you'll get something very close instead.

Share this post


Link to post
Share on other sites
You could try to create a helper program that does the following

struct Vertex
{
union {
struct {
float x;
float y;
float z;
};

float f[3];
};
};

#define MAXIMUMDIFFERENCE 0.0001f

void AnalyzeSingleVertex(Vertex &v)
{
for (unsigned int i = 0; i < 3; i++) {
if (abs(v.f[i] - floor(v.f[i])) < MAXIMUMDIFFERENCE) {
v.f[i] = float(floor(v.f[i]));
continue;
}

if (abs(v.f[i] - ceil(v.f[i])) < MAXIMUMDIFFERENCE) {
v.f[i] = float(ceil(v.f[i]));
continue;
}
}
}

int main()
{
//1. load model
//2. process vertices
//3. some other processing steps?
//4. save to new file or overwrite
}


This code will not take care of all of your accuracy problems (when dealing with vertices with a lot of digits, like 1.2357515), but I think it should convert floating numbers like 1.00001 or 0.99999 to proper floating point numbers.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this