Surfaces or UVs or something...
Blitz3D Forums/Blitz3D Programming/Surfaces or UVs or something...| 
 | ||
| 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 | 
| 
 | ||
| A while ago, now, someone ( oops, cant rememebr who now ) That'd be me! For both MESHflat and MESHtube, using the additional params for addvertex ... Set the vertexu on V0 and V3 to be l / Segs and (l+1)/Segs on V1 and V2. Set the vertexv on V0 and V1 to be 0 and for V2 and V3 to be 1.0 That should work. Stevie | 
| 
 | ||
| Thanks, Stevie - sorry I forgot, it was quite a while ago. I still can't get it to work, I even tried usign some texture flags, but that didn't help. Here's what I have so far (I altered the camera position and range so that the image fills the viewport.) 
Graphics3D 640,480,16,1
Global CAMERA = CreateCamera()
CameraRange CAMERA,0.001,10
WireFrame 0
PositionEntity CAMERA, 0,0,-1.3
Const Radius# = 1.0
FLAT = MESHflat( Radius * Pi ,2,Radius , 16 ) : HideEntity FLAT
TUBE = MESHtube( Radius,2,Radius , 16 ) : HideEntity TUBE
Tubtext=LoadTexture("SoH%20Map2.jpg")
brush=CreateBrush() 
BrushTexture brush,Tubtext 
PaintMesh Tube,brush 
VISIBLE = MESHflat( 1,1,1 , 16 )
PaintMesh FLAT,brush 
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 ,(l/Segs ),0)
		v1 = AddVertex( s , a1 , Sy, Sz,((l+1)/Segs ),0)
		v2 = AddVertex( s , a1 , -Sy, Sz,((l+1)/Segs),1 )
		v3 = AddVertex( s , a0, -Sy, Sz , (l/Segs),1)
		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 ),(l/Segs ),0 )
		v1 = AddVertex( s , Sx * Cos( a1 ) , Sy , Sz * Sin( a1 ) ,(l/Segs ),0)
		v2 = AddVertex( s , Sx * Cos( a1 ) , -Sy , Sz * Sin( a1 ),(l/Segs ),0 )
		v3 = AddVertex( s , Sx * Cos( a0 ) , -Sy , Sz * Sin( a0 ),(l/Segs ),0 )
		AddTriangle s, v0, v1, v2
		AddTriangle s, v2, v3, v0
	Next
	
	Return Mesh
End Function
 | 
| 
 | ||
| This works ... Stevie 
Graphics3D 640,480,16,1
Global CAMERA = CreateCamera()
CameraRange CAMERA,0.001,10
WireFrame 0
PositionEntity CAMERA, 0,0,-1.3
Const Radius# = 1.0
FLAT = MESHflat( Radius * Pi ,2,Radius , 16 ) : HideEntity FLAT
TUBE = MESHtube( Radius,2,Radius , 16 ) : HideEntity TUBE
Texture = LoadTexture("ScreenShot013.bmp")
VISIBLE = MESHflat( 1,1,1 , 16 )
EntityTexture VISIBLE, Texture
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 )
		u0# = Float(l) / Float( Segs )
		u1# = Float(l+1) / Float( Segs )
		DebugLog u0
		DebugLog u1
		DebugLog "**************"
		v0 = AddVertex( s , a0 , Sy, Sz , u0,0)
		v1 = AddVertex( s , a1 , Sy, Sz, u1,0)
		v2 = AddVertex( s , a1 , -Sy, Sz, u1,1 )
		v3 = AddVertex( s , a0, -Sy, Sz , u0,1)
		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 )
		u0# = Float( l/Segs ) 
		u1# = Float( (l+1)/Segs )
		v0 = AddVertex( s , Sx * Cos( a0 ) , Sy , Sz * Sin( a0 ),u0,0 )
		v1 = AddVertex( s , Sx * Cos( a1 ) , Sy , Sz * Sin( a1 ) ,u1,0)
		v2 = AddVertex( s , Sx * Cos( a1 ) , -Sy , Sz * Sin( a1 ),u1,1 )
		v3 = AddVertex( s , Sx * Cos( a0 ) , -Sy , Sz * Sin( a0 ),u0,1 )
		AddTriangle s, v0, v1, v2
		AddTriangle s, v2, v3, v0
	Next
	
	Return Mesh
End Function
 | 
| 
 | ||
| It does indeed work! :) Thanks, muchly Stevie.You've been included in the credits for what is part of a trailer 'video' advertising a new Neverwinter Nights 2 Persistent World module out next month! |