|
@ -6,6 +6,8 @@ use Blobt\Luxcore\scene\materials\Disney; |
|
|
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; |
|
|
|
|
|
use GuzzleHttp\Client; |
|
|
|
|
|
use GuzzleHttp\RequestOptions; |
|
|
|
|
|
|
|
|
class MatHelper{ |
|
|
class MatHelper{ |
|
|
|
|
|
|
|
@ -15,7 +17,7 @@ class MatHelper{ |
|
|
/** |
|
|
/** |
|
|
* 创建一个 Disney 的材质 |
|
|
* 创建一个 Disney 的材质 |
|
|
*/ |
|
|
*/ |
|
|
static function createMatOfDisney($matOriginal, $textureScaleU, $textureScaleV, $scene){ |
|
|
|
|
|
|
|
|
static function createMatOfDisney($matOriginal, $textureScaleU, $textureScaleV, $downloadDir, $scene){ |
|
|
|
|
|
|
|
|
$material = new Disney(); |
|
|
$material = new Disney(); |
|
|
$material->setBaseColor(self::hex2floatColor($matOriginal->matParams->albedoColor)); |
|
|
$material->setBaseColor(self::hex2floatColor($matOriginal->matParams->albedoColor)); |
|
@ -53,31 +55,46 @@ class MatHelper{ |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
if($matOriginal->matParams->albedoTexture){ |
|
|
if($matOriginal->matParams->albedoTexture){ |
|
|
|
|
|
$textureUrl = $matOriginal->matParams->albedoTexture; |
|
|
|
|
|
$textureSavaPath = $downloadDir.basename($textureUrl); |
|
|
|
|
|
$textureHandle = fopen($textureSavaPath, "w"); |
|
|
|
|
|
(new Client())->get($textureUrl, [RequestOptions::SINK => $textureHandle]); |
|
|
|
|
|
|
|
|
$albedoTexture = new ImageMap( |
|
|
$albedoTexture = new ImageMap( |
|
|
['file' => $matOriginal->matParams->albedoTexture] |
|
|
|
|
|
|
|
|
['file' => $textureSavaPath] |
|
|
); |
|
|
); |
|
|
$albedoTexture->mapping = $mapping; |
|
|
$albedoTexture->mapping = $mapping; |
|
|
$scene->registerTexture($albedoTexture); |
|
|
$scene->registerTexture($albedoTexture); |
|
|
$material->setBaseColor($albedoTexture); |
|
|
$material->setBaseColor($albedoTexture); |
|
|
} |
|
|
} |
|
|
if($matOriginal->matParams->metallicTexture){ |
|
|
if($matOriginal->matParams->metallicTexture){ |
|
|
|
|
|
$textureUrl = $matOriginal->matParams->metallicTexture; |
|
|
|
|
|
$textureSavaPath = $downloadDir.basename($textureUrl); |
|
|
|
|
|
$textureHandle = fopen($textureSavaPath, "w"); |
|
|
|
|
|
(new Client())->get($textureUrl, [RequestOptions::SINK => $textureHandle]); |
|
|
|
|
|
|
|
|
$metallicTexture = new ImageMap( |
|
|
$metallicTexture = new ImageMap( |
|
|
['file' => $matOriginal->matParams->metallicTexture] |
|
|
|
|
|
|
|
|
['file' => $textureSavaPath] |
|
|
); |
|
|
); |
|
|
$metallicTexture->mapping = $mapping; |
|
|
$metallicTexture->mapping = $mapping; |
|
|
$scene->registerTexture($metallicTexture); |
|
|
$scene->registerTexture($metallicTexture); |
|
|
$material->setMetallic($metallicTexture); |
|
|
$material->setMetallic($metallicTexture); |
|
|
|
|
|
|
|
|
$roughnessTexture = new ImageMap( |
|
|
$roughnessTexture = new ImageMap( |
|
|
['file' => $matOriginal->matParams->metallicTexture] |
|
|
|
|
|
|
|
|
['file' => $textureSavaPath] |
|
|
); |
|
|
); |
|
|
$roughnessTexture->mapping = $mapping; |
|
|
$roughnessTexture->mapping = $mapping; |
|
|
$scene->registerTexture($roughnessTexture); |
|
|
$scene->registerTexture($roughnessTexture); |
|
|
$material->setRoughness($roughnessTexture); |
|
|
$material->setRoughness($roughnessTexture); |
|
|
} |
|
|
} |
|
|
if($matOriginal->matParams->bumpTexture){ |
|
|
if($matOriginal->matParams->bumpTexture){ |
|
|
|
|
|
$textureUrl = $matOriginal->matParams->bumpTexture; |
|
|
|
|
|
$textureSavaPath = $downloadDir.basename($textureUrl); |
|
|
|
|
|
$textureHandle = fopen($textureSavaPath, "w"); |
|
|
|
|
|
(new Client())->get($textureUrl, [RequestOptions::SINK => $textureHandle]); |
|
|
|
|
|
|
|
|
$bumpTexture = new ImageMap( |
|
|
$bumpTexture = new ImageMap( |
|
|
['file' => $matOriginal->matParams->bumpTexture] |
|
|
|
|
|
|
|
|
['file' => $textureSavaPath] |
|
|
); |
|
|
); |
|
|
$bumpTexture->mapping = $mapping; |
|
|
$bumpTexture->mapping = $mapping; |
|
|
$scene->registerTexture($bumpTexture); |
|
|
$scene->registerTexture($bumpTexture); |
|
|