Skip to content

Commit 666510e

Browse files
author
Roberto De Ioris
authored
Update WritingAColladaFactoryWithPython.md
1 parent 992dae0 commit 666510e

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

‎tutorials/WritingAColladaFactoryWithPython.md‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,48 @@ as you can see from the screenshot, the address of the UClass as well as its pyt
4242

4343
## Parse .dae files with pycollada
4444

45+
The collada format is based on XML, so we can easily parse it from python, but instead of doing the hard work by hand, we can use the amazing pycollada module (https://github.com/pycollada/pycollada). Just pip install it and update your class to import and use it:
46+
47+
```python
48+
from unreal_engine.classes import PyFactory, StaticMesh, Object, Class
49+
50+
import unreal_engine as ue
51+
52+
from collada import Collada
53+
54+
class ColladaFactory(PyFactory):
55+
56+
def __init__(self):
57+
# inform the editor that this class is able to import assets
58+
self.bEditorImport = True
59+
# register the .dae extension as supported
60+
self.Formats = ['dae;Collada']
61+
# set the UClass this UFactory will generate
62+
self.SupportedClass = StaticMesh
63+
64+
def PyFactoryCreateFile(self, uclass: Class, parent: Object, name: str, filename: str) -> Object:
65+
# load the collada file
66+
dae = Collada(filename)
67+
ue.log_warning(dae)
68+
# create a new UStaticMesh with the specified name and parent
69+
static_mesh = StaticMesh(name, parent)
70+
return static_mesh
71+
```
72+
73+
Now download the example .dae file from here:
74+
75+
https://github.com/20tab/UnrealEnginePython/raw/master/tutorials/WritingAColladaFactoryWithPython_Assets/duck_triangles.dae
76+
77+
(it is a simple duck)
78+
79+
once you re-run the collada_factory.py script you will be able to click on 'Import' in the Countent Browser and now you the 'dae' extension will show in the list of supported ones. Select the duck file and just look at the python console:
80+
81+
![First import](https://github.com/20tab/UnrealEnginePython/blob/master/tutorials/WritingAColladaFactoryWithPython_Assets/first_import.png)
82+
83+
obviously we still have not added data to our StaticMesh, so in our Content Browser an empty Static Mesh will appear:
84+
85+
![Empty mesh](https://github.com/20tab/UnrealEnginePython/blob/master/tutorials/WritingAColladaFactoryWithPython_Assets/empty_mesh.png)
86+
4587
## Adding a GUI to the importer: The Slate API
4688

4789
## Persistent importer options: more subclassing

0 commit comments

Comments
 (0)