Browse Source

新增了关于贴图、相机、灯光、体积材质的类文件,“scene.php”添加addobject()函数,解决模型、材质、贴图自对应问题

master
yuanjiajia 3 years ago
parent
commit
45c172a6c7
  1. 38
      examples/print.php
  2. 4
      src/scene/BaseCfg.php
  3. 67
      src/scene/Scene.php
  4. 13
      src/scene/camera/Camera.php
  5. 13
      src/scene/light/LigthBase.php
  6. 12
      src/scene/materials/MaterialsBase.php
  7. 8
      src/scene/objects/Objects.php
  8. 13
      src/scene/texture/TextureBase.php
  9. 13
      src/scene/volumes/VolumesBase.php

38
examples/print.php

@ -4,6 +4,7 @@
namespace Blobt\Luxcore\scene;
use Blobt\Luxcore\scene\materials;
use Blobt\Luxcore\scene\materials\Disney;
use Blobt\Luxcore\scene\objects\Objects;
include dirname(dirname(__FILE__)) . "/vendor/autoload.php";
@ -58,38 +59,35 @@ $film->imagepipelines[5] = [new effect\NoiseReducerOIDN(),new effect\Pretreatmen
echo $film;
*/
$scene = new Scene();//创建一个场景,
//添加第一个模型
$mix = new materials\Mix(); //在场景中创建一个 Mix材质,
$mix->material1 = 'wood1'; //指定混合材质的第一个材质为 wood1
$mix->material2 = 'wood2'; //指定混合材质的第二个材质为 wood2
$mix->amount = 0.6; //指定混合系数为 0.6
$obj = new Objects( [ 'ply' => 'mesh-10086.ply','appliedtransformation' => '1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1' ] ); //创建一个的模型,
$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'; //设置模型的位值参数
$mix = new materials\Mix(); //创建一个 Mix材质,
$scene->objects[] = $obj; //将模型添加到场景中
$mix->material1 = new materials\Disney();//指定混合材质的第一个材质为 Disney
$mix->material2 = new materials\Metal();//指定混合材质的第一个材质为 Metal
$mix->amount = 0.6; //指定混合系数为 0.6
$obj->material = $mix; //为模型赋予这个混合材质
$scene->addobject($obj); //将模型添加到场景中
//添加第二个模型
$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; //将模型添加到场景中
//添加第二个模型
$obj = new Objects( [ 'ply' => 'mesh-119.ply','appliedtransformation' => '1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1' ] ); //创建一个的模型,
$obj->material = new materials\Metal( ['fresnel' => "2517393611944Fresnel"] ); //为模型创建一个 金属 类型的材质
$scene->addobject($obj); //将模型添加到场景中
echo $scene;

4
src/scene/BaseCfg.php

@ -3,16 +3,12 @@
namespace Blobt\Luxcore\scene;
use Blobt\Luxcore\core\Base;
use Blobt\Luxcore\utils\StringHelper;
class BaseCfg extends Base
{

67
src/scene/Scene.php

@ -1,46 +1,87 @@
<?php
namespace Blobt\Luxcore\scene;
use Blobt\Luxcore\scene\objects\Objects;
class Scene extends BaseCfg
{
public static $conn;
/**
* @var array 模型数组
*/
public $objects = [];
private $objects = [];
/**
* @var array 材质数组
*/
public $materials = [];
private $materials = [];
/**
* @var array 体积材质数组
* @var array 贴图数组
*/
public $volumes = [];
private $textures = [];
/**
* @var array 贴图数组
* @var array 体积材质数组
*/
public $textures = [];
private $volumes = [];
/**
* @var array 灯光数组
*/
public $light = [];
private $lights = [];
/**
* @var array 相机数组
*/
public $camera = [];
private $camera = [];
public function __construct()
public function addobject( object $object )
{
$temp = null;
$attributeArr = get_object_vars($object);
if( $object instanceof objects\Objects )
{
$temp = 'obj_'.sprintf("%014d",count($this->objects)+1);
$this->objects[$temp] = $object;
}
else if( $object instanceof materials\MaterialsBase )
{
$temp = 'material_'.sprintf("%014d",count($this->materials)+1);
$this->materials[$temp] = $object;
}
else if($object instanceof ligth\LightBase)
{
self::$conn = $this;
$temp = 'light_'.sprintf("%014d",count($this->lights)+1);
$this->lights[$temp] = $object;
}
else if($object instanceof camera\Camera)
{
$temp = 'camera_'.sprintf("%014d",count($this->camera)+1);
$this->camera[$temp] = $object;
}
else if($object instanceof texture\TextureBase)
{
$temp = 'texture_'.sprintf("%014d",count($this->textures)+1);
$this->textures[$temp] = $object;
}
else if( $object instanceof volumes\VolumesBase )
{
$temp = 'volume_'.sprintf("%014d",count($this->volumes)+1);
$this->volumes[$temp] = $object;
}
else;
foreach( $attributeArr as $key => $value)
{
if( $value instanceof texture\TextureBase || $value instanceof materials\MaterialsBase || $value instanceof volumes\VolumesBase )
{
$object->$key = $this->addobject( $value );
}
}
return $temp;
}
}

13
src/scene/camera/Camera.php

@ -0,0 +1,13 @@
<?php
namespace Blobt\Luxcore\scene\camera;
use Blobt\Luxcore\scene\BaseCfg;
class Camera extends BaseCfg
{
}
?>

13
src/scene/light/LigthBase.php

@ -0,0 +1,13 @@
<?php
namespace Blobt\Luxcore\scene\ligth;
use Blobt\Luxcore\scene\BaseCfg;
class LightBase extends BaseCfg
{
}
?>

12
src/scene/materials/MaterialsBase.php

@ -1,12 +1,9 @@
<?php
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
{
@ -84,13 +81,6 @@ 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;
}
}
?>

8
src/scene/objects/Objects.php

@ -1,6 +1,7 @@
<?php
namespace Blobt\Luxcore\scene\objects;
use Blobt\Luxcore\core\Base;
use Blobt\Luxcore\scene\BaseCfg;
class Objects extends BaseCfg
@ -9,7 +10,7 @@ class Objects extends BaseCfg
/**
* @var string 对应的材质数组键名
*/
public string $material;
public $material;
/**
* @var string 对应的ply网格文件名称
@ -19,7 +20,7 @@ class Objects extends BaseCfg
/**
* @var bool 是否对摄相机可见
*/
public $camerainvisible;
public $camerainvisible = false;
/**
* @var integer 模型的ID(取值:大于0的整数)
@ -31,9 +32,10 @@ class Objects extends BaseCfg
*/
public $appliedtransformation;
public function __construct()
public function __construct($config = [])
{
$this->id = rand(0,1000000);
Base::__construct($config);
}
}

13
src/scene/texture/TextureBase.php

@ -0,0 +1,13 @@
<?php
namespace Blobt\Luxcore\scene\texture;
use Blobt\Luxcore\scene\BaseCfg;
class TextureBase extends BaseCfg
{
}
?>

13
src/scene/volumes/VolumesBase.php

@ -0,0 +1,13 @@
<?php
namespace Blobt\Luxcore\scene\volumes;
use Blobt\Luxcore\scene\BaseCfg;
class VolumesBase extends BaseCfg
{
}
?>
Loading…
Cancel
Save