# Blender 3.4.1 # Debian 12 @ tenko # 20251109, résidence polygones @ Fablab des portes logiques # En ligne 65 on peut choisir : fond transparent ou fond monochrome (changement de couleur en ligne 77) import bpy import math # ------------------------------- # Configuration de la scène # ------------------------------- # Supprimer tous les objets existants bpy.ops.wm.read_factory_settings(use_empty=True) # Importer le STL bpy.ops.import_mesh.stl(filepath="teapot.stl") obj = bpy.context.selected_objects[0] # Supprimer tous les matériaux existants obj.data.materials.clear() # ------------------------------- # Matériau blanc pour les faces # ------------------------------- mat = bpy.data.materials.new("FaceWhite") mat.use_nodes = True bsdf = mat.node_tree.nodes["Principled BSDF"] bsdf.inputs['Base Color'].default_value = (1, 1, 1, 1) # blanc bsdf.inputs['Specular'].default_value = 0 obj.data.materials.append(mat) # ------------------------------- # Matériau Wireframe noir # ------------------------------- # Ajouter un modifier wireframe mod = obj.modifiers.new(name="WireframeMod", type='WIREFRAME') mod.thickness = 0.02 mod.use_replace = False # conserve faces originales # Création d’un second matériau pour le wireframe wire_mat = bpy.data.materials.new("WireBlack") wire_mat.use_nodes = True nodes = wire_mat.node_tree.nodes bsdf_wire = nodes.get("Principled BSDF") bsdf_wire.inputs['Base Color'].default_value = (0, 0, 0, 1) # noir bsdf_wire.inputs['Specular'].default_value = 0 obj.data.materials.append(wire_mat) # Associer le modifier wireframe au matériau noir mod.material_offset = 1 # utilise le second matériau # ------------------------------- # Caméra # ------------------------------- cam_data = bpy.data.cameras.new(name="Camera") cam_object = bpy.data.objects.new("Camera", cam_data) bpy.context.collection.objects.link(cam_object) bpy.context.scene.camera = cam_object # Paramètres de rendu scene = bpy.context.scene scene.render.image_settings.file_format = 'PNG' scene.render.resolution_x = 600 scene.render.resolution_y = 600 scene.render.film_transparent = True # False : fond blanc, True : fond transparent scene.render.engine = 'BLENDER_EEVEE' scene.eevee.taa_render_samples = 1 # anti-aliasing minimal # Fond blanc if scene.world is None: world = bpy.data.worlds.new("World") scene.world = world scene.world.use_nodes = True bg = scene.world.node_tree.nodes['Background'] bg.inputs['Color'].default_value = (1, 1, 1, 1) # blanc # ------------------------------- # Paramètres rotation # ------------------------------- center = obj.location n_views = 30 radius = 10 elevation = 5 # ------------------------------- # Générer les images # ------------------------------- for i in range(n_views): angle = 2 * math.pi * i / n_views cam_object.location.x = center.x + radius * math.cos(angle) cam_object.location.y = center.y + radius * math.sin(angle) cam_object.location.z = center.z + elevation # Orienter la caméra vers le centre de l'objet direction = center - cam_object.location rot_quat = direction.to_track_quat('-Z', 'Y') cam_object.rotation_euler = rot_quat.to_euler() # Nom du fichier scene.render.filepath = f"teapot_facewire_{i:02d}.png" # Rendu bpy.ops.render.render(write_still=True)