]> git.xonotic.org Git - xonotic/xonotic.wiki.git/blob - Exporting-a-weapon-for-Xonotic.md
Add details about Model scale animations problem
[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 # _Table of Contents_
4 > ### 1. [Modeling requirements](#modeling-requirements)
5 > ### 2. [Introduction to export a weapon](#introduction-to-export-a-weapon)
6 > ### 3. [Textures and UV map](#textures-and-uv-map)
7 > ### 4. [Starting to export](#starting-to-export)
8 > > 4.1. [Modifiers](#modifiers)<br/>
9 > > 4.2. [Bones and animations](#bones-and-animations)<br/>
10 > > 4.3. [Textures and materials](#textures-and-materials)
11 > ### 5. [New methodology](#new-methodology)
12 > > 5.1. [SMD (includes IQM converter and dpmodel guide)](#smd-includes-iqm-converter-and-dpmodel-guide)
13 > ### 6. [Export troubleshooting](#export-troubleshooting)
14 > ### 7. [Old methodology](#old-methodology)
15 > > 7.1. [MD3](#md3)<br/>
16 > > 7.2. [IQM](#iqm)
17
18 # Modeling requirements
19 ### To follow this, you need knowledge about modeling using Blender
20
21 Blender version recommended: [**2.79b**](https://download.blender.org/release/Blender2.79/) or [**later**](https://www.blender.org/)
22
23 You need [dpmodel](https://icculus.org/twilight/darkplaces/files/) to convert SMD files:
24 - [dpmodel tool](https://icculus.org/twilight/darkplaces/files/dpmodel20091008beta1.zip)
25
26 Requires these following tools (addons) for Blender:
27 - [IQM exporter](https://gitlab.com/xonotic/iqm) to export IQM files.
28 - [Source Tools (SMD importer/exporter)](http://steamreview.org/BlenderSourceTools/archives/) to import/export SMD files.
29
30 Optional:
31 - [MD3 importer/exporter](https://github.com/neumond/blender-md3) to import/export MD3 files.
32
33 ***IMPORTANT NOTE**: if you want to contribute, it's strongly recommended using 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/>
34 *If the version of a file is later than 2.79b, maybe some tweaks would need to take and would become tedious.*
35
36 # Introduction to export a weapon
37 **Keep in mind about weapon systems:**
38
39 - `g_*.md3`: model mesh for item pickup spawn and third person.
40 - `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)
41 - `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 (usually happens in the [old methodology](#old-methodology)).
42
43 More info: [Weapon modeling system](Weaponsystem)
44
45
46 # Textures and UV map
47
48 ### For MD3 exportation:
49
50 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).
51 <br />
52 Keep in mind, when you've done your UV map in your model, you need to set this:
53 <br />
54 <br />
55 <img src="uploads/efee46a2a80a232ebe5fa63e30f4e2d9/Md3exp.png" alt="Md3exp" width="300" />
56 <br />
57 Texture must:
58
59 - be of **Image** type
60 - mapping type **UV**
61 - have UV map assigned
62
63 otherwise resulting data block will be filled with zeroes.
64 <br />
65 <br />
66 <img src="uploads/c48fb7565453eab24faca2d6ffec4347/Md3_textures.png" alt="Md3_textures" width="360" />
67 <br />
68 <br />
69 If you didn't this, the model will be invisible and it won't be able to interact shaders.
70 <br />
71 <br />
72 [Blender reference about UV in MD3](https://archive.blender.org/wiki/index.php/Extensions:2.6/Py/Scripts/Import-Export/MD3/)
73
74 # Starting to export
75
76 ## Modifiers
77
78 Keep in mind, you need to set these modifiers for the mesh/model object: 
79
80 <img src="uploads/447f6abe0f73c6d6cadce97e4ed66e8b/blendermodifiersiqmandmd3.jpg" alt="blendermodifiersiqmandmd3" />
81
82 ## Bones and animations
83
84 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.
85
86 `tag_Somename` is another one, you can add if you need some optional animation in this bone. (Not useful for [old methodology](#old-methodology))
87
88 Moreover, watch out about position and rotation. `h_*.iqm` alterates the position and rotation of `v_*.md3`. The positions may not be equal.
89
90 `g_*` and `v_*` MUST contain one bone. The animations can't be included. It isn't like `h_*`.
91
92 Required animations and in the correct order: 
93 - `fire`
94 - `fire2`
95 - `idle`
96 - `reload`
97
98 ## Textures and materials
99
100 Please note that before exporting, about textures and materials, you have to assign the same as the script like this example shader file (`crylink.shader` file):
101 ```
102 crylink_new // your material name
103 {
104         dpreflectcube cubemaps/default/sky
105         {
106                 map textures/crylink_new.tga // the texture you wanna display in-game, make sure to test in Blender!
107                 rgbgen lightingDiffuse
108         }
109 }
110 ```
111 Note: `crylink_new` must appear in the material.
112 <br/><br/>Material:<br/>
113 <img src="uploads/abef98eaddd7c61bec7eb467efe4c3fe/crylinkblendermaterialsample.jpg" alt="crylinkblendermaterialsample" width=920 />
114 <br/>
115
116 # New methodology
117
118 You can make optional customized animations adding bones for the animations.
119
120 ## SMD (includes IQM converter and dpmodel guide)
121
122 Use Source Tools addon in Blender to export the model and animations. 
123
124 - For `h_*`:<br/>
125 Select the mesh and 1 animation and click Export, you need to export all animations one per one: 
126 <br/><img src="uploads/3775545047aa58d6e4fcb37df4f500a1/blenderSMDexport1.jpg" alt="blenderSMDexport1" width=380 /><br/><br/>
127 Repeat the process:<br/><img src="uploads/b7c8b250fc1af6b30c999506e7143930/blenderSMDexport2.jpg" alt="blenderSMDexport2" width=350 /><br/><br/>
128 <img src="uploads/9e9efa19232d1c47fd982ad0da2eb1df/blenderSMDexport3.jpg" alt="blenderSMDexport3" width=350 /><br/><br/><img src="uploads/2c929b6993d5e370c1d5498a03cb4ba8/blenderSMDexport4.jpg" alt="blenderSMDexport4" width=350 />
129 <br/><br/>
130
131 - For `g_*` and `v_*`:<br/>
132 Just select the mesh:
133 <br/><img src="uploads/ec37639792378bb6ef9684b19d45a056/blenderSMDexport5.jpg" alt="blenderSMDexport5" width=350 /><br/>
134
135 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`
136 <br/>`iqm g_myweapon.iqm g_mesh.smd`
137 <br/><br/>Linux: `./iqm.exe g_myweapon.iqm g_mesh.smd`
138 <br/>`./iqm.exe v_myweapon.iqm v_mesh.smd`
139
140 Rename extension to MD3: <br/>`g_myweapon.iqm` to `g_myweapon.md3`<br/>and `v_myweapon.iqm` to `v_myweapon.md3`
141
142 Use dpmodel tool to generate `h_myweapon.dpm` and `h_myweapon.dpm.framegroups`, in command line execute: `dpmodel yourconfig.txt`
143 <br/>More info explained about dpmodel tool: [dpmodel](dpmodel)
144 <br/>Rename extension to IQM: `h_myweapon.dpm` to `h_myweapon.iqm` and `h_myweapon.dpm.framegroups` to `h_myweapon.iqm.framegroups`.
145
146 Save those compiled model files into `models/weapons/` folder where they belong.
147
148 **Conclusion**: Sometimes, renaming formats can be useful to save effort. Note: it's a kind of weird way to do stuff, file formats are hardcoded in the gamecode rather than dynamically obtained. The issue of model resources was found here: https://gitlab.com/xonotic/xonotic-data.pk3dir/-/issues/2629#note_686988936
149
150 # Export troubleshooting
151
152 - _**Spamming CSQC errors:**_<br/>
153 If you received spamming errors like that:<br/>
154 <img src="uploads/1f769ede89975be78d88eaad1b062a3d/spammingerrorstagweapon.jpg" alt="spammingerrorstagweapon" width=450 /><br/>
155 It's because you didn't do correctly the steps after exporting the models. Remember, `g_*` and `v_*` MUST contain one bone. 
156
157 - _**Broken shadow artifacts (enabled with `r_shadows 2` and disabled `r_shadow_shadowmapping 0`):**_<br/>
158 To solve this, the possible way is exporting to IQM from Blender, selecting bone and mesh (both highlighted). Usually, this issue happens in `g_*` and `v_*` ones.
159 <br/>Reference: https://gitlab.com/xonotic/xonotic-data.pk3dir/-/issues/2667
160
161 - _**When exporting to IQM, get duplicated names in the texture:**_<br/> 
162 <img src="uploads/cdb90908aab4a52580019c871a936156/duplicatedtexturenameloadingerror.jpg" alt="duplicatedtexturenameloadingerror" width=700 /><br/>
163 Take a closer look what is telling here:<br/>
164 _The "Materials" option controls how material names are generated. "material+image-ext" combines the name of the material and the name of the UV-map image (without its extension or directory) to generate the material name, "material" uses only the name of the material, and "image" just uses the name of the UV-map image (without its directory)._ <br/><br/>
165 When you export to IQM, you need to watch out that detail after selected File > Export > Inter-Quake Model (.iqm, .iqe).<br/>
166 Pay attention to this [section](##textures-and-materials) when you need to export correctly, the material/texture(image) should be one thing, so do the following: Export IQM > Materials: > select `material` or `image` instead `material+image-ext`.<br/>
167 <img src="uploads/4fa75dca8ebb724b89d5fd5513fd2787/exportiqmiqeblenderdetails.jpg" alt="exportiqmiqeblenderdetails" width=200 /><br/>
168
169 - _**Model scale animations aren't working:**_<br/> 
170 SMD format doesn't support bone scaling animations, although you try to compile them into dpmodel tool, it won't change nothing. More info here: https://steamcommunity.com/groups/BlenderSourceTools/discussions/1/152392786900223348/
171
172 # Old methodology
173
174 *Note: this section is obsolete.*
175
176 **IMPORTANT**: In this methodology, you can't make cool animations with separated objects, because `h_*.iqm` here is a plane mesh with bones.
177
178 Note: the model should be rotated as YXZ, instead being XYZ. Because the tip of the weapon is Y, horizontally is X.
179
180 `tag_weapon` is a MUST bone for this methodology.
181
182 ## MD3
183
184 Before to export, you need to select all objects in the scene. (Pressing A, seeing all objects highlighting orange or red)
185
186 <img src="uploads/f3f39c9a06a408bffd5e48bc5e07eac6/exporttutorialMD3.jpg" alt="exporttutorialMD3" />
187
188 And export the model to MD3. _Attention: You can't export a model over than 8192 triangles/polys._
189
190 ## IQM
191
192 Before to export, you need to select all objects and bones in the scene. (Pressing A, seeing all objects highlighting orange or red)
193
194 <img src="uploads/7df860d73a6fae27408c8f0c024122c7/exporttutorialIQM.jpg" alt="exporttutorialIQM" />
195
196 <br/>
197 <br/>
198 For `h_*.iqm`, you will need to make a simple plane with a scale reduced to 0.01 and the following bones attached: `tag_weapon`, `tag_shell` and `tag_shot`.
199
200 There's a post from InsideQC Forums explaining about IQM:
201
202 There is a simple way:
203
204 You just can use an iqm model like a regular mdl file, you only need to use each frame as a framegroup.
205
206 For example, if you have an iqm called "rocketlauncher.iqm" with 20 frames you need to create a framegroup file with notepad like this:
207
208 ```
209 1 1 1 0  
210 2 1 1 0  
211 3 1 1 0  
212 4 1 1 0  
213 5 1 1 0  
214 6 1 1 0  
215 7 1 1 0  
216 8 1 1 0  
217 9 1 1 0  
218 10 1 1 0  
219 11 1 1 0  
220 12 1 1 0  
221 13 1 1 0  
222 14 1 1 0  
223 15 1 1 0  
224 16 1 1 0  
225 17 1 1 0  
226 18 1 1 0  
227 19 1 1 0  
228 20 1 1 0  
229 ```
230 So you will save it with the name.
231
232 "rocketlauncher.iqm.framegroups" and place it in the same directory where "rocketlauncher.iqm" is located.
233
234 About the framegroups file (explained on [Framegroups](framegroups)):
235
236 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).
237
238 The second number represents how many frames is in that specific frame group.
239
240 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.
241
242 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.
243
244 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)
245
246 Reference: [IQM animation framegroups (InsideQC Forums)](https://forums.insideqc.com/viewtopic.php?p=55949&sid=952cd347938ae5f2bb8bde276b5a35cd#p55949)
247