[x] Main Menu

How-to import NFS cars

(2509 total words in this text)
(22649 reads)   Printer Friendly Page




NFS 3-4 Cars import for TORCS




This tutorial explain how to import a car from EA Need For Speed (NFS) file format cars into TORCS.

First important point:

PLEASE DO NOT PORT AND PUBLISH CARS WITHOUT THE AUTHORIZATION OF THE AUTHOR

This tutorial is based on the Jaguar E lightweight of Butch (K/Cendra)

You will need the following tools to make the conversion:
  • NFS Wizard - a Win32 tool to extract the files from the car.viv (Can be found on many NFS related sites)
  • AC3D - a 3D modeler shareware
  • The Gimp - The GNU Image Manipulation Program

Extracting the files

Ok now let's start with a car.viv file, the first step will be to extract the files with NFS Wizard under win32.

the files extracted look like:

-rw-r--r--    1 torcs    torcs     1049115 Aug  4  2003 car00.tga
-rw-r--r--    1 torcs    torcs      825624 Aug  4  2003 careng.bnk
-rw-r--r--    1 torcs    torcs        7528 Aug  4  2003 careng.ctb
-rw-r--r--    1 torcs    torcs        7528 Aug  4  2003 careng.ltb
-rw-r--r--    1 torcs    torcs     1179040 Aug  4  2003 car.fce
-rw-r--r--    1 torcs    torcs        4823 Aug  4  2003 carp.txt
-rw-r--r--    1 torcs    torcs     5643159 Aug  4  2003 car.viv
-rw-r--r--    1 torcs    torcs     1049115 Aug  4  2003 dash00.tga
-rw-r--r--    1 torcs    torcs      675680 Aug  4  2003 dash.fce
-rw-r--r--    1 torcs    torcs       66616 Aug  4  2003 dash.fsh
-rw-r--r--    1 torcs    torcs        1557 Aug  4  2003 fedata.bri
-rw-r--r--    1 torcs    torcs        1557 Aug  4  2003 fedata.eng
-rw-r--r--    1 torcs    torcs        1553 Aug  4  2003 fedata.fre
-rw-r--r--    1 torcs    torcs      131112 Aug  4  2003 fedata.fsh
-rw-r--r--    1 torcs    torcs        1562 Aug  4  2003 fedata.ger
-rw-r--r--    1 torcs    torcs        1577 Aug  4  2003 fedata.ita
-rw-r--r--    1 torcs    torcs        1557 Aug  4  2003 fedata.spa
-rw-r--r--    1 torcs    torcs        1566 Aug  4  2003 fedata.swe
-rw-r--r--    1 torcs    torcs       90981 Aug  4  2003 jgel.qfs
-rw-r--r--    1 torcs    torcs       81976 Aug  4  2003 ocareng.bnk
-rw-r--r--    1 torcs    torcs         257 Aug  4  2003 readme.txt
-rw-r--r--    1 torcs    torcs      553704 Aug  4  2003 scareng.bnk


In red you can see the important files.

We'll continue the tutorial under Linux.

Converting the files

Make a directory to store the car in the runtime directory :

$ cd /usr/share/games/torcs/cars
$ mkdir kc-lightweight

Copy the files in this directory :

-rw-r--r-- 1 torcs torcs 1049115 Mar 17 22:04 car00.tga
-rw-r--r-- 1 torcs torcs 1179040 Mar 17 22:04 car.fce
-rw-r--r-- 1 torcs torcs    4823 Mar 17 22:04 carp.txt
-rw-r--r-- 1 torcs torcs     257 Mar 17 22:04 readme.txt

Use The Gimp to convert the texture in rgb format:







We'll see the necessary modifications of the texture later.

3D Mesh conversion

The tool used to convert the 3D model is called nfs2ac written by Christophe Guionneau.
The usage is:

$ nfs2ac car.fce > kc-lightweight.ac

Now we have the 3D model in AC3D format, we can edit it to change the texture name from car00.tga to kc-lightweight.rgb
and open it with AC3D:



First remove the wheels as TORCS provides its own wheels:

Select the object mode:



The select the wheels:



and remove them:



Set the vertical origin of the car at the bottom:



First select all (Ctrl-a)  then use the arrow to get the size, set the y value to half the height of the car and click on the Move to button.

Now make the transparent parts a separate object.

Select only the body (:HB) with the Hierarchy View tool:



Then hide the other parts of the car:



Now switch in surface mode and select all the glasses:



With the menu Surface -> Cut-away object... (Ctrl + Shift + X)  make a new object from the windows,
switch back to the Object mode and name the new object :WI



Locate the windows location on the texture with the Tool -> Texture Coordinate Editor (F10)
then use The Gimp to make it transparent in the texture (along with the steering wheel border).



Now use the menu Object -> Optimize surfaces... to remove degenerated surfaces.
Save this first version into kc-lightweight.ac and remove the "crease"
lines from the file.

Generating the wheel texture

We will use the wheel in the car texture:

First extract it with The Gimp:



Then add the tire around:



Use the Filter -> Blur -> Motion Blur filter in radial mode with the following values for Length and Angle:
  • 10, 10
  • 20, 20
  • 40, 40


to compose the following image:



Resize it to 128x128 and save it as tex-wheel.rgb

Now create a white image of 128x128 called shadow.rgb

The files so far should be:

-rw-r--r--    1 torcs    torcs     1049115 Mar 17 22:04 car00.tga
-rw-r--r--    1 torcs    torcs     1179040 Mar 17 22:04 car.fce
-rw-r--r--    1 torcs    torcs        4823 Mar 17 22:04 carp.txt
-rw-r--r--    1 torcs    torcs      401487 Mar 17 23:14 kc-lightweight.ac
-rw-rw-r--    1 torcs    torcs     1049088 Mar 17 23:09 kc-lightweight.rgb
-rw-r--r--    1 torcs    torcs         257 Mar 17 22:04 readme.txt
-rw-rw-r--    1 torcs    torcs       66048 Mar 17 23:39 shadow.rgb
-rw-rw-r--    1 torcs    torcs       66048 Mar 17 23:38 tex-wheel.rgb

Creating the XML file with the car's settings

First check that the carp.txt file do not end with a coma ',' (remove it if necessary)
the use the nfsperf tool to convert the settings from the NFS description to TORCS description.

$ nfsperf -c ../../categories/Historic/Historic.xml -o kc-lightweight.xml

Now edit the kc-lightweight.xml file.

First you have to fix the beginning of the file. Replace the header by:

<?xml version="1.0" encoding="UTF-8"?>
<!--
    file        : kc-lightweight.xml
    created     : Thu Mar 18 22:27:40 CET 2004
    copyright   : (C) 2004 by Eric Espié                        
    email       : Eric.Espie@torcs.org  
    version     : $Id$                                 
-->

<!--    This program is free software; you can redistribute it and/or modify  -->
<!--    it under the terms of the GNU General Public License as published by  -->
<!--    the Free Software Foundation; either version 2 of the License, or     -->
<!--    (at your option) any later version.                                   -->

<!DOCTYPE params SYSTEM "../../../../src/libs/tgf/params.dtd">

<!-- 3D Model copyright by Butch (K/cendra) (see readme.txt) -->

<params name="Jaguar E lightweight" type="template" mode="mw">



