CreateEntity() failing

Everything related to 3D programming
williamvanhoecke
User
User
Posts: 65
Joined: Wed Jun 07, 2017 10:13 pm

CreateEntity() failing

Post by williamvanhoecke »

Hello,
Does someone know why the ENT = CreateEntity(#PB_Any, MeshID(LIN), #PB_Material_None,0,0,0,-1,#Mask2) does not work in the below example code ?
Thanks in advance

Code: Select all

  #Mask1 = 1 << 0 ;binary 1
  #Mask2 = 1 << 1 ;binary 2 
  InitEngine3D()
  InitSprite()

  OpenWindow(0, 0, 0, 640, 480, "Line3D 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)

  ; Create the line and attach it to the scene
  OBJ = CreateNode(#PB_Any,0,0,0)
  LIN = CreateLine3D(#PB_Any, 0, 0, 0, RGB(255, 0, 0), 1, 1, 1, RGB(0, 0, 255))
  ENT = CreateEntity(#PB_Any, MeshID(LIN), #PB_Material_None,0,0,0,-1,#Mask2)
  AttachNodeObject(OBJ,EntityID(ENT))

  Repeat
    RenderWorld()
    FlipBuffers()
  Until WaitWindowEvent(1) = #PB_Event_CloseWindow

User avatar
minimy
Enthusiast
Enthusiast
Posts: 551
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Re: CreateEntity() failing

Post by minimy »

Hello, this work.
A line 3D is a mesh but work like an entity.

Code: Select all

  #Mask1 = 1 << 0 ;binary 1
  #Mask2 = 1 << 1 ;binary 2 
  InitEngine3D()
  InitSprite()

  OpenWindow(0, 0, 0, 640, 480, "Line3D 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)

  ; Create the line and attach it to the scene
  OBJ = CreateNode(#PB_Any,0,0,0)
  LIN = CreateLine3D(#PB_Any, 0, 0, 0, RGB(255, 0, 0), 1, 1, 1, RGB(0, 0, 255))
;   ENT = CreateEntity(#PB_Any, MeshID(LIN), #PB_Material_None,0,0,0,-1,#Mask2)
  AttachNodeObject(OBJ,MeshID(LIN))

  Repeat
    RenderWorld()
    FlipBuffers()
  Until WaitWindowEvent(1) = #PB_Event_CloseWindow

If translation=Error: reply="Sorry, Im Spanish": Endif
williamvanhoecke
User
User
Posts: 65
Joined: Wed Jun 07, 2017 10:13 pm

Re: CreateEntity() failing

Post by williamvanhoecke »

Thanks minimy
Confusing dough, helpfile clearly says a line3d is a mesh. So assumed that an Entity could be created from it.
I need the Entity because I need a visibility mask to NOT let it show on all cameras
The way you do it works, but .... I am losing the visibility mask and the line is shown on ALL cameras
User avatar
minimy
Enthusiast
Enthusiast
Posts: 551
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Re: CreateEntity() failing

Post by minimy »

Hello, can create a 'dummy' entity like in this example or can create vertex to make a mesh for use as line.

This example work. You can see line in camera 0 but not in camera 1
I hope this help.

Code: Select all

  
  #Mask1 = 1 << 0 ;binary 1
  #Mask2 = 1 << 1 ;binary 2 
  InitEngine3D()
  InitSprite()

  OpenWindow(0, 0, 0, 640, 480, "Line3D 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, 50, 100,0)
  CreateCamera(1, 50, 0, 50, 100,1)
  CameraBackColor(0,$444444)
  CameraBackColor(1,$888888)
  MoveCamera(0, 2, 1, 3, #PB_Absolute | #PB_Local)
  MoveCamera(1, 2, 1, 3, #PB_Absolute | #PB_Local)
  CameraLookAt(0, 0, 0, 0)
  CameraLookAt(1, 0, 0, 0)
  
  
  ; Create the line and attach it to the scene
  dummyme= CreateCube(#PB_Any,0.01)
  dummyma= CreateMaterial(#PB_Any,#Null,RGB(255, 0, 0))
  dummyen= CreateEntity(#PB_Any,MeshID(dummyme),MaterialID(dummyma),0,0,0,0,0)
  OBJ = CreateNode(#PB_Any,0,0,0)
  LIN = CreateLine3D(#PB_Any, 0, 0, 0, RGB(255, 0, 0), 1, 1, 1, RGB(0, 0, 255))
  AttachEntityObject(dummyen,"",MeshID(LIN))
;   ENT = CreateEntity(#PB_Any, MeshID(LIN), #PB_Material_None,0,0,0,-1,#Mask2)
;   AttachNodeObject(OBJ,MeshID(LIN))
  AttachNodeObject(OBJ,EntityID(dummyen))

  Repeat
    WindowEvent()
    RotateEntity(dummyen,0,1,0,#PB_Relative)
    RenderWorld()
    FlipBuffers()
  Until WaitWindowEvent(1) = #PB_Event_CloseWindow


If translation=Error: reply="Sorry, Im Spanish": Endif
williamvanhoecke
User
User
Posts: 65
Joined: Wed Jun 07, 2017 10:13 pm

Re: CreateEntity() failing

Post by williamvanhoecke »

Minimy,
I already found another way around, I simply used a cube entity to form a line.
But the explanation with the invisible Entity as container for some other visible entitys is usefull for another problem I have.
Thanks.
Post Reply