Rem Project: Animation
Rem By Kentaree
`======================================================
`======================================================
` Project Info
ProjectTitle$ = "Animator"
MajorVersion$ = "1."
MinorVersion$ = "00"
Remstart ==============================================
3D Object Animator
Description
Program to animate native DarkBasic 3D objects using
limbs, using DarkBasic commands
Remend `===============================================
`Setup Program Environment
Sync On
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
`Get The Model To Animate
Set Cursor 0, 15: Input "Model Filename: ", ModelFile$
`Load The Model, Set The Cameras Position
LimbAmount=LoadModel(ModelFile$)
Position Camera 0, 0, -11
`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())
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 "Animator": Print "Amount of Limbs: "; LimbAmount: Print "Selected Limb: "; SelectedLimb
`Stats(State, KeyFrame, Endkeyframe, LimbAmount, 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
Set Cursor 0, 80
Input "Enter Filename for Animation Save (No extension)"; File$
FileName$=File$+".nm8"
SaveAnim(Filename$)
Endif
Set Cursor 0, 30: Print "Keyframer": Print "Amount of Limbs: "; LimbAmount: Print "Keyframe: "; Keyframe: Print "Amount of Frames: "; EndkeyFrame
`Stats(State, KeyFrame, Endkeyframe, LimbAmount, SelectedLimb)
Sync
Loop
Function LoadModel(Model$)
Cls
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 MoveObject(MoveX,MoveY,MoveZ)
XPos=Object Position X(1): YPos=Object Position Y(1): ZPos=Object Position Z(1)
Position Object 1, MoveX, MoveY, MoveZ
Endfunction
Function ScaleLimb(SelectedLimb,ScaleX,ScaleY,ScaleZ)
If SelectedLimb > 0
Scale Limb 1, SelectedLimb, ScaleX, ScaleY, ScaleZ
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(SaveFile$)
If File Exist(SaveFile$)=1
While Done=0
Input "File "; SaveFile$; " already exists. Overwrite (Y/N)? "; Choice$
If Choice$="Y" OR Choice$="y" Then Done=1
If Choice$="N" OR Choice$="n" Then ExitFunction
Endwhile
Endif
Save Object Animation SaveFile$, 1
Print "File Saved. Press Any Key"
Suspend For Key
Endfunction
Function Stats(State, KeyFrame, Endkeyframe, LimbAmount, SelectedLimb)
If State=1 Then State$="Animator"
If State=2 Then State$="KeyFramer"
Set Cursor 0, 30: Print State$: Print "Amount of Limbs: "; LimbAmount: Print "Selected Limb: "; SelectedLimb: If State$="KeyFramer" Then Print "Keyframe: "; Keyframe: If State$="KeyFramer" Then Print "Amount of Frames: "; EndkeyFrame
Endfunction
Function Cam(Value)
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),16.0)
CamAngle#(3)=NewZvalue(CamZ#(1),Wrapvalue(CamAngle#(1)+180.0),16.0)
Position Camera CamAngle#(2), 0.0, CamAngle#(3)
YRotate Camera CamAngle#(1)
Endfunction
This is an animator I made. It is made in DB Classic, but maybe it will help you.
Whatever I did I didn't do it!