Easy way to unzip .blend file data using php?

Currently I want to read some data (metadata, scene names, number of cells, number of vertices ...) from a .blend file using the PHP unpack() function, referring to the Blender SDNA documentation:

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

Is there some simple solution for reading all this information with some existing classes or libraries, or do I need to read block by block from a file and write my own functions / clas / library (so that I can create something like an object)

+4
source share
1 answer

After consulting the php manual, I can tell you that php just doesn't provide a way to read binaries, but I think there is a pretty good way to do this (inspired 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 comments, I will be happy to extend the answer.

+2
source

Source: https://habr.com/ru/post/1392049/


All Articles