Skip to content

Commit

Permalink
Fixed the bug that always exports the first frame of animation data
Browse files Browse the repository at this point in the history
  • Loading branch information
JiepengTan committed Aug 15, 2024
1 parent 45447dd commit 885e4f5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
3 changes: 2 additions & 1 deletion internal/anim/anim.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type IAnimator interface {
Play(clipName string) *common.AnimClipState
GetClipState(clipName string) *common.AnimClipState
GetFrameData() common.AnimExportFrame
UpdateToFrame(frameIndex int)
}

type AnimExportData struct {
Expand Down Expand Up @@ -128,7 +129,7 @@ func GetExportData(pself IAnimator, animName string) (*AnimExportData, error) {
state := pself.Play(animName)
data.Frames = make([]common.AnimExportFrame, state.FrameCount)
for i := 0; i < state.FrameCount; i++ {
pself.Update()
pself.UpdateToFrame(i)
data.Frames[i] = pself.GetFrameData()
}
return data, nil
Expand Down
5 changes: 5 additions & 0 deletions internal/anim/skeleton/animator.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ func (pself *Animator) Update() {
state := pself.GetClipState(pself.CurClipName)
state.Time += engine.Time.DeltaTime
frameIndex := state.GetCurFrame()
pself.UpdateToFrame(frameIndex)

}
func (pself *Animator) UpdateToFrame(frameIndex int) {
animData := pself.Clips[pself.CurClipName].(*AnimClip).Data.AnimData
frame := animData[frameIndex]
for i := 0; i < len(pself.LogicBones); i++ {
offset := i * 3
Expand Down
14 changes: 9 additions & 5 deletions internal/anim/vertex/animator.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,21 @@ func (pself *Animator) Update() {
if meshCount == 0 {
return
}
vertexCount := len(animData.AnimFramesVertex) / animData.FrameCount / 2

state := pself.GetClipState(pself.CurClipName)
state.Time += engine.Time.DeltaTime
frame := state.GetCurFrame()

pself.RederOrder = animData.RenderOrders[frame]
frameIndex := state.GetCurFrame()
pself.UpdateToFrame(frameIndex)

}
func (pself *Animator) UpdateToFrame(frameIndex int) {
animData := pself.Clips[pself.CurClipName].(*AnimClip).Data
vertexCount := len(animData.AnimFramesVertex) / animData.FrameCount / 2
pself.RederOrder = animData.RenderOrders[frameIndex]

// convert2WorldSpace
RenderVerteies := pself.RenderVerteies[0]
offset := frame * vertexCount * 2
offset := frameIndex * vertexCount * 2
for j := 0; j < vertexCount; j++ {
x := animData.AnimFramesVertex[offset+j*2+0]
y := animData.AnimFramesVertex[offset+j*2+1]
Expand Down

0 comments on commit 885e4f5

Please sign in to comment.