Browse Source

loadObj.php类 增加toGltf函数

master
yuanjiajia 3 years ago
parent
commit
c7819abb85
  1. 2
      examples/loadObjDemo.php
  2. 19
      src/core/LoardObj.php

2
examples/loadObjDemo.php

@ -9,7 +9,7 @@ include dirname(dirname(__FILE__)) . "/vendor/autoload.php";
ini_set('memory_limit','4096M'); 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); $ply = $ply->toPly(null,LoardObj::TYPE_TXT);
var_dump($ply ); var_dump($ply );

19
src/core/LoardObj.php

@ -32,11 +32,11 @@ class LoardObj
* @param string $objFile 传入obj文件 * @param string $objFile 传入obj文件
* @param bool $flipYZ 是否翻转Z轴Y轴 * @param bool $flipYZ 是否翻转Z轴Y轴
*/ */
public function __construct( string $objFile, bool $flipYZ = self::CLOSE )
public function __construct( string $objFile )
{ {
$this->objFile = $objFile; $this->objFile = $objFile;
$this->readObj(); $this->readObj();
if( $flipYZ ) $this->flipYZ();
} }
/** /**
@ -45,11 +45,24 @@ class LoardObj
*/ */
public function toPly( string $path = null,string $format = self::TYPE_BINARY) public function toPly( string $path = null,string $format = self::TYPE_BINARY)
{ {
$this->flipYZ();
$this->createPly(); $this->createPly();
if( $path == null) $path = getcwd()."/ply"; if( $path == null) $path = getcwd()."/ply";
return $this->writePly( $path, $format ); 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,7 +144,7 @@ class LoardObj
{ {
$this->objData['v'][$key] = []; $this->objData['v'][$key] = [];
$this->objData['v'][$key][] = $value[0]; $this->objData['v'][$key][] = $value[0];
$this->objData['v'][$key][] = $value[2];
$this->objData['v'][$key][] = -1 * ($value[2]);
$this->objData['v'][$key][] = $value[1]; $this->objData['v'][$key][] = $value[1];
} }

Loading…
Cancel
Save