Browse Source

修改了“Scene.php”、“Material.php”两类文件,以实现材质自对应

master
yuanjiajia 3 years ago
parent
commit
495372440f
  1. 42
      examples/print.php
  2. 7
      src/scene/BaseCfg.php
  3. 20
      src/scene/Scene.php
  4. 6
      src/scene/materials/Disney.php
  5. 4
      src/scene/materials/Glossy.php
  6. 14
      src/scene/materials/MaterialsBase.php
  7. 4
      src/scene/materials/Metal.php
  8. 3
      src/scene/materials/Mix.php
  9. 4
      src/scene/materials/NullMaterial.php
  10. 4
      src/scene/materials/Roughmatte.php
  11. 7
      src/scene/objects/Objects.php

42
examples/print.php

@ -61,33 +61,37 @@ echo $film;
$scene = new Scene();//创建一个场景, $scene = new Scene();//创建一个场景,
$scene->materials[7] = new materials\Mix(); //在场景中创建一个编号为7的 Mix材质,
$scene->materials[7]->material1 = 'wood1'; //指定混合材质的第一个材质为 wood1
$scene->materials[7]->material2 = 'wood2'; //指定混合材质的第二个材质为 wood2
$scene->materials[7]->amount = 0.6; //指定混合系数为 0.6
$scene->objects[0] = new Objects(); //在场景中创建一个编号为0的模型,
$scene->objects[0]->material = 7; //为模型指定编号为7的材质
$scene->objects[0]->ply = 'mesh-00000.ply'; //为模型指定网格
$scene->objects[0]->camerainvisible = false; //是否对摄像机隐藏,
$scene->objects[0]->id = 10086; //为模型指定ID
$scene->objects[0]->appliedtransformation = '1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1'; //设置模型的位值参数
//添加第一个模型
$mix = new materials\Mix(); //在场景中创建一个 Mix材质,
$mix->material1 = 'wood1'; //指定混合材质的第一个材质为 wood1
$mix->material2 = 'wood2'; //指定混合材质的第二个材质为 wood2
$mix->amount = 0.6; //指定混合系数为 0.6
$obj = new Objects(); //创建一个的模型,
$obj->material = $mix; //为模型指定一个材质
$obj->ply = 'mesh-00000.ply'; //为模型指定网格
$obj->camerainvisible = false; //是否对摄像机隐藏,
$obj->id = 10086; //为模型指定ID
$obj->appliedtransformation = '1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1'; //设置模型的位值参数
$scene->objects[] = $obj; //将模型添加到场景中
$scene->materials[8] = new materials\Metal(); //在场景中创建一个编号为8的 Metal材质,
$scene->materials[8]->fresnel = "2517393611944Fresnel"; //指定金属材质菲列尔参数为一个颜色类型的贴图
$scene->objects[1] = new Objects(); //在场景中创建一个编号为1的模型,
$scene->objects[1]->material = 8; //为模型指定编号为8的材质
$scene->objects[1]->ply = 'mesh-119.ply'; //为模型指定网格
$scene->objects[1]->camerainvisible = false; //是否对摄像机隐藏,
$scene->objects[1]->id = 911; //为模型指定ID
$scene->objects[1]->appliedtransformation = '1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1'; //设置模型的位值参数
//添加第二个模型
$metal = new materials\Metal(); //创建一个 金属 类型的材质
$metal->fresnel = "2517393611944Fresnel"; //指定金属材质菲列尔参数为一个颜色类型的贴图
$obj = new Objects(); //创建一个的模型,
$obj->material = $metal; //为模型指定一个材质
$obj->ply = 'mesh-119.ply'; //为模型指定网格
$obj->camerainvisible = false; //是否对摄像机隐藏,
$obj->appliedtransformation = '1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1'; //设置模型的位值参数
$scene->objects[] = $obj; //将模型添加到场景中
echo $scene;
echo $scene;
?> ?>

7
src/scene/BaseCfg.php

@ -30,7 +30,7 @@ class BaseCfg extends Base
$object = new \ReflectionClass($this); $object = new \ReflectionClass($this);
$properties = $object->getProperties(); $properties = $object->getProperties();
//echo '>>>>>>>>>>'."\n";
//获取类名 -> 去除命名空间 -> 转成全小写 //获取类名 -> 去除命名空间 -> 转成全小写
$className = get_called_class(); $className = get_called_class();
@ -74,7 +74,10 @@ class BaseCfg extends Base
break; break;
case 'object': case 'object':
$ret .= $value->toString($className);
if($name != 'conn' && $className != 'scene')
{
$ret .= $value->toString($className);
}
break; break;
case 'NULL': case 'NULL':

