NFSAddons Forums

Oct 05, 2022, 6:58 PM

fcecodec (FCE decoder/encoder - Python module)

This is a discussion for the topic fcecodec (FCE decoder/encoder - Python module) on the board Editing Projects.

Author Topic: fcecodec (FCE decoder/encoder - Python module)  (Read 3092 times)

17 Replies on fcecodec (FCE decoder/encoder - Python module)
on: Oct 29, 2021, 8:30 AM
Sr. Member
Posts: 35 Joined: December 01, 2020

  • **
https://github.com/bfut/fcecodec

Makes available most FCE properties. Via mature, included OBJ 2 FCE conversion tools, opens easy path to using Blender as sole 3D editor for NFS3 and NFS4 projects.

Features:
    Io: full FCE implementation (FCE3, FCE4, FCE4M)
    Io: decodes/encodes transparently
    Io: optionally centers parts on FCE encoding
    Io: imports raw geometry data
    Io: exports to Wavefront OBJ
    Io: validates FCE binary data
    Scripts: converts Wavefront OBJ to finished FCE
    Get/Set: exposes raw geometry data (vertices, normals, triangles, texcoords)
    Get/Set: exposes attributes (triangle flags, texpages, vert animation flags, colors, dummies, etc.)
    Operation: inserts part from another mesh
    Operations: changes part order, copies part, merges parts, deletes part
    Operations: deletes triangles, vertices
    Stats: prints Mesh info
    Stats: prints FCE binary data info
    Python: numpy integration for most functions


Obj2Fce conversion tutorial: https://github.com/bfut/fcecodec/blob/main/scripts/doc_Obj2Fce.md

Reply #1
on: Oct 29, 2021, 10:53 AM
Hero Member
Posts: 305 Joined: May 24, 2008

  • *****
  • Personal Text
    Stupid blunt claws.
Nice to see a new tool for FCE files, although a have a couple of questions:

1- are you planning to make a Windows CLI version, like unvivtool?
2- is the tool able to extract data such as dummies and colors?

Reply #2
on: Oct 30, 2021, 11:57 AM
Sr. Member
Posts: 35 Joined: December 01, 2020

  • **
cheers

yes, everything gets exposed. Colors, dummies, triangle flags, vertex animation flags, etc.
MGetColors_numpy()
MSetColors_numpy()
MGetDummyNames()
MSetDummyNames()
MGetDummyPos_numpy()
MSetDummyPos_numpy()

these return / expect arrays.

Because Wavefront OBJ does not know dummies, IoExportObj() outputs diamonds in their place instead (which is kinda the same idea from the official MCO cars).

Example: the dummies of MCOs 47caddy.viv->part.fce
Code: [Select]
>>>mesh.MGetDummyNames()
['HWYN500', 'HWYN500', 'TRYN550', 'TRYN550', 'POYN350', 'POYN350', 'TRYN550', 'TRYN550', ':ENGINE', ':EXHAUST', ':EXHAUST', 'RWNN350', 'RWNN350']

>>> mesh.MGetDummyPos_numpy().reshape(-1,3)
[[-0.8350089  -0.07701124  2.4603028 ]
 [ 0.8369203  -0.07701124  2.4603028 ]
 [-0.89753664 -0.2275881  -2.348826  ]
 [ 0.9148167  -0.23661205 -2.3675246 ]
 [ 0.82447654 -0.2796423   2.4292781 ]
 [-0.8279473  -0.2796423   2.4486275 ]
 [ 0.90377176 -0.30901065 -2.4441476 ]
 [-0.89753664 -0.30966136 -2.4347985 ]
 [-0.00663905 -0.07701124  2.431279  ]
 [-0.4226048  -0.5902259  -2.5992672 ]
 [ 0.43890017 -0.5902259  -2.5992672 ]
 [-0.9075366  -0.17758808 -2.178826  ]
 [ 0.91246223 -0.17758808 -2.178826  ]]


Example: the colors of NFSHS ldia/car.viv->car.fce
Code: [Select]
# for N colors the array has shape=(N, 4, 4)
# fcelib_fcetypes.h documents the meaning of each row

>>> mesh.MGetColors_numpy()
[[[138  14 210 128]
  [ 31 111 111 127]
  [  3 254 116 127]
  [  1 220  70 127]]

 [[ 35 254 178 127]
  [ 31 151 112 127]
  [171 253  88 127]
  [171 253  62 127]]

 [[254 255 150 127]
  [127   2  73 127]
  [134  11 194 127]
  [134  11 137 127]]

 [[168 178 100 127]
  [127   1  49 127]
  [ 37 176 147 127]
  [ 37 176 103 127]]]



not sure why, but I do stuff like this now >:D
Code: [Select]
mesh.MVertsPos_numpy = mesh.MVertsPos_numpy * 10

Reply #3
on: Nov 17, 2021, 1:21 PM
Sr. Member
Posts: 35 Joined: December 01, 2020

  • **
There have been several updates since the above posts.

Of note, the repo now includes convenient converter scripts Obj2Fce and Fce2Obj. With these, it's just drop in and go:
https://github.com/bfut/fcecodec/tree/main/scripts

Dummies, part positions and triangle flags are all handled, among other features. For NFS:HS, damage models are handled.

For Obj2Fce, there is comprehensive documentation available: https://github.com/bfut/fcecodec/blob/main/scripts/doc_Obj2Fce.md

Finally, here is your shortcut from your favorite 3D editor (e.g. Blender, Houdini FX, etc.) straight to FCE.

Reply #4
on: Dec 13, 2021, 2:47 PM
Sr. Member
Posts: 35 Joined: December 01, 2020

  • **
News:
1) The tutorial has been updated quite a bit and has been posted to NFSAddons:
https://www.nfsaddons.com/downloads/nfshs/tools/6399/convert-obj-to-fce.html
The tutorial now covers FCE3, FCE4, and bits of FCE4M (= MCO).

2) FCE4M output is now also officially supported.

Reply #5
on: Jun 22, 2022, 7:12 AM
Sr. Member
Posts: 35 Joined: December 01, 2020

  • **
The repository is continuously being updated.

* improved FCE4M support
* improved ready-to-use Python scripts
* improved Obj2Fce conversion tutorial ( https://github.com/bfut/fcecodec/blob/main/scripts/doc_Obj2Fce.md )
* python function fcecodec.IoExportObj() optionally allows ignoring part positions (i.e., optionally center parts around the origin on export)

Reply #6
on: Aug 11, 2022, 7:43 AM
Sr. Member
Posts: 35 Joined: December 01, 2020

  • **
With the latest update to version 1.2, fcecodec has pretty much matured. The Python API will be stable from this point on.

OBJ to FCE and vice versa has been part of the package and is ready to use after installation. Would love to see someone share feedback and their own custom scripts.

Latest changes:
* Python: require NumPy; removes redundant non-NumPy functions (i.e., no more API clutter)
* Documentation: add background information for references used

Enjoy. https://github.com/bfut/fcecodec

Reply #7
on: Aug 27, 2022, 1:15 AM
Sr. Member
Posts: 35 Joined: December 01, 2020

  • **
News:
* improved stability: robust handling of manipulated / invalid FCE data

Reply #8
on: Aug 28, 2022, 2:47 AM
Sr. Member
Posts: 102 Joined: June 09, 2018

  • ***
News:
* improved stability: robust handling of manipulated / invalid FCE data
Just that you mentioned manipulated/invalid .fce data. There are quite many car.viv's that were hex edited back in the day. Can your unvivtool handle those kind of viv's? I couldn't try it out yet since the use of this program is very complicated to usual users.

Reply #9
on: Sep 02, 2022, 5:05 AM
Sr. Member
Posts: 35 Joined: December 01, 2020

  • **
News:
* improved stability: robust handling of manipulated / invalid FCE data
Just that you mentioned manipulated/invalid .fce data. There are quite many car.viv's that were hex edited back in the day. Can your unvivtool handle those kind of viv's? I couldn't try it out yet since the use of this program is very complicated to usual users.

1) Complicated in which sense? Are you on Windows? I'm constantly testing on Windows10, but Linux is recommended, because Python module installation is so much easier. Give WSL a try, if on a Windows machine.

2) Yes, that type of manipulation is one target. I specifically remember CPD manipulating his VIV archives (see unvivtool for that), and possibly even the FCEs. My go-to test file is CPD's Porsche 962. I'd be interested in any VIV or FCE that cannot be opened and/or fully parsed by either, unvivtool or fcecodec.

