Browse Source

新增一个 Texture类的类文件, Scene类的add函数修改为register函数,材质、模型、贴图、灯光、相机、体积材质类的set函数增加 异常抛出

master
yuanjiajia 3 years ago
parent
commit
6f0fd66d56
  1. 48
      examples/print.php
  2. 77
      src/scene/Scene.php
  3. 205
      src/scene/materials/Disney.php
  4. 20
      src/scene/materials/MaterialsBase.php
  5. 84
      src/scene/materials/Metal.php
  6. 38
      src/scene/materials/Mix.php
  7. 33
      src/scene/objects/Objects.php
  8. 5
      src/scene/texture/TextureBase.php
  9. 72
      src/scene/texture/map/Blend.php
  10. 7
      src/scene/texture/map/Clouds.php
  11. 2
      src/scene/texture/map/ImageMap.php
  12. 2
      src/scene/texture/mapping/Triplanar.php
  13. 2
      src/scene/texture/transform/NormalMap.php

48
examples/print.php

@ -11,7 +11,7 @@ use Blobt\Luxcore\scene\texture;
include dirname(dirname(__FILE__)) . "/vendor/autoload.php";
/*
echo '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>渲染配置参数>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>';
echo "\n\n\n\n";
@ -70,7 +70,7 @@ echo $film;
*/
@ -86,36 +86,38 @@ $scene = new Scene();//创建一个场景,
$obj = new objects\Objects( [ 'ply' => 'mesh-10086.ply','appliedtransformation' => '1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1' ] ); //创建一个的模型
$baseColor = new texture\map\Clouds( new texture\mapping\Mapping() );
$bump = new texture\map\ImageMap( new texture\mapping\Mapping() );
$ior = new texture\map\ImageMap( new texture\mapping\Mapping() );
$cloudsMap = new texture\map\Clouds( new texture\mapping\Mapping() ); //创建一个 Clouds类的贴图对象
//$scene->registerTexture($cloudsMap); //将这个对象注册到 Scene
$baseColor = $scene->addTexture($baseColor);
$bump = $scene->addTexture($bump);
$ior = $scene->addTexture($ior);
$imageMap = new texture\map\ImageMap( new texture\mapping\Mapping() ); //创建一个 ImageMap类的贴图对象
//$scene->registerTexture($imageMap); //将这个对象注册到 Scene
$disney = new materials\Disney(); //创建一个 Disney 材质
$disney->setBaseColor($baseColor);
$disney->setBumptex($bump);
$disney->setFilmior($ior);
$disney = $scene->addMaterial($disney); //将材质存入材质数组,并获得其键名
$blend = new texture\map\Blend( new texture\mapping\Mapping() ); //创建一个 Blend类的贴图对象
$scene->registerTexture($blend); //将这个对象注册到 Scene
$metal = new materials\Metal(); //创建一个 Metal 材质
$metal->setRefraction($baseColor);
$metal->setBumptex($bump);
$metal = $scene->addMaterial($metal); //将材质存入材质数组,并获得其键名
$disney = new materials\Disney(); //创建一个 Disney 材质对象
$disney->setBaseColor($cloudsMap); //为 basecolor 指定一个贴图对象,如果这个对象没有注册到Scenn,则 set函数抛出异常,以下同理
$disney->setMetallic($blend);
$disney->setBumptex($imageMap);
$scene->registerMaterial($disney); //将这个对象注册到 Scene
$mix = new materials\Mix(); //创建 Mix 材质,
$metal = new materials\Metal(); //创建一个 Disney 材质对象
$metal->setRefraction($imageMap);
$metal->setBumptex($cloudsMap);
$scene->registerMaterial($metal); //将这个对象注册到 Scene
$mix = new materials\Mix(); //创建 Mix 材质对象
$mix->setMaterial1($disney); //为材质通道1 指定一个键名
$mix->setMaterial2($metal); //为材质通道2 指定一个键名
$mix->setAmount($baseColor); //指定混合系数为 0.6
$mix = $scene->addMaterial($mix); //将材质存入材质数组,并获得其键名
$mix->setAmount($blend ); //指定混合系数为 0.6
$scene->registerMaterial($mix); //将这个对象注册到 Scene
$obj->setMaterial($mix) ; //为模型的材属性 指定一个键名
$scene->addObjects($obj); //将模型添加到场景中
$obj->setMaterial($mix) ; //为模型的指定一个混合材质
$scene->registerObjects($obj); //将模型添加到场景中
/*

77
src/scene/Scene.php

@ -45,108 +45,55 @@ class Scene extends BaseCfg
}
public function addObjects($obj)
public function registerObjects(&$obj)
{
$temp = null;
$temp = sprintf("%014d",$obj->id);
$obj->cards = $temp;
$this->objects[$temp] = $obj;
}
public function addMaterial($material)
public function registerMaterial(&$material)
{
$temp = null;
$temp = $material->type.'_'.sprintf("%014d",$material->id);
$material->cards = $temp;
$this->materials[$temp] = $material;
return $temp;
}
public function addTexture($texture)
public function registerTexture(&$texture)
{
$temp = null;
$temp = $texture->type.'_'.sprintf("%014d",$texture->id);
$texture->cards = $temp;
$this->textures[$temp] = $texture;
return $temp;
}
public function addVolume($volume)
public function registerVolume(&$volume)
{
$temp = null;
$temp = $volume->type.'_'.sprintf("%014d",$volume->id);
$volume->cards = $temp;
$this->volumes[$temp] = $volume;
return $temp;
}
public function addLight($light)
public function registerLight(&$light)
{
$temp = null;
$temp = $light->type.'_'.sprintf("%014d",$light->id);
$light->cards = $temp;
$this->lights[$temp] = $light;
return $temp;
}
public function addCamera($camera)
public function registerCamera(&$camera)
{
$temp = null;
$temp = $camera->type.'_'.sprintf("%014d",$camera->id);
$camera->cards = $temp;
$this->cameras[$temp] = $camera;
return $temp;
}
/*
public function addObject( object $object )
{
$temp = null;
$attributeArr = get_object_vars($object);
if( $object instanceof objects\Objects )
{
$temp = sprintf("%014d",count($this->objects)+1);
$this->objects[$temp] = $object;
}
else if( $object instanceof materials\MaterialsBase )
{
$temp = $object->type.'_'.sprintf("%014d",count($this->materials)+1);
$this->materials[$temp] = $object;
}
else if($object instanceof ligth\LightBase)
{
$temp = $object->type.'_'.sprintf("%014d",count($this->lights)+1);
$this->lights[$temp] = $object;
}
else if($object instanceof camera\Camera)
{
$temp = $object->type.'_'.sprintf("%014d",count($this->camera)+1);
$this->camera[$temp] = $object;
}
else if($object instanceof texture\TextureBase)
{
$temp = $object->type.'_'.sprintf("%014d",count($this->textures)+1);
$this->textures[$temp] = $object;
}
else if( $object instanceof volumes\VolumesBase )
{
$temp = $object->type.'_'.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;
}
*/
}
?>

