diff --git a/examples/renderTest.php b/examples/renderTest.php index 94c8d7b..f8d5f11 100644 --- a/examples/renderTest.php +++ b/examples/renderTest.php @@ -4,6 +4,7 @@ namespace Blobt\Luxcore\scene; +use Blobt\Luxcore\scene\materials\Disney; use Blobt\Luxcore\scene\objects\Objects; use Blobt\Luxcore\utils\MatHelper; use GuzzleHttp\Client; @@ -34,10 +35,10 @@ $taskModel = $taskScene->model; /** * 创建 Luxcore 材质 */ -function createLuxcoreMat($matOriginal, $textureScaleU, $textureScaleV, $scene){ +function createLuxcoreMat($matOriginal, $textureScaleU, $textureScaleV, $downloadDir, $scene){ switch($matOriginal->renderType){ case 1: - return MatHelper::createMatOfDisney($matOriginal, $textureScaleU, $textureScaleV, $scene); + return MatHelper::createMatOfDisney($matOriginal, $textureScaleU, $textureScaleV, $downloadDir, $scene); case 2: return; case 3: @@ -175,7 +176,7 @@ $texture = new texture\procedural\ImageMap([ ]); $texture->mapping = $mapping; $scene->registerTexture($texture); -$material = new materials\Disney([ +$material = new Disney([ 'shadowcatcherEnable' => OPEN, 'photongiEnable' => CLOSE ]); @@ -191,6 +192,7 @@ $scene->registerObjects($obj); // 二、添加要渲染的模型 foreach($taskModel->childsParams as $childParams){ + $downloadDir = $sceneTemplatePath.'/cacheFiles/'; $material = null; $matOriginal = (function ($childParams){ if(is_object($childParams->customMat)){ @@ -204,15 +206,14 @@ foreach($taskModel->childsParams as $childParams){ $textureScaleU = $taskModel->uvScale*(MAT_STANDARD_SIZE/$matOriginal->width); $textureScaleV = $taskModel->uvScale*(MAT_STANDARD_SIZE/$matOriginal->height); if(false){ - $material = createLuxcoreMat($matOriginal, $textureScaleU, $textureScaleV, $scene); + $material = createLuxcoreMat($matOriginal, $textureScaleU, $textureScaleV, $downloadDir, $scene); }else{ - $material = new materials\Disney(); + $material = new Disney(); $material->setBaseColor('1 1 1'); } $scene->registerMaterial($material); - - $plyFileSavaPath = $sceneTemplatePath.'/cacheFiles/'.basename($childParams->childPlyFile); + $plyFileSavaPath = $downloadDir.basename($childParams->childPlyFile); $plyFileHandle = fopen($plyFileSavaPath, "w"); (new Client())->get($childParams->childPlyFile, [RequestOptions::SINK => $plyFileHandle]); $obj = new Objects(); diff --git a/src/utils/MatHelper.php b/src/utils/MatHelper.php index 23cce0f..694a84f 100644 --- a/src/utils/MatHelper.php +++ b/src/utils/MatHelper.php @@ -6,6 +6,8 @@ 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; +use GuzzleHttp\Client; +use GuzzleHttp\RequestOptions; class MatHelper{ @@ -15,7 +17,7 @@ class MatHelper{ /** * 创建一个 Disney 的材质 */ - static function createMatOfDisney($matOriginal, $textureScaleU, $textureScaleV, $scene){ + static function createMatOfDisney($matOriginal, $textureScaleU, $textureScaleV, $downloadDir, $scene){ $material = new Disney(); $material->setBaseColor(self::hex2floatColor($matOriginal->matParams->albedoColor)); @@ -53,31 +55,46 @@ class MatHelper{ ); 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( - ['file' => $matOriginal->matParams->albedoTexture] + ['file' => $textureSavaPath] ); $albedoTexture->mapping = $mapping; $scene->registerTexture($albedoTexture); $material->setBaseColor($albedoTexture); } 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( - ['file' => $matOriginal->matParams->metallicTexture] + ['file' => $textureSavaPath] ); $metallicTexture->mapping = $mapping; $scene->registerTexture($metallicTexture); $material->setMetallic($metallicTexture); $roughnessTexture = new ImageMap( - ['file' => $matOriginal->matParams->metallicTexture] + ['file' => $textureSavaPath] ); $roughnessTexture->mapping = $mapping; $scene->registerTexture($roughnessTexture); $material->setRoughness($roughnessTexture); } 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( - ['file' => $matOriginal->matParams->bumpTexture] + ['file' => $textureSavaPath] ); $bumpTexture->mapping = $mapping; $scene->registerTexture($bumpTexture);