|
|
@ -4,6 +4,7 @@ namespace Blobt\Luxcore\utils; |
|
|
|
|
|
|
|
use Blobt\Luxcore\scene\materials\Disney; |
|
|
|
use Blobt\Luxcore\scene\materials\GlassRough; |
|
|
|
use Blobt\Luxcore\scene\materials\GlossyTranslucent; |
|
|
|
use Blobt\Luxcore\scene\texture\composite\Subtract; |
|
|
|
use Blobt\Luxcore\scene\texture\mapping\Mapping; |
|
|
|
use Blobt\Luxcore\scene\texture\procedural\ImageMap; |
|
|
@ -305,8 +306,75 @@ class MatHelper{ |
|
|
|
/** |
|
|
|
* 创建一个半透明材质 |
|
|
|
*/ |
|
|
|
static function createMatOfTranslucent(){ |
|
|
|
static function createMatOfTranslucent($matOriginal, $textureScaleU, $textureScaleV, $cacheFileDir, $scene){ |
|
|
|
$material = new GlossyTranslucent(); |
|
|
|
$material->setTransmission( |
|
|
|
self::hex2floatColor($matOriginal->matParams->translucencyColor), |
|
|
|
$matOriginal->matParams->translucencyIntensity |
|
|
|
); |
|
|
|
$material->setBaseColor( |
|
|
|
self::hex2floatColor($matOriginal->matParams->translucencyColor), |
|
|
|
1 - $matOriginal->matParams->translucencyIntensity |
|
|
|
); |
|
|
|
$material->setUroughness($matOriginal->matParams->roughness); |
|
|
|
$material->setVroughness($matOriginal->matParams->roughness); |
|
|
|
|
|
|
|
|
|
|
|
//创建一个铺贴对象,使用"uvmapping2d"类型的铺贴对象
|
|
|
|
$mapping = new Mapping(); |
|
|
|
$mapping->useUVMapping2d( |
|
|
|
// uv通道
|
|
|
|
0, |
|
|
|
// 旋转角度
|
|
|
|
"0", |
|
|
|
// 缩放比例
|
|
|
|
"{$textureScaleU} {$textureScaleV}", |
|
|
|
// 偏移量
|
|
|
|
"0 0", |
|
|
|
); |
|
|
|
|
|
|
|
// // 加载 透射 纹理
|
|
|
|
// if($matOriginal->matParams->translucencyTexture){
|
|
|
|
// $textureUrl = $matOriginal->matParams->translucencyTexture;
|
|
|
|
// $textureSavaPath = $cacheFileDir.'/'.basename($textureUrl);
|
|
|
|
// $textureHandle = fopen($textureSavaPath, "w");
|
|
|
|
// (new Client())->get($textureUrl, [RequestOptions::SINK => $textureHandle]);
|
|
|
|
|
|
|
|
// $imageMap = new ImageMap(
|
|
|
|
// ['file' => $textureSavaPath]
|
|
|
|
// );
|
|
|
|
// $imageMap->mapping = $mapping;
|
|
|
|
// $scene->registerTexture($imageMap);
|
|
|
|
// $material->setTransmission($imageMap);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// 加载金属度纹理、粗糙度纹理
|
|
|
|
if($matOriginal->matParams->metallicTexture){ |
|
|
|
$metallicTextureUrl = $matOriginal->matParams->metallicTexture; |
|
|
|
$metallicTextureSavaPath = $cacheFileDir.'/'.basename($metallicTextureUrl); |
|
|
|
$metallicTextureHandle = fopen($metallicTextureSavaPath, "w"); |
|
|
|
(new Client())->get($metallicTextureUrl, [RequestOptions::SINK => $metallicTextureHandle]); |
|
|
|
|
|
|
|
$fileName = preg_replace('/(\.[^\.]+)$/','',basename($metallicTextureSavaPath)); |
|
|
|
$extension = preg_replace('/^('.$fileName.')+/','',basename($metallicTextureSavaPath)); |
|
|
|
// 从金属纹理中 分离 绿色通道 作为 粗糙度纹理
|
|
|
|
$roughnessTextureSavaPath = $cacheFileDir.'/'.$fileName.'_roughness'.$extension; |
|
|
|
$imagick = new Imagick($metallicTextureSavaPath); |
|
|
|
$imagick->separateImageChannel(Imagick::CHANNEL_GREEN); |
|
|
|
$imagick->setImageCompressionQuality(100); |
|
|
|
$imagick->writeImage($roughnessTextureSavaPath); |
|
|
|
$roughnessTexture = new ImageMap( |
|
|
|
['file' => $roughnessTextureSavaPath] |
|
|
|
); |
|
|
|
$roughnessTexture->gamma = 1; |
|
|
|
$roughnessTexture->mapping = $mapping; |
|
|
|
$scene->registerTexture($roughnessTexture); |
|
|
|
$material->setUroughness($roughnessTexture); |
|
|
|
$material->setVroughness($roughnessTexture); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $material; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -321,12 +389,12 @@ class MatHelper{ |
|
|
|
/** |
|
|
|
* 十六进制颜色 转换为 浮点数颜色 |
|
|
|
*/ |
|
|
|
static function hex2floatColor($hexColor){ |
|
|
|
static function hex2floatColor($hexColor, $scale = 1){ |
|
|
|
$floatColor = ''; |
|
|
|
$hexColor = trim($hexColor); |
|
|
|
$r = (hexdec(substr($hexColor, 1, 2))/255) ** 2.2; |
|
|
|
$g = (hexdec(substr($hexColor, 3, 2))/255) ** 2.2; |
|
|
|
$b = (hexdec(substr($hexColor, 5, 2))/255) ** 2.2; |
|
|
|
$r = (hexdec(substr($hexColor, 1, 2))/255) ** 2.2 * $scale; |
|
|
|
$g = (hexdec(substr($hexColor, 3, 2))/255) ** 2.2 * $scale; |
|
|
|
$b = (hexdec(substr($hexColor, 5, 2))/255) ** 2.2 * $scale; |
|
|
|
$floatColor = "$r $g $b"; |
|
|
|
return $floatColor; |
|
|
|
} |
|
|
|