-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport_helper_gltf_op.py
159 lines (135 loc) · 5.93 KB
/
export_helper_gltf_op.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import bpy
import os
import math
class EXPORTGLB_OT_Operator(bpy.types.Operator):
bl_idname = "object.export_gltf"
bl_label = "Export Operator"
bl_description = "Export GLB"
def execute(self, context):
glb_dir = '.\GLB'
blend_file_path = bpy.data.filepath
directory = os.path.dirname(blend_file_path)
bpy.ops.object.mode_set(mode = 'OBJECT')
bpy.ops.object.select_all(action='DESELECT')
if os.path.isdir(directory + glb_dir) == False:
os.makedirs(directory + glb_dir)
i = 0
for i in range(len(bpy.context.scene.objects)):
obj_name = bpy.context.scene.objects[i].name
target_file_glb = os.path.join(directory + glb_dir, obj_name)
bpy.data.objects[obj_name].select_set(True)
obj_loc = bpy.data.objects[obj_name].location.copy() # copy location
bpy.data.objects[obj_name].location = (0,0,0) # move object to world origin
bpy.ops.export_scene.gltf(
export_format='GLB',
ui_tab='GENERAL',
export_copyright="Michael Bridges",
export_image_format='PNG',
export_texture_dir="",
export_texcoords=True,
export_normals=True,
export_draco_mesh_compression_enable=False,
export_draco_mesh_compression_level=6,
export_draco_position_quantization=14,
export_draco_normal_quantization=10,
export_draco_texcoord_quantization=12,
export_draco_generic_quantization=12,
export_tangents=False,
export_materials=True,
export_colors=True,
export_cameras=False,
export_selected=True,
export_extras=False,
export_yup=True,
export_apply=True,
export_animations=True,
export_frame_range=True,
export_frame_step=1,
export_force_sampling=True,
export_nla_strips=True,
export_def_bones=False,
export_current_frame=False,
export_skins=True,
export_all_influences=False,
export_morph=True,
export_morph_normal=True,
export_morph_tangent=False,
export_lights=False,
export_displacement=False,
will_save_settings=True,
filepath=target_file_glb,
check_existing=True,
filter_glob="*.glb;*.gltf")
bpy.data.objects[obj_name].location = obj_loc # set object back to it's original location
bpy.ops.object.select_all(action='DESELECT')
i =+ 1
return {'FINISHED'}
class EXPORTGLBALL_OT_Operator(bpy.types.Operator):
bl_idname = "object.export_gltf_all"
bl_label = "Export Operator"
bl_description = "Export GLB"
def execute(self, context):
glb_dir = '.\GLB'
blend_file_path = bpy.data.filepath
directory = os.path.dirname(blend_file_path)
obj_list = bpy.context.scene.objects
obj_locs = {} # dictionary ready for objects locations
obj_name = str(bpy.path.basename(bpy.context.blend_data.filepath))
target_file_glb = os.path.join(directory + glb_dir, obj_name)
bpy.ops.object.mode_set(mode = 'OBJECT')
bpy.ops.object.select_all(action='DESELECT')
if os.path.isdir(directory + glb_dir) == False:
os.makedirs(directory + glb_dir)
i = 0
for i in range(len(obj_list)):
name = bpy.data.objects[i].name
bpy.data.objects[name].select_set(True)
obj_locs[i] = (bpy.data.objects[i].location.copy()) # copy locations of objects
bpy.data.objects[i].location = (0,0,0) # move object to world origin
i += 1
bpy.ops.export_scene.gltf(
export_format='GLB',
ui_tab='GENERAL',
export_copyright="Michael Bridges",
export_image_format='AUTO',
export_texture_dir="",
export_texcoords=True,
export_normals=True,
export_draco_mesh_compression_enable=False,
export_draco_mesh_compression_level=6,
export_draco_position_quantization=14,
export_draco_normal_quantization=10,
export_draco_texcoord_quantization=12,
export_draco_generic_quantization=12,
export_tangents=False,
export_materials=True,
export_colors=True,
export_cameras=False,
export_selected=True,
export_extras=False,
export_yup=True,
export_apply=True,
export_animations=True,
export_frame_range=True,
export_frame_step=1,
export_force_sampling=True,
export_nla_strips=True,
export_def_bones=False,
export_current_frame=False,
export_skins=True,
export_all_influences=False,
export_morph=True,
export_morph_normal=True,
export_morph_tangent=False,
export_lights=False,
export_displacement=False,
will_save_settings=True,
filepath=target_file_glb,
check_existing=True,
filter_glob="*.glb;*.gltf")
i = 0
for i in range(len(obj_list)):
bpy.data.objects[i].location = obj_locs[i] # set object back to it's original location
i =+ 1
bpy.ops.object.select_all(action='DESELECT')
return {'FINISHED'}