blockyserver/internal/render/png.go
devilreef fcc495c06f feat: add autoZoom param to GIF/MP4 renderers
Adjusts camera distance multiplier from 1.5 to 1.25 when enabled,
reducing empty space around character while leaving room for cosmetics.
2026-01-23 01:51:07 +06:00

38 lines
952 B
Go

package render
import (
"bytes"
"fmt"
"image/png"
"github.com/hytale-tools/blockymodel-merger/pkg/texture"
)
// RenderPNG renders a GLB model to PNG with the given parameters
func RenderPNG(glbBytes []byte, atlas *texture.Atlas, rotation float64, background string, width, height int, autoZoom bool) ([]byte, error) {
// Parse background color
bgColor, err := ParseHexColor(background)
if err != nil {
return nil, fmt.Errorf("invalid background color: %w", err)
}
// Get atlas image
var atlasImage = atlas.Image
// Convert GLB to mesh
mesh, err := GLBToMesh(glbBytes, atlasImage)
if err != nil {
return nil, fmt.Errorf("converting GLB to mesh: %w", err)
}
// Render the scene
img := RenderScene(mesh, atlasImage, rotation, width, height, bgColor, autoZoom)
// Encode to PNG
var buf bytes.Buffer
if err := png.Encode(&buf, img); err != nil {
return nil, fmt.Errorf("encoding PNG: %w", err)
}
return buf.Bytes(), nil
}