Try gooner animation
This commit is contained in:
@ -5,21 +5,74 @@ import (
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
func LoadModels() ([]types.ModelAsset, error) {
|
||||
goonerModel := rl.LoadModel("resources/models/goonion.obj")
|
||||
goonerTexture := rl.LoadTexture("resources/models/goonion.png")
|
||||
rl.SetMaterialTexture(goonerModel.Materials, rl.MapDiffuse, goonerTexture)
|
||||
// Helper function to load animations for a model
|
||||
func loadModelAnimations(animPaths map[string]string) (types.AnimationSet, error) {
|
||||
var animSet types.AnimationSet
|
||||
|
||||
// Load idle animations if specified
|
||||
if idlePath, ok := animPaths["idle"]; ok {
|
||||
idleAnims := rl.LoadModelAnimations(idlePath)
|
||||
if len(idleAnims) > 0 {
|
||||
animSet.Idle = idleAnims
|
||||
rl.TraceLog(rl.LogInfo, "Loaded idle animation: %s (%d frames, %f seconds)",
|
||||
idlePath, idleAnims[0].FrameCount, float32(idleAnims[0].FrameCount)/60.0)
|
||||
}
|
||||
}
|
||||
|
||||
// Load walk animations if specified
|
||||
if walkPath, ok := animPaths["walk"]; ok {
|
||||
walkAnims := rl.LoadModelAnimations(walkPath)
|
||||
if len(walkAnims) > 0 {
|
||||
animSet.Walk = walkAnims
|
||||
rl.TraceLog(rl.LogInfo, "Loaded walk animation: %s (%d frames, %f seconds)",
|
||||
walkPath, walkAnims[0].FrameCount, float32(walkAnims[0].FrameCount)/60.0)
|
||||
}
|
||||
}
|
||||
|
||||
return animSet, nil
|
||||
}
|
||||
|
||||
func LoadModels() ([]types.ModelAsset, error) {
|
||||
// Goonion model and animations
|
||||
goonerModel := rl.LoadModel("resources/models/biped/Animation_Unsteady_Walk_withSkin.glb")
|
||||
goonerAnims, _ := loadModelAnimations(map[string]string{"idle": "resources/models/biped/Animation_Idle_withSkin.glb", "walk": "resources/models/biped/Animation_Unsteady_Walk_withSkin.glb"})
|
||||
|
||||
// Apply transformations
|
||||
transform := rl.MatrixIdentity()
|
||||
transform = rl.MatrixMultiply(transform, rl.MatrixRotateY(180*rl.Deg2rad))
|
||||
transform = rl.MatrixMultiply(transform, rl.MatrixRotateX(-90*rl.Deg2rad))
|
||||
transform = rl.MatrixMultiply(transform, rl.MatrixScale(1.0, 1.0, 1.0))
|
||||
goonerModel.Transform = transform
|
||||
|
||||
// Coomer model (ready for animations)
|
||||
coomerModel := rl.LoadModel("resources/models/coomer.obj")
|
||||
coomerTexture := rl.LoadTexture("resources/models/coomer.png")
|
||||
rl.SetMaterialTexture(coomerModel.Materials, rl.MapDiffuse, coomerTexture)
|
||||
// When you have animations, add them like:
|
||||
// coomerAnims, _ := loadModelAnimations("resources/models/coomer.glb",
|
||||
// map[string]string{
|
||||
// "idle": "resources/models/coomer_idle.glb",
|
||||
// "walk": "resources/models/coomer_walk.glb",
|
||||
// })
|
||||
|
||||
// Shreke model (ready for animations)
|
||||
shrekeModel := rl.LoadModel("resources/models/shreke.obj")
|
||||
shrekeTexture := rl.LoadTexture("resources/models/shreke.png")
|
||||
rl.SetMaterialTexture(shrekeModel.Materials, rl.MapDiffuse, shrekeTexture)
|
||||
// When you have animations, add them like:
|
||||
// shrekeAnims, _ := loadModelAnimations("resources/models/shreke.glb",
|
||||
// map[string]string{
|
||||
// "idle": "resources/models/shreke_idle.glb",
|
||||
// "walk": "resources/models/shreke_walk.glb",
|
||||
// })
|
||||
|
||||
return []types.ModelAsset{
|
||||
{Model: goonerModel, Texture: goonerTexture},
|
||||
{
|
||||
Model: goonerModel,
|
||||
Animation: append(goonerAnims.Idle, goonerAnims.Walk...), // For compatibility
|
||||
AnimFrames: int32(len(goonerAnims.Idle) + len(goonerAnims.Walk)),
|
||||
Animations: goonerAnims,
|
||||
},
|
||||
{Model: coomerModel, Texture: coomerTexture},
|
||||
{Model: shrekeModel, Texture: shrekeTexture},
|
||||
}, nil
|
||||
@ -31,6 +84,11 @@ func LoadMusic(filename string) (rl.Music, error) {
|
||||
|
||||
func UnloadModels(models []types.ModelAsset) {
|
||||
for _, model := range models {
|
||||
if model.Animation != nil {
|
||||
for i := int32(0); i < model.AnimFrames; i++ {
|
||||
rl.UnloadModelAnimation(model.Animation[i])
|
||||
}
|
||||
}
|
||||
rl.UnloadModel(model.Model)
|
||||
rl.UnloadTexture(model.Texture)
|
||||
}
|
||||
|
Reference in New Issue
Block a user