From 5bbf741cf03a08d676cb11b9a213522d0f48114a Mon Sep 17 00:00:00 2001 From: yuanjiajia <1139393632@qq.com> Date: Wed, 7 Jun 2023 15:47:06 +0800 Subject: [PATCH] =?UTF-8?q?=20=E6=B8=B2=E6=9F=93=E6=B5=8B=E5=BC=8F=20?= =?UTF-8?q?=E6=A1=88=E4=BE=8B=20=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/MatHelper.php | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/utils/MatHelper.php b/src/utils/MatHelper.php index c6fae71..9b73b02 100644 --- a/src/utils/MatHelper.php +++ b/src/utils/MatHelper.php @@ -69,13 +69,16 @@ class MatHelper{ $material->setBaseColor($albedoTexture); } if($matOriginal->matParams->metallicTexture){ - $textureUrl = $matOriginal->matParams->metallicTexture; - $textureSavaPath = $downloadDir.basename($textureUrl); - $textureHandle = fopen($textureSavaPath, "w"); - (new Client())->get($textureUrl, [RequestOptions::SINK => $textureHandle]); - - $metalnessTextureSavaPath = $downloadDir.'metalness_'.basename($textureUrl); - $metalnessTexture = new Imagick($textureSavaPath); + $metallicTextureUrl = $matOriginal->matParams->metallicTexture; + $metallicTextureSavaPath = $downloadDir.basename($metallicTextureUrl); + $metallicTextureHandle = fopen($metallicTextureSavaPath, "w"); + (new Client())->get($metallicTextureUrl, [RequestOptions::SINK => $metallicTextureHandle]); + + $fileName = preg_replace('/(\.[^\.]+)$/','',basename($metallicTextureUrl)); + $suffixName = preg_replace('/^('.$fileName.')+/','',basename($metallicTextureUrl)); + // 从金属纹理中 分离 蓝色通道 作为 金属度纹理 + $metalnessTextureSavaPath = $downloadDir.$fileName.'_metalness'.$suffixName; + $metalnessTexture = new Imagick($metallicTextureSavaPath); $metalnessTexture->separateImageChannel(Imagick::CHANNEL_BLUE); $metalnessTexture->writeImage($metalnessTextureSavaPath); $metalnessTexture = new ImageMap( @@ -84,10 +87,10 @@ class MatHelper{ $metalnessTexture->mapping = $mapping; $scene->registerTexture($metalnessTexture); $material->setMetallic($metalnessTexture); - - $roughnessTextureSavaPath = $downloadDir.'roughness'.basename($textureUrl); - $roughnessTexture = new Imagick($textureSavaPath); - $roughnessTexture->separateImageChannel(Imagick::CHANNEL_BLUE); + // 从金属纹理中 分离 绿色通道 作为 粗糙度纹理 + $roughnessTextureSavaPath = $downloadDir.$fileName.'_roughness'.$suffixName; + $roughnessTexture = new Imagick($metallicTextureSavaPath); + $roughnessTexture->separateImageChannel(Imagick::CHANNEL_GREEN); $roughnessTexture->writeImage($roughnessTextureSavaPath); $roughnessTexture = new ImageMap( ['file' => $roughnessTextureSavaPath]