the explanations would be a bit long (moreover I'm not sure to master everything)
I think you'll find the explanations on the internet (alphablend, transparent sorting, depthbuffer)
fortunately the sorting is done between submesh (and consequently between entities).
I have created a "meshdoubleside" procedure for this purpose.
it works for convex shapes, for concave shapes, you have to cut the mesh in as many submesh as necessary.
for example for a car, you need a submesh for the top (roof and windows) and another one for the bottom.
Code: Select all
Procedure meshdoubleside(mesh,inversenormal=1)
Protected Dim MV.PB_MeshVertex(0)
Protected Dim MF.PB_MeshFace(0)
Protected i,j,inv=-1
GetMeshData(Mesh,0, MV(), #PB_Mesh_Vertex | #PB_Mesh_UVCoordinate| #PB_Mesh_Normal |#PB_Mesh_Color, 0, MeshVertexCount(Mesh, 0)-1)
GetMeshData(Mesh,0, MF(), #PB_Mesh_Face, 0, MeshIndexCount(Mesh, 0)-1)
CreateMesh(mesh)
For j=0 To 1
AddSubMesh()
If j=1 And inversenormal:inv=1:EndIf
For i=0 To ArraySize(MV())
With MV(i)
MeshVertex(\x,\y,\z,\u,\v,\Color,\NormalX*inv,\NormalY*inv,\NormalZ*inv)
EndWith
Next
Select j
Case 1:For i=0 To ArraySize(MF()) Step 3:MeshFace(MF(i)\Index, MF(i+1)\Index, MF(i+2)\Index):Next
Case 0:For i=0 To ArraySize(MF()) Step 3:MeshFace(MF(i)\Index, MF(i+2)\Index, MF(i+1)\Index):Next
EndSelect
Next
FinishMesh(1)
EndProcedure
Procedure generematiere(num,dx,dy,c1,c2,scalex.f=1,scaley.f=1,AlphaBlend=0)
CreateTexture(num,dx,dy)
StartDrawing(TextureOutput(num))
DrawingMode(#PB_2DDrawing_AllChannels )
Box(0,0,dx,dy,c1)
Box(1,1,dx-2,dy-2,c2)
StopDrawing()
CreateMaterial(num, TextureID(num))
ScaleMaterial(num,scalex,scaley)
MaterialShininess(num,64):SetMaterialColor(num,#PB_Material_SpecularColor,$ffffff)
If AlphaBlend:MaterialBlendingMode(num,#PB_Material_AlphaBlend):EndIf
EndProcedure
InitEngine3D():InitSprite():InitKeyboard():InitMouse()
OpenWindow(0, 0, 0, 0,0, "test alphablend - arrow keys - Esc to Quit",#PB_Window_Maximize)
ex=WindowWidth (0,#PB_Window_InnerCoordinate)
ey=WindowHeight(0,#PB_Window_InnerCoordinate)
OpenWindowedScreen(WindowID(0), 0, 0, ex, ey, 0, 0, 0)
CreateCamera(0, 0, 0, 100, 100):MoveCamera(0,0,10,-20)
CreateLight(0,$ffffff, 5000, 5000, 0)
CameraBackColor(0,$ff8888)
AmbientColor($444444)
CreateSphere(0,8,64,64)
meshdoubleside(0)
generematiere(0,8,8,$ff00ff00,$88444444,0.1,0.1,1):SetMeshMaterial(0,MaterialID(0),0)
generematiere(1,8,8,$ff0000ff,$88444444,0.1,0.1,1):SetMeshMaterial(0,MaterialID(1),1); !!! second submesh is outside !!!
CreateEntity(0,MeshID(0),#PB_Material_None)
CreatePlane(10,100,100,1,1,20,20)
generematiere(10,64,64,$008888,$00ffff)
CreateEntity(10,MeshID(10),MaterialID(10),0,-10,0)
Repeat
WindowEvent()
ExamineMouse()
ExamineKeyboard()
If KeyboardReleased(#PB_Key_Space):action=0:EndIf
If KeyboardReleased(#PB_Key_F2):dis=(dis+1)%3:vdis=2<<dis*5:EndIf
If KeyboardReleased(#PB_Key_F1):EntityAngularFactor(0,0,0,0):EndIf
RotateEntity(0,0.1,0.2,0.3,#PB_Relative)
yrot.f+0.5:MoveCamera(0,Cos(yrot/180*#PI)*40,10,Sin(yrot/180*#PI)*40,0)
CameraLookAt(0,EntityX(0),EntityY(0),EntityZ(0))
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)