Skip to content

Instantly share code, notes, and snippets.

@zeffii
Forked from anonymous/daft.js
Last active August 29, 2015 14:15
Show Gist options
  • Save zeffii/58d2c170bb0dc49bd9b9 to your computer and use it in GitHub Desktop.
Save zeffii/58d2c170bb0dc49bd9b9 to your computer and use it in GitHub Desktop.
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 = Math.sin(theta*3) * 7.2;
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]
}
import bpy
import execjs
def recall(r1, r2, nv, ramp):
local_file = bpy.data.texts['daft.js'].as_string()
ctx = execjs.compile(local_file)
v, e = ctx.call("gen_verts", r1, r2, nv, ramp)
return v, e
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]],
]
js_out = recall(radius1, radius2, num_verts, ramp)
verts_out.extend(js_out[0])
edges_out.extend(js_out[1])
return in_sockets, out_sockets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment