private void CreateBitmapContexts(Data data)
            {
                m_bitmapContexts = new BitmapContext[data.bitmaps.Length];
                for (int i = 0; i < data.bitmaps.Length; ++i) {
                Format.Bitmap bitmap = data.bitmaps[i];
                // Ignore null texture
                if (bitmap.textureFragmentId == -1)
                continue;
                int bitmapExId = -i - 1;
                Format.BitmapEx bitmapEx = new Format.BitmapEx();
                bitmapEx.matrixId = bitmap.matrixId;
                bitmapEx.textureFragmentId = bitmap.textureFragmentId;
                bitmapEx.u = 0;
                bitmapEx.v = 0;
                bitmapEx.w = 1;
                bitmapEx.h = 1;
                m_bitmapContexts[i] =
                new BitmapContext(this, data, bitmapEx, bitmapExId);
                }

                m_bitmapExContexts = new BitmapContext[data.bitmapExs.Length];
                for (int i = 0; i < data.bitmapExs.Length; ++i) {
                Format.BitmapEx bitmapEx = data.bitmapExs[i];
                // Ignore null texture
                if (bitmapEx.textureFragmentId == -1)
                continue;
                m_bitmapExContexts[i] = new BitmapContext(this, data, bitmapEx, i);
                }
            }
Beispiel #2
0
            private void CreateBitmapContexts(Data data)
            {
                m_bitmapContexts = new BitmapContext[data.bitmaps.Length];
                for (int i = 0; i < data.bitmaps.Length; ++i)
                {
                    Format.Bitmap bitmap = data.bitmaps[i];
                    // Ignore null texture
                    if (bitmap.textureFragmentId == -1)
                    {
                        continue;
                    }
                    Format.BitmapEx bitmapEx = new Format.BitmapEx();
                    bitmapEx.matrixId          = bitmap.matrixId;
                    bitmapEx.textureFragmentId = bitmap.textureFragmentId;
                    bitmapEx.u          = 0;
                    bitmapEx.v          = 0;
                    bitmapEx.w          = 1;
                    bitmapEx.h          = 1;
                    m_bitmapContexts[i] = new BitmapContext(this, i, data, bitmapEx);
                }

                m_bitmapExContexts = new BitmapContext[data.bitmapExs.Length];
                for (int i = 0; i < data.bitmapExs.Length; ++i)
                {
                    Format.BitmapEx bitmapEx = data.bitmapExs[i];
                    // Ignore null texture
                    if (bitmapEx.textureFragmentId == -1)
                    {
                        continue;
                    }
                    m_bitmapExContexts[i] = new BitmapContext(this, i, data, bitmapEx);
                }
            }
Beispiel #3
0
            public BitmapContext(Factory factory,
                                 Data data, Format.BitmapEx bitmapEx, int bitmapExId)
            {
                m_factory    = factory;
                m_data       = data;
                m_bitmapExId = bitmapExId;

                Format.TextureFragment fragment =
                    data.textureFragments[bitmapEx.textureFragmentId];
                Format.Texture texture = data.textures[fragment.textureId];

                m_textureName        = factory.texturePrefix + texture.filename;
                m_premultipliedAlpha = (texture.format ==
                                        (int)Format.Constant.TEXTUREFORMAT_PREMULTIPLIEDALPHA);

                m_material = ResourceCache.SharedInstance().LoadTexture(
                    data.name, m_textureName, texture.format,
                    factory.textureLoader, factory.textureUnloader);
                if (factory.renderQueueOffset != 0)
                {
                    m_material.renderQueue += factory.renderQueueOffset;
                }

                MeshContext c = ResourceCache.SharedInstance().LoadMesh(
                    data.name, data, bitmapEx, bitmapExId);

                m_mesh   = c.mesh;
                m_height = c.height;
            }
Beispiel #4
0
            public BitmapContext(Factory f,
                                 Data d, Format.BitmapEx bitmapEx, int bId)
            {
                m_factory    = f;
                m_data       = d;
                m_bitmapExId = bId;

                Format.TextureFragment fragment =
                    data.textureFragments[bitmapEx.textureFragmentId];
                Format.Texture texture = data.textures[fragment.textureId];

                m_textureName = factory.texturePrefix + texture.filename;

                m_premultipliedAlpha = (texture.format ==
                                        (int)Format.Constant.TEXTUREFORMAT_PREMULTIPLIEDALPHA);

                //m_material = ResourceCache.SharedInstance().LoadTexture(
                //	data.name, m_textureName, texture.format,
                //	factory.useAdditionalColor, factory.textureLoader,
                //	factory.textureUnloader, factory.shaderName);
                m_material = new Material(Shader.Find(factory.shaderName));
                m_material.SetTexture("_MainTex", factory.texturePrefix);

                if (factory.renderQueueOffset != 0)
                {
                    m_material.renderQueue += factory.renderQueueOffset;
                }

                MeshContext c = ResourceCache.SharedInstance().LoadMesh(
                    data.name, data, bitmapEx, bitmapExId);

                m_mesh   = c.mesh;
                m_height = c.height;
            }
