updated to modern VTK
[engrid-github.git] / src / blender_scripts / 2.4 / engrid_import.py
blob3fcad7fbbbea8a8e031532a6476829d03cc37e39
1 #!BPY
2 # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 # + +
4 # + This file is part of enGrid. +
5 # + +
6 # + Copyright 2008-2014 enGits GmbH +
7 # + +
8 # + enGrid is free software: you can redistribute it and/or modify +
9 # + it under the terms of the GNU General Public License as published by +
10 # + the Free Software Foundation, either version 3 of the License, or +
11 # + (at your option) any later version. +
12 # + +
13 # + enGrid is distributed in the hope that it will be useful, +
14 # + but WITHOUT ANY WARRANTY; without even the implied warranty of +
15 # + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +
16 # + GNU General Public License for more details. +
17 # + +
18 # + You should have received a copy of the GNU General Public License +
19 # + along with enGrid. If not, see <http://www.gnu.org/licenses/>. +
20 # + +
21 # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 """
24 Name: 'Engrid (*.begc)'
25 Blender: 249
26 Group: 'Import'
27 Tooltip: 'Import from Engrid'
28 """
30 import Blender
31 import bpy
32 import BPyAddMesh
34 def readEngrid(filename):
35 Blender.Window.WaitCursor(1)
36 Vector = Blender.Mathutils.Vector
38 in_file = file(filename, "r")
39 line = in_file.readline()
40 Nobjects = int(line)
41 #print "Nobjects=",Nobjects
42 object_names = []
43 for i in range(0, Nobjects):
44 line = in_file.readline()
45 object_names.append(line.strip())
47 #print "object_names=",object_names
49 global_verts = []
50 offset = 0
51 for i_object in range(0, Nobjects):
52 line = in_file.readline()
53 words = line.split()
54 Nverts = int(words[0])
55 Nfaces = int(words[1])
56 #print "Nverts=",Nverts
57 #print "Nfaces=",Nfaces
59 local_verts = []
60 for i_vert in range(0, Nverts):
61 line = in_file.readline()
62 words = line.split()
63 x = float(words[0])
64 y = float(words[1])
65 z = float(words[2])
66 #print "x,y,z=",x,y,z
67 local_verts.append( Vector(x,y,z) )
68 global_verts.append( Vector(x,y,z) )
70 faces = []
71 for i_face in range(0, Nfaces):
72 line = in_file.readline()
73 words = line.split()
74 if len(words) < 3:
75 Blender.Draw.PupMenu('Error%t|File format error 4')
76 return
77 Nverts_in_face = int(words[0])
78 if len(words) != 1 + Nverts_in_face:
79 Blender.Draw.PupMenu('Error%t|File format error 5')
80 return
81 face_verts = []
82 for i_face_vert in range(0, Nverts_in_face):
83 idx = int(words[i_face_vert + 1]) - offset
84 face_verts.append(idx)
85 #print "face_verts=",face_verts
86 faces.append(face_verts)
88 #print "Adding object ",object_names[i_object]
89 BPyAddMesh.add_mesh_simple(object_names[i_object], local_verts, [], faces)
91 offset += Nverts
93 in_file.close()
95 Blender.Window.WaitCursor(0)
96 Blender.Window.RedrawAll()
98 Blender.Window.FileSelector(readEngrid, "Import", Blender.sys.makename(ext='.begc'))