Closed LyndonAlcock closed 8 months ago
Hey, I'd look at what comes in from a DXF file as that is the only format that supports B-splines currently:
In [1]: p = trimesh.load('models/2D/spline.DXF')
DEBUG load.py:69 loaded <trimesh.Path2D(vertices.shape=(34, 2), len(entities)=10)> in 0.0065s
In [3]: p.entities[4]
Out[3]: <trimesh.path.entities.BSpline at 0x7fcd57f8aec0>
In [4]: p.entities[4].knots
Out[4]: array([0., 0., 0., 1., 1., 1.])
In [5]: p.entities[4].points
Out[5]: array([18, 29, 21])
I have never had any luck manually defining knot vectors, but your mileage may vary haha. This runs and fixes the data type errors (knots are a flat vector). It is kind of suspicious, knots probably need to be normalized to 0.0-1.0, why are they not increasing in order, etc:
p = trimesh.path.Path2D(
entities=[trimesh.path.entities.BSpline(
points=[0,1],knots=[38.0, 38.0, 25.0, 25.0],closed=False)],
vertices=[(0.0, 30.0), (52.0, 0.0)])
Hello, just an update, it turns out this:
In [4]: p.entities[4].knots
Out[4]: array([0., 0., 0., 1., 1., 1.])
is the output of when you ask for knots = curve.KnotSequence
in FreeCAD however, i am unsure what this means in relation to the knot weights as this does not change with the varying knot weights, but i believe that the problem goes a lot deeper than I expected as varying the knot weights in FreeCAD does not change the 3D geometry on my laptop,
long story short, I've kinda got it to work but I am practically treating the BSplines as Bezier Curves but I am behind on my dissertation so this will have to do :expressionless: I have managed to get the format transfer to work with this code:
if curve.TypeId == 'Part::GeomBSplineCurve':
knots = curve.KnotSequence
print(knots)
points = [pole[0:2] for pole in curve.getPoles()]
closed = len(edge.Vertexes) == 1
for point in points:
if index_dict.get(point,None) is None:
index_dict[point] = current_index
vertices.append(point)
current_index+=1
entities.append(BSpline(
points=[index_dict[point] for point in points],
knots=knots,
closed=closed
))
Context
I am currently writing a function that is intended to take faces of a shape in freeCAD and convert it into a 2D path in trimesh so that i can obtain its medial axis tranform (MAT) , i will include the code in the appendix of this issue for completion however i have developed a minimal reproducible example for clarity:
Minimum Reproducible Example
I am using Python311 and all librarys are installed correctly I am trying to create a quadratic bspline with a single knot as follows:
When i try to do
p2d.show()
it throws this error:Stepping through the code I can see that it executes something analagous to the following :
So in this specific example the degree is -2 instead of 2, which feels like it is incorrect but i cant tell what would be correct formatting of this code
thanks for any help :) From Lyndon
Appendix
This is the code that I am currently working on that throws an issue