ArcBasicDocs

samples/JamesH/AnimationFiles

animation_files.abs

115 lines of ArcBasic. Words in colour that are commands link to their help page. To run it, download ArcBasic, open the file and press F5.

Download animation_files.absAll files in this folder

animation_files.abs
; Animation files - one model, animations from separate files;; Kenney's Animated Characters (CC0, www.kenney.nl) come as a single .fbx; model, separate .fbx files for each animation, and skin textures.; LoadAnimSeq adds the animations from each file to the model, and; EntityTexture dresses the whole model in a skin.;; Jump plays once - the characters really leave the ground - and then; they go back to idle. With smooth transitions on, Animate's transition; blends each change of animation instead of snapping.;; Keys:  1  idle   2  run   3  jump   T  smooth transitions on/off;        K  change skins   Left/Right  turn   Escape  quitGraphics3D 1024,768,0,2SetBuffer BackBuffer()camera=CreateCamera()PositionEntity camera,0,1.6,-6.5TurnEntity camera,8,0,0CameraClsColor camera,250,220,180AmbientLight 140,130,130sun=CreateLight(1)RotateEntity sun,50,-30,0LightShadows sunCameraAmbientOcclusion camera,True,3,.5floor=CreatePlane()EntityColor floor,240,200,150; the skinsDim skin(3)skin(0)=LoadTexture("Skins\skaterMaleA.png")skin(1)=LoadTexture("Skins\skaterFemaleA.png")skin(2)=LoadTexture("Skins\cyborgFemaleA.png")skin(3)=LoadTexture("Skins\criminalMaleA.png"); one model, three animation filesmodel=LoadAnimMesh("Model\characterMedium.fbx")idle=LoadAnimSeq(model,"Animations\idle.fbx")run=LoadAnimSeq(model,"Animations\run.fbx")jump=LoadAnimSeq(model,"Animations\jump.fbx")size#=1.8/MeshHeight(model)ScaleEntity model,size,size,sizeTurnEntity model,0,180,0HideEntity model; a line of four characters, each wearing a different skinDim guy(3)For i=0 To 3	guy(i)=CopyEntity(model)	PositionEntity guy(i),-3+i*2,0,0	EntityTexture guy(i),skin(i)	Animate guy(i),1,.5,idleNextfirstSkin=0 : smooth=True : current=idleWhile Not KeyHit(1)	transition#=0 : If smooth Then transition=8	If KeyHit(2) Then current=idle : PlayAll(idle,1,transition)	If KeyHit(3) Then current=run : PlayAll(run,1,transition)	If KeyHit(4) And current<>jump		current=jump		PlayAll(jump,3,transition/2)        ; mode 3: play once	EndIf	; when the jump has finished, always go back to idle	If current=jump And Not Animating(guy(0))		current=idle		PlayAll(idle,1,transition)	EndIf	; while jumping, lift the characters off the ground and back down	height#=0	If current=jump And AnimLength(guy(0))>0		t#=AnimTime(guy(0))/Float(AnimLength(guy(0)))		If t>.2 And t<.8 Then height=Sin((t-.2)/.6*180)*.9	EndIf	For i=0 To 3		PositionEntity guy(i),EntityX(guy(i)),height,EntityZ(guy(i))	Next	If KeyHit(20) Then smooth=Not smooth	If KeyHit(37)		firstSkin=(firstSkin+1) Mod 4		For i=0 To 3			EntityTexture guy(i),skin((firstSkin+i) Mod 4)		Next	EndIf	For i=0 To 3		If KeyDown(203) Then TurnEntity guy(i),0,2,0		If KeyDown(205) Then TurnEntity guy(i),0,-2,0	Next	UpdateWorld	RenderWorld	Color 60,40,30	Text 10,10,"ANIMATION FILES - characters by Kenney (www.kenney.nl, CC0)"	Text 10,30,"1 idle   2 run   3 jump   K change skins   Left/Right turn"	If smooth Then s$="on" Else s$="off"	Text 10,45,"T smooth transitions: "+s$	Text 10,70,"The model has "+CountAnimSeqs(model)+" animation sequences:"	For q=0 To CountAnimSeqs(model)-1		mark$="  " : If q=current Then mark$="> "		Text 10,90+q*15,mark$+q+"  "+AnimSeqName$(model,q)	Next	FlipWendEnd; Plays an animation on all four characters.Function PlayAll(seq,mode,transition#)	For i=0 To 3		Animate guy(i),mode,.5,seq,transition	NextEnd Function