Beispiel #1
0
        public static int Process3DClick(int x, int y)
        {
            Ray   ray     = engine.UnprojectClick(x, y);
            int   idx     = -1;
            float minDist = 100000;

            for (int i = 0; i < objects.Count; i++)
            {
                BF2LevelObject lo = objects[i];
                BoundingSphere s  = lo.CalcBoundingSphere();
                s.Center = lo.position;
                float dist = 0;
                if (Collision.RayIntersectsSphere(ref ray, ref s, out dist))
                {
                    if (lo.CheckRayHit(ray, out dist))
                    {
                        if (dist < minDist)
                        {
                            minDist = dist;
                            idx     = i;
                        }
                    }
                }
            }
            return(idx);
        }
Beispiel #2
0
        private void rtbProps_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            int n = listBox1.SelectedIndex;

            if (n == -1)
            {
                return;
            }
            StringBuilder  sb = new StringBuilder();
            BF2LevelObject lo = BF2Level.objects[n];

            foreach (string s in lo.properties)
            {
                sb.AppendLine(s);
            }
            TextEditor te = new TextEditor();

            te.rtb1.Text = sb.ToString();
            te.ShowDialog();
            if (te._exitOk)
            {
                StringReader  sr    = new StringReader(te.rtb1.Text);
                List <string> props = new List <string>();
                string        line;
                while ((line = sr.ReadLine()) != null)
                {
                    if (line.Trim() != "")
                    {
                        props.Add(line);
                    }
                }
                lo.properties = props;
                rtbProps.Text = te.rtb1.Text;
            }
        }
Beispiel #3
0
        private void listBox1_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            int n = listBox1.SelectedIndex;

            if (n == -1)
            {
                return;
            }
            BF2Level.SelectIndex(n);
            allowEdit = false;
            BF2LevelObject lo = BF2Level.objects[n];

            textBox1.Text   = lo.position.X.ToString();
            textBox2.Text   = lo.position.Y.ToString();
            textBox3.Text   = lo.position.Z.ToString();
            trackBar1.Value = NormRot(lo.rotation.X);
            trackBar2.Value = NormRot(lo.rotation.Y);
            trackBar3.Value = NormRot(lo.rotation.Z);
            bool enabled = true;

            if (lo.type == BF2LevelObject.BF2LOTYPE.Road)
            {
                enabled = false;
            }
            trackBar1.Enabled = trackBar2.Enabled = trackBar3.Enabled = enabled;
            StringBuilder sb = new StringBuilder();

            foreach (string s in lo.properties)
            {
                sb.AppendLine(s);
            }
            rtbProps.Text = sb.ToString();
            allowEdit     = true;
        }
Beispiel #4
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;
            }
        }
Beispiel #5
0
        private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
        {
            int n = listBox1.SelectedIndex;

            if (e.KeyChar == 13 && allowEdit && n != -1)
            {
                try
                {
                    BF2LevelObject lo = BF2Level.objects[n];
                    lo.position.Z = Convert.ToSingle(textBox3.Text);
                    lo.RefreshTransform();
                }
                catch { };
            }
        }
Beispiel #6
0
        private void trackBar3_Scroll(object sender, EventArgs e)
        {
            int n = listBox1.SelectedIndex;

            if (n == -1 || !allowEdit)
            {
                return;
            }
            BF2LevelObject lo = BF2Level.objects[n];

            if (lo.type != BF2LevelObject.BF2LOTYPE.StaticObject)
            {
                return;
            }
            lo.rotation.Z = trackBar3.Value / 10f;
            lo.RefreshTransform();
        }
Beispiel #7
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));
        }
Beispiel #8
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);
            }
        }
Beispiel #9
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);
            }
        }