Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'io_curve_svg')
-rw-r--r--io_curve_svg/__init__.py16
-rw-r--r--io_curve_svg/import_svg.py75
2 files changed, 48 insertions, 43 deletions
diff --git a/io_curve_svg/__init__.py b/io_curve_svg/__init__.py
index 188e9189..c8a9988d 100644
--- a/io_curve_svg/__init__.py
+++ b/io_curve_svg/__init__.py
@@ -21,8 +21,7 @@
bl_info = {
"name": "Scalable Vector Graphics (SVG) 1.1 format",
"author": "JM Soler, Sergey Sharybin",
- "version": (1, 0, 0),
- "blender": (2, 57, 0),
+ "blender": (2, 80, 0),
"location": "File > Import > Scalable Vector Graphics (.svg)",
"description": "Import SVG as curves",
"warning": "",
@@ -53,13 +52,12 @@ class ImportSVG(bpy.types.Operator, ImportHelper):
bl_options = {'UNDO'}
filename_ext = ".svg"
- filter_glob = StringProperty(default="*.svg", options={'HIDDEN'})
+ filter_glob: StringProperty(default="*.svg", options={'HIDDEN'})
def execute(self, context):
from . import import_svg
- return import_svg.load(self, context,
- **self.as_keywords(ignore=("filter_glob",)))
+ return import_svg.load(self, context, filepath=self.filepath)
def menu_func_import(self, context):
@@ -68,15 +66,15 @@ def menu_func_import(self, context):
def register():
- bpy.utils.register_module(__name__)
+ bpy.utils.register_class(ImportSVG)
- bpy.types.INFO_MT_file_import.append(menu_func_import)
+ bpy.types.TOPBAR_MT_file_import.append(menu_func_import)
def unregister():
- bpy.utils.unregister_module(__name__)
+ bpy.utils.unregister_class(ImportSVG)
- bpy.types.INFO_MT_file_import.remove(menu_func_import)
+ bpy.types.TOPBAR_MT_file_import.remove(menu_func_import)
# NOTES
# - blender version is hardcoded
diff --git a/io_curve_svg/import_svg.py b/io_curve_svg/import_svg.py
index 00c90dc6..1a8c2f65 100644
--- a/io_curve_svg/import_svg.py
+++ b/io_curve_svg/import_svg.py
@@ -118,14 +118,15 @@ def SVGParseFloat(s, i=0):
return token, i
-def SVGCreateCurve():
+def SVGCreateCurve(context):
"""
Create new curve object to hold splines in
"""
cu = bpy.data.curves.new("Curve", 'CURVE')
obj = bpy.data.objects.new("Curve", cu)
- bpy.context.scene.objects.link(obj)
+
+ context['collection'].objects.link(obj)
return obj
@@ -213,8 +214,8 @@ def SVGMatrixFromNode(node, context):
m = Matrix.Translation(Vector((x, y, 0.0)))
if has_user_coordinate:
if rect[0] != 0 and rect[1] != 0:
- m = m * Matrix.Scale(w / rect[0], 4, Vector((1.0, 0.0, 0.0)))
- m = m * Matrix.Scale(h / rect[1], 4, Vector((0.0, 1.0, 0.0)))
+ m = m @ Matrix.Scale(w / rect[0], 4, Vector((1.0, 0.0, 0.0)))
+ m = m @ Matrix.Scale(h / rect[1], 4, Vector((0.0, 1.0, 0.0)))
if node.getAttribute('viewBox'):
viewBox = node.getAttribute('viewBox').replace(',', ' ').split()
@@ -237,11 +238,11 @@ def SVGMatrixFromNode(node, context):
tx = (w - vw * scale) / 2
ty = (h - vh * scale) / 2
- m = m * Matrix.Translation(Vector((tx, ty, 0.0)))
+ m = m @ Matrix.Translation(Vector((tx, ty, 0.0)))
- m = m * Matrix.Translation(Vector((-vx, -vy, 0.0)))
- m = m * Matrix.Scale(scale, 4, Vector((1.0, 0.0, 0.0)))
- m = m * Matrix.Scale(scale, 4, Vector((0.0, 1.0, 0.0)))
+ m = m @ Matrix.Translation(Vector((-vx, -vy, 0.0)))
+ m = m @ Matrix.Scale(scale, 4, Vector((1.0, 0.0, 0.0)))
+ m = m @ Matrix.Scale(scale, 4, Vector((0.0, 1.0, 0.0)))
return m
@@ -263,7 +264,7 @@ def SVGParseTransform(transform):
if proc is None:
raise Exception('Unknown trasnform function: ' + func)
- m = m * proc(params)
+ m = m @ proc(params)
return m
@@ -304,7 +305,6 @@ def SVGGetMaterial(color, context):
mat = bpy.data.materials.new(name='SVGMat')
mat.diffuse_color = diffuse_color
- mat.diffuse_intensity = 1.0
materials[color] = mat
@@ -350,8 +350,8 @@ def SVGTransformScale(params):
m = Matrix()
- m = m * Matrix.Scale(sx, 4, Vector((1.0, 0.0, 0.0)))
- m = m * Matrix.Scale(sy, 4, Vector((0.0, 1.0, 0.0)))
+ m = m @ Matrix.Scale(sx, 4, Vector((1.0, 0.0, 0.0)))
+ m = m @ Matrix.Scale(sy, 4, Vector((0.0, 1.0, 0.0)))
return m
@@ -395,7 +395,7 @@ def SVGTransformRotate(params):
tm = Matrix.Translation(Vector((cx, cy, 0.0)))
rm = Matrix.Rotation(ang, 4, Vector((0.0, 0.0, 1.0)))
- return tm * rm * tm.inverted()
+ return tm @ rm @ tm.inverted()
SVGTransforms = {'translate': SVGTransformTranslate,
'scale': SVGTransformScale,
@@ -1030,7 +1030,7 @@ class SVGGeometry:
"""
self._context['transform'].append(matrix)
- self._context['matrix'] = self._context['matrix'] * matrix
+ self._context['matrix'] = self._context['matrix'] @ matrix
def _popMatrix(self):
"""
@@ -1038,7 +1038,7 @@ class SVGGeometry:
"""
matrix = self._context['transform'].pop()
- self._context['matrix'] = self._context['matrix'] * matrix.inverted()
+ self._context['matrix'] = self._context['matrix'] @ matrix.inverted()
def _pushStyle(self, style):
"""
@@ -1063,7 +1063,7 @@ class SVGGeometry:
v = Vector((point[0], point[1], 0.0))
- return self._context['matrix'] * v
+ return self._context['matrix'] @ v
def getNodeMatrix(self):
"""
@@ -1211,7 +1211,7 @@ class SVGGeometryPATH(SVGGeometry):
Create real geometries
"""
- ob = SVGCreateCurve()
+ ob = SVGCreateCurve(self._context)
cu = ob.data
if self._node.getAttribute('id'):
@@ -1234,7 +1234,7 @@ class SVGGeometryPATH(SVGGeometry):
act_spline = cu.splines[-1]
act_spline.use_cyclic_u = spline['closed']
else:
- act_spline.bezier_points.add()
+ act_spline.bezier_points.add(1)
bezt = act_spline.bezier_points[-1]
bezt.co = co
@@ -1378,7 +1378,7 @@ class SVGGeometryRECT(SVGGeometry):
co = self._transformCoord(coord)
if not firstTime:
- spline.bezier_points.add()
+ spline.bezier_points.add(1)
bezt = spline.bezier_points[-1]
bezt.co = co
@@ -1429,7 +1429,7 @@ class SVGGeometryRECT(SVGGeometry):
radius = (rx, ry)
# Geometry creation
- ob = SVGCreateCurve()
+ ob = SVGCreateCurve(self._context)
cu = ob.data
if self._styles['useFill']:
@@ -1539,7 +1539,7 @@ class SVGGeometryELLIPSE(SVGGeometry):
return
# Create circle
- ob = SVGCreateCurve()
+ ob = SVGCreateCurve(self._context)
cu = ob.data
if self._node.getAttribute('id'):
@@ -1578,7 +1578,7 @@ class SVGGeometryELLIPSE(SVGGeometry):
spline = cu.splines[-1]
spline.use_cyclic_u = True
else:
- spline.bezier_points.add()
+ spline.bezier_points.add(1)
bezt = spline.bezier_points[-1]
bezt.co = co
@@ -1656,7 +1656,7 @@ class SVGGeometryLINE(SVGGeometry):
y2 = SVGParseCoord(self._y2, crect[1])
# Create cline
- ob = SVGCreateCurve()
+ ob = SVGCreateCurve(self._context)
cu = ob.data
coords = [(x1, y1), (x2, y2)]
@@ -1670,7 +1670,7 @@ class SVGGeometryLINE(SVGGeometry):
spline = cu.splines[-1]
spline.use_cyclic_u = True
else:
- spline.bezier_points.add()
+ spline.bezier_points.add(1)
bezt = spline.bezier_points[-1]
bezt.co = co
@@ -1727,7 +1727,7 @@ class SVGGeometryPOLY(SVGGeometry):
Create real geometries
"""
- ob = SVGCreateCurve()
+ ob = SVGCreateCurve(self._context)
cu = ob.data
if self._closed and self._styles['useFill']:
@@ -1746,7 +1746,7 @@ class SVGGeometryPOLY(SVGGeometry):
spline = cu.splines[-1]
spline.use_cyclic_u = self._closed
else:
- spline.bezier_points.add()
+ spline.bezier_points.add(1)
bezt = spline.bezier_points[-1]
bezt.co = co
@@ -1798,7 +1798,7 @@ class SVGGeometrySVG(SVGGeometryContainer):
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])
+ matrix = matrix @ matrix.Translation([0.0, -document_height , 0.0])
self._pushMatrix(matrix)
self._pushRect(rect)
@@ -1824,16 +1824,22 @@ class SVGLoader(SVGGeometryContainer):
return None
- def __init__(self, filepath, do_colormanage):
+ def __init__(self, context, filepath, do_colormanage):
"""
Initialize SVG loader
"""
+ import os
+
+ svg_name = os.path.basename(filepath)
+ scene = context.scene
+ collection = bpy.data.collections.new(name=svg_name)
+ scene.collection.children.link(collection)
node = xml.dom.minidom.parse(filepath)
m = Matrix()
- 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)))
+ 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)))
rect = (0, 0)
@@ -1845,7 +1851,8 @@ class SVGLoader(SVGGeometryContainer):
'materials': {},
'styles': [None],
'style': None,
- 'do_colormanage': do_colormanage}
+ 'do_colormanage': do_colormanage,
+ 'collection': collection}
super().__init__(node, self._context)
@@ -1882,7 +1889,7 @@ def parseAbstractNode(node, context):
return None
-def load_svg(filepath, do_colormanage):
+def load_svg(context, filepath, do_colormanage):
"""
Load specified SVG file
"""
@@ -1890,7 +1897,7 @@ def load_svg(filepath, do_colormanage):
if bpy.ops.object.mode_set.poll():
bpy.ops.object.mode_set(mode='OBJECT')
- loader = SVGLoader(filepath, do_colormanage)
+ loader = SVGLoader(context, filepath, do_colormanage)
loader.parse()
loader.createGeom(False)
@@ -1901,7 +1908,7 @@ def load(operator, context, filepath=""):
# non SVG files can give useful messages.
do_colormanage = context.scene.display_settings.display_device != 'NONE'
try:
- load_svg(filepath, do_colormanage)
+ load_svg(context, filepath, do_colormanage)
except (xml.parsers.expat.ExpatError, UnicodeEncodeError) as e:
import traceback
traceback.print_exc()