Last active
December 10, 2016 15:14
-
-
Save zeffii/f5d683e301a39610f65069c001c49753 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
# inspired by https://openmaya.quora.com/How-to-implement-Voronoi-with-Python-for-Maya | |
import numpy as np | |
import random | |
import math | |
class MBoundingBox: | |
def __init__(self): | |
self.xyz = None | |
def add_all(self, vectors): | |
self.xyz = np.array(vectors) | |
x = self.xyz[:,0] | |
y = self.xyz[:,1] | |
z = self.xyz[:,2] | |
self.width = max(x) - min(x) | |
self.depth = max(y) - min(y) | |
self.height = max(z) - min(z) | |
self.center = ( | |
min(x) + (self.width / 2), | |
min(y) + (self.depth / 2), | |
min(z) + (self.height / 2) | |
) | |
def cmds_polyCube(width, height, depth): return [] | |
def cmds_move(vector): pass | |
def cmds_duplicate(something): return [] | |
def cmds_parent(a, b): pass | |
def cmds_angleBetween(euler, v1, v2): return [] | |
def cmds_polyCut(working_geom, deleteFaces, cutPlaneCenter, cutPlaneRotate): pass | |
def cmds_polyCloseBorder(working_geom): pass | |
def cmds_spaceLocator(): return 0,0,0 # some global locator | |
def voronoi_3d(vps): | |
bb = MBoundingBox() | |
bb.add_all(vps) | |
startCube = cmds_polyCube(width=bb.width*1.2, height=bb.height*1.2, depth=bb.depth*1.2) | |
cmds_move(bb.center) #xyz | |
for from_point in vps: | |
working_geom = cmds_duplicate(startCube[0]) | |
for to_point in vps: | |
if from_point != to_point: | |
locator = cmds_spaceLocator() | |
cmds_move(from_point) | |
cmds_parent(locator, working_geom) | |
center_point = [(e1 + e2) / 2 for (e1, e2) in zip(to_point, from_point)] | |
n = [(e1 - e2) for (e1, e2) in zip(from_point, to_point)] | |
es = cmds_angleBetween(euler=True, v1=[0, 0, 1], v2=n) | |
cmds_polyCut(working_geom, deleteFaces=True, cutPlaneCenter=center_point, cutPlaneRotate=es) | |
cmds_polyCloseBorder(working_geom) | |
cmds_delete(startCube) | |
voronoi_3d() |
I tested in Maya and I can see it's using the Cut Plane operation, Blender's equivalent to Bisect. Maybe good idea to understand the Voronoi algorithm itself.
For me, the Voronoi looks like Bubble, it does this weird cutting based on points and in relation to other points. I think, this script is doing the cut at the middle part.
I think the VPS is supposed to represent some kind of point cloud, yes. Show me a picture or better still, a .blend with the obj data that results from this Maya script, seeing it might help.. and seeing the starting points.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So, the vps is a bunch of random points. What kind of format?
This?
[(x,y,z), (x,y,z)]
Obviously the code above is WIP, because not working right away. But potentially for SN Lite right. I am not 100% familiar with Blender Mesh creation, although maybe knowledge of sverchok helps.