205
src/scene/materials/Disney.php

@ -1,6 +1,8 @@
<?php
namespace Blobt\Luxcore\scene\materials;
use __PHP_Incomplete_Class;
use Blobt\Luxcore\core\Base;
use Blobt\Luxcore\scene\Scene;
@ -108,87 +110,256 @@ class Disney extends MaterialsBase
public function setBaseColor($color)
{
$this->basecolor = $color;
if( is_object($color) )
{
if( $color->cards != null ) $this->basecolor = $color->cards;
else
{
$backtrace = debug_backtrace();
$backtrace = $backtrace[0]['file'].':'.$backtrace[0]['line']."\n";
$this->printException($backtrace,$color);
}
}
else $this->basecolor = $color;
}
public function setSubsurface($color)
{
$this->subsurface = $color;
if( is_object($color) )
{
if( $color->cards != null ) $this->subsurface = $color->cards;
else
{
$backtrace = debug_backtrace();
$backtrace = $backtrace[0]['file'].':'.$backtrace[0]['line']."\n";
$this->printException($backtrace,$color);
}
}
else $this->subsurface = $color;
}
public function setMetallic($color)
{
$this->metallic = $color;
if( is_object($color) )
{
if( $color->cards != null ) $this->metallic = $color->cards;
else
{
$backtrace = debug_backtrace();
$backtrace = $backtrace[0]['file'].':'.$backtrace[0]['line']."\n";
$this->printException($backtrace,$color);
}
}
else $this->metallic = $color;
}
public function setSpecular($color)
{
$this->specular = $color;
if( is_object($color) )
{
if( $color->cards != null ) $this->specular = $color->cards;
else
{
$backtrace = debug_backtrace();
$backtrace = $backtrace[0]['file'].':'.$backtrace[0]['line']."\n";
$this->printException($backtrace,$color);
}
}
else $this->specular = $color;
}
public function setSpeculartint($color)
{
$this->speculartint = $color;
if( is_object($color) )
{
if( $color->cards != null ) $this->speculartint = $color->cards;
else
{
$backtrace = debug_backtrace();
$backtrace = $backtrace[0]['file'].':'.$backtrace[0]['line']."\n";
$this->printException($backtrace,$color);
}
}
else $this->speculartint = $color;
}
public function setRoughness($color)
{
$this->roughness = $color;
if( is_object($color) )
{
if( $color->cards != null ) $this->roughness = $color->cards;
else
{
$backtrace = debug_backtrace();
$backtrace = $backtrace[0]['file'].':'.$backtrace[0]['line']."\n";
$this->printException($backtrace,$color);
}
}
else $this->roughness = $color;
}
public function setAnisotropic($color)
{
$this->anisotropic = $color;
if( is_object($color) )
{
if( $color->cards != null ) $this->anisotropic = $color->cards;
else
{
$backtrace = debug_backtrace();
$backtrace = $backtrace[0]['file'].':'.$backtrace[0]['line']."\n";
$this->printException($backtrace,$color);
}
}
else $this->anisotropic = $color;
}
public function setSheen($color)
{
$this->sheen = $color;
if( is_object($color) )
{
if( $color->cards != null ) $this->sheen = $color->cards;
else
{
$backtrace = debug_backtrace();
$backtrace = $backtrace[0]['file'].':'.$backtrace[0]['line']."\n";
$this->printException($backtrace,$color);
}
}
else $this->sheen = $color;
}
public function setSheentint($color)
{
$this->sheentint = $color;
if( is_object($color) )
{
if( $color->cards != null ) $this->sheentint = $color->cards;
else
{
$backtrace = debug_backtrace();
$backtrace = $backtrace[0]['file'].':'.$backtrace[0]['line']."\n";
$this->printException($backtrace,$color);
}
}
else $this->sheentint = $color;
}
public function setClearcoat($color)
{
$this->clearcoat = $color;
if( is_object($color) )
{
if( $color->cards != null ) $this->clearcoat = $color->cards;
else
{
$backtrace = debug_backtrace();
$backtrace = $backtrace[0]['file'].':'.$backtrace[0]['line']."\n";
$this->printException($backtrace,$color);
}
}
else $this->clearcoat = $color;
}
public function setClearcoatgloss($color)
{
$this->clearcoatgloss = $color;
if( is_object($color) )
{
if( $color->cards != null ) $this->clearcoatgloss = $color->cards;
else
{
$backtrace = debug_backtrace();
$backtrace = $backtrace[0]['file'].':'.$backtrace[0]['line']."\n";
$this->printException($backtrace,$color);
}
}
else $this->clearcoatgloss = $color;
}
public function setTransparencyFront($color)
{
$this->transparencyFront = $color;
if( is_object($color) )
{
if( $color->cards != null ) $this->transparencyFront = $color->cards;
else
{
$backtrace = debug_backtrace();
$backtrace = $backtrace[0]['file'].':'.$backtrace[0]['line']."\n";
$this->printException($backtrace,$color);
}
}
else $this->transparencyFront = $color;
}
public function setTransparencyBack($color)
{
$this->transparencyBack = $color;
if( is_object($color) )
{
if( $color->cards != null ) $this->transparencyBack = $color->cards;
else
{
$backtrace = debug_backtrace();
$backtrace = $backtrace[0]['file'].':'.$backtrace[0]['line']."\n";
$this->printException($backtrace,$color);
}
}
else $this->transparencyBack = $color;
}
public function setFilmamount($color)
{
$this->filmamount = $color;
if( is_object($color) )
{
if( $color->cards != null ) $this->filmamount = $color->cards;
else
{
$backtrace = debug_backtrace();
$backtrace = $backtrace[0]['file'].':'.$backtrace[0]['line']."\n";
$this->printException($backtrace,$color);
}
}
else $this->filmamount = $color;
}
public function setFilmthickness($color)
{ if( is_object($color) )
{
if( $color->cards != null ) $this->filmthickness = $color->cards;
else
{
$this->filmthickness = $color;
$backtrace = debug_backtrace();
$backtrace = $backtrace[0]['file'].':'.$backtrace[0]['line']."\n";
$this->printException($backtrace,$color);
}
}
else $this->filmthickness = $color;
}
public function setFilmior($color)
{
$this->filmior = $color;
if( is_object($color) )
{
if( $color->cards != null ) $this->filmior = $color->cards;
else
{
$backtrace = debug_backtrace();
$backtrace = $backtrace[0]['file'].':'.$backtrace[0]['line']."\n";
$this->printException($backtrace,$color);
}
}
else $this->filmior = $color;
}
public function setBumptex($color)
{
$this->bumptex = $color;
if( is_object($color) )
{
if( $color->cards != null ) $this->bumptex = $color->cards;
else
{
$backtrace = debug_backtrace();
$backtrace = $backtrace[0]['file'].':'.$backtrace[0]['line']."\n";
$this->printException($backtrace,$color);
}
}
else $this->bumptex = $color;
}
}

20
src/scene/materials/MaterialsBase.php

@ -25,6 +25,11 @@ class MaterialsBase extends BaseCfg
*/
public $id;
/**
* @var bool 储存个由Scene类颁发的注册信息
*/
public $cards;
/**
* @var float TODO:采样距离,具体作用尚未明确,(固定取值:0.001
*/
@ -96,6 +101,21 @@ class MaterialsBase extends BaseCfg
$this->volumeExterior = $color;
}
protected function printException($backtrace,$temp)
{
try
{
$className = get_class($temp);
$className = array_reverse(explode('\\', $className))[0];
$backtrace .= "你为当前通道赋值是一个未注册的 {$className}对象,这会导致一个默认值的渲染结果!!!";
throw new \Exception($backtrace,0);
}
catch( \Exception $err )
{
echo '警告:在'.$err->getMessage()."\n\n";
}
}
}
?>

84
src/scene/materials/Metal.php

@ -54,39 +54,109 @@ class Metal extends MaterialsBase
public function setRefraction($color)
{
$this->kr = $color;
if( is_object($color) )
{
if( $color->cards != null ) $this->kr = $color->cards;
else
{
$backtrace = debug_backtrace();
$backtrace = $backtrace[0]['file'].':'.$backtrace[0]['line']."\n";
$this->printException($backtrace,$color);
}
}
else $this->kr = $color;
}
public function setFresnel($color)
{
$this->fresnel = $color;
if( is_object($color) )
{
if( $color->cards != null ) $this->fresnel = $color->cards;
else
{
$backtrace = debug_backtrace();
$backtrace = $backtrace[0]['file'].':'.$backtrace[0]['line']."\n";
$this->printException($backtrace,$color);
}
}
else $this->fresnel = $color;
}
public function setUroughness($color)
{
$this->uroughness = $color;
if( is_object($color) )
{
if( $color->cards != null ) $this->uroughness = $color->cards;
else
{
$backtrace = debug_backtrace();
$backtrace = $backtrace[0]['file'].':'.$backtrace[0]['line']."\n";
$this->printException($backtrace,$color);
}
}
else $this->uroughness = $color;
}
public function setVroughness($color)
{
$this->vroughness = $color;
if( is_object($color) )
{
if( $color->cards != null ) $this->vroughness = $color->cards;
else
{
$backtrace = debug_backtrace();
$backtrace = $backtrace[0]['file'].':'.$backtrace[0]['line']."\n";
$this->printException($backtrace,$color);
}
}
else $this->vroughness = $color;
}
public function setTransparencyFront($color)
{
$this->transparencyFront = $color;
if( is_object($color) )
{
if( $color->cards != null ) $this->transparencyFront = $color->cards;
else
{
$backtrace = debug_backtrace();
$backtrace = $backtrace[0]['file'].':'.$backtrace[0]['line']."\n";
$this->printException($backtrace,$color);
}
}
else $this->transparencyFront = $color;
}
public function setTransparencyBack($color)
{
$this->transparencyBack = $color;
if( is_object($color) )
{
if( $color->cards != null ) $this->transparencyBack = $color->cards;
else
{
$backtrace = debug_backtrace();
$backtrace = $backtrace[0]['file'].':'.$backtrace[0]['line']."\n";
$this->printException($backtrace,$color);
}
}
else $this->transparencyBack = $color;
}
public function setBumptex($color)
{
$this->bumptex = $color;
if( is_object($color) )
{
if( $color->cards != null ) $this->bumptex = $color->cards;
else
{
$backtrace = debug_backtrace();
$backtrace = $backtrace[0]['file'].':'.$backtrace[0]['line']."\n";
$this->printException($backtrace,$color);
}
}
else $this->bumptex = $color;
}
}

