Question about Noise.voronoi()

I was trying some months ago to obtain a voronoi 3D from an initial set of points by using externally the qvoronoi program but i haven’t seen that the noise module already have the voronoi function.:o

So now i’m thinking about scripting a voronoi 3D from a list of vertex but i don’t really know how to do that. And does this function already sorts the list of vertex (the second printed, right??) in order to be used as new mesh vertex? or maybe it takes some aditional things to proceed?

Does anybody already have worked on that stuff? It would be really helpful for me. Because i have already looked into the A.N.T landscape generator for its use of the voronoi() but i can’t really see the point.

I will try to illustrate my misunderstanding:

I tried (with a little modified script from the original done by jms about exporting and reading raw files: see:http://jmsoler.free.fr/didacticiel/blender/tutor/cpl_pythonraw2mesh.htm#lire_raw )

to take mesh vertex data and add the Noise.voronoi() to each vertex, and finally write the points it returns in a raw file. Then i read this file to print a new mesh which is supposed to be a voronoi of the initial mesh…results are a bit weird:(:(:(… And of course it is still a points cloud because i haven’t already written how to link vertex to make faces…

here the script:


import Blender

from Blender import NMesh, Noise, Object

objmesh = Object.GetSelected()[0]

rawfile = open("file.raw","w")

mesh = NMesh.GetRaw(objmesh.name)

for v in mesh.verts:
    
    vor = Noise.voronoi((v.co[0],v.co[1],v.co[2])) 
    vorpoints = vor[1]
    
    for points in vorpoints:
        
        rawfile.write('%s %s %s
' % (points[0],points[1],points[2]))   

rawfile.close()

objmeshnew = str(raw_input("Name of the object mesh:"))

rawfile = open("file.raw","r")
tabraw = rawfile.readlines()
rawfile.close()

meshnew = NMesh.GetRaw()

for line in tabraw:
    
    line = line.replace('
','')
    l = line.split(' ')
    
    x = float(l[0])
    y = float(l[1])
    z = float(l[2])
    
    v = NMesh.Vert(x,y,z)
    meshnew.verts.append(v)

NMesh.PutRaw(meshnew,objmeshnew)

Hum…Sorry, things would be clearer with a simple script. I was testing in the same time the writing and reading of a raw file but this is not really the problem. For now, it is about obtaining a 3D voronoi diagram from a selected mesh.
here is the code and its weird results:


import Blender

from Blender import NMesh, Noise, Object

objmesh = Object.GetSelected()[0]

mesh = NMesh.GetRaw(objmesh.name)
meshnew = NMesh.GetRaw()

for v in mesh.verts:
    
    vor = Noise.voronoi((v.co[0],v.co[1],v.co[2])) 
    vorpoints = vor[1]
    for points in vorpoints:
        v = NMesh.Vert(points[0],points[1],points[2])
        meshnew.verts.append(v)
   

objmeshnew = str(raw_input("Name of the object mesh:"))
NMesh.PutRaw(meshnew,objmeshnew)

in this example, you have to type the name of the new mesh in the console (you can skip that by giving directly a name in the code for objmeshnew variable)

Sorry for refreshing this thread but this question is really haunting me!
How does Noise.voronoi() work exactly and how to use it in order to obtain a 3D voronoi diagram from an initial set of points?:confused:

Nobody knows?

The voranoi noise function basically works the way the voronoi texture works in the blender interface. You can’t set an initial set of points, it generates points based on the parameters and then the function returns the distances to those points from the point you pass into the function. It would be great if this could be expanded to let you define an initial point set, but thats not how it currently works.

bydesign