Author Topic: loading an animated 3d character  (Read 290 times)

Offline phodiS

  • Jr. Member
  • **
  • Posts: 40
loading an animated 3d character
« on: November 15, 2018, 04:03:49 PM »
I am trying to load in a 3d animated character, but I keep getting the error
"failed to load object "knightwithshield.x"  I have the file in the root directory of the project directory   ,am I doing this right?.
Code:  (Unknown Language)
  1. // show all errors
  2. SetErrorMode(2)
  3.  
  4. // set window properties
  5. SetWindowTitle( "Animation test" )
  6. SetWindowSize( 1024, 768, 0 )
  7. SetWindowAllowResize( 1 ) // allow the user to resize the window
  8.  
  9. // set display properties
  10. SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
  11. SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
  12. SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
  13. SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
  14. UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
  15. cameraMode = 1
  16. SetCameraPosition(1,2000,180,1400) // startcam position
  17. SetCameraRange( 1, 0.1, 600 )
  18. SetCameraLookAt( 1, 0,40,0,0 )
  19. setcamerafov(1,100)
  20. rotateCameraglobaly(1,45)
  21. type gametype
  22.         obj as integer
  23.         endtype
  24.        
  25.  
  26.  
  27. //Character
  28.  
  29. knight=LoadObjectWithChildren("knightwithshield.x")
  30. SetObjectScalePermanent(knight,1,100,1)
  31. SetObjectColor(knight,255,0,0,255)
  32.  
  33. while rc<300
  34.         d=random(0,360)
  35.         SetObjectRotation(obj,0,d,0)
  36.         playobjectanimation(obj,"knightwithshield.x",1,154,1,0)
  37.         x# = random(-3000,3000)
  38.         z# = random(-3000,3000)
  39.         y# = getobjectheightmapheight(1,x#,z#)
  40.                 if y#>20
  41.         SetobjectPosition (obj,x#,y#,z#)
  42.         SetObjectCastShadow(obj,2)
  43.                 rc=rc+1
  44.         endif  
  45. endwhile        
  46.  
  47. do
  48.     // move the camera
  49.         speed# = 3.0
  50.         if ( GetRawKeyState( 16 ) ) then speed# = 5
  51.         if ( cameraMode = 1 ) then speed# = .5
  52.        
  53.         if ( GetRawKeyState( 87 ) ) then MoveCameraLocalZ( 1, speed# )   //move forward
  54.         if ( GetRawKeyState( 83 ) ) then MoveCameraLocalZ( 1, -speed# )  //move back
  55.  
  56.         if ( GetRawKeyState( 65 ) ) then RotateCameraLocalY( 1, -2 ) //rotate left
  57.         if ( GetRawKeyState( 68 ) ) then RotateCameraLocaly( 1, 2 )  //rotate right
  58.  
  59.         if ( GetRawKeyState( 81 ) ) then RotateCameraLocalx( 1, speed# )
  60.         if ( GetRawKeyState( 69 ) ) then rotatecameralocalx( 1, -speed# )
  61.        
  62.         if ( getvirtualbuttonstate(1) = 1 ) then MoveCameraLocalZ( 1, -speed# )
  63.     if ( getvirtualbuttonstate(2) = 1 ) then MoveCameraLocalZ( 1, speed# )
  64.        
  65.         // rotate the camera
  66.         if ( GetPointerpressed() )
  67.         startx# = GetPointerX()
  68.         starty# = GetPointerY()
  69.         angx# = GetCameraAngleX(1)
  70.         angy# = GetCameraAngleY(1)
  71.         pressed = 1
  72.     endif
  73.  
  74.     if ( GetPointerState() = 1 )
  75.         fDiffX# = (GetPointerX() - startx#)/4.0
  76.         fDiffY# = (GetPointerY() - starty#)/4.0
  77.  
  78.         newX# = angx# + fDiffY#
  79.         if ( newX# > 89 ) then newX# = 89
  80.         if ( newX# < -89 ) then newX# = -89
  81.         SetCameraRotation( 1, newX#, angy# + fDiffX#, 0 )
  82.      endif
  83.    
  84.     // change camera mode
  85. //    if ( GetVirtualButtonPressed(3) = 1 ) then cameraMode = 1-cameraMode
  86. //    if ( cameraMode = 1 )
  87.                 // stick camera to the terrain
  88.                 x# = GetCameraX(1)
  89.                 z# = GetCameraZ(1)
  90.         if GetObjectHeightMapHeight(1,x#,z#)>62
  91.         SetCameraPosition( 1, x#, GetObjectHeightMapHeight(1,x#,z#)+4, z# )
  92.         endif
  93.  
  94.     Print( ScreenFPS() )
  95.     Sync()
  96. loop
  97.  

Offline blinkok

  • Jr. Member
  • **
  • Posts: 23
Re: loading an animated 3d character
« Reply #1 on: November 16, 2018, 04:34:14 AM »
create a directory in your project directory called "media" (lowercase)
Put your model in the "media" folder

Offline phodiS

  • Jr. Member
  • **
  • Posts: 40
Re: loading an animated 3d character
« Reply #2 on: November 19, 2018, 03:54:57 PM »
Hi there, I tried putting it into a media folder in the root directory of the program, but still get the same error. I have tried other models as well like the soldier.X and a robot.x all in the same folder .. is the actual command I am using right   >>>   knight=LoadObjectWithChildren("knightwithshield.x")   <<<   I tried with upper and lower cased ".x" as well with no luck...

Offline blinkok

  • Jr. Member
  • **
  • Posts: 23
Re: loading an animated 3d character
« Reply #3 on: November 19, 2018, 08:03:25 PM »
it worked ok for me. i did it with a simple object though. if you wanna pm me the model i could give it a try

Offline phodiS

  • Jr. Member
  • **
  • Posts: 40
Re: loading an animated 3d character
« Reply #4 on: November 20, 2018, 03:17:02 PM »
Ok, got it going :)   cheers guys.