38
src/scene/materials/Mix.php

@ -37,17 +37,47 @@ class Mix extends MaterialsBase
public function setMaterial1($Material)
{
$this->material1 = $Material;
if( is_object( $Material ) )
{
if( $Material->cards != null ) $this->material1 = $Material->cards;
else
{
$backtrace = debug_backtrace();
$backtrace = $backtrace[0]['file'].':'.$backtrace[0]['line']."\n";
$this->printException($backtrace,$Material);
}
}
else $this->material1 = $Material;
}
public function setMaterial2($Material)
{
$this->material2 = $Material;
if( is_object( $Material ) )
{
if( $Material->cards != null ) $this->material2 = $Material->cards;
else
{
$backtrace = debug_backtrace();
$backtrace = $backtrace[0]['file'].':'.$backtrace[0]['line']."\n";
$this->printException($backtrace,$Material);
}
}
else $this->material2 = $Material;
}
public function setAmount($amount)
public function setAmount($color)
{
if( is_object($color) )
{
$this->amount = $amount;
if( $color->cards != null ) $this->amount = $color->cards;
else
{
$backtrace = debug_backtrace();
$backtrace = $backtrace[0]['file'].':'.$backtrace[0]['line']."\n";
$this->printException($backtrace,$color);
}
}
else $this->amount = $color;
}
}

33
src/scene/objects/Objects.php

@ -28,6 +28,11 @@ class Objects extends BaseCfg
*/
public $id;
/**
* @var string 储存个由Scene类颁发的注册信息
*/
public $cards;
/**
* @var string 一个山16个数据组成模型的变换参数,包抱位置坐标,旋转参数,缩放参数
*/
@ -41,8 +46,34 @@ class Objects extends BaseCfg
public function setMaterial($material)
{
$this->material = $material;
if( is_object( $material ) )
{
if( $material->cards != null ) $this->material = $material->cards;
else
{
$backtrace = debug_backtrace();
$backtrace = $backtrace[0]['file'].':'.$backtrace[0]['line']."\n";
$this->printException($backtrace,$material);
}
}
else $this->material = $material;
}
private function printException($backtrace,$temp)
{
try
{
$className = get_class($temp);
$className = array_reverse(explode('\\', $className))[0];
$backtrace .= "你为当前通道赋值是一个未注册的 {$className}对象,这会导致一个默认值的渲染结果!!!";
throw new \Exception($backtrace,0);
}
catch( \Exception $err )
{
echo '警告:在'.$err->getMessage()."\n\n";
}
}
}

5
src/scene/texture/TextureBase.php

@ -16,6 +16,11 @@ class TextureBase extends BaseCfg
* @var integer 当前贴图的ID号(取值:大于0的整数)
*/
public $id;
/**
* @var string 储存个由Scene类颁发的注册信息
*/
public $cards;
}
?>

