Skip to content

Commit

Permalink
update to latest difbuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomityGuy committed Jan 24, 2023
1 parent aec90e0 commit cbcdaae
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion 3rdparty/DifBuilder
2 changes: 1 addition & 1 deletion blender_plugin/io_dif/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"author": "RandomityGuy",
"description": "Dif import and export plugin for blender",
"blender": (2, 80, 0),
"version": (1, 2, 6),
"version": (1, 2, 7),
"location": "File > Import-Export",
"warning": "",
"category": "Import-Export",
Expand Down
34 changes: 19 additions & 15 deletions blender_plugin/io_dif/export_dif.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,41 +347,45 @@ def save_mesh(obj: Object, mesh: Mesh, offset, flip=False, double=False):

nonlocal tris, difbuilder

mesh_triangulate(mesh)
mesh.calc_loop_triangles()
mesh.calc_normals_split()

mesh_verts = mesh.vertices

active_uv_layer = mesh.uv_layers.active.data

for poly in mesh.polygons:
for tri_idx in mesh.loop_triangles:

tri: bpy.types.MeshLoopTriangle = tri_idx

if tris > maxtricount:
tris = 0
builders.append(DifBuilder())
difbuilder = builders[-1]

rawp1 = mesh_verts[poly.vertices[0]].co
rawp2 = mesh_verts[poly.vertices[1]].co
rawp3 = mesh_verts[poly.vertices[2]].co
rawp1 = mesh_verts[tri.vertices[0]].co
rawp2 = mesh_verts[tri.vertices[1]].co
rawp3 = mesh_verts[tri.vertices[2]].co

p1 = [rawp1[i] + offset[i] for i in range(0, 3)]
p2 = [rawp2[i] + offset[i] for i in range(0, 3)]
p3 = [rawp3[i] + offset[i] for i in range(0, 3)]

uv = [
active_uv_layer[l].uv[:]
for l in range(poly.loop_start, poly.loop_start + poly.loop_total)
]
tri.loops[0]
# uv = [
# active_uv_layer[l].uv[:]
# for l in range(poly.loop_start, poly.loop_start + poly.loop_total)
# ]

uv1 = uv[0]
uv2 = uv[1]
uv3 = uv[2]
uv1 = active_uv_layer[tri.loops[0]].uv[:]
uv2 = active_uv_layer[tri.loops[1]].uv[:]
uv3 = active_uv_layer[tri.loops[2]].uv[:]

n = mesh_verts[poly.vertices[0]].normal
n = mesh.loops[tri.loops[0]].normal

material = (
resolve_texture(mesh.materials[poly.material_index])
if poly.material_index != None
resolve_texture(mesh.materials[tri.material_index])
if tri.material_index != None
else "NULL"
)

Expand Down

0 comments on commit cbcdaae

Please sign in to comment.