|
|
<?php
namespace Blobt\Luxcore\scene; //use function PHPSTORM_META\type;
use Blobt\Luxcore\utils\StringHelper;
class Scene extends BaseCfg {
/** * @var array 模型数组 */ private $objects = [];
/** * @var array 材质数组 */ private $materials = [];
/** * @var array 贴图数组 */ private $textures = [];
/** * @var array 体积材质数组 */ private $volumes = [];
/** * @var array 灯光数组 */ private $lights = [];
/** * @var array 相机数组 */ private $cameras = [];
/** * @var array 世界对象数组 */ public $world = [];
/** * 为每个需要存到Scene的实例化对象生成一个唯一的ID */ public static function createID() { static $num = 0; $num++; return $num; }
/** * @param object $obj 接收一个模型类对象,为其颁发一个注册信息,并将其存到Scene */ public function registerObjects(&$obj) { $id = sprintf("%014d",$obj->id); $obj->registerId = $id; if($obj->material == null) { if( !array_key_exists('__default',$this->materials ) ) { $this->materials['__default'] = new materials\Matte(); } $obj->material = '__default'; } $this->objects[$id] = $obj; }
/** * @param object $material 接收一个材质类对象,为其颁发一个注册信息,并将其存到Scene */ public function registerMaterial(&$material) { $id = $material->type.'_'.sprintf("%014d",$material->id); $material->registerId = $id; $this->materials[$id] = $material; }
/** * @param object $texture 接收一个纹理类对象,为其颁发一个注册信息,并将其存到Scene */ public function registerTexture(&$texture) { $id = $texture->type.'_'.sprintf("%014d",$texture->id); $texture->registerId = $id; $this->textures[$id] = $texture; } /** * @param object $volume 接收一个体积类对象,为其颁发一个注册信息,并将其存到Scene */ public function registerVolume(&$volume) { $id = $volume->type.'_'.sprintf("%014d",$volume->id); $volume->registerId = $id; $this->volumes[$id] = $volume; }
/** * @param object $light 接收一个灯光类对象,为其颁发一个注册信息,并将其存到Scene */ public function registerLight(&$light) { $id = $light->type.'_'.sprintf("%014d",$light->id); $light->registerId = $id; $this->lights[$id] = $light; }
/** * @param object $camera 接收一个相机类对象,为其颁发一个注册信息,并将其存到Scene */ public function registerCamera(&$camera) { $this->cameras = []; foreach( get_object_vars($camera) as $key => $value ) { if($value != null) { $key = implode(".", array_map('strtolower', StringHelper::camelStrToArray($key))); $this->cameras[$key] = $value; } } }
/** * @param object $camera 接收一个World类对象,为其颁发一个注册信息,并将其存到Scene */ public function registerWorld(&$world) { foreach( get_object_vars($world) as $key => $value ) { if($value != null) { $key = implode(".", array_map('strtolower', StringHelper::camelStrToArray($key))); $this->world[$key] = $value; } } }
}
?>
|