Browse Source

修改了bloadObj.php类文件不规范的变量名风格

master
yuanjiajia 2 years ago
parent
commit
c0c7734252
  1. 2
      examples/loadObjDemo.php
  2. 58
      src/core/LoardObj.php

2
examples/loadObjDemo.php

@ -8,7 +8,7 @@ use Blobt\Luxcore\core\LoardObj;
include dirname(dirname(__FILE__)) . "/vendor/autoload.php";
ini_set('memory_limit','4096M');
$transform = new LoardObj('/home/yuanjiajia/Desktop/blender/test/椅子.obj');
$transform = new LoardObj('/home/yuanjiajia/Desktop/blender/test/沙发.obj');
$transform->toGltf();
$transform = $transform->toPly();
var_dump( $transform );

58
src/core/LoardObj.php

@ -195,7 +195,7 @@ class LoardObj
private function createPly()
{
foreach( $this->objData['meshs'] as $meshs_key => $meshs_value )
foreach( $this->objData['meshs'] as $meshsKey => $meshsValue )
{
$ply['vertex'] = [];
$ply['face'] = [];
@ -203,29 +203,29 @@ class LoardObj
$indexesList = [];
$vConst = 0;
foreach( $meshs_value as $face_value ) // 生成顶点和面数据
foreach( $meshsValue as $faceValue ) // 生成顶点和面数据
{
$face_value = implode('/', $face_value);
$face_value = explode('/', $face_value);
$faceValue = implode('/', $faceValue);
$faceValue = explode('/', $faceValue);
$lineFace = [];
$v = [];
$vt = [];
$vn = [];
foreach( $face_value as $v_key => $v_value )
foreach( $faceValue as $vKey => $vValue )
{
switch( ($v_key+1) % 3 )
switch( ($vKey+1) % 3 )
{
case 1:
$v = $this->objData['v'][$v_value-1];
$v = $this->objData['v'][$vValue-1];
break;
case 2:
if( $v_value == null ) $vt = ['0.0000','0.0000'];
else $vt = array_slice($this->objData['vt'][$v_value-1],0,2);
if( $vValue == null ) $vt = ['0.0000','0.0000'];
else $vt = array_slice($this->objData['vt'][$vValue-1],0,2);
break;
case 0;
$vn = $this->objData['vn'][$v_value-1];
$vn = $this->objData['vn'][$vValue-1];
$vnt = implode(' ',$v).' '.implode(' ',$vn).' '.implode(' ',$vt);
$hashVar = hash('md5', $vnt);
if( !array_key_exists($hashVar, $indexesList) )
@ -264,7 +264,7 @@ class LoardObj
$ply['header'][] = "property list uchar uint vertex_indices";
$ply['header'][] = "end_header";
$this->plyData[$meshs_key] = $ply; // 在 数组plyData 中添加一个 $key 所指名称的ply模型
$this->plyData[$meshsKey] = $ply; // 在 数组plyData 中添加一个 $key 所指名称的ply模型
}
}
@ -296,7 +296,7 @@ class LoardObj
$minY = 100000000;
$minZ = 100000000;
foreach( $this->objData['meshs'] as $meshs_key => $meshs_value )
foreach( $this->objData['meshs'] as $meshsKey => $meshsValue )
{
$gltf['v'] = null;
$gltf['vt'] = null;
@ -304,24 +304,24 @@ class LoardObj
$gltf['face'] = null;
$indexesList = [];
$vConst = 0;
foreach( $meshs_value as $face_value )
foreach( $meshsValue as $faceValue )
{
// 生成顶点和面数据
$face_value = implode('/', $face_value);
$face_value = explode('/', $face_value);
$faceValue = implode('/', $faceValue);
$faceValue = explode('/', $faceValue);
$lineFace = [];
$v = null;
$vt = null;
$vn = null;
foreach( $face_value as $v_key => $v_value )
foreach( $faceValue as $vKey => $vValue )
{
switch( ($v_key+1) % 3 )
switch( ($vKey+1) % 3 )
{
case 1:
foreach($this->objData['v'][$v_value-1] as $xyz_key => $xyz_value)
foreach($this->objData['v'][$vValue-1] as $xyzKey => $xyzValue)
{
$xyz_value = (float)$xyz_value;
switch( ($xyz_key+1) % 3 )
$xyz_value = (float)$xyzValue;
switch( ($xyzKey+1) % 3 )
{
case 1:
$maxX = $xyz_value > $maxX ? $xyz_value : $maxX;
@ -339,16 +339,16 @@ class LoardObj
;
}
}
$v = $this->objData['v'][$v_value-1];
$v = $this->objData['v'][$vValue-1];
break;
case 2:
if( $v_value == null ) $vt = ['0.0000','0.0000'];
else $vt = array_slice($this->objData['vt'][$v_value-1],0,2);
if( $vValue == null ) $vt = ['0.0000','0.0000'];
else $vt = array_slice($this->objData['vt'][$vValue-1],0,2);
break;
case 0;
$vn = $this->objData['vn'][$v_value-1];
$vn = $this->objData['vn'][$vValue-1];
$hashVar = implode(' ',$v).' '.implode(' ',$vn).' '.implode(' ',$vt);
$hashVar = hash('md5', $hashVar);
if( !array_key_exists($hashVar, $indexesList) )
@ -497,7 +497,7 @@ class LoardObj
$mesh = null;
$mesh = "\t\t{\n";
$mesh .= "\t\t\t\"name\" : \"".$meshs_key."\",\n";
$mesh .= "\t\t\t\"name\" : \"".$meshsKey."\",\n";
$mesh .= "\t\t\t\"primitives\" :\n";
$mesh .= "\t\t\t[\n";
$mesh .= "\t\t\t\t{\n";
@ -519,7 +519,7 @@ class LoardObj
$node = null;
$node = "\t\t{\n";
$node .= "\t\t\t\"mesh\" : ".$meshCount.",\n";
$node .= "\t\t\t\"name\" : \"".$meshs_key."\"\n";
$node .= "\t\t\t\"name\" : \"".$meshsKey."\"\n";
$node .= "\t\t}";
$this->gltfData['nodes'][$meshCount] = $node;
$bufferCount++;
@ -580,12 +580,12 @@ class LoardObj
fwrite($handle,$data);
}
foreach( $value['vertex'] as $v_value ) // 2、写入顶点数据
foreach( $value['vertex'] as $vValue ) // 2、写入顶点数据
{
if( $format == self::TYPE_BINARY )
{
$data = null;
foreach( explode(' ', $v_value) as $v )
foreach( explode(' ', $vValue) as $v )
{
$data .= pack('f',$v);
}
@ -593,7 +593,7 @@ class LoardObj
}
else
{
$data = $v_value."\n";
$data = $vValue."\n";
fwrite($handle,$data); // 文本格试写入
}
}

Loading…
Cancel
Save