PB5.10 How to Use SkyBox?

Everything related to 3D programming
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

PB5.10 How to Use SkyBox?

Post by IdeasVacuum »

Code: Select all

SkyBox("EnvMap_BK.jpg")
SkyBox("EnvMap_FR.jpg")
SkyBox("EnvMap_DN.jpg")
SkyBox("EnvMap_UP.jpg")
SkyBox("EnvMap_LF.jpg")
SkyBox("EnvMap_RT.jpg")
The EnvMap images are identical, I have tried them in various sizes from 64x64 to 256x256pix.
PB Returns > 0 for each SkyBox function, and the files are in the same folder as all other images (used as textures)
but Ogre reports:

OGRE EXCEPTION(6:FileNotFoundException) Cannot locate resource EnvMap_BK_fr.jpg in resource group General or any other group. in ResourceGroupManager::openResource at OgreResourceGroupManager.cpp (line 756)

Notice that the Ogre log appends _fr to the filenames? That seems a bit strange.

So, anyone hit this before?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Olby
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Jan 12, 2009 10:33 am
Contact:

Re: PB5.10 How to Use SkyBox?

Post by Olby »

Instead of "EnvMap_BK.jpg" use "EnvMap.jpg", PB will automatically append the suffix.
Intel Core i7 Quad 2.3 Ghz, 8GB RAM, GeForce GT 630M 2GB, Windows 10 (x64)
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: PB5.10 How to Use SkyBox?

Post by IdeasVacuum »

Thanks Olby, that does indeed work, but what if you wanted to use different images for each box side?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Thade
Enthusiast
Enthusiast
Posts: 266
Joined: Sun Aug 03, 2003 12:06 am
Location: Austria

Re: PB5.10 How to Use SkyBox?

Post by Thade »

Hi

Unzip the skybox examples in Data/Packs to Data/Unzipped/desert and Data/Unzipped/skybox
In Skybox you'll have stevecube_BK.jpg stevecube_DN.jpg a.s.o.
In desert is desert07_BK.jpg desert07_DN.jpg desert07_FR.jpg etc.

The rest explains itself if you look into the code and into the Folders

This is the Skybox.pb example from Examples/3D with 2 lines changed.

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - SkyBox
;
;    (c) 2002 - Fantaisie Software
;
; ------------------------------------------------------------
;
; Thanks to Steve 'Sinbad' Streeting for the nice SkyBox !
;

; Use [F2]/[F3] to change SkyBox's texture 
; Use [F4] to disable SkyBox

#CameraSpeed = 1

Enumeration
  #MainWindow 
  #Editor
EndEnumeration

IncludeFile "Screen3DRequester.pb"

Define.f KeyX, KeyY, MouseX, MouseY, RatioX, RatioY