Then add the following sections:

  <section name="Driver">
    <!-- Position of the driver -->
    <attnum name="xpos" unit="m" val="0.10"/>
    <attnum name="ypos" unit="m" val="0.0"/>
    <attnum name="zpos" unit="m" val="0.89"/>
  </section>

  <section name="Graphic Objects">

    <attstr name="wheel texture" val="tex-wheel.rgb"/>
    <attstr name="shadow texture" val="shadow.rgb"/>

    <attstr name="tachometer texture" val="rpm7000.rgb"/>
    <attnum name="tachometer min value" unit="rpm" val="0"/>
    <attnum name="tachometer max value" unit="rpm" val="8000"/>

    <attstr name="speedometer texture" val="speed240.rgb"/>
    <attnum name="speedometer min value" unit="km/h" val="0"/>
    <attnum name="speedometer max value" unit="km/h" val="240"/>

    <section name="Ranges">
      <section name="1">
        <attnum name="threshold" val="0"/>
        <attstr name="car" val="kc-lightweight.ac"/>
        <attstr name="wheels" val="yes"/>
      </section>
    </section>

    <section name="Light">
      <section name="1">
        <attstr name="type" val="head1"/>
        <attnum name="xpos" val="1.89"/>
        <attnum name="ypos" val="0.62"/>
        <attnum name="zpos" val="0.44"/>
        <attnum name="size" val="0.2"/>
      </section>
      <section name="2">
        <attstr name="type" val="head1"/>
        <attnum name="xpos" val="1.89"/>
        <attnum name="ypos" val="-0.62"/>
        <attnum name="zpos" val="0.44"/>
        <attnum name="size" val="0.2"/>
      </section>
      <section name="3">
        <attstr name="type" val="head2"/>
        <attnum name="xpos" val="2.08"/>
        <attnum name="ypos" val="0.4"/>
        <attnum name="zpos" val="0.29"/>
        <attnum name="size" val="0.2"/>
      </section>
      <section name="4">
        <attstr name="type" val="head2"/>
        <attnum name="xpos" val="2.08"/>
        <attnum name="ypos" val="-0.4"/>
        <attnum name="zpos" val="0.29"/>
        <attnum name="size" val="0.2"/>
      </section>
      <section name="5">
       <attstr name="type" val="rear"/>
       <attnum name="xpos" val="-2.12"/>
       <attnum name="ypos" val="0.51"/>
       <attnum name="zpos" val="0.41"/>
       <attnum name="size" val="0.13"/>
      </section>
      <section name="6">
       <attstr name="type" val="rear"/>
       <attnum name="xpos" val="-2.12"/>
       <attnum name="ypos" val="-0.51"/>
       <attnum name="zpos" val="0.41"/>
       <attnum name="size" val="0.13"/>
      </section>
      <section name="7">
       <attstr name="type" val="brake"/>
       <attnum name="xpos" val="-2.16"/>
       <attnum name="ypos" val="0.42"/>
       <attnum name="zpos" val="0.41"/>
       <attnum name="size" val="0.2"/>
      </section>
      <section name="8">
       <attstr name="type" val="brake"/>
       <attnum name="xpos" val="-2.16"/>
       <attnum name="ypos" val="-0.42"/>
       <attnum name="zpos" val="0.41"/>
       <attnum name="size" val="0.2"/>
      </section>
    </section>

  </section>

The position of the driver have to be just before the wind-shield and the lights are optional.
The position are taken within AC3D.

Update the Car section with the values measured within AC3D.

  <section name="Car">
    <attstr name="category" val="Historic"/>
    <attnum name="body length" unit="m" val="4.341"/>
    <attnum name="body width" unit="m" val="1.80"/>
    <attnum name="body height" unit="m" val="1.028"/>
    <attnum name="overall length" unit="m" val="4.341"/>
    <attnum name="overall width" unit="m" val="1.8"/>
    <attnum name="mass" unit="kg" val="880"/>
    <attnum name="GC height" unit="m" val="0.3"/>
    <attnum name="front-rear weight repartition" val="0.55"/>
    <attnum name="front right-left weight repartition" val="0.5"/>
    <attnum name="rear right-left weight repartition" val="0.5"/>
    <attnum name="mass repartition coefficient" min="0.1" max="3" val="0.6"/>
    <attnum name="fuel tank" min="20" max="300" unit="l" val="50"/>
    <attnum name="initial fuel" min="1" max="300" unit="l" val="50"/>
  </section>


