|
|
@ -319,6 +319,50 @@ class MatHelper{ |
|
|
|
$material->setVroughness($roughnessTexture); |
|
|
|
} |
|
|
|
|
|
|
|
// 加载法线纹理
|
|
|
|
if($matOriginal->matParams->bumpTexture){ |
|
|
|
$textureUrl = $matOriginal->matParams->bumpTexture; |
|
|
|
$textureSavaPath = $cacheFileDir.'/'.basename($textureUrl); |
|
|
|
$textureSavaHandle = fopen($textureSavaPath, "w"); |
|
|
|
(new Client())->get($textureUrl, [RequestOptions::SINK => $textureSavaHandle]); |
|
|
|
|
|
|
|
// 因为 LuxCore 使用 opengl 规范的法线纹理格式,与 babylon 使用的 DirectX 不同,
|
|
|
|
// 所以这里需要反转 G 通道色值,以保证法线纹理应用效果与 babylon 一致。
|
|
|
|
$fileName = preg_replace('/(\.[^\.]+)$/','',basename($textureSavaPath)); |
|
|
|
$extension = preg_replace('/^('.$fileName.')+/','',basename($textureSavaPath)); |
|
|
|
$textureInvertSavaGPath = $cacheFileDir.'/'.$fileName.'_InvertG'.$extension; |
|
|
|
$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->setImageCompressionQuality(100); |
|
|
|
$imagick->writeImage($textureInvertSavaGPath); |
|
|
|
|
|
|
|
$bumpTexture = new ImageMap( |
|
|
|
['file' => $textureInvertSavaGPath] |
|
|
|
); |
|
|
|
$bumpTexture->gamma = 1; |
|
|
|
$bumpTexture->mapping = $mapping; |
|
|
|
$scene->registerTexture($bumpTexture); |
|
|
|
|
|
|
|
$normalTexture = new NormalMap(); |
|
|
|
$normalTexture->setTexture($bumpTexture); |
|
|
|
$normalTexture->scale = $matOriginal->matParams->bumpLevel; |
|
|
|
$scene->registerTexture($normalTexture); |
|
|
|
$material->setBumptex($normalTexture); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $material; |
|
|
|
} |
|
|
@ -443,6 +487,50 @@ class MatHelper{ |
|
|
|
$material->setVroughness($roughnessTexture); |
|
|
|
} |
|
|
|
|
|
|
|
// 加载法线纹理
|
|
|
|
if($matOriginal->matParams->bumpTexture){ |
|
|
|
$textureUrl = $matOriginal->matParams->bumpTexture; |
|
|
|
$textureSavaPath = $cacheFileDir.'/'.basename($textureUrl); |
|
|
|
$textureSavaHandle = fopen($textureSavaPath, "w"); |
|
|
|
(new Client())->get($textureUrl, [RequestOptions::SINK => $textureSavaHandle]); |
|
|
|
|
|
|
|
// 因为 LuxCore 使用 opengl 规范的法线纹理格式,与 babylon 使用的 DirectX 不同,
|
|
|
|
// 所以这里需要反转 G 通道色值,以保证法线纹理应用效果与 babylon 一致。
|
|
|
|
$fileName = preg_replace('/(\.[^\.]+)$/','',basename($textureSavaPath)); |
|
|
|
$extension = preg_replace('/^('.$fileName.')+/','',basename($textureSavaPath)); |
|
|
|
$textureInvertSavaGPath = $cacheFileDir.'/'.$fileName.'_InvertG'.$extension; |
|
|
|
$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->setImageCompressionQuality(100); |
|
|
|
$imagick->writeImage($textureInvertSavaGPath); |
|
|
|
|
|
|
|
$bumpTexture = new ImageMap( |
|
|
|
['file' => $textureInvertSavaGPath] |
|
|
|
); |
|
|
|
$bumpTexture->gamma = 1; |
|
|
|
$bumpTexture->mapping = $mapping; |
|
|
|
$scene->registerTexture($bumpTexture); |
|
|
|
|
|
|
|
$normalTexture = new NormalMap(); |
|
|
|
$normalTexture->setTexture($bumpTexture); |
|
|
|
$normalTexture->scale = $matOriginal->matParams->bumpLevel; |
|
|
|
$scene->registerTexture($normalTexture); |
|
|
|
$material->setBumptex($normalTexture); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $material; |
|
|
|
} |
|
|
|