Browse Source

渲染测式 案例 开发

master
yuanjiajia 1 year ago
parent
commit
a6a357bbc9
  1. 15
      examples/renderTest.php
  2. 27
      src/utils/MatHelper.php

15
examples/renderTest.php

@ -4,6 +4,7 @@
namespace Blobt\Luxcore\scene; namespace Blobt\Luxcore\scene;
use Blobt\Luxcore\scene\materials\Disney;
use Blobt\Luxcore\scene\objects\Objects; use Blobt\Luxcore\scene\objects\Objects;
use Blobt\Luxcore\utils\MatHelper; use Blobt\Luxcore\utils\MatHelper;
use GuzzleHttp\Client; use GuzzleHttp\Client;
@ -34,10 +35,10 @@ $taskModel = $taskScene->model;
/** /**
* 创建 Luxcore 材质 * 创建 Luxcore 材质
*/ */
function createLuxcoreMat($matOriginal, $textureScaleU, $textureScaleV, $scene){
function createLuxcoreMat($matOriginal, $textureScaleU, $textureScaleV, $downloadDir, $scene){
switch($matOriginal->renderType){ switch($matOriginal->renderType){
case 1: case 1:
return MatHelper::createMatOfDisney($matOriginal, $textureScaleU, $textureScaleV, $scene);
return MatHelper::createMatOfDisney($matOriginal, $textureScaleU, $textureScaleV, $downloadDir, $scene);
case 2: case 2:
return; return;
case 3: case 3:
@ -175,7 +176,7 @@ $texture = new texture\procedural\ImageMap([
]); ]);
$texture->mapping = $mapping; $texture->mapping = $mapping;
$scene->registerTexture($texture); $scene->registerTexture($texture);
$material = new materials\Disney([
$material = new Disney([
'shadowcatcherEnable' => OPEN, 'shadowcatcherEnable' => OPEN,
'photongiEnable' => CLOSE 'photongiEnable' => CLOSE
]); ]);
@ -191,6 +192,7 @@ $scene->registerObjects($obj);
// 二、添加要渲染的模型 // 二、添加要渲染的模型
foreach($taskModel->childsParams as $childParams){ foreach($taskModel->childsParams as $childParams){
$downloadDir = $sceneTemplatePath.'/cacheFiles/';
$material = null; $material = null;
$matOriginal = (function ($childParams){ $matOriginal = (function ($childParams){
if(is_object($childParams->customMat)){ if(is_object($childParams->customMat)){
@ -204,15 +206,14 @@ foreach($taskModel->childsParams as $childParams){
$textureScaleU = $taskModel->uvScale*(MAT_STANDARD_SIZE/$matOriginal->width); $textureScaleU = $taskModel->uvScale*(MAT_STANDARD_SIZE/$matOriginal->width);
$textureScaleV = $taskModel->uvScale*(MAT_STANDARD_SIZE/$matOriginal->height); $textureScaleV = $taskModel->uvScale*(MAT_STANDARD_SIZE/$matOriginal->height);
if(false){ if(false){
$material = createLuxcoreMat($matOriginal, $textureScaleU, $textureScaleV, $scene);
$material = createLuxcoreMat($matOriginal, $textureScaleU, $textureScaleV, $downloadDir, $scene);
}else{ }else{
$material = new materials\Disney();
$material = new Disney();
$material->setBaseColor('1 1 1'); $material->setBaseColor('1 1 1');
} }
$scene->registerMaterial($material); $scene->registerMaterial($material);
$plyFileSavaPath = $sceneTemplatePath.'/cacheFiles/'.basename($childParams->childPlyFile);
$plyFileSavaPath = $downloadDir.basename($childParams->childPlyFile);
$plyFileHandle = fopen($plyFileSavaPath, "w"); $plyFileHandle = fopen($plyFileSavaPath, "w");
(new Client())->get($childParams->childPlyFile, [RequestOptions::SINK => $plyFileHandle]); (new Client())->get($childParams->childPlyFile, [RequestOptions::SINK => $plyFileHandle]);
$obj = new Objects(); $obj = new Objects();

27
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\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);

Loading…
Cancel
Save