47 lines
937 B
Go
47 lines
937 B
Go
package thumbnail
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/sotigr/slic3r-api/internal/cli"
|
|
)
|
|
|
|
// ThumbnailService generates preview images of 3D model files.
|
|
type ThumbnailService interface {
|
|
Generate(ctx context.Context, modelPath, outputPath string) error
|
|
}
|
|
|
|
type f3dService struct{}
|
|
|
|
// NewThumbnailService creates a ThumbnailService backed by the f3d renderer.
|
|
func NewThumbnailService() ThumbnailService {
|
|
return &f3dService{}
|
|
}
|
|
|
|
func (s *f3dService) Generate(ctx context.Context, modelPath, outputPath string) error {
|
|
pipe := cli.Pipe{
|
|
Command: "f3d",
|
|
Args: []string{
|
|
modelPath,
|
|
"--resolution=128,128",
|
|
"-a",
|
|
"--anti-aliasing-mode=taa",
|
|
"--filename=false",
|
|
"--metadata=false",
|
|
"--color=#999",
|
|
"-t",
|
|
"--grid=false",
|
|
"--axis=false",
|
|
"--no-background",
|
|
"--output=" + outputPath,
|
|
},
|
|
}
|
|
|
|
_, _, err := pipe.Execute(ctx)
|
|
if err != nil {
|
|
return fmt.Errorf("f3d: %w", err)
|
|
}
|
|
return nil
|
|
}
|