Browse Source

修改了“print.php”、“Scene.php”类文件

master
yuanjiajia 3 years ago
parent
commit
07f65dd7a6
  1. 17
      examples/print.php
  2. 41
      src/scene/Scene.php

17
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->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); //将模型添加到场景中 $scene->addobjects($obj); //将模型添加到场景中
@ -105,6 +110,6 @@ $scene->addObject($obj); //将模型添加到场景中
*/ */
//echo $scene;
echo $scene;
?> ?>

41
src/scene/Scene.php

@ -40,54 +40,25 @@ class Scene extends BaseCfg
public function addobjects($obj) public function addobjects($obj)
{ {
$temp = null;
$attributeArr = get_object_vars($obj);
$className = get_class($obj);
$className = array_reverse(explode('\\', $className))[0];
switch($className)
{
case 'Objects':
$temp = null;
$temp = sprintf("%014d",count($this->objects)+1); $temp = sprintf("%014d",count($this->objects)+1);
$this->objects[$temp] = $obj; $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 )
public function addmaterial($material)
{ {
$obj->$key = $this->addobjects( $value );
}
}
$temp = null;
$temp = $material->type.'_'.sprintf("%014d",count($this->materials)+1);
$this->materials[$temp] = $material;
return $temp; return $temp;
} }
/* /*
public function addObject( object $object ) public function addObject( object $object )
{ {

Loading…
Cancel
Save