Basics of exporting from blender to SA-MP
#1

The main export tools for GTA:SA are written for 3dsmax. But if you're like me and don't model professionally, the cost of 3dsmax can be a bit much.

Blender is a free modeling program with importers and exporters for many different games, including GTA:SA.

Tools needed:
- blender 2.63+
- gtatools blender scripts by ponz
- TXD Workshop by TurtleL
- kdff.exe command line tool (comes with the SA-MP server package)
- Collision File Editor II 0.4 BETA

Instructions for getting started.
- Download and install blender. Check that it runs.
- Extract the gtatools scripts in to your blender addons folder e.g. C:\blender-2.71-windows64\2.71\scripts\addons. You should then have a "space_view3d_gta_tools" folder in your blender addons folder.
- Enable GTA tools in blender by going to File > User Preferences > Addons > and checking 3D View: GTA Tools.

We'll be exporting blender's default cube as a dff with a collision attached.

Find a texture for the cube. Open a txd material in TXD workshop and export it to something blender can read like bmp or png.



Step 01) Open up blender.



Step 02) Game engines use triangles to render, but modeling programs support different types of edges like quads (squares). We need to triangulate the cube's faces so it can be exported to the game.

02_triangulate_cube.mp4

Step 03) Create a UV map by running UV unwrap and apply the texture we exported earlier.

03_add_cube_texture.mp4

Step 04) Make sure the material name in blender matches the material name in our txd file.

04_change_material_to_txdmatname.mp4

Step 05) Export the cube as a dff and we'll attach a collision. I named my cube as testcube1.dff.

05_export_cube.mp4

Now we need to use the kdff.exe tool in the server package to generate a collision (.col file) then attach the collision to the dff. Copy the kdff.exe tool to the folder where you are exporting your models, then open a command prompt, cd to that folder, then run kdff on your dff file. Example:

Quote:

c:\>cd c:\gtasa\03server\models\modeling
c:\gtasa\03server\models\modeling>kdff.exe -g box -d testcube1.dff -o testcube1.col

In the above command, we used kdff to generate a simple box collision for our testcube. Now we should attach this collision to the dff file.

Quote:

c:\gtasa\03server\models\modeling>kdff.exe -a -d testcube1.dff -c testcube1.col -o testcubeC.dff

At this point, our final model file testcubeC.dff is ready. We just need to make sure our texture is in wallzzz.txd and has the correct material name. We could load this in to the artconfig.txt and spawn it with /crobj.

Quote:

artconfig line: AddSimpleModel(-1,19379, -2001, "testcubeC.dff", "wallzzz.txd");

If we spawn it like this it'll look dull because we did not apply any lighting. Everything in GTA is prelit, that means the lighting information is embedded in the dff. We should apply some vertex lighting now.

Step 06) Bake lighting to vertex colors, export the dff again and reattach the col. Make sure Shadeless is turned off in the material tab so we can see the lights being applied to the model.

06_vertex_lighting.mp4

Step 07) After we've re-exported our dff, reattached the col so we have testcubeC.dff ready, we can go ahead and see our final result.

07_test_cube.mp4



More on kdff.exe
kdff can generate 3 types of collision files: empty, box, mesh. 'empty' is for objects that don't need a physical collision, such as objects attached to players. 'box' mode will generate a single box around the object. A box is suitable for many simple interior objects like fridges, plants etc. 'mesh' mode will use the object's faces to create a proper collision. After exporting in 'mesh' mode, you should take the .col file in to 'Collision Editor II' and generate face groups and also set the material type of the surfaces if needed.
Reply
#2

Great tutorial, thanks.
Reply
#3

Thats nice.
Reply
#4

Thats great.
Reply
#5

Well done, Kye.
Reply
#6

Could you give us more insight on the parameters of AddCharModel and AddSimpleModel?

For example, what is the 1st param of AddCharModel? I used a valid skin ID then used the skin ID from the 2nd one in SetPlayerSkin and it worked.
Reply
#7

Quote:

AddCharModel(base skin (used for voice, animations), new skin ID, dff file in the models folder, txd file in the models folder);
from pawn: SetPlayerSkin(playerid, new skin ID);

AddSimpleModel(virtual world (-1 is all virtual worlds), base model (used for IDE flags), new model ID (-1000 to -30000), dff file in models folder, txd file in models folder);
from pawn: CreateObject(new model ID, position, rotation etc..);

Also, 'kdff', needed to make the collision has a gui version, which is easier to use, since this tutorial was written.
Reply
#8

Quote:
Originally Posted by Kalcor
View Post
Also, 'kdff', needed to make the collision has a gui version, which is easier to use, since this tutorial was written.
Thanks!

Here's a little thing that's annoying with the GUI program, it attempts to open up the ballontest dff file, what I removed so every time I open it, it gives me an error about not finding it.


Also I'm getting this when I try and open a specific .txd file from a model I got from a gta website to test it.
(in game the txd is also invisible.)
Reply
#9

Is there possibility to access my own object's texture via native SA:MP functions (SetObjectMaterial)?
Reply
#10

It seems the gui always access violates with ANY txd file.
Reply
#11

Don't remove the balloon files. Maybe you'll be able to in some future version, for now it's part of the loading process.

Right now you can't use SetObjectMaterial with custom models. There's no real need to since you can supply any texture you want.
Reply
#12

Quote:
Originally Posted by Kalcor
Посмотреть сообщение
Don't remove the balloon files. Maybe you'll be able to in some future version, for now it's part of the loading process.

Right now you can't use SetObjectMaterial with custom models. There's no real need to since you can supply any texture you want.
Thanks, that fixed it! It's a bit odd that we have to keep the balloon files though.
Reply
#13

What about using new objects in textdraws? (preview model)
Reply
#14

Quote:
Originally Posted by iDayZ
Посмотреть сообщение
What about using new objects in textdraws? (preview model)
We tested them and they seem to work fine. If there are problems let us know.
Reply
#15

can I put custom texture?
Reply
#16

Do you know what'd cause the game not displaying the .dff or .txd for that matter?
I copied the AddSimpleModel example and added my own dff & txd with the dff having the sa-mp col, and it is basically invisible, the collision works though.

(kdff displays it correctly.)
Reply
#17

Can I replace current .txd files for the new ones (like weapons) ?
Reply
#18

Just. Fix update SetObjectMaterial and SetObjectMaterialText.
Reply
#19

This should be sticky.

Thanks for tutorial
Reply
#20

Nice tuto.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)