Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
blender-addons
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
blender
blender-addons
Commits
2a0d3baf
Commit
2a0d3baf
authored
6 years ago
by
Sergey Sharybin
Browse files
Options
Downloads
Patches
Plain Diff
SVG: Port to 2.8
parent
cdbcfdb9
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
io_curve_svg/__init__.py
+1
-1
1 addition, 1 deletion
io_curve_svg/__init__.py
io_curve_svg/import_svg.py
+20
-13
20 additions, 13 deletions
io_curve_svg/import_svg.py
with
21 additions
and
14 deletions
io_curve_svg/__init__.py
+
1
−
1
View file @
2a0d3baf
...
@@ -21,7 +21,7 @@
...
@@ -21,7 +21,7 @@
bl_info
=
{
bl_info
=
{
"
name
"
:
"
Scalable Vector Graphics (SVG) 1.1 format
"
,
"
name
"
:
"
Scalable Vector Graphics (SVG) 1.1 format
"
,
"
author
"
:
"
JM Soler, Sergey Sharybin
"
,
"
author
"
:
"
JM Soler, Sergey Sharybin
"
,
"
blender
"
:
(
2
,
57
,
0
),
"
blender
"
:
(
2
,
80
,
0
),
"
location
"
:
"
File > Import > Scalable Vector Graphics (.svg)
"
,
"
location
"
:
"
File > Import > Scalable Vector Graphics (.svg)
"
,
"
description
"
:
"
Import SVG as curves
"
,
"
description
"
:
"
Import SVG as curves
"
,
"
warning
"
:
""
,
"
warning
"
:
""
,
...
...
This diff is collapsed.
Click to expand it.
io_curve_svg/import_svg.py
+
20
−
13
View file @
2a0d3baf
...
@@ -118,14 +118,15 @@ def SVGParseFloat(s, i=0):
...
@@ -118,14 +118,15 @@ def SVGParseFloat(s, i=0):
return
token
,
i
return
token
,
i
def
SVGCreateCurve
():
def
SVGCreateCurve
(
context
):
"""
"""
Create new curve object to hold splines in
Create new curve object to hold splines in
"""
"""
cu
=
bpy
.
data
.
curves
.
new
(
"
Curve
"
,
'
CURVE
'
)
cu
=
bpy
.
data
.
curves
.
new
(
"
Curve
"
,
'
CURVE
'
)
obj
=
bpy
.
data
.
objects
.
new
(
"
Curve
"
,
cu
)
obj
=
bpy
.
data
.
objects
.
new
(
"
Curve
"
,
cu
)
bpy
.
context
.
scene
.
objects
.
link
(
obj
)
context
[
'
collection
'
].
objects
.
link
(
obj
)
return
obj
return
obj
...
@@ -304,7 +305,6 @@ def SVGGetMaterial(color, context):
...
@@ -304,7 +305,6 @@ def SVGGetMaterial(color, context):
mat
=
bpy
.
data
.
materials
.
new
(
name
=
'
SVGMat
'
)
mat
=
bpy
.
data
.
materials
.
new
(
name
=
'
SVGMat
'
)
mat
.
diffuse_color
=
diffuse_color
mat
.
diffuse_color
=
diffuse_color
mat
.
diffuse_intensity
=
1.0
materials
[
color
]
=
mat
materials
[
color
]
=
mat
...
@@ -1211,7 +1211,7 @@ class SVGGeometryPATH(SVGGeometry):
...
@@ -1211,7 +1211,7 @@ class SVGGeometryPATH(SVGGeometry):
Create real geometries
Create real geometries
"""
"""
ob
=
SVGCreateCurve
()
ob
=
SVGCreateCurve
(
self
.
_context
)
cu
=
ob
.
data
cu
=
ob
.
data
if
self
.
_node
.
getAttribute
(
'
id
'
):
if
self
.
_node
.
getAttribute
(
'
id
'
):
...
@@ -1429,7 +1429,7 @@ class SVGGeometryRECT(SVGGeometry):
...
@@ -1429,7 +1429,7 @@ class SVGGeometryRECT(SVGGeometry):
radius
=
(
rx
,
ry
)
radius
=
(
rx
,
ry
)
# Geometry creation
# Geometry creation
ob
=
SVGCreateCurve
()
ob
=
SVGCreateCurve
(
self
.
_context
)
cu
=
ob
.
data
cu
=
ob
.
data
if
self
.
_styles
[
'
useFill
'
]:
if
self
.
_styles
[
'
useFill
'
]:
...
@@ -1539,7 +1539,7 @@ class SVGGeometryELLIPSE(SVGGeometry):
...
@@ -1539,7 +1539,7 @@ class SVGGeometryELLIPSE(SVGGeometry):
return
return
# Create circle
# Create circle
ob
=
SVGCreateCurve
()
ob
=
SVGCreateCurve
(
self
.
_context
)
cu
=
ob
.
data
cu
=
ob
.
data
if
self
.
_node
.
getAttribute
(
'
id
'
):
if
self
.
_node
.
getAttribute
(
'
id
'
):
...
@@ -1656,7 +1656,7 @@ class SVGGeometryLINE(SVGGeometry):
...
@@ -1656,7 +1656,7 @@ class SVGGeometryLINE(SVGGeometry):
y2
=
SVGParseCoord
(
self
.
_y2
,
crect
[
1
])
y2
=
SVGParseCoord
(
self
.
_y2
,
crect
[
1
])
# Create cline
# Create cline
ob
=
SVGCreateCurve
()
ob
=
SVGCreateCurve
(
self
.
_context
)
cu
=
ob
.
data
cu
=
ob
.
data
coords
=
[(
x1
,
y1
),
(
x2
,
y2
)]
coords
=
[(
x1
,
y1
),
(
x2
,
y2
)]
...
@@ -1727,7 +1727,7 @@ class SVGGeometryPOLY(SVGGeometry):
...
@@ -1727,7 +1727,7 @@ class SVGGeometryPOLY(SVGGeometry):
Create real geometries
Create real geometries
"""
"""
ob
=
SVGCreateCurve
()
ob
=
SVGCreateCurve
(
self
.
_context
)
cu
=
ob
.
data
cu
=
ob
.
data
if
self
.
_closed
and
self
.
_styles
[
'
useFill
'
]:
if
self
.
_closed
and
self
.
_styles
[
'
useFill
'
]:
...
@@ -1824,10 +1824,16 @@ class SVGLoader(SVGGeometryContainer):
...
@@ -1824,10 +1824,16 @@ class SVGLoader(SVGGeometryContainer):
return
None
return
None
def
__init__
(
self
,
filepath
,
do_colormanage
):
def
__init__
(
self
,
context
,
filepath
,
do_colormanage
):
"""
"""
Initialize SVG loader
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
)
node
=
xml
.
dom
.
minidom
.
parse
(
filepath
)
...
@@ -1845,7 +1851,8 @@ class SVGLoader(SVGGeometryContainer):
...
@@ -1845,7 +1851,8 @@ class SVGLoader(SVGGeometryContainer):
'
materials
'
:
{},
'
materials
'
:
{},
'
styles
'
:
[
None
],
'
styles
'
:
[
None
],
'
style
'
:
None
,
'
style
'
:
None
,
'
do_colormanage
'
:
do_colormanage
}
'
do_colormanage
'
:
do_colormanage
,
'
collection
'
:
collection
}
super
().
__init__
(
node
,
self
.
_context
)
super
().
__init__
(
node
,
self
.
_context
)
...
@@ -1882,7 +1889,7 @@ def parseAbstractNode(node, context):
...
@@ -1882,7 +1889,7 @@ def parseAbstractNode(node, context):
return
None
return
None
def
load_svg
(
filepath
,
do_colormanage
):
def
load_svg
(
context
,
filepath
,
do_colormanage
):
"""
"""
Load specified SVG file
Load specified SVG file
"""
"""
...
@@ -1890,7 +1897,7 @@ def load_svg(filepath, do_colormanage):
...
@@ -1890,7 +1897,7 @@ def load_svg(filepath, do_colormanage):
if
bpy
.
ops
.
object
.
mode_set
.
poll
():
if
bpy
.
ops
.
object
.
mode_set
.
poll
():
bpy
.
ops
.
object
.
mode_set
(
mode
=
'
OBJECT
'
)
bpy
.
ops
.
object
.
mode_set
(
mode
=
'
OBJECT
'
)
loader
=
SVGLoader
(
filepath
,
do_colormanage
)
loader
=
SVGLoader
(
context
,
filepath
,
do_colormanage
)
loader
.
parse
()
loader
.
parse
()
loader
.
createGeom
(
False
)
loader
.
createGeom
(
False
)
...
@@ -1901,7 +1908,7 @@ def load(operator, context, filepath=""):
...
@@ -1901,7 +1908,7 @@ def load(operator, context, filepath=""):
# non SVG files can give useful messages.
# non SVG files can give useful messages.
do_colormanage
=
context
.
scene
.
display_settings
.
display_device
!=
'
NONE
'
do_colormanage
=
context
.
scene
.
display_settings
.
display_device
!=
'
NONE
'
try
:
try
:
load_svg
(
filepath
,
do_colormanage
)
load_svg
(
context
,
filepath
,
do_colormanage
)
except
(
xml
.
parsers
.
expat
.
ExpatError
,
UnicodeEncodeError
)
as
e
:
except
(
xml
.
parsers
.
expat
.
ExpatError
,
UnicodeEncodeError
)
as
e
:
import
traceback
import
traceback
traceback
.
print_exc
()
traceback
.
print_exc
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment