Following on from my bottomless cube, I've got a wall assembled from four boxes. I'm using custom UV coords for a texture. In the top-left corner of this 128x128 texture I've a semi-transparent pixel.
My cunning plan to create a wall that's semi-transparent from the outside is to set the UV coords of the back rectangle to point to this semi-transparent pixel and with texture Alpha on...Bob's your uncle.
It works, but only properly for two walls. The other two walls show through the transparency and I don't understand why.
The code is...
Graphics3D 1024,768,32,0
pivot=CreatePivot()
camera=CreateCamera(pivot)
PositionEntity camera,0,50,-500
PointEntity camera,pivot
CameraClsColor camera,0,128,255
AmbientLight 120,120,120
light1=CreateLight()
LightColor light1,40,100,255
TurnEntity light1,45,-205,0
light2=CreateLight()
LightColor light2,255,230,180
TurnEntity light2,45,35,0
tex_wall=LoadTexture("Textures\wall.png",3)
;#Region Create Block
mdl_block=CreateMesh()
surface=CreateSurface(mdl_block)
; Face A
vA1=AddVertex(surface, 1,-1,-1, 0,1)
vA2=AddVertex(surface, 1, 1,-1, 0,0.02)
vA3=AddVertex(surface,-1, 1,-1, 1,0.02)
vA4=AddVertex(surface,-1,-1, -1, 1,1)
VertexNormal surface,vA1,0,0,-1
VertexNormal surface,vA2,0,0,-1
VertexNormal surface,vA3,0,0,-1
VertexNormal surface,vA4,0,0,-1
AddTriangle (surface,vA1, vA2, vA3)
AddTriangle (surface,vA1, vA3, vA4)
; Face B
vB1=AddVertex(surface,-1,-1,-1, 0.01,0.01)
vB2=AddVertex(surface,-1, 1,-1, 0.01,0.01)
vB3=AddVertex(surface,-1, 1, 1, 0.01,0.01)
vB4=AddVertex(surface,-1,-1, 1, 0.01,0.01)
VertexNormal surface,vB1,-1,0,0
VertexNormal surface,vB2,-1,0,0
VertexNormal surface,vB3,-1,0,0
VertexNormal surface,vB4,-1,0,0
AddTriangle (surface,vB1, vB2, vB3)
AddTriangle (surface,vB1, vB3, vB4)
; Face C
vC1=AddVertex(surface, 1,1, 1, 1,1);0.01,0.01)
vC2=AddVertex(surface,-1,1, 1, 1,1);0.01,0.01)
vC3=AddVertex(surface,-1,1,-1, 1,1);0.01,0.01)
vC4=AddVertex(surface, 1,1,-1, 1,1);0.01,0.01)
VertexNormal surface,vC1,0,1,0
VertexNormal surface,vC2,0,1,0
VertexNormal surface,vC3,0,1,0
VertexNormal surface,vC4,0,1,0
AddTriangle (surface,vC1, vC2, vC3)
AddTriangle (surface,vC1, vC3, vC4)
; Face D
vD1=AddVertex(surface,1,-1, 1, 0.01,0.01)
vD2=AddVertex(surface,1, 1, 1, 0.01,0.01)
vD3=AddVertex(surface,1, 1,-1, 0.01,0.01)
vD4=AddVertex(surface,1,-1,-1, 0.01,0.01)
VertexNormal surface,vD1,1,0,0
VertexNormal surface,vD2,1,0,0
VertexNormal surface,vD3,1,0,0
VertexNormal surface,vD4,1,0,0
AddTriangle (surface,vD1, vD2, vD3)
AddTriangle (surface,vD1, vD3, vD4)
; Face E
vE1=AddVertex(surface,-1,-1,1, 1,0)
vE2=AddVertex(surface,-1, 1,1, 1,0)
vE3=AddVertex(surface, 1, 1,1, 1,0)
vE4=AddVertex(surface, 1,-1,1, 1,0)
VertexNormal surface,vE1,0,0,1
VertexNormal surface,vE2,0,0,1
VertexNormal surface,vE3,0,0,1
VertexNormal surface,vE4,0,0,1
AddTriangle (surface,vE1, vE2, vE3)
AddTriangle (surface,vE1, vE3, vE4)
HideEntity mdl_block
;#End Region
;#Region Create walls
mdl_wall=CreateMesh()
length=500 : height=30 : depth = 5
mdl_block1=CopyMesh(mdl_block)
FitMesh mdl_block1,-length/2, 0,0, length, height, depth
PositionMesh mdl_block1,0,0,length/2
AddMesh mdl_block1,mdl_wall
mdl_block2=CopyMesh(mdl_block1) : RotateMesh mdl_block2,0,90,0 : AddMesh mdl_block2,mdl_wall
mdl_block3=CopyMesh(mdl_block1) : RotateMesh mdl_block3,0,180,0 : AddMesh mdl_block3,mdl_wall
mdl_block4=CopyMesh(mdl_block1) : RotateMesh mdl_block4,0,-90,0 : AddMesh mdl_block4,mdl_wall
FreeEntity mdl_block1 : FreeEntity mdl_block2 : FreeEntity mdl_block3 : FreeEntity mdl_block4
EntityTexture mdl_wall,tex_wall
ScaleTexture tex_wall,0.0769,1.0
; EntityFX mdl_wall,16
FlipMesh mdl_wall
;#End Region
cube=CreateCube()
EntityColor cube,0,128,0
ScaleEntity cube,255,2,255
PositionEntity cube,0,-2,0
texScale#=0.0769
While Not KeyHit(1)
If KeyDown(205)
TurnEntity pivot,0,1.0,0
ElseIf KeyDown(203)
TurnEntity pivot,0,-1.0,0
EndIf
If KeyDown(200)
TurnEntity pivot,1.0,0,0
ElseIf KeyDown(208)
TurnEntity pivot,-1.0,0,0
EndIf
If KeyDown(209)
MoveEntity camera,0,0,1
ElseIf KeyDown(201)
MoveEntity camera,0,0,-1
EndIf
If KeyDown(13)
texScale=texScale+0.0001
ScaleTexture tex_wall,texScale,1.0
ElseIf KeyDown(12)
texScale=texScale-0.0001
ScaleTexture tex_wall,texScale,1.0
EndIf
RenderWorld
Text 10,10,texScale
Flip
Wend I feel a bit bad not using the box routines provided me but my simple brain was happier dealing with each vertex one by one with the UV coords!
|