Page 1 of 1

WorldShadows and NormalizeMesh() make entity disappear

Posted: Thu Oct 11, 2012 7:48 pm
by Samuel
When using WorldShadows, if you create a mesh and then normalize it using NormalizeMesh(). The mesh will not appear when you display it on the screen. If you comment out one or the other though the mesh displays fine.

Code: Select all


;***********************************************
;PRESS ESCAPE TO EXIT PROGRAM
;***********************************************

ExamineDesktops()

  InitKeyboard()
  InitMouse()
  
DeskWid=DesktopWidth(0)
DeskHei=DesktopHeight(0)

#CameraRotateSpeed=2

If OpenWindow(0, 0, 0, DeskWid, DeskHei, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget)
  If InitEngine3D()
  Else
    MessageRequester("Information", "ERROR///Could not InitEngine3D", 0) 
    End
  EndIf
  If  InitSprite()
  Else
    MessageRequester("Information", "ERROR///Could not InitSprite", 0)     
    End
  EndIf  

 If OpenWindowedScreen(WindowID(0), 0, 0, DeskWid, DeskHei, 0, 0, 0)

   
    CreateTexture(2, 512, 512)
    StartDrawing(TextureOutput(2))
       Box(0, 0, 512, 512 ,RGB(255,100,20))
    StopDrawing()
       
    CreateTexture(1, 512, 512)
    StartDrawing(TextureOutput(1))
       Box(0, 0, 512, 512 ,RGB(150,150,150))
    StopDrawing()
    CreateMaterial(2, TextureID(1))
    
     CreateMaterial(3, TextureID(2))
     MaterialAmbientColor(3, RGB(0,0,0))
     CreatePlane(3, 30000, 30000, 100, 100, 100, 100)
     CreateEntity(3,MeshID(3),MaterialID(3), 0, -1000, 0)
     
     CreateLight(0, RGB(250, 250, 250), 0, 0, 400)

;****************************Comment out Shadows or NormalizeMesh() to make mesh appear***************

     WorldShadows(#PB_Shadow_Modulative, 600,RGB(150,150,150))

;*******************************************************************************************    

     CreateCamera(0, 0, 0, 100, 100)
     CameraLocate(0, 1250, 0, 100)
     CameraLookAt(0, 0, 0, 0)
     CameraBackColor(0, RGB(155, 155, 155)) 
     
If CreateMesh(0)     
AddMeshVertex(-210,176,50)
AddMeshVertex(203,176,50)
AddMeshVertex(203,-166,50)
AddMeshVertex(-210,-166,50)
AddMeshVertex(-210,176,-50)
AddMeshVertex(203,176,-50)
AddMeshVertex(203,-166,-50)
AddMeshVertex(-210,-166,-50)
AddMeshFace(0,2,1)
AddMeshFace(4,5,6)
AddMeshFace(2,3,0)
AddMeshFace(2,0,3)
AddMeshFace(6,7,4)
AddMeshFace(0,1,4)
AddMeshFace(5,4,1)
AddMeshFace(1,2,5)
AddMeshFace(6,5,2)
AddMeshFace(2,3,6)
AddMeshFace(7,6,3)
AddMeshFace(3,0,7)
AddMeshFace(4,7,0)
FinishMesh()

MeshCreated=1 

;****************************Comment out Shadows or NormalizeMesh() to make mesh appear***************

NormalizeMesh(0)

;*******************************************************************************************

CreateEntity(1, MeshID(0), MaterialID(2))
EndIf
     
     
 Repeat
      Event = WaitWindowEvent(0) 

      If ExamineKeyboard()
      EndIf
      
      If ExamineMouse()
        MouseX = -(MouseDeltaX()/10)*#CameraRotateSpeed/2
        MouseY = -(MouseDeltaY()/10)*#CameraRotateSpeed/2
      EndIf
      
      If MeshCreated=1 
        MX=MX+MouseX
        MY=MY+MouseY
      RotateEntity(1, MY, MX, RollZ, #PB_Absolute)
      EndIf   

      RenderWorld()
      FlipBuffers()
      Delay(10)
      
  Until KeyboardPushed(#PB_Key_Escape)
 EndIf
EndIf    
End

Re: WorldShadows and NormalizeMesh() make entity disappear

Posted: Thu Oct 11, 2012 9:24 pm
by Olby
Your code works fine if custom mesh is substituted with CreateCube() for example. It might be the order you create faces in, or something along the lines.

Re: WorldShadows and NormalizeMesh() make entity disappear

Posted: Thu Oct 11, 2012 10:02 pm
by Polo
Had this issue as well with custom meshes! :)

Re: WorldShadows and NormalizeMesh() make entity disappear

Posted: Thu Oct 11, 2012 10:58 pm
by Samuel
Well at least i know I'm not the only one having this problem. I'll try changing around the order of the face creation and see if anything happens.