|
|
@ -40,7 +40,8 @@ class LoardObj |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @param string $format 储存 ply模型 的格式 |
|
|
|
* @param string $path ply模型 保存路径 |
|
|
|
* @param string $format ply模型 保存格式 |
|
|
|
*/ |
|
|
|
public function toPly( string $path = null,string $format = self::TYPE_BINARY) |
|
|
|
{ |
|
|
@ -151,10 +152,12 @@ class LoardObj |
|
|
|
|
|
|
|
foreach( $this->objData['meshs'] as $meshs_key => $meshs_value ) |
|
|
|
{ |
|
|
|
$ply = []; |
|
|
|
$vCount = 0; |
|
|
|
$fCount = 0; |
|
|
|
|
|
|
|
$ply['vertex'] = []; |
|
|
|
$ply['face'] = []; |
|
|
|
$ply['header'] = []; |
|
|
|
$indexesList = []; |
|
|
|
$vConst = 0; |
|
|
|
|
|
|
|
foreach( $meshs_value as $face_value ) // 生成顶点和面数据
|
|
|
|
{ |
|
|
|
$face_value = implode('/', $face_value); |
|
|
@ -178,23 +181,32 @@ class LoardObj |
|
|
|
|
|
|
|
case 0; |
|
|
|
$vn = $this->objData['vn'][$v_value-1]; |
|
|
|
$ply['vertex'][$vCount] = implode(' ',$v).' '.implode(' ',$vn).' '.implode(' ',$vt); |
|
|
|
$lineFace[] = $vCount; |
|
|
|
$vCount++; |
|
|
|
$vnt = implode(' ',$v).' '.implode(' ',$vn).' '.implode(' ',$vt); |
|
|
|
$hashVar = hash('md5', $vnt); |
|
|
|
if( !array_key_exists($hashVar, $indexesList) ) |
|
|
|
{ |
|
|
|
$ply['vertex'][$vConst] = $vnt; |
|
|
|
$lineFace[] = $vConst; |
|
|
|
$indexesList[$hashVar] = $vConst; |
|
|
|
$vConst++; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
$lineFace[] = $indexesList[$hashVar]; |
|
|
|
} |
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
; |
|
|
|
} |
|
|
|
} |
|
|
|
$ply['face'][$fCount] = count($lineFace).' '.implode(' ',$lineFace); |
|
|
|
$fCount++; |
|
|
|
$ply['face'][] = count($lineFace).' '.implode(' ',$lineFace); |
|
|
|
} |
|
|
|
|
|
|
|
$ply['header'][] = 'ply'; // 生成头部数据
|
|
|
|
$ply['header'][] = "format "; |
|
|
|
$ply['header'][] = "comment Created by reaiyunju, source file: ''"; |
|
|
|
$ply['header'][] = "element vertex ".$vCount; |
|
|
|
$ply['header'][] = "element vertex ".$vConst; |
|
|
|
$ply['header'][] = "property float x"; |
|
|
|
$ply['header'][] = "property float y"; |
|
|
|
$ply['header'][] = "property float z"; |
|
|
|