I think major waste of time is object adding (to tree).
I will have a look at curveWB, perhaps i can find the place where Chris_G does the magic.
@Chris_G, can we please have a hint from Premier LeagueChris_G wrote:ping
Moderator: bernd
@Chris_G, can we please have a hint from Premier LeagueChris_G wrote:ping
Hi,
Code: Select all
import FreeCAD
from FreeCAD import Vector
import Part
from pivy import coin
NUM = 10
# create a sample curve
poles0 = [Vector (-2.207077980041504, -0.4698541462421417, 0.0), Vector (-1.3755598068237305, 1.137541651725769, 0.0), Vector (0.10200775414705276, 1.2364583015441895, 0.0), Vector (1.397197961807251, -0.0834609717130661, 0.0)]
weights0 = [1.0, 1.0, 1.0, 1.0]
knots0 = [0.0, 1.0]
mults0 = [4L, 4L]
periodic0 = False
degree0 = 3
rational0 = False
bs0 = Part.BSplineCurve()
bs0.buildFromPolesMultsKnots(poles0, mults0, knots0, periodic0, degree0)
obj0 = FreeCAD.ActiveDocument.addObject("Part::Spline","BSplineCurve0")
edge = bs0.toShape()
obj0.Shape = edge
# compute sample points
parameters = [float(i)/NUM for i in range(NUM+1)]
poc = [edge.valueAt(p) for p in parameters] # poc = points on curve
nor = [edge.valueAt(p)+edge.normalAt(p) for p in parameters] # nor = normals
# here is the coin stuff
coinVec = list()
indexes = list()
for i in range(NUM+1):
coinVec.append(coin.SbVec3f(poc[i].x,poc[i].y,poc[i].z))
coinVec.append(coin.SbVec3f(nor[i].x,nor[i].y,nor[i].z))
indexes.extend([i*2,1+i*2,-1])
# indexes = [0, 1, -1, 2, 3, -1, 4, 5, -1, 6, 7, -1, 8, 9, -1, 10, 11, -1, 12, 13, -1, 14, 15, -1, 16, 17, -1, 18, 19, -1, 20, 21, -1]
# the -1 index value is a break in the polyline
node = coin.SoSeparator()
pts = coin.SoCoordinate3()
lineset = coin.SoIndexedLineSet()
node.addChild(pts)
node.addChild(lineset)
pts.point.setValues(0,len(coinVec),coinVec)
lineset.coordIndex.setValues(0,len(indexes),indexes)
sg = FreeCADGui.ActiveDocument.ActiveView.getSceneGraph()
sg.addChild(node)
#sg.removeChild(node)
Now it's a little bit faster.