From 98ce816ab83abd6194b207edbaf41298ee68db0d Mon Sep 17 00:00:00 2001 From: JupiterRider <60042618+JupiterRider@users.noreply.github.com> Date: Sat, 14 Dec 2024 20:19:05 +0100 Subject: [PATCH 1/6] ModelAnimation.GetBones() added #466 --- raylib/raylib.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/raylib/raylib.go b/raylib/raylib.go index 95c6911d..fa7f817c 100644 --- a/raylib/raylib.go +++ b/raylib/raylib.go @@ -932,6 +932,11 @@ type ModelAnimation struct { Name [32]int8 } +// GetBones returns the bones information (skeleton) of a ModelAnimation as go slice +func (m ModelAnimation) GetBones() []BoneInfo { + return unsafe.Slice(m.Bones, m.BoneCount) +} + // RayCollision type - ray hit information type RayCollision struct { Hit bool From dce94f509d87231b33a8d6e3695724d44cf8e401 Mon Sep 17 00:00:00 2001 From: JupiterRider <60042618+JupiterRider@users.noreply.github.com> Date: Sat, 14 Dec 2024 21:15:08 +0100 Subject: [PATCH 2/6] ModelAnimation.GetFramePose() added #466 --- raylib/raylib.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/raylib/raylib.go b/raylib/raylib.go index fa7f817c..935709a3 100644 --- a/raylib/raylib.go +++ b/raylib/raylib.go @@ -937,6 +937,12 @@ 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] +} + // RayCollision type - ray hit information type RayCollision struct { Hit bool From 533c35110b498d7fa10dd256ae3687a172450dd3 Mon Sep 17 00:00:00 2001 From: JupiterRider <60042618+JupiterRider@users.noreply.github.com> Date: Sat, 14 Dec 2024 21:26:58 +0100 Subject: [PATCH 3/6] ModelAnimation.GetName() added --- raylib/raylib.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/raylib/raylib.go b/raylib/raylib.go index 935709a3..0cd31264 100644 --- a/raylib/raylib.go +++ b/raylib/raylib.go @@ -929,7 +929,7 @@ 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 @@ -943,6 +943,17 @@ func (m ModelAnimation) GetFramePose(frame, bone int) Transform { 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 type RayCollision struct { Hit bool From 46524a8c46b9a6ab43ca53d1be5f0835e83040ad Mon Sep 17 00:00:00 2001 From: JupiterRider <60042618+JupiterRider@users.noreply.github.com> Date: Sat, 14 Dec 2024 21:47:37 +0100 Subject: [PATCH 4/6] Update examples for #466 --- examples/models/m3d_loading/main.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/examples/models/m3d_loading/main.go b/examples/models/m3d_loading/main.go index 2d8ef560..192775f5 100644 --- a/examples/models/m3d_loading/main.go +++ b/examples/models/m3d_loading/main.go @@ -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) } } } From 041142d30c9b87693b4cc01f81e145b0ab1aec89 Mon Sep 17 00:00:00 2001 From: JupiterRider <60042618+JupiterRider@users.noreply.github.com> Date: Sat, 14 Dec 2024 21:57:46 +0100 Subject: [PATCH 5/6] update another ModelAnimation example --- examples/models/animation/main.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/examples/models/animation/main.go b/examples/models/animation/main.go index 851d38f1..b8d3c40d 100644 --- a/examples/models/animation/main.go +++ b/examples/models/animation/main.go @@ -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) From c301540ef5e413b48664cfb5b0874946afdcdd11 Mon Sep 17 00:00:00 2001 From: JupiterRider <60042618+JupiterRider@users.noreply.github.com> Date: Sat, 14 Dec 2024 22:04:59 +0100 Subject: [PATCH 6/6] gltf_loading example shows the name of the current animation now --- examples/models/gltf_loading/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/models/gltf_loading/main.go b/examples/models/gltf_loading/main.go index 26f31200..a8298787 100644 --- a/examples/models/gltf_loading/main.go +++ b/examples/models/gltf_loading/main.go @@ -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()