From c7819abb85844dc7b25683694e6b25e0fde5b1cf Mon Sep 17 00:00:00 2001 From: yuanjiajia <1139393632@qq.com> Date: Sun, 8 May 2022 16:41:34 +0800 Subject: [PATCH] =?UTF-8?q?loadObj.php=E7=B1=BB=20=E5=A2=9E=E5=8A=A0toGltf?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/loadObjDemo.php | 2 +- src/core/LoardObj.php | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/examples/loadObjDemo.php b/examples/loadObjDemo.php index 3837eee..317b500 100644 --- a/examples/loadObjDemo.php +++ b/examples/loadObjDemo.php @@ -9,7 +9,7 @@ include dirname(dirname(__FILE__)) . "/vendor/autoload.php"; ini_set('memory_limit','4096M'); -$ply = new LoardObj('/home/yuanjiajia/Desktop/blender/test/202112201847576528.obj',LoardObj::CLOSE); +$ply = new LoardObj('/home/yuanjiajia/Desktop/blender/test/6D.obj'); $ply = $ply->toPly(null,LoardObj::TYPE_TXT); var_dump($ply ); diff --git a/src/core/LoardObj.php b/src/core/LoardObj.php index a6d0528..0a3e690 100644 --- a/src/core/LoardObj.php +++ b/src/core/LoardObj.php @@ -32,11 +32,11 @@ class LoardObj * @param string $objFile 传入obj文件 * @param bool $flipYZ 是否翻转Z轴Y轴 */ - public function __construct( string $objFile, bool $flipYZ = self::CLOSE ) + public function __construct( string $objFile ) { $this->objFile = $objFile; $this->readObj(); - if( $flipYZ ) $this->flipYZ(); + } /** @@ -45,11 +45,24 @@ class LoardObj */ public function toPly( string $path = null,string $format = self::TYPE_BINARY) { + $this->flipYZ(); $this->createPly(); if( $path == null) $path = getcwd()."/ply"; return $this->writePly( $path, $format ); } + /** + * @param string $path ply模型 保存路径 + * @param string $format ply模型 保存格式 + */ + public function toGltf( string $path = null,string $format = self::TYPE_BINARY) + { + // $this->createGltf(); + // if( $path == null) $path = getcwd()."/gltf"; + // return $this->writeGltf( $path, $format ); + } + + @@ -131,8 +144,8 @@ class LoardObj { $this->objData['v'][$key] = []; $this->objData['v'][$key][] = $value[0]; - $this->objData['v'][$key][] = $value[2]; - $this->objData['v'][$key][] = $value[1]; + $this->objData['v'][$key][] = -1 * ($value[2]); + $this->objData['v'][$key][] = $value[1]; } foreach( $this->objData['vn'] as $key => $value)