Browse Source

渲染测式 案例 开发

master
yuanjiajia 1 year ago
parent
commit
8a33d895d2
  1. 25
      examples/renderTest.php
  2. 9
      src/scene/texture/mapping/Mapping.php
  3. 2
      src/scene/texture/transform/NormalMap.php
  4. 106
      src/utils/MatHelper.php

25
examples/renderTest.php

@ -9,8 +9,12 @@ use GuzzleHttp\Client;
include dirname(dirname(__FILE__)) . "/vendor/autoload.php"; include dirname(dirname(__FILE__)) . "/vendor/autoload.php";
const OPEN = true;
const CLOSE = false;
const OPEN = true | 1;
const CLOSE = false | 0;
/**
* 标准材质长宽
*/
const MAT_STANDARD_SIZE = 1000;
@ -18,11 +22,9 @@ $client = new Client();
$response = $client->get("deep3d.backend-api.dev.com/test/render-task"); $response = $client->get("deep3d.backend-api.dev.com/test/render-task");
$resContents = $response->getBody()->getContents(); $resContents = $response->getBody()->getContents();
$result = json_decode($resContents,false); $result = json_decode($resContents,false);
$taskData = $result->data; $taskData = $result->data;
$taskScene = $taskData->scene; $taskScene = $taskData->scene;
$taskModel = $taskScene->model; $taskModel = $taskScene->model;
// print_r($taskModel);
@ -30,10 +32,10 @@ $taskModel = $taskScene->model;
/** /**
* 创建个 Luxcore 材质 * 创建个 Luxcore 材质
*/ */
function createLuxcoreMat($matParams){
switch($matParams->renderType){
function createLuxcoreMat($matOriginal, $textureScaleU, $textureScaleV, $scene){
switch($matOriginal->renderType){
case 1: case 1:
return MatHelper::createMatOfDisney($matParams);
return MatHelper::createMatOfDisney($matOriginal, $textureScaleU, $textureScaleV, $scene);
case 2: case 2:
return; return;
case 3: case 3:
@ -186,9 +188,8 @@ $scene->registerObjects($obj);
// 二、添加要渲染的模型 // 二、添加要渲染的模型
foreach($taskModel->childsParams as $childParams){ foreach($taskModel->childsParams as $childParams){
$material = null; $material = null;
$matParams = (function ($childParams){
$matOriginal = (function ($childParams){
if(is_object($childParams->customMat)){ if(is_object($childParams->customMat)){
return $childParams->customMat; return $childParams->customMat;
}else if(is_object($childParams->fixedMat)){ }else if(is_object($childParams->fixedMat)){
@ -197,8 +198,10 @@ foreach($taskModel->childsParams as $childParams){
return $childParams->defaultMat; return $childParams->defaultMat;
} }
})($childParams); })($childParams);
if(is_object($matParams)){
$material = createLuxcoreMat($matParams,$scene);
$textureScaleU = $taskModel->uvScale*(MAT_STANDARD_SIZE/$matOriginal->width);
$textureScaleV = $taskModel->uvScale*(MAT_STANDARD_SIZE/$matOriginal->height);
if(is_object($matOriginal)){
$material = createLuxcoreMat($matOriginal, $textureScaleU, $textureScaleV, $scene);
}else{ }else{
$material = new materials\Disney(); $material = new materials\Disney();
$material->setBaseColor('1 1 1'); $material->setBaseColor('1 1 1');

9
src/scene/texture/mapping/Mapping.php

@ -13,8 +13,8 @@ class Mapping extends BaseCfg
const TYPE_UVMAPPING2D = 'uvmapping2d'; // 以模型的UV坐标,调整贴图变换参数的类型 const TYPE_UVMAPPING2D = 'uvmapping2d'; // 以模型的UV坐标,调整贴图变换参数的类型
const TYPE_UVRANDOMMAPPING2D = 'uvrandommapping2d'; // 以模型的UV坐标,调整贴图随机变换参数的类型 const TYPE_UVRANDOMMAPPING2D = 'uvrandommapping2d'; // 以模型的UV坐标,调整贴图随机变换参数的类型
const TYPE_LOCALMAPPING3D = 'localmapping3d'; // 以模型的本地坐标,调整贴图三维变换参数的类型 const TYPE_LOCALMAPPING3D = 'localmapping3d'; // 以模型的本地坐标,调整贴图三维变换参数的类型
const TYPE_GLOBALMAPPING3D = 'globalmapping3d'; // 以世界坐标,调整贴图三维变换参数的类型
const TYPE_LOCALRANDOMMAPPING3D = 'localrandommapping3d'; // 以模型的本地坐标,调整贴图三维随机变换参数的类型 const TYPE_LOCALRANDOMMAPPING3D = 'localrandommapping3d'; // 以模型的本地坐标,调整贴图三维随机变换参数的类型
const TYPE_GLOBALMAPPING3D = 'globalmapping3d'; // 以世界坐标,调整贴图三维变换参数的类型
const TYPE_UVMAPPING3D = 'uvmapping3d'; // 以模型的UV坐标,调整贴图三维变换参数的类型 const TYPE_UVMAPPING3D = 'uvmapping3d'; // 以模型的UV坐标,调整贴图三维变换参数的类型
@ -115,14 +115,12 @@ class Mapping extends BaseCfg
private $ytranslate; private $ytranslate;
private $ztranslate; private $ztranslate;
public function useUVMapping2d
(
public function useUVMapping2d(
int $uvindex = 0, int $uvindex = 0,
string $rotation = '0', string $rotation = '0',
string $uvscale = '0', string $uvscale = '0',
string $uvdelta = '0' string $uvdelta = '0'
)
{
){
$this->type = self::TYPE_UVMAPPING2D; $this->type = self::TYPE_UVMAPPING2D;
$this->uvindex = $uvindex; $this->uvindex = $uvindex;
$this->rotation = $rotation; $this->rotation = $rotation;
@ -154,7 +152,6 @@ class Mapping extends BaseCfg
{ {
// 等完善 // 等完善
} }
} }
?> ?>

2
src/scene/texture/transform/NormalMap.php

@ -5,7 +5,7 @@ use Blobt\Luxcore\scene\texture\TextureBase;
use Blobt\Luxcore\scene\Scene; use Blobt\Luxcore\scene\Scene;
use Blobt\Luxcore\core\Base; use Blobt\Luxcore\core\Base;
class ImageMap extends TextureBase
class NormalMap extends TextureBase
{ {
/** /**

106
src/utils/MatHelper.php

@ -2,16 +2,99 @@
namespace Blobt\Luxcore\utils; namespace Blobt\Luxcore\utils;
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;
class MatHelper{
const OPEN = 1 | true;
const CLOSE = 0 | false;
class MatHelper
{
/** /**
* 创建一个 Disney 的材质 * 创建一个 Disney 的材质
*/ */
static function createMatOfDisney($matParams){
static function createMatOfDisney($matOriginal, $textureScaleU, $textureScaleV, $scene){
$material = new Disney();
$material->setBaseColor(self::hex2floatColor($matOriginal->matParams->albedoColor));
$material->setMetallic($matOriginal->matParams->metallic);
$material->setRoughness($matOriginal->matParams->roughness);
if($matOriginal->matParams->isClearCoatEnabled === self::OPEN){
$material->setClearcoat($matOriginal->matParams->clearCoat);
$material->setClearcoatgloss(1 - $matOriginal->matParams->clearCoat);
}
if($matOriginal->matParams->isFilmEnabled === self::OPEN){
$material->setFilmamount($matOriginal->matParams->film);
$material->setFilmthickness($matOriginal->matParams->filmthickness);
$material->setFilmior($matOriginal->matParams->filmIor);
}
if($matOriginal->matParams->isSheenEnabled === self::OPEN){
$material->setSheen(($matOriginal->matParams->sheen)*100);
}
if($matOriginal->matParams->isAnisotropyEnabled === self::OPEN){
$material->setAnisotropic($matOriginal->matParams->anisotropy);
}
// 创建一个铺贴对象
$mapping = new Mapping();
// 使用"uvmapping2d"类型的铺贴对象
$mapping->useUVMapping2d(
// uv通道
0,
// 旋转角度
"0",
// 缩放比例
`$textureScaleU $textureScaleV`,
// 偏移量
"0 0",
);
if($matOriginal->matParams->albedoTexture){
$albedoTexture = new ImageMap(
['file' => $matOriginal->matParams->albedoTexture]
);
$albedoTexture->mapping = $mapping;
$scene->registerTexture($albedoTexture);
$material->setBaseColor($albedoTexture);
}
if($matOriginal->matParams->metallicTexture){
$metallicTexture = new ImageMap(
['file' => $matOriginal->matParams->metallicTexture]
);
$metallicTexture->mapping = $mapping;
$scene->registerTexture($metallicTexture);
$material->setMetallic($metallicTexture);
$roughnessTexture = new ImageMap(
['file' => $matOriginal->matParams->metallicTexture]
);
$roughnessTexture->mapping = $mapping;
$scene->registerTexture($roughnessTexture);
$material->setMetallic($roughnessTexture);
}
if($matOriginal->matParams->bumpTexture){
$bumpTexture = new ImageMap(
['file' => $matOriginal->matParams->bumpTexture]
);
$bumpTexture->mapping = $mapping;
$scene->registerTexture($bumpTexture);
$normalTexture = new NormalMap();
$normalTexture->texture = $bumpTexture;
$normalTexture->scale = $matOriginal->matParams->bumpLevel;
$scene->registerTexture($normalTexture);
$material->setBumptex($normalTexture);
} }
//TODO: 更多通道贴图处理,待后续完善
return $material;
}
/** /**
* 创建一个 Glass 材质(折射材质) * 创建一个 Glass 材质(折射材质)
*/ */
@ -19,18 +102,35 @@ class MatHelper
} }
/** /**
* 创建一个半透明材质 * 创建一个半透明材质
*/ */
static function createMatOfTranslucent(){ static function createMatOfTranslucent(){
} }
/** /**
* 创建一个自发光材质 * 创建一个自发光材质
*/ */
static function createMatOfEmission(){ static function createMatOfEmission(){
} }
/**
* 十六进制颜色 转换为 浮点数颜色
*/
static function hex2floatColor($hexColor){
$floatColor = '';
$hexColor = trim($hexColor);
$r = hexdec(substr($hexColor, 1, 2))/256;
$g = hexdec(substr($hexColor, 3, 2))/256;
$b = hexdec(substr($hexColor, 5, 2))/256;
$floatColor = `$r $g $b`;
return $floatColor;
}
} }
?> ?>
Loading…
Cancel
Save