Ha, yes. I have made a similar script as well. And it is Not perfect. I need to at Least have it add the weighted normal as well. And I’d probably want to fix it up to actually ask the user about the smooth angle and merge threshold as well. And I think I’ll want it to work on only selected objects as well, in case you import just some new pieces or something. But this may help someone:
import bpy, bmesh
from math import radians
SmoothAngle = 45
MergeThreshold = .0001
# I don't think this is needed so commenting out. selection = bpy.context.selected_objects
ctx = bpy.context.copy() #created context override variable. copies the context
smooth_radians = radians(SmoothAngle) #blender uses radians. So just converts the SmoothAngle to radians for the smooth angle number.
for ob in bpy.context.scene.objects:
if not isinstance(ob.data, bpy.types.Mesh): #this is a python function, not blender specific. If it's not mesh, return false, so continue.
continue #this actually means if it isn't Mesh, continue to the next object without processing what's next in the for loop
# create a context override so you don't need to handle selecting/deselecting objects to make the operators work correctly
ctx['object'] = ob
ctx['active_object'] = ob
ctx['selected_objects'] = [ob]
ctx['selected_editable_objects'] = [ob]
bpy.ops.object.shade_smooth(ctx)
ob.data.use_auto_smooth = True
ob.data.auto_smooth_angle = smooth_radians
bm = bmesh.new()
bm.from_mesh(ob.data)
bmesh.ops.remove_doubles(bm, verts=bm.verts, dist=MergeThreshold)
bm.to_mesh(ob.data)
bm.free()
It has a few catches to not work on some other stuff, and I left a bunch of notes there, for myself because I’m new to that sort of thing. The first time I did it, I was trying to do it more like user based scripts. So it was just walking through exactly how you would do it all by hand. On 17000 pieces, blender did Not like it. lol
And you’re right. It could be Much better. The custom split normals don’t translate correctly. On a plain old fillet, not even next to a compound curve, you Clearly see a harsh seam before you rebuild normals. And that only works well if you also use weighted normals. It Can be “fixed up a bit” but each part would have to be fixed manually. And sometimes that also means either you have to use more mesh than you want, or manually create some loop cuts. And you can’t really just add loop cuts, because the mesh is Not ideal for polygon modeling. And don’t try and tell me that I should use the WIP quad remesh, because it has very limited uses where it gives you what you need.
Unfortunately, not everyone uses this sort of thing enough to justify the cost of datasmith. Although, Unreal has it built in with the design version, and That cost is low. I haven’t looked to see if you can import things to Unreal using that, then export that out cleanly to blender. It’s a bit of extra work and time, but if it’s nice and clean normals, then it may be a good low cost solution. Although, we were using Unreal just to look at models in VR. And now that blender has some of that limited functionality built in, it’s Much faster of a workflow. We had to optimize things a bit to get advanced materials working ok in Unreal on a GTX 2070 (and making advanced materials also took some time and the learning curve for Unreal is a bit steeper than blender I think.