Posted: 21st Feb 2003 23:47
This is a program which uses all of the basic functions anyone needs to know to animate a model in DarkBasic. I'm still adding to all the time, so any suggestions are always welcome.

Edit:
Sadly, as the save object animation command was left out in DBPro, this is DBClassic only

*Uncomplete code cut out*
Posted: 21st Feb 2003 23:52
+ Code Snippet
Rem Project: Animation
Rem By Kentaree

`======================================================
`======================================================
` Project Info
ProjectTitle$ = "Animator"
MajorVersion$ = "1."
MinorVersion$ = "01"

Remstart ==============================================
    3D Object Animator
Description
    Program to animate native DarkBasic 3D objects using
    limbs, using DarkBasic commands
=======================================================
Instructions
=======================================================
Limb Animator
    + and - change the selected limb.
    Pressing up/down rotates the limb around its y-axis
    Pressing left/right rotates the limb around its x-axis
    Pressing up/down + shift rotates the limb around its z-axis

    Moving the mouse horizontally rotates the camera around the object
    Holding the left mouse button and moving the mouse vertically changes zoom

    Pressing F3 goes to the KeyFramer
=======================================================
KeyFramer
    + and - changes KeyFrame
    Return saves the current limb positions to KeyFrame number
    Space saves the animation

    Pressing F2 goes to Limb Animator
=======================================================
Remend

`Setup Program Environment
Sync On: Sync Rate 30
Set Display Mode 800,600,16
Set Window On : Set Window Size 800,600
TitleBar$ = ProjectTitle$+" "+MajorVersion$+MinorVersion$
Set Window Title TitleBar$
Maximize Window
Autocam Off
Draw To Front

`Setup Key Program Variables
Dim CamAngle#(3)
Dim Angle#(1)
Dim CamX#(1)
Dim CamZ#(1)

KeyFrame=1
EndKeyFrame=KeyFrame
Zoom#=20.0

`Input The Model To Animate
`Set Cursor 0, 30: Input "Model Filename (Must be in same folder as this file): ", ModelFile$

`Load The Model, Set The Cameras Position
LimbAmount=LoadModel(ModelFile$)
`Position Camera 0, 0, -11
Cam(0,Zoom#)

`Setup Necessary Camera Variables
CamX#(1)=Object Position X(1)
CamZ#(1)=Object Position Z(1)

`Model Animator
Animator:
Do
If Inkey$()="+" Then Inc Sel: SelectedLimb=LimbSelector(LimbAmount,Sel)
If Inkey$()="-" Then Dec Sel: SelectedLimb=LimbSelector(LimbAmount,Sel)
If Upkey()=1 And Shiftkey()=0 Then RotateLimb(SelectedLimb,0,-10,0)
If Downkey()=1 And Shiftkey()=0 Then RotateLimb(SelectedLimb,0,10,0)
If Leftkey()=1 Then RotateLimb(SelectedLimb,-10,0,0)
If Rightkey()=1 Then RotateLimb(SelectedLimb,10,0,0)
If Mousemovex()<>0 Then Cam(Mousemovex(),Zoom#)
If Mousemovey()<>0 And Mouseclick()=1 Then Zoom#=Zoom#+Mousemovey(): Cam(0,Zoom#)
If Upkey()=1 And Shiftkey()=1 Then RotateLimb(SelectedLimb,0,0,10)
If Downkey()=1 And Shiftkey()=1 Then RotateLimb(SelectedLimb,0,0,-10)
If Keystate(61)=1 Then Goto Keyframer
Set Cursor 0, 30: Print "Limb Animator": Print "Amount of Limbs: "; LimbAmount: Print "Selected Limb: "; SelectedLimb
Sync
Loop

`Model KeyFramer
KeyFramer:
Do
If Inkey$()="+" Then Inc KeyFrame
If Inkey$()="-" Then Dec KeyFrame
If Keystate(60)=1 Then Goto Animator
If Returnkey()=1 Then EndkeyFrame=SetKeyFrame(KeyFrame,EndKeyFrame)
If Spacekey()=1 Then SaveAnim()
If Scancode()=211 Then DeleteKeyFrames()
Set Cursor 0, 30: Print "Keyframer": Print "Amount of Limbs: "; LimbAmount: Print "Keyframe: "; Keyframe: Print "Amount of Frames: "; EndkeyFrame
Sync
Loop

Function LoadModel(Model$)
  While Done=0
    Cls
    Set Cursor 0, 30: Input "Model Filename (Must be in same folder as this file): ", Model$
    If File Exist(Model$)=0
      Wait 500
      Cls
      While Inkey$()=""
        Set Cursor 0,30: Print "File "; Model$; " doesn't exist. Press any key."
        Sync
      Endwhile
    Else
      Done=1
    Endif
    Sync
  Endwhile
  Load Object Model$, 1
  Set Object 1,0,1,1,1,0
  Position Object 1,0,0,5
  Color Object 1, RGB(255,255,255)
  Perform Checklist For Object Limbs 1
  LimbAmount=Checklist Quantity()
  Empty Checklist
Endfunction LimbAmount

Function LimbSelector(LimbAmount,Sel)
  If Sel <= LimbAmount And Sel >= 0
    If SelectedLimb <> Sel
      Color Limb 1, SelectedLimb, RGB(255,255,255)
    Endif
    SelectedLimb=Sel
  Endif
  If Sel < 0 Then Sel = 0
  If Sel > LimbAmount Then Sel = LimbAmount
  Color Limb 1, SelectedLimb, RGB(255,0,0)
