From 6940428b88bb1b8709b83bd078e3fd6c1d4cf274 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Wed, 17 Jul 2024 19:45:35 +0800 Subject: [PATCH] fix: fix blender 4.2 mesh issue. - fix issue that blender 4.2 lost use_auto_smooth and calc_split_normals. (it almost works but not perfect. still need more debugging) - remove depracted material blend_mode. use modern one instead. (the modern setting make me consufes but it works) --- bbp_ng/OP_ADDS_rail.py | 2 -- bbp_ng/PROP_virtools_material.py | 9 ++++++++- bbp_ng/UTIL_blender_mesh.py | 14 ++++---------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/bbp_ng/OP_ADDS_rail.py b/bbp_ng/OP_ADDS_rail.py index ce090ec..e163ed1 100644 --- a/bbp_ng/OP_ADDS_rail.py +++ b/bbp_ng/OP_ADDS_rail.py @@ -537,8 +537,6 @@ def _rail_creator_wrapper(fct_poly_cret: typing.Callable[[bmesh.types.BMesh], No bm.free() # setup smooth for mesh - mesh.use_auto_smooth = True - mesh.auto_smooth_angle = math.radians(50) mesh.shade_smooth() # create object and assoc with it diff --git a/bbp_ng/PROP_virtools_material.py b/bbp_ng/PROP_virtools_material.py index efd445a..c73e015 100644 --- a/bbp_ng/PROP_virtools_material.py +++ b/bbp_ng/PROP_virtools_material.py @@ -403,7 +403,14 @@ def apply_to_blender_material(mtl: bpy.types.Material): # set some alpha data mtl.use_backface_culling = not rawdata.mEnableTwoSided - mtl.blend_method = 'BLEND' if rawdata.mEnableAlphaBlend else 'OPAQUE' + if rawdata.mEnableAlphaBlend: + # In old format: mtl.blend_method = 'BLEND' + mtl.surface_render_method = 'BLENDED' + mtl.use_raytrace_refraction = True + else: + # In old format: mtl.blend_method = 'OPAQUE' + mtl.surface_render_method = 'DITHERED' + mtl.use_raytrace_refraction = False # set texture if rawdata.mTexture is not None: diff --git a/bbp_ng/UTIL_blender_mesh.py b/bbp_ng/UTIL_blender_mesh.py index 04ba23c..f67277a 100644 --- a/bbp_ng/UTIL_blender_mesh.py +++ b/bbp_ng/UTIL_blender_mesh.py @@ -157,7 +157,6 @@ class MeshReader(): # triangulate temp mesh if self.is_valid(): self.__triangulate_mesh() - self.__mAssocMesh.calc_normals_split() def is_valid(self) -> bool: return self.__mAssocMesh is not None @@ -171,7 +170,6 @@ class MeshReader(): def dispose(self) -> None: if self.is_valid(): # reset mesh - self.__mAssocMesh.free_normals_split() self.__mAssocMesh = None def get_vertex_position_count(self) -> int: @@ -203,10 +201,10 @@ class MeshReader(): raise UTIL_functions.BBPException('try to call an invalid MeshReader.') cache: UTIL_virtools_types.VxVector3 = UTIL_virtools_types.VxVector3() - for nml in self.__mAssocMesh.loops: - cache.x = nml.normal.x - cache.y = nml.normal.y - cache.z = nml.normal.z + for nml in self.__mAssocMesh.corner_normals: + cache.x = nml.vector.x + cache.y = nml.vector.y + cache.z = nml.vector.z yield cache def get_vertex_uv_count(self) -> int: @@ -446,8 +444,6 @@ class MeshWriter(): self.__mAssocMesh.polygons.add(len(self.__mFaceVertexCount)) # create uv layer self.__mAssocMesh.uv_layers.new(do_init = False) - # split normals, it is IMPORTANT - self.__mAssocMesh.create_normals_split() # add vertex position data self.__mAssocMesh.vertices.foreach_set('co', self.__mVertexPos) @@ -500,8 +496,6 @@ class MeshWriter(): self.__mAssocMesh.normals_split_custom_set( tuple(_nest_custom_split_normal(loops_normals)) ) - # enable auto smooth. it is IMPORTANT - self.__mAssocMesh.use_auto_smooth = True def __clear_mesh(self): if not self.is_valid():