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
Whatever I did I didn't do it!