Endfunction SelectedLimb

Function RotateLimb(SelectedLimb,RotateX,RotateY,RotateZ)
  If SelectedLimb > 0
    XAngle=Limb Angle X(1,SelectedLimb): YAngle=Limb Angle Y(1, SelectedLimb): ZAngle=Limb Angle Z(1, SelectedLimb)
    Rotate Limb 1, SelectedLimb, Wrapvalue((XAngle+RotateX)), Wrapvalue((YAngle+RotateY)), Wrapvalue((ZAngle+RotateZ))
  Endif
Endfunction

Function SetKeyFrame(KeyFrame,MaxKeyFrame)
  If KeyFrame > 0
    Set Object Keyframe 1, Keyframe
    If KeyFrame > MaxKeyFrame Then MaxKeyFrame=KeyFrame
  Endif
EndFunction MaxKeyFrame

Function SaveAnim()
  While Execute=0
  If ReturnKey()=1 Then Execute=1
  If Inkey$()=""
    State=0
  Else
    If State=0 and Keystate(14)=0 and returnkey()=0
      SaveFile$=SaveFile$+Inkey$()
      Inc Amount, 1
      State=1
    Endif
    If Scancode()=14 and Amount>0 and State=0
      SaveFile$=Left$(SaveFile$,Amount-1)
      State=1
      Dec Amount, 1
    Endif
  Endif
  Set Cursor 0, 30:Print "Please Enter Filename: "; SaveFile$
  Sync
  Endwhile
  SaveFile$=SaveFile$+".nm8"

  If File Exist(SaveFile$)=1
     Cls
     Done=0
     While Done=0
     Set Cursor 0,30: Print "File "; SaveFile$; " already exists. Overwrite (Y/N)?"
     If Upper$(Inkey$())="Y" Then Done=1
     If Upper$(Inkey$())="N" Then ExitFunction
     Sync
     Endwhile
  Endif
  Save Object Animation SaveFile$, 1
  Wait 500
  While Inkey$()=""
    Set Cursor 0,40:Print "File "; SaveFile$; " Saved. Press Any Key"
    Sync
  Endwhile
  SaveFile$=""
  Execute=0
  Amount=0
Endfunction

Function Cam(Value,Zoom#)
  If Value>90 Then Value=90
  If Value<-90 Then Value=-90
  CamX#(1)=Object Position X(1)
  CamZ#(1)=Object Position Z(1)
  Angle#(1)=Wrapvalue(Angle#(1)+Value)
  CamAngle#(1)=Wrapvalue(Curveangle(Angle#(1),CamAngle#(1.0),1.0))
  CamAngle#(2)=NewXvalue(CamX#(1),Wrapvalue(CamAngle#(1)+180.0),Zoom#)
  CamAngle#(3)=NewZvalue(CamZ#(1),Wrapvalue(CamAngle#(1)+180.0),Zoom#)
  Position Camera CamAngle#(2), 0.0, CamAngle#(3)
  YRotate Camera CamAngle#(1)
Endfunction

Function Deletekeyframes()
  Done=0
  While Done=0
    Set Cursor 0,30: Print "This will delete all Keyframes! Are you sure?"
    If Upper$(Inkey$())="N" Then Exitfunction
    If Upper$(Inkey$())="Y"
      Clear All Object KeyFrames 1
      Wait 500
      While Inkey$()=""
      Set Cursor 0,50: Print "All Keyframes have been deleted. Press any key."
      Sync
      Endwhile
      Done=1
    Endif
    Sync
  Endwhile
Endfunction
Posted: 21st Feb 2003 23:53
Sorry, first post didnt work. Damn I wish that edit function would work...
Posted: 22nd Feb 2003 1:00
You should mention that it oly work with dbc
(cose the save comand exist any longer )
Posted: 22nd Feb 2003 16:15
Yea,sorry. I was actually far into developing a version with DBPro, before I found that out, luckily I could convert most of the code into DB classic.
Posted: 25th Feb 2003 13:45
At the moment I'm also working on a GUI for it, its not entirely necessary but it does make it look good
Posted: 28th Feb 2003 15:14
hey, this is a real cool program, tried it out.btw, is there a way i could load the animation file it saves, so i could us them. [/img]
Posted: 28th Feb 2003 22:04
+ Code Snippet
append object animation modelName$,animFile$,objectNo,startingFrame


where modelName$=the original model file used for animating
animFile$=your .nm8 file containing anim data
objectNo=the number of the object you want to append the
anim to
startingFrame=the frame number where it will start appending
Posted: 28th Feb 2003 22:07
So say you made a walk animation that is 10 frames long

append object animation "model.x","walk.nm8",1,1

will set frames 1-10 as walk animations. So when you add another animation you can append them from frame 11.
Good luck!
Posted: 4th Mar 2003 20:29
oh
Posted: 11th May 2003 21:25
Geez, Kentaree this looks more like an entire program than a snippit.
Maybe you could post this on the Program Announcements board. I'd bet a ton of people would be interested. Just an idea
Underhill
Posted: 11th May 2003 21:26
It's OK if you like it as a snippit, too.
Posted: 11th May 2003 23:10
LOL, I had forgotten totally about this thread. Yeah, you're probably right. I might actually just adjust it a bit more, finish the GUI and release it as a program.