Skip to content

Commit e81a8c2

Browse files
authored
Merge pull request #1101 from compas-dev/bugfix/nurbs_point_count
Bugfix/nurbs point count
2 parents a35bca4 + 7994c07 commit e81a8c2

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
### Changed
1313

1414
* Fixed strange point values in RhinoNurbsCurve caused by conversion `ControlPoint` to COMPAS instead of `ControlPoint.Location`.
15+
* Fixed flipped order of NURBS point count values when creating RhinoNurbsSurface from parameters.
1516

1617
### Removed
1718

src/compas_rhino/geometry/surfaces/nurbs.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,27 +61,38 @@ def rhino_surface_from_parameters(
6161
is_u_periodic=False,
6262
is_v_periodic=False,
6363
):
64-
rhino_surface = Rhino.Geometry.NurbsSurface.Create(3, True, u_degree + 1, v_degree + 1, len(points[0]), len(points))
65-
u_knotvector = [knot for knot, mult in zip(u_knots, u_mults) for _ in range(mult)]
66-
v_knotvector = [knot for knot, mult in zip(v_knots, v_mults) for _ in range(mult)]
67-
u_count = len(points[0])
68-
v_count = len(points)
6964
u_order = u_degree + 1
7065
v_order = v_degree + 1
66+
u_point_count = len(points)
67+
v_point_count = len(points[0])
68+
is_rational = True # TODO: check if all weights are equal? https://developer.rhino3d.com/guides/opennurbs/nurbs-geometry-overview/
69+
dimensions = 3
70+
rhino_surface = Rhino.Geometry.NurbsSurface.Create(
71+
dimensions, is_rational, u_order, v_order, u_point_count, v_point_count
72+
)
73+
74+
if not rhino_surface:
75+
message = "dimensions: {} is_rational: {} u_order: {} v_order: {} u_points: {} v_points: {}".format(
76+
dimensions, is_rational, u_order, v_order, u_point_count, v_point_count
77+
)
78+
raise ValueError("Failed to create NurbsSurface with params:\n{}".format(message))
79+
80+
u_knotvector = [knot for knot, mult in zip(u_knots, u_mults) for _ in range(mult)]
81+
v_knotvector = [knot for knot, mult in zip(v_knots, v_mults) for _ in range(mult)]
7182
# account for superfluous knots
7283
# https://developer.rhino3d.com/guides/opennurbs/superfluous-knots/
73-
if len(u_knotvector) == u_count + u_order:
84+
if len(u_knotvector) == u_point_count + u_order:
7485
u_knotvector[:] = u_knotvector[1:-1]
75-
if len(v_knotvector) == v_count + v_order:
86+
if len(v_knotvector) == v_point_count + v_order:
7687
v_knotvector[:] = v_knotvector[1:-1]
7788
# add knots
7889
for index, knot in enumerate(u_knotvector):
7990
rhino_surface.KnotsU[index] = knot
8091
for index, knot in enumerate(v_knotvector):
8192
rhino_surface.KnotsV[index] = knot
8293
# add control points
83-
for i in range(v_count):
84-
for j in range(u_count):
94+
for i in range(u_point_count):
95+
for j in range(v_point_count):
8596
rhino_surface.Points.SetPoint(i, j, point_to_rhino(points[i][j]), weights[i][j])
8697
return rhino_surface
8798

0 commit comments

Comments
 (0)