Blender渲染
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
3.7 KiB

  1. <?php
  2. namespace Blobt\Luxcore\scene;
  3. //use function PHPSTORM_META\type;
  4. use Blobt\Luxcore\utils\StringHelper;
  5. class Scene extends BaseCfg
  6. {
  7. /**
  8. * @var array 模型数组
  9. */
  10. private $objects = [];
  11. /**
  12. * @var array 材质数组
  13. */
  14. private $materials = [];
  15. /**
  16. * @var array 贴图数组
  17. */
  18. private $textures = [];
  19. /**
  20. * @var array 体积材质数组
  21. */
  22. private $volumes = [];
  23. /**
  24. * @var array 灯光数组
  25. */
  26. private $lights = [];
  27. /**
  28. * @var array 相机数组
  29. */
  30. private $cameras = [];
  31. /**
  32. * @var array 世界对象数组
  33. */
  34. public $world = [];
  35. /**
  36. * 为每个需要存到Scene的实例化对象生成一个唯一的ID
  37. */
  38. public static function createID()
  39. {
  40. static $num = 0;
  41. $num++;
  42. return $num;
  43. }
  44. /**
  45. * @param object $obj 接收一个模型类对象,为其颁发一个注册信息,并将其存到Scene
  46. */
  47. public function registerObjects(&$obj)
  48. {
  49. $id = sprintf("%014d",$obj->id);
  50. $obj->registerId = $id;
  51. if($obj->material == null)
  52. {
  53. if( !array_key_exists('__default',$this->materials ) )
  54. {
  55. $this->materials['__default'] = new materials\Matte();
  56. }
  57. $obj->material = '__default';
  58. }
  59. $this->objects[$id] = $obj;
  60. }
  61. /**
  62. * @param object $material 接收一个材质类对象,为其颁发一个注册信息,并将其存到Scene
  63. */
  64. public function registerMaterial(&$material)
  65. {
  66. $id = $material->type.'_'.sprintf("%014d",$material->id);
  67. $material->registerId = $id;
  68. $this->materials[$id] = $material;
  69. }
  70. /**
  71. * @param object $texture 接收一个纹理类对象,为其颁发一个注册信息,并将其存到Scene
  72. */
  73. public function registerTexture(&$texture)
  74. {
  75. $id = $texture->type.'_'.sprintf("%014d",$texture->id);
  76. $texture->registerId = $id;
  77. $this->textures[$id] = $texture;
  78. }
  79. /**
  80. * @param object $volume 接收一个体积类对象,为其颁发一个注册信息,并将其存到Scene
  81. */
  82. public function registerVolume(&$volume)
  83. {
  84. $id = $volume->type.'_'.sprintf("%014d",$volume->id);
  85. $volume->registerId = $id;
  86. $this->volumes[$id] = $volume;
  87. }
  88. /**
  89. * @param object $light 接收一个灯光类对象,为其颁发一个注册信息,并将其存到Scene
  90. */
  91. public function registerLight(&$light)
  92. {
  93. $id = $light->type.'_'.sprintf("%014d",$light->id);
  94. $light->registerId = $id;
  95. $this->lights[$id] = $light;
  96. }
  97. /**
  98. * @param object $camera 接收一个相机类对象,为其颁发一个注册信息,并将其存到Scene
  99. */
  100. public function registerCamera(&$camera)
  101. {
  102. $this->cameras = [];
  103. foreach( get_object_vars($camera) as $key => $value )
  104. {
  105. if($value != null)
  106. {
  107. $key = implode(".", array_map('strtolower', StringHelper::camelStrToArray($key)));
  108. $this->cameras[$key] = $value;
  109. }
  110. }
  111. }
  112. /**
  113. * @param object $camera 接收一个World类对象,为其颁发一个注册信息,并将其存到Scene
  114. */
  115. public function registerWorld(&$world)
  116. {
  117. foreach( get_object_vars($world) as $key => $value )
  118. {
  119. if($value != null)
  120. {
  121. $key = implode(".", array_map('strtolower', StringHelper::camelStrToArray($key)));
  122. $this->world[$key] = $value;
  123. }
  124. }
  125. }
  126. }
  127. ?>