Last active
February 9, 2017 16:27
-
-
Save zeffii/71c969a5d3a8b9f339686a280e7dd789 to your computer and use it in GitHub Desktop.
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
from math import radians | |
import bmesh | |
from mathutils import Matrix | |
from svrx.util.geom import generator | |
from svrx.util.mesh import rxdata_from_bm | |
def make_torus(maj_segs, min_segs, maj_rad, min_rad, phase): | |
matrix_rotate = Matrix.Rotation(radians(90.0), 3, 'Y') | |
matrix_phase = Matrix.Rotation(radians(phase), 3, 'Z') | |
axis = (0,0,1) | |
dvec = cent = (0,0,0) | |
angle = radians(360) | |
bm = bmesh.new() | |
bmesh.ops.create_circle(bm, cap_ends=False, diameter=min_rad*2, segments=min_segs) | |
bmesh.ops.rotate(bm, cent=cent, matrix=matrix_phase, verts=bm.verts[:]) | |
bmesh.ops.rotate(bm, cent=cent, matrix=matrix_rotate, verts=bm.verts[:]) | |
bmesh.ops.translate(bm, vec=(0,maj_rad,0), verts=bm.verts[:]) | |
bmesh.ops.spin( | |
bm, geom=bm.verts[:]+bm.edges[:], | |
cent=cent, axis=axis, dvec=dvec, angle=radians(360), | |
steps=maj_segs, use_duplicate=0 | |
) | |
bmesh.ops.remove_doubles(bm, verts=bm.verts[:], dist=0.0001) | |
return rxdata_from_bm(bm) | |
@node_script | |
@generator | |
def sn_make_torus( | |
maj_segs: Int = 10, | |
min_segs: Int = 6, | |
maj_rad: Float = 1.0, | |
min_rad: Float = 0.2, | |
phase: Float = 90.0 | |
) -> ([Vertices], [Edges], [Faces]): | |
return make_torus(maj_segs, min_segs, maj_rad, min_rad, phase) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment