Browse Source

渲染测式 开发

master
yuanjiajia 1 year ago
parent
commit
f109caee76
  1. 55
      src/utils/MatHelper.php

55
src/utils/MatHelper.php

@ -3,6 +3,7 @@
namespace Blobt\Luxcore\utils; namespace Blobt\Luxcore\utils;
use Blobt\Luxcore\scene\materials\Disney; use Blobt\Luxcore\scene\materials\Disney;
use Blobt\Luxcore\scene\texture\composite\Subtract;
use Blobt\Luxcore\scene\texture\mapping\Mapping; use Blobt\Luxcore\scene\texture\mapping\Mapping;
use Blobt\Luxcore\scene\texture\procedural\ImageMap; use Blobt\Luxcore\scene\texture\procedural\ImageMap;
use Blobt\Luxcore\scene\texture\transform\NormalMap; use Blobt\Luxcore\scene\texture\transform\NormalMap;
@ -41,20 +42,20 @@ class MatHelper{
} }
// 创建一个铺贴对象
//创建一个铺贴对象,使用"uvmapping2d"类型的铺贴对象
$mapping = new Mapping(); $mapping = new Mapping();
// 使用"uvmapping2d"类型的铺贴对象
$mapping->useUVMapping2d( $mapping->useUVMapping2d(
// uv通道 // uv通道
0, 0,
// 旋转角度 // 旋转角度
"0", "0",
// 缩放比例 // 缩放比例
"$textureScaleU $textureScaleV",
"{$textureScaleU} {$textureScaleV}",
// 偏移量 // 偏移量
"0 0", "0 0",
); );
// 加载反照率(基础颜色)纹理
if($matOriginal->matParams->albedoTexture){ if($matOriginal->matParams->albedoTexture){
$textureUrl = $matOriginal->matParams->albedoTexture; $textureUrl = $matOriginal->matParams->albedoTexture;
$textureSavaPath = $cacheFileDir.'/'.basename($textureUrl); $textureSavaPath = $cacheFileDir.'/'.basename($textureUrl);
@ -68,6 +69,8 @@ class MatHelper{
$scene->registerTexture($albedoTexture); $scene->registerTexture($albedoTexture);
$material->setBaseColor($albedoTexture); $material->setBaseColor($albedoTexture);
} }
// 加载金属度纹理、粗糙度纹理
if($matOriginal->matParams->metallicTexture){ if($matOriginal->matParams->metallicTexture){
$metallicTextureUrl = $matOriginal->matParams->metallicTexture; $metallicTextureUrl = $matOriginal->matParams->metallicTexture;
$metallicTextureSavaPath = $cacheFileDir.'/'.basename($metallicTextureUrl); $metallicTextureSavaPath = $cacheFileDir.'/'.basename($metallicTextureUrl);
@ -103,6 +106,8 @@ class MatHelper{
$scene->registerTexture($roughnessTexture); $scene->registerTexture($roughnessTexture);
$material->setRoughness($roughnessTexture); $material->setRoughness($roughnessTexture);
} }
// 加载法线纹理
if($matOriginal->matParams->bumpTexture){ if($matOriginal->matParams->bumpTexture){
$textureUrl = $matOriginal->matParams->bumpTexture; $textureUrl = $matOriginal->matParams->bumpTexture;
$textureSavaPath = $cacheFileDir.'/'.basename($textureUrl); $textureSavaPath = $cacheFileDir.'/'.basename($textureUrl);
@ -132,7 +137,6 @@ class MatHelper{
$imagick->setImageCompressionQuality(100); $imagick->setImageCompressionQuality(100);
$imagick->writeImage($textureInvertGPath); $imagick->writeImage($textureInvertGPath);
$bumpTexture = new ImageMap( $bumpTexture = new ImageMap(
['file' => $textureInvertGPath] ['file' => $textureInvertGPath]
); );
@ -147,6 +151,49 @@ class MatHelper{
$material->setBumptex($normalTexture); $material->setBumptex($normalTexture);
} }
// 加载清漆涂层纹理
if($matOriginal->matParams->isClearCoatEnabled === self::OPEN && $matOriginal->matParams->clearCoatTexture){
$textureUrl = $matOriginal->matParams->clearCoatTexture;
$savaTexturePath = $cacheFileDir.'/'.basename($textureUrl);
$savaTextureHandle = fopen($savaTexturePath, "w");
(new Client())->get($textureUrl, [RequestOptions::SINK => $savaTextureHandle]);
$fileName = preg_replace('/(\.[^\.]+)$/','',basename($savaTexturePath));
$extension = preg_replace('/^('.$fileName.')+/','',basename($savaTexturePath));
// 从清漆涂层纹理中 分离 红色通道 作为 清漆涂层强度纹理
$coatIntensityTextureSavaPath = $cacheFileDir.'/'.$fileName.'_coatIntensity'.$extension;
$imagick = new Imagick($savaTexturePath);
$imagick->separateImageChannel(Imagick::CHANNEL_RED);
$imagick->setImageCompressionQuality(100);
$imagick->writeImage($coatIntensityTextureSavaPath);
$coatIntensityTexture = new ImageMap(
['file' => $coatIntensityTextureSavaPath]
);
$coatIntensityTexture->gamma = 1;
$coatIntensityTexture->mapping = $mapping;
$scene->registerTexture($coatIntensityTexture);
$material->setClearcoat($coatIntensityTexture);
// 从清漆涂层纹理中 分离 绿色通道 作为 清漆涂层光泽度纹理
$coatGlossTextureSavaPath = $cacheFileDir.'/'.$fileName.'_coatGloss'.$extension;
$imagick = new Imagick($savaTexturePath);
$imagick->separateImageChannel(Imagick::CHANNEL_GREEN);
$imagick->setImageCompressionQuality(100);
$imagick->writeImage($coatGlossTextureSavaPath);
$coatGlossTexture = new ImageMap(
['file' => $coatGlossTextureSavaPath]
);
$coatGlossTexture->gamma = 1;
$coatGlossTexture->mapping = $mapping;
$scene->registerTexture($coatGlossTexture);
$subtract = new Subtract();
$subtract->setTexture1("1");
$subtract-> setTexture2($coatGlossTexture);
$scene->registerTexture($subtract);
$material->setClearcoatgloss($subtract);
}
//TODO: 更多贴图通道处理,待后续完善 //TODO: 更多贴图通道处理,待后续完善
return $material; return $material;

Loading…
Cancel
Save