]> git.xonotic.org Git - xonotic/xonotic.wiki.git/blob - Exporting-a-weapon-for-Xonotic.md
Complete exporting new methodology, old methodology not completely explained yet
[xonotic/xonotic.wiki.git] / Exporting-a-weapon-for-Xonotic.md
1 # This article looks complete, [old methodology](#old-methodology) isn't a very complete section due to  the obsolescence
2
3 # Modeling requirements
4 ### To follow this, you need knowledge about modeling using Blender
5
6 Blender version recommended: 2.79b or later
7
8 You need [dpmodel](https://icculus.org/twilight/darkplaces/files/) to convert SMD files:
9 - [dpmodel tool](https://icculus.org/twilight/darkplaces/files/dpmodel20091008beta1.zip)
10
11 Requires these following tools (addons) for Blender:
12 - [IQM exporter](https://gitlab.com/xonotic/iqm) to export IQM files.
13 - [Source Tools (SMD importer/exporter)](http://steamreview.org/BlenderSourceTools/archives/) to import/export SMD files.
14
15 Optional:
16 - [MD3 importer/exporter](https://github.com/neumond/blender-md3) to import/export MD3 files.
17
18 ***IMPORTANT NOTE**: if you want to contribute, it's strongly important use 2.79b version for compatibility cases, they need to open from this version. Share the .blend file using 2.79b or earlier , make sure to work properly from this version!*<br/>
19 *If the version of a file is later than 2.79b, we may to make some tweaks and become tedious.*
20
21 # Introduction to export a weapon
22 **Keep in mind about weapon systems:**
23
24 - `g_*.md3`: model mesh for item pickup spawn and third person.
25 - `h_*.iqm`: for first person animations (if this step used [old methodology](#old-methodology) is a glue of `v_*`); the skeleton and the bones (the rigging and animation part). Keep in mind, you would need `*.iqm.framegroups` (more info: [Framegroups](framegroups), you can look `*.iqm.framegroups` opening a notepad to see what animations contain and the keyframes where these are set)
26 - `v_*.md3`: model mesh for third person; if `h_*.iqm` doesn't match with the animations needed of `v_*.md3`, it will generate spamming errors and bad pivot position.
27
28 More info: [Weapon modeling system](Weaponsystem)
29
30
31 # Textures and UV map
32
33 ### For MD3 exportation:
34
35 You have to add single material with single texture for every mesh object. Name of texture node will be written as is into MD3 data (suffixes like .001, .002 are ignored, feel free to use one texture for many meshes).
36 <br />
37 Keep in mind, when you've done your UV map in your model, you need to set this:
38 <br />
39 <br />
40 <img src="uploads/efee46a2a80a232ebe5fa63e30f4e2d9/Md3exp.png" alt="Md3exp" width="300" />
41 <br />
42 Texture must:
43
44 - be of **Image** type
45 - mapping type **UV**
46 - have UV map assigned
47
48 otherwise resulting data block will be filled with zeroes.
49 <br />
50 <br />
51 <img src="uploads/c48fb7565453eab24faca2d6ffec4347/Md3_textures.png" alt="Md3_textures" width="360" />
52 <br />
53 <br />
54 If you didn't this, the model will be invisible and it won't be able to interact shaders.
55 <br />
56 <br />
57 [Blender reference about UV in MD3](https://archive.blender.org/wiki/index.php/Extensions:2.6/Py/Scripts/Import-Export/MD3/)
58
59 # Starting to export
60
61 Keep in mind, you need to set these modifiers for the mesh/model object: 
62
63 <img src="uploads/447f6abe0f73c6d6cadce97e4ed66e8b/blendermodifiersiqmandmd3.jpg" alt="blendermodifiersiqmandmd3" />
64
65 MUST contain `tag_handle`, `tag_shell` and `tag_shot` bone names attached. These tag_names MUST be attached, if not the model will cause errors.
66
67 `tag_Somename` is another one, you can add if you need some optional animation in this bone.
68
69 Moreover, watch out about position and rotation. `h_*.iqm` alterates the position and rotation of `v_*.md3`. The positions may not be equal.
70
71 `g_*` and `v_*` MUST contain one bone. The animations can't be included. It isn't like `h_*`.
72
73 The animations are `fire`, `fire2`, `idle` and `reload`.
74
75 # New methodology
76
77 You can make optional customized animations adding bones for the animations.
78
79 ## SMD (includes IQM converter and dpmodel guide)
80
81 Use Source Tools addon in Blender to export the model and animations. 
82
83 - For `h_*`:
84 Select the mesh and 1 animation and click Export, you need to export all animations one per one: 
85 <br/><img src="uploads/3775545047aa58d6e4fcb37df4f500a1/blenderSMDexport1.jpg" alt="blenderSMDexport1" width=700 /><br/>
86 Repeat the process:<br/><img src="uploads/b7c8b250fc1af6b30c999506e7143930/blenderSMDexport2.jpg" alt="blenderSMDexport2" width=700 /><br/><br/>
87 <img src="uploads/9e9efa19232d1c47fd982ad0da2eb1df/blenderSMDexport3.jpg" alt="blenderSMDexport3" width=700 /><br/><br/>
88 <img src="uploads/2c929b6993d5e370c1d5498a03cb4ba8/blenderSMDexport4.jpg" alt="blenderSMDexport4" width=700 />
89 <br/><br/>
90
91 - For `g_*` and `v_*`:
92 Just select the mesh:
93 <br/><img src="uploads/ec37639792378bb6ef9684b19d45a056/blenderSMDexport5.jpg" alt="blenderSMDexport5 width=700 /><br/>
94
95 Use `iqm.exe` from [IQM exporter](https://gitlab.com/xonotic/iqm), in Windows, in CMD execute for convert SMD to IQM for `v_*` and `g_*`: <br/>`iqm v_myweapon.iqm v_mesh.smd`
96 <br/>`iqm g_myweapon.iqm g_mesh.smd`
97 <br/><br/>Linux: `./iqm.exe g_myweapon.iqm g_mesh.smd`
98 <br/>`./iqm.exe v_myweapon.iqm v_mesh.smd`
99
100 Rename extension to MD3: <br/>`g_myweapon.iqm` to `g_myweapon.md3`<br/>and `v_myweapon.iqm` to `v_myweapon.md3`
101
102 Use dpmodel tool to generate `h_myweapon.dpm` and `h_myweapon.dpm.framegroups`, in command line execute: `dpmodel yourconfig.txt`
103 <br/>More info explained about dpmodel tool: [dpmodel](dpmodel)
104 <br/>Rename extension to IQM: `h_myweapon.dpm` to `h_myweapon.iqm` and `h_myweapon.dpm.framegroups` to `h_myweapon.iqm.framegroups`.
105
106 Save those compiled model files into `models/weapons/` folder where they belong.
107
108 **Conclusion**: Sometimes, renaming formats can be useful to save effort. Note: it's a kind of weird way to do stuff, the issue of model resources was found here: https://gitlab.com/xonotic/xonotic-data.pk3dir/-/issues/2629#note_686988936
109
110 If you received spamming errors like that:<br/>
111 <img src="uploads/1f769ede89975be78d88eaad1b062a3d/spammingerrorstagweapon.jpg" alt="spammingerrorstagweapon" width=600 /><br/>
112 It's because you didn't do correctly the steps after exporting the models. Remember, `g_*` and `v_*` MUST contain one bone. 
113
114 # Old methodology
115
116 **IMPORTANT**: In this methodology, you can't make cool animations with separated objects, because `h_*.iqm` here is a plane mesh with bones.
117
118 Note: the model should be rotated as YXZ, instead being XYZ. Because the tip of the weapon is Y, horizontally is X.
119
120 `tag_weapon` is a MUST bone for this methodology.
121
122 ## MD3
123
124 Before to export, you need to select all objects in the scene. (Pressing A, seeing all objects highlighting orange or red)
125
126 <img src="uploads/f3f39c9a06a408bffd5e48bc5e07eac6/exporttutorialMD3.jpg" alt="exporttutorialMD3" />
127
128 ## IQM
129
130 Before to export, you need to select all objects and bones in the scene. (Pressing A, seeing all objects highlighting orange or red)
131
132 <img src="uploads/7df860d73a6fae27408c8f0c024122c7/exporttutorialIQM.jpg" alt="exporttutorialIQM" />
133
134 <br/>
135 <br/>
136 There's a post from InsideQC Forums explaining about IQM:
137
138 For `h_*.iqm`, you will need to do this:
139
140 There is a simple way:
141
142 You just can use an iqm model like a regular mdl file, you only need to use each frame as a framegroup.
143
144 For example, if you have an iqm called "rocketlauncher.iqm" with 20 frames you need to create a framegroup file with notepad like this:
145
146 ```
147 1 1 1 0  
148 2 1 1 0  
149 3 1 1 0  
150 4 1 1 0  
151 5 1 1 0  
152 6 1 1 0  
153 7 1 1 0  
154 8 1 1 0  
155 9 1 1 0  
156 10 1 1 0  
157 11 1 1 0  
158 12 1 1 0  
159 13 1 1 0  
160 14 1 1 0  
161 15 1 1 0  
162 16 1 1 0  
163 17 1 1 0  
164 18 1 1 0  
165 19 1 1 0  
166 20 1 1 0  
167 ```
168 So you will save it with the name.
169
170 "rocketlauncher.iqm.framegroups" and place it in the same directory where "rocketlauncher.iqm" is located.
171
172 About the framegroups file (explained on [Framegroups](framegroups)):
173
174 The first number represents the start frame of the animation (.framegroups files always start at frame 0, some modeling software starts at 1, so you might have to subtract 1 for the start frame).
175
176 The second number represents how many frames is in that specific frame group.
177
178 The third number is the frame rate at which the sequence plays. This is independent from what the monsters "think" rate is, which I have set at 10 frames-per-second.
179
180 The fourth number is whether the frame sequence loops. 1 for true, 0 for false. The only frame groups that should loop are the standing, walking and running animations.
181
182 It becomes very tedious to make framegroups for models with really many frames, you can use this sample generated for the darkplaces model compiler. It will work in every iqm model (if you wan you only need to cut the specific number of frames in the framegroups file, but it will work anyway)
183
184 Reference: [IQM animation framegroups (InsideQC Forums)](https://forums.insideqc.com/viewtopic.php?p=55949&sid=952cd347938ae5f2bb8bde276b5a35cd#p55949)
185