Browse Source

写一个场景文件,当前已完成场景光场的创建

master
yuanjiajia 2 years ago
parent
commit
7c228e9cdc
  1. 2
      .vscode/launch.json
  2. 238
      examples/printScene.php
  3. 3
      src/scene/lights/Emission.php
  4. 2
      src/scene/lights/LightBase.php
  5. 8
      src/scene/materials/MaterialsBase.php
  6. 2
      src/scene/objects/Objects.php

2
.vscode/launch.json

@ -12,7 +12,7 @@
"name": "Launch currently open script", "name": "Launch currently open script",
"type": "php", "type": "php",
"request": "launch", "request": "launch",
"program": "${workspaceFolder}/examples/loadObjDemo.php",
"program": "${workspaceFolder}/examples/printScene.php",
"cwd": "${workspaceFolder}", "cwd": "${workspaceFolder}",
"port": 9055 "port": 9055
} }

238
examples/printScene.php

@ -3,83 +3,227 @@
namespace Blobt\Luxcore\scene; namespace Blobt\Luxcore\scene;
include dirname(dirname(__FILE__)) . "/vendor/autoload.php";
$scene = new Scene(); // 创建一个场景
// 一、创建光场:
// 1、创建 面片光001
$obj = new objects\Objects(); // 创建 面片光001 的实体
$obj->ply = './ply/面光.001.ply'; // 指定 面片光001 实体网格数据
$materials = new materials\Matte(); // 创建一个材质
$materials->setBaseColor('0 0 0'); // 设置材质的漫反射
$materials->setTransparencyShadow('1 1 1'); // 设置材质产生阴影的透明度
$materials->setEmission('1 1 1'); // 设置材质为一个自发光材质,并指定发光颜色
$scene->registerMaterial($materials); // 将的自发光材质注册到 scene 中
$obj->setMaterial($materials); // 为 面片光001 指定一个自发光材质
$scene->registerObjects($obj); // 将 面片光001 注册到 scene 中
// 2、创建 面片光002
$obj = new objects\Objects(); // 创建 面片光002 的实体
$obj->ply = './ply/面光.002.ply'; // 指定 面片光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( // 设置发光属性
[
'gain' => "30 30 30", // 设置发光增益
]
);
$scene->registerMaterial($materials); // 将的自发光材质注册到 scene 中
$obj->setMaterial($materials); // 为 面片光002 指定一个自发光材质
$scene->registerObjects($obj); // 将 面片光002 注册到 scene 中
// 3、创建 面片光003
$obj = new objects\Objects(); // 创建 面片光003 的实体
$obj->ply = './ply/面光.003.ply'; // 指定 面片光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( // 设置发光属性
[
'gain' => "50 50 50", // 设置发光增益
]
);
$scene->registerMaterial($materials); // 将的自发光材质注册到 scene 中
$obj->setMaterial($materials); // 为 面片光003 指定一个自发光材质
$scene->registerObjects($obj); // 将 面片光003 注册到 scene 中
// 4、创建 面片光004
$obj = new objects\Objects(); // 创建 面片光004 的实体
$obj->ply = './ply/面光.004.ply'; // 指定 面片光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( // 设置发光属性
[
'gain' => "4 4 4", // 设置发光增益
]
);
$scene->registerMaterial($materials); // 将的自发光材质注册到 scene 中
$obj->setMaterial($materials); // 为 面片光004 指定一个自发光材质
$scene->registerObjects($obj); // 将 面片光004 注册到 scene 中
// 5、创建 面片光005
$obj = new objects\Objects(); // 创建 面片光005 的实体
$obj->ply = './ply/面光.005.ply'; // 指定 面片光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( // 设置发光属性
[
'gain' => "10 10 10", // 设置发光增益
]
);
$scene->registerMaterial($materials); // 将的自发光材质注册到 scene 中
$obj->setMaterial($materials); // 为 面片光005 指定一个自发光材质
$scene->registerObjects($obj); // 将 面片光005 注册到 scene 中
// 6、创建 面片光006
$obj = new objects\Objects(); // 创建 面片光006 的实体
$obj->ply = './ply/面光.006.ply'; // 指定 面片光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( // 设置发光属性
[
'gain' => "8 8 8", // 设置发光增益
'mapfile' => "SD-037.exr", // 加载一个光域文件
'gamma' => 1, // 设置校正光域文件的gamma值
'storage' => "float" // 声明光域文件表示色值的数据类型
]
);
$scene->registerMaterial($materials); // 将的自发光材质注册到 scene 中
$obj->setMaterial($materials); // 为 面片光006 指定一个自发光材质
$scene->registerObjects($obj); // 将 面片光006 注册到 scene 中
// 7、创建 面片光006
$obj = new objects\Objects(); // 创建 面片光 的实体
$obj->ply = './ply/面光.ply'; // 指定 面片光 实体网格数据
$materials = new materials\Matte(); // 创建一个材质
$materials->setBaseColor('0 0 0'); // 设置材质的漫反射
$materials->setTransparencyShadow('1 1 1'); // 设置材质产生阴影的透明度
$materials->setEmission('1 1 1'); // 设置材质为一个自发光材质,并指定发光颜色
$materials->emissionCfg = new lights\Emission( // 设置发光属性
[
'gain' => "3.3 3.3 3.3", // 设置发光增益
]
);
$scene->registerMaterial($materials); // 将的自发光材质注册到 scene 中
$obj->setMaterial($materials); // 为 面片光 指定一个自发光材质
$scene->registerObjects($obj); // 将 面片光 注册到 scene 中
// 8、创建环境光
$light = new lights\env\HdrImage( // new 一个环境光对象
[
'gain' => "1.25 1.25 1.25", // 设置颜色增益
'transformation' => "0.1736481 -0.9848078 0 0 -0.9848078 -0.1736481 0 0 0 0 1 0 0 0 0 1", //设置对象变换
'file' => "env.png", // 加载一个全景图像文件
'gamma' => 1, // 设置一个校正全景图像文件的 gamma 值
'storage' => "byte" // 声明这个图像文件表示色值的数据类型
]
);
$scene->registerLight($light); // 将环境光注册到 scene 中
// 二、加载要渲染的模型
include dirname(dirname(__FILE__)) . "/vendor/autoload.php";
$scene = new Scene();
//添加第一个模型
$obj = new objects\Objects( [ 'ply' => 'mesh-10086.ply','appliedtransformation' => '1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1' ] ); //创建一个的模型
// //添加第一个模型
// $obj = new objects\Objects( [ 'ply' => 'mesh-10086.ply','appliedtransformation' => '1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1' ] ); //创建一个的模型
$cloudsMap = new texture\procedural\BlenderClouds(); //创建一个 Clouds类的贴图对象
$scene->registerTexture($cloudsMap); //将这个对象注册到 Scene
// $cloudsMap = new texture\procedural\BlenderClouds(); //创建一个 Clouds类的贴图对象
// $scene->registerTexture($cloudsMap); //将这个对象注册到 Scene
$imageMap = new texture\procedural\ImageMap(); //创建一个 ImageMap类的贴图对象
$scene->registerTexture($imageMap); //将这个对象注册到 Scene
// $imageMap = new texture\procedural\ImageMap(); //创建一个 ImageMap类的贴图对象
// $scene->registerTexture($imageMap); //将这个对象注册到 Scene
$blend = new texture\procedural\BlenderBlend(); //创建一个 Blend类的贴图对象
$scene->registerTexture($blend); //将这个对象注册到 Scene
// $blend = new texture\procedural\BlenderBlend(); //创建一个 Blend类的贴图对象
// $scene->registerTexture($blend); //将这个对象注册到 Scene
$disney = new materials\Disney(); //创建一个 Disney 材质对象
$disney->setBaseColor($cloudsMap); //为 basecolor 指定一个贴图对象,如果这个对象没有注册到Scene,则 set函数抛出异常,以下同理
$disney->setMetallic($blend);
$disney->setBumptex($imageMap);
$scene->registerMaterial($disney); //将这个对象注册到 Scene
// $disney = new materials\Disney(); //创建一个 Disney 材质对象
// $disney->setBaseColor($cloudsMap); //为 basecolor 指定一个贴图对象,如果这个对象没有注册到Scene,则 set函数抛出异常,以下同理
// $disney->setMetallic($blend);
// $disney->setBumptex($imageMap);
// $scene->registerMaterial($disney); //将这个对象注册到 Scene
$metal = new materials\Metal(); //创建一个 Disney 材质对象
$metal->setBumptex($cloudsMap);
$scene->registerMaterial($metal); //将这个对象注册到 Scene
// $metal = new materials\Metal(); //创建一个 Disney 材质对象
// $metal->setBumptex($cloudsMap);
// $scene->registerMaterial($metal); //将这个对象注册到 Scene
$mix = new materials\Mix(); //创建 Mix 材质对象
$mix->setMaterial1($disney); //为材质通道1 指定一个键名
$mix->setMaterial2($metal); //为材质通道2 指定一个键名
$mix->setAmount($blend ); //指定混合系数为 0.6
$scene->registerMaterial($mix); //将这个对象注册到 Scene
// $mix = new materials\Mix(); //创建 Mix 材质对象
// $mix->setMaterial1($disney); //为材质通道1 指定一个键名
// $mix->setMaterial2($metal); //为材质通道2 指定一个键名
// $mix->setAmount($blend ); //指定混合系数为 0.6
// $scene->registerMaterial($mix); //将这个对象注册到 Scene
$obj->setMaterial($mix) ; //为模型的指定一个混合材质
$scene->registerObjects($obj); //将模型添加到场景中
// $obj->setMaterial($mix) ; //为模型的指定一个混合材质
// $scene->registerObjects($obj); //将模型添加到场景中
//添加第二个模型
$obj = new objects\Objects( [ 'ply' => 'mesh-119.ply','appliedtransformation' => '1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1' ] ); //创建一个的模型,
$scene->registerObjects($obj); //将模型添加到场景中
// //添加第二个模型
// $obj = new objects\Objects( [ 'ply' => 'mesh-119.ply','appliedtransformation' => '1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1' ] ); //创建一个的模型,
// $scene->registerObjects($obj); //将模型添加到场景中
//添加第三个模型
$obj = new objects\Objects( [ 'ply' => 'mesh-119.ply','appliedtransformation' => '1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1' ] ); //创建一个的模型,
$scene->registerObjects($obj); //将模型添加到场景中
// //添加第三个模型
// $obj = new objects\Objects( [ 'ply' => 'mesh-119.ply','appliedtransformation' => '1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1' ] ); //创建一个的模型,
// $scene->registerObjects($obj); //将模型添加到场景中
//添加第四个模型
$obj = new objects\Objects( [ 'ply' => 'mesh-119.ply','appliedtransformation' => '1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1' ] ); //创建一个的模型,
// //添加第四个模型
// $obj = new objects\Objects( [ 'ply' => 'mesh-119.ply','appliedtransformation' => '1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1' ] ); //创建一个的模型,
$ClearVol = new volumes\Clear(); //创建一个 Clear体积效果
$scene->registerVolume($ClearVol); //将体积效果注册到Scene
// $ClearVol = new volumes\Clear(); //创建一个 Clear体积效果
// $scene->registerVolume($ClearVol); //将体积效果注册到Scene
$colorGlass = new materials\Glass(); //创建一个玻璃材质,
$colorGlass->setVolumeInterior($ClearVol); //将 Clear体积效果赋值到玻璃材质 的 体积属性
$scene->registerMaterial($colorGlass); //将玻璃材质注册到 Scene
// $colorGlass = new materials\Glass(); //创建一个玻璃材质,
// $colorGlass->setVolumeInterior($ClearVol); //将 Clear体积效果赋值到玻璃材质 的 体积属性
// $scene->registerMaterial($colorGlass); //将玻璃材质注册到 Scene
$obj->setMaterial($colorGlass); //将玻璃材质赋值到模型的材质属性
$scene->registerObjects($obj); //将模型添加到场景中
// $obj->setMaterial($colorGlass); //将玻璃材质赋值到模型的材质属性
// $scene->registerObjects($obj); //将模型添加到场景中
//添加一个世界对象
$default = new world\WorldDefault();
$default->setDefaultVolume($ClearVol);
// //添加一个世界对象
// $default = new world\WorldDefault();
// $default->setDefaultVolume($ClearVol);
$scene->registerWorld($default);
// $scene->registerWorld($default);
//添加一个相机
$camera = new camera\Perspective();
$scene->registerCamera($camera);
// //添加一个相机
// $camera = new camera\Perspective();
// $scene->registerCamera($camera);
echo $scene; echo $scene;

3
src/scene/lights/Emission.php

@ -87,14 +87,13 @@ class Emission extends BaseCfg
/** /**
* @var integer 当前灯光的ID号(取值:大于0的整数) * @var integer 当前灯光的ID号(取值:大于0的整数)
*/ */
public $id;
public $id = 0;
/** /**
* @param array $config 接收一个数组,可以初始化当前实例化对象的各种属性 * @param array $config 接收一个数组,可以初始化当前实例化对象的各种属性
*/ */
public function __construct($config = []) public function __construct($config = [])
{ {
$this->id = Scene::createID();
Base::__construct($config); Base::__construct($config);
} }

2
src/scene/lights/LightBase.php

@ -11,7 +11,7 @@ class LightBase extends BaseCfg
*/ */
const TYPE_CONSTANTINFINITE = 'constantinfinite'; //单一纯色的天光 const TYPE_CONSTANTINFINITE = 'constantinfinite'; //单一纯色的天光
const TYPE_SKY2 = 'sky2'; //模拟自然的天光 const TYPE_SKY2 = 'sky2'; //模拟自然的天光
const TYPE_INFINITE = 'infinite'; //HDR图像模拟的
const TYPE_INFINITE = 'infinite'; //HDR图像模拟的
const TYPE_DISTANT = 'distant'; //遥远的恒星 const TYPE_DISTANT = 'distant'; //遥远的恒星
const TYPE_SUN = 'sun'; //太阳 const TYPE_SUN = 'sun'; //太阳
const TYPE_SPHERE = 'sphere'; //球形光或点光 const TYPE_SPHERE = 'sphere'; //球形光或点光

