Surfaces or UVs or something...

Blitz3D Forums/Blitz3D Programming/Surfaces or UVs or something...

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

A while ago, now, someone ( oops, cant rememebr who now )
kindly provided me this code to simulate a cylinder 'unwrapping' - flattening out into a rectangle.

It works fine, but now I've properly integrated it into where it needs to go, I have a problem, that I am unable to add a texture.

(I guess I might need to use brushes or what-not, but all this surfaces stuff goes over my head!)

I only need a single texture, as it should look like, say, a rolled up picture being opened.

If anyone can help with how to set tyhe UVs or whatever I need to do to texture this, Id be really, really grateful!!

Graphics3D 640,480,16,1
Global CAMERA = CreateCamera()
CameraRange CAMERA,0.001,10
WireFrame 0

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

EntityTexture Tube,Tubtext
VISIBLE = MESHflat( 1,1,1 , 16 )

EntityTexture FLAT,Flattext
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
End Function