Skip to content

Commit

Permalink
fix: fix some issues with the SVG import
Browse files Browse the repository at this point in the history
  • Loading branch information
ntamas committed Jul 14, 2023
1 parent ad7327f commit e4c036f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def _create_points(self, context) -> PointsAndColors:
point_color_pairs = parse_static_csv_zip(filepath)

points = zeros((len(point_color_pairs), 3), dtype=float)
colors = zeros((len(point_color_pairs), 3), dtype=float) + 255
colors = zeros((len(point_color_pairs), 3), dtype=float) + 1

for index, (p, c) in enumerate(point_color_pairs.values()):
points[index, :] = p
Expand Down Expand Up @@ -103,6 +103,8 @@ def parse_static_csv_zip(filename: str) -> Dict[str, Item]:
raise RuntimeError(f"Duplicate object name in input CSV file: {name}")

# store position and color entry
result[name] = array((x, y, z), dtype=float), array((r, g, b), dtype=int)
result[name] = array((x, y, z), dtype=float), array(
(r, g, b, 255), dtype=int
)

return result
6 changes: 4 additions & 2 deletions src/modules/sbstudio/plugin/operators/add_markers_from_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ def parse_svg(
raise

# rotate from XY to ZY plane
points = array((0, p.y, p.x) for p in points)
colors = array((c.r / 255, c.g / 255, c.b / 255) for c in colors)
points = array([(0, p.y, p.x) for p in points], dtype=float)
colors = array(
[(c.r / 255, c.g / 255, c.b / 255, 1.0) for c in colors], dtype=float
)

return points, colors
6 changes: 3 additions & 3 deletions src/modules/sbstudio/plugin/operators/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class PointsAndColors:
colors: Optional[NDArray[float]] = None
"""Optional colors corresponding to the points in a marker creation
operation, in a NumPy array where the i-th row is the color of the i-th
point in RGB space; color components must be specified in the range [0; 1].
point in RGBA space; color components must be specified in the range [0; 1].
"""


Expand All @@ -131,7 +131,7 @@ def execute_on_formation(self, formation, context):
points = points_and_colors.points
colors = points_and_colors.colors

if points.shape[0] < 1:
if len(points) < 1:
self.report({"ERROR"}, "Formation would be empty, nothing was created")
return {"CANCELLED"}

Expand Down Expand Up @@ -176,7 +176,7 @@ def execute_on_formation(self, formation, context):
width=1,
height=len(colors),
)
image.pixels.foreach_set(colors.flat)
image.pixels.foreach_set(list(colors.flat))

return {"FINISHED"}

Expand Down

0 comments on commit e4c036f

Please sign in to comment.