how can I make a cube with transparent walls?
I want to draw a cube in which the rear wall with texture and the front without texture but all the faces with the visible skeleton (ribs).
I also want to make the particles which would move along the edges of the cube, how can I do it?
Transparent cube some polygons
Re: Transparent cube some polygons
by using a material like this:how can I make a cube with transparent walls
Code: Select all
CreateMaterial(#tex2, LoadTexture(#tex2, "Wood.jpg"))
MaterialBlendingMode(#tex2, #PB_Material_AlphaBlend)
SetMaterialColor(#tex2, #PB_Material_DiffuseColor, RGBA(255, 255, 255, 20))not sure if you want a black lines around the textured faces, but look example CreateTextureAlpha.pb . i suppose you want to look from the front wall and to see the rear textured wall . this what i understant from "the front without texture"I want to draw a cube in which the rear wall with texture and the front without texture but all the faces with the visible skeleton (ribs).
to texture the rear and front walls and any wall , i prefer to build the cube from scratch from 6 submeshes (numbered 0 to 5) and after that we assign a specific texture to specific submesh (the cube side) like this for the front wall
SetEntityMaterial(0, MaterialID(#tex2), 0) ; material for the cube front side (transparent
here is the coordinated of the cube i have used:

the camera here at this position:
Code: Select all
MoveCamera(0,0,0, 10,#PB_Absolute)PS: i have make the left and right sides semi tranparent with this material:
SetMaterialColor(#tex5, #PB_Material_DiffuseColor, RGBA(255, 255, 255, 120))
assigned to submesh 1 and 3 (the last 2 lines)
Code: Select all
Declare DrawCube()
Define.f keyX, keyY, CameraSpeed = 0.1
Enumeration
#mesh
#entity
#tex
#tex2
#tex3
#tex4
#tex5
#texWhite
#light
#camera
#sphere
EndEnumeration
InitEngine3D(#PB_Engine3D_DebugLog)
InitSprite()
InitKeyboard()
InitMouse()
ExamineDesktops()
OpenWindow(0,0,0,DesktopWidth(0), DesktopHeight(0),"Cube with different textures",#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),0,0,DesktopWidth(0), DesktopHeight(0),1,0,0,#PB_Screen_WaitSynchronization)
Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
KeyboardMode(#PB_Keyboard_AllowSystemKeys)
CreateMaterial(#texWhite, LoadTexture(#texWhite, "white.jpg"))
MaterialBlendingMode(#texWhite, #PB_Material_AlphaBlend)
SetMaterialColor(#texWhite, #PB_Material_DiffuseColor, RGBA(255, 255, 255, 50))
CreateMaterial(#tex, LoadTexture(#tex, "Geebee2.bmp"))
MaterialCullingMode(#tex, #PB_Material_NoCulling)
CreateMaterial(#tex2, LoadTexture(#tex2, "Wood.jpg"))
MaterialBlendingMode(#tex2, #PB_Material_AlphaBlend)
SetMaterialColor(#tex2, #PB_Material_DiffuseColor, RGBA(255, 255, 255, 20))
CreateMaterial(#tex4, LoadTexture(#tex4, "DosCarte.png"))
MaterialCullingMode(#tex4, #PB_Material_NoCulling)
CreateMaterial(#tex5, LoadTexture(#tex5, "ValetCoeur.jpg"))
MaterialCullingMode(#tex5, #PB_Material_NoCulling)
MaterialBlendingMode(#tex5, #PB_Material_AlphaBlend)
SetMaterialColor(#tex5, #PB_Material_DiffuseColor, RGBA(255, 255, 255, 120))
MaterialCullingMode(#tex2, #PB_Material_NoCulling)
CreateMaterial(#tex3, LoadTexture(#tex3, "MRAMOR6X6.jpg"))
CreatePlane(500, 30, 30, 5, 5, 2, 2)
CreateEntity(500, MeshID(500), MaterialID(#tex3), 0,-6,0)
CreateLight(0,RGB(245,245,205),6,13,0)
;Create Camera
CreateCamera(0,0,0,100,100)
MoveCamera(0,0,0, 10,#PB_Absolute)
CameraLookAt(0, 0, 0, 0)
CameraBackColor(0, RGB(0,200,200))
AmbientColor(RGB(100,100,100))
;WorldShadows(#PB_Shadow_Modulative , -1, RGB(100, 100, 100))
;WorldShadows(#PB_Shadow_Additive )
;-Mesh
DrawCube()
CreateSphere(#sphere, 0.5)
CreateEntity(#sphere,MeshID(#sphere), #PB_Material_None, 0,-1,0 )
wireFrame = 1 : rot=1
Repeat
WindowEvent()
If ExamineMouse()
MouseX = -MouseDeltaX() * CameraSpeed * 0.7
MouseY = -MouseDeltaY() * CameraSpeed * 0.7
EndIf
ShowCursor_(0)
; Use arrow keys and mouse to rotate camera and fly in/out
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left)
KeyX.f = -CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX.f = CameraSpeed
Else
KeyX = 0
EndIf
If KeyboardPushed(#PB_Key_Up)
KeyY = -CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY = CameraSpeed
Else
KeyY = 0
EndIf
If KeyboardReleased(#PB_Key_W)
If wireFrame
MaterialShadingMode(#tex, #PB_Material_Wireframe)
MaterialShadingMode(#tex2, #PB_Material_Wireframe)
MaterialShadingMode(#tex5, #PB_Material_Wireframe)
MaterialShadingMode(#tex4, #PB_Material_Wireframe)
wireFrame ! 1
Else
MaterialShadingMode(#tex, #PB_Material_Solid)
MaterialShadingMode(#tex2, #PB_Material_Solid)
MaterialShadingMode(#tex5, #PB_Material_Solid)
MaterialShadingMode(#tex4, #PB_Material_Solid)
wireFrame ! 1
EndIf
EndIf
If KeyboardReleased(#PB_Key_Space) ;press key to toggle the rotation of the object
rot ! 1
EndIf
RotateEntity(0, 0, rot, 0,#PB_Relative)
RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
MoveCamera (0, KeyX, 0, KeyY)
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or WindowEvent() = #PB_Event_CloseWindow
;main drawing routine
Procedure DrawCube()
CreateMesh(0, #PB_Mesh_TriangleList, #PB_Mesh_Dynamic)
;pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp
;subMesh 0 ; Front Side
MeshVertexPosition(-1,-1,1)
MeshVertexNormal(0,1,0)
MeshVertexTextureCoordinate(0, 0)
MeshVertexPosition(1,-1,1)
MeshVertexNormal(0,1,0)
MeshVertexTextureCoordinate(1, 0)
MeshVertexPosition(1,1,1)
MeshVertexNormal(0,1,0)
MeshVertexTextureCoordinate(1, 1)
MeshVertexPosition(-1,1,1)
MeshVertexNormal(0,1,0)
MeshVertexTextureCoordinate(0, 1)
MeshFace(0, 1, 2)
MeshFace(2,3,0)
;ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
;subMesh 1 ; right side
AddSubMesh(#PB_Mesh_TriangleList)
MeshVertexPosition(1,-1,1)
MeshVertexNormal(0,1,0)
MeshVertexTextureCoordinate(0, 0)
MeshVertexPosition(1,-1,-1)
MeshVertexNormal(0,1,0)
MeshVertexTextureCoordinate(1, 0)
MeshVertexPosition(1,1,-1)
MeshVertexNormal(0,1,0)
MeshVertexTextureCoordinate(1, 1)
MeshVertexPosition(1,1,1);;;;;;
MeshVertexNormal(0,1,0)
MeshVertexTextureCoordinate(0, 1)
MeshFace(0, 1, 2)
MeshFace(2,3,0)
;;ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
;subMesh 2 ; back side
AddSubMesh(#PB_Mesh_TriangleList)
MeshVertexPosition(1,-1,-1)
MeshVertexNormal(0,1,0)
MeshVertexTextureCoordinate(0, 0)
MeshVertexPosition(-1,-1,-1)
MeshVertexNormal(0,1,0)
MeshVertexTextureCoordinate(1, 0)
MeshVertexPosition(-1,1,-1)
MeshVertexNormal(0,1,0)
MeshVertexTextureCoordinate(1, 1)
MeshVertexPosition(1,1,-1)
MeshVertexNormal(0,1,0)
MeshVertexTextureCoordinate(0, 1)
MeshFace(0, 1, 2)
MeshFace(2,3,0)
;000000000000000000000000000000000000000000000000000000000
;subMesh 3 ; Left side
AddSubMesh(#PB_Mesh_TriangleList)
MeshVertexPosition(-1,-1,-1)
MeshVertexNormal(0,1,0)
MeshVertexTextureCoordinate(0, 0)
MeshVertexPosition(-1,-1,1)
MeshVertexNormal(0,1,0)
MeshVertexTextureCoordinate(1, 0)
MeshVertexPosition(-1,1,1)
MeshVertexNormal(0,1,0)
MeshVertexTextureCoordinate(1, 1)
MeshVertexPosition(-1,1,-1)
MeshVertexNormal(0,1,0)
MeshVertexTextureCoordinate(0, 1)
MeshFace(0, 1, 2)
MeshFace(2,3,0)
;000000000000000000000000000000000000000000000000000000000
;subMesh 4 ; Upper side
AddSubMesh(#PB_Mesh_TriangleList)
MeshVertexPosition(-1,1,1)
MeshVertexNormal(0,1,0)
MeshVertexTextureCoordinate(0, 0)
MeshVertexPosition(1,1,1)
MeshVertexNormal(0,1,0)
MeshVertexTextureCoordinate(1, 0)
MeshVertexPosition(1,1,-1)
MeshVertexNormal(0,1,0)
MeshVertexTextureCoordinate(1, 1)
MeshVertexPosition(-1,1,-1)
MeshVertexNormal(0,1,0)
MeshVertexTextureCoordinate(0, 1)
MeshFace(0, 1, 2)
MeshFace(2,3,0)
;000000000000000000000000000000000000000000000000000000000
;subMesh 5 ; Bottom side
AddSubMesh(#PB_Mesh_TriangleList)
MeshVertexPosition(-1,-1,-1)
MeshVertexNormal(0,1,0)
MeshVertexTextureCoordinate(0, 0)
MeshVertexPosition(1,-1,-1)
MeshVertexNormal(0,1,0)
MeshVertexTextureCoordinate(1, 0)
MeshVertexPosition(1,-1,1)
MeshVertexNormal(0,1,0)
MeshVertexTextureCoordinate(1, 1)
MeshVertexPosition(-1,-1,1)
MeshVertexNormal(0,1,0)
MeshVertexTextureCoordinate(0, 1)
MeshFace(0, 1, 2)
MeshFace(2,3,0)
FinishMesh(#True)
CreateEntity(0, MeshID(0), MaterialID(#tex) ,0,0,0)
ScaleEntity(0, 2,2,2)
SetEntityMaterial(0, MaterialID(#tex2), 0) ; material for the cube front side (transparent
SetEntityMaterial(0, MaterialID(#tex4), 2) ;material for the cube Back side
SetEntityMaterial(0, MaterialID(#tex5), 1) ; material for the cube right side
SetEntityMaterial(0, MaterialID(#tex5), 3) ; material for the cube Left side
;SetEntityMaterial(0, MaterialID(#tex2), 1)
EndProcedurei don't know how to do this now, but i saw in the PB examples the robot throw particles like a thick line .I also want to make the particles which would move along the edges of the cube
Re: Transparent cube some polygons
applePi this superb!!
very thx!!
This is what i need!
Plus it immediately anticipates my question about how to build a cube of meshes. Thank you so much!
very thx!!
This is what i need!
Plus it immediately anticipates my question about how to build a cube of meshes. Thank you so much!
Re: Transparent cube some polygons
…man that's a lot of code for a cube…guess I should study this…(select)…(copy)…(paste into new IDE pane)…(run)… Beep!BONK!!!…
________
POLINK: fatal error: Access is denied.
________
AVIRA
Security Alert
Date 2/27/2015, 2:32:48 PM
Type: Detection
A Virus or unwanted program
'TR/Crypt.ZPACK.Gen7' was found in file
'C:\Documents and
Settings\mlc\…\~56099E0.TMP'.
Access to this file was denied.
Please select a further action:
[Remove] [Details]
________
That's a first for me.
A forum code triggered "false positive".
An oxymoron used to cover a somewhat malicious result.
A "false positive" is very much a "true lie", and this situation is getting very weird.
Glad I don't use Windows® much anymore on the old workstation, because this AV crap is crazy.
How can they get away with disseminating this misinformation?
Of course "possibly found" or "potentially found" would be true and correct, but not as reassuring for the "protected".
Oh well, time to uncheck realtime "Protection" Enabled, and hear see the white X on red Windows®XP "Security" Shield pop, and carry on.
@ applePi, thanks.
Nice.
________
POLINK: fatal error: Access is denied.
________
AVIRA
Security Alert
Date 2/27/2015, 2:32:48 PM
Type: Detection
A Virus or unwanted program
'TR/Crypt.ZPACK.Gen7' was found in file
'C:\Documents and
Settings\mlc\…\~56099E0.TMP'.
Access to this file was denied.
Please select a further action:
[Remove] [Details]
________
That's a first for me.
A forum code triggered "false positive".
An oxymoron used to cover a somewhat malicious result.
A "false positive" is very much a "true lie", and this situation is getting very weird.
Glad I don't use Windows® much anymore on the old workstation, because this AV crap is crazy.
How can they get away with disseminating this misinformation?
Of course "possibly found" or "potentially found" would be true and correct, but not as reassuring for the "protected".
Oh well, time to uncheck realtime "Protection" Enabled, and hear see the white X on red Windows®XP "Security" Shield pop, and carry on.
@ applePi, thanks.
Nice.
Keep it BASIC.
Re: Transparent cube some polygons
Thanks Didaktik and heartbone ,
more about Cube texturing codes:
1- suppose you want to cast the shadow of the transparent cube texture, Samuel have provided a solution and i have used his solution here http://purebasic.fr/english/viewtopic.p ... 37#p428242 to cast the shadow of a transparent batman picture a cube textured with. replace the batman picture with any picture with alpha channel from the web.
2- i am sure Didaktik wants also to texture the cube faces differently using the cube made with CreateCube(...), but i can't see how to do that. except to rebuild the cube again, it is a kind of a gymnastic code, the size of the cube mesh array made from createCube is 23, ie 0 to 23, with every cube face have 4 points, we can construct a compound texture and then referring to its coordinates (u,v)
here is the texture i use

and here is its coordinates as used by the graphics engine


more about Cube texturing codes:
1- suppose you want to cast the shadow of the transparent cube texture, Samuel have provided a solution and i have used his solution here http://purebasic.fr/english/viewtopic.p ... 37#p428242 to cast the shadow of a transparent batman picture a cube textured with. replace the batman picture with any picture with alpha channel from the web.
2- i am sure Didaktik wants also to texture the cube faces differently using the cube made with CreateCube(...), but i can't see how to do that. except to rebuild the cube again, it is a kind of a gymnastic code, the size of the cube mesh array made from createCube is 23, ie 0 to 23, with every cube face have 4 points, we can construct a compound texture and then referring to its coordinates (u,v)
here is the texture i use

and here is its coordinates as used by the graphics engine

Code: Select all
Enumeration
#LIGHT
#CAMERA
EndEnumeration
Define.f KeyX, KeyY, MouseX, MouseY
Global Dim MeshData.PB_MeshVertex(0)
Global Dim MeshDataInd.PB_MeshFace(0)
ExamineDesktops()
If OpenWindow(0, 0, 0, DesktopWidth(0), DesktopHeight(0), " use mouse + Arrows to rotate + move Camera", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
Define.f KeyX, KeyY
Declare CreateMatrix()
If InitEngine3D()
Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts",#PB_3DArchive_FileSystem)
Parse3DScripts()
InitSprite()
InitKeyboard()
InitMouse()
OpenWindowedScreen(WindowID(0), 0, 0, DesktopWidth(0), DesktopHeight(0), 0, 0, 0)
CreateCamera(#camera, 0, 0, 100, 100)
MoveCamera(#camera, 0, 10, 20, #PB_Absolute)
CameraFOV(#camera, 70)
CameraBackColor(#camera, RGB(255,200,200))
CameraLookAt(#camera,0,0,0)
CreateLight(0, RGB(255,255,255), 0, 20, 30)
AmbientColor(RGB(200, 200, 200))
CreateMaterial(0, LoadTexture(0, "texture.jpg"))
MaterialCullingMode(0, #PB_Material_NoCulling)
CreateMatrix() ; calling the cube rebuild procedure
Repeat
Event = WindowEvent()
If ExamineMouse()
MouseX = -MouseDeltaX()/20
MouseY = -MouseDeltaY()/20
EndIf
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left)
KeyX = -1
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX = 1
Else
KeyX = 0
EndIf
If KeyboardPushed(#PB_Key_Up)
KeyY = -1
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY = 1
Else
KeyY = 0
EndIf
EndIf
RotateEntity(0,0,1,0, #PB_Relative)
RotateCamera(#Camera, MouseY, MouseX, 0, #PB_Relative)
MoveCamera(#Camera, KeyX, 0, KeyY)
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
EndIf
Else
MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf
End
Procedure CreateMatrix()
CreateMesh(0, #PB_Mesh_TriangleList, #PB_Mesh_Dynamic)
CreateCube(30,10)
GetMeshData(30,0, MeshData(), #PB_Mesh_Vertex | #PB_Mesh_UVCoordinate , 0, MeshVertexCount(30)-1)
GetMeshData(30,0, MeshDataInd(), #PB_Mesh_Face, 0, MeshIndexCount(30, 0)-1)
ArrSize = ArraySize(MeshData())
;rebuild the mesh
For c=0 To ArrSize
x.f = MeshData(c)\x
y.f = MeshData(c)\y
z.f = MeshData(c)\z
MeshVertexPosition(x,y,z)
Select c
Case 0,1,2,3 ; cube face 0
If MeshData(c)\u =0
MeshData(c)\u = 0.5
EndIf
Case 4,5,6,7 ; cube face 1
If MeshData(c)\u =1
MeshData(c)\u = 0.5
EndIf
Case 8,9,10,11 ; cube face 2
If MeshData(c)\u =0
MeshData(c)\u = 0.5
EndIf
EndSelect
MeshVertexTextureCoordinate(MeshData(c)\u, MeshData(c)\v)
Next
SetMeshData(30,0, MeshData(), #PB_Mesh_UVCoordinate , 0, MeshVertexCount(30)-1)
ArrSizeInd = ArraySize(MeshDataInd())
For i=0 To ArrSizeInd Step 3
MeshFace(MeshDataInd(i)\Index, MeshDataInd(i+1)\Index,MeshDataInd(i+2)\Index)
Next
FinishMesh(#True)
SetMeshMaterial(0, MaterialID(0), 0)
CreateEntity(0, MeshID(0), #PB_Material_None , 0,0,0)
EndProcedure
Last edited by applePi on Sun Mar 01, 2015 11:37 am, edited 1 time in total.
Re: Transparent cube some polygons
here is a more convenient way and much more smaller code, in which we convert the cube made with CreateCube to submeshes from 0 to 5, then it is easy to assign textures to the submeshes using SetEntityMaterial(entity,MaterialID(material),submesh number)
in the following we assign different textures to different cube faces
in the following we assign different textures to different cube faces
Code: Select all
Enumeration
#LIGHT
#CAMERA
EndEnumeration
Define.f KeyX, KeyY, MouseX, MouseY
Global Dim MeshData.PB_MeshVertex(0)
Global Dim MeshDataInd.PB_MeshFace(0)
ExamineDesktops()
If OpenWindow(0, 0, 0, DesktopWidth(0), DesktopHeight(0), " use mouse + Arrows to rotate + move Camera", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
Define.f KeyX, KeyY
Declare CreateMatrix()
If InitEngine3D()
Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts",#PB_3DArchive_FileSystem)
Parse3DScripts()
InitSprite()
InitKeyboard()
InitMouse()
OpenWindowedScreen(WindowID(0), 0, 0, DesktopWidth(0), DesktopHeight(0), 0, 0, 0)
CreateCamera(#camera, 0, 0, 100, 100)
MoveCamera(#camera, 0, 15, 18, #PB_Absolute)
CameraFOV(#camera, 70)
CameraBackColor(#camera, RGB(255,200,200))
CameraLookAt(#camera,0,0,0)
CreateLight(0, RGB(255,255,255), 0, 20, 30)
AmbientColor(RGB(200, 200, 200))
CreateMaterial(0, LoadTexture(0, "ValetCoeur.jpg"))
MaterialCullingMode(0, #PB_Material_NoCulling)
CreateMaterial(1, LoadTexture(1, "MRAMOR6X6.jpg"))
MaterialCullingMode(1, #PB_Material_NoCulling)
CreateMaterial(2, LoadTexture(2, "RustySteel.jpg"))
MaterialCullingMode(2, #PB_Material_NoCulling)
CreateMaterial(3, LoadTexture(3, "snow_1024.jpg"))
MaterialCullingMode(3, #PB_Material_NoCulling)
CreateMaterial(4, LoadTexture(4, "ground_diffuse.png"))
MaterialCullingMode(4, #PB_Material_NoCulling)
CreateMaterial(5, LoadTexture(5, "Geebee2.bmp"))
MaterialCullingMode(5, #PB_Material_NoCulling)
CreateMatrix() ; calling the cube rebuild procedure
SetEntityMaterial(0,MaterialID(1),0)
SetEntityMaterial(0,MaterialID(2),1)
SetEntityMaterial(0,MaterialID(4),2)
SetEntityMaterial(0,MaterialID(5),3)
SetEntityMaterial(0,MaterialID(0),4)
SetEntityMaterial(0,MaterialID(5),5)
Repeat
Event = WindowEvent()
If ExamineMouse()
MouseX = -MouseDeltaX()/20
MouseY = -MouseDeltaY()/20
EndIf
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left)
KeyX = -1
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX = 1
Else
KeyX = 0
EndIf
If KeyboardPushed(#PB_Key_Up)
KeyY = -1
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY = 1
Else
KeyY = 0
EndIf
EndIf
RotateEntity(0,0,1,0, #PB_Relative)
RotateCamera(#Camera, MouseY, MouseX, 0, #PB_Relative)
MoveCamera(#Camera, KeyX, 0, KeyY)
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
EndIf
Else
MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf
End
Procedure CreateMatrix()
CreateMesh(0, #PB_Mesh_TriangleList, #PB_Mesh_Dynamic)
CreateCube(30,10)
GetMeshData(30,0, MeshData(), #PB_Mesh_Vertex | #PB_Mesh_UVCoordinate , 0, MeshVertexCount(30)-1)
GetMeshData(30,0, MeshDataInd(), #PB_Mesh_Face, 0, MeshIndexCount(30, 0)-1)
ArrSize = ArraySize(MeshData())
;rebuild the mesh
For c=0 To ArrSize
x.f = MeshData(c)\x
y.f = MeshData(c)\y
z.f = MeshData(c)\z
MeshVertexPosition(x,y,z)
MeshVertexTextureCoordinate(MeshData(c)\u, MeshData(c)\v)
vert+1
If vert=4
MeshFace(0, 1, 2)
MeshFace(2,3,0)
vert = 0
AddSubMesh()
EndIf
Next
FinishMesh(#True)
CreateEntity(0, MeshID(0), #PB_Material_None , 0,0,0)
EndProcedureRe: Transparent cube some polygons
@ApplePi
Nice examples.
@Didaktik
As you can see, there are a lot of possibilities.
Here is another small quickie, which makes use of planes instead.
Actually it's a bit bigger since, I've added a little extra to it.
I've used the font "Arial"...Change it to whatever you want.
Copy the following script and save it as: 'whatever.material'
Place everything it the same folder.
The code:
Nice examples.
@Didaktik
As you can see, there are a lot of possibilities.
Here is another small quickie, which makes use of planes instead.
Actually it's a bit bigger since, I've added a little extra to it.
I've used the font "Arial"...Change it to whatever you want.
Copy the following script and save it as: 'whatever.material'
Place everything it the same folder.
Code: Select all
material "bluefront"
{
technique bluefront_technique
{
pass bluefront_standard
{
cull_hardware none
cull_software none
ambient 0.290196 0.317647 0.807843 0.55
diffuse 0.290196 0.317647 0.807843 0.55
specular 0 0 0 0 25.5
emissive 0.180392 0.152941 0.552941 0.55
scene_blend alpha_blend
depth_write off
texture_unit
{
texture front.jpg
}
}
}
}
material "blueback"
{
technique blueback_technique
{
pass blueback_standard
{
cull_hardware none
cull_software none
ambient 0.290196 0.317647 0.807843 0.55
diffuse 0.290196 0.317647 0.807843 0.55
specular 0 0 0 0 25.5
emissive 0.180392 0.152941 0.552941 0.55
scene_blend alpha_blend
depth_write off
texture_unit
{
texture back.jpg
}
}
}
}
material "blueleft"
{
technique blueleft_technique
{
pass blueleft_standard
{
cull_hardware none
cull_software none
ambient 0.290196 0.317647 0.807843 0.55
diffuse 0.290196 0.317647 0.807843 0.55
specular 0 0 0 0 25.5
emissive 0.180392 0.152941 0.552941 0.55
scene_blend alpha_blend
depth_write off
texture_unit
{
texture left.jpg
}
}
}
}
material "blueright"
{
technique blueright_technique
{
pass blueright_standard
{
cull_hardware none
cull_software none
ambient 0.290196 0.317647 0.807843 0.55
diffuse 0.290196 0.317647 0.807843 0.55
specular 0 0 0 0 25.5
emissive 0.180392 0.152941 0.552941 0.55
scene_blend alpha_blend
depth_write off
texture_unit
{
texture right.jpg
}
}
}
}
material "blueup"
{
technique blueup_technique
{
pass blueup_standard
{
cull_hardware none
cull_software none
ambient 0.290196 0.317647 0.807843 0.55
diffuse 0.290196 0.317647 0.807843 0.55
specular 0 0 0 0 25.5
emissive 0.180392 0.152941 0.552941 0.55
scene_blend alpha_blend
depth_write off
texture_unit
{
texture up.jpg
}
}
}
}
material "bluedown"
{
technique bluedown_technique
{
pass bluedown_standard
{
cull_hardware none
cull_software none
ambient 0.290196 0.317647 0.807843 0.55
diffuse 0.290196 0.317647 0.807843 0.55
specular 0 0 0 0 25.5
emissive 0.180392 0.152941 0.552941 0.55
scene_blend alpha_blend
depth_write off
texture_unit
{
texture down.jpg
}
}
}
}
Code: Select all
InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
UseJPEGImageEncoder()
UseJPEGImageDecoder()
DeclareModule _Boxed_Aqua
Declare.i InitWin(width.i = 1024, height.i = 768, Fullscreen.i = #False)
Declare.i RunBox()
EndDeclareModule
Module _Boxed_Aqua
Structure _mesh
id.i
ms.i
tx.i
ma.i
EndStructure
Structure _box
fr._mesh
bk._mesh
lf._mesh
rt._mesh
up._mesh
dn._mesh
EndStructure
Structure _table
legs._mesh[4]
surface._mesh
EndStructure
Structure _par
id.i
tx.i
ma.i
EndStructure
Declare.i CreateBox()
Declare.i CreatePar()
Declare.i CreateImg(Transp.i = 255, text.s = " ", FntID.i = #PB_Default)
Global bo._box,tb._table, bub._par, fs.i, win.i, cam.i
Procedure.i InitWin(width.i = 1024, height.i = 768, Fullscreen.i = #False)
Protected ret.i
fs = Fullscreen
Select Fullscreen
Case #False
win = OpenWindow(#PB_Any, 0, 0, width, height, "Living in a box", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ret = OpenWindowedScreen(WindowID(win), 0, 0, 1024, 768, #False, 0, 0)
Default
ret = OpenScreen(1024, 768, 32, "Living in a box",#PB_Screen_SmartSynchronization)
EndSelect
If ret > 0
Add3DArchive(".", #PB_3DArchive_FileSystem)
Parse3DScripts()
cam = CreateCamera(#PB_Any, 0, 0, 100, 100)
MoveCamera(cam, 0, 0, 5)
ret = CreateBox()
ret = CreatePar()
EndIf
ProcedureReturn ret
EndProcedure
Procedure.i CreateImg(Transp.i = 255, text.s = " ", FntID.i = -1)
Protected tx.i
tx = CreateImage(#PB_Any, 512, 512)
StartDrawing(ImageOutput(tx))
DrawingMode(#PB_2DDrawing_AllChannels)
Box(0, 0, 512, 512, RGBA(36, 54, 208, Transp))
DrawingMode(#PB_2DDrawing_Transparent)
If IsFont(FntID)
DrawingFont(FontID(FntID))
EndIf
DrawText(256 - (TextWidth(text)/2), 256 -(TextHeight(text)/2), text, $FF3ED024)
StopDrawing()
ProcedureReturn tx
EndProcedure
Procedure.i CreateBox()
Protected im.i ,fnt.i, x.i
;----------------- Choose your own font -----------
fnt = LoadFont(#PB_Any, "Arial", 72)
With bo\fr
\ms = CreatePlane(#PB_Any, 1, 1, 1, 1, 1, 1)
\tx = CreateImg(255, "Front", fnt)
ret = SaveImage(\tx, "front.jpg", #PB_ImagePlugin_JPEG, 10)
\ma = GetScriptMaterial(#PB_Any, "bluefront")
\id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), -0.5, 0, -0.5)
RotateEntity(\id, -90, 0, 0, #PB_Absolute)
EndWith
With bo\bk
\ms = CreatePlane(#PB_Any, 1, 1, 1, 1, 1, 1)
\tx = CreateImg(255, "Back", fnt)
ret = SaveImage(\tx, "back.jpg", #PB_ImagePlugin_JPEG, 10)
ma = GetScriptMaterial(#PB_Any, "blueback")
\id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(ma), -0.5, 0, 0.5)
RotateEntity(\id, -90, 0, 180, #PB_Absolute)
EndWith
With bo\lf
\ms = CreatePlane(#PB_Any, 1, 1, 1, 1, 1, 1)
\tx = CreateImg(255, "Left", fnt)
ret = SaveImage(\tx, "left.jpg", #PB_ImagePlugin_JPEG, 10)
ma = GetScriptMaterial(#PB_Any, "blueleft")
\id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(ma), -1, 0, 0)
RotateEntity(\id, -90, 0, 90, #PB_Absolute)
EndWith
With bo\rt
\ms = CreatePlane(#PB_Any, 1, 1, 1, 1, 1, 1)
\tx = CreateImg(255, "Right", fnt)
ret = SaveImage(\tx, "right.jpg", #PB_ImagePlugin_JPEG, 10)
ma = GetScriptMaterial(#PB_Any, "blueright")
\id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(ma), 0, 0, 0)
RotateEntity(\id, -90, 0, -90, #PB_Absolute)
EndWith
With bo\up
\ms = CreatePlane(#PB_Any, 1, 1, 1, 1, 1, 1)
\tx = CreateImg(255, "Up", fnt)
ret = SaveImage(\tx, "up.jpg", #PB_ImagePlugin_JPEG, 10)
ma = GetScriptMaterial(#PB_Any, "blueup")
\id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(ma), -0.5, 0.5, 0)
RotateEntity(\id, -180, 0, -180, #PB_Absolute)
EndWith
With bo\dn
\ms = CreatePlane(#PB_Any, 1, 1, 1, 1, 1, 1)
\tx = CreateImg(255, "Down", fnt)
ret = SaveImage(\tx, "down.jpg", #PB_ImagePlugin_JPEG, 10)
ma = GetScriptMaterial(#PB_Any, "bluedown")
\id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(ma), -0.5, -0.5, 0)
RotateEntity(\id, -180, 180, 0, #PB_Absolute)
EndWith
With tb\legs[0]
\ms = CreateCylinder(#PB_Any, 0.03, 0.4, 8, 1, 0)
\tx = CreateTexture(#PB_Any, 512, 512)
StartDrawing(TextureOutput(\tx))
DrawingMode(#PB_2DDrawing_AllChannels)
Box(0, 0, 512, 512, $FF283F74)
For x = 0 To 50
Plot(Random(511, 1), Random(511,1), $FF2C3C61)
Next x
StopDrawing()
\ma = CreateMaterial(#PB_Any, TextureID(\tx))
ScaleMaterial(\ma, -0.3, -4)
\id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma))
EndWith
For x = 1 To 3
With tb\legs[x]
\id = CopyEntity(tb\legs[0]\id, #PB_Any)
EndWith
Next x
MoveEntity(tb\legs[0]\id, -1, -0.7,-0.5)
MoveEntity(tb\legs[1]\id, -1, -0.7, 0.5)
MoveEntity(tb\legs[2]\id, 0, -0.7, -0.5)
MoveEntity(tb\legs[3]\id, 0, -0.7, 0.5)
With tb\surface
\ms = CreateCube(#PB_Any, 0.1)
\ma = CopyMaterial(tb\legs[0]\ma, #PB_Any)
\id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma),-0.5, -0.55, 0)
ScaleEntity(\id, 10,0.5,10)
EndWith
EndProcedure
Procedure.i CreatePar()
With bub
\id = CreateParticleEmitter(#PB_Any, 1, 0.71, 0.1, #PB_Particle_Box, -0.5, -0.5, 0)
\tx = CreateTexture(#PB_Any, 128, 128)
StartDrawing(TextureOutput(\tx))
DrawingMode(#PB_2DDrawing_AllChannels)
Circle(64, 64, 63, $FFF0955D)
FillArea(64,64,$FFF0955D, $FFDF6920)
Circle(30, 30, 4, $FFF0955D)
StopDrawing()
\ma = CreateMaterial(#PB_Any, TextureID(\tx))
MaterialBlendingMode(\ma, #PB_Material_Add)
ParticleMaterial(\id, MaterialID(\ma))
ParticleEmitterDirection(\id, 0, 1, 0)
ParticleSize(\id, 0.03, 0.03)
ParticleTimeToLive(\id, 0.05, 0.14)
ParticleVelocity(\id, 0.1, 0.4)
ParticleSpeedFactor(\id, 0.3)
ParticleEmissionRate(\id, 170)
EndWith
EndProcedure
Procedure.i RunBox()
Protected Quit.i = 0, KeyX.f = 0, KeyY.f = 0, MouseX.f = 0, MouseY.f = 0
Repeat
If fs = #False
Repeat
ev = WindowEvent()
Until ev = 0
EndIf
If ExamineMouse()
MouseX = -MouseDeltaX() * 0.05
MouseY = -MouseDeltaY() * 0.05
EndIf
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left)
KeyX = -0.1
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX = 0.1
Else
KeyX = 0
EndIf
If KeyboardPushed(#PB_Key_Up)
KeyY = -0.1
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY = 0.1
Else
KeyY = 0
EndIf
EndIf
RotateCamera(cam, MouseY, MouseX, 0, #PB_Relative)
MoveCamera(cam, KeyX, 0, KeyY)
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
EndProcedure
EndModule
_Boxed_Aqua::InitWin(1024,768,#True)
_Boxed_Aqua::RunBox()
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
Re: Transparent cube some polygons
DK_PETER, that is a nice demo , the water bubbles can be very useful in a future projects. i see the box as a water tank, or a water heater, many future usages are possible for this code, thanks

