yuanjiajia
3 years ago
1 changed files with 139 additions and 0 deletions
@ -0,0 +1,139 @@ |
|||
<?php |
|||
|
|||
namespace Blobt\Luxcore\core; |
|||
|
|||
class Base |
|||
{ |
|||
|
|||
const TYPE_TXT = 'txt'; |
|||
const TYPE_BINARY = 'binary'; |
|||
const OPEN = true; |
|||
const CLOSE = false; |
|||
|
|||
|
|||
|
|||
|
|||
/** |
|||
* @var string $objFile obj文件路径 |
|||
*/ |
|||
public $objFile; |
|||
|
|||
/** |
|||
* @var string $plyFile ply文件路径 |
|||
*/ |
|||
public $plyFile = []; |
|||
|
|||
/** |
|||
* @var string $format ply文件储存格式 |
|||
*/ |
|||
public $format = self::TYPE_TXT; |
|||
|
|||
/** |
|||
* @var bool $flipYZ 是 |
|||
*/ |
|||
public $flipYZ; |
|||
|
|||
/** |
|||
* @var array $vertexs 顶点坐标数组 |
|||
*/ |
|||
public $vertexs = []; |
|||
|
|||
/** |
|||
* @var array $textureUV 纹理坐标数组 |
|||
*/ |
|||
public $textureUV = []; |
|||
|
|||
/** |
|||
* @var array $normals 顶点法线数组 |
|||
*/ |
|||
public $normals = []; |
|||
|
|||
/** |
|||
* @var array $faces 面片数组 |
|||
*/ |
|||
public $mesh = []; |
|||
|
|||
|
|||
|
|||
|
|||
/** |
|||
* @param string $objFile 传入obj文件 |
|||
* @param bool $flipYZ 是否翻转Z轴Y轴 |
|||
*/ |
|||
public function __construct(string $objFile,bool $flipYZ = self::OPEN) |
|||
{ |
|||
$this->file = $objFile; |
|||
$this->flipYZ = $flipYZ; |
|||
} |
|||
|
|||
public function toPly() |
|||
{ |
|||
return $this->plyFile; |
|||
} |
|||
|
|||
/** |
|||
* |
|||
*/ |
|||
public function readObj() |
|||
{ |
|||
$handle = null; |
|||
$line = true; |
|||
|
|||
|
|||
if( !file_exists($this->objFile) ) |
|||
{ |
|||
throw new \Exception($this->objFile." file does not exist"); |
|||
} |
|||
else |
|||
{ |
|||
$handle = fopen($this->file,'r'); |
|||
} |
|||
|
|||
|
|||
if( !$handle ) |
|||
{ |
|||
throw new \Exception("File ".$this->objFile." open failed"); |
|||
} |
|||
else |
|||
{ |
|||
|
|||
fseek($handle, 0); |
|||
while( !feof($handle) ) // 读取所有的 顶点坐标、UV坐标、顶点法线,并存入到相应的数组
|
|||
{ |
|||
$line = fgets( $handle ); |
|||
$line = ltrim( $line ); |
|||
if( $line[0] == '#' ) continue; |
|||
|
|||
switch( explode(' ', $line)[0] ) |
|||
{ |
|||
case 'v': |
|||
$this->vertexs[] = $line; |
|||
|
|||
case 'vn': |
|||
$this->normals[] = $line; |
|||
|
|||
case 'vt': |
|||
$this->textureUV[] = $line; |
|||
} |
|||
} |
|||
|
|||
fseek($handle, 0); |
|||
while( !feof($handle) ) // 读取 顶点坐标、UV坐标、顶点法线,并存入到相应的数组
|
|||
{ |
|||
$line = fgets( $handle ); |
|||
$line = ltrim( $line ); |
|||
if( $line[0] == '#' ) continue; |
|||
|
|||
if ( explode(' ', $line)[0] == 'o' ) |
|||
} |
|||
|
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue