From 8b36c4cb64fcc281c3564614b11120b54e20b813 Mon Sep 17 00:00:00 2001 From: yuanjiajia <1139393632@qq.com> Date: Wed, 4 May 2022 19:43:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EloadObj.php=E7=B1=BB=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/LoardObj.php | 139 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 src/core/LoardObj.php diff --git a/src/core/LoardObj.php b/src/core/LoardObj.php new file mode 100644 index 0000000..0d7c754 --- /dev/null +++ b/src/core/LoardObj.php @@ -0,0 +1,139 @@ +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' ) + } + + } + + + + + + + } + +}