使用 php 解压 .blend 文件数据的更简单方法?

发布于 2024-12-27 23:03:03 字数 356 浏览 5 评论 0原文

目前我想使用 PHP 的 unpack() 函数从 .blend 文件中读取一些数据(元数据、场景名称、网格数、顶点数...)到 Blender SDNA 文档:

http://www.atmind.nl/blender/blender-sdna-256.html

是否有一些简单的解决方案可以使用一些现有的类或库读取所有这些信息,或者我必须这样做从文件中逐块读取并编写我自己的函数/类/库(这样我就可以创建类似对象的东西)?

Currently I want to read some data (metadata, scene names, mesh count, vertices count ...) from a .blend file with the unpack() function of PHP refering to the Blender SDNA documentation:

http://www.atmind.nl/blender/blender-sdna-256.html

Is there some easy solution to read all these information with some existing classes or libraries or do I have to read block by block from the file and write my own functions / clas / library (so I can create something like an object)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

恍梦境° 2025-01-03 23:03:03

在查阅 php 手册后,我可以告诉你,php 只是不提供读取二进制文件的方法,但我认为有很好的方法来做到这一点(受到 c 和 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();
            ...
        }
    }
}

如果您有任何改进或提示,请将其发布在评论中,我很乐意扩展答案。

After consultation with php manual I can tell you that php just doesn't provide way to read binary files, but I think there's quite nice way to do this (inspirited by 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();
            ...
        }
    }
}

If you have any improvements or tips, just post them in the comment I'll be glad to extend the answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文