Class BlenderFile

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable
    Direct Known Subclasses:
    BlenderFactoryBase.BlenderFileImplBase, BlenderFactoryBase.StructDNAImage, StructDNAImageGenerator

    public class BlenderFile
    extends java.lang.Object
    implements java.io.Closeable
    Class BlenderFile implements various functionalities to support in reading or writing blender files.

    Reading

    To simply read a blender file you can use the constructor BlenderFile(File). If the data model was generated with the optional utilities (i.e. with the 'utils' package) then you will find a class MainLib in this package. The MainLib provides CFacades to all data available in the file. To instantiate the MainLib you need block table received via getBlockTable(). The block table is also a way to access blocks directly. The block table maps virtual addresses to memory in blocks. Internally, it maintains a sorted list of the blocks. If you prefer or need direct access to blocks in the order given in the blender file then you can use the list returned from getBlocks() instead.

    Writing

    Unfortunately, writing a blender file can take a bit more effort, especially if you are adding new blocks. First of all, it is important to know, that the list of blocks you may have received after reading, is not in sync with the block table. Adding and removing blocks in the block table is not reflected in the list.

    The order of blocks usually doesn't matter except of the ENDB block and some special cases I saw in blender code. The methods write() and write(List) take care of ENDB and DNA1, i.e. they add a StructDNA block and an ENDB block at the end. Since those remaining special cases in blender code, where the order of blocks matters, are version specific, Java Blend cannot provide a generic solution and instead allows the API developer to provide his own block list to method write(List).

    To help maintain a certain order of blocks, Java Blend provides the class BlockList which is a linked list of blocks, and therefore optimised for fast adding and removing of blocks. But this list is not automatically updated if blocks are added to or removed from the block table.

    • Constructor Detail

      • BlenderFile

        public BlenderFile​(java.io.File file)
                    throws java.io.IOException
        Throws:
        java.io.IOException
      • BlenderFile

        protected BlenderFile​(java.io.File file,
                              StructDNA sdna,
                              int blenderVersion,
                              java.lang.String[] offheapAreas)
                       throws java.io.IOException
        Throws:
        java.io.IOException
      • BlenderFile

        protected BlenderFile​(java.io.File file,
                              StructDNA sdna,
                              int blenderVersion,
                              Encoding encoding,
                              java.lang.String[] offheapAreas)
                       throws java.io.IOException
        Throws:
        java.io.IOException
      • BlenderFile

        protected BlenderFile()
    • Method Detail

      • readFileHeader

        protected void readFileHeader​(CDataReadWriteAccess in)
                               throws java.io.IOException
        Just basic read initialisation. Reading file header. (byte order doesn't matter in this case).
        Parameters:
        in -
        Throws:
        java.io.IOException
      • getSdnaIndices

        protected int[] getSdnaIndices​(java.lang.String[] structNames)
                                throws java.io.IOException
        Retrieve indices for given names from Struct DNA.
        Throws:
        java.io.IOException
      • write

        public void write()
                   throws java.io.IOException
        Write all blocks to the file. This method calls write(List) whith all blocks stored in this instance of BlenderFile.
        Throws:
        java.io.IOException
      • write

        public void write​(java.util.List<Block> blocks)
                   throws java.io.IOException
        Write given blocks to the file. This reorders only the Struct DNA (DNA1) block and the End (ENDB) block. All other blocks have to be in the order expected by blender.
        Throws:
        java.io.IOException
      • writeEndBlock

        protected void writeEndBlock()
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • writeSdnaBlock

        protected void writeSdnaBlock()
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • getBlenderModel

        public DNAModel getBlenderModel()
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • readFileGlobal

        public FileVersionInfo readFileGlobal()
                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • readStructDNA

        protected void readStructDNA()
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • seekFirstBlock

        public BlockHeader seekFirstBlock​(Identifier code)
                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • getBlockTable

        public BlockTable getBlockTable()
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • getEncoding

        public Encoding getEncoding()
        Returns:
        Encoding according to the files header
      • getMetaModel

        public CMetaModel getMetaModel()
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • getStructDNA

        public StructDNA getStructDNA()
      • add

        public void add​(Block block)
        Adds a block to the end of the file. Please note, that method write() will rearrange blocks eventually to move ENDB at the end.
        Parameters:
        block -
      • getFile

        public java.io.File getFile()