Exemplo n.º 1
0
        private static BF2StaticMesh LoadStaticMesh(List <string> infos, BF2LevelObject lo)
        {
            string geoTemplate = Helper.FindLineStartingWith(infos, "GeometryTemplate.create");

            if (geoTemplate == null)
            {
                return(null);
            }
            string[] parts        = geoTemplate.Split(' ');
            string   templateName = parts[2].Trim() + ".staticmesh";

            BF2FileSystem.BF2FSEntry entry = BF2FileSystem.FindFirstEntry(templateName);
            byte[] data = BF2FileSystem.GetFileFromEntry(entry);
            if (data == null)
            {
                return(null);
            }
            lo._data = data;
            return(new BF2StaticMesh(data));
        }
Exemplo n.º 2
0
        private static void LoadStaticObject(List <string> infos)
        {
            string templateName = Helper.FindLineStartingWith(infos, "Object.create");

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

            if (position != null)
            {
                pos = Helper.ParseVector3(position.Split(' ')[1]);
            }
            if (rotation != null)
            {
                rot = Helper.ParseVector3(rotation.Split(' ')[1]);
            }
            templateName = templateName.Split(' ')[1] + ".con";
            BF2LevelObject lo          = null;
            bool           foundCached = false;

            foreach (BF2LevelObject obj in objects)
            {
                if (obj._template == templateName && obj.type == BF2LevelObject.BF2LOTYPE.StaticObject)
                {
                    lo            = new BF2LevelObject(pos, rot, obj.type);
                    lo._template  = templateName;
                    lo._name      = templateName;
                    lo._data      = obj._data.ToArray();
                    lo.properties = infos;
                    switch (obj.type)
                    {
                    case BF2LevelObject.BF2LOTYPE.StaticObject:
                        BF2StaticMesh stm = new BF2StaticMesh(lo._data);
                        if (stm == null)
                        {
                            return;
                        }
                        lo.staticMeshes = stm.ConvertForEngine(engine, true, 0);
                        foreach (RenderObject ro in lo.staticMeshes)
                        {
                            ro.transform = lo.transform;
                        }
                        lo._valid   = true;
                        foundCached = true;
                        break;
                    }
                    break;
                }
            }
            if (!foundCached)
            {
                BF2FileSystem.BF2FSEntry entry = BF2FileSystem.FindFirstEntry(templateName);
                byte[] data = BF2FileSystem.GetFileFromEntry(entry);
                if (data == null)
                {
                    return;
                }
                List <string> infosObject = new List <string>(Encoding.ASCII.GetString(data).Split('\n'));
                string        geoTemplate = Helper.FindLineStartingWith(infosObject, "GeometryTemplate.create");
                if (geoTemplate == null)
                {
                    return;
                }
                string[] parts = geoTemplate.Split(' ');
                switch (parts[1].ToLower())
                {
                case "staticmesh":
                    lo            = new BF2LevelObject(pos, rot, BF2LevelObject.BF2LOTYPE.StaticObject);
                    lo._template  = templateName;
                    lo._name      = templateName;
                    lo.properties = infos;
                    BF2StaticMesh stm = LoadStaticMesh(infosObject, lo);
                    if (stm == null)
                    {
                        return;
                    }
                    lo.staticMeshes = stm.ConvertForEngine(engine, true, 0);
                    foreach (RenderObject ro in lo.staticMeshes)
                    {
                        ro.transform = lo.transform;
                    }
                    lo._valid = true;
                    break;
                }
            }
            if (lo != null && lo._valid)
            {
                objects.Add(lo);
            }
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
0
        private void exportALLAsObjToolStripMenuItem_Click(object sender, EventArgs e)
        {
            exportALLAsObjToolStripMenuItem.Enabled = false;
            FolderBrowserDialog fbd = new FolderBrowserDialog();

            if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string basePath = fbd.SelectedPath + "\\";
                pb1.Maximum = BF2FileSystem.clientFS.Count;
                int count = 0;
                foreach (BF2FileSystem.BF2FSEntry entry in BF2FileSystem.clientFS)
                {
                    pb1.Value = count++;
                    try
                    {
                        string ending = Path.GetExtension(entry.inFSPath).ToLower();
                        switch (ending)
                        {
                        case ".staticmesh":
                        case ".bundledmesh":
                        case ".skinnedmesh":
                        case ".collisionmesh":
                            break;

                        default:
                            continue;
                        }
                        string path = basePath + Path.GetDirectoryName(entry.inFSPath);
                        byte[] data = BF2FileSystem.GetFileFromEntry(entry);
                        if (data == null)
                        {
                            continue;
                        }
                        switch (ending)
                        {
                        case ".staticmesh":
                            CheckAndMakeDir(path);
                            path += "\\" + Path.GetFileNameWithoutExtension(entry.inFSPath);
                            Log.WriteLine("Exporting \"" + path + ".staticmesh\"...");
                            BF2StaticMesh stm = new BF2StaticMesh(data);
                            for (int i = 0; i < stm.geomat.Count; i++)
                            {
                                ExporterObj.Export(stm, path + ".lod" + i + ".obj", i);
                            }
                            break;

                        case ".bundledmesh":
                            CheckAndMakeDir(path);
                            path += "\\" + Path.GetFileNameWithoutExtension(entry.inFSPath);
                            Log.WriteLine("Exporting \"" + path + ".bundledmesh\"...");
                            BF2BundledMesh bm = new BF2BundledMesh(data);
                            for (int i = 0; i < bm.geomat.Count; i++)
                            {
                                ExporterObj.Export(bm, path + ".lod" + i + ".obj", i);
                            }
                            break;

                        case ".skinnedmesh":
                            CheckAndMakeDir(path);
                            path += "\\" + Path.GetFileNameWithoutExtension(entry.inFSPath);
                            Log.WriteLine("Exporting \"" + path + ".skinnedmesh\"...");
                            BF2SkinnedMesh skm = new BF2SkinnedMesh(data);
                            for (int i = 0; i < skm.geomat.Count; i++)
                            {
                                ExporterObj.Export(skm, path + ".lod" + i + ".obj", i);
                            }
                            break;

                        case ".collisionmesh":
                            CheckAndMakeDir(path);
                            path += "\\" + Path.GetFileNameWithoutExtension(entry.inFSPath);
                            Log.WriteLine("Exporting \"" + path + ".bundledmesh\"...");
                            ExporterObj.Export(new BF2CollisionMesh(data), path + ".obj");
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.WriteLine("ERROR: " + ex.Message);
                    }
                    Application.DoEvents();
                }
                pb1.Value = 0;
                exportALLAsObjToolStripMenuItem.Enabled = true;
            }
        }