Tile texture on mesh?

Blitz3D Forums/Blitz3D Programming/Tile texture on mesh?

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.

Sometimes I think I'm invisible here. Below is a function I knocked up for you and example usage ...

Graphics3D 640,480,16,1

;create texture
tex = CreateTexture( 64, 64 )
SetBuffer TextureBuffer( tex )
For y = 0 To 1
	For x = 0 To 1
		If ( x + y ) Mod 2 = 0
			Color 255,0,0
		Else
			Color 0,0,255
		EndIf
		Rect x*32,y*32,32,32,1
	Next
Next
SetBuffer BackBuffer()

;set up camera
camera = CreateCamera()
PositionEntity camera, 0,0,-10
pivot = CreatePivot()

;create normal cube
cube = CreateCube( pivot )
PositionEntity cube, 5,0,0
EntityTexture cube, tex

;create wide cube
widecube = CopyMesh( cube, pivot )
PositionEntity widecube, -5,0,0
ScaleMesh widecube, 3,1,1
MESHscaleUV( widecube, 1 , 3,1 )
EntityTexture widecube, tex

;create tall cube
tallcube = CopyMesh( cube, pivot )
PositionEntity tallcube, 0,0,5
ScaleMesh tallcube, 1,4,1
MESHscaleUV( tallcube, 2, 1, 4 )
EntityTexture tallcube, tex

;create long cube
longcube = CopyMesh( cube, pivot )
PositionEntity longcube, 0,0,-5
ScaleMesh longcube, 1,1,2
MESHscaleUV( longcube, 3, 2, 1 )
EntityTexture longcube, tex

;show
While Not KeyDown(1)

	TurnEntity pivot, 0,1,0
	RenderWorld()
	Flip

Wend

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

Function MESHscaleUV( mesh , Axis , ScaleU#, ScaleV# )

	;axis = 1 = x
	;axis = 2 = y
	;axis = 3 = z
	
	s = GetSurface( mesh ,1 )
	
	For v = 0 To CountVertices( s ) - 1
	
		Select Axis
			Case 1
				CHANGE = ( VertexNY( s, v ) <> 0 Or VertexNZ( s, v ) <> 0 )
			Case 2
				CHANGE = ( VertexNX( s, v ) <> 0 Or VertexNZ( s, v ) <> 0 )
			Case 3
				CHANGE = ( VertexNX( s, v ) <> 0 Or VertexNY( s, v ) <> 0 )
		End Select

		If CHANGE VertexTexCoords s, v, VertexU( s, v ) * ScaleU , VertexV( s, v ) * ScaleV
	
	Next
	
End Function