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;
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();

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

Loading…
Cancel
Save