Tris/Verts Help

Blitz3D Forums/Blitz3D Programming/Tris/Verts Help

wmaass(Posted 2004) [#1]
How would you go about doing the following properly?

Say I have a mesh and I color all of its vertices blue. Then I color a patch of vertices in the middle of it red. Now I want to "optimize" this mesh by removing all the vertices that are blue in order to reduce the triangle count.


jfk EO-11110(Posted 2004) [#2]
pretty confusing question :°/

right now I am not sure if there is a command like GetVertexColor :) But if there is such a command (yes, shame on me), then I'd use it to create a list of vertices and tris that I will keep. Then I'd assemble a new Mesh with the used Vertices only and then delete the original one.

But why would you need this?


N(Posted 2004) [#3]
First, I'd take a look at this:
http://blitzbasic.com/codearcs/codearcs.php?code=1080

Then I'd go through all your vertices and see if they're colored blue, and use the code I linked to above to remove (or get an idea of how you can remove them) the vertices.


wmaass(Posted 2004) [#4]
jfk,

Frankly? For an ALE like landscape thingy (skitch, your program is awesome!). I want to get rid of triangles that don't end up being used in the process of "painting" the vertices to reveal a texture layer. I probably should just buy the damn thing but I'm trying to learn a thing or two. Noel and jfk thanks for the bearing on this -- I'll give it a try using that neat function. My initial try produced some weird results, the mesh I wanted to "keep" ended up malformed. I suspect that is because a vertex I'm deleting actually makes up a triangle that has another vertex that I need. If I can't get it all have to post some crap code that hopefully someone can help with. I can do this so far but I end up with many more triangles than I need -- basically the number of triangles in the base layer times 4 in this screen shot, which of course is not very efficient.




CyberHeater(Posted 2004) [#5]
How are your meshes constucted? If your using shared vertex then that is the problem.

Here is the algorythm that I use to construct my meshes.

first I use this bit to call the function

	For loop = 1 To V_Pos -1
		For p_loop = 0 To profile_end -1

			x1 = T_PointsX (loop-1, p_loop) : 	x2 = T_PointsX (loop-1, p_loop+1)
			x3 = T_PointsX (loop,p_loop) :		x4 = T_PointsX (loop,p_loop+1)

			y1 = T_PointsY (loop-1, p_loop) : 	y2 = T_PointsY (loop-1, p_loop+1)
			y3 = T_PointsY (loop,p_loop) :		y4 = T_PointsY (loop,p_loop+1)

			z1 = T_PointsZ (loop-1,p_loop) : 	z2 = T_PointsZ (loop-1,p_loop+1)
			z3 = T_PointsZ (loop,p_loop) :		z4 = T_PointsZ (loop,p_loop+1)
			DrawQuadOnSurface (x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4,y5,1,0,1,surf)
		Next	
	Next


and then use this function to draw the quad


Function DrawQuadOnSurface (x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4,start_u#,end_u#,start_v#,end_v#,surf)
;2---3 (x3,y3,z3,x4,y4,z4)
;|    |
;0---1 (x1,y1,z1,x2,y2,z2)
		v0 = AddVertex (surf,x3,y3,z3,start_u,start_v) ; 0 left top
		v1 = AddVertex (surf, x4,y4,z4,end_u,start_v); 1 right top
		v2 =AddVertex (surf,x1,y1,z1,start_u,end_v) ; 2 left bottom
		v3 =AddVertex (surf,x2,y2,z2,end_u,end_v) ; 3 right bottom
		AddTriangle surf,v2,v0,v1 ; and 2 triangles...
		AddTriangle surf,v2,v1,v3
End Function


Each quad has it's own set of vertex.


wmaass(Posted 2004) [#6]
Ah ha, I think you are right. I'll give that a try.


REDi(Posted 2004) [#7]
@CyberHeater
Whoa, Vertex overkill! there is a vertex limit you know ;) (hint,hint)

@wmaass
You need to check each vertex of each triangle for alpha, if there is alpha on any one of the three vertices you must include that tri, if not don't include it on your optimized mesh. Then your left with some vertices that aren't being used, so get rid of them (rebuild the mesh without these vertices).

HINT... You could create a custom type containing the new and old vertex indexs.

Optimizer Challenge... (shameless plug for future release)
My optimizer can do 100x100 landscape at around one layer per second, so theres something for you to aim at. ;)

BTW You must also remove tris that have been painted over by another layer with an alpha of 1.


wmaass(Posted 2004) [#8]
Hehe, I've made some progress using the remove tri functions is the code archives doing pretty much what you describe -- however its pretty slooowww. If I can get it faster then I think your last suggestion is next. There is not need to have those extra triangles on the base layer if they are covered.


REDi(Posted 2004) [#9]
I haven't optimized the base layer at all in my app, because I think it would double the surface count and increase the vertex count, eg each layer would need a non vertex alpha version, otherwise you'll get zbuffer problems.

If you want to speed things up, try doing it without those functions, calling them is doing alot more "For Next" loops than you really need too.