diff --git a/examples/print.php b/examples/print.php index 08b5028..de9be08 100644 --- a/examples/print.php +++ b/examples/print.php @@ -86,19 +86,19 @@ $scene = new Scene();//创建一个场景, $material1 = new materials\Disney(); //创建一个 Disney 材质 $material2 = new materials\Metal(); //创建一个 Metal 材质 -$material1 = $scene->addmaterial($material1); //将材质存入材质数组,并获得其键名 -$material2 = $scene->addmaterial($material2); //将材质存入材质数组,并获得其键名 +$material1 = $scene->setMaterial($material1); //将材质存入材质数组,并获得其键名 +$material2 = $scene->setMaterial($material2); //将材质存入材质数组,并获得其键名 $mix = new materials\Mix(); //创建 Mix 材质, $mix->material1 = $material1; //为材质通道1 指定一个键名 $mix->material2 = $material2; //为材质通道2 指定一个键名 $mix->amount = 0.6; //指定混合系数为 0.6 -$mix = $scene->addmaterial($mix); //将材质存入材质数组,并获得其键名 +$mix = $scene->setMaterial($mix); //将材质存入材质数组,并获得其键名 $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->material = $mix; //为模型的材属性 指定一个键名 -$scene->addobjects($obj); //将模型添加到场景中 +$scene->setObjects($obj); //将模型添加到场景中 /* diff --git a/src/scene/Scene.php b/src/scene/Scene.php index 03abd44..f832425 100644 --- a/src/scene/Scene.php +++ b/src/scene/Scene.php @@ -35,27 +35,64 @@ class Scene extends BaseCfg /** * @var array 相机数组 */ - private $camera = []; + private $cameras = []; + + public static function createID() + { + static $num = 0; + $num++; + return $num; + } - public function addobjects($obj) + public function setObjects($obj) { - $temp = null; - $temp = sprintf("%014d",count($this->objects)+1); + $temp = sprintf("%014d",$obj->id); $this->objects[$temp] = $obj; - } - public function addmaterial($material) + public function setMaterial($material) { - $temp = null; - $temp = $material->type.'_'.sprintf("%014d",count($this->materials)+1); + $temp = $material->type.'_'.sprintf("%014d",$material->id); $this->materials[$temp] = $material; return $temp; + } + + public function setTexture($texture) + { + $temp = null; + $temp = $texture->type.'_'.sprintf("%014d",$texture->id); + $this->textures[$temp] = $texture; + return $temp; + } + + public function setVolume($volume) + { + $temp = null; + $temp = $volume->type.'_'.sprintf("%014d",$volume->id); + $this->volumes[$temp] = $volume; + return $temp; + } + + public function setLight($light) + { + $temp = null; + $temp = $light->type.'_'.sprintf("%014d",$light->id); + $this->lights[$temp] = $light; + return $temp; + } + + public function setCamera($camera) + { + $temp = null; + $temp = $camera->type.'_'.sprintf("%014d",$camera->id); + $this->cameras[$temp] = $camera; + return $temp; } + diff --git a/src/scene/camera/Camera.php b/src/scene/camera/Camera.php index 07db399..54b4264 100644 --- a/src/scene/camera/Camera.php +++ b/src/scene/camera/Camera.php @@ -2,11 +2,17 @@ namespace Blobt\Luxcore\scene\camera; use Blobt\Luxcore\scene\BaseCfg; +use Blobt\Luxcore\scene\Scene; +use Blobt\Luxcore\core\Base; class Camera extends BaseCfg { - + public function __construct($config = []) + { + $this->id = Scene::createID(); + Base::__construct($config); + } } diff --git a/src/scene/light/LigthBase.php b/src/scene/light/LigthBase.php index 0f410ee..3d636bf 100644 --- a/src/scene/light/LigthBase.php +++ b/src/scene/light/LigthBase.php @@ -2,11 +2,18 @@ namespace Blobt\Luxcore\scene\ligth; use Blobt\Luxcore\scene\BaseCfg; +use Blobt\Luxcore\scene\Scene; +use Blobt\Luxcore\core\Base; class LightBase extends BaseCfg { + public function __construct($config = []) + { + $this->id = Scene::createID(); + Base::__construct($config); + } } diff --git a/src/scene/materials/Disney.php b/src/scene/materials/Disney.php index 61cabe8..7e59577 100644 --- a/src/scene/materials/Disney.php +++ b/src/scene/materials/Disney.php @@ -2,6 +2,8 @@ namespace Blobt\Luxcore\scene\materials; use Blobt\Luxcore\core\Base; +use Blobt\Luxcore\scene\Scene; + class Disney extends MaterialsBase { @@ -96,6 +98,7 @@ class Disney extends MaterialsBase public function __construct($config = []) { $this->type = self::TYPE_DISNEY; + $this->id = Scene::createID(); $this->emissionCfg = new Emission($config); $this->visibility = new Visibility($config); Base::__construct($config); diff --git a/src/scene/materials/Glass.php b/src/scene/materials/Glass.php index f14da6c..4a64da4 100644 --- a/src/scene/materials/Glass.php +++ b/src/scene/materials/Glass.php @@ -2,6 +2,7 @@ namespace Blobt\Luxcore\scene\materials; use Blobt\Luxcore\core\Base; +use Blobt\Luxcore\scene\Scene; class Glass extends MaterialsBase { @@ -79,6 +80,7 @@ class Glass extends MaterialsBase public function __construct($config = []) { $this->type = self::TYPE_GLASS; + $this->id = Scene::createID(); $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 07e2bd4..735d11d 100644 --- a/src/scene/materials/Glossy.php +++ b/src/scene/materials/Glossy.php @@ -2,6 +2,7 @@ namespace Blobt\Luxcore\scene\materials; use Blobt\Luxcore\core\Base; +use Blobt\Luxcore\scene\Scene; class Glossy extends MaterialsBase { @@ -67,6 +68,7 @@ class Glossy extends MaterialsBase public function __construct($config = []) { $this->type = self::TYPE_GLOSSY; + $this->id = Scene::createID(); $this->emissionCfg = new Emission($config); $this->visibility = new Visibility($config); Base::__construct($config); diff --git a/src/scene/materials/Metal.php b/src/scene/materials/Metal.php index 0510335..1f748ab 100644 --- a/src/scene/materials/Metal.php +++ b/src/scene/materials/Metal.php @@ -2,6 +2,7 @@ namespace Blobt\Luxcore\scene\materials; use Blobt\Luxcore\core\Base; +use Blobt\Luxcore\scene\Scene; class Metal extends MaterialsBase { @@ -42,6 +43,7 @@ class Metal extends MaterialsBase public function __construct($config = []) { $this->type = self::TYPE_METAL; + $this->id = Scene::createID(); $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 19e8133..ff49ee2 100644 --- a/src/scene/materials/Mix.php +++ b/src/scene/materials/Mix.php @@ -2,6 +2,7 @@ namespace Blobt\Luxcore\scene\materials; use Blobt\Luxcore\core\Base; +use Blobt\Luxcore\scene\Scene; class Mix extends MaterialsBase { @@ -30,6 +31,7 @@ class Mix extends MaterialsBase public function __construct($config = []) { $this->type = self::TYPE_MIX; + $this->id = Scene::createID(); $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 84aa2d5..2a834ca 100644 --- a/src/scene/materials/NullMaterial.php +++ b/src/scene/materials/NullMaterial.php @@ -2,6 +2,7 @@ namespace Blobt\Luxcore\scene\materials; use Blobt\Luxcore\core\Base; +use Blobt\Luxcore\scene\Scene; class NullMaterial extends MaterialsBase { @@ -26,6 +27,7 @@ class NullMaterial extends MaterialsBase public function __construct($config = []) { $this->type = self::TYPE_NULL; + $this->id = Scene::createID(); $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 3d95f30..dceff8a 100644 --- a/src/scene/materials/Roughmatte.php +++ b/src/scene/materials/Roughmatte.php @@ -2,6 +2,7 @@ namespace Blobt\Luxcore\scene\materials; use Blobt\Luxcore\core\Base; +use Blobt\Luxcore\scene\Scene; class Roughmatte extends MaterialsBase { @@ -36,6 +37,7 @@ class Roughmatte extends MaterialsBase public function __construct($config = []) { $this->type = self::TYPE_ROUGHMATTE; + $this->id = Scene::createID(); $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 83bdb02..4f4a83a 100644 --- a/src/scene/objects/Objects.php +++ b/src/scene/objects/Objects.php @@ -3,6 +3,7 @@ namespace Blobt\Luxcore\scene\objects; use Blobt\Luxcore\core\Base; use Blobt\Luxcore\scene\BaseCfg; +use Blobt\Luxcore\scene\Scene; class Objects extends BaseCfg { @@ -34,7 +35,7 @@ class Objects extends BaseCfg public function __construct($config = []) { - $this->id = rand(0,1000000); + $this->id = Scene::createID(); Base::__construct($config); } diff --git a/src/scene/texture/TextureBase.php b/src/scene/texture/TextureBase.php index bd0cdc0..eac2cb4 100644 --- a/src/scene/texture/TextureBase.php +++ b/src/scene/texture/TextureBase.php @@ -2,11 +2,18 @@ namespace Blobt\Luxcore\scene\texture; use Blobt\Luxcore\scene\BaseCfg; +use Blobt\Luxcore\scene\Scene; +use Blobt\Luxcore\core\Base; class TextureBase extends BaseCfg { + public function __construct($config = []) + { + $this->id = Scene::createID(); + Base::__construct($config); + } } diff --git a/src/scene/volumes/VolumesBase.php b/src/scene/volumes/VolumesBase.php index 2128ec8..7829231 100644 --- a/src/scene/volumes/VolumesBase.php +++ b/src/scene/volumes/VolumesBase.php @@ -2,11 +2,18 @@ namespace Blobt\Luxcore\scene\volumes; use Blobt\Luxcore\scene\BaseCfg; +use Blobt\Luxcore\scene\Scene; +use Blobt\Luxcore\core\Base; class VolumesBase extends BaseCfg { + public function __construct($config = []) + { + $this->id = Scene::createID(); + Base::__construct($config); + } }