If InitEngine3D()
  
  Add3DArchive("Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive("Data/Models", #PB_3DArchive_FileSystem)
  Add3DArchive("Data/Unzipped/desert", #PB_3DArchive_FileSystem)
  Add3DArchive("Data/Unzipped/skybox", #PB_3DArchive_FileSystem)
;  Add3DArchive("Data/Packs/desert.zip", #PB_3DArchive_Zip)
;  Add3DArchive("Data/Packs/skybox.zip", #PB_3DArchive_Zip)
  Add3DArchive("Data/Scripts", #PB_3DArchive_FileSystem)
  Add3DArchive("Data/GUI", #PB_3DArchive_FileSystem)
  Parse3DScripts()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  If Screen3DRequester()
    ;-Material
    CreateMaterial(0, LoadTexture(0, "r2skin.jpg"))
    
    ;-Entity
    CreateEntity(0, LoadMesh(0, "robot.mesh"), MaterialID(0))
    
    ;-Camera 
    CreateCamera(0,0,0,100,100)
    MoveCamera(0,0,0,100, #PB_Absolute)
    CameraBackColor(0, RGB(19, 34, 49))
    
    ;-GUI
    RatioX = CameraViewWidth(0) / 1920
    RatioY = CameraViewHeight(0) / 1080
    
    OpenWindow3D(#MainWindow, 10, 10, 570 * RatioX, 180 * RatioY, "SkyBox")
    EditorGadget3D(#Editor, 10 * RatioX, 20 * RatioY, 530 * RatioX, 90 * RatioY, #PB_Editor3D_ReadOnly)
    SetGadgetText3D(#Editor, "[F2]/[F3] = Change SkyBox " + Chr(10) + "[F4] = Disable SkyBox")
    
    ShowGUI(155, 0)
    
    Repeat
      Screen3DEvents()
      
      If ExamineMouse()
        MouseX = -MouseDeltaX() * #CameraSpeed * 0.05
        MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
      EndIf
      
      If ExamineKeyboard()
        
        If KeyboardReleased(#PB_Key_F2)
          SkyBox("stevecube.jpg")
        ElseIf KeyboardReleased(#PB_Key_F3) 
          SkyBox("desert07.jpg")
        ElseIf KeyboardReleased(#PB_Key_F4)
          SkyBox("")
        EndIf
        
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -#CameraSpeed 
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = #CameraSpeed 
        Else
          KeyX = 0
        EndIf
                  
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -#CameraSpeed 
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = #CameraSpeed 
        Else
          KeyY = 0
        EndIf

      EndIf
           
      RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
      MoveCamera  (0, 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
RGR

.
--------------
Yes, its an Irish Wolfhound.
Height: 107 cm; Weight: 88 kg
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: PB5.10 How to Use SkyBox?

Post by IdeasVacuum »

Hi Thade

I understand that the series of images are saved with the relative postfix.
So 6 images, each image is different:

EnvMap_FR.jpg
EnvMap_BK.jpg
EnvMap_DN.jpg
EnvMap_LF.jpg
EnvMap_RT.jpg
EnvMap_UP.jpg

But if I use:

Result1 = SkyBox("EnvMap.jpg")

The first image is used for all 6 sides.......

Although the Ogre log says:

Texture: EnvMap_fr.jpg: Loading 1 faces(PF_R8G8B8,64x64x1)
Texture: EnvMap_bk.jpg: Loading 1 faces(PF_R8G8B8,64x64x1)
Texture: EnvMap_lf.jpg: Loading 1 faces(PF_R8G8B8,64x64x1)
Texture: EnvMap_rt.jpg: Loading 1 faces(PF_R8G8B8,64x64x1)
Texture: EnvMap_up.jpg: Loading 1 faces(PF_R8G8B8,64x64x1)
Texture: EnvMap_dn.jpg: Loading 1 faces(PF_R8G8B8,64x64x1)
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: PB5.10 How to Use SkyBox?

Post by applePi »

if you want to texture a face differenly as an example the ground with different texture: example
1-unzip the desert.zip
2-change the name of MRAMOR6X6.jpg from textures folder to desert07_DN.jpg and resize it like the original 512X512
3- copy it to the unziped desert.zip
4-make an empty zip file, and drag all the 6 jpg files to that empty zip file.
now when you run a code using
SkyBox("desert07.jpg")
it will search for the desert.zip file and will display what it have together with your change, surely it has an algorithm for that.
try this rotating cube you have previously posted with the skybox after applying the described procedure above.
you will see the down picture different, change all the other pictures if you want, but preferably the pictures must reflect a true appearance a true continous topography.

Code: Select all

IncludeFile "Screen3DRequester.pb"

Enumeration
#MyMesh
#MyMatl
#MyEnt
#MyNode
#MyCamera
#MyLight

EndEnumeration

#CameraSpeed = 2

NewList sgListPts.s()
sgDelim.s = Chr(44)
igFaceCnt.i = 0

Define iKeyX.i, iKeyY.i, iMouseX.i, iMouseY.i


If InitEngine3D()

InitSprite()
InitKeyboard()
InitMouse()

Add3DArchive("Data\Scripts", #PB_3DArchive_FileSystem)
Add3DArchive("Data\Textures", #PB_3DArchive_FileSystem)
Add3DArchive("Data/Packs/skybox.zip", #PB_3DArchive_Zip)
Add3DArchive("Data/Packs/desert.zip", #PB_3DArchive_Zip)
Parse3DScripts()
                                                    

If Screen3DRequester()
AmbientColor(RGB(255,255,255))
GetScriptMaterial(#MyMatl, "Template/TransparentTexture")
MaterialCullingMode(#MyMatl, #PB_Material_NoCulling)
CreateMesh(#MyMesh, #PB_Mesh_TriangleList, #PB_Mesh_Static)

FirstElement(sgListPts())
i = 0
                       
SkyBox("desert07.jpg")
CreateCube(#MyEnt,60)
CreateEntity(#MyEnt,MeshID(#MyEnt), #PB_Material_None,0,0,0)

;Camera
CreateCamera(#MyCamera, 0, 0, 100, 100)
MoveCamera(#MyCamera,0,200,350, #PB_Absolute)
CameraLookAt(#MyCamera, EntityX(#MyEnt), EntityY(#MyEnt), EntityZ(#MyEnt))
CameraFixedYawAxis(#MyCamera, #True, 0, 1, 0)
CameraBackColor(#MyCamera, RGB(35, 35, 35))
                       ;node
node = CreateNode(#PB_Any, 0,0,0)
AttachNodeObject(node, CameraID(#MyCamera)) 
                      
                       
;Light
CreateLight(#MyLight, RGB(255, 255, 255), 20, 150, 120)
AmbientColor(RGB(255, 255, 255))

Repeat

Screen3DEvents()

If ExamineKeyboard()

If KeyboardPushed(#PB_Key_Left)

iKeyX = -#CameraSpeed
 
ElseIf KeyboardPushed(#PB_Key_Right)

iKeyX = #CameraSpeed 
Else
iKeyX = 0
EndIf
                                        
If KeyboardPushed(#PB_Key_Up)

iKeyY = -#CameraSpeed
 
ElseIf KeyboardPushed(#PB_Key_Down) 

iKeyY = #CameraSpeed 
Else
iKeyY = 0
EndIf
EndIf

If ExamineMouse()
                               
iMouseX = -(MouseDeltaX()/10)
iMouseY = -(MouseDeltaY()/10)
EndIf

RotateNode(node, 0, -0.4, 0, #PB_Relative)
                                
RenderWorld()
FlipBuffers()

Until KeyboardPushed(#PB_Key_Escape)

EndIf
EndIf
End

IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: PB5.10 How to Use SkyBox?

Post by IdeasVacuum »

....Thanks for the help guys. At the moment, it is just not working for me. I have other things to tackle so I will return to this one later.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 756
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: PB5.10 How to Use SkyBox?

Post by Samuel »

applePi wrote:if you want to texture a face differenly as an example the ground with different texture: example
1-unzip the desert.zip
2-change the name of MRAMOR6X6.jpg from textures folder to desert07_DN.jpg and resize it like the original 512X512
3- copy it to the unziped desert.zip
4-make an empty zip file, and drag all the 6 jpg files to that empty zip file.
You don't need to put the Skybox textures in a zip file. You can treat them just like a normal texture. Also as long as you don't have
a older computer you should be able to use any size format.

As for your problem IdeasVacuum the only thing I can think of is a misspelled path or texture name.
Here is a short code example that works for me.

For my example I'll call the Skybox NightSky. Just make sure the textures are named like this.

NightSky_BK.png
NightSky_DN.png
NightSky_FR.png
NightSky_LF.png
NightSky_RT.png
NightSky_UP.png


Then you should just have to use this command once to call the Skybox.
SkyBox("NightSky.png")

Purebasic should place the texture in the proper location on the screen.
NightSky_UP= Top of world

All this was shown in the previous examples, but I thought I might be able to help a little.

Code: Select all

;**********PRESS ESCAPE TO EXIT************
#CameraSpeed = 1
Define.f MouseX, MouseY

If InitEngine3D()
;***Don't forget to set me***
  Add3DArchive("Textures/NightSky", #PB_3DArchive_FileSystem)
  InitSprite()
  InitKeyboard()
  InitMouse()
  
ExamineDesktops()
DeskWid=DesktopWidth(0)
DeskHei=DesktopHeight(0)

OpenWindow(0, 0, 0, DeskWid, DeskHei, "Skybox")
OpenWindowedScreen(WindowID(0), 0, 0, DeskWid, DeskHei, 0, 0, 0)

    CreateCamera(0,0,0,100,100)
    MoveCamera(0,0,0,100)
    
    SkyBox("NightSky.png")
    
    Repeat
      
      If ExamineMouse()
        MouseX = -MouseDeltaX() * #CameraSpeed * 0.05
        MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
      EndIf
      ExamineKeyboard()
      RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
      MoveCamera  (0, KeyX, 0, KeyY)
      RenderWorld()
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape)
    
Else
  MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf
End
Not that it matters much, but I used a Skybox for the moon in my user picture thingy.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: PB5.10 How to Use SkyBox?

Post by IdeasVacuum »

Well, here we are later. I followed your example Samuel with my own images, with labels on them. Oh my giddy aunt - your example works perfectly and more to the point, This time I can see which image goes to which face - and that is the thing that had me flummoxed!

I had wrongly assumed that the back face of the box would be at 0,0,-1. Nope, that is actually the front face! :shock:

At the same time, I accidently discovered that an environment map can be loaded from an Ogre material script, which does exactly what I need.

So thanks everyone for your help - made great strides today, the only major issue I have now is getting the views to be orthographic instead of perspective.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 756
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: PB5.10 How to Use SkyBox?

Post by Samuel »

IdeasVacuum wrote: So thanks everyone for your help - made great strides today, the only major issue I have now is getting the views to be orthographic instead of perspective.
Always happy to help. As for changing the view to orthographic. You could try CameraProjectionMode(#Camera, Mode), but last time I
checked it was disabled because of some sort of bug. Hopefully they will have that fixed soon though. If you do anything like CAD
software its nice to have that feature from time to time.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: PB5.10 How to Use SkyBox?

Post by IdeasVacuum »

Hi Samuel

Yup, CameraProjectionMode(#Camera, Mode) worked fine in PB4.61, but in 5.10 it corrupts memory and causes your app to crash :cry: CameraProjectionMode() crashes app

I really hope Fred can fix it quickly as it is a vital component for any CAD related apps - like mine.

In the meantime I'm wondering if I could use the Irrlicht wrapper N3xtD, it is no longer supported by the developer.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply