Example #1
0
        public static void CloneEntry(int n)
        {
            BF2LevelObject lo = objects[n];
            BF2LevelObject nlo;

            switch (lo.type)
            {
            case BF2LevelObject.BF2LOTYPE.StaticObject:
                nlo            = new BF2LevelObject(lo.position, lo.rotation, BF2LevelObject.BF2LOTYPE.StaticObject);
                nlo._data      = lo._data.ToArray();
                nlo._template  = lo._template;
                nlo._name      = lo._name;
                nlo.properties = new List <string>(lo.properties.ToArray());
                BF2StaticMesh stm = new BF2StaticMesh(nlo._data);
                if (stm == null)
                {
                    return;
                }
                nlo.staticMeshes = stm.ConvertForEngine(engine, true, 0);
                foreach (RenderObject ro in nlo.staticMeshes)
                {
                    nlo.transform = lo.transform;
                }
                nlo._valid = true;
                objects.Add(nlo);
                break;

            case BF2LevelObject.BF2LOTYPE.Road:
                nlo            = new BF2LevelObject(lo.position, lo.rotation, BF2LevelObject.BF2LOTYPE.Road);
                nlo._data      = lo._data.ToArray();
                nlo._template  = lo._template;
                nlo._name      = lo._name;
                nlo.properties = new List <string>(lo.properties.ToArray());
                BF2Mesh mesh = new BF2Mesh(nlo._data);
                if (mesh == null)
                {
                    return;
                }
                Texture2D tex = FindRoadTexture(nlo._name);
                nlo.meshes = mesh.ConvertForEngine(engine, tex);
                foreach (RenderObject ro in nlo.meshes)
                {
                    ro.transform = nlo.transform;
                }
                nlo._valid = true;
                objects.Add(nlo);
                break;
            }
        }
Example #2
0
        private static void LoadRoadObject(List <string> infos)
        {
            string objectName = Helper.FindLineStartingWith(infos, "object.create");

            if (objectName == null)
            {
                return;
            }
            string meshName = Helper.FindLineStartingWith(infos, "object.geometry.loadMesh");

            if (meshName == null)
            {
                return;
            }
            string  position = Helper.FindLineStartingWith(infos, "object.absolutePosition");
            Vector3 pos      = Vector3.Zero;
            Vector3 rot      = Vector3.Zero;

            if (position != null)
            {
                pos = Helper.ParseVector3(position.Split(' ')[1]);
            }
            objectName = objectName.Split(' ')[1];
            meshName   = meshName.Split(' ')[1];
            BF2LevelObject lo          = null;
            bool           foundCached = false;

            foreach (BF2LevelObject obj in objects)
            {
                if (obj._template == meshName && obj.type == BF2LevelObject.BF2LOTYPE.Road)
                {
                    lo            = new BF2LevelObject(pos, rot, obj.type);
                    lo._template  = meshName;
                    lo._name      = objectName;
                    lo._data      = obj._data.ToArray();
                    lo.properties = infos;
                    switch (obj.type)
                    {
                    case BF2LevelObject.BF2LOTYPE.Road:
                        BF2Mesh mesh = new BF2Mesh(lo._data);
                        if (mesh == null)
                        {
                            return;
                        }
                        Texture2D tex = FindRoadTexture(lo._name);
                        lo.meshes = mesh.ConvertForEngine(engine, tex);
                        foreach (RenderObject ro in lo.meshes)
                        {
                            ro.transform = lo.transform;
                        }
                        lo._valid   = true;
                        foundCached = true;
                        break;
                    }
                    break;
                }
            }
            if (!foundCached)
            {
                lo = new BF2LevelObject(pos, rot, BF2LevelObject.BF2LOTYPE.Road);
                BF2FileSystem.BF2FSEntry entry = BF2FileSystem.FindFirstEntry(meshName);
                lo._data = BF2FileSystem.GetFileFromEntry(entry);
                if (lo._data == null)
                {
                    return;
                }
                lo._template  = meshName;
                lo._name      = objectName;
                lo.properties = infos;
                BF2Mesh mesh = new BF2Mesh(lo._data);
                if (mesh == null)
                {
                    return;
                }
                Texture2D tex = FindRoadTexture(lo._name);
                lo.meshes = mesh.ConvertForEngine(engine, tex);
                foreach (RenderObject ro in lo.meshes)
                {
                    ro.transform = lo.transform;
                }
                lo._valid = true;
            }
            if (lo != null && lo._valid)
            {
                objects.Add(lo);
            }
        }