Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
# <pep8 compliant>
"""Importing a vector file into Model format.
"""
__author__ = "howard.trickey@gmail.com"
from . import geom
from . import model
from . import vecfile
from . import art2polyarea
from . import triquad
from . import offset
import math
class ImportOptions(object):
"""Contains options used to control model import.
Attributes:
quadrangulate: bool - should n-gons be quadrangulated?
convert_options: art2polyarea.ConvertOptions -
options about how to convert vector files into
polygonal areas
scaled_side_target: float - scale model so that longest side
is this length, if > 0.
extrude_depth: float - if > 0, extrude polygons up by this amount
bevel_amount: float - if > 0, inset polygons by this amount
bevel_pitch: float - if > 0, angle in radians of bevel
cap_back: bool - should we cap the back, if extruding?
"""
def __init__(self):
self.quadrangulate = True
self.convert_options = art2polyarea.ConvertOptions()
self.scaled_side_target = 4.0
self.extrude_depth = 0.0
self.bevel_amount = 0.0
self.bevel_pitch = 45.0 * math.pi / 180.0
self.cap_back = False
def ReadVecFileToModel(fname, options):
"""Read vector art file and convert to Model.
Args:
fname: string - the file to read
options: ImportOptions - specifies some choices about import
Returns:
(Model, string): if there was a major problem, Model may be None.
The string will be errors and warnings.
"""
art = vecfile.ParseVecFile(fname)
if art is None:
return (None, "Problem reading file or unhandled type")
return ArtToModel(art, options)
def ArtToModel(art, options):
"""Convert an Art object into a Model object.
Args:
art: geom.Art - the Art object to convert.
options: ImportOptions - specifies some choices about import
Returns:
(geom.Model, string): if there was a major problem, Model may be None.
The string will be errors and warnings.
"""
pareas = art2polyarea.ArtToPolyAreas(art, options.convert_options)
if not pareas:
return (None, "No visible faces found")
if options.scaled_side_target > 0:
pareas.scale_and_center(options.scaled_side_target)
m = model.PolyAreasToModel(pareas, options.bevel_amount,
options.bevel_pitch, options.quadrangulate)
if options.extrude_depth > 0:
model.ExtrudePolyAreasInModel(m, pareas, options.extrude_depth,
options.cap_back)
return (m, "")