-
-
Save zeffii/f2b705bf2ea7a2c53aac 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
function gen_verts(r1, r2, num_verts, ramp){ | |
var tv = []; | |
var edges = []; | |
// # verts | |
for (var i=0; i<num_verts; i+=1){ | |
var tamp = i/num_verts * 14 * Math.PI; | |
var theta = i/num_verts * 2 * Math.PI; | |
var x = (Math.sin(theta)*r1) + (Math.sin(tamp) * ramp), | |
y = (Math.cos(theta)*r2) + (Math.cos(tamp) * ramp), | |
z = 0.0; | |
tv.push([x, y, z]) | |
} | |
// # edges | |
for (var i=0; i<(num_verts-1); i+=1){ | |
edges.push([i, i+1]) | |
} | |
edges.push([num_verts-1, 0]) | |
return [tv, edges] | |
} |
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 execjs | |
# https://github.com/doloopwhile/PyExecJS (for python 3.4 too!) | |
class CompiledCall(): | |
def __init__(self, text_name): | |
local_file = bpy.data.texts[text_name].as_string() | |
self.ctx = execjs.compile(local_file) | |
def call(self, r1, r2, nv, ramp): | |
return self.ctx.call("gen_verts", r1, r2, nv, ramp) | |
CC = CompiledCall('daft.js') | |
def sv_main(radius1=0.3, radius2=0.4, num_verts=10, ramp=0.5): | |
verts_out = [] | |
edges_out = [] | |
in_sockets = [ | |
['s', 'radius1', radius1], | |
['s', 'radius2', radius2], | |
['s', 'num_verts', num_verts], | |
['s', 'ramp', ramp] | |
] | |
out_sockets = [ | |
['v', 'verts', [verts_out]], | |
['s', 'edges', [edges_out]], | |
] | |
verts, edges = CC.call(radius1, radius2, num_verts, ramp) | |
verts_out.extend(verts) | |
edges_out.extend(edges) | |
return in_sockets, out_sockets |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment