-
-
Save zeffii/11388355 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
def sv_main(size=1, divx=1, divy=1, divz=1): | |
# in boilerplate - make your own sockets | |
in_sockets = [ | |
['s', 'Size(float)', size], | |
['s', 'DivisionsX(int)', divx], | |
['s', 'DivisionsY(int)', divy], | |
['s', 'DivisionsZ(int)', divz], | |
] | |
out_sockets = [ | |
['v', 'Ver', []], | |
['s', 'Pol', []], | |
] | |
if 0 in (divx, divy, divz): | |
return in_sockets, out_sockets | |
b = size/2 | |
verts = [(b, b,-b), ( b,-b,-b), (-b,-b,-b), | |
(-b, b,-b), ( b, b, b), ( b,-b, b), | |
(-b,-b, b), (-b, b, b)] | |
faces = [(0, 1, 2, 3), (4, 7, 6, 5), | |
(0, 4, 5, 1), (1, 5, 6, 2), | |
(2, 6, 7, 3), (4, 0, 3, 7)] | |
if (divx, divy, divz) == (1, 1, 1): | |
out_sockets[0][2] = verts | |
out_sockets[1][2] = [faces] | |
return in_sockets, out_sockets | |
# import libraries | |
import bmesh | |
import mathutils | |
from mathutils import Vector | |
import bpy | |
bm = bmesh.new() | |
[bm.verts.new(co) for co in verts] | |
bm.normal_update() | |
for face in faces: | |
bm.faces.new(tuple(bm.verts[i] for i in face)) | |
bm.normal_update() | |
dist = 0.0001 | |
section_dict = {0: divx, 1: divy, 2:divz} | |
for axis in range(3): | |
num_sections = section_dict[axis] | |
if num_sections == 1: | |
continue | |
step = 1/num_sections | |
v1 = Vector(tuple(( b if i==axis else 0) for i in [0,1,2])) | |
v2 = Vector(tuple((-b if i==axis else 0) for i in [0,1,2])) | |
for section in range(num_sections): | |
mid_vec = v1.lerp(v2, section*step) | |
plane_no = v2 - mid_vec | |
plane_co = mid_vec | |
visible_geom = bm.faces[:] + bm.verts[:] + bm.edges[:] | |
bmesh.ops.bisect_plane( | |
bm, geom=visible_geom, dist=dist, | |
plane_co=plane_co, plane_no=plane_no, | |
use_snap_center=False, | |
clear_outer=False, clear_inner=False) | |
indices = lambda face: [v.index for v in face.verts] | |
out = [v.co.to_tuple() for v in bm.verts] | |
pol = [indices(face) for face in bm.faces] | |
print(out, pol) | |
# out boilerplate - set your own sockets packet | |
out_sockets = [ | |
['v', 'Ver', out], | |
['s', 'Pol', [pol]] | |
] | |
return in_sockets, out_sockets |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment