Last active
December 19, 2020 12:01
-
-
Save shspage/f809698433a286e0b461fed07e77b173 to your computer and use it in GitHub Desktop.
いびつな面をなめらかにするテスト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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