It is currently Mon Dec 11, 2017 6:42 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Simulate planet atmosphere using billboard
PostPosted: Sun Mar 12, 2017 7:54 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Feb 19, 2011 10:06 am
Posts: 685
Location: Denmark
Could those of you trying the code please examine the ogre3D.log?
The example works in PB 5.43 and up...
I get this at the end of the Ogre3D.log file...(In PB 5.44 and PB 5.60 both)..Why?
Though the code have been smashed together in a jiffy, I can't find the reason for the message below:

Quote:
Can't assign material Sphere to SubEntity of E84087120 because this Material does not exist. Have you forgotten to define it in a .material script?

All material are created 'on the fly'.
TIA.

Edit: Ooops..Forgot adding paths..

Example:

Code:
;Easy way to create an *atmosphere* around a distant planet using a billboard
;BY DK_PETER
;The rest of the mishmash is simply to make it a bit more - a'hmm watchable.
;NOTE: Downloading assets may take some time...Please be patience.

EnableExplicit
UseJPEGImageDecoder()
UseOGGSoundDecoder()

Structure _object
  id.i
  ma.i
  ms.i
  tx.i[2]
  no.i
EndStructure

Structure _poss
  x.i
  y.i
  w.i
  h.i
  r.i
  c.i
EndStructure

Structure _Moving
  id.i
  tx.i
  ma.i
  no.i
  active.i
EndStructure

Structure _3DVector
  x.f
  y.f
  z.f
EndStructure

Structure _WhatsNeeded
  halo._Moving
  earth._object
  moon._object
  cloudcover._object
  sky._object
  mus.i
  met._object[9]
  par._Moving[10]
EndStructure

Structure _vars
  elap.q
  pos._poss
  ret.i
  rad.i
  snd.i
  thr.i
  ev.i
  starry.i
EndStructure

Declare.i Init()
Declare.i CreateScene()
Declare.i DownloadAssets()
Declare.i CreateWindow()
Declare.f RandomF(min.f, Max.f)
Declare.f SpaceRandom(min.f, Max.f)

Global count.i, wn._WhatsNeeded, path.s = GetPathPart(ProgramFilename())
Global va._vars, x.i, ve._3DVector

va\ret = Init()
va\ret = CreateWindow()
va\ret = DownloadAssets()
va\ret = CreateScene()

