blobt
3 years ago
11 changed files with 217 additions and 28 deletions
-
4.vscode/launch.json
-
21examples/print.php
-
8examples/test.php
-
9src/Base.php
-
9src/OpenCL.php
-
18src/core/Base.php
-
58src/scene/BaseCfg.php
-
37src/scene/OpenCL.php
-
9src/scene/Path.php
-
14src/scene/PathDepth.php
-
58src/utils/StringHelper.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; |
@ -1,8 +0,0 @@ |
|||
<?php |
|||
include dirname(dirname(__FILE__)) . "/vendor/autoload.php"; |
|||
|
|||
use Blobt\Luxcore\OpenCL; |
|||
|
|||
$opencl = new OpenCL(); |
|||
|
|||
echo $opencl; |
@ -1,9 +0,0 @@ |
|||
<?php |
|||
|
|||
namespace Blobt\Luxcore; |
|||
|
|||
class Base { |
|||
public function __toString(){ |
|||
return "sasasasa"; |
|||
} |
|||
} |
@ -1,9 +0,0 @@ |
|||
<?php |
|||
|
|||
namespace Blobt\Luxcore; |
|||
|
|||
class OpenCL extends Base{ |
|||
public $cpuUse; |
|||
public $gpuUse; |
|||
} |
|||
?>
|
@ -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; |
|||
} |
|||
} |
|||
} |
|||
} |
@ -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; |
|||
} |
|||
} |
@ -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; |
|||
} |
|||
} |
@ -0,0 +1,9 @@ |
|||
<?php |
|||
|
|||
namespace Blobt\Luxcore\scene; |
|||
|
|||
class Path extends BaseCfg |
|||
{ |
|||
public $pathdepth = null; |
|||
|
|||
} |
@ -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; |
|||
} |
@ -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); |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue