Newbie needs Surface help!

Blitz3D Forums/Blitz3D Programming/Newbie needs Surface help!

C64Retro(Posted 2003) [#1]
Hi guys,

I've been a long-time Blitz user, but even though I have Blitz3D I've only ever done 2D stuff.

I'm now starting on the basic 3D stuff, and I was wondering if someone could help.

With a lot of the surface examples given, CreateCube() is used and a texture is applied, but this texture is applied to ALL faces of the cube. I would, however, like to create a separate texture for each surface of the cube.

Am I right in thinking that CreateCube() does "too much" of the hard work, so you can't apply separate textures; which means building your own cube from scratch?

Whatever the answer, could someone just give me some tips on how to create a cube with different textures on each face?

Ta v much!

Boz.


Ross C(Posted 2003) [#2]
i dunno, much about your actual question but a cube (created with createcube() has only one surface, that's why the textures the same all over. you could make a texture with all the sides you want and modify the texture locations with the VertexTexCoords command, or create 6 quads and position them to make up a cibe.


DrakeX(Posted 2003) [#3]
you could build one from scratch with the mesh commands, it's not too hard. it's just 6 surfaces with 2 triangles each. the only "hard" part would be getting all the face vertex orders right.

let me try..

here.

Graphics3D 640,480
SetBuffer BackBuffer()

Global cam=CreateCamera()
Global light1=CreateLight()
RotateEntity light1,45,45,45

MoveEntity cam,0,0,-10

c=CreateCube6sfc()

Repeat

TurnEntity c,1,1,1

UpdateWorld
RenderWorld

Flip
Until KeyDown(1)
End

Function CreateCube6sfc(parent=0)
	m=CreateMesh()
	sfc=CreateSurface(m)
	AddVertex sfc,-1,1,-1 : AddVertex sfc,1,1,-1
	AddVertex sfc,1,-1,-1 : AddVertex sfc,-1,-1,-1
	VertexNormal sfc,0,0,0,-1 : VertexNormal sfc,1,0,0,-1
	VertexNormal sfc,2,0,0,-1 : VertexNormal sfc,3,0,0,-1
	AddTriangle sfc,0,1,2 : AddTriangle sfc,2,3,0
	
	sfc=CreateSurface(m)
	AddVertex sfc,-1,1,-1 : AddVertex sfc,-1,1,1
	AddVertex sfc,1,1,1   : AddVertex sfc,1,1,-1
	VertexNormal sfc,0,0,1,0 : VertexNormal sfc,1,0,1,0
	VertexNormal sfc,2,0,1,0 : VertexNormal sfc,3,0,1,0
	AddTriangle sfc,0,1,2 : AddTriangle sfc,2,3,0
	
	sfc=CreateSurface(m)
	AddVertex sfc,-1,1,1  : AddVertex sfc,-1,-1,1
	AddVertex sfc,1,-1,1  : AddVertex sfc,1,1,1
	VertexNormal sfc,0,0,0,1 : VertexNormal sfc,1,0,0,1
	VertexNormal sfc,2,0,0,1 : VertexNormal sfc,3,0,0,1
	AddTriangle sfc,0,1,2 : AddTriangle sfc,2,3,0
	
	sfc=CreateSurface(m)
	AddVertex sfc,-1,-1,-1 : AddVertex sfc,1,-1,-1
	AddVertex sfc,1,-1,1   : AddVertex sfc,-1,-1,1
	VertexNormal sfc,0,0,-1,0 : VertexNormal sfc,1,0,-1,0
	VertexNormal sfc,2,0,-1,0 : VertexNormal sfc,3,0,-1,0
	AddTriangle sfc,0,1,2  : AddTriangle sfc,2,3,0
	
	sfc=CreateSurface(m)
	AddVertex sfc,-1,1,1   : AddVertex sfc,-1,1,-1
	AddVertex sfc,-1,-1,-1 : AddVertex sfc,-1,-1,1
	VertexNormal sfc,0,-1,0,0 : VertexNormal sfc,1,-1,0,0
	VertexNormal sfc,2,-1,0,0 : VertexNormal sfc,3,-1,0,0
	AddTriangle sfc,0,1,2  : AddTriangle sfc,2,3,0
	
	sfc=CreateSurface(m)
	AddVertex sfc,1,1,-1  : AddVertex sfc,1,1,1
	AddVertex sfc,1,-1,1  : AddVertex sfc,1,-1,-1
	VertexNormal sfc,0,1,0,0 : VertexNormal sfc,1,1,0,0
	VertexNormal sfc,2,1,0,0 : VertexNormal sfc,3,1,0,0
	AddTriangle sfc,0,1,2 : AddTriangle sfc,2,3,0
	
	EntityParent m,parent
	Return m
End Function


this function can be used in place of the CreateCube() function (even with the optional parent parameter).

you can use the Brush commands PaintSurface to affect the visual properties of each surface. the surfaces are as follows:

1 - front
2 - top
3 - back
4 - bottom
5 - left
6 - right

there :)


C64Retro(Posted 2003) [#4]
Thanks, DrakeX!

That's exactly what I needed - just an example of building something from the fround up. I will try that now...

Cheers

Boz.


C64Retro(Posted 2003) [#5]
Hmmm, following on from this; the cube itself worked but I'm unable to paint a texture onto it. It seems to just take the top-left pixel's color and use that. Scaling the texture doesn't do anything either.

I decided to cut down the program and just have one surface. It works, but the same problem happens - no texture.

The code I have is:

mesh = CreateMesh()
sfc = CreateSurface(mesh)

AddVertex sfc, 0, 0, 0 ; 0 (bl)
AddVertex sfc, 0, 12.5, 0 ; 1 (tl)
AddVertex sfc, 14, 12.5, 0 ; 2 (tr)
AddVertex sfc, 14, 0, 0 ; 3 (br)
AddTriangle sfc, 0, 1, 3
AddTriangle sfc, 1, 2, 3

; Add a texture To this
b = CreateBrush()
t = LoadTexture( "BozTest.bmp" )
BrushTexture b, t
BrushShininess b, 1
PaintSurface sfc, b

It _seems_ right, but I'm probably being as thick as pig-poo and forgetting something vital(!). The Shininess works - the color that's on the surface sparkles when the light hits it dead-on, but the texture-map just isn't plotted.

Any thoughts?

Cheers

Boz.


DrakeX(Posted 2003) [#6]
oh *slaps forehead* stupid me. i forgot to put the UV coords in the cube function. hold on....

here's the new cube function.

Function CreateCube6sfc(parent=0)
	m=CreateMesh()
	sfc=CreateSurface(m)
	AddVertex sfc,-1,1,-1,0,0 : AddVertex sfc,1,1,-1,1,0
	AddVertex sfc,1,-1,-1,1,1 : AddVertex sfc,-1,-1,-1,0,1
	VertexNormal sfc,0,0,0,-1 : VertexNormal sfc,1,0,0,-1
	VertexNormal sfc,2,0,0,-1 : VertexNormal sfc,3,0,0,-1
	AddTriangle sfc,0,1,2 : AddTriangle sfc,2,3,0
	
	sfc=CreateSurface(m)
	AddVertex sfc,-1,1,-1,0,0 : AddVertex sfc,-1,1,1,1,0
	AddVertex sfc,1,1,1,1,1   : AddVertex sfc,1,1,-1,0,1
	VertexNormal sfc,0,0,1,0 : VertexNormal sfc,1,0,1,0
	VertexNormal sfc,2,0,1,0 : VertexNormal sfc,3,0,1,0
	AddTriangle sfc,0,1,2 : AddTriangle sfc,2,3,0
	
	sfc=CreateSurface(m)
	AddVertex sfc,-1,1,1,0,0  : AddVertex sfc,-1,-1,1,1,0
	AddVertex sfc,1,-1,1,1,1  : AddVertex sfc,1,1,1,0,1
	VertexNormal sfc,0,0,0,1 : VertexNormal sfc,1,0,0,1
	VertexNormal sfc,2,0,0,1 : VertexNormal sfc,3,0,0,1
	AddTriangle sfc,0,1,2 : AddTriangle sfc,2,3,0
	
	sfc=CreateSurface(m)
	AddVertex sfc,-1,-1,-1,0,0 : AddVertex sfc,1,-1,-1,1,0
	AddVertex sfc,1,-1,1,1,1   : AddVertex sfc,-1,-1,1,0,1
	VertexNormal sfc,0,0,-1,0 : VertexNormal sfc,1,0,-1,0
	VertexNormal sfc,2,0,-1,0 : VertexNormal sfc,3,0,-1,0
	AddTriangle sfc,0,1,2  : AddTriangle sfc,2,3,0
	
	sfc=CreateSurface(m)
	AddVertex sfc,-1,1,1,0,0   : AddVertex sfc,-1,1,-1,1,0
	AddVertex sfc,-1,-1,-1,1,1 : AddVertex sfc,-1,-1,1,0,1
	VertexNormal sfc,0,-1,0,0 : VertexNormal sfc,1,-1,0,0
	VertexNormal sfc,2,-1,0,0 : VertexNormal sfc,3,-1,0,0
	AddTriangle sfc,0,1,2  : AddTriangle sfc,2,3,0
	
	sfc=CreateSurface(m)
	AddVertex sfc,1,1,-1,0,0  : AddVertex sfc,1,1,1,1,0
	AddVertex sfc,1,-1,1,1,1  : AddVertex sfc,1,-1,-1,0,1
	VertexNormal sfc,0,1,0,0 : VertexNormal sfc,1,1,0,0
	VertexNormal sfc,2,1,0,0 : VertexNormal sfc,3,1,0,0
	AddTriangle sfc,0,1,2 : AddTriangle sfc,2,3,0
	
	EntityParent m,parent
	Return m
End Function


there :)


C64Retro(Posted 2003) [#7]
Hehe... yep, I sussed it jut before coming back to this page. Works a treat! Thanks v much for your help.

Boz.