Some kind of script that "splits" Jbeam files in 2 symmetrically?

Discussion in 'Programming' started by Agent_Y, Aug 19, 2021.

  1. Agent_Y

    Agent_Y
    Expand Collapse
    Jbeam/QA support
    BeamNG Team

    Joined:
    Jul 10, 2020
    Messages:
    10,060
    So i've had the idea for a mod that adds asymmetrical wheels. This is totally doable, has worked for me on trailers. All you have to do is have separate left and right spindles, and separate wheels Jbeam, asymmetrical brakes are also easy. To implement this in a car, you would simply have to add asymmetrical wheel hubs in place of normal wheels, have separate slots there for left and right brakes and wheels, spindles for custom wheels loaded after each wheel, and then a bunch of code that negates the effect of the car's normal spindles so that old wheels won't spawn on top of new ones. (Which is doable, just set all the wheel and brake values to false before they spawn, like it's done for the 2 axle trailers.)

    The only issue is that, you need Jbeam for the wheels. You would have to split the Jbeam of every wheel, tire and hubcap in the game into left and right wheels, and rename everything accordingly. And there are a lot of wheels and tires in the game especially, so doing it manually is definitely out of the question. I have done it manually for a few stock trailer wheels and tires, and it already took several days.

    So specifically, for wheels, we need to turn this:
    1.png
    Into something like these:
    2.png
    And the same for tires and hubcaps too. For every single file in the wheels, tires and hubcaps folders. (except Pigeon single front wheels and tires.)

    So I thought that someone could write a script that does this automatically, because it just requires a lot of repeated procedures, which is what scripts are usually for. Something to run in the Windows command prompt for example. I could do it myself, but honestly I have no idea where to even start. Last time I did something similar was 3 years ago and on Linux, which is fundamentally different than Windows, and I mostly forgot how to do this. Either someone has to explain to me how to do it, or maybe write the whole script, it can't be THAT hard.

    If nobody wants to help, that's fine, it's just a random idea and I don't have to make a mod out of this after all.
     
    • Like Like x 1
  2. fufsgfen

    fufsgfen
    Expand Collapse

    Joined:
    Jan 10, 2017
    Messages:
    6,782
    I just quickly glanced those changes, but maybe that is something that you would do with a regex?

    In Notepad++ you can set search and replace to work in regex mode, which then could allow you to do similar thing you did with the Linux.

    If you think that you can go with regular expressions, there is quite lot of tutorials about it, like this site for example:
    https://www.regular-expressions.info/

    I have also a book called Regular expressions pocket primer, which is quite handy to have around.

    Not sure if that helps you forward, but regex is one of things I'm working on to learn, just haven't got enough hours on my days for everything.
     
  3. Agent_Y

    Agent_Y
    Expand Collapse
    Jbeam/QA support
    BeamNG Team

    Joined:
    Jul 10, 2020
    Messages:
    10,060
    I was using regex to do this the manual way, I know very well how it works. Writing a regex that would cover the entire file would be a ton of work. But the idea is good, this would be faster than doing it file by file. Maybe like multiple regular expressions step by step would do the job.
     
  4. fufsgfen

    fufsgfen
    Expand Collapse

    Joined:
    Jan 10, 2017
    Messages:
    6,782
    Also one thing, that you probably know, but it might make task easier if splitting tires to separate files for game it should not matter if left and right ones are separate files.

    Oh yes and I did eventually realize you had done that already, like super smart brain and all that :D
     
    #4 fufsgfen, Aug 20, 2021
    Last edited: Aug 20, 2021
  5. fufsgfen

    fufsgfen
    Expand Collapse

    Joined:
    Jan 10, 2017
    Messages:
    6,782
    For fun I did see if I could make program that would split file to two and modify lines, I guess it might be possible, but then again it is so much work that I'm not sure if there is point.

    Anyway this is very beginning of what I got, after first stage then new round of renaming is needed, so essentially it is same to do with regex in notepad++ I guess.

    By itself this part of C# code does nothing, but perhaps just shows idea if one wants to keep working on it.
    Code:
    StreamReader reader = new StreamReader(@"pathtofile\wheels_F_4.jbeam");
                StreamWriter writer = new StreamWriter(@"pathtofile\wheels_FR_4.jbeam");
                while (!reader.EndOfStream)
                {
                    string line = reader.ReadLine();
                    if (line.Contains("_F\"") || line.Contains("_F_"))
                    {
                        line = line.Replace("_F", "_FR");
                    }
                    writer.WriteLine(line);
                }
                reader.Close();
                writer.Close();
    
     
  6. Agent_Y

    Agent_Y
    Expand Collapse
    Jbeam/QA support
    BeamNG Team

    Joined:
    Jul 10, 2020
    Messages:
    10,060
    Well, this shows that making a script for this makes no sense after all, and it's way easier to just use regex multiple times. Thanks for testing this.
     
    • Like Like x 1
  7. fufsgfen

    fufsgfen
    Expand Collapse

    Joined:
    Jan 10, 2017
    Messages:
    6,782
    If we would build universal jbeam deserializer, then it might be worth the time and effort as such class could be then used for other tools.

    It's just way over my skills, but it is kinda fun to try...
     
  8. Agent_Y

    Agent_Y
    Expand Collapse
    Jbeam/QA support
    BeamNG Team

    Joined:
    Jul 10, 2020
    Messages:
    10,060
    That would be so much work for little purpose, there are tons of possible sections in Jbeam, also with the ability to add your own ones using LUA controllers, there are also many things that lack standarizations (mostly with the props rather than vehicles, there are various header formats there that aren't compatible with each other or with vehicles, various incompatible formats of variables, flexbodies and thrusters among the vehicles, many deprecated things that do nothing but still need to be kept for compatibility with stuff in the common folder and mods)...
     
  9. fufsgfen

    fufsgfen
    Expand Collapse

    Joined:
    Jan 10, 2017
    Messages:
    6,782
    And to add to that, next update always stirs something new into mess throwing all or at least some of the work out of the window
     
    • Agree Agree x 1
  10. NOCARGO

    NOCARGO
    Expand Collapse

    Joined:
    Apr 1, 2019
    Messages:
    1,514
    agreed :)

    and agreed :)



    Notepad++ very good friend, finds and replaces :)
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice