The paper discussion in OT reminded me of this little problem I have :)
I am trying to make a function that decides whether or not an entity will work as a convex hull, because the convex hull program doesn't like flat meshes and the bloody user never remembers this. So basically, it decides if a mesh is flat (regardless of its angle, etc.).
So, here is my function which doesn't work:
Sorry, there aren't many comments, but the debuglog entries help a bit.
I also haven't looked at this code recently and I sort of gave up halfway through so that's my early excuse for any stupid mistakes.
So, do you have a better way to do this or a way to fix this function?
I am trying to make a function that decides whether or not an entity will work as a convex hull, because the convex hull program doesn't like flat meshes and the bloody user never remembers this. So basically, it decides if a mesh is flat (regardless of its angle, etc.).
So, here is my function which doesn't work:
function isFlat(mesh,surface) if meshwidth(mesh) = 0 or meshheight(mesh) = 0 or meshdepth(mesh) = 0 then debuglog "IsFlat() Returns that entity is flat (via meshWidth() etc. check)" : return true LastX# = vertexX(surface,0) LastY# = vertexy(surface,0) LastZ# = vertexz(surface,0) Debuglog "Matching X: " + lastX# Debuglog "Matching Y: " + lastY# Debuglog "Matching Z: " + lastZ# ChangePitch# = 0 ChangeYaw# = 0 ChangedCount = 0 for vert = 1 to countvertices(surface) - 1 pass = false if vertexx(surface,vert) = LastX pass = true debuglog "X position the same. Vertex number " + vert else debuglog "X axis changed, leaving note" XChange = true endif if vertexy(surface,vert) = LastY pass = true debuglog "Y position the same. Vertex number " + vert else debuglog "Y axis changed, leaving note" YChange = true endif if vertexZ(surface,vert) = LastZ pass = true debuglog "Z position the same. Vertex number " + vert else debuglog "Z axis changed, leaving note" ZChange = true endif if XChange or YChange or ZChange if changedcount < 1 ;there can be one single position change without argument ChangedCount = ChangedCount + 1 changepitch# = vectorpitch(lastX - vertexx(surface,vert),lastY - vertexy(surface,vert),lastZ - vertexZ(surface,vert)) changeYaw# = vectoryaw(lastX - vertexx(surface,vert),lastY - vertexy(surface,vert),lastZ - vertexZ(surface,vert)) pass = true else ;another position change will get argument, and will only work if it is still carrying along the same angle as the last one if ChangePitch# = vectorpitch(vertexx(surface,vert),vertexy(surface,vert),vertexZ(surface,vert)) and changeYaw# = vectoryaw(vertexx(surface,vert),vertexy(surface,vert),vertexZ(surface,vert)) pass = true else pass = false endif endif endif if pass = false then debuglog "IsFlat() Returns that entity is not flat (via vertex section)" : return false next debuglog "IsFlat() Returns that entity is flat" return true end function
Sorry, there aren't many comments, but the debuglog entries help a bit.
I also haven't looked at this code recently and I sort of gave up halfway through so that's my early excuse for any stupid mistakes.
So, do you have a better way to do this or a way to fix this function?