Thursday, February 21, 2013

Trilateration of Normals for IsoSurface 3D meshes

Edit-
So I have managed a nice fast script that makes perfect normals, based on the shape formula rather than the mesh.

it can update a 6500 vertex mesh 58 times per second, pretty fast, if you need the code im around.

The rest of the posts just goes through the total puzzlement I went through to figure out the above solution, and in the end of the following solutions were kind of nonsense.

I figured that Trilateration , same as they use with GPS, would be good for surmising the exact normal position. apart from the fact we are missing the exact iso value that should exist at the normal point, as well as position. if you're really hard in maths, you can try that, it's a simple formula but it needs to be derived properly. Trying to think of triangles on and within spheres screws with your head!

Afterwards, I decided to draw  3 points very close to the vertex, measure the difference in between iso levels at the 3 points, and seeing as we can measure the precise iso level that exists at the vertex made by the marching cubes, we can prolong the 3 points as 2 segments in a straight line up to where they would meet the exact iso level of the vertex , and have the exact plane of the iso in close proximity to the vertex.

I coded it fine except it's buggy I don't know how to finish the code.
Here is a picture to show the general idea, it's basically sending out 3 points as feelers close to the vertex and prolonging the points relative to each other's value so that they equals the vertex value. that will give you 2 points coplanar to the vertex on the same iso that you make a normal from.


Its taking too long to program these things, forget both of those methods for now, I am going to do a simple solution, Which involves sampling 3 points on a small sphere surrounding vertex, taking the highest ISO value, then sampling 3 more points next to it , in a smaller radius, and then 3 more in a smaller radius, which should narrow it down to about 1/10000 in about 20 cycles, I will see if I can use a RotateAround method for it. After some thinking the best tools for that would be quaternion.aroundaxis (something) and vector3.slerp, in case one day you find yourself doing a spherical point scanner for something!

Here is a brief code for highlighting normals in unity, you have to switch to scene view to see them :
highlight normals:


#pragma strict

function Update () {

    var mesh : Mesh = GetComponent(MeshFilter).mesh;
    var vertices : Vector3[]  = mesh.vertices;
var normals : Vector3[]  = mesh.normals;

    for (var i = 0 ; i < vertices.length; i++){

vertices[i] =  transform.TransformPoint(vertices[i] );

    Debug.DrawLine (vertices[i], vertices[i] + (normals[i] * 0.1), Color.red);
}

}



1 comment:

  1. Hi there, do you mind to send me the code you used to smooth the mesh :)

    hosein_moazzen AT yahoo.com

    ReplyDelete