|
|
@ -3,6 +3,8 @@ |
|
|
|
|
|
|
|
|
|
|
|
namespace Blobt\Luxcore\scene; |
|
|
|
|
|
|
|
use Blobt\Luxcore\utils\MatHelper; |
|
|
|
use GuzzleHttp\Client; |
|
|
|
|
|
|
|
include dirname(dirname(__FILE__)) . "/vendor/autoload.php"; |
|
|
@ -15,8 +17,31 @@ const CLOSE = false; |
|
|
|
$client = new Client(); |
|
|
|
$response = $client->get("deep3d.backend-api.dev.com/test/render-task"); |
|
|
|
$resContents = $response->getBody()->getContents(); |
|
|
|
$resData = json_decode($resContents); |
|
|
|
|
|
|
|
$result = json_decode($resContents,false); |
|
|
|
|
|
|
|
$taskData = $result->data; |
|
|
|
$taskScene = $taskData->scene; |
|
|
|
$taskModel = $taskScene->model; |
|
|
|
// print_r($taskModel);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 创建个 Luxcore 材质 |
|
|
|
*/ |
|
|
|
function createLuxcoreMat($matParams){ |
|
|
|
switch($matParams->renderType){ |
|
|
|
case 1: |
|
|
|
return MatHelper::createMatOfDisney($matParams); |
|
|
|
case 2: |
|
|
|
return; |
|
|
|
case 3: |
|
|
|
return; |
|
|
|
case 4: |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -27,101 +52,101 @@ $scene = new Scene(); |
|
|
|
|
|
|
|
// 一、创建光场:
|
|
|
|
// 1、创建 面片光001
|
|
|
|
$materials = new materials\Matte(); |
|
|
|
$materials->setBaseColor('0 0 0'); |
|
|
|
$materials->setTransparencyShadow('1 1 1'); |
|
|
|
$materials->setEmission('1 1 1'); |
|
|
|
$scene->registerMaterial($materials); |
|
|
|
$material = new materials\Matte(); |
|
|
|
$material->setBaseColor('0 0 0'); |
|
|
|
$material->setTransparencyShadow('1 1 1'); |
|
|
|
$material->setEmission('1 1 1'); |
|
|
|
$scene->registerMaterial($material); |
|
|
|
$obj = new objects\Objects(); |
|
|
|
$obj->ply = './ply/FaceLight001.ply'; |
|
|
|
$obj->setMaterial($materials); |
|
|
|
$obj->setMaterial($material); |
|
|
|
$scene->registerObjects($obj); |
|
|
|
|
|
|
|
// 2、创建 面片光002
|
|
|
|
$materials = new materials\Matte(); |
|
|
|
$materials->setBaseColor('0 0 0'); |
|
|
|
$materials->setTransparencyShadow('1 1 1'); |
|
|
|
$materials->setEmission('0 0 0'); |
|
|
|
$materials->emissionCfg = new lights\Emission([ |
|
|
|
$material = new materials\Matte(); |
|
|
|
$material->setBaseColor('0 0 0'); |
|
|
|
$material->setTransparencyShadow('1 1 1'); |
|
|
|
$material->setEmission('0 0 0'); |
|
|
|
$material->emissionCfg = new lights\Emission([ |
|
|
|
'gain' => "30 30 30", |
|
|
|
]); |
|
|
|
$scene->registerMaterial($materials); |
|
|
|
$scene->registerMaterial($material); |
|
|
|
$obj = new objects\Objects(); |
|
|
|
$obj->ply = './ply/FaceLight002.ply'; |
|
|
|
$obj->setMaterial($materials); |
|
|
|
$obj->setMaterial($material); |
|
|
|
$scene->registerObjects($obj); |
|
|
|
|
|
|
|
// 3、创建 面片光003
|
|
|
|
$materials = new materials\Matte(); |
|
|
|
$materials->setBaseColor('0 0 0'); |
|
|
|
$materials->setTransparencyShadow('1 1 1'); |
|
|
|
$materials->setEmission('1 1 1'); |
|
|
|
$materials->emissionCfg = new lights\Emission([ |
|
|
|
$material = new materials\Matte(); |
|
|
|
$material->setBaseColor('0 0 0'); |
|
|
|
$material->setTransparencyShadow('1 1 1'); |
|
|
|
$material->setEmission('1 1 1'); |
|
|
|
$material->emissionCfg = new lights\Emission([ |
|
|
|
'gain' => "50 50 50", |
|
|
|
]); |
|
|
|
$scene->registerMaterial($materials); |
|
|
|
$scene->registerMaterial($material); |
|
|
|
$obj = new objects\Objects(); |
|
|
|
$obj->ply = './ply/FaceLight003.ply'; |
|
|
|
$obj->setMaterial($materials); |
|
|
|
$obj->setMaterial($material); |
|
|
|
$scene->registerObjects($obj); |
|
|
|
|
|
|
|
// 4、创建 面片光004
|
|
|
|
$materials = new materials\Matte(); |
|
|
|
$materials->setBaseColor('0 0 0'); |
|
|
|
$materials->setTransparencyShadow('1 1 1'); |
|
|
|
$materials->setEmission('0 0 0'); |
|
|
|
$materials->emissionCfg = new lights\Emission([ |
|
|
|
$material = new materials\Matte(); |
|
|
|
$material->setBaseColor('0 0 0'); |
|
|
|
$material->setTransparencyShadow('1 1 1'); |
|
|
|
$material->setEmission('0 0 0'); |
|
|
|
$material->emissionCfg = new lights\Emission([ |
|
|
|
'gain' => "4 4 4", |
|
|
|
]); |
|
|
|
$scene->registerMaterial($materials); |
|
|
|
$scene->registerMaterial($material); |
|
|
|
$obj = new objects\Objects(); |
|
|
|
$obj->ply = './ply/FaceLight004.ply'; |
|
|
|
$obj->setMaterial($materials); |
|
|
|
$obj->setMaterial($material); |
|
|
|
$scene->registerObjects($obj); |
|
|
|
|
|
|
|
// 5、创建 面片光005
|
|
|
|
$materials = new materials\Matte(); |
|
|
|
$materials->setBaseColor('0 0 0'); |
|
|
|
$materials->setTransparencyShadow('1 1 1'); |
|
|
|
$materials->setEmission('1 1 1'); |
|
|
|
$materials->emissionCfg = new lights\Emission([ |
|
|
|
$material = new materials\Matte(); |
|
|
|
$material->setBaseColor('0 0 0'); |
|
|
|
$material->setTransparencyShadow('1 1 1'); |
|
|
|
$material->setEmission('1 1 1'); |
|
|
|
$material->emissionCfg = new lights\Emission([ |
|
|
|
'gain' => "10 10 10", |
|
|
|
]); |
|
|
|
$scene->registerMaterial($materials); |
|
|
|
$scene->registerMaterial($material); |
|
|
|
$obj = new objects\Objects(); |
|
|
|
$obj->ply = './ply/FaceLight005.ply'; |
|
|
|
$obj->setMaterial($materials); |
|
|
|
$obj->setMaterial($material); |
|
|
|
$scene->registerObjects($obj); |
|
|
|
|
|
|
|
// 6、创建 面片光006
|
|
|
|
$materials = new materials\Matte(); |
|
|
|
$materials->setBaseColor('0 0 0'); |
|
|
|
$materials->setTransparencyShadow('1 1 1'); |
|
|
|
$materials->setEmission('1 1 1'); |
|
|
|
$materials->emissionCfg = new lights\Emission([ |
|
|
|
$material = new materials\Matte(); |
|
|
|
$material->setBaseColor('0 0 0'); |
|
|
|
$material->setTransparencyShadow('1 1 1'); |
|
|
|
$material->setEmission('1 1 1'); |
|
|
|
$material->emissionCfg = new lights\Emission([ |
|
|
|
'gain' => "8 8 8", |
|
|
|
'mapfile' => "./map/SD-037.exr", |
|
|
|
'gamma' => 1, |
|
|
|
'storage' => "float" |
|
|
|
]); |
|
|
|
$scene->registerMaterial($materials); |
|
|
|
$scene->registerMaterial($material); |
|
|
|
$obj = new objects\Objects(); |
|
|
|
$obj->ply = './ply/FaceLight006.ply'; |
|
|
|
$obj->setMaterial($materials); |
|
|
|
$obj->setMaterial($material); |
|
|
|
$scene->registerObjects($obj); |
|
|
|
|
|
|
|
// 7、创建 面片光000
|
|
|
|
$materials = new materials\Matte(); |
|
|
|
$materials->setBaseColor('0 0 0'); |
|
|
|
$materials->setTransparencyShadow('1 1 1'); |
|
|
|
$materials->setEmission('1 1 1'); |
|
|
|
$materials->emissionCfg = new lights\Emission([ |
|
|
|
$material = new materials\Matte(); |
|
|
|
$material->setBaseColor('0 0 0'); |
|
|
|
$material->setTransparencyShadow('1 1 1'); |
|
|
|
$material->setEmission('1 1 1'); |
|
|
|
$material->emissionCfg = new lights\Emission([ |
|
|
|
'gain' => "3.3 3.3 3.3", |
|
|
|
]); |
|
|
|
$scene->registerMaterial($materials); |
|
|
|
$scene->registerMaterial($material); |
|
|
|
$obj = new objects\Objects(); |
|
|
|
$obj->ply = './ply/FaceLight000.ply'; |
|
|
|
$obj->setMaterial($materials); |
|
|
|
$obj->setMaterial($material); |
|
|
|
$scene->registerObjects($obj); |
|
|
|
|
|
|
|
// 8、创建环境光
|
|
|
@ -145,31 +170,142 @@ $texture = new texture\procedural\ImageMap([ |
|
|
|
]); |
|
|
|
$texture->mapping = $mapping; |
|
|
|
$scene->registerTexture($texture); |
|
|
|
$materials = new materials\Disney([ |
|
|
|
$material = new materials\Disney([ |
|
|
|
'shadowcatcherEnable' => OPEN, |
|
|
|
'photongiEnable' => CLOSE |
|
|
|
]); |
|
|
|
$materials->setBaseColor('1 1 1'); |
|
|
|
$materials->setTransparencyFront($texture); |
|
|
|
$materials->setTransparencyBack($texture); |
|
|
|
$scene->registerMaterial($materials); |
|
|
|
$material->setBaseColor('1 1 1'); |
|
|
|
$material->setTransparencyFront($texture); |
|
|
|
$material->setTransparencyBack($texture); |
|
|
|
$scene->registerMaterial($material); |
|
|
|
$obj = new objects\Objects(); |
|
|
|
$obj->ply = './ply/ground.ply'; |
|
|
|
$obj->setMaterial($materials); |
|
|
|
$obj->setMaterial($material); |
|
|
|
$scene->registerObjects($obj); |
|
|
|
|
|
|
|
|
|
|
|
// 二、添加要渲染的模型
|
|
|
|
$loadModel = $resData->data->scene->model; |
|
|
|
$loadCamera = $resData->data->scene->camera; |
|
|
|
|
|
|
|
foreach($loadModel->childsParams as $childParams){ |
|
|
|
print_r($childParams); |
|
|
|
foreach($taskModel->childsParams as $childParams){ |
|
|
|
|
|
|
|
$material = null; |
|
|
|
$matParams = (function ($childParams){ |
|
|
|
if(is_object($childParams->customMat)){ |
|
|
|
return $childParams->customMat; |
|
|
|
}else if(is_object($childParams->fixedMat)){ |
|
|
|
return $childParams->fixedMat; |
|
|
|
}else if(is_object($childParams->defaultMat)){ |
|
|
|
return $childParams->defaultMat; |
|
|
|
} |
|
|
|
})($childParams); |
|
|
|
if(is_object($matParams)){ |
|
|
|
$material = createLuxcoreMat($matParams,$scene); |
|
|
|
}else{ |
|
|
|
$material = new materials\Disney(); |
|
|
|
$material->setBaseColor('1 1 1'); |
|
|
|
} |
|
|
|
$scene->registerMaterial($material); |
|
|
|
|
|
|
|
$obj = new objects\Objects(); |
|
|
|
$obj->ply = $childParams->childPlyFile; |
|
|
|
$obj->setMaterial($material); |
|
|
|
$scene->registerObjects($obj); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 三、创建相机
|
|
|
|
$camera = new camera\Perspective( // 创建一个相机
|
|
|
|
[ |
|
|
|
'autovolumeEnable' => 0, // 关闭自动体积效果
|
|
|
|
'lookatOrig' => "-3.197486 -4.560584 0.8914337", // 视点坐标位置
|
|
|
|
'lookatTarget' => "-2.632151 -3.747173 0.7544713", // 目标点坐标位置
|
|
|
|
'up' => "0.0781663 0.1124666 0.9905763", // 旋转参数
|
|
|
|
'screenwindow' => "-1 1 -1 1", // 视野比例
|
|
|
|
'autofocusEnable' => 0, // 关闭自动对焦
|
|
|
|
'fieldofview' => 3.40608, // 视野角度大小
|
|
|
|
'cliphither' => 0.1 // 剪切成像起始位置,单位跟随系统
|
|
|
|
] |
|
|
|
); |
|
|
|
$camera->bokeh->blades = 0; // 模拟镜头模糊效果的光圈数
|
|
|
|
$scene->registerCamera($camera); // 将相机注册到 scene 中
|
|
|
|
|
|
|
|
|
|
|
|
// 四、设置渲染参数
|
|
|
|
$render = ''; |
|
|
|
$renderEngine = new render\RenderEngine(); // 设置 渲染引擎 的配置参数,默认使用了 PATHOCL,意义着将使用 GPU 设备渲染
|
|
|
|
$render .= $renderEngine; |
|
|
|
|
|
|
|
$openCL = new render\OpenCL(); // 设置 GPU 渲染参数,这里使用一个默认的参数
|
|
|
|
$render .= $openCL; |
|
|
|
|
|
|
|
$path = new render\Path(); // 设置 光线跟踪 参数,这里使用一个默认的参数
|
|
|
|
$render .= $path; |
|
|
|
|
|
|
|
$sampler = new render\Sampler(); // 设置 采样器 配置参数,默认使用 Sobol 类型的自适应采样器
|
|
|
|
$render .= $sampler; |
|
|
|
|
|
|
|
$lightStrategy = new render\LightStrategy(); // 设置 灯光策略 类型,默认使用 LOG_POWER 类型
|
|
|
|
$render .= $lightStrategy; |
|
|
|
|
|
|
|
$filesaver = new render\FileSaver(); // 设置 文件储存格式 配置参数
|
|
|
|
$render .= $filesaver; |
|
|
|
|
|
|
|
$batch = new render\Batch(); // 设置 渲染终止 参数,
|
|
|
|
$batch->haltspp = 1000; // 设置 每像素 采样达 800 则终止渲染
|
|
|
|
// $batch->halttime = 2000; // 设置 渲染 超时参数,
|
|
|
|
$render .= $batch; |
|
|
|
|
|
|
|
$sceneCfg = new render\Scene(); // 设置 场景属性 参数
|
|
|
|
$render .= $sceneCfg; |
|
|
|
|
|
|
|
|
|
|
|
$film = new render\Film(); // 添加一个渲染胶片
|
|
|
|
$film->width = 3000; // 设置渲染胶片宽度,单位像素
|
|
|
|
$film->heigth = 3000; // 设置渲染胶片宽度,单位像素
|
|
|
|
$img = new render\Image(); // 添加一个图像输出
|
|
|
|
$img->effect = [new render\effect\Pretreatment(),new render\effect\ToneMapLinear(),new render\effect\CammaCorrection()]; |
|
|
|
// 为该图像添加效果管线
|
|
|
|
$film->addImage($img); // 将该图像输出添加到渲染胶片
|
|
|
|
|
|
|
|
$film->addImage(new render\Image(['type' => render\Image::TYPE_OBJECT_ID])); // 为渲染胶片添加一个 通道图类型 的图像输出
|
|
|
|
$film->addImage(new render\Image(['type' => render\Image::TYPE_RGBA])); // 添加一个 透明底 的图像输出
|
|
|
|
|
|
|
|
$img = new render\Image(); // 添加一个图像输出,使用默认参数
|
|
|
|
$img->effect[] = new render\effect\NoiseReducerOIDN(); // 添加降噪效果管线,使用默认参数
|
|
|
|
$img->effect[] = new render\effect\Pretreatment(); //
|
|
|
|
$img->effect[] = new render\effect\ToneMapLinear(); // 添加一亮度效果管线,使用默认参数
|
|
|
|
$img->effect[] = new render\effect\Synthesis(); // 添加一个合成效果管线,使用默认参数
|
|
|
|
$img->effect[] = new render\effect\BackgroundImg( // 添加一个背景图像,使用默认参数
|
|
|
|
[ |
|
|
|
'file' => "./map/纯白242.png" |
|
|
|
] |
|
|
|
); |
|
|
|
$img->effect[] = new render\effect\CammaCorrection(); // 添加一个 gamma 校正,,使用默认参数
|
|
|
|
$film->addImage($img); // 将该图像输出添加到渲染胶片
|
|
|
|
$render .= $film; |
|
|
|
|
|
|
|
|
|
|
|
// 五、输出场景文件 scene.scn,及渲染文件 render.cfg
|
|
|
|
echo $scene; |
|
|
|
$handle = fopen( "./DemoScene/scene.scn",'w+'); |
|
|
|
fwrite($handle,$scene); |
|
|
|
fclose($handle); |
|
|
|
|
|
|
|
echo $render ; |
|
|
|
$handle = fopen( "./DemoScene/render.cfg",'w+'); |
|
|
|
fwrite($handle,$render); |
|
|
|
fclose($handle); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // 六、启动渲染器
|
|
|
|
// $cmd = "luxcoreconsole -o ./DemoScene/render.cfg -f ./DemoScene/scene.scn 1>./DemoScene/render.log 2>&1";
|
|
|
|
// $output;
|
|
|
|
// $returnVar;
|
|
|
|
// exec($cmd,$output,$returnVar);
|
|
|
|
|
|
|
|
// if( $returnVar == 127 ){
|
|
|
|
// throw new \Exception("Please install the luxcorerender bin file in the system directory correctly,Or add to the system environment variable");
|
|
|
|
// }
|
|
|
|
|
|
|
|
?>
|