Skip to content

Commit 518f39e

Browse files
committed
redo texture2d read
1 parent 2889477 commit 518f39e

File tree

1 file changed

+14
-54
lines changed

1 file changed

+14
-54
lines changed

UnityAsset.php

+14-54
Original file line numberDiff line numberDiff line change
@@ -678,62 +678,22 @@ function __construct($preloadData, $readSwitch) {
678678
throw new Exception('no support');
679679
}
680680

681-
$this->name = $stream->readAlignedString($stream->long);
682-
if ($sourceFile->version[0] > 2017 || ($sourceFile->version[0] == 2017 && $sourceFile->version[1] >= 3)) {
683-
$stream->ulong;
684-
$stream->byte;
685-
$stream->alignStream(4);
686-
}
687-
$this->width = $stream->long;
688-
$this->height = $stream->long;
689-
$this->completeImageSize = $stream->long;
690-
$this->textureFormat = $stream->long;
691-
692-
if ($sourceFile->version[0] <5 || ($sourceFile->version[0] == 5 && $sourceFile->version[1] < 2)) {
693-
$this->mipMap = $stream->bool;
694-
} else {
695-
$this->dwFlags += 0x20000;
696-
$this->dwMipMapCount = $stream->long;
697-
$this->dwCaps += 0x400008;
698-
}
699-
$this->isReadable = $stream->bool;
700-
$this->readAllowed = $stream->bool;
701-
$stream->alignStream(4);
702-
if ($sourceFile->version[0] > 2018 || ($sourceFile->version[0] == 2018 && $sourceFile->version[1] >= 2)) {
703-
$this->streamingMipmapsPriority = $stream->long;
704-
}
705-
$this->imageCount = $stream->long;
706-
$this->textureDimension = $stream->long;
707-
$this->filterMode = $stream->long;
708-
$this->aniso = $stream->long;
709-
$this->MipBias = $stream->float;
710-
$this->wrapMode = $stream->long;
711-
712-
if ($sourceFile->version[0] >= 2017) {
713-
$stream->ulong;
714-
$stream->ulong;
715-
}
716-
if ($sourceFile->version[0] >= 3) {
717-
$this->lightmapFormat = $stream->long;
718-
if ($sourceFile->version[0] >=4 || $sourceFile->version[1] >= 5) {
719-
$this->colorSpace = $stream->long;
720-
}
721-
}
722-
$this->imageDataSize = $stream->long;
723-
if ($this->mipMap) {
724-
$this->dwFlags += 0x20000;
725-
//$this->dwMipMapCount = Convert.ToInt32(Math.Log((double)Math.Max(this.m_Width, this.m_Height)) / Math.Log(2.0));
726-
$this->dwMipMapCount = log(max($this->width, $this->height)) / log(2.0);
727-
$this->dwCaps += 0x400008;
728-
}
729-
730-
if ($this->imageDataSize == 0 && (($sourceFile->version[0] == 5 && $sourceFile->version[1] >= 3) || $sourceFile->version[0] > 5)) {
731-
$this->offset = $stream->ulong;
732-
$this->size = $stream->ulong;
681+
$struct = ClassStructHelper::OrganizeStruct(ClassStructHelper::DeserializeStruct($stream, $preloadData->sourceFile->ClassStructures[28]['members']));
682+
$this->name = $struct['m_Name'];
683+
$this->width = $struct['m_Width'];
684+
$this->height = $struct['m_Height'];
685+
$this->completeImageSize = $struct['m_CompleteImageSize'];
686+
$this->textureFormat = $struct['m_TextureFormat'];
687+
$this->imageCount = $struct['m_ImageCount'];
688+
$this->textureDimension = $struct['m_TextureDimension'];
689+
$this->imageData = $struct['image data'];
690+
$this->imageDataSize = strlen($this->imageData);
691+
if (isset($struct['m_StreamData'])) {
692+
$this->offset = $struct['m_StreamData']['offset'];
693+
$this->size = $struct['m_StreamData']['size'];
733694
$this->imageDataSize = $this->size;
734-
$this->path = $stream->readAlignedString($stream->long);
695+
$this->path = $struct['m_StreamData']['path'];
735696
}
736-
737697
$this->textureFormatStr = TextureFormat::map[$this->textureFormat];
738698

739699
if ($readSwitch) {

0 commit comments

Comments
 (0)