20
src/scene/Scene.php

@ -1,39 +1,47 @@
<?php <?php
namespace Blobt\Luxcore\scene; namespace Blobt\Luxcore\scene;
use Blobt\Luxcore\scene\objects\Objects;
class Scene extends BaseCfg class Scene extends BaseCfg
{ {
public static $conn;
/** /**
* @var array 模型数组 * @var array 模型数组
*/ */
public $objects;
public $objects = [];
/** /**
* @var array 材质数组 * @var array 材质数组
*/ */
public $materials;
public $materials = [];
/** /**
* @var array 体积材质数组 * @var array 体积材质数组
*/ */
public $volumes;
public $volumes = [];
/** /**
* @var array 贴图数组 * @var array 贴图数组
*/ */
public $textures;
public $textures = [];
/** /**
* @var array 灯光数组 * @var array 灯光数组
*/ */
public $light;
public $light = [];
/** /**
* @var array 相机数组 * @var array 相机数组
*/ */
public $camera;
public $camera = [];
public function __construct()
{
self::$conn = $this;
}
} }

6
src/scene/materials/Disney.php

@ -6,6 +6,8 @@ use Blobt\Luxcore\core\Base;
class Disney extends MaterialsBase class Disney extends MaterialsBase
{ {
const TYPE_DISNEY = 'disney';
/** /**
* @var string 漫反射颜色,一个小数形式的RGB色值,或是一个textures(贴图数组)中的某个键名 * @var string 漫反射颜色,一个小数形式的RGB色值,或是一个textures(贴图数组)中的某个键名
*/ */
@ -93,12 +95,12 @@ class Disney extends MaterialsBase
public function __construct($config = []) public function __construct($config = [])
{ {
$this->type = 'disney';
$this->type = self::TYPE_DISNEY;
$this->emissionCfg = new Emission($config); $this->emissionCfg = new Emission($config);
$this->visibility = new Visibility($config); $this->visibility = new Visibility($config);
Base::__construct($config); Base::__construct($config);
} }
} }
?> ?>

4
src/scene/materials/Glossy.php

@ -6,6 +6,8 @@ use Blobt\Luxcore\core\Base;
class Glossy extends MaterialsBase class Glossy extends MaterialsBase
{ {
const TYPE_GLOSSY = 'glossy';
/** /**
* @var string 漫反射颜色,一个小数形式的RGB色值,或是一个textures(贴图数组)中的某个键名 * @var string 漫反射颜色,一个小数形式的RGB色值,或是一个textures(贴图数组)中的某个键名
*/ */
@ -64,7 +66,7 @@ class Glossy extends MaterialsBase
public function __construct($config = []) public function __construct($config = [])
{ {
$this->type = 'glossy2';
$this->type = self::TYPE_GLOSSY;
$this->emissionCfg = new Emission($config); $this->emissionCfg = new Emission($config);
$this->visibility = new Visibility($config); $this->visibility = new Visibility($config);
Base::__construct($config); Base::__construct($config);

14
src/scene/materials/MaterialsBase.php

@ -4,14 +4,19 @@ namespace Blobt\Luxcore\scene\materials;
use Blobt\Luxcore\core\Base; use Blobt\Luxcore\core\Base;
use Blobt\Luxcore\scene\BaseCfg; use Blobt\Luxcore\scene\BaseCfg;
use Blobt\Luxcore\scene\Scene;
use function PHPSTORM_META\type;
class MaterialsBase extends BaseCfg class MaterialsBase extends BaseCfg
{ {
const TYPE_MATTE = 'matte';
/** /**
* @var string 材质类型 * @var string 材质类型
*/ */
public $type = "matte";
public $type = self::TYPE_MATTE;
/** /**
* @var string 此参数控制材质与光线作用时,产生阴影的透明度,或控制阴影的颜色(取值,小数形式的色值) * @var string 此参数控制材质与光线作用时,产生阴影的透明度,或控制阴影的颜色(取值,小数形式的色值)
@ -79,6 +84,13 @@ class MaterialsBase extends BaseCfg
*/ */
public $volumeExterior; public $volumeExterior;
public function __toString()
{
$temp = $this->type.'_'.sprintf("%09d",count(Scene::$conn->materials)+1);
Scene::$conn->materials[$temp] = $this;
return $temp;
}
} }
?> ?>

4
src/scene/materials/Metal.php

@ -6,6 +6,8 @@ use Blobt\Luxcore\core\Base;
class Metal extends MaterialsBase class Metal extends MaterialsBase
{ {
const TYPE_METAL = 'matal';
/** /**
* @var string 菲列尔参数,一个textures(贴图数组)中的某个键名,只能是“fresnelconst(预设的菲列尔参数)”、 * @var string 菲列尔参数,一个textures(贴图数组)中的某个键名,只能是“fresnelconst(预设的菲列尔参数)”、
* “fresnelcolor(颜色的菲列尔)”两个类型的帖图。 * “fresnelcolor(颜色的菲列尔)”两个类型的帖图。
@ -39,7 +41,7 @@ class Metal extends MaterialsBase
public function __construct($config = []) public function __construct($config = [])
{ {
$this->type = 'metal2';
$this->type = self::TYPE_METAL;
$this->emissionCfg = new Emission($config); $this->emissionCfg = new Emission($config);
$this->visibility = new Visibility($config); $this->visibility = new Visibility($config);
Base::__construct($config); Base::__construct($config);

3
src/scene/materials/Mix.php

@ -5,6 +5,7 @@ use Blobt\Luxcore\core\Base;
class Mix extends MaterialsBase class Mix extends MaterialsBase
{ {
const TYPE_MIX = 'mix';
/** /**
* @var string 材质1,(材质数组的某个键名) * @var string 材质1,(材质数组的某个键名)
@ -28,7 +29,7 @@ class Mix extends MaterialsBase
public function __construct($config = []) public function __construct($config = [])
{ {
$this->type = 'mix';
$this->type = self::TYPE_MIX;
$this->emissionCfg = new Emission($config); $this->emissionCfg = new Emission($config);
$this->visibility = new Visibility($config); $this->visibility = new Visibility($config);
Base::__construct($config); Base::__construct($config);

4
src/scene/materials/NullMaterial.php

@ -6,6 +6,8 @@ use Blobt\Luxcore\core\Base;
class NullMaterial extends MaterialsBase class NullMaterial extends MaterialsBase
{ {
const TYPE_NULL = 'null';
/** /**
* @var float 前向不透明度,一个0-1的小数,或是一个textures(贴图数组)中的某个键名 * @var float 前向不透明度,一个0-1的小数,或是一个textures(贴图数组)中的某个键名
*/ */
@ -23,7 +25,7 @@ class NullMaterial extends MaterialsBase
public function __construct($config = []) public function __construct($config = [])
{ {
$this->type = 'null';
$this->type = self::TYPE_NULL;
$this->emissionCfg = new Emission($config); $this->emissionCfg = new Emission($config);
$this->visibility = new Visibility($config); $this->visibility = new Visibility($config);
Base::__construct($config); Base::__construct($config);

4
src/scene/materials/Roughmatte.php

@ -6,6 +6,8 @@ use Blobt\Luxcore\core\Base;
class Roughmatte extends MaterialsBase class Roughmatte extends MaterialsBase
{ {
const TYPE_ROUGHMATTE = 'roughmatte';
/** /**
* @var string 漫反射颜色,一个小数形式的RGB色值,或是一个textures(贴图数组)中的某个键名 * @var string 漫反射颜色,一个小数形式的RGB色值,或是一个textures(贴图数组)中的某个键名
*/ */
@ -33,7 +35,7 @@ class Roughmatte extends MaterialsBase
public function __construct($config = []) public function __construct($config = [])
{ {
$this->type = 'roughmatte';
$this->type = self::TYPE_ROUGHMATTE;
$this->emissionCfg = new Emission($config); $this->emissionCfg = new Emission($config);
$this->visibility = new Visibility($config); $this->visibility = new Visibility($config);
Base::__construct($config); Base::__construct($config);

7
src/scene/objects/Objects.php

@ -9,7 +9,7 @@ class Objects extends BaseCfg
/** /**
* @var string 对应的材质数组键名 * @var string 对应的材质数组键名
*/ */
public $material;
public string $material;
/** /**
* @var string 对应的ply网格文件名称 * @var string 对应的ply网格文件名称
@ -31,6 +31,11 @@ class Objects extends BaseCfg
*/ */
public $appliedtransformation; public $appliedtransformation;
public function __construct()
{
$this->id = rand(0,1000000);
}
} }
?> ?>
Loading…
Cancel
Save