If va\snd = #True
  wn\mus = LoadSound(#PB_Any, path + "music.ogg")
  If IsSound(wn\mus)
    PlaySound(wn\mus)
  EndIf
EndIf

va\elap = ElapsedMilliseconds()
Repeat
 
  Repeat : va\ev = WindowEvent() : Until va\ev = 0
  RotateNode(wn\earth\no, 0, 0.5, 0, #PB_Relative)
  RotateNode(wn\moon\no, 0, 0.05, 0, #PB_Relative)
  For x = 0 To 8
    Select x
      Case 0,2
        RotateEntity(wn\met[x]\id, 1.3, 1.11, 0.5, #PB_Relative)
        RotateNode(wn\met[x]\no, 0.5, 0.35, 0.2, #PB_Relative)
      Case 1,3
        RotateEntity(wn\met[x]\id, -1.3, -1.11, -0.5, #PB_Relative)
        RotateNode(wn\met[x]\no, 0.4, 0.35, 0.4, #PB_Relative)
      Case 4,6
        RotateEntity(wn\met[x]\id, 1.8, 1.41, -1.2, #PB_Relative)
        RotateNode(wn\met[x]\no, 0.5, 0.45, 0.3, #PB_Relative)
      Case 5,7
        RotateEntity(wn\met[x]\id, -0.1, -0.1, -0.7, #PB_Relative)
        RotateNode(wn\met[x]\no, -0.28, -0.55, -0.1, #PB_Relative)
      Default
        RotateEntity(wn\met[x]\id, 0.1, 0.51, 1.1, #PB_Relative)
        RotateNode(wn\met[x]\no, -0.58, 0.45, 0.01, #PB_Relative)
    EndSelect
  Next x
  CompilerIf #PB_Compiler_Version >= 550
    If ElapsedMilliseconds() >= 62000 And wn\par[0]\active = #False
      For x = 0 To 8 : DisableParticleEmitter(wn\par[x]\id, #False) : wn\par[x]\active = #True : Next x
    EndIf
    If ElapsedMilliseconds() >= 100000 And va\starry = #False
      DisableParticleEmitter(wn\par[9]\id, #False)
    EndIf
  CompilerElse
    If ElapsedMilliseconds() - va\elap >= 62000 And wn\par[0]\active = #False
      For x = 0 To 8 : DisableParticleEmitter(wn\par[x]\id, #False) : wn\par[x]\active = #True : Next x
    EndIf
  CompilerEndIf     
 
  RenderWorld()
 
  FlipBuffers()
  ExamineKeyboard()
  If va\snd = #True And SoundStatus(wn\mus) = #PB_Sound_Stopped
    Break
  EndIf
Until KeyboardReleased(#PB_Key_Escape)

Procedure.i Init()
  If InitEngine3D(#PB_Engine3D_DebugLog) = 0
    MessageRequester("Engine", "Error initializing engine")
    End
  EndIf
  If InitSprite() = 0 Or InitKeyboard() = 0
    End
  EndIf
  If InitNetwork() = 0
    MessageRequester("Network", "Error initializing network!")
    End
  EndIf
  If InitSound() = 0 : va\snd = #False : Else : va\snd = #True : EndIf
  ProcedureReturn #True
EndProcedure

Procedure.i DownloadAssets()
  va\ret = ReceiveHTTPFile("http://earthobservatory.nasa.gov/blogs/elegantfigures/files/2011/10/land_shallow_topo_2011_8192.jpg", path + "earth.jpg")
  va\ret = ReceiveHTTPFile("http://www.vdata.dk/tmp/cloudy.jpg", path + "cloudy.jpg")
  va\ret = ReceiveHTTPFile("http://www.solarsystemscope.com/textures/2k_moon.jpg", path + "moon.jpg")
  va\ret = ReceiveHTTPFile("https://oss.adm.ntu.edu.sg/chan0797/wp-content/uploads/sites/843/2017/02/11216236-Seamless-Texture-surface-of-the-moon-high-resolution-25-megapixels-Texture-number-19-in-the-collecti-Stock-Photo.jpg", path + "met1.jpg")
  va\ret = ReceiveHTTPFile("https://static.brusheezy.com/system/resources/previews/000/046/510/non_2x/lens-flare-textures-by-brandondorf.jpg", "flare.jpg")
  If va\snd = #True
    va\ret = ReceiveHTTPFile("http://www.vorbis.com/music/Hydrate-Kenny_Beltrey.ogg", path + "music.ogg")
  EndIf
  ProcedureReturn #True
EndProcedure

Procedure.i CreateWindow()
  AntialiasingMode(#PB_AntialiasingMode_x6)
  ExamineDesktops()
  OpenWindow(0, 0, 0, DesktopWidth(0), DesktopHeight(0), "Planet atmosphere", #PB_Window_ScreenCentered|#PB_Window_BorderLess)
  OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0))
  Add3DArchive(path , #PB_3DArchive_FileSystem)
  Add3DArchive("." , #PB_3DArchive_FileSystem)
  CreateCamera(0, 0, 0, 100, 100)
  MoveCamera(0, 0, 0, 0)
EndProcedure

Procedure.i CreateScene()
  Protected v._3DVector, tf._3DVector
  wn\earth\tx[1]      = LoadTexture(#PB_Any, "earth.jpg")
  wn\cloudcover\tx[0] = LoadTexture(#PB_Any, "cloudy.jpg")
  wn\moon\tx[0]       = LoadTexture(#PB_Any, "moon.jpg")
  wn\met[0]\tx[0]     = LoadTexture(#PB_Any, "met1.jpg")
  wn\par[0]\tx        = LoadTexture(#PB_Any, "flare.jpg")
 
  CompilerIf #PB_Compiler_Version >= 550
    wn\sky\tx[0]      = CreateTexture(#PB_Any, 2048, 2048, "sky")
  CompilerElse
    wn\sky\tx[0]      = CreateTexture(#PB_Any, 2048, 2048)
  CompilerEndIf
  CompilerIf #PB_Compiler_Version >= 550
    wn\earth\tx[0]    = CreateTexture(#PB_Any, 2048, 2048, "Blaze")
  CompilerElse
    wn\earth\tx[0]    = CreateTexture(#PB_Any, 2048, 2048)
  CompilerEndIf
 
  StartDrawing(TextureOutput(wn\sky\tx[0]))
  For count = 0 To 6000
    va\pos\x = Random(2040, 8) : va\pos\y = Random(2040, 8)
    Select Random(100)
      Case 0 To 90
        va\pos\x = Random(2047, 1) : va\pos\y = Random(2047, 1)
        DrawingMode(#PB_2DDrawing_AlphaBlend)
        Circle(va\pos\x, va\pos\y, 1, RGBA(va\pos\c, va\pos\c, va\pos\c, Random(255,60)))
      Case 91 To 99
        DrawingMode(#PB_2DDrawing_AlphaBlend|#PB_2DDrawing_Gradient)
        va\pos\c = Random(255,80) : va\pos\r = Random(4, 2)
        BackColor(RGBA(va\pos\c, va\pos\c, va\pos\c, Random(255,20))) : FrontColor(0)
        CircularGradient(va\pos\x, va\pos\y, va\pos\r)
        Circle(va\pos\x, va\pos\y, va\pos\r)
      Default
        va\pos\w = Random(10,5) : va\pos\h = Random(10,5)
        DrawingMode(#PB_2DDrawing_AlphaBlend|#PB_2DDrawing_Gradient)
        va\pos\c = RGBA(Random(255,100), Random(255,100), Random(255,100), Random(255,20))
        BackColor(RGBA(va\pos\c, va\pos\c, va\pos\c, Random(255,20))) : FrontColor(0)
        EllipticalGradient(va\pos\x, va\pos\y, va\pos\w, va\pos\h)
        Ellipse(va\pos\x, va\pos\y, va\pos\w, va\pos\h)
    EndSelect
  Next count
  StopDrawing()
 
  StartDrawing(TextureOutput(wn\earth\tx[0]))
  DrawingMode(#PB_2DDrawing_AlphaBlend|#PB_2DDrawing_Gradient)
  BackColor($FFFFFFFF) : FrontColor($00000000)
  EllipticalGradient(1024, 1024, 768, 1024)
  GradientColor(0.7,$FFFFFFFF)
  Ellipse(1024, 1024, 768, 1024)
  StopDrawing()
 
  wn\sky\ma = CreateMaterial(#PB_Any, TextureID(wn\sky\tx[0]))
  MaterialBlendingMode(wn\sky\ma, #PB_Material_Add)
  AddMaterialLayer(wn\sky\ma, TextureID(wn\sky\tx[0]), #PB_Material_Add)
  MaterialCullingMode(wn\sky\ma, #PB_Material_NoCulling)
  ScaleMaterial(wn\sky\ma, 0.1, 0.1, 0)
  ScaleMaterial(wn\sky\ma, 0.1, 0.1, 1)
 
  wn\sky\ms   = CreateSphere(#PB_Any, 450, 60, 60)
  wn\sky\id   = CreateEntity(#PB_Any, MeshID(wn\sky\ms), MaterialID(wn\sky\ma), 0, 0, 0)
 
  wn\earth\ms = CreateSphere(#PB_Any, 4)
  wn\earth\ma = CreateMaterial(#PB_Any, TextureID(wn\earth\tx[0]))
  AddMaterialLayer(wn\earth\ma, TextureID(wn\earth\tx[1]), #PB_Material_Add)
  ScrollMaterial(wn\earth\ma, -0.0501, 0, #PB_Material_Animated, 0)
  MaterialFilteringMode(wn\earth\ma, #PB_Material_Anisotropic, 8)
  wn\earth\id = CreateEntity(#PB_Any, MeshID(wn\earth\ms), MaterialID(wn\earth\ma), 0, 0, 0)
 
  wn\cloudcover\ms = CreateSphere(#PB_Any, 4.15)
  wn\cloudcover\ma = CreateMaterial(#PB_Any, TextureID(wn\cloudcover\tx[0]))
  MaterialBlendingMode(wn\cloudcover\ma, #PB_Material_Add)
  AddMaterialLayer(wn\cloudcover\ma, TextureID(wn\cloudcover\tx[0]), #PB_Material_Modulate)
  ScrollMaterial(wn\cloudcover\ma, 0.1, 0, #PB_Material_Animated, 1)
  wn\cloudcover\id = CreateEntity(#PB_Any, MeshID(wn\cloudcover\ms), MaterialID(wn\cloudcover\ma), 0, 0, 0)
 
  CompilerIf #PB_Compiler_Version >= 550
    wn\halo\tx = CreateTexture(#PB_Any, 2048, 2048, "Halo")
  CompilerElse
    wn\halo\tx = CreateTexture(#PB_Any, 2048, 2048)
  CompilerEndIf
  StartDrawing(TextureOutput(wn\halo\tx))
  DrawingMode(#PB_2DDrawing_AlphaBlend|#PB_2DDrawing_Gradient)
  BackColor($FFFF7F00) : FrontColor($00000000)
  CircularGradient(1024, 1024, 800)
  GradientColor(0.86, $FFFF7F00)
  Circle(1024, 1024, 900)
  StopDrawing()
  wn\halo\ma = CreateMaterial(#PB_Any, TextureID(wn\halo\tx))
  MaterialBlendingMode(wn\halo\ma, #PB_Material_Add)
  MaterialFilteringMode(wn\halo\ma, #PB_Material_Anisotropic, 8)
  wn\halo\id = CreateBillboardGroup(#PB_Any, MaterialID(wn\halo\ma), 12, 12)
  AddBillboard(wn\halo\id, 0, 0, 0)
  wn\earth\no = CreateNode(#PB_Any, 0, 0, -58)
  AttachNodeObject(wn\earth\no, EntityID(wn\earth\id))
  AttachNodeObject(wn\earth\no, EntityID(wn\cloudcover\id))
  AttachNodeObject(wn\earth\no, BillboardGroupID(wn\halo\id))
  RotateNode(wn\earth\no, 0, 0, -23.4)
 
  wn\moon\ms = CreateSphere(#PB_Any, 0.9, 50, 50)
  wn\moon\ma = CreateMaterial(#PB_Any, TextureID(wn\moon\tx[0]))
  ScrollMaterial(wn\moon\ma, 0.005, 0, #PB_Material_Animated)
  wn\moon\id = CreateEntity(#PB_Any, MeshID(wn\moon\ms), MaterialID(wn\moon\ma), 30, 0,0)
  RotateEntity(wn\moon\id, 90, 0, -90, #PB_Absolute)
  wn\moon\no = CreateNode(#PB_Any, 0, 0, -58)
  AttachNodeObject(wn\moon\no, EntityID(wn\moon\id))
 
  For x = 0 To 8
    wn\met[x]\no = CreateNode(#PB_Any, 0, 0, -58)
    wn\met[x]\ms = CreateSphere(#PB_Any, 1, Random(16,5), Random(16,5))
    v\x = SpaceRandom(-100, 100)
    v\y = SpaceRandom(-100, 100)
    v\z = SpaceRandom(-100, 100)
    tf\x = RandomF(1, 3) : tf\y = RandomF(1,3) : tf\z = RandomF(1,3)
    TransformMesh(wn\met[x]\ms, 0, 0, 0, tf\x, tf\y, tf\z, Random(180, 0), Random(180, 0), Random(180, 0))
    wn\met[x]\ma = CreateMaterial(#PB_Any, TextureID(wn\met[0]\tx[0]))
    wn\met[x]\id = CreateEntity(#PB_Any, MeshID(wn\met[x]\ms), MaterialID(wn\met[x]\ma), v\x, v\y, v\z)
    AttachNodeObject(wn\met[x]\no, EntityID(wn\met[x]\id))
   
    wn\par[x]\id = CreateParticleEmitter(#PB_Any, tf\x*3 , tf\y*3 , tf\z*3, #PB_Particle_Box, v\x, v\y, v\z)
    wn\par[x]\ma = CreateMaterial(#PB_Any, TextureID(wn\par[0]\tx))
    MaterialBlendingMode(wn\par[x]\ma, #PB_Material_Add)
    ParticleEmissionRate(wn\par[x]\id, Random(300,100))
    ParticleMaterial(wn\par[x]\id, MaterialID(wn\par[x]\ma))
    ParticleSize(wn\par[x]\id, 8, 8)
    ParticleEmitterDirection(wn\par[x]\id, 0, 0, 0) ;just follow
    CompilerIf  #PB_Compiler_Version >= 550
      ParticleVelocity(wn\par[x]\id, #PB_Particle_MinimumVelocity, 2)
      ParticleVelocity(wn\par[x]\id, #PB_Particle_Velocity, 3)
      ParticleVelocity(wn\par[x]\id, #PB_Particle_MaximumVelocity, 5)
    CompilerElse
      ParticleVelocity(wn\par[x]\id, 0.02, 0.04)
    CompilerEndIf
    ParticleTimeToLive(wn\par[x]\id, 0.02, 0.3)
    DisableParticleEmitter(wn\par[x]\id, #True)
    wn\par[x]\active = #False
    AttachNodeObject(wn\met[x]\no, ParticleEmitterID(wn\par[x]\id))
  Next x
  wn\par[9]\ma = CopyMaterial(wn\par[0]\ma, #PB_Any)
  wn\par[9]\id = CreateParticleEmitter(#PB_Any, 400, 400, 200, #PB_Particle_Box, 0, 0, -400)
  ParticleMaterial(wn\par[9]\id, MaterialID(wn\par[9]\ma))
  ParticleTimeToLive(wn\par[9]\id, 10, 100)
  ParticleEmitterDirection(wn\par[9]\id, 0, 0, 1)
  ParticleSize(wn\par[9]\id, 0.5, 0.5)
  ParticleEmissionRate(wn\par[9]\id, 1000)
  CompilerIf  #PB_Compiler_Version >= 550
    ParticleVelocity(wn\par[x]\id, #PB_Particle_MinimumVelocity, 17)
    ParticleVelocity(wn\par[x]\id, #PB_Particle_Velocity, 30)
    ParticleVelocity(wn\par[x]\id, #PB_Particle_MaximumVelocity, 50)
  CompilerElse
    ParticleVelocity(wn\par[x]\id, 17, 50)
  CompilerEndIf
  ProcedureReturn #True
EndProcedure

Procedure.f SpaceRandom(min.f, Max.f)
  ;Just to avoid center
  Protected SeedVal.i = Random(20000,500)
  Protected NewVal.f = (Min + (Max - Min) * Random(SeedVal) / SeedVal)
  If NewVal >= 0 And NewVal <= 100
    NewVal + 100
  ElseIf NewVal < 0 And NewVal > -100
    NewVal - 100
  EndIf
  ProcedureReturn NewVal
EndProcedure

Procedure.f RandomF(min.f, Max.f)
  Protected SeedVal.i = Random(20000,500)
  ProcedureReturn (Min + (Max - Min) * Random(SeedVal) / SeedVal)
EndProcedure

_________________
“Tell me and I forget. Teach me and I remember. Involve me and I learn.”
— Benjamin Franklin
Current configurations: Windows 7/10, Intel 6800K, Gtx 970, 32 gb ram.


Top
 Profile  
Reply with quote  
 Post subject: Re: Simulate planet atmosphere using billboard
PostPosted: Mon Mar 13, 2017 5:45 am 
Offline
Addict
Addict

Joined: Sun Jun 25, 2006 7:28 pm
Posts: 1258
Hi DK_PETER
yesterday i failed to run your code , i was on winxp . today i tried your code in windows 7 x64. PB 5.50 and after about one minute the planet displayed on the screen with some comets passing randomly and a starry night
Image
i have checked the ogre.txt file and there are 13 warning of "Can't assign material Sphere to SubEntity of ..."
i remember something like this happened and reported before , will try to search for it
but your example is nice, thanks.
will try to run it again in win xp ( my favorite environment, i feel homeless and lost in win7+) with the ready downloaded materials and [music.ogg file (downloaded with Getright util)] .


Top
 Profile  
Reply with quote  
 Post subject: Re: Simulate planet atmosphere using billboard
PostPosted: Mon Mar 13, 2017 12:42 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Apr 30, 2003 8:15 am
Posts: 942
Location: Germany
Amazing! :shock: :D

_________________
"Daddy, I'll run faster, then it is not so far..."


Top
 Profile  
Reply with quote  
 Post subject: Re: Simulate planet atmosphere using billboard
PostPosted: Mon Mar 13, 2017 7:14 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Jul 09, 2007 4:47 pm
Posts: 207
Location: Courthouse
I am without speech :D


Top
 Profile  
Reply with quote  
 Post subject: Re: Simulate planet atmosphere using billboard
PostPosted: Tue Mar 14, 2017 9:29 pm 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 6:14 pm
Posts: 1391
Location: Germany (Saxony, Deutscheinsiedel)
applePi wrote:
i have checked the ogre.txt file and there are 13 warning of "Can't assign material Sphere to SubEntity of ..."

The same here (and I have no clue why, but I'm no 3D expert... :wink:)

But it works and is an amazing 3D example. Thank you! :D
It takes around 30 sec here, before it starts (tested with and without debugger, on Win10).

_________________
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye