'Cutting a hole' in an object with vertex alpha?

Blitz3D Forums/Blitz3D Programming/'Cutting a hole' in an object with vertex alpha?

John Pickford(Posted 2003) [#1]
Is this possible?

I want to create an apparent 'hole' in an object by comparing the distance of each vertex to an arbitrary 3d line. Those within a certain distance will have vertex alpha set to 1 and others set to zero (those on the fringe will be set somewhere in between).

I'm not sure how to scan through the vertex list of a mesh.


semar(Posted 2003) [#2]

I'm not sure how to scan through the vertex list of a mesh.


As far as I understand, you should:
- go through all the surfaces of a mesh and
-- for each surface, go for all the triangles and
---- for each triangle, pick the 3 vertex (0,1,2)

In this way, you can scan through all the vertex of a mesh.

I think you may find useful these commands:

CountSurfaces(mesh) -> returns how many surfaces the mesh is made with

Getsurface(mesh,n) -> returns the handle of the nth surface

CountTriangles(surface) -> returns how many triangles that surface is made with

TriangleVertex ( surface,triangle_index,corner )
Parameters:
surface - surface handle
triangle_index - triangle index
corner - corner of triangle. Should be 0, 1 or 2.
Description:
Returns the vertex of a triangle corner.

Do I have understood right your question ?

Sergio.


BlitzSupport(Posted 2003) [#3]
John, this covers parsing a mesh down to vertex level -- very straightforward:

http://www.blitzbasic.com/codearcs/codearcs.php?code=380

What the heck... here's the relevant part:

			; Parse each surface in mesh...
			
			For s = 1 To CountSurfaces (mesh)
	
				surf = GetSurface (mesh, s)
	
				; Parse each triangle in surface...
				
				For t = 0 To CountTriangles (surf) - 1
	
					; Get triangle's vertice positions... presumably these are
					; in anti-clockwise order (since it appears to work :)
	
					v0 = TriangleVertex (surf, t, 0)
					v1 = TriangleVertex (surf, t, 1)
					v2 = TriangleVertex (surf, t, 2)

Next: Next ; [Quick-fix edit!]



John Pickford(Posted 2003) [#4]
Yes it sounds like you understood my question.


Can I just get directly to the vertices and ignore triangles all together?

Presumably the vertex coords will be local to the mesh so I'll have to either transform them into their world position or put my object at 0,0,0 (quite possible on this project).


John Pickford(Posted 2003) [#5]
What does TriMesh mean?


John Pickford(Posted 2003) [#6]
Found it (380) I mean.

Here's a simple version (untested). It cuts a spherical hole in the mesh.

Function cut_hole_in_mesh (mesh,hx#,hy#,hz#,size#)

	
	For s = 1 To CountSurfaces (mesh) 
		surf = GetSurface (mesh, s) ; Parse each triangle in surface... 
			For t = 0 To CountTriangles (surf) - 1 ; Get triangle's vertice positions... presumably these are ; in anti-clockwise order (since it appears to work :) 
				For v=0 To 2
							vert = TriangleVertex (surf, t, v)
			
							dx#=VertexX(surf,vert)-hx
							dy#=VertexY(surf,vert)-hy
							dz#=VertexZ(surf,vert)-hz
							
							dist#=Sqr (dx*dx+dy*dy+dz*dz)
							
							If dist< size Then alpha#=0 Else alpha#=1
							
							VertexColor surf,vert,255,255,255,alpha

			
			
			
						Next
				  Next
				
			
			
			
		Next
		
		
End Function		




semar(Posted 2003) [#7]
A small optimization:

if dist < size Then
VertexColor surf,vert,255,255,255,0
endif

You save an 'else' clause always, and a vertexcolor command when dist >= size.

BTW, that's a pretty handy function !

Sergio.


John Pickford(Posted 2003) [#8]
Yes but it won't reset the alpha's (remove previous holes).


John Pickford(Posted 2003) [#9]
Cheers for the help BTW!


BlitzSupport(Posted 2003) [#10]

What does TriMesh mean?


That was pre-edit -- there was a forum code for archive entries, but it looks like I've forgotten it...


John Pickford(Posted 2003) [#11]
I realised I can use countvertices and bypass the triangle all together. This prevents any vertex being processed more than once (very likely on a triangle by triangle basis).


semar(Posted 2003) [#12]

I realised I can use countvertices and bypass the triangle all together.


So, what's about updating your handy function and post it into the code archive ?

:)

Sergio.