Various improvements in svg import #61270

Closed
opened 2019-02-07 08:50:50 +01:00 by Michael Soluyanov · 4 comments

Various improvements in svg import:

  • Correct bezier handles in rounded rectangles
  • Viewbox center alignment with world origin
  • Default scale X100

import_svg.py

Снимок экрана от 2019-02-07 11-07-32.png

diff ./blender-2.80-9df460203517-linux-glibc224-x86_64/2.80/scripts/addons/io_curve_svg/import_svg.py ./blender-2.80-141c6073ca39-linux-glibc224-x86_64/2.80/scripts/addons/io_curve_svg/import_svg.py
1381c1381
<     def _appendCorner(self, spline, coord, firstTime, rounded):
---
>     def _appendCorner(self, spline, coord, firstTime):

1387c1387,1389
<         if len(coord) == 3:
---
>         
>      
>         if len(coord) == 4:

1389,1391c1391,1393
<             coord = (coord[0], coord[1])
< 
<         co = self._transformCoord(coord)
---
>             co = self._transformCoord((coord[0], coord[1]))
>         else:
>             co = self._transformCoord(coord)

1398,1400c1400,1403
< 
<         if rounded:
<             if handle:
---
>         
>         # correct bezier handles in rounded rectangles
>         if len(coord) == 4:
>             if coord[3] == 'R':

1403d1405
< 
1408c1410
<                 bezt.handle_left = co
---
>                 bezt.handle_left = handle

1462c1464
<         rounded = False
---
>         

1476,1486c1478,1492
<             #
< 
<             # Optional third component -- right handle coord
<             coords = [(x + rx, y),
<                       (x + w - rx, y, (x + w, y)),
<                       (x + w, y + ry),
<                       (x + w, y + h - ry, (x + w, y + h)),
<                       (x + w - rx, y + h),
<                       (x + rx, y + h, (x, y + h)),
<                       (x, y + h - ry),
<                       (x, y + ry, (x, y))]
---
>             
>             
>             # correct bezier handles in rounded rectangles
>             # dconst is (4/3)*tan(pi/8) = 4*(sqrt(2)-1)/3 = 0.552284749831
>             dconst = 1 - 0.552284749831
>             
>             # third component -- right/left handle coord
>             coords = [(x + rx, y, (x + (dconst * rx), y), 'L'),
>                       (x + w - rx, y, (x + w - (dconst * rx), y), 'R'),
>                       (x + w, y + ry, (x + w, y + (ry * dconst) ), 'L'),
>                       (x + w, y + h - ry, (x + w, y + h - (ry * dconst)), 'R'),
>                       (x + w - rx, y + h, (x + w - (dconst * rx), y + h), 'L'), #4
>                       (x + rx, y + h, (x + (dconst * rx), y + h), 'R'),
>                       (x, y + h - ry, (x, y + h - (ry * dconst)), 'L'),
>                       (x, y + ry, (x, y + (ry * dconst)), 'R')]

1488c1494
<             rounded = True
---
>             

1494c1500
<             self._appendCorner(spline, coord, firstTime, rounded)
---
>             self._appendCorner(spline, coord, firstTime)

1809,1812c1815,1828
<         if self._node.getAttribute('inkscape:version'):
<             raw_height = self._node.getAttribute('height')
<             document_height = SVGParseCoord(raw_height, 1.0)
<             matrix = matrix @ matrix.Translation([0.0, -document_height , 0.0])
---
>         #if self._node.getAttribute('inkscape:version'):
>         #    raw_height = self._node.getAttribute('height')
>         #    document_height = SVGParseCoord(raw_height, 1.0)
>         #    matrix = matrix @ matrix.Translation([0.0, -document_height , 0.0])
> 
>         # get center of viewbox and place it in world orign 
>         if(self._node.getAttribute('viewBox')):
>             viewbox = self._node.getAttribute('viewBox').split(' ')
>         
>             center_x = (float(viewbox[2])+float(viewbox[0]))/2
>             center_y = (float(viewbox[3])+float(viewbox[1]))/2
>         
>             matrix = matrix @ matrix.Translation( Vector((-center_x,-center_y,0.0)) )  
>             

1852,1853c1868,1870
<         m = m @ Matrix.Scale(1.0 / 90.0 * 0.3048 / 12.0, 4, Vector((1.0, 0.0, 0.0)))
<         m = m @ Matrix.Scale(-1.0 / 90.0 * 0.3048 / 12.0, 4, Vector((0.0, 1.0, 0.0)))
---
>         #default scale usualy small, set it to 100
>         m = m @ Matrix.Scale(100.0 / 90.0 * 0.3048 / 12.0, 4, Vector((1.0, 0.0, 0.0)))
>         m = m @ Matrix.Scale(-100.0 / 90.0 * 0.3048 / 12.0, 4, Vector((0.0, 1.0, 0.0)))




Various improvements in svg import: - Correct bezier handles in rounded rectangles - Viewbox center alignment with world origin - Default scale X100 [import_svg.py](https://archive.blender.org/developer/F6536209/import_svg.py) ![Снимок экрана от 2019-02-07 11-07-32.png](https://archive.blender.org/developer/F6536337/Снимок_экрана_от_2019-02-07_11-07-32.png) ``` diff ./blender-2.80-9df460203517-linux-glibc224-x86_64/2.80/scripts/addons/io_curve_svg/import_svg.py ./blender-2.80-141c6073ca39-linux-glibc224-x86_64/2.80/scripts/addons/io_curve_svg/import_svg.py 1381c1381 < def _appendCorner(self, spline, coord, firstTime, rounded): --- > def _appendCorner(self, spline, coord, firstTime): 1387c1387,1389 < if len(coord) == 3: --- > > > if len(coord) == 4: 1389,1391c1391,1393 < coord = (coord[0], coord[1]) < < co = self._transformCoord(coord) --- > co = self._transformCoord((coord[0], coord[1])) > else: > co = self._transformCoord(coord) 1398,1400c1400,1403 < < if rounded: < if handle: --- > > # correct bezier handles in rounded rectangles > if len(coord) == 4: > if coord[3] == 'R': 1403d1405 < 1408c1410 < bezt.handle_left = co --- > bezt.handle_left = handle 1462c1464 < rounded = False --- > 1476,1486c1478,1492 < # < < # Optional third component -- right handle coord < coords = [(x + rx, y), < (x + w - rx, y, (x + w, y)), < (x + w, y + ry), < (x + w, y + h - ry, (x + w, y + h)), < (x + w - rx, y + h), < (x + rx, y + h, (x, y + h)), < (x, y + h - ry), < (x, y + ry, (x, y))] --- > > > # correct bezier handles in rounded rectangles > # dconst is (4/3)*tan(pi/8) = 4*(sqrt(2)-1)/3 = 0.552284749831 > dconst = 1 - 0.552284749831 > > # third component -- right/left handle coord > coords = [(x + rx, y, (x + (dconst * rx), y), 'L'), > (x + w - rx, y, (x + w - (dconst * rx), y), 'R'), > (x + w, y + ry, (x + w, y + (ry * dconst) ), 'L'), > (x + w, y + h - ry, (x + w, y + h - (ry * dconst)), 'R'), > (x + w - rx, y + h, (x + w - (dconst * rx), y + h), 'L'), #4 > (x + rx, y + h, (x + (dconst * rx), y + h), 'R'), > (x, y + h - ry, (x, y + h - (ry * dconst)), 'L'), > (x, y + ry, (x, y + (ry * dconst)), 'R')] 1488c1494 < rounded = True --- > 1494c1500 < self._appendCorner(spline, coord, firstTime, rounded) --- > self._appendCorner(spline, coord, firstTime) 1809,1812c1815,1828 < if self._node.getAttribute('inkscape:version'): < raw_height = self._node.getAttribute('height') < document_height = SVGParseCoord(raw_height, 1.0) < matrix = matrix @ matrix.Translation([0.0, -document_height , 0.0]) --- > #if self._node.getAttribute('inkscape:version'): > # raw_height = self._node.getAttribute('height') > # document_height = SVGParseCoord(raw_height, 1.0) > # matrix = matrix @ matrix.Translation([0.0, -document_height , 0.0]) > > # get center of viewbox and place it in world orign > if(self._node.getAttribute('viewBox')): > viewbox = self._node.getAttribute('viewBox').split(' ') > > center_x = (float(viewbox[2])+float(viewbox[0]))/2 > center_y = (float(viewbox[3])+float(viewbox[1]))/2 > > matrix = matrix @ matrix.Translation( Vector((-center_x,-center_y,0.0)) ) > 1852,1853c1868,1870 < m = m @ Matrix.Scale(1.0 / 90.0 * 0.3048 / 12.0, 4, Vector((1.0, 0.0, 0.0))) < m = m @ Matrix.Scale(-1.0 / 90.0 * 0.3048 / 12.0, 4, Vector((0.0, 1.0, 0.0))) --- > #default scale usualy small, set it to 100 > m = m @ Matrix.Scale(100.0 / 90.0 * 0.3048 / 12.0, 4, Vector((1.0, 0.0, 0.0))) > m = m @ Matrix.Scale(-100.0 / 90.0 * 0.3048 / 12.0, 4, Vector((0.0, 1.0, 0.0))) ```
Author
Member

Added subscriber: @crantisz

Added subscriber: @crantisz
Member

Added subscriber: @JacquesLucke

Added subscriber: @JacquesLucke
Member

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Jacques Lucke self-assigned this 2019-02-07 11:10:17 +01:00
Member

Please create a git diff and use the "Submit Code" button on the main page.
That makes it much easier to see which changes you made.

You can add me as an initial reviewer.

Please create a git diff and use the "Submit Code" button on the main page. That makes it much easier to see which changes you made. You can add me as an initial reviewer.
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#61270
No description provided.