Use AC3D  to  set the axles positions:

  <section name="Front Axle">
    <attnum name="xpos" val="1.31"/>
    <attnum name="inertia" unit="kg.m2" val="0.0056"/>
    <attnum name="roll center height" min="-1" max="5" unit="m" val="0.2"/>
  </section>

  <section name="Rear Axle">
    <attnum name="xpos" val="-1.15"/>
    <attnum name="inertia" unit="kg.m2" val="0.008"/>
    <attnum name="roll center height" unit="m" val="0.2"/>
  </section>


Set up the wheels too:

  <section name="Front Right Wheel">
    <attnum name="ypos" min="-2" max="-0.1" unit="m" val="-0.62"/>
    <attnum name="rim diameter" unit="in" val="16"/>
    <attnum name="tire width" unit="mm" val="185"/>
    <attnum name="tire height-width ratio" unit="%" val="65"/>
    <attnum name="inertia" unit="kg.m2" val="1.22"/>
    <attnum name="ride height" min="100" max="2000" unit="mm" val="150"/>
    <attnum name="toe" min="-5" max="5" unit="deg" val="0"/>
    <attnum name="camber" min="-5" max="0" unit="deg" val="0"/>
    <attnum name="stiffness" min="1" max="30" val="20"/>
    <attnum name="dynamic friction" min="50" max="100" unit="%" val="80"/>
    <attnum name="rolling resistance" val="0.02"/>
    <attnum name="mu" val="1.35"/>
  </section>

  <section name="Front Left Wheel">
    <attnum name="ypos" min="0.1" max="2" unit="m" val="0.62"/>
    <attnum name="rim diameter" unit="in" val="16"/>
    <attnum name="tire width" unit="mm" val="185"/>
    <attnum name="tire height-width ratio" unit="%" val="65"/>
    <attnum name="inertia" unit="kg.m2" val="1.22"/>
    <attnum name="ride height" min="50" max="2000" unit="mm" val="150"/>
    <attnum name="toe" min="-5" max="5" unit="deg" val="0"/>
    <attnum name="camber" min="-5" max="0" unit="deg" val="0"/>
    <attnum name="stiffness" min="1" max="30" val="30"/>
    <attnum name="dynamic friction" min="50" max="100" unit="%" val="80"/>
    <attnum name="rolling resistance" val="0.02"/>
    <attnum name="mu" val="1.35"/>
  </section>

  <section name="Rear Right Wheel">
    <attnum name="ypos" min="-2" max="-0.1" unit="m" val="-0.72"/>
    <attnum name="rim diameter" unit="in" val="16"/>
    <attnum name="tire width" unit="mm" val="205"/>
    <attnum name="tire height-width ratio" unit="%" val="50"/>
    <attnum name="inertia" unit="kg.m2" val="1.22"/>
    <attnum name="ride height" min="50" max="2000" unit="mm" val="150"/>
    <attnum name="toe" min="-5" max="5" unit="deg" val="0"/>
    <attnum name="camber" min="-5" max="0" unit="deg" val="0"/>
    <attnum name="stiffness" min="1" max="30" val="30"/>
    <attnum name="dynamic friction" min="50" max="100" unit="%" val="80"/>
    <attnum name="rolling resistance" val="0.02"/>
    <attnum name="mu" val="1.65"/>
  </section>

  <section name="Rear Left Wheel">
    <attnum name="ypos" min="0.1" max="2" unit="m" val="0.72"/>
    <attnum name="rim diameter" unit="in" val="16"/>
    <attnum name="tire width" unit="mm" val="205"/>
    <attnum name="tire height-width ratio" unit="%" val="50"/>
    <attnum name="inertia" unit="kg.m2" val="1.22"/>
    <attnum name="ride height" min="50" max="2000" unit="mm" val="150"/>
    <attnum name="toe" min="-5" max="5" unit="deg" val="0"/>
    <attnum name="camber" min="-5" max="0" unit="deg" val="0"/>
    <attnum name="stiffness" min="1" max="30" val="30"/>
    <attnum name="dynamic friction" min="50" max="100" unit="%" val="80"/>
    <attnum name="rolling resistance" val="0.02"/>
    <attnum name="mu" val="1.65"/>
  </section>



Now the car should be driveable, the result so far is:



To make the shadow texture follow the tutorial.

It looks better now:



Additional Steps - Smoothing and Level of Details

To have reflections on the car, you'll need to run a tool called accc written by Christophe Guionneau.

$ kc-lightweight]$ accc +es 0 kc-lightweight.ac kc-lightweight.acc

This will generate an .acc file that will be referenced in the kc-lightweight.xml file instead of kc-lightweight.ac

<section name="Ranges">
   <section name="1">
     <attnum name="threshold" val="0"/>
     <attstr name="car" val="kc-lightweight.acc"/>
     <attstr name="wheels" val="yes"/>
   </section>
</section>

Now it looks much better:



Generating the LOD (Level of details)

This can be done with AC3D:

First load the kc-lightweight.ac file in AC3D, then switch to object mode and select all then use the menu:
Object -> Reduce... function with 80% as value:



Save the model as kc-lightweight-lod1.ac and uses accc to smooth it:

$ accc +es 30 kc-lightweight-lod1.ac kc-lightweight-lod1.acc

you can do the same to generate kc-lightweight-lod2.acc  kc-kc-lightweight-lod3.acc lightweight-lod4.acc
with respectively 60%, 40% and 20% of reduction factor.

Change kc-lightweight.xml accordingly:

<section name="Ranges">
  <section name="1">
    <attnum name="threshold" val="20"/>
    <attstr name="car" val="kc-lightweight.acc"/>
    <attstr name="wheels" val="yes"/>
  </section>
  <section name="2">
    <attnum name="threshold" val="15"/>
    <attstr name="car" val="kc-lightweight-lod1.acc"/>
    <attstr name="wheels" val="yes"/>
  </section>
  <section name="3">
    <attnum name="threshold" val="10"/>
    <attstr name="car" val="kc-lightweight-lod2.acc"/>
    <attstr name="wheels" val="no"/>
  </section>
  <section name="4">
    <attnum name="threshold" val="5"/>
    <attstr name="car" val="kc-lightweight-lod3.acc"/>
    <attstr name="wheels" val="no"/>
  </section>
  <section name="5">
    <attnum name="threshold" val="0"/>
    <attstr name="car" val="kc-lightweight-lod4.acc"/>
    <attstr name="wheels" val="no"/>
  </section>
</section>


Now, it's done you can play with it.
User Info [x]

Welcome Anonymous

Nickname
Password

Membership:
Latest: Skoynay
New Today: 0
New Yesterday: 0
Overall: 3576

People Online:
Members: 0
Visitors: 16
Bots: 1
Staff: 0
Staff Online:

No staff members are online!

Current Poll [x]
Would you like to develop a robot ?

I don't know what you are talking about
25 %25 %25 %
I know what you mean, but I just want to drive
35 %35 %35 %
Yes (check the other polls)
34 %34 %34 %
I already have developed a robot (let us know)
5 %5 %5 %
Results :: Polls

Votes: 6489
Comments: 29

Hits [x]
We have received
12181827
page views since
November 2001


Hosted by:
SourceForge.net Logo
All logos and trademarks on this site are property of their respective owner. The comments are property of their posters.
The site content and design is © 2001-2012 Bernhard Wymann, Eric EspiĆ©.
Interactive software released under GNU GPL, Code Credits, Privacy Policy