Browse Source

渲染测式 案例 开发

master
yuanjiajia 1 year ago
parent
commit
c85c3aeced
  1. 37
      examples/testImage.php
  2. 25
      src/utils/MatHelper.php

37
examples/testImage.php

@ -0,0 +1,37 @@
<?php
namespace Blobt\Luxcore\scene;
use Imagick;
include dirname(dirname(__FILE__)) . "/vendor/autoload.php";
const OPEN = true;
const CLOSE = false;
$imagick = new \Imagick(realpath("/media/yuanjiajia/zhiTai_300GB_P4/LuxcoreModel/normal_maps1.jpg"));
$imageIterator = $imagick->getPixelIterator();
$ll = 0;
foreach ($imageIterator as $row => $pixels) {
foreach ($pixels as $column => $pixel) {
// 获取每个像素色值;
$value = $pixel->getColor();
// 反相绿色通道色值;
$r = $value["r"];
$g = abs(($value["g"] - 255));
$b = $value["b"];
$a = $value["a"];
$pixel->setColor("rgba({$r}, {$g}, {$b}, {$a})");
}
$imageIterator->syncIterator();
}
$imagick->writeImage("/media/yuanjiajia/zhiTai_300GB_P4/LuxcoreModel/normal_maps1-g.jpg");
?>

25
src/utils/MatHelper.php

@ -107,8 +107,31 @@ class MatHelper{
$textureHandle = fopen($textureSavaPath, "w");
(new Client())->get($textureUrl, [RequestOptions::SINK => $textureHandle]);
// 因为 LuxCore 使用 opengl 规范的法线纹理格式,与 babylon 使用的 DirectX 不同,
// 所以这里需要反转 G 通道色值,以保证法线纹理应用效果与 babylon 一致。
$fileName = preg_replace('/(\.[^\.]+)$/','',basename($textureSavaPath));
$suffixName = preg_replace('/^('.$fileName.')+/','',basename($textureSavaPath));
$textureInvertGPath = $downloadDir.$fileName.'_InvertG'.$suffixName;
$imagick = new \Imagick($textureSavaPath);
$imageIterator = $imagick->getPixelIterator();
foreach ($imageIterator as $row => $pixels) {
foreach ($pixels as $column => $pixel) {
// 获取每个像素色值;
$value = $pixel->getColor();
// 反相绿色通道色值;
$r = $value["r"];
$g = abs(($value["g"] - 255));
$b = $value["b"];
$a = $value["a"];
$pixel->setColor("rgba({$r}, {$g}, {$b}, {$a})");
}
$imageIterator->syncIterator();
}
$imagick->writeImage($textureInvertGPath);
$bumpTexture = new ImageMap(
['file' => $textureSavaPath]
['file' => $textureInvertGPath]
);
$bumpTexture->gamma = 1;
$bumpTexture->mapping = $mapping;

Loading…
Cancel
Save