Blender tip: Remove double, active autosmooth, and smooth shading, in a script
othelarian started this discussion in Help and Tips

Hi everyone,

I'm currently working on my last mecabricks creation in blender, but my computer is not a beast, so I need to lighten the meshes before being able to do something, like selecting in fact. So after some wasted time passed in active autosmooth and remove doubles, I finally came with a very little script to do three things that help a lot:

  1. remove doubles (between 25 and 45 % of the vertices are useless)
  2. active autosmooth
  3. apply smooth shading

So from the collada mecabricks export, without any normals (Normals: None in the export options), you just have to run the script, and it's baked!

NOTE: before running the script you must do one thing in fact in blender: move all the imported model in the last top layer.
NOTE 2 (optional): I used to scale up the model by 100.

|o|o|o|o|o| |o|o|o|o|here|
|o|o|o|o|o| |o|o|o|o|o|

Here the script, have fun 😉

#########################################

import bpy

objs = [ob for ob in bpy.context.scene.objects if ob.layers[9]]

for ob in objs:
ob.select = False
if ob.type == "MESH":
ob.select = True
bpy.context.scene.objects.active = ob
bpy.ops.object.mode_set(mode="EDIT")
bpy.ops.mesh.select_all(action="SELECT")
bpy.ops.mesh.remove_doubles(use_unselected=True)
bpy.ops.object.mode_set(mode="OBJECT")
ob.data.use_auto_smooth = 1

bpy.ops.object.shade_smooth()

EDIT: the indentation is not working, so here a gist: https://gist.github.com/othelarian/43caa3233ba463e6ca975f9117735fb5

0 replies · Page 1 of 1
Advertising
1 participant
Avatar of othelarian

LEGO, the LEGO logo, the Minifigure, and the Brick and Knob configurations are trademarks of the LEGO Group of Companies. ©2024 The LEGO Group.

Mecabricks, the Mecabricks logo and all content not covered by The LEGO Group's copyright is, unless otherwise stated, ©2011-2024 Mecabricks.