Page 1 of 1
How to create a small column of smoke?
Posted: Mon Apr 22, 2024 4:49 pm
by jacdelad
Hi,
so I tried to add a small column of smoke to my 3D-pcb. I took a look at the plane example from pf shadoko (
https://www.purebasic.fr/english/viewto ... 64#p535964) and wanted to add the code for the smoke to my program. This doesn't work and I'm completely lost how to do this. What I learned, is that the particle-library doesn't seem to work as I expected it (the particles aren't "ejected", the are placed in a random manner within a defined space?!). It the particle library even the right place to look at? My goal is a small "fountain" of smoke over a certain point of my pcb (to show where a part is). Is this possible with little code?
Code: Select all
InitEngine3D()
InitSprite()
OpenWindow(0, 0, 0, 640, 480, "Cube example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, 640, 480, 0, 0, 0)
; Light
CreateLight(#PB_Any, RGB(25, 25, 180), -5, 10, 5, #PB_Light_Point)
; Camera
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 2, 1, 3, #PB_Absolute | #PB_Local)
CameraLookAt(0, 0, 0, 0)
; Erstelle den Würfel und binde ihn an die Szene
CreateCube(0, 1)
CreateEntity(0, MeshID(0), #PB_Material_None)
Repeat
RenderWorld()
FlipBuffers()
Until WaitWindowEvent(1) = #PB_Event_CloseWindow
If possible, could someone show me how to add a fountain of smoke being "ejected" from to a certain point of the cube?
Re: How to create a small column of smoke?
Posted: Tue Apr 23, 2024 12:15 pm
by spikey
Yup I'd be thinking about using the particle library.
Have a look at Particle2.pb and Particle3.pb in the Examples\3D folder - see if there's any styles that are close to what you're thinking of.
By default the particles will have no direction or velocity - so they just appear, stay put and do nothing. You need to give them a course of action.
Re: How to create a small column of smoke?
Posted: Tue Apr 23, 2024 12:29 pm
by jacdelad
I'll take a look, thanks!
Re: How to create a small column of smoke?
Posted: Tue Apr 23, 2024 2:09 pm
by jacdelad
I looked into it and example 3 seems to be everything I need. Thanks again. Btw, the example is really cool. Unbelievable what we can do with so little code.
Re: How to create a small column of smoke?
Posted: Tue Apr 23, 2024 2:38 pm
by spikey
I can't claim any of the credit there!

But yes, it's a really interesting demonstration of what the particle library can do.
Re: How to create a small column of smoke?
Posted: Tue Apr 23, 2024 3:54 pm
by jacdelad
The this is your chance

: I tried to add the water fountain to my code, but it failed:
Code: Select all
InitEngine3D()
InitSprite()
OpenWindow(0, 0, 0, 640, 480, "Cube example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, 640, 480, 0, 0, 0)
; Light
CreateLight(#PB_Any, RGB(25, 25, 180), -5, 10, 5, #PB_Light_Point)
; Camera
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 2, 1, 3, #PB_Absolute | #PB_Local)
CameraLookAt(0, 0, 0, 0)
; Erstelle den Würfel und binde ihn an die Szene
CreateCube(0, 1)
CreateEntity(0, MeshID(0), #PB_Material_None)
;----- Code from Example 3: -----
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
LoadTexture(4, "water.png")
CreateMaterial(4, TextureID(4))
DisableMaterialLighting(4, 1)
MaterialBlendingMode (4, #PB_Material_AlphaBlend)
SetMaterialAttribute(4,#PB_Material_TAM,#PB_Material_ClampTAM)
CreateParticleEmitter(2, 0, 0, 0, 0, -50,0,50)
ParticleMaterial (2, MaterialID(4))
ParticleSize (2, 1,1):ParticleScaleRate(2,5)
ParticleColorFader(2, 0, 0, 0, -0.4)
ParticleEmitterDirection(2, 0, 1, 0)
ParticleTimeToLive (2, 2,2)
ParticleVelocity(2, 2,100)
ParticleAcceleration(2, 0, -1, 0)
ParticleEmitterAngle(2,5)
ParticleAngle(2,-180,180,-180,180)
ParticleEmissionRate(2, 100)
;--------------------------------
Repeat
RenderWorld()
FlipBuffers()
Until WaitWindowEvent(1) = #PB_Event_CloseWindow
I'm surely doing something fundamentally wrong?!
Re: How to create a small column of smoke?
Posted: Tue Apr 23, 2024 5:50 pm
by spikey
jacdelad wrote: Tue Apr 23, 2024 3:54 pm
I'm surely doing something fundamentally wrong?!
Yes, but probably not in the way you were expecting. You've created the emitter at -50, 0, 50 but the camera is at 2, 1, 3 and looking at 0, 0, 0.
The emitter is working fine but the camera can't see it, the action is all taking place behind the camera!
I've moved the emitter to the origin, moved the camera back a bit and slowed the particles down so they aren't so vigorous:
Code: Select all
InitEngine3D()
InitSprite()
OpenWindow(0, 0, 0, 640, 480, "Cube example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, 640, 480, 0, 0, 0)
; Light
CreateLight(#PB_Any, RGB(25, 25, 180), -5, 10, 5, #PB_Light_Point)
; Camera
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 10, 10, 10, #PB_Absolute | #PB_Local) ; <---
CameraLookAt(0, 0, 0, 0)
; Erstelle den Würfel und binde ihn an die Szene
CreateCube(0, 1)
CreateEntity(0, MeshID(0), #PB_Material_None)
;----- Code from Example 3: -----
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
LoadTexture(4, "water.png")
CreateMaterial(4, TextureID(4))
DisableMaterialLighting(4, 1)
MaterialBlendingMode (4, #PB_Material_AlphaBlend)
SetMaterialAttribute(4,#PB_Material_TAM,#PB_Material_ClampTAM)
CreateParticleEmitter(2, 0, 0, 0, 0, 0,0,0) ; <---
ParticleMaterial (2, MaterialID(4))
ParticleSize (2, 1,1):ParticleScaleRate(2,5)
ParticleColorFader(2, 0, 0, 0, -0.4)
ParticleEmitterDirection(2, 0, 1, 0)
ParticleTimeToLive (2, 2,2)
ParticleVelocity(2, 2, 40) ; <---
ParticleAcceleration(2, 0, -1, 0)
ParticleEmitterAngle(2,5)
ParticleAngle(2,-180,180,-180,180)
ParticleEmissionRate(2, 100)
;--------------------------------
Repeat
RenderWorld()
FlipBuffers()
Until WaitWindowEvent(1) = #PB_Event_CloseWindow
Re: How to create a small column of smoke?
Posted: Tue Apr 23, 2024 6:40 pm
by pf shadoko
a few small changes
note that the alpharate parameter of ParticleColorFader must be consistent with ParticleTimeToLive
if duration is 2 seconds, alpha must lose 0.5 per second
Code: Select all
InitEngine3D()
InitSprite()
OpenWindow(0, 0, 0, 640, 480, "Cube example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, 640, 480, 0, 0, 0)
; Light
CreateLight(#PB_Any, RGB(25, 25, 180), -5, 10, 5, #PB_Light_Point)
; Camera
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 4, 4, 4, #PB_Absolute | #PB_Local) ; <---
CameraLookAt(0, 0, 2, 0)
; Erstelle den Würfel und binde ihn an die Szene
CreateCube(0, 1)
CreateEntity(0, MeshID(0), #PB_Material_None)
;----- Code from Example 3: -----
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
LoadTexture(4, "smoke2.png")
CreateMaterial(4, TextureID(4))
DisableMaterialLighting(4, 1)
MaterialBlendingMode (4, #PB_Material_AlphaBlend)
SetMaterialAttribute(4,#PB_Material_TAM,#PB_Material_ClampTAM)
CreateParticleEmitter(2, 0, 0, 0, 0, 0,0,0) ; <---
ParticleMaterial (2, MaterialID(4))
ParticleSize (2, 0.1,0.1):ParticleScaleRate(2,1)
ParticleColorFader(2, 0, 0, 0, -0.5)
ParticleEmitterDirection(2, 0, 1, 0)
ParticleTimeToLive (2, 2,2)
ParticleVelocity(2, 2, 8) ; <---
ParticleAcceleration(2, 0, -0.08, 0)
ParticleEmitterAngle(2,5)
ParticleAngle(2,-180,180,-180,180)
ParticleEmissionRate(2, 100)
;--------------------------------
Repeat
RenderWorld()
FlipBuffers()
Until WaitWindowEvent(1) = #PB_Event_CloseWindow
Re: How to create a small column of smoke?
Posted: Tue Apr 23, 2024 7:16 pm
by jacdelad
Ah, thanks, both of you! I hope I can do this now.
Edit: There's still a problem: I can't just move the camera, because it needs to look at the pcb. I wanted to attach the particle emitter to the board, but this doesn't work too?!
Re: How to create a small column of smoke?
Posted: Wed Apr 24, 2024 6:46 pm
by spikey
jacdelad wrote: Tue Apr 23, 2024 7:16 pm
Ah, thanks, both of you! I hope I can do this now.
Edit: There's still a problem: I can't just move the camera, because it needs to look at the pcb. I wanted to attach the particle emitter to the board, but this doesn't work too?!
Its just a question of changing the parameters of the emitter until it makes sense on the scale you're working. The original code you borrowed was on quite a large scale and is much bigger than a unit cube.
If I've read things correctly the emitter isn't an entity like the cube so you can't attach it as such.
Re: How to create a small column of smoke?
Posted: Wed Apr 24, 2024 7:24 pm
by jacdelad
AttachEntityObject() lists ParticleEmitter as possible object:
https://www.purebasic.com/documentation ... bject.html
Anyway, I'm in severe backpain today, so I think I will be not coding for some days. I don't want to push all the work to you, but maybe your eagle eye can spot the problem: I create a board with its dimensions in millimeters (like W=200, H=100, T=1.6). The camera moves so far away to put the whole board into view (MoveCamera(#Camera_Standard, 0, 0, 100, #PB_Absolute | #PB_Local):CameraLookAt(#Camera_Standard, 0, 0, 0)). Maybe the fountain is just too small.
Re: How to create a small column of smoke?
Posted: Thu Apr 25, 2024 3:39 pm
by spikey
Ok, so I've
not read it correctly then!
jacdelad wrote: Wed Apr 24, 2024 7:24 pm
I create a board with its dimensions in millimeters (like W=200, H=100, T=1.6). The camera moves so far away to put the whole board into view (MoveCamera(#Camera_Standard, 0, 0, 100, #PB_Absolute | #PB_Local):CameraLookAt(#Camera_Standard, 0, 0, 0)). Maybe the fountain is just too small.
What scale are you using? 1 world unit = 1 mm or something different?
Re: How to create a small column of smoke?
Posted: Thu Apr 25, 2024 3:53 pm
by jacdelad
Yupp.
Re: How to create a small column of smoke?
Posted: Thu Apr 25, 2024 3:56 pm
by spikey
Is that "Yupp - you've not read the documentation correctly" or "Yupp - I'm using a scale of 1 world unit = 1 mm"?

Re: How to create a small column of smoke?
Posted: Thu Apr 25, 2024 4:42 pm
by jacdelad
Both.
I'll try to solve it myself first, it must be a scaling or positioning problem.