; ModelLoadError Example ; ---------------------- ; Requires Extended mode. Graphics3D 640,480,0,2 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,1,-6 light=CreateLight() RotateEntity light,45,45,0 ; A stand-in prop that spins while no model has been loaded placeholder=CreateSphere(12) ScaleEntity placeholder,0.4,0.4,0.4 ; Start with a deliberate failure so there is a message to read straight away tried$="media/no_such_model.b3d" model=LoadMesh(tried$) ; ModelLoadError reports the last loader failure, or "" after a success why$=ModelLoadError() While Not KeyDown(1) ; 1 a real model, 2 a file that is not there, 3 a file that is not a model want$="" If KeyHit(2) Then want$="media/oil-drum/oildrum.3ds" If KeyHit(3) Then want$="media/no_such_model.b3d" If KeyHit(4) Then want$="media/b3dlogo.jpg" If want$<>"" If model<>0 Then FreeEntity model tried$=want$ ; LoadMesh just returns 0 when it fails - it never says why model=LoadMesh(tried$) why$=ModelLoadError() If model<>0 Then FitMesh model,-1,0,-1,2,2,2,True EndIf ; Show the placeholder only while there is no model to look at If model=0 ShowEntity placeholder Else HideEntity placeholder EndIf TurnEntity placeholder,0,1.5,0 If model<>0 Then TurnEntity model,0,0.6,0 ; Arrow keys move the camera If KeyDown(200) Then MoveEntity camera,0,0,0.1 If KeyDown(208) Then MoveEntity camera,0,0,-0.1 If KeyDown(203) Then TurnEntity camera,0,1,0 If KeyDown(205) Then TurnEntity camera,0,-1,0 RenderWorld Text 0,0,"1: real model 2: missing file 3: not a model Arrows: camera Esc: exit" Text 0,20,"LoadMesh("+Chr$(34)+tried$+Chr$(34)+") = "+model If why$="" Text 0,40,"ModelLoadError() = "+Chr$(34)+Chr$(34)+" - empty, so that load worked" Else Text 0,40,"ModelLoadError() = "+why$ EndIf Text 0,60,"Print this string when a load fails and you know exactly what broke" Flip Wend End