|
@ -2,16 +2,99 @@ |
|
|
|
|
|
|
|
|
namespace Blobt\Luxcore\utils; |
|
|
namespace Blobt\Luxcore\utils; |
|
|
|
|
|
|
|
|
|
|
|
use Blobt\Luxcore\scene\materials\Disney; |
|
|
|
|
|
use Blobt\Luxcore\scene\texture\mapping\Mapping; |
|
|
|
|
|
use Blobt\Luxcore\scene\texture\procedural\ImageMap; |
|
|
|
|
|
use Blobt\Luxcore\scene\texture\transform\NormalMap; |
|
|
|
|
|
|
|
|
|
|
|
class MatHelper{ |
|
|
|
|
|
|
|
|
|
|
|
const OPEN = 1 | true; |
|
|
|
|
|
const CLOSE = 0 | false; |
|
|
|
|
|
|
|
|
class MatHelper |
|
|
|
|
|
{ |
|
|
|
|
|
/** |
|
|
/** |
|
|
* 创建一个 Disney 的材质 |
|
|
* 创建一个 Disney 的材质 |
|
|
*/ |
|
|
*/ |
|
|
static function createMatOfDisney($matParams){ |
|
|
|
|
|
|
|
|
static function createMatOfDisney($matOriginal, $textureScaleU, $textureScaleV, $scene){ |
|
|
|
|
|
|
|
|
|
|
|
$material = new Disney(); |
|
|
|
|
|
$material->setBaseColor(self::hex2floatColor($matOriginal->matParams->albedoColor)); |
|
|
|
|
|
$material->setMetallic($matOriginal->matParams->metallic); |
|
|
|
|
|
$material->setRoughness($matOriginal->matParams->roughness); |
|
|
|
|
|
if($matOriginal->matParams->isClearCoatEnabled === self::OPEN){ |
|
|
|
|
|
$material->setClearcoat($matOriginal->matParams->clearCoat); |
|
|
|
|
|
$material->setClearcoatgloss(1 - $matOriginal->matParams->clearCoat); |
|
|
|
|
|
} |
|
|
|
|
|
if($matOriginal->matParams->isFilmEnabled === self::OPEN){ |
|
|
|
|
|
$material->setFilmamount($matOriginal->matParams->film); |
|
|
|
|
|
$material->setFilmthickness($matOriginal->matParams->filmthickness); |
|
|
|
|
|
$material->setFilmior($matOriginal->matParams->filmIor); |
|
|
|
|
|
} |
|
|
|
|
|
if($matOriginal->matParams->isSheenEnabled === self::OPEN){ |
|
|
|
|
|
$material->setSheen(($matOriginal->matParams->sheen)*100); |
|
|
|
|
|
} |
|
|
|
|
|
if($matOriginal->matParams->isAnisotropyEnabled === self::OPEN){ |
|
|
|
|
|
$material->setAnisotropic($matOriginal->matParams->anisotropy); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建一个铺贴对象
|
|
|
|
|
|
$mapping = new Mapping(); |
|
|
|
|
|
// 使用"uvmapping2d"类型的铺贴对象
|
|
|
|
|
|
$mapping->useUVMapping2d( |
|
|
|
|
|
// uv通道
|
|
|
|
|
|
0, |
|
|
|
|
|
// 旋转角度
|
|
|
|
|
|
"0", |
|
|
|
|
|
// 缩放比例
|
|
|
|
|
|
`$textureScaleU $textureScaleV`, |
|
|
|
|
|
// 偏移量
|
|
|
|
|
|
"0 0", |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if($matOriginal->matParams->albedoTexture){ |
|
|
|
|
|
$albedoTexture = new ImageMap( |
|
|
|
|
|
['file' => $matOriginal->matParams->albedoTexture] |
|
|
|
|
|
); |
|
|
|
|
|
$albedoTexture->mapping = $mapping; |
|
|
|
|
|
$scene->registerTexture($albedoTexture); |
|
|
|
|
|
$material->setBaseColor($albedoTexture); |
|
|
|
|
|
} |
|
|
|
|
|
if($matOriginal->matParams->metallicTexture){ |
|
|
|
|
|
$metallicTexture = new ImageMap( |
|
|
|
|
|
['file' => $matOriginal->matParams->metallicTexture] |
|
|
|
|
|
); |
|
|
|
|
|
$metallicTexture->mapping = $mapping; |
|
|
|
|
|
$scene->registerTexture($metallicTexture); |
|
|
|
|
|
$material->setMetallic($metallicTexture); |
|
|
|
|
|
|
|
|
|
|
|
$roughnessTexture = new ImageMap( |
|
|
|
|
|
['file' => $matOriginal->matParams->metallicTexture] |
|
|
|
|
|
); |
|
|
|
|
|
$roughnessTexture->mapping = $mapping; |
|
|
|
|
|
$scene->registerTexture($roughnessTexture); |
|
|
|
|
|
$material->setMetallic($roughnessTexture); |
|
|
|
|
|
} |
|
|
|
|
|
if($matOriginal->matParams->bumpTexture){ |
|
|
|
|
|
$bumpTexture = new ImageMap( |
|
|
|
|
|
['file' => $matOriginal->matParams->bumpTexture] |
|
|
|
|
|
); |
|
|
|
|
|
$bumpTexture->mapping = $mapping; |
|
|
|
|
|
$scene->registerTexture($bumpTexture); |
|
|
|
|
|
|
|
|
|
|
|
$normalTexture = new NormalMap(); |
|
|
|
|
|
$normalTexture->texture = $bumpTexture; |
|
|
|
|
|
$normalTexture->scale = $matOriginal->matParams->bumpLevel; |
|
|
|
|
|
$scene->registerTexture($normalTexture); |
|
|
|
|
|
$material->setBumptex($normalTexture); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//TODO: 更多通道贴图处理,待后续完善
|
|
|
|
|
|
|
|
|
|
|
|
return $material; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 创建一个 Glass 材质(折射材质) |
|
|
* 创建一个 Glass 材质(折射材质) |
|
|
*/ |
|
|
*/ |
|
@ -19,18 +102,35 @@ class MatHelper |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 创建一个半透明材质 |
|
|
* 创建一个半透明材质 |
|
|
*/ |
|
|
*/ |
|
|
static function createMatOfTranslucent(){ |
|
|
static function createMatOfTranslucent(){ |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 创建一个自发光材质 |
|
|
* 创建一个自发光材质 |
|
|
*/ |
|
|
*/ |
|
|
static function createMatOfEmission(){ |
|
|
static function createMatOfEmission(){ |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 十六进制颜色 转换为 浮点数颜色 |
|
|
|
|
|
*/ |
|
|
|
|
|
static function hex2floatColor($hexColor){ |
|
|
|
|
|
$floatColor = ''; |
|
|
|
|
|
$hexColor = trim($hexColor); |
|
|
|
|
|
$r = hexdec(substr($hexColor, 1, 2))/256; |
|
|
|
|
|
$g = hexdec(substr($hexColor, 3, 2))/256; |
|
|
|
|
|
$b = hexdec(substr($hexColor, 5, 2))/256; |
|
|
|
|
|
$floatColor = `$r $g $b`; |
|
|
|
|
|
return $floatColor; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
?>
|
|
|
?>
|