Skip to content

Commit

Permalink
Further work on the import mesh building.
Browse files Browse the repository at this point in the history
Updated the normal setting to use:me.normals_split_custom_set_from_vertices(normals)

moved the smoothing code into the mesh building.

per this conversation:  X-Plane#714
  • Loading branch information
imc committed Oct 23, 2022
1 parent 5698fc4 commit 88f0eef
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
21 changes: 14 additions & 7 deletions io_xplane2blender/importer/xplane_imp_cmd_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,10 @@ def chunk(it, size):
]

me = bpy.data.meshes.new(self.name)
# check if the smoothing operation is requested in the scene properties
if bpy.context.scene.xplane.smooth:
me.use_auto_smooth = True

me.from_pydata(py_vertices, [], py_faces)

if me.validate(verbose=True):
Expand All @@ -401,19 +405,22 @@ def chunk(it, size):
for mesh_uv_loop, mesh_loop in zip(me.uv_layers[-1].data, me.loops):
mesh_uv_loop.uv = uvs[mesh_loop.vertex_index]

try:
# try:
# IMC for Blender 3+ this needs to use the new vertex_normals collection
# as the vertex.normal property became readonly
for i, vertex_normal in enumerate(me.vertex_normals):
vertex_normal = normals[i]
except:
# for i, vertex_normal in enumerate(me.vertex_normals):
# vertex_normal = normals[i]
# except:
# if we can't find vertex_normals, try it the old way
for i, vertex in enumerate(me.vertices):
vertex.normal = normals[i]
# for i, vertex in enumerate(me.vertices):
# vertex.normal = normals[i]

# me.calc_normals()

me.calc_normals()
me.update(calc_edges=True)

me.normals_split_custom_set_from_vertices(normals)

# merge the nearby duplicate vertices
self.merge_verts(me)

Expand Down
6 changes: 3 additions & 3 deletions io_xplane2blender/tests/test_creation_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,10 @@ def create_object(name, mesh):
ob = bpy.data.objects.new(name, object_data=mesh)

# check if the smoothing operation is requested in the scene properties
if bpy.context.scene.xplane.smooth:
#if bpy.context.scene.xplane.smooth:
# set the mesh faces to smooth by default
for face in ob.data.polygons:
face.use_smooth = True
# for face in ob.data.polygons:
# face.use_smooth = True

return ob

Expand Down

0 comments on commit 88f0eef

Please sign in to comment.