Merge pull request #474 from JupiterRider/model_animation
ModelAnimation improvements
This commit is contained in:
commit
7a899c5e3a
4 changed files with 33 additions and 15 deletions
|
@ -21,8 +21,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
|
@ -76,9 +74,8 @@ func main() {
|
|||
rl.DrawModelEx(model, position, rl.NewVector3(1, 0, 0), -90, rl.NewVector3(1, 1, 1), rl.White)
|
||||
// Draw translation cubes
|
||||
for i := int32(0); i < model.BoneCount; i++ {
|
||||
framePose := unsafe.Slice(anims[0].FramePoses, anims[0].FrameCount)
|
||||
trans := unsafe.Slice(framePose[animFrameCount], model.BoneCount)
|
||||
rl.DrawCube(trans[i].Translation, 0.2, 0.2, 0.2, rl.Red)
|
||||
pose := anims[0].GetFramePose(animFrameCount, int(i))
|
||||
rl.DrawCube(pose.Translation, 0.2, 0.2, 0.2, rl.Red)
|
||||
}
|
||||
rl.DrawGrid(10, 1)
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ func main() {
|
|||
|
||||
rl.EndMode3D()
|
||||
|
||||
rl.DrawText("current animation number: "+fmt.Sprint(animIndex), 10, 10, 10, rl.Black)
|
||||
rl.DrawText(fmt.Sprintf("current animation: %s [%d]", animPlaying.GetName(), animIndex), 10, 10, 10, rl.Black)
|
||||
rl.DrawText("UP/DOWN ARROW KEYS CHANGE ANIMATION", 10, 30, 10, rl.Black)
|
||||
|
||||
rl.EndDrawing()
|
||||
|
|
|
@ -19,9 +19,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
|
||||
"github.com/gen2brain/raylib-go/raylib"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -116,9 +114,8 @@ func main() {
|
|||
if drawSkeleton {
|
||||
modelBones := model.GetBones()
|
||||
modelPoses := model.GetBindPose()
|
||||
animBones := unsafe.Slice(anims[animID].Bones, anims[animID].BoneCount)
|
||||
animPoses := unsafe.Slice(anims[animID].FramePoses, anims[animID].FrameCount)
|
||||
transforms := unsafe.Slice(animPoses[animFrameCounter], anims[animID].BoneCount)
|
||||
anim := anims[animID]
|
||||
animBones := anim.GetBones()
|
||||
for bone := 0; bone < int(model.BoneCount)-1; bone++ {
|
||||
if !animPlaying || animsCount == 0 {
|
||||
// Display the bind-pose skeleton
|
||||
|
@ -128,9 +125,11 @@ func main() {
|
|||
}
|
||||
} else {
|
||||
// // Display the frame-pose skeleton
|
||||
rl.DrawCube(transforms[bone].Translation, 0.05, 0.05, 0.05, rl.Red)
|
||||
pos := anim.GetFramePose(animFrameCounter, bone).Translation
|
||||
rl.DrawCube(pos, 0.05, 0.05, 0.05, rl.Red)
|
||||
if animBones[bone].Parent >= 0 {
|
||||
rl.DrawLine3D(transforms[bone].Translation, transforms[animBones[bone].Parent].Translation, rl.Red)
|
||||
endPos := anim.GetFramePose(animFrameCounter, int(animBones[bone].Parent)).Translation
|
||||
rl.DrawLine3D(pos, endPos, rl.Red)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -929,7 +929,29 @@ type ModelAnimation struct {
|
|||
FrameCount int32
|
||||
Bones *BoneInfo
|
||||
FramePoses **Transform
|
||||
Name [32]int8
|
||||
Name [32]uint8
|
||||
}
|
||||
|
||||
// GetBones returns the bones information (skeleton) of a ModelAnimation as go slice
|
||||
func (m ModelAnimation) GetBones() []BoneInfo {
|
||||
return unsafe.Slice(m.Bones, m.BoneCount)
|
||||
}
|
||||
|
||||
// GetFramePose returns the Transform for a specific bone at a specific frame
|
||||
func (m ModelAnimation) GetFramePose(frame, bone int) Transform {
|
||||
framePoses := unsafe.Slice(m.FramePoses, m.FrameCount)
|
||||
return unsafe.Slice(framePoses[frame], m.BoneCount)[bone]
|
||||
}
|
||||
|
||||
// GetName returns the ModelAnimation's name as go string
|
||||
func (m ModelAnimation) GetName() string {
|
||||
var end int
|
||||
for end = range m.Name {
|
||||
if m.Name[end] == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
return string(m.Name[:end])
|
||||
}
|
||||
|
||||
// RayCollision type - ray hit information
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue