Skip to content

Instantly share code, notes, and snippets.

@shspage
Last active December 19, 2020 12:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shspage/f809698433a286e0b461fed07e77b173 to your computer and use it in GitHub Desktop.
Save shspage/f809698433a286e0b461fed07e77b173 to your computer and use it in GitHub Desktop.
いびつな面をなめらかにするテスト
import bpy
import numpy as np
from scipy.interpolate import Rbf
def getGridEdgeIndices(polys):
"""Gets the index of the vertices on the outer edge"""
idxs = []
for poly in polys:
idxs.extend([x for x in poly.vertices])
idxs, counts = np.unique(idxs, return_counts=1)
return idxs[counts < 4]
def func():
bpy.ops.object.mode_set(mode='OBJECT')
obj = bpy.data.objects['Grid']
vs = obj.data.vertices
xi = np.array([v.co.x for v in vs])
yi = np.array([v.co.y for v in vs])
zi = np.array([v.co.z for v in vs])
rbfi = Rbf(xi, yi, zi,
function = 'linear', smooth=1)
zs = rbfi(xi, yi)
edge_idxs = getGridEdgeIndices(obj.data.polygons)
for v,z in zip(vs, zs):
if v.index not in edge_idxs:
v.co.z = z
func()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment