Skip to content

Commit 4de7e93

Browse files
committed
add pvr export support
1 parent fba0405 commit 4de7e93

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

UnityAsset.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,11 @@ function __construct($preloadData, $readSwitch) {
781781
$this->transcodeFormat = 'bmp';
782782
$this->bitDepth = 16;
783783
break;
784+
case TextureFormat::PVRTC_RGB4:
785+
$this->outputMethod = 'pvr';
786+
$this->transcodeFormat = 'bmp';
787+
// use PVRTexToolCLI
788+
break;
784789
default:
785790
throw new Exception('not implemented: '.$this->textureFormat.' '.$this->textureFormatStr);
786791
}
@@ -837,8 +842,34 @@ function exportTo($saveTo, $format = 'png', $extraEncodeParam = '') {
837842
file_put_contents('output.bmp', $bmp->readData($bmp->size));
838843
unset($bmp);
839844
$transcodeFile = 'output.bmp';
845+
} else if ($this->outputMethod == 'pvr') {
846+
/*fclose(fopen('output.pvr','wb'));
847+
$pvr = new FileStream('output.pvr');
848+
$pvr->write(hex2bin('5056520300000000'));
849+
$pvr->write(pack('P', [
850+
TextureFormat::PVRTC_RGB2 => 0,
851+
TextureFormat::PVRTC_RGB4 => 2,
852+
TextureFormat::PVRTC_RGBA2 => 1,
853+
TextureFormat::PVRTC_RGBA4 => 3,
854+
][$this->textureFormat]));
855+
$pvr->write(hex2bin('0000000000000000'));
856+
$pvr->write(pack('V', $this->height));
857+
$pvr->write(pack('V', $this->width));
858+
$pvr->write(hex2bin('0100000001000000010000000100000000000000'));
859+
$pvr->write($this->imageData);
860+
unset($pvr);*/
861+
file_put_contents('output.pvr', $this->imageData);
862+
exec('pvr-decompress output.pvr output.bmp '.implode(' ', [$this->width, $this->height, [
863+
TextureFormat::PVRTC_RGB2 => 1,
864+
TextureFormat::PVRTC_RGB4 => 0,
865+
TextureFormat::PVRTC_RGBA2 => 1,
866+
TextureFormat::PVRTC_RGBA4 => 0,
867+
][$this->textureFormat]]));
868+
unlink('output.pvr');
869+
$transcodeFile = 'output.bmp';
870+
//throw new Exception('wip');
840871
} else {
841-
throw new Excpetion('not supported');
872+
throw new Exception('not supported');
842873
}
843874

844875
if ($this->transcodeFormat != $format) {

0 commit comments

Comments
 (0)