-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare-object-lq-file.py
40 lines (27 loc) · 1.23 KB
/
prepare-object-lq-file.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
Imports a GLTF file, joins all meshes, and saves the blend file at the same place as the GLTF
"""
import bpy
import sys
import bmesh
argv = sys.argv
argv = argv[argv.index("--") + 1:] # get all args after "--"
gltfPath = argv[0]
bpy.ops.import_scene.gltf(filepath=gltfPath)
# Join all meshes
meshes = list(filter(lambda obj: obj.type == 'MESH', bpy.data.objects))
if len(meshes) > 1:
with bpy.context.temp_override(active_object=meshes[0], selected_editable_objects=meshes):
bpy.ops.object.join()
# Find the joined mesh, move it to root, and apply the transform
joinedMesh = next(filter(lambda obj: obj.type == 'MESH', bpy.data.objects))
with bpy.context.temp_override(active_object=joinedMesh, selected_objects=[joinedMesh]):
bpy.ops.object.parent_clear(type='CLEAR_KEEP_TRANSFORM')
#bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)
# Delete all non-meshes objects
nonMeshes = list(filter(lambda obj: obj.type != 'MESH', bpy.data.objects))
with bpy.context.temp_override(active_object=None, selected_objects=nonMeshes):
bpy.ops.object.delete()
# Change the name of the joined mesh
joinedMesh.name = "__render_importObject"
bpy.ops.wm.save_mainfile(filepath=gltfPath.replace('.gltf', '.blend'))