Beispiel #5
0
            public MeshContext LoadMesh(string lwfName,
                                        Data data, Format.BitmapEx bitmapEx, int bitmapExId)
            {
                MeshItem item;
                string   cacheName = string.Format("{0}/{1}", lwfName, bitmapExId);

                if (!m_meshCache.TryGetValue(cacheName, out item))
                {
                    Format.TextureFragment fragment =
                        data.textureFragments[bitmapEx.textureFragmentId];
                    Format.Texture texture = data.textures[fragment.textureId];

                    float tw = (float)texture.width;
                    float th = (float)texture.height;

                    float x = (float)fragment.x;
                    float y = -(float)fragment.y;
                    float u = (float)fragment.u;
                    float v = th - (float)fragment.v;
                    float w = (float)fragment.w;
                    float h = (float)fragment.h;

                    float bu = bitmapEx.u * w;
                    float bv = bitmapEx.v * h;
                    float bw = bitmapEx.w;
                    float bh = bitmapEx.h;

                    x += bu;
                    y += bv;
                    u += bu;
                    v += bv;
                    w *= bw;
                    h *= bh;

                    float height = h / texture.scale;

                    float x0 = x / texture.scale;
                    float y0 = y / texture.scale;
                    float x1 = (x + w) / texture.scale;
                    float y1 = (y + h) / texture.scale;

                    Mesh mesh = new Mesh();
                    mesh.name     = "LWF/" + cacheName;
                    mesh.vertices = new Vector3[] {
                        new Vector3(x1, y1, 0),
                        new Vector3(x1, y0, 0),
                        new Vector3(x0, y1, 0),
                        new Vector3(x0, y0, 0),
                    };

                    float dw = 2.0f * tw;
                    float dh = 2.0f * th;
                    if (fragment.rotated == 0)
                    {
                        float u0 = (float)(2 * u + 1) / dw;
                        float v0 = (float)(2 * (v - h) + 1) / dh;
                        float u1 = u0 + (float)(w * 2 - 2) / dw;
                        float v1 = (float)(v * 2 - 1) / dh;
                        mesh.uv = new Vector2[] {
                            new Vector2(u1, v1),
                            new Vector2(u1, v0),
                            new Vector2(u0, v1),
                            new Vector2(u0, v0),
                        };
                    }
                    else
                    {
                        float u0 = (float)(2 * u + 1) / dw;
                        float v0 = (float)(2 * (v - w) + 1) / dh;
                        float u1 = u0 + (float)(h * 2 - 2) / dw;
                        float v1 = (float)(v * 2 - 1) / dh;
                        mesh.uv = new Vector2[] {
                            new Vector2(u1, v0),
                            new Vector2(u0, v0),
                            new Vector2(u1, v1),
                            new Vector2(u0, v1),
                        };
                    }

                    mesh.triangles = new int[] {
                        0, 1, 2,
                        2, 1, 3,
                    };
                    mesh.RecalculateBounds();
                    //mesh.Optimize();

                    MeshContext context = new MeshContext(mesh, height);
                    item = new MeshItem(context);
                    m_meshCache[cacheName] = item;
                }
                item.Ref();
                return(item.Entity());
            }
            public BitmapContext(Factory f,
                                 Data d, Format.BitmapEx bitmapEx, int objId, int bId)
            {
                m_factory    = f;
                m_data       = d;
                m_objectId   = objId;
                m_bitmapExId = bId;

                Format.TextureFragment fragment =
                    data.textureFragments[bitmapEx.textureFragmentId];
                Format.Texture texture = data.textures[fragment.textureId];

                m_textureName = factory.texturePrefix + texture.filename;
                if (LWF.GetTextureLoadHandler() != null)
                {
                    m_textureName = LWF.GetTextureLoadHandler()(
                        m_textureName, factory.texturePrefix, texture.filename);
                }

                m_premultipliedAlpha = (texture.format ==
                                        (int)Format.Constant.TEXTUREFORMAT_PREMULTIPLIEDALPHA);

                m_material = ResourceCache.SharedInstance().LoadTexture(
                    data.name, m_textureName, texture.format,
                    factory.useAdditionalColor, factory.textureLoader,
                    factory.textureUnloader);
                if (factory.renderQueueOffset != 0)
                {
                    m_material.renderQueue += factory.renderQueueOffset;
                }

                m_format = (Format.Constant)texture.format;

                float tw = (float)texture.width;
                float th = (float)texture.height;

                float x = (float)fragment.x;
                float y = -(float)fragment.y;
                float u = (float)fragment.u;
                float v = th - (float)fragment.v;
                float w = (float)fragment.w;
                float h = (float)fragment.h;

                float bu = bitmapEx.u * w;
                float bv = bitmapEx.v * h;
                float bw = bitmapEx.w;
                float bh = bitmapEx.h;

                x += bu;
                y += bv;
                u += bu;
                v += bv;
                w *= bw;
                h *= bh;

                m_height = h / texture.scale;

                float x0 = x / texture.scale;
                float y0 = y / texture.scale;
                float x1 = (x + w) / texture.scale;
                float y1 = (y + h) / texture.scale;

                m_vertices = new Vector3[] {
                    new Vector3(x1, y1, 0),
                    new Vector3(x1, y0, 0),
                    new Vector3(x0, y1, 0),
                    new Vector3(x0, y0, 0),
                };

                if (fragment.rotated == 0)
                {
                    float u0 = u / tw;
                    float v0 = (v - h) / th;
                    float u1 = (u + w) / tw;
                    float v1 = v / th;
                    m_uv = new Vector2[] {
                        new Vector2(u1, v1),
                        new Vector2(u1, v0),
                        new Vector2(u0, v1),
                        new Vector2(u0, v0),
                    };
                }
                else
                {
                    float u0 = u / tw;
                    float v0 = (v - w) / th;
                    float u1 = (u + h) / tw;
                    float v1 = v / th;
                    m_uv = new Vector2[] {
                        new Vector2(u1, v0),
                        new Vector2(u0, v0),
                        new Vector2(u1, v1),
                        new Vector2(u0, v1),
                    };
                }
            }
Beispiel #7
0
            public BitmapContext(Factory f,
                                 int objId, Data data, Format.BitmapEx bitmapEx)
            {
                factory = f;
                Format.TextureFragment fragment =
                    data.textureFragments[bitmapEx.textureFragmentId];
                Format.Texture texture = data.textures[fragment.textureId];

                objectId = objId;
                format   = (Format.Constant)texture.format;

                float tw = (float)texture.width;
                float th = (float)texture.height;

                float x = (float)fragment.x;
                float y = -(float)fragment.y;
                float u = (float)fragment.u;
                float v = th - (float)fragment.v;
                float w = (float)fragment.w;
                float h = (float)fragment.h;

                float bu = bitmapEx.u * w;
                float bv = bitmapEx.v * h;
                float bw = bitmapEx.w;
                float bh = bitmapEx.h;

                x += bu;
                y += bv;
                u += bu;
                v += bv;
                w *= bw;
                h *= bh;

                height = h / texture.scale;

                float x0 = x / texture.scale;
                float y0 = y / texture.scale;
                float x1 = (x + w) / texture.scale;
                float y1 = (y + h) / texture.scale;

                vertices = new Vector3[] {
                    new Vector3(x1, y1, 0),
                    new Vector3(x1, y0, 0),
                    new Vector3(x0, y1, 0),
                    new Vector3(x0, y0, 0),
                };

                if (fragment.rotated == 0)
                {
                    float u0 = u / tw;
                    float v0 = (v - h) / th;
                    float u1 = (u + w) / tw;
                    float v1 = v / th;
                    uv = new Vector2[] {
                        new Vector2(u1, v1),
                        new Vector2(u1, v0),
                        new Vector2(u0, v1),
                        new Vector2(u0, v0),
                    };
                }
                else
                {
                    float u0 = u / tw;
                    float v0 = (v - w) / th;
                    float u1 = (u + h) / tw;
                    float v1 = v / th;
                    uv = new Vector2[] {
                        new Vector2(u1, v0),
                        new Vector2(u0, v0),
                        new Vector2(u1, v1),
                        new Vector2(u0, v1),
                    };
                }

                triangles = new int[] {
                    0, 1, 2,
                    2, 1, 3,
                };
            }
