From 258972eba99fd9226383a78e93c3db56b393f8c4 Mon Sep 17 00:00:00 2001 From: yuanjiajia <1139393632@qq.com> Date: Wed, 19 Jul 2023 17:59:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=B2=E6=9F=93=E6=B5=8B=E5=BC=8F=20?= =?UTF-8?q?=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 | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/utils/MatHelper.php b/src/utils/MatHelper.php index 753cf1d..8fb9268 100644 --- a/src/utils/MatHelper.php +++ b/src/utils/MatHelper.php @@ -19,6 +19,8 @@ class MatHelper{ const OPEN = 1 | true; const CLOSE = 0 | false; + const COLOR_SPACE_SRGB = 2.2; + const COLOR_SPACE_NO = 1; @@ -26,12 +28,16 @@ class MatHelper{ /** * 十六进制颜色 转换为 浮点数颜色 */ - static function hex2floatColor($hexColor, $scale = 1, $gamma = 2.2){ + static function hex2floatColor($hexColor, $scale = 1, $gamma = self::COLOR_SPACE_SRGB){ + // 十六进制颜色 转 RGB色 + $color = Factory::fromString(trim($hexColor)); + $color = $color->toRgb(); + + // RGB色 转 浮点数RGB颜色 $floatColor = ''; - $hexColor = trim($hexColor); - $r = (hexdec(substr($hexColor, 1, 2))/255 * $scale) ** $gamma; - $g = (hexdec(substr($hexColor, 3, 2))/255 * $scale) ** $gamma; - $b = (hexdec(substr($hexColor, 5, 2))/255 * $scale) ** $gamma; + $r = ($color->red() / 255 * $scale) ** $gamma; + $g = ($color->green() / 255 * $scale) ** $gamma; + $b = ($color->blue() / 255 * $scale) ** $gamma; $floatColor = "$r $g $b"; return $floatColor; } @@ -39,7 +45,7 @@ class MatHelper{ /** * 获得 十六进制颜色 同色调 的 最大亮度 */ - static function colorMaxBrightness($hexColor,$scale){ + static function colorMaxBrightness($hexColor,$scale = 1){ // 十六进制颜色 转 HSB色 $color = Factory::fromString($hexColor); $color = $color->toHsb(); @@ -427,7 +433,10 @@ class MatHelper{ $matOriginal->matParams->translucencyColor )); $material->setBaseColor( self::hex2floatColor( - self::colorMaxBrightness($matOriginal->matParams->translucencyColor, $translucencyIntensity), + self::colorMaxBrightness( + $matOriginal->matParams->translucencyColor, + $translucencyIntensity ** (1/2.2) + ), 1 - $translucencyIntensity )); // $material->setSpecular(