Jump to content

Tutorial - Importing and Exporting GR2 Models


Recommended Posts

Importing and Exporting GR2 Models

 

This tutorial is written for users of 3DSmax6/7/8, but once you've got your model in 3DSmax it applies to all versions.

Because this tutorial describes using grnreader, it is recommended to read the GR2 Decode Documentation before continuing.

 

There's a separate part for weapons in the next post. If you want to edit or create a new weapon mesh, then go to that post.

It contains for instance a description of special settings for exporting a weapon as a GR2 file.

 

 

Tools to use

- grnreader98 v1.4.0.3 debug (download it here (link));

- a version of 3DSmax which can properly import SMD files, preferrably 3DSmax6/7/8;

- a granny2 export plugin for 3DSmax (I'm not gonna advertise any link about this plugin in this post);

- an SMD import plugin or script for 3DSmax - I strongly advise using Cannonfodder's SMD plugins (link) for 3DSmax 6/7/8;

- GrannyViewer by RAD Game Tools (link)

At the end of this page (link), there's a Tools section with links to exporters.

 

 

Step 1 - Extracting Stuff from a GR2 Model File

Extract a GR2 file from eg. graphics05.zip and put it in a separate directory.

This separate directory is probably going to hold quite a few files, so name it after the model.

Copy grnreader98.exe and your version of granny2.dll into this directory (for instance version 2.7.0.28 of Sacred 2 (US v2.43)).

Open a command prompt, navigate to your new directory and type:

> grnreader98 <your_model.GR2> -a -t

 

Note 1: <your_model.GR2> is the name of the GR2 model file you extracted.

Note 2: this command line is the current working command line for grnreader98 v1.3.0.4. It may change in the near future.

 

The output of grnreader98 is an SMD file, which is a text-only file, so it can be opened in any text editor.

Sometimes you want to open such an SMD file to edit something, so it is useful to learn it's format.

 

Two main types of SMD files exist:

- the socalled SMD reference file;

- the socalled SMD sequence file.

Only the SMD reference file is important for our purposes.

An SMD sequence file holds animation data. This type of SMD file is not used in this tutorial.

An SMD reference file contains a mesh, a skeleton (with one or more bones), a 'skin', and texture information.

 

The 'skin' is not a skin of flesh & blood, it merely represents the coupling (or 'binding') between the bones and the vertices of the mesh.

A model's skin is also referred to as 'the vertex weights'.

 

 

Step 2 - Importing the SMD into 3DSmax

Using Cannonfodder's SMD import plugin for 3DSmax is largely described in my Archangel Manual (link), which also includes images.

 

 

Step 3 - Checking your Model's Type

Sofar we've seen two types of models with Sacred 2:

a.) static models like weapons;

b.) dynamic (or animated) models.

 

To check whether your model belongs to the 'static type', open your SMD file in a text editor.

Here's an example of what you might see in the 'triangles' section:

n_brassknuckle06_0
0 0.057934 -0.630990 0.000168 1.000000 0.000000 -0.000000 0.461213 -0.441767 1 0 1.000000 
0 0.057934 2.362213 0.000169 1.000000 0.000000 -0.000000 0.237679 -0.441413 1 0 1.000000 
0 0.057933 0.277408 -0.518283 1.000000 0.000000 -0.000000 0.393373 -0.624539 1 0 1.000000

 

If all your triangles have the last three parameters equal to "1 0 1.000000", then you can be sure you are looking at a static-type model.

 

If you are editing or creating such a static model, then go to the next post in this thread (**).

 

<Edit (April 10, 2011): Taken out the part where it says to delete the 'Skin' modifier..>

 

 

Step 4 - Editing the Sub-Material(s)

Open your GR2 file in GrannyViewer and click the 'Material List' tab.

Usually you will see only one material.

Note down the name of the material(s).

 

At this point you might want to check whether the material name(s) exists in the file surface.txt.

This file is located in the directory: <your Sacred 2 directory>\scripts\client

 

The name(s) of the material(s) will be applied to the sub-materials of your multi-material in 3DSmax.

To do so, open the Material Editor in 3DSmax and pick the multi-material from the imported SMD mesh as described in the Archangel Manual.

 

Sofar it seems that the order of appearance of the sub-materials is equal to their list sequence in GrannyViewer,

so you can easily apply the material list you noted down:

- click on the button of each sub-material;

- change the sub-material's name;

- remove it's texture.

To remove a (diffuse) texture, right-click the button of the texture and select the pop-up menu option <Clear>.

When you clear a texture, you will see that the color of your model changes to a darker grey.

 

This is all you have to do before exporting the model as GR2.

 

 

Step 5 - Changing the Model

There's several ways to alter an imported model, or to create a completely new one.

The latter is beyond the scope of this tutorial.

One thing is important when changing an imported model, and that is trying to prevent Skin corruption.

 

If you have a new mesh part for your model, make sure it's type is a socalled "Editable Mesh", without a 'Skin' modifier.

This new mesh part must also be connected to the model's skeleton, therefor:

- select the main part of your model's mesh and go to the Modifier tab in the sidepanel;

- right-click the 'Skin' modifier and select <Copy> from the pop-up menu;

- select your new mesh part, right-click in the list of modifiers and select <Paste Instanced> from the pop-up menu.

 

Last thing to do would be to attach the new mesh part to the main mesh, but I'm not sure whether this is really necessary.

In any case I don't recommended to edit the Skin's Environment.

 

Comment by Dimitrius154:

"I strongly recommend uniting all meshes of the modified model into one editable mesh (you won't loose material bindings) before applying the Skin modifier.

I found Skin corruption when more than one mesh was present within a model.

No Skin corruption appeared for the same model, when all meshes were united into one.

Unification of meshes is done by <Compound Objects -> Boolean -> Union>, and then converting the resulting structure into an Editable Mesh.

I should note that the new unified mesh may need to be repositioned a bit, 'cause its root coordinates may differ from the root coordinates of the original primary mesh.

Not sure about how Skin instance would behave for totally new meshes, but the general rule is: the larger the surface - the worse the distortion."

 

New meshes may look partially torn after copying and pasting the Skin (as 'Instance'), because this manual operation doesn't always apply vertex weights properly.

This can however be fixed easily by editing the Skin 'Envelope' for particular bones. Note that you must be very careful when going into this mode, otherwise you might cause more damage to your model.

For appendages (rigid armor, head included) all vertex weights for the main bone should be equal, and preferably equal to one (1.000).

(This should be tailored as you see fit).

If distortion spikes show up in-game, then one or more vertices have an improperly high weight for the secondary bone (in most cases this weight should be set to 0).

 

Pesmontis (edit - Jan. 9, 2012):

In case a model still shows distorted in-game, or in case the game crashes with your new GR2 file, I recommend the following:

- in 3DSmax, export the model as an SMD reference file (select <Export> and use Cannonfodder's plugin);

- using a text editor, delete the node(s) which actually represent a mesh - this node / these nodes are usually the last one(s) in the node list. Also delete them from the "time 0" skeleton list;

- the SMD exporter will probably have put "null.bmp" for the material name, so replace "null.bmp" with the name of the material (without the extension). In case the model uses more than one material, then apply bitmaps with distinguished names before exporting as SMD;

- reset 3DSmax and re-import the edited SMD file;

- check your materials and re-export as GR2.

 

<Step 5 is 'To Be Expanded' **>

 

 

Step 6 - Exporting the Model

The export settings described below do NOT apply to weapons or other 'static' models.

Go to the next post in this thread if you want to export a weapon as a GR2 file (**).

Select only your mesh(es) and click the menu option <File><Export Selected>.

In the "Select File to Export" window, select "Granny Run-time (*.GR2)" from the "Save as type" drop down list.

Type an appropriate name for your model in the "File name" textbox.

Click the button <Save>.

 

The "Granny Exporter Settings" window will appear with lots of export options.

The recommended exporter settings are:

 

= Uncheck the first three checkboxes with the 'Animations' settings;

 

= Uncheck the first two checkboxes with the 'File' settings;

 

= Uncheck the second AND the third checkbox with the 'Materials' settings,

so you only need a tick in the checkbox "Include reference in export";

 

= Select the following options with the 'Meshes' settings:

- enable the first three checkboxes;

- tick the checkbox with the setting 'Truncate vertex indices to 16bit';

- set the slider called 'Coords per vetex' to two (2). It's default is one (1);

- tick the checkbox 'Include tangent vectors';

- tick the checkbox 'Include binormal vectors';

- tick the checkbox 'Include per-bone triangle arrays';

- tick the checkbox 'Include topology information'.

 

= In the 'Models' settings,

- uncheck the third checkbox ('Include art tool specific data'), and

- uncheck the fourth checkbox ('Move to Origin');

 

= In the 'Textures' settings uncheck the first three checkboxes.

At the moment it's not recommended to include (a) texture(s) in your export.

 

 

Step 7 - Testing

Open your new GR2 file in GrannyViewer and check whether all materials are present and named correctly.

Create the appropriate directories in the 'pak' folder of your Sacred 2 installation and copy your new GR2 file there.

 

In case you want to use a file name for your new GR2 file, which differs from the original GR2 file name,

then you have to change the file name in the file 'itemtype.txt' in the directory: <your Sacred 2 directory>\scripts\shared

 

Start Sacred 2 and check the looks of your model in-game.

If you see a glowing white blob wielding a weapon (a 'GWBWW' ;-) then somit went wrong and you have to go back to 3DSmax to check your sub-material names.

 

Good luck & happy modding :-)

Edited by Pesmontis
  • Like! 1
Link to comment

Creating New or Altered Weapons

 

About maxscript files exported with grnreader98:

Be aware that the .ms files only contain a mesh.

They don't contain a skeleton (no bones) and no material reference (no texture).

 

If you run this script with 3DSmax, and export the model as GR2, your weapon won't be able to socket gems, and it won't display effects.

It's better to go with the SMD file.

 

In order to have a weapon with effect(s), follow iandave68's new method, described below.

 

Here, the n_brassknuckle-06.GR2 model is used as an example.

 

0.) Run grnreader98 against the GR2 file with the switches "-a" and "-t":

 

WeaponChange01grnreader98run.jpg

 

1.) Import the resulting SMD file into 3DSmax7 with Cannonfodder's SMD import plugin.

Importing an SMD file into 3DSmax7 is described here (link);

 

1a.) To change (only) the mesh outside of 3DSmax, select the mesh called "smdimport" and click the menu option <File><Export Selected>.

Save it for example as an OBJ file:

 

WeaponChange02exportOBJ.jpg

 

Now you can import the OBJ file into your preferred 3D modeling app to edit only the mesh.

For this purpose I recommend using Rhino3D.

Note that you can use 3DSmax for mesh editing, but here iandave's new method is followed, which in fact demonstrates how to create an entirely new mesh.

 

Make sure that your OBJ file contains UV coordinates after you're done editing the mesh (**).

This implies texturing the new mesh with a (new) texture.

 

1b.) Pick the material from the mesh as described here (link).

Clear the material's texture reference, and name the sub-material according to the name of the material in GrannyViewer.

 

 

2.) After editing the exported OBJ file outside of 3DSmax, re-import this new mesh into the scene.

Note: at this point you might want to check the new mesh's UV coordinates, for instance by creating a new material with your (new) texture and applying it directly to the new mesh;

 

2a.) Assign the picked material to the new mesh;

 

2b.) Click the original editable mesh and attach the new mesh to it.

To do so, select the modifier "Editable Mesh" in the sidepanel (ignore the warning), open it by clicking the small '+' to the left of it, and then click on 'Element'.

In the "Edit Geometry" roll-out, click the button <Attach>:

 

WeaponChange03attachNewMesh.jpg

 

Now click the new mesh once. This will attach the new mesh to the old mesh.

Again click the button <Attach> to leave the attaching modus, and

click on 'Element' again to leave the modus of altering the editable mesh;

 

To check that the attaching operation was successful, type the <H> key on your keyboard: you shouldn't see any other name but the names of the bones and the name of the original mesh.

 

3.) Next step is to remove the old mesh completely.

You can do so by opening the editable mesh modifier again.

Select 'Element'.

In one of the viewports, select each element belonging to the original mesh, and hit the <Delete> key on your keyboard.

Note 1: Your original mesh will probably have multiple elements, which may coincide with elements from your new mesh,

so that removing elements should be a painstaking process (**).

Note 2: You don't have to detach elements before deleting them.

 

Click on 'Element' again to leave the modus of altering the editable mesh.

Now only the new mesh remains.

 

3a.) Delete the 'Skin' modifier;

 

3b.) Now there are no more modifiers depending on changes in the editable mesh modifier, therefor

you can safely apply smooth groups to the mesh in case the mesh looks crude in the perspective viewport.

 

Select the mesh and right-click it.

Select the pop-up menu option <Convert to:><Convert to Editable Poly>.

Open the 'Editable Poly' modifier and select 'Element'.

Now select each element and assign a 'Smoothing Group' ID to it.

To do so, scroll down to the "Polygon Properties" roll-out and click on one of the numbered buttons.

You will see a significant change to the element in the perspective viewport.

 

Convert the 'Editable Poly' back to 'Editable Mesh'.

 

3b.) Link the new mesh to the root bone.

The root bone usually has (almost) the same name as the mesh.

Check the result of the 'Link' operation by typing the <H> key on your keyboard and then ticking the checkbox "Display Subtree":

 

WeaponChange04checkNewLink.jpg

 

4.) Export the mesh as a GR2 file.

Make sure nothing is selected and click the menu option <File><Export>.

Select "Granny run-time (*.GR2)" from the file type drop-down list, type a name for the GR2 file, and click the button <Save>.

The Granny2 Export Settings window will appear.

 

In the list, doubleclick on 'Models'.

A list will be displayed, which should contain only one model.

Doubleclick this model in order to display a list of bones.

Because the mesh is linked to the root bone, it is listed here as well, but it should not be exported as a bone (**).

Simply click it's name and untick the first three checkboxes.

 

Click twice on the button <Back> in the upper left corner.

 

In the list, click on 'Meshes' and untick the first three checkboxes.

Now doubleclick on 'Meshes'.

A list will be displayed, which also contains mesh objects for the bones, but these should not be exported as mesh (**).

Select the name of your new mesh and tick the first three checkboxes.

 

In addition use these settings:

- enable the option 'Preserve bones affecting no verts' (**);

- tick the checkbox with the setting 'Truncate vertex indices to 16bit';

- untick the option 'Allow vertex weighting' (**);

- set the slider called 'Coords per vetex' to two (2);

- tick the checkbox 'Include tangent vectors';

- tick the checkbox 'Include binormal vectors';

- tick the checkbox 'Include topology information'.

 

Click on the button <Back> in the upper left corner.

 

The other export settings are:

= untick the first three checkboxes in the 'Animations' settings;

= untick the first two checkboxes in the 'File' settings;

= untick the second and the third checkbox in the 'Materials' settings;

= untick the third checkbox ('Include art tool specific data') in the 'Models' settings;

= untick the fourth checkbox ('Move to Origin') in the 'Models' settings;

= untick the first three checkboxes in the 'Textures' settings, in order to exclude textures (**);

 

Click the button <Export>.

 

5.) Save the scene as a new max file.

 

6.) Check the exported GR2 file in GrannyViewer.

Click the "Model List" tab and make sure that all the bones are there (and not the mesh):

- right-click AND HOLD the model in the list (there should be only one model in this list);

- drag the mouse to the pop-up menu option <View in Detail> and release the right mouse button;

- you'll see a list of parameters for this model. Click on the line "(click to view sub-structure)" to the right of the table entry "Struct * Skeleton";

- you'll see the number of bones in the Skeleton, which you can inspect in detail by further clicks on '(click to view sub-structure)' lines;

 

7.) Test the new GR2 file in Sacred 2.

Again, if you see a 'GWBWW', then you must go back to 3DSmax to check the name of your sub-material.

 

Many thanks to iandave68 for outlining the preliminary steps for this procedure!

Edited by Pesmontis
Link to comment
  • 6 months later...

This is a full tutorial?:thumbsup:

 

Of course not, but it contains a lot of things we found to be correct.

Anyone who creates many new models or who does many alterations will adjust steps to his liking, or add stuff that wasn't known at the time of writing.

Link to comment

I'm sorry Pesmontis, this should have been done before. Considering the quality and time put into this writeup, it's definitely something we want to headline the sacred 2 modding section.

 

Stickied

 

:)

 

gogo

Link to comment

> ".. I'm sorry Pesmontis, this should have been done before.."

 

Nothing to be sorry about, thanks for pinning it :-)

 

Ehm.. could I just edit a slight bit in the first post?

(the part where it says to delete the Skin modifier actually belongs to the second post).

Edited by Pesmontis
Link to comment

 

 

Ehm.. could I just edit a slight bit in the first post?

(the part where it says to delete the Skin modifier actually belongs to the second post).

 

Pesmontis, hi, can you please try the edit now? I've adjusted setting.

 

:)

 

gogo

Link to comment
  • 3 months later...

This article gave me a lot of help, but I had a difficult problem.

I with your method to export the model. But in the Granny Viewer,Not on the model shows map.I checked the first three checkbox in'Texture'settings.And in the Granny Viewer "Texture List" and "Material List" has map information.

This is a very serious problem,My model no map! .....

How do I make map display on the model?

Please help me!

Link to comment
  • 1 year later...

Not sure if Pesmontis is still around but I had a question on this exporter. I had a different type of gr2 (ends in 31 this was for 26) but it appears to have created the SMD. But I tried to import the SMD using the plug-in for blender (I don'thave 3DSmx) but it wouldn't import. Any chance someone can see why the SMD import into blender wouldn't work?

Edited by ekmek
Link to comment
  • 2 weeks later...
  • 8 months later...

Okay, why not. This will take some time though.

I think the focus should be on configuring the model's material(s) in Blender.

 

And then exporting as FBX, so that it can be imported in Nexus Buddy 2.0, or in 3DSmax / Maya.

 

btw. I think it's also possible to use Maya 6 with the "Blitzkrieg 2 export tools" in order to export GR2 files.

Link to comment

Pfew.. that was quite a hassle in Blender..

Since I've not used Blender very often, I had to learn how to use the GUI.

I don't think it's very intuitive, and I think it's easy to get frustrated.

I think it's like being confronted with Win8.0 for the first time ;-)

(where is all my stuff :)!!).

 

I've used Blender v2.69 and the SMD Tools v1.9.0 add-on.

 

In the SMD file exported with grnreader98 you must add something, otherwise only the bones will be imported.

You can edit such an SMD file with any text editor.

 

The first section of an SMD file contains the node names.

grnreader98 only writes the names of the bones in this section.

The Blender SMD importer also needs a node name for the actual mesh.

 

So if the SMD nodes section contains 10 bone names, numbered from 0 to 9,

then you should add:

 

10 "mesh name" -1

 

You must also add this node in the 'skeleton' section:

 

10 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000

 

That's all for proper SMD import.

--------------------------------------------

 

Now, to check the 'skin':

- In the upper right-hand corner, Blender displays an hierarchy tree;

- Click on the small '+' signs in front of a node to see the node's children;

- Look through this hierarchy tree until you find the node called "vertex groups", and display it's children;

- You'll see a list of all the bones;

- Now, in the lower left corner, the "3D View" menu is displayed. It has a pull-down menu saying "Object Mode";

- Click on this pull-down menu and select "Weight Paint";

- At this point don't left-click in the 3D view, because you're only checking, not editing (!);

- Now click on each bone node in the hierarchy tree under "vertex groups";

- In the 3D view, you'll see the vertex weights for that bone. Red = vertex weight 1.0, Blue = vertex weight 0.0;

- Use the middle mouse button to rotate the scene, to inspect the entire mesh.

 

Tomorrow I'll write-up something about the materials and exporting the model.

Link to comment

See post #17 for the first part of this Blender explanation.

 

In order to check your model's texture and UV mapping in Blender, do the following:

- Select your model's mesh in the hierarchy tree (the node with the golden triangle);
- In the 3D View menu (lower left) click the pull-down menu 'Object Mode' and select 'Edit Mode';
- You'll see the mesh triangles outlined in black;
- Now simply type 'a' to select all faces;
- Click the top menu 'Info' icon and select 'UV Image Editor';
- This is actually a window which you have to drag down:

if you move the mouse to the lower edge of the menu,

you'll see the mouse cursor change to an up/down arrow.

Now left click, hold & drag;


- You should now see the graphical representation of the UV coordinates of the mesh;
- In the UV Image Editor menu, select <Image><Open Image>;
- Browse to the texture file for this mesh, select it and click the <Open Image> button in the top right corner;
- On the keyboard, hold the <Alt> key and press <z>: the texture will be shown in the 3D View;
- Switch back to 'Object Mode', and type 'a' to deselect all;


- To check whether the texture is propperly mapped, hold the middle mouse button to rotate the scene.

Hold <Shift> and hold the middle mouse button to pan the scene.

For those who are familiar with other 3D modeling programs it should be noted that for checking the model's texture mapping, it is NOT necessary to add a texture to the mesh's material.

For the purpose of exporting the model to a GR2 capable tool, it's even unwanted to add a texture to any material in Blender (**).

The only thing that is important with regard to the material is its name:
the material name should correspond to one of the known Sacred 2 materials, listed in surface.txt.

 

To find the mesh's material, expand the nodes in the hierarchy tree, until you see a node with a small, shield-like icon.

Edited by Pesmontis
Link to comment

Whew, ok. I'm having a tough time with this. I'm experimenting with "c_ancientshield.GR2". I followed your instruction to edit the smd. I used notepad++ to do this. After adding the extra node and skeleton I loaded it in blender but I'm still not succeeding. What appears to be happening is "I think" only the bones are being loaded. What I see on my screen in blender are 3 long bars. As I click each one I can see in the "Outliner" window at the top right of the screen that the bones become active in that list. So I am loading bones but I can't see a mesh...

When I look at the smd in notepad++, I notice that it seems as though it already has the node and skeleton that you ask to add. Here is what the shield smd looks like before I do any edits:

 

Using "c_ancientshield.gr2.smd" from "graphics05.zip\models\heroes\seraphim\sets\ancient\c_ancientshield.GR2"

Version 1
nodes
0 "shield02" -1 
1 "shield_l_arm" 0 
2 "Camera01" 0 
end 
skeleton 
time 0
0 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 
1 -5.141632 -0.322998 -2.622437 1.280443 0.032219 -0.017174 
2 -0.300865 -13.932366 35.157043 0.000000 -0.349066 1.570796 
end

 

Does this need the additional lines that post #17 asks for?

 

P.s.

I also tested with "a_helve.GR2" and found the same results. Lots of bones but no mesh. I'll keep trying. Maybe I read something wrong.

Link to comment

Yes, it needs the extra node.

So for the c_ancientshield I would add in a new line after "2 "Camera01" 0":

 

3 c_ancientshield -1

 

And in the skeleton section, in a new line after "2 -0.300865 -13.932366..":

 

3 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000

 

 

One thing I'm not entirely sure about is the number of spaces that should (?) be used, in any line in an SMD file.

This seems to depend on the importer: I think sometimes an importer has trouble with a space after "skeleton",

or it needs to have two spaces after a node name. Something like that.

 

If you experience trouble importing an SMD file, then it would be best to export another skinned model as SMD from Blender, and then checking each (invisible) character that might be used as a format property..

For the write-up in post 17, I used an SMD file exported with 3DSmax7 and Cannonfodder's SMD export plugin.

Edited by Pesmontis
Link to comment

Perfect. Got it. Thanx for the tip Pesmontis! I removed all the white space from the ends of every line in the smd and then the model loaded fine. :)

 

P.s.

More testing with spaces... If I only remove space from the end of skeleton, the mesh still does not load. When I removed space from the end of skeleton and triangles it loaded fine.

Link to comment

Excellent testing :-)

Stupid thing w. spaces.. it's one of the things that can be overlooked easily when programming for text, I hate it.

 

Anyway, for our purposes I think it's quite useful to have SMD files, because their content can be looked through and understood w/o too much trouble. See here for the explanation of it's contents: https://developer.valvesoftware.com/wiki/Studiomdl_Data

 

Thanks to Schot I can now add an illustration to post #17:

post-19689-0-82701500-1383734614_thumb.jpg

Image: Vertex weights in Blender v2.69

Edited by Pesmontis
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...
Please Sign In or Sign Up