Beispiel #8
0
        public Data(byte[] bytes)
        {
            if (bytes.Length < (int)Format.Constant.HEADER_SIZE)
            {
                return;
            }

            Stream       s  = new MemoryStream(bytes);
            BinaryReader br = new BinaryReader(s);

            header = new Format.Header(br);
            if (!Check())
            {
                return;
            }

            byte[] stringByteData    = br.ReadBytes((int)header.stringBytes.length);
            byte[] animationByteData =
                br.ReadBytes((int)header.animationBytes.length);

            translates = new Translate[header.translate.length];
            for (int i = 0; i < translates.Length; ++i)
            {
                translates[i] = new Translate(br);
            }
            matrices = new Matrix[header.matrix.length];
            for (int i = 0; i < matrices.Length; ++i)
            {
                matrices[i] = new Matrix(br);
            }
            colors = new Color[header.color.length];
            for (int i = 0; i < colors.Length; ++i)
            {
                colors[i] = new Color(br);
            }
            alphaTransforms = new AlphaTransform[header.alphaTransform.length];
            for (int i = 0; i < alphaTransforms.Length; ++i)
            {
                alphaTransforms[i] = new AlphaTransform(br);
            }
            colorTransforms = new ColorTransform[header.colorTransform.length];
            for (int i = 0; i < colorTransforms.Length; ++i)
            {
                colorTransforms[i] = new ColorTransform(br);
            }
            objects = new Format.Object[header.objectData.length];
            for (int i = 0; i < objects.Length; ++i)
            {
                objects[i] = new Format.Object(br);
            }
            textures = new Format.Texture[header.texture.length];
            for (int i = 0; i < textures.Length; ++i)
            {
                textures[i] = new Format.Texture(br);
            }
            textureFragments =
                new Format.TextureFragment[header.textureFragment.length];
            for (int i = 0; i < textureFragments.Length; ++i)
            {
                textureFragments[i] = new Format.TextureFragment(br);
            }
            bitmaps = new Format.Bitmap[header.bitmap.length];
            for (int i = 0; i < bitmaps.Length; ++i)
            {
                bitmaps[i] = new Format.Bitmap(br);
            }
            bitmapExs = new Format.BitmapEx[header.bitmapEx.length];
            for (int i = 0; i < bitmapExs.Length; ++i)
            {
                bitmapExs[i] = new Format.BitmapEx(br);
            }
            fonts = new Format.Font[header.font.length];
            for (int i = 0; i < fonts.Length; ++i)
            {
                fonts[i] = new Format.Font(br);
            }
            textProperties = new Format.TextProperty[header.textProperty.length];
            for (int i = 0; i < textProperties.Length; ++i)
            {
                textProperties[i] = new Format.TextProperty(br);
            }
            texts = new Format.Text[header.text.length];
            for (int i = 0; i < texts.Length; ++i)
            {
                texts[i] = new Format.Text(br);
            }
            particleDatas = new Format.ParticleData[header.particleData.length];
            for (int i = 0; i < particleDatas.Length; ++i)
            {
                particleDatas[i] = new Format.ParticleData(br);
            }
            particles = new Format.Particle[header.particle.length];
            for (int i = 0; i < particles.Length; ++i)
            {
                particles[i] = new Format.Particle(br);
            }
            programObjects =
                new Format.ProgramObject[header.programObject.length];
            for (int i = 0; i < programObjects.Length; ++i)
            {
                programObjects[i] = new Format.ProgramObject(br);
            }
            graphicObjects =
                new Format.GraphicObject[header.graphicObject.length];
            for (int i = 0; i < graphicObjects.Length; ++i)
            {
                graphicObjects[i] = new Format.GraphicObject(br);
            }
            graphics = new Format.Graphic[header.graphic.length];
            for (int i = 0; i < graphics.Length; ++i)
            {
                graphics[i] = new Format.Graphic(br);
            }
            Format.Animation[] animationData =
                new Format.Animation[header.animation.length];
            for (int i = 0; i < animationData.Length; ++i)
            {
                animationData[i] = new Format.Animation(br);
            }
            buttonConditions =
                new Format.ButtonCondition[header.buttonCondition.length];
            for (int i = 0; i < buttonConditions.Length; ++i)
            {
                buttonConditions[i] = new Format.ButtonCondition(br);
            }
            buttons = new Format.Button[header.button.length];
            for (int i = 0; i < buttons.Length; ++i)
            {
                buttons[i] = new Format.Button(br);
            }
            labels = new Format.Label[header.label.length];
            for (int i = 0; i < labels.Length; ++i)
            {
                labels[i] = new Format.Label(br);
            }
            instanceNames = new Format.InstanceName[header.instanceName.length];
            for (int i = 0; i < instanceNames.Length; ++i)
            {
                instanceNames[i] = new Format.InstanceName(br);
            }
            events = new Format.Event[header.eventData.length];
            for (int i = 0; i < events.Length; ++i)
            {
                events[i] = new Format.Event(br);
            }
            places = new Format.Place[header.place.length];
            for (int i = 0; i < places.Length; ++i)
            {
                places[i] = new Format.Place(br);
            }
            controlMoveMs = new Format.ControlMoveM[header.controlMoveM.length];
            for (int i = 0; i < controlMoveMs.Length; ++i)
            {
                controlMoveMs[i] = new Format.ControlMoveM(br);
            }
            controlMoveCs = new Format.ControlMoveC[header.controlMoveC.length];
            for (int i = 0; i < controlMoveCs.Length; ++i)
            {
                controlMoveCs[i] = new Format.ControlMoveC(br);
            }
            controlMoveMCs =
                new Format.ControlMoveMC[header.controlMoveMC.length];
            for (int i = 0; i < controlMoveMCs.Length; ++i)
            {
                controlMoveMCs[i] = new Format.ControlMoveMC(br);
            }
            controls = new Format.Control[header.control.length];
            for (int i = 0; i < controls.Length; ++i)
            {
                controls[i] = new Format.Control(br);
            }
            frames = new Format.Frame[header.frame.length];
            for (int i = 0; i < frames.Length; ++i)
            {
                frames[i] = new Format.Frame(br);
            }
            movieClipEvents =
                new Format.MovieClipEvent[header.movieClipEvent.length];
            for (int i = 0; i < movieClipEvents.Length; ++i)
            {
                movieClipEvents[i] = new Format.MovieClipEvent(br);
            }
            movies = new Format.Movie[header.movie.length];
            for (int i = 0; i < movies.Length; ++i)
            {
                movies[i] = new Format.Movie(br);
            }
            movieLinkages = new Format.MovieLinkage[header.movieLinkage.length];
            for (int i = 0; i < movieLinkages.Length; ++i)
            {
                movieLinkages[i] = new Format.MovieLinkage(br);
            }
            Format.String[] stringData =
                new Format.String[header.stringData.length];
            for (int i = 0; i < stringData.Length; ++i)
            {
                stringData[i] = new Format.String(br);
            }

            animations = new int[animationData.Length][];
            for (int i = 0; i < animationData.Length; ++i)
            {
                animations[i] = ReadAnimation(animationByteData,
                                              (int)animationData[i].animationOffset,
                                              (int)animationData[i].animationLength);
            }

            strings = new string[stringData.Length];
            for (int i = 0; i < stringData.Length; ++i)
            {
                strings[i] = System.Text.Encoding.UTF8.GetString(stringByteData,
                                                                 (int)stringData[i].stringOffset,
                                                                 (int)stringData[i].stringLength);
            }

            stringMap = new Dictionary <string, int>();
            for (int i = 0; i < strings.Length; ++i)
            {
                stringMap[strings[i]] = i;
            }

            instanceNameMap = new Dictionary <int, int>();
            for (int i = 0; i < instanceNames.Length; ++i)
            {
                instanceNameMap[instanceNames[i].stringId] = i;
            }

            eventMap = new Dictionary <int, int>();
            for (int i = 0; i < events.Length; ++i)
            {
                eventMap[events[i].stringId] = i;
            }

            movieLinkageMap     = new Dictionary <int, int>();
            movieLinkageNameMap = new Dictionary <int, int>();
            for (int i = 0; i < movieLinkages.Length; ++i)
            {
                movieLinkageMap[movieLinkages[i].stringId]    = i;
                movieLinkageNameMap[movieLinkages[i].movieId] =
                    movieLinkages[i].stringId;
            }

            programObjectMap = new Dictionary <int, int>();
            for (int i = 0; i < programObjects.Length; ++i)
            {
                programObjectMap[programObjects[i].stringId] = i;
            }

            labelMap = new Dictionary <int, int> [movies.Length];
            for (int i = 0; i < movies.Length; ++i)
            {
                Format.Movie          m   = movies[i];
                int                   o   = m.labelOffset;
                Dictionary <int, int> map = new Dictionary <int, int>();
                for (int j = 0; j < m.labels; ++j)
                {
                    Format.Label l = labels[o + j];
                    map[l.stringId] = l.frameNo;
                }
                labelMap[i] = map;
            }

            for (int i = 0; i < textures.Length; ++i)
            {
                textures[i].SetFilename(this);
            }

            bitmapMap = new Dictionary <string, int>();
            var bitmapList = new List <Format.Bitmap>(bitmaps);

            for (int i = 0; i < textureFragments.Length; ++i)
            {
                textureFragments[i].SetFilename(this);
                bitmapMap[textureFragments[i].filename] = bitmapList.Count;
                bitmapList.Add(
                    new Format.Bitmap {
                    matrixId = 0, textureFragmentId = i
                });
            }
            bitmaps = bitmapList.ToArray();
        }
