summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 967848f)
raw | patch | inline | side by side (parent: 967848f)
author | ozmikepittman <ozmikepittman@users.sourceforge.net> | |
Mon, 19 May 2008 16:28:00 +0000 (16:28 +0000) | ||
committer | ozmikepittman <ozmikepittman@users.sourceforge.net> | |
Mon, 19 May 2008 16:28:00 +0000 (16:28 +0000) |
index e5450abac733f5ba8c955f75ae57413715452a70..b996d6e849437a2c74dd6322de18f8c1d03f4b5a 100644 (file)
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-'''\r
+'''
import inkex
import simplestyle, sys
from math import *
-def log_N(base, x): #computes the base-n log of x
- return log(x)/log(base)
-
def draw_SVG_line(x1, y1, x2, y2, width, name, parent):
style = { 'stroke': '#000000', 'stroke-width':str(width), 'fill': 'none' }
line_attribs = {'style':simplestyle.formatStyle(style),
- 'inkscape:label':name,
+ inkex.addNS('label','inkscape'):name,
'd':'M '+str(x1)+','+str(y1)+' L '+str(x2)+','+str(y2)}
inkex.etree.SubElement(parent, inkex.addNS('path','svg'), line_attribs )
def draw_SVG_rect(x,y,w,h, width, fill, name, parent):
style = { 'stroke': '#000000', 'stroke-width':str(width), 'fill':fill}
rect_attribs = {'style':simplestyle.formatStyle(style),
- 'inkscape:label':name,
+ inkex.addNS('label','inkscape'):name,
'x':str(x), 'y':str(y), 'width':str(w), 'height':str(h)}
inkex.etree.SubElement(parent, inkex.addNS('rect','svg'), rect_attribs )
if self.options.x_log: #log x subdivs
for j in range (1, sd):
if j>1: #the first loop is only for subsubdivs
- draw_SVG_line(self.options.dx*(i+log_N(sd, j)), 0,
- self.options.dx*(i+log_N(sd, j)), ymax,
+ draw_SVG_line(self.options.dx*(i+log(j, sd)), 0,
+ self.options.dx*(i+log(j, sd)), ymax,
self.options.x_subdivs_th,
'MinorXDiv'+str(i)+':'+str(j), minglx)
ssd2 = ssd+1 #make even
else:
ssd2 = ssd #no change
- draw_SVG_line(self.options.dx*(i+log_N(sd, j+k/float(ssd2) )), 0,
- self.options.dx*(i+log_N(sd, j+k/float(ssd2) )), ymax,
+ draw_SVG_line(self.options.dx*(i+log(j+k/float(ssd2),sd )), 0,
+ self.options.dx*(i+log(j+k/float(ssd2),sd )), ymax,
self.options.x_subsubdivs_th,'SubminorXDiv'+str(i)+':'+str(j)+':'+str(k), mminglx)
else: #linear x subdivs
if self.options.y_log: #log y subdivs
for j in range (1, sd):
if j>1: #the first loop is only for subsubdivs
- draw_SVG_line(0, self.options.dy*(i+1-log_N(sd, j)),
- xmax, self.options.dy*(i+1-log_N(sd, j)),
+ draw_SVG_line(0, self.options.dy*(i+1-log(j,sd)),
+ xmax, self.options.dy*(i+1-log(j,sd)),
self.options.y_subdivs_th,
'MinorXDiv'+str(i)+':'+str(j), mingly)
ssd2 = ssd+1
else:
ssd2 = ssd #no change
- draw_SVG_line(0, self.options.dx*(i+1-log_N(sd, j+k/float(ssd2) )),
- xmax, self.options.dx*(i+1-log_N(sd, j+k/float(ssd2) )),
+ draw_SVG_line(0, self.options.dx*(i+1-log(j+k/float(ssd2),sd )),
+ xmax, self.options.dx*(i+1-log(j+k/float(ssd2),sd )),
self.options.y_subsubdivs_th,
'SubminorXDiv'+str(i)+':'+str(j)+':'+str(k), mmingly)
else: #linear y subdivs
e = Grid_Polar()
e.affect()
+
index 93871f1b8bd1edecd0f52a5d9834bd546538304e..9da5017aa93d00e861fc2d83044a0df6236cde88 100644 (file)
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-'''\r
+'''
import inkex
import simplestyle, sys
from math import *
-def log_N(base, x): #computes the base-n log of x
- return log(x)/log(base)
-
-def draw_SVG_ellipse(rx, ry, cx, cy, width, fill, name, parent):
+def draw_SVG_circle(r, cx, cy, width, fill, name, parent):
style = { 'stroke': '#000000', 'stroke-width':str(width), 'fill': fill }
circ_attribs = {'style':simplestyle.formatStyle(style),
- 'inkscape:label':name,
- 'sodipodi:cx':str(cx), 'sodipodi:cy':str(cy),
- 'sodipodi:rx':str(rx), 'sodipodi:ry':str(ry),
- 'sodipodi:type':'arc'}
- inkex.etree.SubElement(parent, inkex.addNS('path','svg'), circ_attribs )
+ 'cx':str(cx), 'cy':str(cy),
+ 'r':str(r),
+ inkex.addNS('label','inkscape'):name}
+ circle = inkex.etree.SubElement(parent, inkex.addNS('circle','svg'), circ_attribs )
def draw_SVG_line(x1, y1, x2, y2, width, name, parent):
style = { 'stroke': '#000000', 'stroke-width':str(width), 'fill': 'none' }
line_attribs = {'style':simplestyle.formatStyle(style),
- 'inkscape:label':name,
+ inkex.addNS('label','inkscape'):name,
'd':'M '+str(x1)+','+str(y1)+' L '+str(x2)+','+str(y2)}
inkex.etree.SubElement(parent, inkex.addNS('path','svg'), line_attribs )
'fill-opacity': '1.0', 'stroke': 'none',
'font-weight': 'normal', 'font-style': 'normal', 'fill': '#000000'}
label_attribs = {'style':simplestyle.formatStyle(style),
- 'inkscape:label':name,
+ inkex.addNS('label','inkscape'):name,
'x':str(x), 'y':str(y)}
label = inkex.etree.SubElement(parent, inkex.addNS('text','svg'), label_attribs)
label.text = string
#Create SVG circles
for i in range(1, self.options.r_divs+1):
- draw_SVG_ellipse(i*dr, i*dr, 0, 0, #major div circles
+ draw_SVG_circle(i*dr, 0, 0, #major div circles
self.options.r_divs_th, 'none',
'MajorDivCircle'+str(i)+':R'+str(i*dr), grid)
if self.options.r_log: #logarithmic subdivisions
for j in range (2, self.options.r_subdivs):
- draw_SVG_ellipse(i*dr-(1-log_N(self.options.r_subdivs, j))*dr, #minor div circles
- i*dr-(1-log_N(self.options.r_subdivs, j))*dr, 0, 0,
- self.options.r_subdivs_th, 'none',
+ draw_SVG_circle(i*dr-(1-log(j, self.options.r_subdivs))*dr, #minor div circles
+ 0, 0, self.options.r_subdivs_th, 'none',
'MinorDivCircle'+str(i)+':Log'+str(j), grid)
else: #linear subdivs
for j in range (1, self.options.r_subdivs):
- draw_SVG_ellipse(i*dr-j*dr/self.options.r_subdivs, #minor div circles
- i*dr-j*dr/self.options.r_subdivs, 0, 0,
- self.options.r_subdivs_th, 'none',
+ draw_SVG_circle(i*dr-j*dr/self.options.r_subdivs, #minor div circles
+ 0, 0, self.options.r_subdivs_th, 'none',
'MinorDivCircle'+str(i)+':R'+str(i*dr), grid)
if self.options.a_divs == self.options.a_divs_cent: #the lines can go from the centre to the edge
self.options.a_subdivs_th, 'RadialMinorGridline'+str(i), grid)
if self.options.c_dot_dia <> 0: #if a non-zero diameter, draw the centre dot
- draw_SVG_ellipse(self.options.c_dot_dia /2.0, self.options.c_dot_dia/2.0,
+ draw_SVG_circle(self.options.c_dot_dia /2.0,
0, 0, 0, '#000000', 'CentreDot', grid)
if self.options.a_labels == 'deg':
e = Grid_Polar()
e.affect()
+
index e09311c06baec9086a74e3c883bf99c6c271c73b..6a6d4010d4ae88fc973265968428e740c64b4f66 100644 (file)
<dependency type="executable" location="extensions">polyhedron_3d.py</dependency>\r
<dependency type="executable" location="extensions">inkex.py</dependency>\r
<param name="tab" type="notebook">\r
- <page name="common" _gui-text="Common Objects">\r
+ <page name="common" _gui-text="Model File">\r
<param name="obj" type="optiongroup" _gui-text="Object:">\r
<_option value="cube">Cube</_option>\r
<_option value="t_cube">Truncated Cube</_option>\r
<_option value="from_file">Load From File</_option>\r
</param>\r
<param name="spec_file" type="string" _gui-text="Filename:">great_rhombicuboct.obj</param>\r
+ <param name="type" type="optiongroup" _gui-text="Object Type">\r
+ <_option value="face">Face-Specified</_option>\r
+ <_option value="edge">Edge-Specified</_option></param>\r
<param name="cw_wound" type="boolean" _gui-text="Clockwise Wound Object">0</param>\r
</page>\r
<page name="view" _gui-text="View">\r
<script>\r
<command reldir="extensions" interpreter="python">polyhedron_3d.py</command>\r
</script>\r
-</inkscape-extension>
\ No newline at end of file
+</inkscape-extension>\r
index 2b5698e746bcc89636e49e465d066f440aab5f2b..d6bf2c5dabcc420deb367641fd50df888f7b6af9 100644 (file)
'''
Copyright (C) 2007 John Beard john.j.beard@gmail.com
-##This extension draws 3d objects from an .obj file stored in a local folder
+##This extension draws 3d objects from a Wavefront .obj 3D file stored in a local folder
##Many settings for appearance, lighting, rotation, etc are available.
# ^y
# IMAGE PLANE SCENE|
# |
-#The .obj file must contain "#Name:" followed by a name,
-#and "#Type:" follwed by "edge_specified" or "face-specified"
-#if edge_specified is given, then faces cannot be drawn,
-#if face_specified is given then faces and edges can be drawn
-
#Vertices are given as "v" followed by three numbers (x,y,z).
#All files need a vertex list
#v x.xxx y.yyy z.zzz
inkex.debug("Failed to import the numpy module. This module is required by this extension. Please install them and try again. On a Debian-like system this can be done with the command, sudo apt-get install python-numpy.")
sys.exit()
-def mydir():
+def objfile(name):
import os.path
if __name__ == '__main__':
filename = sys.argv[0]
else:
filename = __file__
- return os.path.abspath(os.path.dirname(filename))
+ path = os.path.abspath(os.path.dirname(filename))
+ path = os.path.join(path, 'Poly3DObjects', name)
+ return path
def get_obj_data(obj, name):
- infile = open(mydir() +'\\Poly3DObjects\\'+name)
+ infile = open(objfile(name))
#regular expressions
getname = '(.[nN]ame:\\s*)(.*)'
- gettype = '(.[tT]ype:\\s*)([Ff]ace|[Ee]dge)(.specified)'
- getvertex = '(v\\s+)([\-\\d*\.]*)\\s+([\-\\d*\.]*)\\s+([\-\\d*\.]*)'
+ floating = '([\-\+\\d*\.e]*)'
+ getvertex = '(v\\s+)'+floating+'\\s+'+floating+'\\s+'+floating
getedgeline = '(l\\s+)(.*)'
getfaceline = '(f\\s+)(.*)'
- getnextint = '\\s*(\\d+)(.*)'
+ getnextint = '(\\d+)([/\\d]*)(.*)'#we need to deal with 133\343\123 or 123\\456 as one item
obj.vtx = []
obj.edg = []
obj.fce = []
- obj.type=''
obj.name=''
for line in infile:
m = re.search(getname, line)
if m:
obj.name = m.group(2)
- m = re.search(gettype, line)
- if m:
- typestr = m.group(2).lower()
- obj.type=typestr
elif line[0:1] == 'v': #we have a vertex (maybe)
m = re.search(getvertex, line)
if m: #we have a valid vertex
m2 = re.search(getnextint, line)
if m2:
vtxlist.append( int(m2.group(1)) )
- line = m2.group(2)#remainder
+ line = m2.group(3)#remainder
else:
line = None
if len(vtxlist) > 1:#we need at least 2 vertices to make an edge
m2 = re.search(getnextint, line)
if m2:
vtxlist.append( int(m2.group(1)) )
- line = m2.group(2)#remainder
+ line = m2.group(3)#remainder
else:
line = None
if len(vtxlist) > 2:#we need at least 3 vertices to make an edge
obj.fce.append(vtxlist)
+
+ if obj.name == '':#no name was found, use filename, without extension
+ obj.name = name[0:-4]
def draw_SVG_dot((cx, cy), st, name, parent):
style = { 'stroke': '#000000', 'stroke-width':str(st.th), 'fill': st.fill, 'stroke-opacity':st.s_opac, 'fill-opacity':st.f_opac}
circ_attribs = {'style':simplestyle.formatStyle(style),
- 'inkscape:label':name,
+ inkex.addNS('label','inkscape'):name,
'r':str(st.r),
'cx':str(cx), 'cy':str(-cy)}
inkex.etree.SubElement(parent, inkex.addNS('circle','svg'), circ_attribs )
#sys.stderr.write(str(p1))
style = { 'stroke': '#000000', 'stroke-width':str(st.th)}
line_attribs = {'style':simplestyle.formatStyle(style),
- 'inkscape:label':name,
+ inkex.addNS('label','inkscape'):name,
'd':'M '+str(x1)+','+str(-y1)+' L '+str(x2)+','+str(-y2)}
inkex.etree.SubElement(parent, inkex.addNS('path','svg'), line_attribs )
d = d + 'z' #close the polygon
line_attribs = {'style':simplestyle.formatStyle(style),
- 'inkscape:label':name,'d': d}
+ inkex.addNS('label','inkscape'):name,'d': d}
inkex.etree.SubElement(parent, inkex.addNS('path','svg'), line_attribs )
def get_normal( pts, face): #returns the normal vector for the plane passing though the first three elements of face of pts
@@ -235,13 +230,14 @@ class Obj(object): #a 3d object defined by the vertices and the faces (eg a poly
def __init__(self):
None
-class Draw_From_Triangle(inkex.Effect):
+class Poly_3D(inkex.Effect):
def __init__(self):
inkex.Effect.__init__(self)
self.OptionParser.add_option("--tab",
action="store", type="string",
dest="tab", default="object")
+#MODEL FILE SETTINGS
self.OptionParser.add_option("--obj",
action="store", type="string",
dest="obj", default='cube')
self.OptionParser.add_option("--cw_wound",
action="store", type="inkbool",
dest="cw_wound", default='true')
+ self.OptionParser.add_option("--type",
+ action="store", type="string",
+ dest="type", default='face')
#VEIW SETTINGS
self.OptionParser.add_option("--r1_ax",
action="store", type="string",
st.linejoin = 'round'
file = ''
- obj = Obj() #create the object
if so.obj == 'cube':
file = 'cube.obj'
elif so.obj == 't_cube':
file = 'trunc_dodec.obj'
elif so.obj == 'from_file':
file = so.spec_file
+
+ obj = Obj() #create the object
get_obj_data(obj, file)
+ obj.type=''
+ if so.type == 'face':
+ if len(obj.fce) > 0:
+ obj.type = 'face'
+ else:
+ sys.stderr.write('No face data found in specified file\n')
+ obj.type = 'error'
+ else:
+ if len(obj.edg) > 0:
+ obj.type = 'edge'
+ else:
+ sys.stderr.write('No edge data found in specified file\n')
+ obj.type = 'error'
+
trans_mat = mat(identity(3, float)) #init. trans matrix as identity matrix
#perform rotations
face_no = z_list[i][3]#the number of the face to draw
draw_SVG_poly(vp_pts, obj.fce[ face_no ], st, 'Face:'+str(face_no), proj)
else:
- sys.stderr.write('The selected file does not contain face data.\nPlease select point or edge plotting options.')
+ sys.stderr.write('Face Data Not Found. Ensure file contains face data, and check the file is imported as "Face-Specifed" under the "Model File" tab.\n')
else:
- sys.stderr.write('Internal Error. No view type selected')
+ sys.stderr.write('Internal Error. No view type selected\n')
-e = Draw_From_Triangle()
+e = Poly_3D()
e.affect()
+
index 22c8633f05ea4ed3d1db6e5658d3c428b74cd11f..a50904b3f4d4f15f116920c2c922e714d02dfeb3 100644 (file)
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-'''\r
+'''
import inkex
import simplestyle, sys
def draw_SVG_tri( (x1, y1), (x2, y2), (x3, y3), (ox,oy), width, name, parent):
style = { 'stroke': '#000000', 'stroke-width':str(width), 'fill': 'none' }
tri_attribs = {'style':simplestyle.formatStyle(style),
- 'inkscape:label':name,
+ inkex.addNS('label','inkscape'):name,
'd':'M '+str(x1+ox)+','+str(y1+oy)+
' L '+str(x2+ox)+','+str(y2+oy)+
' L '+str(x3+ox)+','+str(y3+oy)+
e = Grid_Polar()
e.affect()
+