用php解压缩.blend文件数据的方法更简单?
发布时间:2020-12-13 16:14:44 所属栏目:PHP教程 来源:网络整理
导读:目前我想从.blend文件中读取一些数据(元数据,场景名称,网格数,顶点数…),并使用 PHP的unpack()函数参考Blender SDNA文档: http://www.atmind.nl/blender/blender-sdna-256.html 是否有一些简单的解决方案可以使用现有的类或库来读取所有这些信息,或者我必须
目前我想从.blend文件中读取一些数据(元数据,场景名称,网格数,顶点数…),并使用
PHP的unpack()函数参考Blender SDNA文档:
http://www.atmind.nl/blender/blender-sdna-256.html 是否有一些简单的解决方案可以使用现有的类或库来读取所有这些信息,或者我必须从文件中逐块读取并编写我自己的函数/ clas /库(这样我可以创建类似对象的东西)? 解决方法
在咨询了PHP手册后,我可以告诉你,php只是没有提供读取二进制文件的方法,但我认为有很好的方法来做到这一点(受到
c and fread的鼓舞)
class BinaryReader { const FLOAT_SIZE = 4; protected $fp = null; // file pointer ... public function readFloat() { $data = fread( $fp,self::FLOAT_SIZE); $array = unpack( 'f',$data); return $array[0]; } // Reading unsigned short int public function readUint16( $endian = null){ if( $endian === null){ $endian = $this->getDefaultEndian(); } // Assuming _fread handles EOF and similar things $data = $this->_fread( 2); $array = unapack( ($endian == BIG_ENDIAN ? 'n' : 'v'),$data); return $array[0]; } // ... All other binary type functions // You may also write it more general: public function readByReference( &$variable){ switch( get_type( $variable)){ case 'double': return $this->readDouble(); ... } } } 如果您有任何改进或提示,只需将其发布在评论中,我将很乐意为您提供答案. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |