I’ve imported a model from Lightwave.
I want to use the vertices from this model to make curves.
Is there a way to convert these vertices to curve objects?
Or else a way to snap to vertices??
Or is there no other option than to model the curves from scratch again??
i dont know if this is what your talking about but in the edit buttons panel, click “subsurf”…
It doesnt make the mesh into curves as far as i know… but it smooths out the mesh as though it was made from curves.
I’ve got a lot of point. These are mesh-object points.
I want to make a Bezier curve from these points.
Then i can use this for a bevel object. (BevOb)
You can convert a curve to a mesh… This is the opposite I think…
Or something like use mesh-points in curve…
Here is a quick and dirty script I just wrote that converts vertices to a curve in the order that they’re stored in blender. No GUI, but you can set the weight of all points.
Just copy and paste it into the text editor in blender. Change the settings at the top of the script (enable syntax highlighting for more clarity), select your mesh, press ALT-P.
I’d appreciate it if I could get some feedback.
################### WRITTEN BY BARTIUS CROUCH ###################
#importing modules
import Blender
from Blender import *
############# VARIABLES THAT CAN BE SET BY THE USER #############
weight1 = 0.01 #weight of the first vertice
weight2 = 20 #weight of the last vertice
weight = 1 #weight of the other vertices
# EXTRA OPTIONAL WEIGHT VALUES
# Enter in this list which point you want to have a custom weight
extraweightpoint = [3, 2, ]
# Enter the weight, right underneath the point above
extraweightvalue = [0.2, 0.17 ]
# So currently the weight is distributed like this:
# First point: 0.01
# Point 2: 0.17
# Point 3: 0.2
# Last point: 20
# Other points: 1
#################################################################
#get the selected object
obj = Object.GetSelected()
#check whether something is selected
if obj == []:
#popup
result = Draw.PupMenu("Error%t|No selection")
#print to console
print 'Error: No selection'
#check whether the selecte object is a mesh
elif obj[0].getType() != "Mesh":
#popup
result = Draw.PupMenu("Error%t|Selected object is not a mesh")
#print to console
print 'Error: Selected object is not a mesh'
#run the script on the selected mesh object
else:
#getting the mesh that has to be converted
mesh = NMesh.GetRaw(obj[0].getName())
#creating empty lists for the coordinates
meshlistx = []
meshlisty = []
meshlistz = []
for v in mesh.verts:
#append the vertex locations to the right list
meshlistx.append(v.co[0])
meshlisty.append(v.co[1])
meshlistz.append(v.co[2])
### CREATE THE POINTS OF THE CURVE
#creating new curve data
c = Curve.New()
#creating a counter object
counter = -1
for b in mesh.verts:
#add a round to the counter
counter += 1
#create a new list for the new point in the curve
meshlist = []
#append the coordinates of the new point to the list
meshlist.append(meshlistx[counter])
meshlist.append(meshlisty[counter])
meshlist.append(meshlistz[counter])
#append the weight of the new point to the list
#check if user specified a custom weight for this point
if (counter+1) in extraweightpoint:
#user did indeed specify a custom weight
count = 0
for bla in extraweightpoint:
test = extraweightpoint[count]
if test == (counter+1):
meshlist.append(extraweightvalue[count])
count += 1
#check if it is the first point
elif (counter == 0):
#set the right weight
meshlist.append(weight1)
#append normal weight, since there is no custom setting
elif ( len(mesh.verts) != (counter+1) ):
#not the last point
meshlist.append(weight)
else:
#the last point
meshlist.append(weight2)
#####add the point to the curve
print(meshlist)
if (counter==0):
#it is the first point
c.appendNurb(meshlist)
else:
#it is another point
c[-1].append(meshlist)
#get the current scene
currentscene = Scene.getCurrent()
#create the new curve object
ob = Object.New('Curve')
#link the curve data 'c' to the new curve object
ob.link(c)
#link the curve object to the current scene
currentscene.link(ob)
#get the rotation of the original object
orirot = Object.Get(obj[0].getName()).rot
#get the position of the original object
oriloc = Object.Get(obj[0].getName()).loc
#get the size of the original object
orisiz = Object.Get(obj[0].getName()).size
#set the rotation of the new curve
ob.rot = orirot
#set the position of the new curve
ob.setLocation(oriloc)
#set the size of the new curve
ob.setSize(orisiz)
Blender.Redraw()
As far as I know it is impossible to set the 3D button by use of a python script (at least I can’t find it in the blender pythondocs).
However when I run the script on whatever mesh it will create a correct curve, even though the 3D button isn’t pressed. The only thing that’s missing is that when you’re going into edit-mode you can’t see the tilt of the curve. For that you can press the 3D button yourself.
Over here you can see an example where this indeed works. Could you please give me an example file of the mesh that doesn’t work?
I know 3D meshes get a bit messy. The problem is that it adds points in the order that they are stored in the mesh. Instead it should add them by first finding a starting point (a vertex that is connected to only one other vertex) and then use the edges to define the order of the points to add.
I’m still looking at a way to do this though. I’ll get back to you, once I find a solution (or when I can’t solve it).
The problem in your file is indeed the order in which the vertices are stored. I’ll try to develop a method that solves the problem, but I can’t promise anything. You’ll hear back from me.
When correcting it I ran into 2 errors. The first is that the script thinks the mesh is a Nonetype object. The second is that it links the points in the wrong order (just try to run the script again on the mesh in the file above and you’ll see the second problem).
The first problem doesn’t always occur and can be solved by joining your mesh to a cube, going into edit-mode and removing the vertices of the cube. Of course this is just a work-around and I’ll try to correct it in the script.
The second problem can be solved by deleting the segments and reconnecting the points. For low poly models this isn’t too much work, but it’s of course unacceptable for larger models. This will be difficult to correct in the script though. I think it’s possible, but if it’s possible it will take quite some time. Please bear with me.
Any suggestions on solving the problems as well as other comments/crits/questions are very welcome.
I am not sure what the first error you are talking about is but easy enough to workaround.
For the second error, if my spiral were much longer, could i have laid it on its side and used the xsort edit feature to re-arrange the verts automatically? The answer is yes, i tried it and it worked perfectly for this string of verts!
I hadn’t even thought about the xsort method, which is of course THE solution for springs and so on. Unfortunately it won’t solve the problems for all meshes.
Anyway, I’m glad I could be of help.
not all my meshes are fine, but with the xsort but now i have the base-points to make new segments…
First i run the script, this is the messy part.
then i delete segments that are not correct.
At the end i make new segments at the place where they should be…