0
# Post-Processing Options
1
2
Extensive mesh processing and optimization capabilities through bitwise-combinable flags. Post-processing steps transform and optimize 3D model data during loading and export operations, enabling mesh optimization, geometry fixes, format conversions, and rendering preparation.
3
4
## Capabilities
5
6
### Geometry Processing
7
8
Fundamental geometry processing operations for mesh optimization and standardization.
9
10
```python { .api }
11
# Tangent and bitangent calculation
12
aiProcess_CalcTangentSpace = 0x1
13
14
# Vertex deduplication
15
aiProcess_JoinIdenticalVertices = 0x2
16
17
# Coordinate system conversion
18
aiProcess_MakeLeftHanded = 0x4
19
20
# Face triangulation
21
aiProcess_Triangulate = 0x8
22
23
# Normal generation
24
aiProcess_GenNormals = 0x20
25
aiProcess_GenSmoothNormals = 0x40
26
```
27
28
Usage examples:
29
30
```python
31
import pyassimp
32
from pyassimp.postprocess import *
33
34
# Basic triangulation (default)
35
scene = pyassimp.load("model.obj", processing=aiProcess_Triangulate)
36
37
# Generate smooth normals and tangents
38
processing = aiProcess_Triangulate | aiProcess_GenSmoothNormals | aiProcess_CalcTangentSpace
39
scene = pyassimp.load("model.dae", processing=processing)
40
41
# Join identical vertices to reduce memory usage
42
processing = aiProcess_JoinIdenticalVertices | aiProcess_Triangulate
43
scene = pyassimp.load("model.stl", processing=processing)
44
```
45
46
### Mesh Optimization
47
48
Performance optimization operations for real-time rendering and memory efficiency.
49
50
```python { .api }
51
# Cache locality optimization
52
aiProcess_ImproveCacheLocality = 0x800
53
54
# Material deduplication
55
aiProcess_RemoveRedundantMaterials = 0x1000
56
57
# Mesh combination
58
aiProcess_OptimizeMeshes = 0x200000
59
60
# Scene graph optimization
61
aiProcess_OptimizeGraph = 0x400000
62
63
# Large mesh subdivision
64
aiProcess_SplitLargeMeshes = 0x80
65
66
# Bone weight limiting
67
aiProcess_LimitBoneWeights = 0x200
68
```
69
70
Usage examples:
71
72
```python
73
from pyassimp.postprocess import *
74
75
# Real-time rendering optimization
76
processing = (aiProcess_Triangulate |
77
aiProcess_JoinIdenticalVertices |
78
aiProcess_ImproveCacheLocality |
79
aiProcess_OptimizeMeshes)
80
81
scene = pyassimp.load("complex_model.dae", processing=processing)
82
83
# Memory optimization
84
processing = (aiProcess_RemoveRedundantMaterials |
85
aiProcess_OptimizeGraph |
86
aiProcess_SplitLargeMeshes)
87
88
scene = pyassimp.load("large_model.obj", processing=processing)
89
```
90
91
### Data Validation and Fixes
92
93
Data integrity validation and automatic fixes for common mesh issues.
94
95
```python { .api }
96
# Structure validation
97
aiProcess_ValidateDataStructure = 0x400
98
99
# Normal direction fixes
100
aiProcess_FixInfacingNormals = 0x2000
101
102
# Degenerate primitive detection
103
aiProcess_FindDegenerates = 0x10000
104
105
# Invalid data detection and removal
106
aiProcess_FindInvalidData = 0x20000
107
108
# Primitive type sorting
109
aiProcess_SortByPType = 0x8000
110
```
111
112
Usage examples:
113
114
```python
115
from pyassimp.postprocess import *
116
117
# Comprehensive validation and fixes
118
processing = (aiProcess_ValidateDataStructure |
119
aiProcess_FixInfacingNormals |
120
aiProcess_FindInvalidData |
121
aiProcess_FindDegenerates)
122
123
scene = pyassimp.load("potentially_broken.obj", processing=processing)
124
125
# Sort primitives by type (separate triangles, lines, points)
126
processing = aiProcess_SortByPType | aiProcess_Triangulate
127
scene = pyassimp.load("mixed_primitives.ply", processing=processing)
128
```
129
130
### Format Conversion
131
132
Coordinate system and data format conversions for different rendering pipelines.
133
134
```python { .api }
135
# Coordinate system conversion
136
aiProcess_MakeLeftHanded = 0x4
137
aiProcess_FlipUVs = 0x800000
138
aiProcess_FlipWindingOrder = 0x1000000
139
140
# UV coordinate generation and transformation
141
aiProcess_GenUVCoords = 0x40000
142
aiProcess_TransformUVCoords = 0x80000
143
144
# Scene preprocessing
145
aiProcess_PreTransformVertices = 0x100
146
aiProcess_RemoveComponent = 0x10
147
```
148
149
Usage examples:
150
151
```python
152
from pyassimp.postprocess import *
153
154
# DirectX/Direct3D conversion
155
processing = (aiProcess_MakeLeftHanded |
156
aiProcess_FlipUVs |
157
aiProcess_FlipWindingOrder)
158
159
scene = pyassimp.load("opengl_model.obj", processing=processing)
160
161
# Generate UV coordinates for non-UV mapped models
162
processing = aiProcess_GenUVCoords | aiProcess_Triangulate
163
scene = pyassimp.load("no_uvs.stl", processing=processing)
164
165
# Flatten scene hierarchy (remove transformations)
166
processing = aiProcess_PreTransformVertices | aiProcess_Triangulate
167
scene = pyassimp.load("hierarchical.dae", processing=processing)
168
```
169
170
### Animation and Rigging
171
172
Processing options for animated models and skeletal data.
173
174
```python { .api }
175
# Bone processing
176
aiProcess_LimitBoneWeights = 0x200
177
aiProcess_SplitByBoneCount = 0x2000000
178
aiProcess_Debone = 0x4000000
179
180
# Mesh instancing and duplicates
181
aiProcess_FindInstances = 0x100000
182
183
# Additional processing (note: these constants may have conflicts in source)
184
aiProcess_GenEntityMeshes = 0x100000
185
aiProcess_OptimizeAnimations = 0x200000
186
aiProcess_FixTexturePaths = 0x200000
187
```
188
189
Usage examples:
190
191
```python
192
from pyassimp.postprocess import *
193
194
# Optimize for hardware skinning (max 4 bones per vertex)
195
processing = (aiProcess_LimitBoneWeights |
196
aiProcess_Triangulate)
197
198
scene = pyassimp.load("rigged_character.dae", processing=processing)
199
200
# Remove unnecessary bones
201
processing = aiProcess_Debone | aiProcess_Triangulate
202
scene = pyassimp.load("over_rigged.fbx", processing=processing)
203
```
204
205
## Preset Combinations
206
207
Predefined processing combinations for common use cases.
208
209
```python { .api }
210
# DirectX/Direct3D preset
211
aiProcess_ConvertToLeftHanded = (aiProcess_MakeLeftHanded |
212
aiProcess_FlipUVs |
213
aiProcess_FlipWindingOrder)
214
215
# Fast real-time rendering preset
216
aiProcessPreset_TargetRealtime_Fast = (aiProcess_CalcTangentSpace |
217
aiProcess_GenNormals |
218
aiProcess_JoinIdenticalVertices |
219
aiProcess_Triangulate |
220
aiProcess_GenUVCoords |
221
aiProcess_SortByPType)
222
223
# Quality real-time rendering preset
224
aiProcessPreset_TargetRealtime_Quality = (aiProcess_CalcTangentSpace |
225
aiProcess_GenSmoothNormals |
226
aiProcess_JoinIdenticalVertices |
227
aiProcess_ImproveCacheLocality |
228
aiProcess_LimitBoneWeights |
229
aiProcess_RemoveRedundantMaterials |
230
aiProcess_SplitLargeMeshes |
231
aiProcess_Triangulate |
232
aiProcess_GenUVCoords |
233
aiProcess_SortByPType |
234
aiProcess_FindDegenerates |
235
aiProcess_FindInvalidData)
236
237
# Maximum quality preset
238
aiProcessPreset_TargetRealtime_MaxQuality = (aiProcessPreset_TargetRealtime_Quality |
239
aiProcess_FindInstances |
240
aiProcess_ValidateDataStructure |
241
aiProcess_OptimizeMeshes)
242
```
243
244
Usage examples:
245
246
```python
247
from pyassimp.postprocess import *
248
249
# Use preset for DirectX applications
250
scene = pyassimp.load("model.obj", processing=aiProcess_ConvertToLeftHanded)
251
252
# Use preset for fast loading
253
scene = pyassimp.load("model.dae", processing=aiProcessPreset_TargetRealtime_Fast)
254
255
# Use preset for maximum quality
256
scene = pyassimp.load("model.blend", processing=aiProcessPreset_TargetRealtime_MaxQuality)
257
258
# Combine preset with custom flags
259
custom_processing = aiProcessPreset_TargetRealtime_Quality | aiProcess_FixTexturePaths
260
scene = pyassimp.load("model.x", processing=custom_processing)
261
```
262
263
## Advanced Usage Patterns
264
265
### Conditional Processing
266
267
Apply different processing based on model characteristics:
268
269
```python
270
import pyassimp
271
from pyassimp.postprocess import *
272
273
def load_with_smart_processing(filename):
274
# Basic load to inspect model
275
scene = pyassimp.load(filename, processing=0) # No processing
276
277
processing = aiProcess_Triangulate # Always triangulate
278
279
# Add processing based on model characteristics
280
if len(scene.meshes) > 100:
281
processing |= aiProcess_OptimizeMeshes
282
283
if any(len(mesh.faces) > 10000 for mesh in scene.meshes):
284
processing |= aiProcess_SplitLargeMeshes
285
286
if any(not hasattr(mesh, 'normals') or not mesh.normals for mesh in scene.meshes):
287
processing |= aiProcess_GenSmoothNormals
288
289
# Release initial scene and reload with proper processing
290
pyassimp.release(scene)
291
return pyassimp.load(filename, processing=processing)
292
```
293
294
### Processing Pipeline
295
296
Chain multiple processing steps:
297
298
```python
299
from pyassimp.postprocess import *
300
301
def create_processing_pipeline(target="realtime"):
302
"""Create processing pipeline for different targets."""
303
304
base = aiProcess_Triangulate | aiProcess_JoinIdenticalVertices
305
306
if target == "realtime":
307
return base | aiProcess_GenSmoothNormals | aiProcess_ImproveCacheLocality
308
elif target == "quality":
309
return base | aiProcess_CalcTangentSpace | aiProcess_OptimizeMeshes
310
elif target == "directx":
311
return base | aiProcess_ConvertToLeftHanded
312
elif target == "validation":
313
return base | aiProcess_ValidateDataStructure | aiProcess_FindInvalidData
314
else:
315
return base
316
317
# Usage
318
scene = pyassimp.load("model.obj", processing=create_processing_pipeline("quality"))
319
```
320
321
## Performance Considerations
322
323
1. **Processing Time**: More flags = longer processing time
324
2. **Memory Usage**: Some flags increase memory usage (e.g., tangent calculation)
325
3. **Quality vs Speed**: Balance processing quality with loading performance
326
4. **Format-Specific**: Some formats benefit more from certain processing steps
327
5. **Order Independence**: Processing flags are applied in optimal order automatically
328
329
## Common Processing Combinations
330
331
```python
332
from pyassimp.postprocess import *
333
334
# Game development (fast rendering)
335
GAME_PROCESSING = (aiProcess_Triangulate |
336
aiProcess_JoinIdenticalVertices |
337
aiProcess_GenSmoothNormals |
338
aiProcess_ImproveCacheLocality)
339
340
# Visualization (quality focus)
341
VIZ_PROCESSING = (aiProcess_Triangulate |
342
aiProcess_CalcTangentSpace |
343
aiProcess_GenSmoothNormals |
344
aiProcess_OptimizeMeshes)
345
346
# CAD import (data integrity)
347
CAD_PROCESSING = (aiProcess_Triangulate |
348
aiProcess_ValidateDataStructure |
349
aiProcess_FixInfacingNormals |
350
aiProcess_FindInvalidData)
351
352
# Mobile/WebGL (size optimization)
353
MOBILE_PROCESSING = (aiProcess_Triangulate |
354
aiProcess_JoinIdenticalVertices |
355
aiProcess_RemoveRedundantMaterials |
356
aiProcess_SplitLargeMeshes |
357
aiProcess_OptimizeGraph)
358
```