Meshes

Blitz3D Forums/Blitz3D Programming/Meshes

JoeRetro(Posted 2004) [#1]
I want to create a cube and paint each side a texture that is loaded from my hard drive. The code below does this for me, but I feel that I'm doing it the hard way. I'm curious to know if there is a better way to handle this. Is there a simpler way to paint each side of a cube a unique texture?

Thanks in advance!

Global top=LoadMesh("models\surface.X")

PositionMesh top,0,0,0 

; Create trunk mesh 
bottom=CopyMesh(top)
FlipMesh bottom
PositionMesh bottom,0.0,-1.0,0.0 

side1=CopyMesh(top)
RotateMesh side1,90,0,0
PositionMesh side1,0,0.0,0.0 


side2=CopyMesh(top)
RotateMesh side2,0,0,90
PositionMesh side2,0.0,0.0,0.0 


side3=CopyMesh(top)
RotateMesh side3,0,90,90
PositionMesh side3,0.0,0.0,0.0 


side4=CopyMesh(top)
RotateMesh side4,-90,90,0
PositionMesh side4,0.0,0.0,0.0 

For i=1 To MAX_CUBES
	mytex = retriveimage()
	br1=CreateBrush(255,255,255)
	BrushTexture br1, mytex
	PaintMesh top,br1
	FreeTexture mytex
	FreeBrush br1
	
	mytex = retriveimage()
	br2=CreateBrush(255,255,255) 
	BrushTexture br2, mytex
	PaintMesh bottom,br2
	FreeTexture mytex
	FreeBrush br2
	
	mytex = retriveimage()
	br3=CreateBrush(255,255,255) 
	BrushTexture br3, mytex 
	PaintMesh side1,br3
	FreeTexture mytex
	FreeBrush br3
	
	mytex = retriveimage()
	br4=CreateBrush(255,255,255) 
	BrushTexture br4, mytex
	PaintMesh side2,br4
	FreeTexture mytex
	FreeBrush br4
	
	mytex = retriveimage()
	br5=CreateBrush(255,255,255) 	
	BrushTexture br5, mytex
	PaintMesh side3,br5
	FreeTexture mytex
	FreeBrush br5
	
	mytex = retriveimage()
	br6=CreateBrush(255,255,255) 
	BrushTexture br6, mytex
	PaintMesh side4,br6
	FreeTexture mytex
	FreeBrush br6
	
	topcopy=CopyMesh(top)

	AddMesh bottom,topcopy
	AddMesh side1, topcopy
	AddMesh side2, topcopy
	AddMesh side3, topcopy
	AddMesh side4, topcopy

	s.cubes = New cubes
	s\rotx# = 0.3 + Rnd(1.0)
	s\roty# = 0.3 + Rnd(1.0)
	s\rotz# = 0.3 + Rnd(1.0)
	s\rots# = 0.3 + Rnd(1.0)
	
	s\mesh=CopyEntity(topcopy)
	ScaleMesh s\mesh, 1.8,1.8,1.8
	RotateEntity s\mesh, Rand(360), Rand(360), Rand(36)
	PositionEntity s\mesh, Rand(-MAX_FIELD/2,MAX_FIELD/2), Rand(-45,MAX_FIELD), Rand(-MAX_FIELD/2, MAX_FIELD/2)
	
	FreeEntity topcopy
	
	Cls
	Color 255,0,0
	Text 0,0,"Loading cube " + i
Flip 
	
Next

FreeEntity top
FreeEntity bottom
FreeEntity side1 
FreeEntity side2
FreeEntity side3
FreeEntity side4



Ross C(Posted 2004) [#2]
Do you have a modelling app with UV tools? If so you can set the the UV to use a texture for each side :)

Or you can build the cube out of vertexs and triangles, using addvertex and addtriangle commands :)


JoeRetro(Posted 2004) [#3]
Hey Ross,

Keep in mind I want to load 200+ textures to paint each side of a cube. So the modeling approach will not work for me.

Could you explain how building a cube with vertexes and triangles is a better approach than my method above? I would like to understand your reasoning. Perhaps it will render more efficiently, or is quicker to build and render?

Thanks!