- Added support for uploading and compressing GLB models using Draco in the backoffice. - Implemented commands for importing and re-compressing 3D models. - Updated model resource to handle 3D model uploads and validations. - Introduced a new script for compressing GLB files with Draco. - Modified Vite configuration to remove GLB files from the build output. - Updated package dependencies to include GLTF-transform libraries for handling 3D models. - Added tests to ensure proper functionality of 3D model handling and compression.
38 lines
1.3 KiB
PHP
38 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Support\Configuratore;
|
|
|
|
use Illuminate\Support\Facades\Process;
|
|
use Illuminate\Support\Str;
|
|
use Throwable;
|
|
|
|
/**
|
|
* Comprime un .glb con Draco tramite lo script Node scripts/comprimi-glb.mjs (stesse opzioni
|
|
* di quantizzazione usate prima in build dal configuratore).
|
|
*/
|
|
class CompressoreGlb
|
|
{
|
|
public function comprimi(string $sorgente, string $destinazione): void
|
|
{
|
|
$config = config('configuratore.modelli_3d');
|
|
|
|
if (! is_file($config['script'])) {
|
|
throw new Modello3dNonValido("Script di compressione non trovato: {$config['script']}.");
|
|
}
|
|
|
|
try {
|
|
$risultato = Process::timeout($config['timeout'])
|
|
->run([$config['node'], $config['script'], $sorgente, $destinazione]);
|
|
} catch (Throwable $e) {
|
|
// Es. Node non trovato (NODE_BINARY) o timeout.
|
|
throw new Modello3dNonValido('Compressione Draco non avviata: '.$e->getMessage(), previous: $e);
|
|
}
|
|
|
|
if ($risultato->failed() || ! is_file($destinazione) || filesize($destinazione) === 0) {
|
|
$errore = trim($risultato->errorOutput()) ?: trim($risultato->output());
|
|
|
|
throw new Modello3dNonValido('Compressione Draco non riuscita: '.(Str::limit($errore, 300) ?: 'errore sconosciuto').'.');
|
|
}
|
|
}
|
|
}
|