polyhedron_3d.py revision 9fefe969c78790b255996a6fa8ebe02c403761ba
'''
Copyright (C) 2007 John Beard john.j.beard@gmail.com
##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
# |
# __--``| |_--``| __--
# __--`` | __--``| |_--``
# | z | | |_--``|
# | <----|--------|-----_0-----|----------------
# | | |_--`` | |
# | __--`` <-``| |_--``
# |__--`` x |__--``|
# IMAGE PLANE SCENE|
# |
#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
#Faces are given by a list of vertices
#(vertex 1 is the first in the list above, 2 the second, etc):
#f 1 2 3
#Edges are given by a list of vertices. These will be broken down
#into adjacent pairs. Each edge can connect only two vertices
#l 1 2 3
#Faces are rendered according to the painter's algorithm and perhaps
#back-face culling, if selected. The parameter to sort the faces by
#is user-selectable
######LICENCE#######
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
'''
import inkex
from math import *
try:
from numpy import *
except:
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.")
if __name__ == '__main__':
else:
return path
#regular expressions
getname = '(.[nN]ame:\\s*)(.*)'
floating = '([\-\+\\d*\.e]*)'
getedgeline = '(l\\s+)(.*)'
getfaceline = '(f\\s+)(.*)'
if m:
if m: #we have a valid vertex
if m:#we have a line beginning 'l '
vtxlist = []#buffer
while line:
if m2:
else:
line = None
if m:#we have a line beginning 'l '
vtxlist = []#buffer
while line:
if m2:
else:
line = None
style = { 'stroke': '#000000', 'stroke-width':str(st.th), 'fill': st.fill, 'stroke-opacity':st.s_opac, 'fill-opacity':st.f_opac}
#sys.stderr.write(str(p1))
if i == 0:#for first point
d = 'M'#move to
else:
d = d + 'L'#line to
d = d + 'z' #close the polygon
def get_normal( pts, face): #returns the normal vector for the plane passing though the first three elements of face of pts
#n = pt[0]->pt[1] x pt[0]->pt[3]
return max_z
return min_z
sum = 0
[ 0 , 0 , 1 ]]))
[ 0 , 1 , 0 ],
edge_list = []
edge_list.append( [face_list[i][j], face_list[i][(j+1)%edges] ] )#get the vertex pair between that vertex and the next
del edge_list[i]
else:
return edge_list
None
#edges can be generated from this information
None
#MODEL FILE SETTINGS
#VEIW SETTINGS
#STYLE SETTINGS
st.r = 2
file = ''
file = 'cube.obj'
file = 'trunc_cube.obj'
file = 'snub_cube.obj'
file = 'cuboct.obj'
file = 'tet.obj'
file = 'trunc_tet.obj'
file = 'oct.obj'
file = 'trunc_oct.obj'
file = 'icos.obj'
file = 'trunc_icos.obj'
file = 'small_triam_icos.obj'
file = 'great_stel_dodec.obj'
file = 'dodec.obj'
file = 'snub_dodec.obj'
file = 'great_dodec.obj'
file = 'trunc_dodec.obj'
else:
else:
else:
#perform rotations
if axis == 'x':
elif axis == 'y':
elif axis == 'z':
# Embed points in group
#Put in in the centre of the current view
#we will put all the rotations in the object name, so it can be repeated in future
'transform':t }
vp_pts=[] #the points as projected in the z-axis onto the viewplane
vp_pts.append((so.scl* (trans_mat * mat(obj.vtx[i]).T)).T.tolist()[0] )#transform the points at add to vp_pts
else:#we already have an edge list
else: rev = 1
z_list = []
else:
if i == 0:
z_list.append((z_sort_param, angle, norm, i) ) #record the maximum z-value of the face and angle to light, along with the face ID and normal
else:
else:
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:
e = Poly_3D()
e.affect()