Last active
November 10, 2020 22:51
-
-
Save shspage/bb64228e8ddde06f21577b3fdfbbb1a7 to your computer and use it in GitHub Desktop.
カーブ生成 + 渦巻き (blender 2.82a)
This file contains 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 math | |
# カーブ生成 + 渦巻き (blender 2.82a) | |
# (渦巻きは曲線上の点をプロットしたもので、NURBSのポイントとして適切かは考慮していません。) | |
def createPolyline(coords, obj_name, closed=False): | |
# ref: https://blender.stackexchange.com/questions/120074/how-to-make-a-curve-path-from-scratch-given-a-list-of-x-y-z-points | |
cv = bpy.data.curves.new('cv', 'CURVE') | |
cv.dimensions = '3D' | |
spline = cv.splines.new(type='NURBS') # 'POLY', 'BEZIER', 'BSPLINE', 'CARDINAL', 'NURBS' | |
spline.points.add(len(coords) - 1) | |
spline.use_cyclic_u = closed | |
for p, co in zip(spline.points, coords): | |
p.co = co + [1.0] | |
obj = bpy.data.objects.new(obj_name, cv) | |
bpy.context.scene.collection.objects.link(obj) | |
return obj | |
def uzumaki1(): | |
# 渦巻き。点がだいたい等間隔になる描き方 | |
coords = [] | |
r = t = 0.0 | |
y = 2.0 | |
m = 1.0 | |
for i in range(100): | |
coords.append([math.cos(t) * r, math.sin(t) * r, 0]) | |
t += math.atan2(y, r) * m | |
r += y / t * m | |
return createPolyline(coords, "uzumaki1") | |
def uzumaki2(): | |
# 渦巻き。オーソドックスな数式による描き方 | |
coords = [] | |
t = 0.0 | |
t_incr = 0.2 | |
for i in range(100): | |
coords.append([math.cos(t) * t, math.sin(t) * t, 0]) | |
t += t_incr | |
return createPolyline(coords, "uzumaki2") | |
uzu = uzumaki1() | |
#uzu = uzumaki2() | |
uzu.data.bevel_depth = 1.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment