-
Notifications
You must be signed in to change notification settings - Fork 1
/
3d_objs_to_files.py
69 lines (41 loc) · 1.31 KB
/
3d_objs_to_files.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
import bpy
import os
import bmesh
desFolder = "./3dModels/"
prefix = ''
fileWPath = bpy.context.blend_data.filepath
file = os.path.basename(fileWPath)
file = file.split(".")[0]
print("file: [%s]"%file)
prefix+= file+"_3dex"
bpy.ops.object.select_all(action='DESELECT')
s = bpy.context.scene
print("--------")
print(s)
print("prefix: [%s]"%prefix)
ff = open(desFolder+prefix+"_files.list", "w")
fo = open(desFolder+prefix+"_objNames.list", "w")
for o in s.objects:
for oo in s.objects:
oName = o.name
s.objects.active = oo
oo.select = False
oName = o.name
print("obj [%s]"%o.name)
targetName=prefix+"_"+oName
s.objects.active = o
o.select = True
if o.type == "MESH":
print("triangulating [%s].... "%oName)
trian = bmesh.new()
trian.from_mesh(o.data)
bmesh.ops.triangulate( trian, faces=trian.faces[:], quad_method=0, ngon_method=0 )
trian.to_mesh(o.data)
trian.free()
print("mesh ready to export...")
bpy.ops.export_scene.obj( filepath=desFolder+targetName+".obj", use_selection=True )
ff.write(desFolder+targetName+"\n")
fo.write(desFolder+oName+"\n")
print("error with obj[%s]"%oName)
ff.close()
fo.close()