Voilas le code des procs :Declare AttachEntityAnimation(Entity, File.s)Declare SetEntityAnimation(Entity, Anim.s)Code : Tout sélectionner
Attache un "fichier de description d'animation" à l'entité Entity. Une entité peut avoir 100 animations au MAXIMUM! --- Entity : Identifiant de l'entité File.s : Chemin du fichier de description d'animation --- Renvois #True si l'opération à été effectuée avec succès, sinon renvois #False
Declare.s GetEntityAnimation(Entity)Code : Tout sélectionner
Change l'animation courante de l'entité Enity par l'animation qui a pour nom Anim.s --- Entity : Identifiant de l'entité Anim.s : Nom de l'animation --- Renvois #True si l'opération à été effectuée avec succès, sinon renvois #False
Declare AnimateEntities()Code : Tout sélectionner
Renvois le nom de l'animation courante
Code : Tout sélectionner
Permet d'animer correctement les entité par rapport à leur fichier de description d'animation. Cette procédure est à appeler de préférence avant l'affichage de la scène (donc juste avant RenderWorld())
Code : Tout sélectionner
Structure AnimInf
Start.l
End.l
Name.s
EndStructure
Structure EntityAnim
Entity.l
AnimTab.AnimInf[100]
NbAnim.l
CurrentAnim.l
FPS.l
EndStructure
NewList EntityAnim.EntityAnim()
Procedure AnimateEntities()
ForEach EntityAnim()
CurrentAnim = EntityAnim()\CurrentAnim
Entity = EntityAnim()\Entity
AStart = EntityAnim()\AnimTab[CurrentAnim]\Start
AEnd = EntityAnim()\AnimTab[CurrentAnim]\End
ACurrent.f = GetEntityAnimationTime(Entity)
;Debug Acurrent
If ACurrent < AStart / EntityAnim()\FPS
SetEntityAnimationTime(Entity, AStart)
EndIf
If ACurrent => AEnd / EntityAnim()\FPS
SetEntityAnimationTime(Entity, AStart)
EndIf
Next
EndProcedure
Procedure AttachEntityAnimation(Entity, File.s)
tempFile = OpenFile(#PB_Any, File)
If tempFile
AddElement(EntityAnim())
EntityAnim()\Entity = Entity
EntityAnim()\FPS = Val(Trim(ReadString()))
Repeat
cLine.s = Trim(ReadString())
EntityAnim()\AnimTab[EntityAnim()\NbAnim]\Start = Val(StringField(cLine, 1, ","))
EntityAnim()\AnimTab[EntityAnim()\NbAnim]\End = Val(StringField(cLine, 2, ","))
EntityAnim()\AnimTab[EntityAnim()\NbAnim]\Name = StringField(cLine, 3, ",")
EntityAnim()\NbAnim + 1
Until Eof(tempFile)
CloseFile(tempFile)
AnimateEntity(Entity, "Default")
ProcedureReturn #True
EndIf
ProcedureReturn #False
EndProcedure
Procedure.s GetEntityAnimation(Entity)
ForEach EntityAnim()
If EntityAnim()\Entity = Entity
ProcedureReturn EntityAnim()\AnimTab[EntityAnim()\CurrentAnim]\Name
EndIf
Next
ProcedureReturn ""
EndProcedure
Procedure SetEntityAnimation(Entity, Anim.s)
ForEach EntityAnim()
If EntityAnim()\Entity = Entity
For t = 0 To EntityAnim()\NbAnim
If EntityAnim()\AnimTab[t]\Name = Anim
EntityAnim()\CurrentAnim = t
ProcedureReturn #True
EndIf
Next
EndIf
Next
ProcedureReturn #False
EndProcedure
un exemple d'utilisation :24
0,20,Walk
22,62,IdleCode : Tout sélectionner
La première ligne indique le taux de frame(s) par seconde des animations, ensuite viennent les descriptions des animations. Il y a ici 2 animations : Walk et Idle. Le preimier nombre indique la premiere frame de l'animation et le deuxième, la dernière frame de l'animation.
Et pour finir, une capture de l'export du mesh sous MilkShape :Un fichier *.rar, contenant les ressources necessaires, est disponible à l'adresse suivante : http://perso.wanadoo.fr/persomrn/download/Gordon.rar
Voila l'exemple :Code : Tout sélectionner
;Auteur : Cederavic ;Version de PB : 3.93 ;Date : 24/05/05 ;Description : Permet d'animer des entity gràce à un fichier de description d'animation InitEngine3D() InitSprite() InitKeyboard() InitMouse() Structure AnimInf Start.l End.l Name.s EndStructure Structure EntityAnim Entity.l AnimTab.AnimInf[100] NbAnim.l CurrentAnim.l FPS.l EndStructure NewList EntityAnim.EntityAnim() Declare AttachEntityAnimation(Entity, File.s) Declare SetEntityAnimation(Entity, Anim.s) Declare.s GetEntityAnimation(Entity) Declare AnimateEntities() OpenScreen(1024, 768, 32, "EntityAnimation") UsePNGImageDecoder() LoadTexture(0, "Gordon.png") CreateMaterial(0, TextureID(0)) LoadMesh(0, "Gordon.mesh") CreateEntity(0, MeshID(0), MaterialID(0)) AttachEntityAnimation(0, "Gordon_Anim.txt") CreateCamera(0, 0, 0, 100, 100) CameraLocate(0, 0, 50, 100) Repeat ExamineKeyboard() ExamineMouse() If KeyboardPushed(#PB_Key_Left) cmovx = -5 ElseIf KeyboardPushed(#PB_Key_Right) cmovx = 5 Else cmovx = 0 EndIf If KeyboardPushed(#PB_Key_PageUp) cmovy = 5 ElseIf KeyboardPushed(#PB_Key_PageDown) cmovy = -5 Else cmovy = 0 EndIf If KeyboardPushed(#PB_Key_Up) cmovz = -5 ElseIf KeyboardPushed(#PB_Key_Down) cmovz = 5 Else cmovz = 0 EndIf If KeyboardReleased(#PB_Key_Pad1) SetEntityAnimation(0, "Idle") ElseIf KeyboardReleased(#PB_Key_Pad2) SetEntityAnimation(0, "Walk") EndIf crotx = -MouseDeltaX() croty = -MouseDeltaY() MoveCamera(0, cmovx, cmovy, cmovz) RotateCamera(0, crotx, croty, 0) ClearScreen(248, 186, 255) AnimateEntities() RenderWorld() StartDrawing(ScreenOutput()) DrawingMode(1) FrontColor(248, 186, 255) Locate(10, 10) DrawText(Str(Engine3DFrameRate(#PB_Engine3D_Current))) StopDrawing() FlipBuffers() Until KeyboardPushed(#PB_Key_Escape) Procedure AnimateEntities() ForEach EntityAnim() CurrentAnim = EntityAnim()\CurrentAnim Entity = EntityAnim()\Entity AStart = EntityAnim()\AnimTab[CurrentAnim]\Start AEnd = EntityAnim()\AnimTab[CurrentAnim]\End ACurrent.f = GetEntityAnimationTime(Entity) ;Debug Acurrent If ACurrent < AStart / EntityAnim()\FPS SetEntityAnimationTime(Entity, AStart) EndIf If ACurrent => AEnd / EntityAnim()\FPS SetEntityAnimationTime(Entity, AStart) EndIf Next EndProcedure Procedure AttachEntityAnimation(Entity, File.s) tempFile = OpenFile(#PB_Any, File) If tempFile AddElement(EntityAnim()) EntityAnim()\Entity = Entity EntityAnim()\FPS = Val(Trim(ReadString())) Repeat cLine.s = Trim(ReadString()) EntityAnim()\AnimTab[EntityAnim()\NbAnim]\Start = Val(StringField(cLine, 1, ",")) EntityAnim()\AnimTab[EntityAnim()\NbAnim]\End = Val(StringField(cLine, 2, ",")) EntityAnim()\AnimTab[EntityAnim()\NbAnim]\Name = StringField(cLine, 3, ",") EntityAnim()\NbAnim + 1 Until Eof(tempFile) CloseFile(tempFile) AnimateEntity(Entity, "Default") ProcedureReturn #True EndIf ProcedureReturn #False EndProcedure Procedure.s GetEntityAnimation(Entity) ForEach EntityAnim() If EntityAnim()\Entity = Entity ProcedureReturn EntityAnim()\AnimTab[EntityAnim()\CurrentAnim]\Name EndIf Next ProcedureReturn "" EndProcedure Procedure SetEntityAnimation(Entity, Anim.s) ForEach EntityAnim() If EntityAnim()\Entity = Entity For t = 0 To EntityAnim()\NbAnim If EntityAnim()\AnimTab[t]\Name = Anim EntityAnim()\CurrentAnim = t ProcedureReturn #True EndIf Next EndIf Next ProcedureReturn #False EndProcedure

Voili voilou...
