HHelp with Working with Mesh Tris

Blitz3D Forums/Blitz3D Programming/HHelp with Working with Mesh Tris

_PJ_(Posted 2007) [#1]
What I am trying to achieve is to have a stanadard Cylinder mesh with no 'ends' like a tube (standing 'vertical' like a flagpole) and then for it to 'split' at the 'back' (furthest from the camera) and 'unwrap' until it becomes a flat rectangle.

I know the theory here, I need to select a point on the cylinders' "top" circumference, then Unweld the Tris down in a vertical line.

Starting with these Tri's and working around the cylinder, they need to gradually be rotated to face the camera and be moved outwards away from the sylinder center (effectively towards the edge of the viewport).

Hope this makes sense! I have no idea how to do this as my knowledge of tri's, vertices etc. is really really poor :(

I'd welcome and appreciate any help on this matter!


Stevie G(Posted 2007) [#2]
LIke this ....

Graphics3D 640,480,16,1
Global CAMERA = CreateCamera()

WireFrame 1

PositionEntity CAMERA, 0,0,-5

Const Radius# = 1.0

FLAT = MESHflat( Radius * Pi ,2,Radius , 16 ) : HideEntity FLAT
TUBE = MESHtube( Radius,2,Radius , 16 ) : HideEntity TUBE

VISIBLE = MESHflat( 1,1,1 , 16 )

Dir# = 1.0 : TimeStep# = 0.0

While Not KeyDown(1)

	TimeStep = TimeStep + .01 * Dir
	If TimeStep >= 1.0 Dir = - 1
	If TimeStep <= 0.0 Dir = 1.0 

	MESHmorph( VISIBLE , TUBE, FLAT , TimeStep )

	RenderWorld()
	Flip

Wend

;====================================================================================
;====================================================================================
;====================================================================================

Function MESHmorph( Source , Initial , Final , T# )

	ss = GetSurface( Source , 1 )
	is = GetSurface( Initial , 1 )
	fs = GetSurface( Final , 1 )
	
	For v = 0 To CountVertices( ss ) - 1
	
		Nx# = VertexX( is, v ) + ( VertexX( fs , v ) - VertexX( is , v ) ) * T
		Ny# = VertexY( is, v ) + ( VertexY( fs , v ) - VertexY( is , v ) ) * T
		Nz# = VertexZ( is, v ) + ( VertexZ( fs , v ) - VertexZ( is , v ) ) * T
		VertexCoords ss, v , Nx, Ny, Nz
		
	Next
	
End Function

;====================================================================================
;====================================================================================
;====================================================================================

Function MESHflat( Sx#, Sy#, Sz#, Segs = 8 )

	Mesh = CreateMesh()
	s = CreateSurface( Mesh )

	For l = 0 To Segs - 1
		a0# = - Sx + 2.0 * Sx * Float( l ) / Float( Segs )  
		a1# = - Sx + 2.0 * Sx * Float ( l + 1 ) / Float( Segs )
		v0 = AddVertex( s , a0 , Sy, Sz )
		v1 = AddVertex( s , a1 , Sy, Sz )
		v2 = AddVertex( s , a1 , -Sy, Sz )
		v3 = AddVertex( s , a0, -Sy, Sz )
		AddTriangle s, v0, v1, v2
		AddTriangle s, v2, v3, v0
	Next
	
	Return Mesh
		
End Function

;====================================================================================
;====================================================================================
;====================================================================================

Function MESHtube( Sx#, Sy#, Sz# , Segs = 8 )

	Mesh = CreateMesh()
	s = CreateSurface( Mesh )

	For l = 0 To Segs - 1
		a0# = 90.0 + l * 360.0 / Float( Segs )	;+90 important so starts at rear
		a1# = 90.0 + ( l + 1 ) * 360.0 / Float( Segs )
		v0 = AddVertex( s , Sx * Cos( a0 ) , Sy , Sz * Sin( a0 ) )
		v1 = AddVertex( s , Sx * Cos( a1 ) , Sy , Sz * Sin( a1 ) )
		v2 = AddVertex( s , Sx * Cos( a1 ) , -Sy , Sz * Sin( a1 ) )
		v3 = AddVertex( s , Sx * Cos( a0 ) , -Sy , Sz * Sin( a0 ) )
		AddTriangle s, v0, v1, v2
		AddTriangle s, v2, v3, v0
	Next
	
	Return Mesh
		



_PJ_(Posted 2007) [#3]
Just like that!

Perfect, Stevie!

The MESHMorph function seems really useful too! I might have a playaround and see what else I can make this do, (and maybe learn a bit about the Addvertex funcs etc. too!)

Thanks a million!