|
14 | 14 | script_file = sys.argv[4] |
15 | 15 | out_file_path = sys.argv[5] |
16 | 16 | decimals = int([e for e in sys.argv if e.startswith('--decimals=')][0][len('--decimals='):]) |
| 17 | +TRIANGULATE = '--triangulate' in sys.argv |
| 18 | + |
| 19 | + |
| 20 | +print('-----------------------', 'decimals:', decimals, 'triangulate:', TRIANGULATE) |
17 | 21 |
|
18 | 22 | scene_name = Path(bpy.data.filepath).stem |
19 | 23 | print('file_name:', scene_name) |
|
46 | 50 |
|
47 | 51 |
|
48 | 52 | for key, ob in unique_objects.items(): |
49 | | - mesh = ob.evaluated_get(dg).data |
50 | | - |
51 | | - # triangulate mesh |
52 | | - bm = bmesh.new() |
53 | | - bm.from_mesh(mesh) |
54 | | - bmesh.ops.triangulate(bm, faces=bm.faces[:], quad_method='BEAUTY', ngon_method='BEAUTY') |
55 | | - bm.normal_update() |
56 | | - bm.to_mesh(mesh) |
57 | | - bm.free() |
58 | | - |
| 53 | + polygons =[] |
59 | 54 | verts = [] |
60 | 55 | normals = [] |
61 | 56 | vertex_colors = [] |
62 | 57 | uvs = [] |
63 | | - |
64 | 58 | indices = [] |
65 | 59 |
|
| 60 | + mesh = ob.evaluated_get(dg).data |
| 61 | + # for poly in mesh.polygons: |
| 62 | + # print('---------------poly:', [int(e) for e in poly.vertices]) |
| 63 | + if TRIANGULATE: |
| 64 | + # triangulate mesh |
| 65 | + bm = bmesh.new() |
| 66 | + bm.from_mesh(mesh) |
| 67 | + bmesh.ops.triangulate(bm, faces=bm.faces[:], quad_method='BEAUTY', ngon_method='BEAUTY') |
| 68 | + bm.normal_update() |
| 69 | + bm.to_mesh(mesh) |
| 70 | + bm.free() |
| 71 | + else: |
| 72 | + for poly in mesh.polygons: |
| 73 | + # print('---------------poly:', [int(e) for e in poly.vertices]) |
| 74 | + polygons.append([int(e) for e in poly.vertices]) |
| 75 | + |
| 76 | + |
66 | 77 | for poly in mesh.polygons: |
67 | 78 | indices.extend(poly.vertices) |
68 | 79 |
|
69 | | - for idx in indices: |
70 | | - v = mesh.vertices[idx] |
71 | | - verts.append((round(v.co[0],decimals),round(v.co[2],decimals),round(v.co[1],decimals))) |
72 | | - |
| 80 | + if TRIANGULATE: |
| 81 | + for idx in indices: |
| 82 | + v = mesh.vertices[idx] |
| 83 | + verts.append((round(v.co[0],decimals),round(v.co[2],decimals),round(v.co[1],decimals))) |
| 84 | + else: |
| 85 | + verts = [(round(v.co[0],decimals),round(v.co[2],decimals),round(v.co[1],decimals)) for v in mesh.vertices] |
73 | 86 |
|
74 | 87 | if '--vertex_colors' in sys.argv and 'Color' in mesh.attributes: |
75 | 88 | color_data = mesh.attributes['Color'].data |
|
104 | 117 | code += f''' |
105 | 118 | '{mesh.name}' : Mesh( |
106 | 119 | vertices={str(verts).replace(' ', '')}, |
| 120 | + triangles={polygons}, |
107 | 121 | normals={str(normals).replace(' ', '')}, |
108 | 122 | colors={str(vertex_colors).replace(' ', '')}, |
109 | 123 | uvs={str(uvs).replace(' ', '')}, |
|
0 commit comments