NFSAddons Forums

Main Menu

fcecodec (FCE decoder/encoder - Python module)

Started by bfut, Oct 29, 2021, 8:30 AM


AJ_Lethal

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?

bfut

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

>>>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

# 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
mesh.MVertsPos_numpy = mesh.MVertsPos_numpy * 10


bfut

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.

bfut

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.

bfut

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)

bfut

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


pete9516

Quote from: bfut on Aug 27, 2022,  1:15 AM
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.

bfut

Quote from: pete9516 on Aug 28, 2022,  2:47 AM
Quote from: bfut on Aug 27, 2022,  1:15 AM
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?

pete9516

Quote from: bfut on Sep 02, 2022,  5:05 AM
Quote from: pete9516 on Aug 28, 2022,  2:47 AM
Quote from: bfut on Aug 27, 2022,  1:15 AM
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

pete9516

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:

pete9516

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.

bfut

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. :)

bfut

#14
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.