Adjusting a triangles normal?

Blitz3D Forums/Blitz3D Programming/Adjusting a triangles normal?

JA2(Posted 2009) [#1]
Hi :)

I need some help with automatically adjusting normals on a mesh. If you look at the picture below, you can see where I've moved a section of the mesh down. It's the corners that are the problem, I'd like each corner to be the same, either a sharp corner or angled but not both like in the picture.



Here's the code to make the mesh and move sections of it up and down.

Can anyone help?




Ross C(Posted 2009) [#2]
I believe you need to call updatenormals() after you reposition your vertices. sswift has a good updatenormals function in the archives too.


Warner(Posted 2009) [#3]
This probem has not much to do with normals. The way the base mesh is created, it will allways create two different type of corners for the lowered areas. Maybe you can replace the way the triangles are connected in the 'upperleft' and 'lowerright' corner of the lowered area?



JA2(Posted 2009) [#4]
Thanks for the replies :)

Any idea how to select only the upper left and lower right triangles of the altered sections and turn them?


Warner(Posted 2009) [#5]
I believe that is not possible. The triangles are allready defined, and I don't know any way to change that. Also, if you change the vertices, the surrounding triangles are affected as well.
As far as I can see it, there are two options:
1) rebuild the mesh every time it is changed
2) use a different design for the terrain
I think that with the first approach, the terrain would require less triangles.


JA2(Posted 2009) [#6]
I think it's possible to remove the corner triangles/quads and rebuild them with the centre line facing the other way. It's a bit beyond me to this to be honest. I'm kinda hoping someone will be able to help me with this.

I'm doing this to make quick simple terrains for a small game I'm working on. I've got it setup to texture each area based on slope and height so far, just need to fix this issue with the corner areas and I can move on.


Warner(Posted 2009) [#7]
No, it is not possible to remove any triangles. Do do that, you need to clear the surface, and then rebuild it.
1. store all vertices/triangles in type
2. use ClearSurface
3. rebuild surface using AddVertex/AddTriangle

In your case, you need to UnWeld the terrain mesh, then turn the triangle, then Weld it again.
To turn the triangle, use the above method but redefine that specific triangle when your at step 3-rebuilding the surface.


Stevie G(Posted 2009) [#8]
^^ 1. Just take a copy of the mesh and use this as a reference to re-build the mesh, deleting the copy once you're done. No need to store anything in types.


JA2(Posted 2009) [#9]
I tried this for a few hours yesterday and a few more this morning. I thought I had it working but when the mesh is rebuilt with those triangles/quads facing the other direction, they get turned back to normal when the mesh is rebuilt on the next loop.

Anyway, I decided to change the way the mesh is built to begin with. Took me awhile to get it working but now the mesh is built out of hexagons instead, always giving an angled corner. Still low poly enough and looks quite good IMO.




Warner(Posted 2009) [#10]
Great work. It looks good indeed.


big10p(Posted 2009) [#11]
For some reason I cant see your images, JA2.

Anyway, one possible solution that occured to me is to create each mesh quad from 4 tris, instead of just 2, like so:
|--------|
|\      /|
| \    / |
|  \  /  |
|   \/   |
|   /\   |
|  /  \  |
| /    \ |
|/      \|
|--------|

This would let you deform the corners correctly without having to rebuild the mesh and turn triangles. You would also be able to choose sharp or rounded corners, as such a quad can be used to represent either, when deformed correctly.