Skip to content

Commit 0bf5077

Browse files
author
Roberto De Ioris
committed
2 parents a29c89f + cf429c6 commit 0bf5077

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

tutorials/WritingAColladaFactoryWithPython.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,89 @@ Try to play a bit with MeshBuildSettings values in the code (expecially note the
196196

197197
## A more complex model: Mixamo's Vampire
198198

199+
Download this file: https://github.com/20tab/UnrealEnginePython/raw/master/tutorials/WritingAColladaFactoryWithPython_Assets/vampire.dae
200+
201+
it is the Vampire from mixmamo.com.
202+
203+
Technically it is a skeletal mesh with an animation (something we will try to import in a future tutorial), if we try to import it we will end with a dead vampire :P
204+
205+
![Broken vampire](https://github.com/20tab/UnrealEnginePython/blob/master/tutorials/WritingAColladaFactoryWithPython_Assets/broken_vampire.png)
206+
207+
time to use some vector math to fix the mesh rotation:
208+
209+
```python
210+
...
211+
212+
from unreal_engine import FVector, FRotator
213+
...
214+
def FixMeshData(self):
215+
# move from collada system (y on top) to ue4 one (z on top, forward decreases over viewer)
216+
for i in range(0, len(self.vertices), 3):
217+
xv, yv, zv = self.vertices[i], self.vertices[i+1], self.vertices[i+2]
218+
# invert forward
219+
vec = FVector(zv * -1, xv, yv) * FRotator(0, -90, 180)
220+
self.vertices[i] = vec.x
221+
self.vertices[i+1] = vec.y
222+
self.vertices[i+2] = vec.z
223+
xn, yn, zn = self.normals[i], self.normals[i+1], self.normals[i+2]
224+
nor = FVector(zn * -1, xn, yn) * FRotator(0, -90, 180)
225+
# invert forward
226+
self.normals[i] = nor.x
227+
self.normals[i+1] = nor.y
228+
self.normals[i+2] = nor.z
229+
230+
# fix uvs from 0 on bottom to 0 on top
231+
for i, uv in enumerate(uvs):
232+
if i % 2 != 0:
233+
uvs[i] = 1 - uv
234+
```
235+
236+
re-run and re-import the vampire, it should be correctly rotated now.
237+
238+
Obviously if we reimport the duck with the current code, its rotation will be wrong. So, time to add a configurator GUI for the factory.
239+
199240
## Adding a GUI to the importer: The Slate API
200241

242+
Slate is the GUI technology of Unreal Engine. It is based on tons of preprocessor macros to simplify readability to the developer building graphical interfaces. Its python wrapper tries to resemble this spirit by adapting it to the pythonic style. Note: the slate python api wrapper development has been completely sponsored by Kite & Lightning (http://kiteandlightning.la/). Big thanks to them.
243+
244+
A Python Slate interface looks like this:
245+
246+
```python
247+
from unreal_engine import SWindow, SVerticalBox, SHorizontalBox, SButton, STextBlock, SBorder, FLinearColor
248+
from unreal_engine.enums import EHorizontalAlignment, EVerticalAlignment
249+
250+
import unreal_engine as ue
251+
252+
SWindow(title='Hello I am Slate', client_size=(1024, 512))(
253+
SVerticalBox()
254+
(
255+
STextBlock(text='I am the first top vertical item, without alignment'),
256+
)
257+
(
258+
SBorder(color_and_opacity=FLinearColor(1, 0, 0, 1))
259+
(
260+
STextBlock(text='I am the second top vertical item with center/bottom alignment'),
261+
),
262+
h_align = EHorizontalAlignment.HAlign_Center,
263+
v_align = EVerticalAlignment.VAlign_Bottom
264+
)
265+
(
266+
SHorizontalBox()
267+
(
268+
SButton(text='Button Left', on_clicked=lambda: ue.log('Hello from left'), h_align=EHorizontalAlignment.HAlign_Center)
269+
)
270+
(
271+
SButton(text='Button Right', on_clicked=lambda: ue.log('Hello from right'), v_align=EVerticalAlignment.VAlign_Center)
272+
),
273+
fill_height=0.2
274+
)
275+
)
276+
```
277+
278+
feel free to run the previous code to obtain something like this (click on the buttons, they will write to the console !):
279+
280+
![Slate demo](https://github.com/20tab/UnrealEnginePython/blob/master/tutorials/WritingAColladaFactoryWithPython_Assets/slate_demo.png)
281+
201282
## Persistent importer options: more subclassing
202283

203284
## Automatically add the ColladaFactory on editor startup

0 commit comments

Comments
 (0)