From 07f65dd7a6e70fdc0ff8df5e7fd04e6cb29ad0f7 Mon Sep 17 00:00:00 2001 From: yuanjiajia <1139393632@qq.com> Date: Mon, 28 Feb 2022 17:43:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E2=80=9Cprint.php?= =?UTF-8?q?=E2=80=9D=E3=80=81=E2=80=9CScene.php=E2=80=9D=E7=B1=BB=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/print.php | 17 ++++++++++------ src/scene/Scene.php | 47 +++++++++------------------------------------ 2 files changed, 20 insertions(+), 44 deletions(-) diff --git a/examples/print.php b/examples/print.php index faddc77..08b5028 100644 --- a/examples/print.php +++ b/examples/print.php @@ -83,15 +83,20 @@ $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' ] ); //创建一个的模型, -$mix = new materials\Mix(); //创建一个 Mix材质, +$material1 = new materials\Disney(); //创建一个 Disney 材质 +$material2 = new materials\Metal(); //创建一个 Metal 材质 +$material1 = $scene->addmaterial($material1); //将材质存入材质数组,并获得其键名 +$material2 = $scene->addmaterial($material2); //将材质存入材质数组,并获得其键名 -$mix->material1 = new materials\Disney();//指定混合材质的第一个材质为 Disney -$mix->material2 = new materials\Metal();//指定混合材质的第一个材质为 Metal +$mix = new materials\Mix(); //创建 Mix 材质, +$mix->material1 = $material1; //为材质通道1 指定一个键名 +$mix->material2 = $material2; //为材质通道2 指定一个键名 $mix->amount = 0.6; //指定混合系数为 0.6 +$mix = $scene->addmaterial($mix); //将材质存入材质数组,并获得其键名 -$obj->material = $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); //将模型添加到场景中 @@ -105,6 +110,6 @@ $scene->addObject($obj); //将模型添加到场景中 */ -//echo $scene; +echo $scene; ?> diff --git a/src/scene/Scene.php b/src/scene/Scene.php index ac53d6c..03abd44 100644 --- a/src/scene/Scene.php +++ b/src/scene/Scene.php @@ -40,54 +40,25 @@ class Scene extends BaseCfg public function addobjects($obj) { + $temp = null; - $attributeArr = get_object_vars($obj); + $temp = sprintf("%014d",count($this->objects)+1); + $this->objects[$temp] = $obj; - $className = get_class($obj); - $className = array_reverse(explode('\\', $className))[0]; + } + public function addmaterial($material) + { - - switch($className) - { - case 'Objects': - $temp = sprintf("%014d",count($this->objects)+1); - $this->objects[$temp] = $obj; - break; - - case 'MaterialsBase': - $temp = $obj->type.'_'.sprintf("%014d",count($this->materials)+1); - $this->materials[$temp] = $obj; - break; - - case 'VolumesBase': - $temp = $obj->type.'_'.sprintf("%014d",count($this->volumes)+1); - $this->volumes[$temp] = $obj; - break; - - case 'TextureBase': - $temp = $obj->type.'_'.sprintf("%014d",count($this->textures)+1); - $this->textures[$temp] = $obj; - break; - - default: - break; - } - - foreach( $attributeArr as $key => $value) - { - if( $value instanceof texture\TextureBase || $value instanceof materials\MaterialsBase || $value instanceof volumes\VolumesBase ) - { - $obj->$key = $this->addobjects( $value ); - } - } + $temp = null; + $temp = $material->type.'_'.sprintf("%014d",count($this->materials)+1); + $this->materials[$temp] = $material; return $temp; } - /* public function addObject( object $object ) {