Created
December 4, 2015 05:15
-
-
Save MetroWind/fc0468fc596e440a9b63 to your computer and use it in GitHub Desktop.
Create a curve in Blender.
This file contains hidden or 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
import bpy | |
import math | |
import numpy | |
from mathutils import Vector | |
w = 1 # weight | |
Scale = 0.03 | |
def readCoords(filename): | |
with open(filename, 'r') as File: | |
Coords = [[float(x) * Scale for x in line.split()] for line in File] | |
return list(map(Vector, Coords)) | |
# ListOfVectors = [Vector((0,0,0)),Vector((1,0,0)),Vector((2,0,0)),Vector((2,3,0)), | |
# Vector((0,2,1))] | |
ListOfVectors = readCoords("/file/name") | |
def genCurveData(fx, fy, fz, u_range, u_count, scale): | |
Data = [] | |
for u in numpy.arange(u_range[0], u_range[1], (u_range[1]- u_range[0]) / float(u_count)): | |
Data.append(Vector((fx(u), fy(u), fz(u)))) | |
return Data | |
def makePolyLine(objname, curvename, cList): | |
curvedata = bpy.data.curves.new(name=curvename, type='CURVE') | |
curvedata.dimensions = '3D' | |
objectdata = bpy.data.objects.new(objname, curvedata) | |
objectdata.location = (0,0,0) #object origin | |
bpy.context.scene.objects.link(objectdata) | |
polyline = curvedata.splines.new('NURBS') | |
for i in range(len(cList)): | |
# bpy.context.scene.frame_set(i+1) | |
if i > 0: | |
polyline.points.add(1) | |
x, y, z = cList[i] | |
polyline.points[i].co = (x, y, z, w) | |
makePolyLine("NameOfMyCurveObject", "NameOfMyCurve", ListOfVectors) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment