|
@ -18,7 +18,7 @@ class MatHelper{ |
|
|
/** |
|
|
/** |
|
|
* 创建一个 Disney 的材质 |
|
|
* 创建一个 Disney 的材质 |
|
|
*/ |
|
|
*/ |
|
|
static function createMatOfDisney($matOriginal, $textureScaleU, $textureScaleV, $downloadDir, $scene){ |
|
|
|
|
|
|
|
|
static function createMatOfDisney($matOriginal, $textureScaleU, $textureScaleV, $cacheFileDir, $scene){ |
|
|
|
|
|
|
|
|
$material = new Disney(); |
|
|
$material = new Disney(); |
|
|
$material->setBaseColor(self::hex2floatColor($matOriginal->matParams->albedoColor)); |
|
|
$material->setBaseColor(self::hex2floatColor($matOriginal->matParams->albedoColor)); |
|
@ -57,7 +57,7 @@ class MatHelper{ |
|
|
|
|
|
|
|
|
if($matOriginal->matParams->albedoTexture){ |
|
|
if($matOriginal->matParams->albedoTexture){ |
|
|
$textureUrl = $matOriginal->matParams->albedoTexture; |
|
|
$textureUrl = $matOriginal->matParams->albedoTexture; |
|
|
$textureSavaPath = $downloadDir.basename($textureUrl); |
|
|
|
|
|
|
|
|
$textureSavaPath = $cacheFileDir.'/'.basename($textureUrl); |
|
|
$textureHandle = fopen($textureSavaPath, "w"); |
|
|
$textureHandle = fopen($textureSavaPath, "w"); |
|
|
(new Client())->get($textureUrl, [RequestOptions::SINK => $textureHandle]); |
|
|
(new Client())->get($textureUrl, [RequestOptions::SINK => $textureHandle]); |
|
|
|
|
|
|
|
@ -70,14 +70,14 @@ class MatHelper{ |
|
|
} |
|
|
} |
|
|
if($matOriginal->matParams->metallicTexture){ |
|
|
if($matOriginal->matParams->metallicTexture){ |
|
|
$metallicTextureUrl = $matOriginal->matParams->metallicTexture; |
|
|
$metallicTextureUrl = $matOriginal->matParams->metallicTexture; |
|
|
$metallicTextureSavaPath = $downloadDir.basename($metallicTextureUrl); |
|
|
|
|
|
|
|
|
$metallicTextureSavaPath = $cacheFileDir.'/'.basename($metallicTextureUrl); |
|
|
$metallicTextureHandle = fopen($metallicTextureSavaPath, "w"); |
|
|
$metallicTextureHandle = fopen($metallicTextureSavaPath, "w"); |
|
|
(new Client())->get($metallicTextureUrl, [RequestOptions::SINK => $metallicTextureHandle]); |
|
|
(new Client())->get($metallicTextureUrl, [RequestOptions::SINK => $metallicTextureHandle]); |
|
|
|
|
|
|
|
|
$fileName = preg_replace('/(\.[^\.]+)$/','',basename($metallicTextureUrl)); |
|
|
$fileName = preg_replace('/(\.[^\.]+)$/','',basename($metallicTextureUrl)); |
|
|
$suffixName = preg_replace('/^('.$fileName.')+/','',basename($metallicTextureUrl)); |
|
|
|
|
|
|
|
|
$extension = preg_replace('/^('.$fileName.')+/','',basename($metallicTextureUrl)); |
|
|
// 从金属纹理中 分离 蓝色通道 作为 金属度纹理
|
|
|
// 从金属纹理中 分离 蓝色通道 作为 金属度纹理
|
|
|
$metalnessTextureSavaPath = $downloadDir.$fileName.'_metalness'.$suffixName; |
|
|
|
|
|
|
|
|
$metalnessTextureSavaPath = $cacheFileDir.'/'.$fileName.'_metalness'.$extension; |
|
|
$metalnessTexture = new Imagick($metallicTextureSavaPath); |
|
|
$metalnessTexture = new Imagick($metallicTextureSavaPath); |
|
|
$metalnessTexture->separateImageChannel(Imagick::CHANNEL_BLUE); |
|
|
$metalnessTexture->separateImageChannel(Imagick::CHANNEL_BLUE); |
|
|
$metalnessTexture->writeImage($metalnessTextureSavaPath); |
|
|
$metalnessTexture->writeImage($metalnessTextureSavaPath); |
|
@ -89,7 +89,7 @@ class MatHelper{ |
|
|
$scene->registerTexture($metalnessTexture); |
|
|
$scene->registerTexture($metalnessTexture); |
|
|
$material->setMetallic($metalnessTexture); |
|
|
$material->setMetallic($metalnessTexture); |
|
|
// 从金属纹理中 分离 绿色通道 作为 粗糙度纹理
|
|
|
// 从金属纹理中 分离 绿色通道 作为 粗糙度纹理
|
|
|
$roughnessTextureSavaPath = $downloadDir.$fileName.'_roughness'.$suffixName; |
|
|
|
|
|
|
|
|
$roughnessTextureSavaPath = $cacheFileDir.'/'.$fileName.'_roughness'.$extension; |
|
|
$roughnessTexture = new Imagick($metallicTextureSavaPath); |
|
|
$roughnessTexture = new Imagick($metallicTextureSavaPath); |
|
|
$roughnessTexture->separateImageChannel(Imagick::CHANNEL_GREEN); |
|
|
$roughnessTexture->separateImageChannel(Imagick::CHANNEL_GREEN); |
|
|
$roughnessTexture->writeImage($roughnessTextureSavaPath); |
|
|
$roughnessTexture->writeImage($roughnessTextureSavaPath); |
|
@ -103,15 +103,15 @@ class MatHelper{ |
|
|
} |
|
|
} |
|
|
if($matOriginal->matParams->bumpTexture){ |
|
|
if($matOriginal->matParams->bumpTexture){ |
|
|
$textureUrl = $matOriginal->matParams->bumpTexture; |
|
|
$textureUrl = $matOriginal->matParams->bumpTexture; |
|
|
$textureSavaPath = $downloadDir.basename($textureUrl); |
|
|
|
|
|
|
|
|
$textureSavaPath = $cacheFileDir.'/'.basename($textureUrl); |
|
|
$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 不同,
|
|
|
// 因为 LuxCore 使用 opengl 规范的法线纹理格式,与 babylon 使用的 DirectX 不同,
|
|
|
// 所以这里需要反转 G 通道色值,以保证法线纹理应用效果与 babylon 一致。
|
|
|
// 所以这里需要反转 G 通道色值,以保证法线纹理应用效果与 babylon 一致。
|
|
|
$fileName = preg_replace('/(\.[^\.]+)$/','',basename($textureSavaPath)); |
|
|
$fileName = preg_replace('/(\.[^\.]+)$/','',basename($textureSavaPath)); |
|
|
$suffixName = preg_replace('/^('.$fileName.')+/','',basename($textureSavaPath)); |
|
|
|
|
|
$textureInvertGPath = $downloadDir.$fileName.'_InvertG'.$suffixName; |
|
|
|
|
|
|
|
|
$extension = preg_replace('/^('.$fileName.')+/','',basename($textureSavaPath)); |
|
|
|
|
|
$textureInvertGPath = $cacheFileDir.'/'.$fileName.'_InvertG'.$extension; |
|
|
$imagick = new \Imagick($textureSavaPath); |
|
|
$imagick = new \Imagick($textureSavaPath); |
|
|
$imageIterator = $imagick->getPixelIterator(); |
|
|
$imageIterator = $imagick->getPixelIterator(); |
|
|
foreach ($imageIterator as $row => $pixels) { |
|
|
foreach ($imageIterator as $row => $pixels) { |
|
|