goonscape/assets/assets.go

100 lines
3.4 KiB
Go
Raw Normal View History

2025-01-13 11:10:48 +01:00
package assets
import (
"gitea.boner.be/bdnugget/goonscape/types"
rl "github.com/gen2brain/raylib-go/raylib"
)
2025-01-20 14:30:34 +01:00
// 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
}
2025-01-13 11:10:48 +01:00
func LoadModels() ([]types.ModelAsset, error) {
2025-01-20 14:30:34 +01:00
// Goonion model and animations
goonerModel := rl.LoadModel("resources/models/gooner/walk_no_y_transform.glb")
goonerAnims, _ := loadModelAnimations(map[string]string{"idle": "resources/models/gooner/idle_no_y_transform.glb", "walk": "resources/models/gooner/walk_no_y_transform.glb"})
2025-01-20 14:30:34 +01:00
// 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
2025-01-13 11:10:48 +01:00
2025-01-20 14:30:34 +01:00
// Coomer model (ready for animations)
2025-01-13 11:10:48 +01:00
coomerModel := rl.LoadModel("resources/models/coomer.obj")
coomerTexture := rl.LoadTexture("resources/models/coomer.png")
rl.SetMaterialTexture(coomerModel.Materials, rl.MapDiffuse, coomerTexture)
2025-01-20 14:30:34 +01:00
// 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",
// })
2025-01-13 11:10:48 +01:00
2025-01-20 14:30:34 +01:00
// Shreke model (ready for animations)
2025-01-13 11:10:48 +01:00
shrekeModel := rl.LoadModel("resources/models/shreke.obj")
shrekeTexture := rl.LoadTexture("resources/models/shreke.png")
rl.SetMaterialTexture(shrekeModel.Materials, rl.MapDiffuse, shrekeTexture)
2025-01-20 14:30:34 +01:00
// 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",
// })
2025-01-13 11:10:48 +01:00
return []types.ModelAsset{
2025-01-20 14:30:34 +01:00
{
Model: goonerModel,
Animation: append(goonerAnims.Idle, goonerAnims.Walk...), // For compatibility
AnimFrames: int32(len(goonerAnims.Idle) + len(goonerAnims.Walk)),
Animations: goonerAnims,
},
2025-01-13 11:10:48 +01:00
{Model: coomerModel, Texture: coomerTexture},
{Model: shrekeModel, Texture: shrekeTexture},
}, nil
}
func LoadMusic(filename string) (rl.Music, error) {
return rl.LoadMusicStream(filename), nil
}
func UnloadModels(models []types.ModelAsset) {
for _, model := range models {
2025-01-20 14:30:34 +01:00
if model.Animation != nil {
for i := int32(0); i < model.AnimFrames; i++ {
rl.UnloadModelAnimation(model.Animation[i])
}
}
2025-01-13 11:10:48 +01:00
rl.UnloadModel(model.Model)
rl.UnloadTexture(model.Texture)
}
}
func UnloadMusic(music rl.Music) {
rl.UnloadMusicStream(music)
}