CameraFollow and Billboard(group)

Everything related to 3D programming
Philippe-felixer76-3
User
User
Posts: 45
Joined: Mon Dec 30, 2013 10:12 pm

CameraFollow and Billboard(group)

Post by Philippe-felixer76-3 »

Hi,

Is it possible tot attach a billboard(group) to a CameraFollow fixed in view, and let de billboard have a CreateRenderTexture.
____________
| |
| |
| ___ |
| | | |
| ---- |
-----------------

Like this?
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

Re: CameraFollow and Billboard(group)

Post by Olli »

Hello,

You can use the code bbcode markup to show an orthogonal grid. It is the following markup

Code: Select all

[code]
to start and near the same markup to finish. Just insert a slash character before the 'code' statement.





Example :

Code: Select all

       \||/
[ a "beautiful" scheme ]
       /||\




I suppose you wanted to show a thing like this :
+-----------+
| |
+--+--+--+--+
| | | | |
+--+--+--+--+
[/code]
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

Re: CameraFollow and Billboard(group)

Post by Olli »

And 'my' opinion is mixed :

- Yes you can if you need not to get future 3D arguments about the billboard(s) and if billboard(s) are not blended with your 3D background : you create multiple camera views and one of these camera will focus your billboard. If you want even to blend billboard(s) on front of a 3D render, you can (but you will loose speedness) do it by projecting your 3D view on a material and display this material as a textured 3D entity behind the billboard(s).

- No, you cannot do it. Try to make your own billboards by making several entities grouped thanks to the nodes, but you will loose speedness too by rotating each face on front of the camera, on every frame.

Conclusion : yno (or nyes)
Philippe-felixer76-3
User
User
Posts: 45
Joined: Mon Dec 30, 2013 10:12 pm

Re: CameraFollow and Billboard(group)

Post by Philippe-felixer76-3 »

Olli wrote:And 'my' opinion is mixed :

- Yes you can if you need not to get future 3D arguments about the billboard(s) and if billboard(s) are not blended with your 3D background : you create multiple camera views and one of these camera will focus your billboard. If you want even to blend billboard(s) on front of a 3D render, you can (but you will loose speedness) do it by projecting your 3D view on a material and display this material as a textured 3D entity behind the billboard(s).

- No, you cannot do it. Try to make your own billboards by making several entities grouped thanks to the nodes, but you will loose speedness too by rotating each face on front of the camera, on every frame.

Conclusion : yno (or nyes)
Hi there, tnx for the support...

The next code works for me for a entity:

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - CameraFollow
;
;    (c) Fantaisie Software
;
; ------------------------------------------------------------
;

#CameraSpeed = 2

IncludeFile #PB_Compiler_Home + "examples/3d/Screen3DRequester.pb"

Define.f KeyX, KeyY, MouseX, MouseY

