public class BlenderFile
extends java.lang.Object
implements java.io.Closeable
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.
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.
Modifier and Type | Field and Description |
---|---|
protected long |
firstBlockOffset |
protected FileHeader |
header |
protected CDataReadWriteAccess |
io |
Modifier | Constructor and Description |
---|---|
protected |
BlenderFile() |
|
BlenderFile(java.io.File file) |
protected |
BlenderFile(java.io.File file,
StructDNA sdna,
int blenderVersion,
Encoding encoding,
java.lang.String[] offheapAreas) |
protected |
BlenderFile(java.io.File file,
StructDNA sdna,
int blenderVersion,
java.lang.String[] offheapAreas) |
Modifier and Type | Method and Description |
---|---|
void |
add(Block block)
Adds a block to the end of the file.
|
void |
close() |
DNAModel |
getBlenderModel() |
BlockList |
getBlocks() |
BlockTable |
getBlockTable() |
Encoding |
getEncoding() |
java.io.File |
getFile() |
FileHeader |
getHeader() |
CMetaModel |
getMetaModel() |
protected int[] |
getSdnaIndices(java.lang.String[] structNames)
Retrieve indices for given names from Struct DNA.
|
StructDNA |
getStructDNA() |
FileHeader.Version |
getVersion() |
FileVersionInfo |
readFileGlobal() |
protected void |
readFileHeader(CDataReadWriteAccess in)
Just basic read initialisation.
|
protected void |
readStructDNA() |
BlockHeader |
seekFirstBlock(Identifier code) |
void |
write()
Write all blocks to the file.
|
void |
write(java.util.List<Block> blocks)
Write given blocks to the file.
|
protected void |
writeEndBlock() |
protected void |
writeSdnaBlock() |
protected FileHeader header
protected CDataReadWriteAccess io
protected long firstBlockOffset
public BlenderFile(java.io.File file) throws java.io.IOException
java.io.IOException
protected BlenderFile(java.io.File file, StructDNA sdna, int blenderVersion, java.lang.String[] offheapAreas) throws java.io.IOException
java.io.IOException
protected BlenderFile(java.io.File file, StructDNA sdna, int blenderVersion, Encoding encoding, java.lang.String[] offheapAreas) throws java.io.IOException
java.io.IOException
protected BlenderFile()
protected void readFileHeader(CDataReadWriteAccess in) throws java.io.IOException
in
- java.io.IOException
protected int[] getSdnaIndices(java.lang.String[] structNames) throws java.io.IOException
java.io.IOException
public void write() throws java.io.IOException
write(List)
whith
all blocks stored in this instance of BlenderFile.java.io.IOException
public void write(java.util.List<Block> blocks) throws java.io.IOException
java.io.IOException
protected void writeEndBlock() throws java.io.IOException
java.io.IOException
protected void writeSdnaBlock() throws java.io.IOException
java.io.IOException
public DNAModel getBlenderModel() throws java.io.IOException
java.io.IOException
public FileVersionInfo readFileGlobal() throws java.io.IOException
java.io.IOException
protected void readStructDNA() throws java.io.IOException
java.io.IOException
public BlockHeader seekFirstBlock(Identifier code) throws java.io.IOException
java.io.IOException
public BlockTable getBlockTable() throws java.io.IOException
java.io.IOException
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
java.io.IOException
public FileHeader getHeader()
public Encoding getEncoding()
public CMetaModel getMetaModel() throws java.io.IOException
java.io.IOException
public FileHeader.Version getVersion()
public StructDNA getStructDNA()
public BlockList getBlocks()
public void add(Block block)
write()
will rearrange blocks eventually to move ENDB at the end.block
- public java.io.File getFile()