#### Archived

This topic is now archived and is closed to further replies.

# Metaballs - Normals

This topic is 5764 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

At the moment I''m using the polygon normals to calc the vertex normals. If you look close enough you''ll notice the mapping isn''t perfect. Does anyone know how to calculate the vertex normals on these metaballs?

##### Share on other sites
Maybe this''ll help:
I''m using the marching cubes algorithm...

Any comment links or whatever is respected...

##### Share on other sites
During the calculations of the triangles with marching cubes, you should add the normal of each triangle to the used vertex normals. When all triangles has been defined the normals are normalized. (If you use OpenGL or Direct3D the API can do the normalization for you, probably faster than you yourself can do it.)

You of course need some way of storing the vertices and vertex normals so that they can be shared among the triangles. To figure out the correct way of storing the vertices you should think of that the cubes has 12 edges that are all shared among four cubes.

- WitchLord

##### Share on other sites
First of all, thanks for your response WitchLord!

To take this further...

I''m not using OpenGL or DirectX, but I''m coding an oldfashioned software rendered engine, but that''s ok. I''ve got the principle of normal calculation under control.

When I use x triangle normals I just calculate the average normal. (Add the normals, and normalize again)
Here''s the problem (You don''t need to know metaballs to solve this!):

Most polygons are on one side:

top view

When I calculate the "average normal" I get the red normal:

side view

I need the blue normal...

##### Share on other sites
Any marching-cube-guru''s around?

##### Share on other sites
The solution to that particular problem is that you add a fraction of the triangle normal depending on the angle that the two edges sharing the vertex make.

Let's say you want to compute the normal for vertex V0 in a triangle V0,V1,V2

You can compute the normal like this:

E1 = V1-V0
E2 = V2-V0
Normal = CrossProduct(E1,E2);

The length of this normal is dependant on the angle between the two edges E1 and E2. And also the length of the edges like this:

LengthOf(Normal) = LengthOf(E1)*LengthOf(E2)*sin(SmallestAngleBetween(E1,E2))

If you add this normal to the vertex directly without normalizing it first you'll almost have what you want. The larger triangles have more influence than than smaller. I suggest that you try this way as I believe it gives an acceptable approximation.

If you want it to be perfect then you need to compute the actual angle between the edges. Which is done with either

angle = asin(LengthOf(Normal)/LengthOf(E1)/LengthOf(E2))

or

angle = acos(DotProduct(E1,E2)/LengthOf(E1)/LenghtOf(E2))

The second is derived from the formula for the dot product:

DotProduct(E1,E2) = LengthOf(E1)*LengthOf(E2)*cos(SmallestAngleBetween(E1,E2))

In either case the determination of the angle requires a lot of computations (as you can see).

Then the normals should be summed together like this:

V0Normal += angle/2/pi*Normalize(Normal);

Does this make me a marching-cube-guru?

- WitchLord

Edited by - WitchLord on May 19, 2000 8:39:44 PM

##### Share on other sites
whoa whoa wait.. cant you just use the first derivative? i havent looked into metaballs a whole lot, but as far as i understand, they're implicit surfaces and as such can be differentiated..

--
Float like a butterfly, bite like a crocodile.

Edited by - goltrpoat on May 21, 2000 10:42:00 AM

##### Share on other sites
The metaballs can be described mathematically with implicit surfaces, but it is my belief that it would require a lot more computations to find the normal from the first derivative than the method I describe. At least if you are using marching cubes to produce the surfaces.

But then again I haven''t worked with metaballs myself either so I could be completely wrong.

- WitchLord

##### Share on other sites
Brilliant, WitchLord!!!!!!!!!!

That I didn''t think of it...use the angle to multiply with the normal, add em all and normalize...perfect!

> Does this make me a marching-cube-guru?

Well, If you as me - not a marching-cube-guru -
The solution is to a more trivial problem. (So it''s even better)
You can use this in a lot more of normal calculations!
Never thought anyone could answer this, thanks! ...Brilliant perfect superb...!!!

##### Share on other sites
Why, thank you!

I can''t take credit for the solution though as I read it somewhere. I just can''t remember where.

- WitchLord

• 17
• 19
• 24
• 10
• 21