Assigning textures to a cube ?

Blitz3D Forums/Blitz3D Beginners Area/Assigning textures to a cube ?

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.

I tackled this using some code by Birdie that makes a segmented cube rather than straightforward CreateCube().

Graphics3D 800, 600

Global burn = LoadAnimTexture("burnhole.jpg", 2, 128, 128, 0, 8)
Global raze = LoadAnimTexture("raze.jpg",2, 128, 128, 0, 8)
Global burnbrush = CreateBrush()
Global razebrush = CreateBrush()
BrushTexture burnbrush, burn, 0
BrushTexture razebrush, raze, 0

Global cam = CreateCamera()
PositionEntity cam, 0,8,-15
Global light = CreateLight()
Global cube = create_scube();CreateCube()

PositionEntity cube, 0, -2, 10
PositionEntity light, 10, 40, -20

Repeat
SeedRnd(MilliSecs())
For ii = 1 To 20
	CreateBurningCube()
Next
	

While Not KeyHit(1)
	Delay 100
	UpdateBurningCube()
	RenderWorld
	Flip
Wend 

WaitKey
For ditch.BurningCube = Each BurningCube
	Delete ditch
Next
Until MouseHit(1)

End
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Type BurningCube
	 Field itsmesh
	 Field x
	 Field y
	 Field z
	 Field lifetime
End Type

;==================================================================================
Function CreateBurningCube()
	newcube.BurningCube = New BurningCube
	newcube\x = Rnd(20)-10
	newcube\y = Rnd(20)-10
	newcube\z = Rnd(20)-10
	newcube\itsmesh = create_scube()
	PositionEntity newcube\itsmesh, newcube\x, newcube\y, newcube\z
	newcube\lifetime = 24 + Rnd(500)
End Function
;==================================================================================
Function UpdateBurningCube()
	For acube.BurningCube = Each BurningCube
		Select True
			   Case acube\lifetime > 15   ; burn the top
					If acube\lifetime < 25 Then
						burningbrush = CreateBrush()
						BrushTexture burningbrush, burn, 23 - acube\lifetime
						surf = GetSurface(acube\itsmesh, 5)
						PaintSurface surf, burningbrush
						FreeBrush burningbrush
					EndIf
			   Case acube\lifetime = 15
					black = CreateBrush (0,0,0)
					;BrushBlend black, 1
					BrushAlpha black, 0
					surf = GetSurface(acube\itsmesh, 5)
					PaintSurface surf, black
					FreeBrush black
			
			   Case acube\lifetime = 8
					black = CreateBrush (0,0,0)
					BrushAlpha black, 0
					For s = 1 To 4
						surf = GetSurface(acube\itsmesh, s)
						PaintSurface surf, black
					Next
					FreeBrush black
			   Case acube\lifetime < 8    ; burn the bottom
			
			   Case acube\lifetime = 0
				FreeEntity acube\itsmesh
			   Default
					razingbrush = CreateBrush()
					BrushTexture razingbrush, raze, 15 - acube\lifetime
					For s = 1 To 4
						surf = GetSurface(acube\itsmesh, s)
						PaintSurface surf, razingbrush
					Next
		End Select
		
	If acube\lifetime > 0 Then
		acube\lifetime = acube\lifetime - 1
	EndIf
	Next
End Function
;==================================================================================
Function create_scube()             ; original code by Birdie
	Local cmesh,surf,v0,v1,v2,v3
	cmesh=CreateMesh()
	surf=CreateSurface(cmesh)
	v0=AddVertex(surf,-1,1,-1,0,0)
	v1=AddVertex(surf,1,1,-1,1,0)
	v2=AddVertex(surf,-1,-1,-1,0,1)
	v3=AddVertex(surf,1,-1,-1,1,1)
	AddTriangle surf,v0,v1,v2
	AddTriangle surf,v1,v3,v2
	surf=CreateSurface(cmesh)
	v0=AddVertex(surf,-1,1,1,0,0)
	v1=AddVertex(surf,-1,1,-1,1,0)
	v2=AddVertex(surf,-1,-1,1,0,1)
	v3=AddVertex(surf,-1,-1,-1,1,1)
	AddTriangle surf,v0,v1,v2
	AddTriangle surf,v1,v3,v2
	surf=CreateSurface(cmesh)
	v0=AddVertex(surf,1,1,1,0,0)
	v1=AddVertex(surf,-1,1,1,1,0)
	v2=AddVertex(surf,1,-1,1,0,1)
	v3=AddVertex(surf,-1,-1,1,1,1)
	AddTriangle surf,v0,v1,v2
	AddTriangle surf,v1,v3,v2
	surf=CreateSurface(cmesh)
	v0=AddVertex(surf,1,1,-1,0,0)
	v1=AddVertex(surf,1,1,1,1,0)
	v2=AddVertex(surf,1,-1,-1,0,1)
	v3=AddVertex(surf,1,-1,1,1,1)
	AddTriangle surf,v0,v1,v2
	AddTriangle surf,v1,v3,v2
	surf=CreateSurface(cmesh)
	v0=AddVertex(surf,-1,1,1,0,0)
	v1=AddVertex(surf,1,1,1,1,0)
	v2=AddVertex(surf,-1,1,-1,0,1)
	v3=AddVertex(surf,1,1,-1,1,1)
	AddTriangle surf,v0,v1,v2
	AddTriangle surf,v1,v3,v2
	surf=CreateSurface(cmesh)
	v0=AddVertex(surf,-1,-1,-1,0,0)
	v1=AddVertex(surf,1,-1,-1,1,0)
	v2=AddVertex(surf,-1,-1,1,0,1)
	v3=AddVertex(surf,1,-1,1,1,1)
	AddTriangle surf,v0,v1,v2
	AddTriangle surf,v1,v3,v2
	UpdateNormals cmesh
	Return cmesh
End Function


You can use these animstrips that are referenced in the code...
[img http:\\www.blackjumper.com\selling\burnhole.jpg]

[img http:\\www.blackjumper.com\selling\raze.jpg]