Browse Source

架构初步实现

master
blobt 3 years ago
parent
commit
dcc6b8b7a9
  1. 4
      .vscode/launch.json
  2. 21
      examples/print.php
  3. 8
      examples/test.php
  4. 9
      src/Base.php
  5. 9
      src/OpenCL.php
  6. 18
      src/core/Base.php
  7. 58
      src/scene/BaseCfg.php
  8. 37
      src/scene/OpenCL.php
  9. 9
      src/scene/Path.php
  10. 14
      src/scene/PathDepth.php
  11. 58
      src/utils/StringHelper.php

4
.vscode/launch.json

@ -11,8 +11,8 @@
"name": "Launch currently open script", "name": "Launch currently open script",
"type": "php", "type": "php",
"request": "launch", "request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"program": "${workspaceFolder}/examples/print.php",
"cwd": "${workspaceFolder}",
"port": 9055 "port": 9055
} }
] ]

21
examples/print.php

@ -0,0 +1,21 @@
<?php
namespace Blobt\Luxcore\scene;
include dirname(dirname(__FILE__)) . "/vendor/autoload.php";
$opencl = new OpenCL();
$opencl->useGpu();
echo $opencl;
$pathDepth = new PathDepth([
"total" => 12
]);
$depth = new Path([
"pathdepth" => $pathDepth
]);
echo $depth;

8
examples/test.php

@ -1,8 +0,0 @@
<?php
include dirname(dirname(__FILE__)) . "/vendor/autoload.php";
use Blobt\Luxcore\OpenCL;
$opencl = new OpenCL();
echo $opencl;

9
src/Base.php

@ -1,9 +0,0 @@
<?php
namespace Blobt\Luxcore;
class Base {
public function __toString(){
return "sasasasa";
}
}

9
src/OpenCL.php

@ -1,9 +0,0 @@
<?php
namespace Blobt\Luxcore;
class OpenCL extends Base{
public $cpuUse;
public $gpuUse;
}
?>

18
src/core/Base.php

@ -0,0 +1,18 @@
<?php
namespace Blobt\Luxcore\core;
class Base
{
/**
* 实现自动配置
*/
public function __construct($config = [])
{
if (!empty($config)) {
foreach ($config as $name => $value) {
$this->$name = $value;
}
}
}
}

58
src/scene/BaseCfg.php

@ -0,0 +1,58 @@
<?php
namespace Blobt\Luxcore\scene;
use Blobt\Luxcore\core\Base;
use Blobt\Luxcore\utils\StringHelper;
class BaseCfg extends Base
{
public function __toString()
{
return $this->toString();
}
public function toString($parentClassName = false)
{
$object = new \ReflectionClass($this);
$properties = $object->getProperties();
//获取类名 -> 去除命名空间 -> 转成全小写
$className = get_called_class();
$className = strtolower(array_reverse(explode('\\', $className))[0]);
if (!empty($parentClassName)) {
$className = "{$parentClassName}.$className";
}
$ret = "";
foreach ($properties as $item) {
$item->setAccessible(true);
//获取属性名称,并根据驼峰规则截开后从新用‘.’连接
$name = $item->getName();
$name = implode(".", array_map('strtolower', StringHelper::camelStrToArray($name)));
$value = $item->getValue($this);
if (is_string($value)) {
$ret .= "{$className}.{$name} = \"{$value}\"\n";
} else if (is_integer($value)) {
$ret .= "{$className}.{$name} = {$value}\n";
} else if (is_bool($value)) {
$value = $value ? 1 : 0;
$ret .= "{$className}.{$name} = {$value}\n";
} else if (is_object($value) && $value instanceof BaseCfg) {
$ret .= $value->toString($className);
} else if(is_null($value)){
$ret .= "{$className}.{$name} = \"null\"\n";
} else
{
$ret .= "{$className}.{$name} = \"unknow type\"\n";
}
}
return $ret;
}
}

37
src/scene/OpenCL.php

@ -0,0 +1,37 @@
<?php
namespace Blobt\Luxcore\scene;
class OpenCL extends BaseCfg
{
//打开或关闭
const OPEN = 1;
const CLOSE = 0;
/**
* @var integral 是否使用cpu渲染,默认是
*/
private $cpuUse = self::OPEN;
/**
* @var integral 是否使用gpu渲染,默认否
*/
private $gpuUse = self::CLOSE;
/**
* 使用cpu渲染
*/
public function useCpu(){
$this->cpuUse = self::OPEN;
$this->gpuUse = self::CLOSE;
}
/**
* 使用gpu渲染
*/
public function useGpu(){
$this->cpuUse = self::CLOSE;
$this->gpuUse = self::OPEN;
}
}

9
src/scene/Path.php

@ -0,0 +1,9 @@
<?php
namespace Blobt\Luxcore\scene;
class Path extends BaseCfg
{
public $pathdepth = null;
}

14
src/scene/PathDepth.php

@ -0,0 +1,14 @@
<?php
namespace Blobt\Luxcore\scene;
class PathDepth extends BaseCfg
{
public $total = 11;
public $diffuse = 5;
public $glossy = 11;
public $specular = 10;
}

58
src/utils/StringHelper.php

@ -0,0 +1,58 @@
<?php
namespace Blobt\Luxcore\utils;
class StringHelper
{
static public function functionNameStrToArray($functionNameStr)
{
$functionNameArray = null;
$functionNameTemp = null;
if ($functionNameStr != null) {
$strLen = strlen($functionNameStr);
/*
检查字符串内不能包含 英文字母及“_” 以外的字符
*/
for ($i = 0; $i < $strLen; $i++) {
if (!((ord($functionNameStr[$i]) >= 65) && (ord($functionNameStr[$i]) <= 122)) && ($functionNameStr[$i] != "_")) {
echo '解析错误: 函数名称 存在非法字符 “' . $functionNameStr[$i] . '”' . "\n";
return null;
}
}
/*
将函数名字符串,以大写的首字母为分割,转换成数组
*/
for ($i = 0; $i < $strLen; $i++) {
$functionNameTemp[] = $functionNameStr[$i];
if (((ord(substr($functionNameStr, $i + 1, 1)) >= 65) && (ord(substr($functionNameStr, $i + 1, 1)) <= 90)) || ($i == $strLen - 1)) {
$functionNameTemp = implode($functionNameTemp);
$functionNameArray[] = $functionNameTemp;
$functionNameTemp = null;
}
}
return $functionNameArray;
} else {
echo '解析错误:函数名称字符串不能为空' . "\n";
return null;
}
}
/**
* 把驼峰命名字符串截成数组
*/
static public function camelStrToArray($str)
{
if (!is_string($str)) {
throw new \Exception("Expected parameter 2 to be an string");
}
return preg_split("/(?=[A-Z])/", $str);
}
}
Loading…
Cancel
Save