8
src/scene/materials/MaterialsBase.php

@ -158,6 +158,14 @@ class MaterialsBase extends BaseCfg
$this->bumptex = $this->judgeAttribute($color); $this->bumptex = $this->judgeAttribute($color);
} }
/**
* @param object $color 接收一个贴图对象或小数形式的色值,设置材质的凹凸属性
*/
public function setTransparencyShadow($color)
{
$this->transparencyShadow = $this->judgeAttribute($color);
}
/** /**
* @param object $color 接收一个贴图对象或小数形式的色值,设置材质的自发光属性,并初始化自发光属性的配置参数 * @param object $color 接收一个贴图对象或小数形式的色值,设置材质的自发光属性,并初始化自发光属性的配置参数
*/ */

2
src/scene/objects/Objects.php

@ -36,7 +36,7 @@ class Objects extends BaseCfg
/** /**
* @var string 一个山16个数据组成模型的变换参数,包抱位置坐标,旋转参数,缩放参数 * @var string 一个山16个数据组成模型的变换参数,包抱位置坐标,旋转参数,缩放参数
*/ */
public $appliedtransformation;
public $appliedtransformation = '1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1';
/** /**
* @param array $config 接收一个数组,可以初始化当前实例化对象的各种属性 * @param array $config 接收一个数组,可以初始化当前实例化对象的各种属性

Loading…
Cancel
Save