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:
All material are created 'on the fly'.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?
TIA.
Example:
Code: Select all
EnableExplicit
;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. (fixed links Jan. 10 - 2022.)
EnableExplicit
UseJPEGImageDecoder()
UseOGGSoundDecoder()
UsePNGImageDecoder()
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
mus.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 = LoadMovie(#PB_Any, path + "music.mp3")
If IsMovie(wn\mus)
PlayMovie(wn\mus, 0)
EndIf
EndIf
RenderWorld()
FlipBuffers()
va\elap = ElapsedMilliseconds()
Repeat
Repeat : va\ev = WindowEvent() : Until va\ev = 0
RotateNode(wn\earth\no, 0, 0.05, 0, #PB_Relative)
RotateNode(wn\moon\no, 0, 0.01, 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 MovieStatus(wn\mus) = 0
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 InitMovie() = 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("https://img1.cgtrader.com/items/237624/dfa3ac0be6/planet-earth-3d-model-max.jpg", path + "cloudy.jpg")
va\ret = ReceiveHTTPFile("https://www.solarsystemscope.com/textures/download/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("https://www.bensound.com/bensound-music/bensound-betterdays.mp3", path + "music.mp3")
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.0005, 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.006, 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.001, 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