fcecodec is required to fully handle all valid FCE data. fcecodec (and unvivtool, for that matter) is designed in a way to recover as much information as possible until encountering faulty information within an invalid file. Nomenclatura: invalid = Need For Speed cannot handle it, valid = Need For Speed does handle the file. Those manipulated files of old were in fact valid in this sense, because they could be played in the games; but some tools of the day crashed. Contrary to that, crashes are not supposed to happen with my tools either way.

I have yet to encounter either FCE or VIV that cannot be opened by my tools, but would work in the games.

What information do you believe is missing from fcecodec documentation?
Do you have examples of manipulated files?

Reply #10
on: Sep 05, 2022, 1:53 AM
Sr. Member
Posts: 102 Joined: June 09, 2018

  • ***
News:
* improved stability: robust handling of manipulated / invalid FCE data
Just that you mentioned manipulated/invalid .fce data. There are quite many car.viv's that were hex edited back in the day. Can your unvivtool handle those kind of viv's? I couldn't try it out yet since the use of this program is very complicated to usual users.

1) Complicated in which sense? Are you on Windows? I'm constantly testing on Windows10, but Linux is recommended, because Python module installation is so much easier. Give WSL a try, if on a Windows machine.

2) Yes, that type of manipulation is one target. I specifically remember CPD manipulating his VIV archives (see unvivtool for that), and possibly even the FCEs. My go-to test file is CPD's Porsche 962. I'd be interested in any VIV or FCE that cannot be opened and/or fully parsed by either, unvivtool or fcecodec.

fcecodec is required to fully handle all valid FCE data. fcecodec (and unvivtool, for that matter) is designed in a way to recover as much information as possible until encountering faulty information within an invalid file. Nomenclatura: invalid = Need For Speed cannot handle it, valid = Need For Speed does handle the file. Those manipulated files of old were in fact valid in this sense, because they could be played in the games; but some tools of the day crashed. Contrary to that, crashes are not supposed to happen with my tools either way.

I have yet to encounter either FCE or VIV that cannot be opened by my tools, but would work in the games.

What information do you believe is missing from fcecodec documentation?
Do you have examples of manipulated files?
Well i think that those tools would be very simple in a way that where you drag'n'drop the car.viv onto the .exe file, it will get exported in the same folder. Maybe this kind of feature is too hard to code, but i know it's possible. For usual people like me it's a pain in the ass to open cmd.exe and type the whole stuff. And i know how to copy'n'paste paths in cmd.exe. But still it would be way more pleaserable to just drag & drop the car.viv onto the .exe. And yes there is one car.viv i have which i don't know any tool that can export the inner data out of it. And it's drivable in the game. Here's the link to it:
https://drive.google.com/file/d/1opmNuVo4sXjrs-pn8xdRh6bA0ifkSQhJ/view?usp=sharing

Reply #11
on: Sep 06, 2022, 5:43 AM
Sr. Member
Posts: 102 Joined: June 09, 2018

  • ***
I was just trying to use example 2:
EXAMPLE 2
   unvivtool d car.viv .

      decodes and extracts all files from archive 'car.viv' to current working
      directory

But this doesn't work at all. All it does is this:

Reply #12
on: Sep 06, 2022, 5:48 AM
Sr. Member
Posts: 102 Joined: June 09, 2018

  • ***
And this is the error message when i do it the more complicated way, which finally works, but the car.viv is just too screwed.

Reply #13
on: Sep 10, 2022, 5:14 AM
Sr. Member
Posts: 35 Joined: December 01, 2020

  • **
I've responded in the unvivtool thread: https://www.nfsaddons.com/forums//index.php?topic=2294.15
Please post your questions about unvivtool in the dedicated thread instead.

Spoilers: car.fce is manipulated but fcecodec can handle it. :)

Reply #14
on: Sep 27, 2022, 9:17 AM
Sr. Member
Posts: 35 Joined: December 01, 2020

  • **
The latest update on Github fixes a potential crash in the DeletePart() function.

New Python are now included: 1) Convert dummies between NFS3, NFS4 and MCO. 2) Rename and merge parts for easy conversion between NFS3, NFS4 and MCO. The latter will make it possible to easily choose between convertible, chopped roof, normal roof as well as open and closed hood.

 


Support NFSAddons: