MaxScript PKG importer/exporter

User avatar
SuperSecret
MM2X Junior User
MM2X Junior User
Posts: 127
Registered for: 15 years 4 months
Location: Italy

MaxScript PKG importer/exporter

Postby SuperSecret » Tue Apr 30, 2013 10:47 pm

Some time ago Carluver69 worked on a MaxScript PKG importer. I decided to finish it, since ZModeler's importer is buggy. For the same reason, I made also an exporter.

The scripts support every feature of the .pkg format, including xrefs and .ter files. (if I didn't forget anything)

To install the scripts, put them in 3dsMax's "scripts" folder. To use them, go in the "MaxScript" menu, select "Run script" and then select the script you need.

I tested successfully the scripts on 3dsMax 2013 64bit, but they should work also with other versions.

Tips for exporting:
  • Put the :m suffix at the end of the name of a part to generate the .mtx file for it.

    Dashboards use 9 different "paintjobs" for the different gears. (only the gear indicator changes texture in MM2) To set different textures for gears on the gear indicator, set 8 different paintjobs (the 9th is the base texture), using as suffix the gear indicator's texture name. (for dashboards, it won't be treated as a suffix, only that texture will be changed in the paintjobs)

    To export the bound as .bnd, name it "BOUND", to export it as .bbnd (and, optionally, to generate the .ter file), name the bound "BINARY_BOUND". The generation of .ter files is quite slow (can take up to 3 minutes with most complex bounds), since it contains a division in sections of the bound, which must be calculated. The properties of a material in a bound are defined in the material's name (for example: default/0.1/0.5/none/none)

    To assign a "reflective" color to a material, set its filter color to anything different from [128,128,128] (it will be the reflective color). To change the alpha value of a color, adjust its map amount value.

    To export xrefs: create a helper (for example a dummy), name it as the referenced object, and position it where you want. Only rotation about Max's Z axis will be exported, since MM2 rotates xrefs only about that axis.
Download links:
Importer (updated on 2013-08-02): https://app.box.com/s/5c63mos01d3movne5mhv
Exporter (updated on 2013 08-02): https://app.box.com/s/3cb2vj6k0fzmjyaabq72
Last edited by SuperSecret on Sat Aug 03, 2013 1:28 am, edited 3 times in total.

User avatar
Diatosta
MM2X Active User
MM2X Active User
Posts: 783
Registered for: 11 years 9 months
Location: Portugal? Maybe...
Contact:

Postby Diatosta » Wed May 01, 2013 4:24 pm

How to install it? Because I don't find anywhere any docs where to install it.
[color=white]MM2 lover! Yeah![/color]
[color=white]diatosta.pt[/color]

[color=white]Also, gotta love when people don't publicize their work or ask for support in their signatures. Also don't forget to check my unfinished mods and donate to my Paypal

Also, one of my trucks[/color]
[img][/img]

User avatar
SuperSecret
MM2X Junior User
MM2X Junior User
Posts: 127
Registered for: 15 years 4 months
Location: Italy

Postby SuperSecret » Wed May 01, 2013 5:00 pm

Just put the script in 3dsMax's "scripts" folder. To use it, go in the "MaxScript" menu, select "Run script" and then select the script.

User avatar
CarLuver69
MM2X Active User
MM2X Active User
Posts: 934
Registered for: 17 years 1 month
Location: California, USA
Contact:

Postby CarLuver69 » Wed May 01, 2013 9:37 pm

Very nice work. Looks like you're going to need a GUI though, the way I had written the old one was by no means the proper way to release a tool :P

There's MTX glitches -

* Wheels are not positioned properly
* ":m" suffix is appended over 9 times!

Other than the bugs, great work!

EDIT: Yep, there's definitely a lot of bugs that need to be sorted out...lol
[img]https://img59.imageshack.us/img59/2562/2010mm2cawardssilver.png[/img] [color=orange]Best MM2 Innovation - Author of best car of the year[/color]
[color=silver][i]Proud supporter of MM2X[/i][/color]

[color=#CCCCCC]How do I love thee MM2? Let me count the add-ons...
[size=134][b]Are my pictures not showing up? [url=https://photobucket.com/CL69MM2]CLICK HERE![/url][/b][/size][/color]

User avatar
SuperSecret
MM2X Junior User
MM2X Junior User
Posts: 127
Registered for: 15 years 4 months
Location: Italy

Postby SuperSecret » Wed May 01, 2013 10:00 pm

The :m suffix is intended, for re-exporting. About the wheels, they were imported correctly when I tested it with the NYC Ford Mustang Cruiser. Which car did you test? Also, what are the other bugs?

Apart from that, today I tried to write also an exporter. For the moment, it only exports geometry, no shaders or anything else.

User avatar
CarLuver69
MM2X Active User
MM2X Active User
Posts: 934
Registered for: 17 years 1 month
Location: California, USA
Contact:

Postby CarLuver69 » Mon May 06, 2013 8:41 pm

Why would you test with an add-on car? That's a silly idea. Default cars do not load properly, and parts with ":m" have it assigned over 9 times, like this:

"WHL1_H:m:m:m:m:m:m:m:m:m:m:m:m"

And the wheels themselves load really far apart from the model. There's a glitch in the matrix. :P
[img]https://img59.imageshack.us/img59/2562/2010mm2cawardssilver.png[/img] [color=orange]Best MM2 Innovation - Author of best car of the year[/color]
[color=silver][i]Proud supporter of MM2X[/i][/color]

[color=#CCCCCC]How do I love thee MM2? Let me count the add-ons...
[size=134][b]Are my pictures not showing up? [url=https://photobucket.com/CL69MM2]CLICK HERE![/url][/b][/size][/color]

User avatar
SuperSecret
MM2X Junior User
MM2X Junior User
Posts: 127
Registered for: 15 years 4 months
Location: Italy

Postby SuperSecret » Mon May 06, 2013 8:53 pm

Ouch, I had tested also the Audi TT and some other default cars, but I re-tested it now, and effectively there are the bugs. (some changes before the release must have broke it) I'll try to fix them now.

EDIT: OK, I found the problem: it worked correctly when I tried it for the first time because I had put in the folder only the files of the car I wanted to import. When the files are in a folder where there are also files of other cars, the importer will load also the mtx files of the other cars (because it sorts every mtx file), and will import the car incorrectly.

EDIT 2 (and 3, I always forget something): Bug fixed, new version: https://www.box.com/s/5c63mos01d3movne5mhv

User avatar
SuperSecret
MM2X Junior User
MM2X Junior User
Posts: 127
Registered for: 15 years 4 months
Location: Italy

Postby SuperSecret » Sat Aug 03, 2013 1:28 am

I updated the importer (I fixed some issues with materials, mtx and normals). I made also an exporter, which supports every feature of the .pkg format (if I didn't forget anything), including .ter files.

Here's the structure of the .ter format in case you want to see it (there was no documentation before). Basically it works like the CPVS format, it divides the bound in sections, and tells the game which polygons must be loaded in each section. (to speed up the collision detection)

Code: Select all

struct TER { float version; // == 1.1 ulong nPolygons; // Number of polygons of the associated bnd/bbnd. ulong nUniqueEdges; // Number of unique edges in the associated bnd/bbnd* char unknownChar; // Always 0 float boxWidth; // Width of the bounding box. float boxHeight; // Height of the bounding box. float boxDepth; // Depth of the bounding box. ulong WidthSecs; // Width sections. Always ceil(boxWidth/10) (always > 0) ulong HeightSecs; // Height sections. Always 1 ulong DepthSecs; // Depth sections. Always ceil(boxDepth/10) (always > 0) ulong nSecs; // Number of sections (WidthSecs*DepthSecs). ulong nPolyIndices; // Number of groups of polygons of the bnd/bbnd mesh (assigned to the various sections). Vector SectSizeReciprocal; // Reciprocal values of section size. Always [WidthSecs/boxWidth, 1, DepthSecs/boxDepth] Vector boxMin; // Minimum boundary of the associated bnd/bbnd mesh. Vector boxMax; // Maximum boundary of the associated bnd/bbnd mesh. ushort PolyGroupsIndices[nSecs]; // Indices of first polygon index in each section. ushort SecsPolyCount[nSecs]; // Numbers of polygons in each section. ushort PolyIndices[nPolyGroups]; // Indices of polygons, divided in the sections according to the above data. ushort EdgeVertices[nUniqueEdges*2]; // Describes edges (2 vert. each)** long PolygonEdges[nPolygons*4]; // Lists the edges of the polygons** float IndexedFloats[nUniqueEdges*4]; // Values between -1 and 1, occasionally 2** }; *Can be changed to 0 without affecting anything. Allocates memory (i.e. decreases stability if high). **Absolutely no effect, even if it's a blob of random data, can be absent.

User avatar
CarLuver69
MM2X Active User
MM2X Active User
Posts: 934
Registered for: 17 years 1 month
Location: California, USA
Contact:

Postby CarLuver69 » Mon Oct 21, 2013 12:02 pm

I updated the importer (I fixed some issues with materials, mtx and normals). I made also an exporter, which supports every feature of the .pkg format (if I didn't forget anything), including .ter files.

Here's the structure of the .ter format in case you want to see it (there was no documentation before). Basically it works like the CPVS format, it divides the bound in sections, and tells the game which polygons must be loaded in each section. (to speed up the collision detection)

Code: Select all

struct TER { float version; // == 1.1 ulong nPolygons; // Number of polygons of the associated bnd/bbnd. ulong nUniqueEdges; // Number of unique edges in the associated bnd/bbnd* char unknownChar; // Always 0 float boxWidth; // Width of the bounding box. float boxHeight; // Height of the bounding box. float boxDepth; // Depth of the bounding box. ulong WidthSecs; // Width sections. Always ceil(boxWidth/10) (always > 0) ulong HeightSecs; // Height sections. Always 1 ulong DepthSecs; // Depth sections. Always ceil(boxDepth/10) (always > 0) ulong nSecs; // Number of sections (WidthSecs*DepthSecs). ulong nPolyIndices; // Number of groups of polygons of the bnd/bbnd mesh (assigned to the various sections). Vector SectSizeReciprocal; // Reciprocal values of section size. Always [WidthSecs/boxWidth, 1, DepthSecs/boxDepth] Vector boxMin; // Minimum boundary of the associated bnd/bbnd mesh. Vector boxMax; // Maximum boundary of the associated bnd/bbnd mesh. ushort PolyGroupsIndices[nSecs]; // Indices of first polygon index in each section. ushort SecsPolyCount[nSecs]; // Numbers of polygons in each section. ushort PolyIndices[nPolyGroups]; // Indices of polygons, divided in the sections according to the above data. ushort EdgeVertices[nUniqueEdges*2]; // Describes edges (2 vert. each)** long PolygonEdges[nPolygons*4]; // Lists the edges of the polygons** float IndexedFloats[nUniqueEdges*4]; // Values between -1 and 1, occasionally 2** }; *Can be changed to 0 without affecting anything. Allocates memory (i.e. decreases stability if high). **Absolutely no effect, even if it's a blob of random data, can be absent.
Wow, I wish I had seen this earlier. Very nice!
[img]https://img59.imageshack.us/img59/2562/2010mm2cawardssilver.png[/img] [color=orange]Best MM2 Innovation - Author of best car of the year[/color]
[color=silver][i]Proud supporter of MM2X[/i][/color]

[color=#CCCCCC]How do I love thee MM2? Let me count the add-ons...
[size=134][b]Are my pictures not showing up? [url=https://photobucket.com/CL69MM2]CLICK HERE![/url][/b][/size][/color]