diff --git a/examples/print.php b/examples/print.php index b83710c..a81f6da 100644 --- a/examples/print.php +++ b/examples/print.php @@ -61,33 +61,37 @@ echo $film; $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; ?> diff --git a/src/scene/BaseCfg.php b/src/scene/BaseCfg.php index c08a1c8..cd23be2 100644 --- a/src/scene/BaseCfg.php +++ b/src/scene/BaseCfg.php @@ -30,7 +30,7 @@ class BaseCfg extends Base $object = new \ReflectionClass($this); $properties = $object->getProperties(); - + //echo '>>>>>>>>>>'."\n"; //获取类名 -> 去除命名空间 -> 转成全小写 $className = get_called_class(); @@ -74,7 +74,10 @@ class BaseCfg extends Base break; case 'object': - $ret .= $value->toString($className); + if($name != 'conn' && $className != 'scene') + { + $ret .= $value->toString($className); + } break; case 'NULL': diff --git a/src/scene/Scene.php b/src/scene/Scene.php index c5d91bc..be5d940 100644 --- a/src/scene/Scene.php +++ b/src/scene/Scene.php @@ -1,39 +1,47 @@ type = 'disney'; + $this->type = self::TYPE_DISNEY; $this->emissionCfg = new Emission($config); $this->visibility = new Visibility($config); Base::__construct($config); } - + } ?> diff --git a/src/scene/materials/Glossy.php b/src/scene/materials/Glossy.php index c738dc2..07e2bd4 100644 --- a/src/scene/materials/Glossy.php +++ b/src/scene/materials/Glossy.php @@ -6,6 +6,8 @@ use Blobt\Luxcore\core\Base; class Glossy extends MaterialsBase { + const TYPE_GLOSSY = 'glossy'; + /** * @var string 漫反射颜色,一个小数形式的RGB色值,或是一个textures(贴图数组)中的某个键名 */ @@ -64,7 +66,7 @@ class Glossy extends MaterialsBase public function __construct($config = []) { - $this->type = 'glossy2'; + $this->type = self::TYPE_GLOSSY; $this->emissionCfg = new Emission($config); $this->visibility = new Visibility($config); Base::__construct($config); diff --git a/src/scene/materials/MaterialsBase.php b/src/scene/materials/MaterialsBase.php index 97d76dd..7fdaaab 100644 --- a/src/scene/materials/MaterialsBase.php +++ b/src/scene/materials/MaterialsBase.php @@ -4,14 +4,19 @@ namespace Blobt\Luxcore\scene\materials; use Blobt\Luxcore\core\Base; use Blobt\Luxcore\scene\BaseCfg; +use Blobt\Luxcore\scene\Scene; + +use function PHPSTORM_META\type; class MaterialsBase extends BaseCfg { + const TYPE_MATTE = 'matte'; + /** * @var string 材质类型 */ - public $type = "matte"; + public $type = self::TYPE_MATTE; /** * @var string 此参数控制材质与光线作用时,产生阴影的透明度,或控制阴影的颜色(取值,小数形式的色值) @@ -79,6 +84,13 @@ class MaterialsBase extends BaseCfg */ public $volumeExterior; + public function __toString() + { + $temp = $this->type.'_'.sprintf("%09d",count(Scene::$conn->materials)+1); + Scene::$conn->materials[$temp] = $this; + return $temp; + } + } ?> diff --git a/src/scene/materials/Metal.php b/src/scene/materials/Metal.php index 5df183a..0510335 100644 --- a/src/scene/materials/Metal.php +++ b/src/scene/materials/Metal.php @@ -6,6 +6,8 @@ use Blobt\Luxcore\core\Base; class Metal extends MaterialsBase { + const TYPE_METAL = 'matal'; + /** * @var string 菲列尔参数,一个textures(贴图数组)中的某个键名,只能是“fresnelconst(预设的菲列尔参数)”、 * “fresnelcolor(颜色的菲列尔)”两个类型的帖图。 @@ -39,7 +41,7 @@ class Metal extends MaterialsBase public function __construct($config = []) { - $this->type = 'metal2'; + $this->type = self::TYPE_METAL; $this->emissionCfg = new Emission($config); $this->visibility = new Visibility($config); Base::__construct($config); diff --git a/src/scene/materials/Mix.php b/src/scene/materials/Mix.php index 7f1b035..19e8133 100644 --- a/src/scene/materials/Mix.php +++ b/src/scene/materials/Mix.php @@ -5,6 +5,7 @@ use Blobt\Luxcore\core\Base; class Mix extends MaterialsBase { + const TYPE_MIX = 'mix'; /** * @var string 材质1,(材质数组的某个键名) @@ -28,7 +29,7 @@ class Mix extends MaterialsBase public function __construct($config = []) { - $this->type = 'mix'; + $this->type = self::TYPE_MIX; $this->emissionCfg = new Emission($config); $this->visibility = new Visibility($config); Base::__construct($config); diff --git a/src/scene/materials/NullMaterial.php b/src/scene/materials/NullMaterial.php index 028ab0f..84aa2d5 100644 --- a/src/scene/materials/NullMaterial.php +++ b/src/scene/materials/NullMaterial.php @@ -6,6 +6,8 @@ use Blobt\Luxcore\core\Base; class NullMaterial extends MaterialsBase { + const TYPE_NULL = 'null'; + /** * @var float 前向不透明度,一个0-1的小数,或是一个textures(贴图数组)中的某个键名 */ @@ -23,7 +25,7 @@ class NullMaterial extends MaterialsBase public function __construct($config = []) { - $this->type = 'null'; + $this->type = self::TYPE_NULL; $this->emissionCfg = new Emission($config); $this->visibility = new Visibility($config); Base::__construct($config); diff --git a/src/scene/materials/Roughmatte.php b/src/scene/materials/Roughmatte.php index 0ff327f..3d95f30 100644 --- a/src/scene/materials/Roughmatte.php +++ b/src/scene/materials/Roughmatte.php @@ -6,6 +6,8 @@ use Blobt\Luxcore\core\Base; class Roughmatte extends MaterialsBase { + const TYPE_ROUGHMATTE = 'roughmatte'; + /** * @var string 漫反射颜色,一个小数形式的RGB色值,或是一个textures(贴图数组)中的某个键名 */ @@ -33,7 +35,7 @@ class Roughmatte extends MaterialsBase public function __construct($config = []) { - $this->type = 'roughmatte'; + $this->type = self::TYPE_ROUGHMATTE; $this->emissionCfg = new Emission($config); $this->visibility = new Visibility($config); Base::__construct($config); diff --git a/src/scene/objects/Objects.php b/src/scene/objects/Objects.php index 83432b9..053e034 100644 --- a/src/scene/objects/Objects.php +++ b/src/scene/objects/Objects.php @@ -9,7 +9,7 @@ class Objects extends BaseCfg /** * @var string 对应的材质数组键名 */ - public $material; + public string $material; /** * @var string 对应的ply网格文件名称 @@ -31,6 +31,11 @@ class Objects extends BaseCfg */ public $appliedtransformation; + public function __construct() + { + $this->id = rand(0,1000000); + } + } ?>