If InitEngine3D()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  If Screen3DRequester()
    
    Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Models", #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Scripts", #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Packs/Desert.zip", #PB_3DArchive_Zip)
    Parse3DScripts()
    
    ; First create materials
    ;
    
    GrassMaterial = CreateMaterial(#PB_Any, TextureID(LoadTexture(#PB_Any,"grass1.png")))
    MaterialBlendingMode(GrassMaterial, #PB_Material_AlphaBlend)
    DirtMaterial = CreateMaterial(#PB_Any, TextureID(LoadTexture(#PB_Any,"Dirt.jpg")))
    NinjaRed = CreateMaterial(#PB_Any, TextureID(LoadTexture(#PB_Any,"nskinrd.jpg")))
    
    ; Then create the billboard group and use the previous material
    ;
    ;-Billboard
    
    Billboard = CreateBillboardGroup(#PB_Any, MaterialID(GrassMaterial), 60, 60)
    For i = 0 To 1000
      AddBillboard(Billboard, Random(2000)-1000, 30, Random(2000) - 1000)
    Next i
    
    ; create ground
    MeshPlane = CreatePlane(#PB_Any, 2000, 2000, 40, 40, 4, 4)
    CreateEntity(#PB_Any, MeshID(MeshPlane), MaterialID(DirtMaterial))
    
    ; Add house
    MeshHouse = LoadMesh(#PB_Any, "tudorhouse.mesh")
    House = CreateEntity(#PB_Any, MeshID(MeshHouse), #PB_Material_None, 0, 280, 0)
    ScaleEntity(House, 0.5, 0.5, 0.5)
    
    ;- Ninja
    NinjaMesh = LoadMesh(#PB_Any, "ninja.mesh")
    Ninja = CreateEntity(#PB_Any, MeshID(NinjaMesh), MaterialID(NinjaRed), 500, 0, 400)
    ScaleEntity(Ninja, 0.5, 0.5, 0.5)  
    StartEntityAnimation(Ninja, "Walk")
    
    ; SkyBox
    SkyBox("Desert07.jpg")
    
    ; create camera
    Camera = CreateCamera(#PB_Any, 0, 0, 100, 100)
    
    ; CUBE ENTITY IN FRONT OF CAMERA 
    ; ------------------------------------------
    node.l = CreateNode(#PB_Any,  0, 0, 0)
    boxm.l = CreateCube(#PB_Any, 50)
    boxe.l = CreateEntity(#PB_Any, MeshID(boxm), MaterialID(NinjaRed), 0,10,-200)
    AttachNodeObject(node.l, EntityID(boxe))
      
    Repeat
      Screen3DEvents()
      
      If ExamineMouse()
        MouseX = -MouseDeltaX() * #CameraSpeed * 0.03
        MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
      EndIf
      
      If ExamineKeyboard()
        
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -#CameraSpeed
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = #CameraSpeed
        Else
          KeyX * 0.85
        EndIf
        
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -#CameraSpeed
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = #CameraSpeed
        Else
          KeyY * 0.9
        EndIf
        
      EndIf
      
      MoveEntity(Ninja, KeyX, 0, KeyY, #PB_Local)
      Yaw(EntityID(Ninja), MouseX, #PB_World)       
      
      CameraFollow(Camera, EntityID(Ninja), 0, 120, 300, 1, 0.05, #True)     

      ; MOVE NODE
      MoveNode(node.l, CameraX(Camera), CameraY(Camera), CameraZ(Camera), #PB_Absolute)
      NodeFixedYawAxis(node, #True, 0, 1, 0)
      NodeLookAt(node, EntityX(Ninja), EntityY(Ninja), EntityZ(Ninja))
      
      RenderWorld()
      Screen3DStats()
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  EndIf
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf

End
But the thing is, i need to attach a entity that is build from several entity's (AttachEntityObject), when i try this PB just crashes:

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - CameraFollow
;
;    (c) Fantaisie Software
;
; ------------------------------------------------------------
;

#CameraSpeed = 2

IncludeFile #PB_Compiler_Home + "examples/3d/Screen3DRequester.pb"

Define.f KeyX, KeyY, MouseX, MouseY

If InitEngine3D()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  If Screen3DRequester()
    
    Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Models", #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Scripts", #PB_3DArchive_FileSystem)
    Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Packs/Desert.zip", #PB_3DArchive_Zip)
    Parse3DScripts()
    
    ; First create materials
    ;
    
    GrassMaterial = CreateMaterial(#PB_Any, TextureID(LoadTexture(#PB_Any,"grass1.png")))
    MaterialBlendingMode(GrassMaterial, #PB_Material_AlphaBlend)
    DirtMaterial = CreateMaterial(#PB_Any, TextureID(LoadTexture(#PB_Any,"Dirt.jpg")))
    NinjaRed = CreateMaterial(#PB_Any, TextureID(LoadTexture(#PB_Any,"nskinrd.jpg")))
    
    ; Then create the billboard group and use the previous material
    ;
    ;-Billboard
    
    Billboard = CreateBillboardGroup(#PB_Any, MaterialID(GrassMaterial), 60, 60)
    For i = 0 To 1000
      AddBillboard(Billboard, Random(2000)-1000, 30, Random(2000) - 1000)
    Next i
    
    ; create ground
    MeshPlane = CreatePlane(#PB_Any, 2000, 2000, 40, 40, 4, 4)
    CreateEntity(#PB_Any, MeshID(MeshPlane), MaterialID(DirtMaterial))
    
    ; Add house
    MeshHouse = LoadMesh(#PB_Any, "tudorhouse.mesh")
    House = CreateEntity(#PB_Any, MeshID(MeshHouse), #PB_Material_None, 0, 280, 0)
    ScaleEntity(House, 0.5, 0.5, 0.5)
    
    ;- Ninja
    NinjaMesh = LoadMesh(#PB_Any, "ninja.mesh")
    Ninja = CreateEntity(#PB_Any, MeshID(NinjaMesh), MaterialID(NinjaRed), 500, 0, 400)
    ScaleEntity(Ninja, 0.5, 0.5, 0.5)  
    StartEntityAnimation(Ninja, "Walk")
    
    ; SkyBox
    SkyBox("Desert07.jpg")
    
    ; create camera
    Camera = CreateCamera(#PB_Any, 0, 0, 100, 100)
    
    ; CUBE ENTITY ATTACHED TO ANOTHER ENTITY ATTACHED TO THE NODE  (CRASH PB)
    ; ---------------------------------------------------------------------------------
    node.l = CreateNode(#PB_Any,  0, 0, 0)
    boxm.l = CreateCube(#PB_Any, 50)
    boxe.l = CreateEntity(#PB_Any, MeshID(boxm), MaterialID(NinjaRed), 0,10,-200)
    ent.l = CreateEntity(#PB_Any)
    AttachEntityObject(ent.l, "", EntityID(boxe.l))
    AttachNodeObject(node.l, EntityID(ent.l))
    
    Repeat
      Screen3DEvents()
      
      If ExamineMouse()
        MouseX = -MouseDeltaX() * #CameraSpeed * 0.03
        MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
      EndIf
      
      If ExamineKeyboard()
        
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -#CameraSpeed
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = #CameraSpeed
        Else
          KeyX * 0.85
        EndIf
        
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -#CameraSpeed
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = #CameraSpeed
        Else
          KeyY * 0.9
        EndIf
        
      EndIf
      
      MoveEntity(Ninja, KeyX, 0, KeyY, #PB_Local)
      Yaw(EntityID(Ninja), MouseX, #PB_World)       
      
      
      CameraFollow(Camera, EntityID(Ninja), 0, 120, 300, 1, 0.05, #True)
     
      ; MOVE NODE  
      MoveNode(node.l, CameraX(Camera), CameraY(Camera), CameraZ(Camera), #PB_Absolute)
      NodeFixedYawAxis(node, #True, 0, 1, 0)
      NodeLookAt(node, EntityX(Ninja), EntityY(Ninja), EntityZ(Ninja))
      
      RenderWorld()
      Screen3DStats()
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  EndIf
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf

End
How do i get this to work?
Philippe-felixer76-3
User
User
Posts: 45
Joined: Mon Dec 30, 2013 10:12 pm

Re: CameraFollow and Billboard(group)

Post by Philippe-felixer76-3 »

Olli wrote:Hello,

You can use the code bbcode markup to show an orthogonal grid. It is the following markup

Code: Select all

[code]
to start and near the same markup to finish. Just insert a slash character before the 'code' statement.





Example :

Code: Select all

       \||/
[ a "beautiful" scheme ]
       /||\




I suppose you wanted to show a thing like this :
+-----------+
| |
+--+--+--+--+
| | | | |
+--+--+--+--+
[/code]
Tnx
User avatar
DK_PETER
Addict
Addict
Posts: 898
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: CameraFollow and Billboard(group)

Post by DK_PETER »

You can't just create en entity with #PB_Any without a mesh...
Small example for attachment to nodes..

Code: Select all

UsePNGImageDecoder()
UseJPEGImageDecoder()

InitEngine3D(#PB_Engine3D_DebugLog)
InitSprite()
InitKeyboard()

Structure valu
  tx.f
  ty.f
  tz.f
EndStructure
Global s.valu
Global b.valu

Structure obj
  id.i
  ma.i
  ms.i
  tx.i
EndStructure
Global o.obj

Structure BillB
  id.i
  tx.i
  ma.i
EndStructure
Global bb.BillB

Global Dim ob(10)

Global  BBnod.i, SaucerNod.i, ret.i, ev.i, bel.i, sel.i, quit.i = #False

Declare.i CreateSaucer()
Declare.i BB_Points()
Declare.f RandomF(Min.f, Max.f, Res.i = 100000)
Declare.i NewRotation(type.i)

OpenWindow(0, 0, 0, 1024, 768, "Attach", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0), 0, 0, 1024 * DesktopResolutionX(), 768 * DesktopResolutionY())
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
CreateCamera(0, 0, 0, 100, 100)

ret = BB_Points()

ret = CreateSaucer()

bel = ElapsedMilliseconds()
sel = ElapsedMilliseconds()

NewRotation(0)
NewRotation(1)

Repeat
  
  Repeat 
    ev = WindowEvent() 
    If ev  = #PB_Event_CloseWindow 
      quit  = #True 
    EndIf
  Until ev = 0
  
  ExamineKeyboard()
  If ElapsedMilliseconds() - bel > 5000
    ret = NewRotation(0)
    bel = ElapsedMilliseconds()
  EndIf
  
  If ElapsedMilliseconds() - sel > 15000
    ret = NewRotation(1)
    sel = ElapsedMilliseconds()
  EndIf
  
  RotateNode(BBnod, b\tx, b\ty, b\tz, #PB_Relative)
  RotateNode(SaucerNod, s\tx, s\ty, s\tz, #PB_Relative)
  RenderWorld()
  
  FlipBuffers()
  
Until KeyboardPushed(#PB_Key_Escape) Or quit = #True

Procedure.i CreateSaucer()
  Protected num, var.i = #False
  SaucerNod = CreateNode(#PB_Any, 0, 0, 0)
  o\tx = LoadTexture(#PB_Any, "BugSPIN.png")
  o\ma = CreateMaterial(#PB_Any, TextureID(o\tx))
  o\ms = CreateSphere(#PB_Any, 1, 40, 30)
  TransformMesh(o\ms, 0, 0, 0, 1, 0.1, 1, 0, 0, 0)
  UpdateMeshBoundingBox(o\ms)
  o\id = CreateEntity(#PB_Any, MeshID(o\ms), MaterialID(o\ma), 0, 0, -9)
  
  For num = 0 To 9
    ob(num) = CopyEntity(o\id, #PB_Any)
    MoveEntity(ob(num), RandomF(-20, 20), RandomF(-5, 5), RandomF(-40, -5), #PB_Absolute)
    If var = #True
      AttachNodeObject(SaucerNod, EntityID(ob(num)))
      var = #False
    Else
      var = #True
    EndIf
  Next
  
EndProcedure

Procedure.i BB_Points()
  Protected num
  bb\tx = LoadTexture(#PB_Any, "Lensflare5.jpg")
  bb\ma = CreateMaterial(#PB_Any, TextureID(bb\tx))
  MaterialBlendingMode(bb\ma, #PB_Material_Add)
  MaterialCullingMode(bb\ma, #PB_Material_NoCulling)
  bb\id = CreateBillboardGroup(#PB_Any, MaterialID(bb\ma), 0.5, 0.5, 0, 0, 0)
  For num = 0 To 2500
    AddBillboard(bb\id, RandomF(-50, 50), RandomF(-50, 50), RandomF(-50, 50))
  Next num
  BBnod = CreateNode(#PB_Any, 0, 0, 0)
  AttachNodeObject(BBnod, BillboardGroupID(bb\id))
   ProcedureReturn #True
EndProcedure

Procedure.i NewRotation(type.i)
  If type = 0
  If Random(100, 1) > 50  : b\tx = -0.1 : Else : b\tx = 0.1 : EndIf 
  If Random(100, 1) > 50  : b\ty = -0.1 : Else : b\ty = 0.1 : EndIf 
  If Random(100, 1) > 50  : b\tz = -0.1 : Else : b\tz = 0.1 : EndIf 
  Else
  If Random(100, 1) > 50  : s\tx = -0.1 : Else : s\tx = 0.1 : EndIf 
  If Random(100, 1) > 50  : s\ty = -0.1 : Else : s\ty = 0.1 : EndIf 
  If Random(100, 1) > 50  : s\tz = -0.1 : Else : s\tz = 0.1 : EndIf 
  EndIf
  ProcedureReturn #True
EndProcedure

;Negative and positive extremes allowed 
  Procedure.f RandomF(Min.f, Max.f, Res.i = 100000)
    ProcedureReturn (Min + (Max - Min) * Random(Res) / Res)
  EndProcedure
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
Philippe-felixer76-3
User
User
Posts: 45
Joined: Mon Dec 30, 2013 10:12 pm

Re: CameraFollow and Billboard(group)

Post by Philippe-felixer76-3 »

DK_PETER wrote:You can't just create en entity with #PB_Any without a mesh...
Small example for attachment to nodes..
Tnx, that solved my problem :lol:
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

Re: CameraFollow and Billboard(group)

Post by Olli »

I add the code of DK_Peter containing this function AttachNodeObject(), whom I did not the ability to attach BillboardGroup too.

Thank you DK_Peter ! Good subject.
Post Reply