Logo Search packages:      
Sourcecode: java3ds-fileloader version File versions  Download package

synchronized SceneBase com::microcrowd::loader::java3d::max3ds::ChunkChopper::loadSceneBase ( InputStream  inputStream,
Loader3DS  loader,
int  modelSize 
) [inline]

This sequentially parses the chunks out of the input stream and constructs the 3D entities represented within. A Chunk is a little endian data structure consists of a 6 byte header followed by subchunks and or data. The first short int(little endian) represent the id of the chunk. The next int represent the total length of the chunk(total of data, subchunks and chunk header).

The first chunk is the main chunk (id=4D4D) and its length is always the length of the file. It only contains sub chunks. Other chunks may contain data, subchunks or both. If the format of a chunk is unknown skipped.

Subclasses of chunk will all automagically load the subchunks. It is the programmers responsibility to ensure that the data preceeding the subchunks is loaded or skipped as required and that something useful is done with the data. If data from the subchunks is needed in order to initialize components then that code should be placed in Chunk#initialize. Otherwise the data may be dealt with in Chunk#loadData. Also, if a chunk has data preceeding its subchunks it communicates how many bytes long that data is by returning it from loadData.

This chopper reads a file in order from beginning to end

Parameters:
inputStream the stream with the data to be parsed.
loader the loader that will be configured from the data.
modelName name of the model file for display purposes.
modelSize size in bytes of the file to read.

Definition at line 120 of file ChunkChopper.java.

References getByteBuffer(), and loadSubChunks().

Referenced by com::microcrowd::loader::java3d::max3ds::Loader3DS::parseChunks().

    {
        this.loader = loader;
        this.sceneGroup = new BranchGroup();
        this.base = new SceneBase();
        this.dataMap = new HashMap();
        base.setSceneGroup(sceneGroup);

        //FileChannel channel = null; 
        ReadableByteChannel channel = null; 
        try {
            channel = Channels.newChannel(inputStream);
            chunkBuffer = getByteBuffer(channel, modelSize);
            //chunkBuffer = getDirectByteBuffer(channel, modelSize);

            int mainChunkID     = chunkBuffer.getShort();
            long mainChunkLength = chunkBuffer.getInt();

            long begin = System.currentTimeMillis();     
            logger.finest("\n\n\n STARTING SUBCUNKS " + (mainChunkLength - 61));
            try {
                loadSubChunks(mainChunk, 0);
            }
            catch(CannotChopException e){
                
            }
            logger.finest("FINISHED WITH THE SUBCHUNKS");
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        finally
        {
            try {
                if(channel != null) {
                    channel.close();
                }
            } catch (Exception e){
                //Just closing file.. don't care.
            }
        }
        return base;
    }


Generated by  Doxygen 1.6.0   Back to index