0
0

More than 1 year has passed since last update.

Blenderの「辺ループのブリッジ」

Posted at

概要

Blenderの「辺ループのブリッジ」を紹介します。
2つの面を選んで辺ループのブリッジをすると、面をブリッジすることができます。
下図は、2つの球の面をランダムに選んでブリッジを作成したものです。30回繰り返しています。

Pythonで実行

下記では、bpy.ops.mesh.bridge_edge_loops(number_cuts=20)で辺ループのブリッジをしています。number_cutsはブリッジの分割数です。最後にスムーズとサブディビジョンサーフェスをかけて紐っぽくしています。面の向きによっては内側を通るので穴が空いたようになります。

import numpy as np
import bmesh
import bpy
import random

def center(face):
    return tuple(np.round(face.calc_center_median(), 4))

bpy.ops.object.mode_set(mode="OBJECT")
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(use_global=False)
bpy.ops.outliner.orphans_purge(do_recursive=True)

bpy.ops.mesh.primitive_uv_sphere_add()
bpy.ops.mesh.primitive_uv_sphere_add(location=(4, 0, 0))
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.join()
bpy.ops.object.transform_apply(location=True)
obj = bpy.context.object

st1, st2 = set(), set()

for _ in range(30):
    bpy.ops.object.mode_set(mode="OBJECT")
    bpy.ops.object.mode_set(mode="EDIT")
    bpy.ops.mesh.select_mode(type='FACE')
    bpy.ops.mesh.select_all(action="DESELECT")
    bm = bmesh.from_edit_mesh(obj.data)
    bm.faces.ensure_lookup_table()

    if not st1:
        for face in bm.faces:
            p = center(face)
            if abs(p[2]) < 0.8:
                if p[0] < 2:
                    st1.add(p)
                else:
                    st2.add(p)

    for st in [st1, st2]:
        while True:
            f = random.choice(bm.faces)
            p = center(f)
            if p in st:
                st.remove(p)
                f.select_set(True)
                break
    bpy.ops.mesh.bridge_edge_loops(number_cuts=20)
    bm.free()

bpy.ops.object.mode_set(mode="OBJECT")
bpy.ops.object.shade_smooth(use_auto_smooth=True)
bpy.ops.object.modifier_add(type='SUBSURF')
bpy.context.object.modifiers["Subdivision"].levels = 2

以上

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0