How to create a small column of smoke?

Everything related to 3D programming
User avatar
jacdelad
Addict
Addict
Posts: 2003
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

How to create a small column of smoke?

Post 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?
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
spikey
Enthusiast
Enthusiast
Posts: 765
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: How to create a small column of smoke?

Post 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.
Last edited by spikey on Tue Apr 23, 2024 12:31 pm, edited 1 time in total.
User avatar
jacdelad
Addict
Addict
Posts: 2003
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: How to create a small column of smoke?

Post by jacdelad »

I'll take a look, thanks!
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
jacdelad
Addict
Addict
Posts: 2003
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: How to create a small column of smoke?

Post 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.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
spikey
Enthusiast
Enthusiast
Posts: 765
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: How to create a small column of smoke?

Post by spikey »

I can't claim any of the credit there! :D But yes, it's a really interesting demonstration of what the particle library can do.
User avatar
jacdelad
Addict
Addict
Posts: 2003
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: How to create a small column of smoke?

Post by jacdelad »

The this is your chance :mrgreen: : 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?!
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
spikey
Enthusiast
Enthusiast
Posts: 765
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: How to create a small column of smoke?

Post 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
User avatar
pf shadoko
Enthusiast
Enthusiast
Posts: 386
Joined: Thu Jul 09, 2015 9:07 am

Re: How to create a small column of smoke?

Post 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
User avatar
jacdelad
Addict
Addict
Posts: 2003
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: How to create a small column of smoke?

Post 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?!
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
spikey
Enthusiast
Enthusiast
Posts: 765
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: How to create a small column of smoke?

Post 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.
User avatar
jacdelad
Addict
Addict
Posts: 2003
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: How to create a small column of smoke?

Post 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.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
spikey
Enthusiast
Enthusiast
Posts: 765
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: How to create a small column of smoke?

Post by spikey »

jacdelad wrote: Wed Apr 24, 2024 7:24 pm AttachEntityObject() lists ParticleEmitter as possible object: https://www.purebasic.com/documentation ... bject.html
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?
User avatar
jacdelad
Addict
Addict
Posts: 2003
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: How to create a small column of smoke?

Post by jacdelad »

Yupp.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
spikey
Enthusiast
Enthusiast
Posts: 765
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: How to create a small column of smoke?

Post 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"? :)
User avatar
jacdelad
Addict
Addict
Posts: 2003
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: How to create a small column of smoke?

Post by jacdelad »

Both. :wink:
I'll try to solve it myself first, it must be a scaling or positioning problem.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Post Reply