Cycle through all vertexs

Blitz3D Forums/Blitz3D Programming/Cycle through all vertexs

Ross C(Posted 2003) [#1]
How would you go about cycling through all the vertexs in a mesh?


Stevie G(Posted 2003) [#2]
for surf_no = 1 to countsurfaces(mesh)
for vert_no = 0 to countvertices(surf_no)-1
{do something to vert}
vertexcolor surf_no,vert_no,blah,blah,blah
next
next

... or did you mean something else??


Ross C(Posted 2003) [#3]
yeah, that's what i mean, but i'm looking to get the co-ords of the vertexs. It's the index number that's putting me off tho. How do i get the vertexs index. When i cycle thru, i imagine it's starts at index 0?


Floyd(Posted 2003) [#4]
Here's an example, a function I wrote to examine vertex information.

; Sample usage of DumpVertices.

Graphics3D 800,600,16,2

cone=CreateCone(5)

dumpvertices(cone,100,"Blitz primitive: Cone(5)")

Stop  :  End


Function DumpVertices( mesh, maxVertices, message$="Vertex list" )

Local nSurfs, sIndex, surface, vCount, lf$, txt$
Local x$,y$,z$, nx$,ny$,nz$

	lf$=Chr$(10)	
	nSurfs=CountSurfaces( mesh )
	DebugLog lf+message+lf
	DebugLog "Number of surfaces = "+nSurfs

	For sIndex=1 To nSurfs
		DebugLog lf + lf
		DebugLog "Surface = "+sIndex+lf
		surface=GetSurface( mesh, sIndex )

		For v=0 To CountVertices( surface ) - 1
		
			vCount = vCount + 1
			If vCount > maxVertices 
				DebugLog lf+"Number of vertices shown = "+(vCount-1)
				Return
			End If

			 x = RSet(  VertexX( surface, v ), 13)
			 y = RSet(  VertexY( surface, v ), 13)
			 z = RSet(  VertexZ( surface, v ), 13)
			nx = RSet( VertexNX( surface, v ), 13)
			ny = RSet( VertexNY( surface, v ), 13)
			nz = RSet( VertexNZ( surface, v ), 13)
		
			txt="v="+RSet(v,4)+"  "+x+y+z+"     "+nx+ny+nz
			DebugLog txt
			
		Next
				
	Next
	
	DebugLog lf+"Number of vertices shown = "+vCount

End Function


I usually copy the DebugLog output and paste it into an empty window in the Blitz IDE.

The MaxVertices parameter is there so I can quickly examine some vertices without filling up the DebugLog with thousands of lines of output.

If you want all vertices just use a huge number like 999999.


Ross C(Posted 2003) [#5]
There are two surfaces on a blitz cone? Never knew that. What does knowing the normals of the vertexs help with?

Thanks for the code :)


Floyd(Posted 2003) [#6]
Normals determine how the mesh reacts to light.