72
src/scene/texture/map/Blend.php

@ -0,0 +1,72 @@
<?php
namespace Blobt\Luxcore\scene\texture\map;
use Blobt\Luxcore\scene\texture\TextureBase;
use Blobt\Luxcore\scene\Scene;
use Blobt\Luxcore\core\Base;
use Blobt\Luxcore\scene\texture\mapping\Mapping;
class Blend extends TextureBase
{
/**
* 程序贴图的类型
*/
const TYPE_BLENDER_BLEND = 'blender_blend';
/**
* 噪波的 柔和 锐利 类型
*/
const TYPE_HORIZONTAL = 'horizontal';
const TYPE_VERTICAL = 'vertical';
/**
* 噪波 基本效果 类型
*/
const TYPE_LINEAR = 'linear';
const TYPE_QUADRATIC = 'quadratic';
const TYPE_EASING = 'easing';
const TYPE_DIAGONAL = 'diagonal';
const TYPE_SPHERICAL = 'spherical';
const TYPE_HALO = 'halo';
const TYPE_RADIAL = 'radial';
/**
* @var string 渐变方向,(取值:horizontal或vertical)
*/
public $direction = self::TYPE_HORIZONTAL;
/**
* @var string 渐变 基本效果 类型,取值是一个属于 基本效果 的字符串常量
*/
public $progressiontype = self::TYPE_LINEAR;
/**
* @var float 亮度,(取值:大于等于0的小数)
*/
public $bright = 1;
/**
* @var float 对比度,(取值:大于等于0的小数)
*/
public $contrast = 1;
/**
* @var object 铺贴参数,一个Mapping类对象
*/
public $mapping;
/**
* @param $mapping 必须传入一个 Mapping类对象
*/
public function __construct(Mapping $mapping,$config = [])
{
$this->mapping = $mapping;
$this->type = self::TYPE_BLENDER_BLEND;
$this->id = Scene::createID();
Base::__construct($config);
}
}
?>

7
src/scene/texture/map/Clouds.php

@ -63,14 +63,19 @@ class Clouds extends TextureBase
*/
public $contrast = 1;
/**
* @var object 铺贴参数,一个Mapping类对象
*/
public $mapping;
/**
* @param $mapping 必须传入一个 Mapping类对象
*/
public function __construct(Mapping $mapping,$config = [])
{
$this->id = Scene::createID();
$this->mapping = $mapping;
$this->type = self::TYPE_BLENDER_CLOUDS;
$this->id = Scene::createID();
Base::__construct($config);
}

2
src/scene/texture/map/ImageMap.php

@ -48,9 +48,9 @@ class ImageMap extends TextureBase
*/
public function __construct(Mapping $mapping,$config = [])
{
$this->id = Scene::createID();
$this->mapping = $mapping;
$this->type = self::TYPE_IMAGEMAP;
$this->id = Scene::createID();
Base::__construct($config);
}

2
src/scene/texture/mapping/Triplanar.php

@ -41,9 +41,9 @@ class Triplanar extends TextureBase
*/
public function __construct(Mapping $mapping,$config = [])
{
$this->id = Scene::createID();
$this->mapping = $mapping;
$this->type = self::TYPE_TRIPLANAR;
$this->id = Scene::createID();
Base::__construct($config);
}

2
src/scene/texture/transform/NormalMap.php

@ -27,9 +27,9 @@ class ImageMap extends TextureBase
*/
public function __construct(Mapping $mapping,$config = [])
{
$this->id = Scene::createID();
$this->mapping = $mapping;
$this->type = self::TYPE_NORMALMAP;
$this->id = Scene::createID();
Base::__construct($config);
}

Loading…
Cancel
Save