Beispiel #9
0
        public Data(byte[] bytes)
        {
            if (bytes.Length < (int)Format.Constant.HEADER_SIZE)
            return;

            Stream s = new MemoryStream(bytes);
            BinaryReader br = new BinaryReader(s);

            header = new Format.Header(br);
            if (!Check())
            return;

            byte[] stringByteData = br.ReadBytes((int)header.stringBytes.length);
            byte[] animationByteData =
            br.ReadBytes((int)header.animationBytes.length);

            translates = new Translate[header.translate.length];
            for (int i = 0; i < translates.Length; ++i)
            translates[i] = new Translate(br);
            matrices = new Matrix[header.matrix.length];
            for (int i = 0; i < matrices.Length; ++i)
            matrices[i] = new Matrix(br);
            colors = new Color[header.color.length];
            for (int i = 0; i < colors.Length; ++i)
            colors[i] = new Color(br);
            alphaTransforms = new AlphaTransform[header.alphaTransform.length];
            for (int i = 0; i < alphaTransforms.Length; ++i)
            alphaTransforms[i] = new AlphaTransform(br);
            colorTransforms = new ColorTransform[header.colorTransform.length];
            for (int i = 0; i < colorTransforms.Length; ++i)
            colorTransforms[i] = new ColorTransform(br);
            objects = new Format.Object[header.objectData.length];
            for (int i = 0; i < objects.Length; ++i)
            objects[i] = new Format.Object(br);
            textures = new Format.Texture[header.texture.length];
            for (int i = 0; i < textures.Length; ++i)
            textures[i] = new Format.Texture(br);
            textureFragments =
            new Format.TextureFragment[header.textureFragment.length];
            for (int i = 0; i < textureFragments.Length; ++i)
            textureFragments[i] = new Format.TextureFragment(br);
            bitmaps = new Format.Bitmap[header.bitmap.length];
            for (int i = 0; i < bitmaps.Length; ++i)
            bitmaps[i] = new Format.Bitmap(br);
            bitmapExs = new Format.BitmapEx[header.bitmapEx.length];
            for (int i = 0; i < bitmapExs.Length; ++i)
            bitmapExs[i] = new Format.BitmapEx(br);
            fonts = new Format.Font[header.font.length];
            for (int i = 0; i < fonts.Length; ++i)
            fonts[i] = new Format.Font(br);
            textProperties = new Format.TextProperty[header.textProperty.length];
            for (int i = 0; i < textProperties.Length; ++i)
            textProperties[i] = new Format.TextProperty(br);
            texts = new Format.Text[header.text.length];
            for (int i = 0; i < texts.Length; ++i)
            texts[i] = new Format.Text(br);
            particleDatas = new Format.ParticleData[header.particleData.length];
            for (int i = 0; i < particleDatas.Length; ++i)
            particleDatas[i] = new Format.ParticleData(br);
            particles = new Format.Particle[header.particle.length];
            for (int i = 0; i < particles.Length; ++i)
            particles[i] = new Format.Particle(br);
            programObjects =
            new Format.ProgramObject[header.programObject.length];
            for (int i = 0; i < programObjects.Length; ++i)
            programObjects[i] = new Format.ProgramObject(br);
            graphicObjects =
            new Format.GraphicObject[header.graphicObject.length];
            for (int i = 0; i < graphicObjects.Length; ++i)
            graphicObjects[i] = new Format.GraphicObject(br);
            graphics = new Format.Graphic[header.graphic.length];
            for (int i = 0; i < graphics.Length; ++i)
            graphics[i] = new Format.Graphic(br);
            Format.Animation[] animationData =
            new Format.Animation[header.animation.length];
            for (int i = 0; i < animationData.Length; ++i)
            animationData[i] = new Format.Animation(br);
            buttonConditions =
            new Format.ButtonCondition[header.buttonCondition.length];
            for (int i = 0; i < buttonConditions.Length; ++i)
            buttonConditions[i] = new Format.ButtonCondition(br);
            buttons = new Format.Button[header.button.length];
            for (int i = 0; i < buttons.Length; ++i)
            buttons[i] = new Format.Button(br);
            labels = new Format.Label[header.label.length];
            for (int i = 0; i < labels.Length; ++i)
            labels[i] = new Format.Label(br);
            instanceNames = new Format.InstanceName[header.instanceName.length];
            for (int i = 0; i < instanceNames.Length; ++i)
            instanceNames[i] = new Format.InstanceName(br);
            events = new Format.Event[header.eventData.length];
            for (int i = 0; i < events.Length; ++i)
            events[i] = new Format.Event(br);
            places = new Format.Place[header.place.length];
            for (int i = 0; i < places.Length; ++i)
            places[i] = new Format.Place(br);
            controlMoveMs = new Format.ControlMoveM[header.controlMoveM.length];
            for (int i = 0; i < controlMoveMs.Length; ++i)
            controlMoveMs[i] = new Format.ControlMoveM(br);
            controlMoveCs = new Format.ControlMoveC[header.controlMoveC.length];
            for (int i = 0; i < controlMoveCs.Length; ++i)
            controlMoveCs[i] = new Format.ControlMoveC(br);
            controlMoveMCs =
            new Format.ControlMoveMC[header.controlMoveMC.length];
            for (int i = 0; i < controlMoveMCs.Length; ++i)
            controlMoveMCs[i] = new Format.ControlMoveMC(br);
            controls = new Format.Control[header.control.length];
            for (int i = 0; i < controls.Length; ++i)
            controls[i] = new Format.Control(br);
            frames = new Format.Frame[header.frame.length];
            for (int i = 0; i < frames.Length; ++i)
            frames[i] = new Format.Frame(br);
            movieClipEvents =
            new Format.MovieClipEvent[header.movieClipEvent.length];
            for (int i = 0; i < movieClipEvents.Length; ++i)
            movieClipEvents[i] = new Format.MovieClipEvent(br);
            movies = new Format.Movie[header.movie.length];
            for (int i = 0; i < movies.Length; ++i)
            movies[i] = new Format.Movie(br);
            movieLinkages = new Format.MovieLinkage[header.movieLinkage.length];
            for (int i = 0; i < movieLinkages.Length; ++i)
            movieLinkages[i] = new Format.MovieLinkage(br);
            Format.String[] stringData =
            new Format.String[header.stringData.length];
            for (int i = 0; i < stringData.Length; ++i)
            stringData[i] = new Format.String(br);

            animations = new int[animationData.Length][];
            for (int i = 0; i < animationData.Length; ++i) {
            animations[i] = ReadAnimation(animationByteData,
                (int)animationData[i].animationOffset,
                (int)animationData[i].animationLength);
            }

            strings = new string[stringData.Length];
            for (int i = 0; i < stringData.Length; ++i) {
            strings[i] = System.Text.Encoding.UTF8.GetString(stringByteData,
                (int)stringData[i].stringOffset,
                (int)stringData[i].stringLength);
            }

            stringMap = new Dictionary<string, int>();
            for (int i = 0; i < strings.Length; ++i)
            stringMap[strings[i]] = i;

            instanceNameMap = new Dictionary<int, int>();
            for (int i = 0; i < instanceNames.Length; ++i)
            instanceNameMap[instanceNames[i].stringId] = i;

            eventMap = new Dictionary<int, int>();
            for (int i = 0; i < events.Length; ++i)
            eventMap[events[i].stringId] = i;

            movieLinkageMap = new Dictionary<int, int>();
            movieLinkageNameMap = new Dictionary<int, int>();
            for (int i = 0; i < movieLinkages.Length; ++i) {
            movieLinkageMap[movieLinkages[i].stringId] = i;
            movieLinkageNameMap[movieLinkages[i].movieId] =
                movieLinkages[i].stringId;
            }

            programObjectMap = new Dictionary<int, int>();
            for (int i = 0; i < programObjects.Length; ++i)
            programObjectMap[programObjects[i].stringId] = i;

            labelMap = new Dictionary<int, int>[movies.Length];
            for (int i = 0; i < movies.Length; ++i) {
            Format.Movie m = movies[i];
            int o = m.labelOffset;
            Dictionary<int, int> map = new Dictionary<int, int>();
            for (int j = 0; j < m.labels; ++j) {
                Format.Label l = labels[o + j];
                map[l.stringId] = l.frameNo;
            }
            labelMap[i] = map;
            }

            for (int i = 0; i < textures.Length; ++i)
            textures[i].SetFilename(this);

            bitmapMap = new Dictionary<string, int>();
            var bitmapList = new List<Format.Bitmap>(bitmaps);
            for (int i = 0; i < textureFragments.Length; ++i) {
            textureFragments[i].SetFilename(this);
            bitmapMap[textureFragments[i].filename] = bitmapList.Count;
            bitmapList.Add(
                new Format.Bitmap{matrixId = 0, textureFragmentId = i});
            }
            bitmaps = bitmapList.ToArray();
        }