This topic contains 1 reply, has 0 voices, and was last updated by  cbx550f 13 years, 2 months ago.

  • Author
    Posts
  • #2773

    cbx550f
    Participant

    I’ve been having trouble loading the models that Shockwave has made and posted – kept getting the “Failed to load…” error. (I’m running Linux)

    Took a look into it, and I found two problems:

    1. Shock: Many of your texture files are referenced like:
    “……..Scorched3Ddatatanksvaderstieblack.bmp”

    This should just be:
    “.black.bmp”

    This will ensure that they will work regardless of the installation path. (For example my installation path on my Linux machine is /usr/local/games/scorched3d/share/data/tanks/, and Linux is case sensitive for path and filenames, so it failed)

    2. The files Shock created had both a CR and a LF (ie:rn) at the end of each line. This is not your fault Shock, just a difference in the way Windows and *nix systems end their lines. This can be worked around by removing the r from the end of each line, one way to do this is as follows:

    Open the offending file in binary mode in vi:
    vi -b modelfile.txt
    Type the following to delete the r on every line:
    :%s/r//g
    Save and quit (shift-ZZ)

    A bit of a kludge, but it works. I took a look at the Scorched source, and added a fix for this in “src/3dsparse/MSFile.cpp”

    In the MSFile::getNextLine section, at line 41, I added the following lines:

                    if(strpbrk(line,"r"))
    {
    char * wincr;
    if (wincr=strchr(line,'r'))
    {
    *wincr='n';
    *(wincr + 1) = '';
    }
    }

    To be clear, the whole section now looks as follows:

    bool MSFile::getNextLine(char *line, FILE *in)
    {
    while (fgets(line, 256, in) != 0)
    {
    lineNo_++;
    if(strpbrk(line,"r"))
    {
    char * wincr;
    if (wincr=strchr(line,'r'))
    {
    *wincr='n';
    *(wincr + 1) = '';
    }
    }


    if ((line[0] == '\' && line[1] == '\') ||
    (line[0] == '/' && line[1] == '/') ||
    (line[0] == '') ||
    (line[0] == 'n'))
    {
    // Skip this line
    }
    else return true;
    }

    return false;
    }

    I shouldn’t think that this would cause any trouble with Windows users, and it stops it from puking out on a Linux machine. 🙂

    Cheers!

    cbx

    #12761

    imported_gcamp
    Participant

    Cheers, i’ve added this fix into CVS.

    #12762

    cbx550f
    Participant

    M.O. requested some instructions on how to fix this – I’m guessing that editing the source was not a desireable solution, so try the following. (if you want to edit the source, instructions are above!)

    (I’m assuming you have the tank’s files extracted to the data/tanks folder already)

    1. With your favourite text editor, save the following to a file (call it tankfix.sh, for ease of instructions, save it to your home directory):

    #!/bin/bash
    #
    # Fixes up Scorched3d models made by Windows users for Linux
    # Dangerous! Be careful!
    #Removes r from EOL
    #Also fixes naughty pathnames:
    # example offending line:
    # "........Scorched3Ddatatanksxwingblue.bmp"
    # converts to: ".blue.bmp"

    if [ ! $1 ]
    then
    echo "Usage: $0 tankfile.txt"
    echo "Where "tankfile.txt" is the file you need to fix."
    else
    # Making backup:
    cp -v $1 $1.bak
    sed -e 's/.$//' -e '/"../s/(.*)\/".\/' $1 > $1.tmp

    mv -v $1.tmp $1
    fi

    2. Go to the tank’s directory. (ie: In a console/xterm do:
    cd /usr/local/games/scorched3d/share/data/tanks/xwing)

    3. Run the script: ~/tankfix.sh xwing.txt

    That should be all you need to do. The script creates a backup of the original and saves it with a .bak extension, so if something ugly happened, you can recover.

    Be careful with the script, make sure you only run it on tank files! Unknown things could happen otherwise. 😉

    Hope this helps!

    cbx

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.