|
@ -107,8 +107,31 @@ class MatHelper{ |
|
|
$textureHandle = fopen($textureSavaPath, "w"); |
|
|
$textureHandle = fopen($textureSavaPath, "w"); |
|
|
(new Client())->get($textureUrl, [RequestOptions::SINK => $textureHandle]); |
|
|
(new Client())->get($textureUrl, [RequestOptions::SINK => $textureHandle]); |
|
|
|
|
|
|
|
|
|
|
|
// 因为 LuxCore 使用 opengl 规范的法线纹理格式,与 babylon 使用的 DirectX 不同,
|
|
|
|
|
|
// 所以这里需要反转 G 通道色值,以保证法线纹理应用效果与 babylon 一致。
|
|
|
|
|
|
$fileName = preg_replace('/(\.[^\.]+)$/','',basename($textureSavaPath)); |
|
|
|
|
|
$suffixName = preg_replace('/^('.$fileName.')+/','',basename($textureSavaPath)); |
|
|
|
|
|
$textureInvertGPath = $downloadDir.$fileName.'_InvertG'.$suffixName; |
|
|
|
|
|
$imagick = new \Imagick($textureSavaPath); |
|
|
|
|
|
$imageIterator = $imagick->getPixelIterator(); |
|
|
|
|
|
foreach ($imageIterator as $row => $pixels) { |
|
|
|
|
|
foreach ($pixels as $column => $pixel) { |
|
|
|
|
|
// 获取每个像素色值;
|
|
|
|
|
|
$value = $pixel->getColor(); |
|
|
|
|
|
// 反相绿色通道色值;
|
|
|
|
|
|
$r = $value["r"]; |
|
|
|
|
|
$g = abs(($value["g"] - 255)); |
|
|
|
|
|
$b = $value["b"]; |
|
|
|
|
|
$a = $value["a"]; |
|
|
|
|
|
$pixel->setColor("rgba({$r}, {$g}, {$b}, {$a})"); |
|
|
|
|
|
} |
|
|
|
|
|
$imageIterator->syncIterator(); |
|
|
|
|
|
} |
|
|
|
|
|
$imagick->writeImage($textureInvertGPath); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$bumpTexture = new ImageMap( |
|
|
$bumpTexture = new ImageMap( |
|
|
['file' => $textureSavaPath] |
|
|
|
|
|
|
|
|
['file' => $textureInvertGPath] |
|
|
); |
|
|
); |
|
|
$bumpTexture->gamma = 1; |
|
|
$bumpTexture->gamma = 1; |
|
|
$bumpTexture->mapping = $mapping; |
|
|
$bumpTexture->mapping = $mapping; |
|
|