File: export_raw.python

package info (click to toggle)
k3d 0.4.3.0-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 51,716 kB
  • ctags: 81,610
  • sloc: cpp: 283,698; ansic: 64,095; xml: 61,533; sh: 9,026; makefile: 5,282; python: 431; perl: 308; awk: 130
file content (64 lines) | stat: -rw-r--r-- 1,191 bytes parent folder | download
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
#python


# Export geometry

def Export(Document, FileName):

	# open output file ...
	try:
		exportfile = open(FileName, "w")
	except IOError:
		print "Couldn't open file!"
		return

	# export meshes ...
	objects = Document.mesh_instances()
	for object in objects:
		DumpMesh(object.mesh, object.name, exportfile)

	# export is over
	exportfile.close()


# Serialize mesh object

def DumpMesh(Mesh, Name, File):

	# title
	File.write("# " + str(Name) + "\n")

	# write points
	meshpoints = Mesh.points()
	File.write("# points: " + str(len(meshpoints)) + "\n")
	point_map = {}
	for p in meshpoints:
		val = p.position
		File.write(str(val[0]) + " " + str(val[1]) + " " + str(val[2]))
		File.write("\n")

		point_map[p.reference] = len(point_map)

	# write faces
	meshpolyhedra = Mesh.polyhedra()
	for poln in meshpolyhedra:
		polfaces = poln.faces
		File.write("# faces: " + str(len(polfaces)) + "\n")
		for face in polfaces:
			points = face.points
			for pt in points:
				val = pt.reference
				File.write(str(point_map[val]) + ' ')
			File.write("\n")


# Main

# Find a valid document
if not MyDocument:
	print "No document found\n"
	exit

Export(MyDocument, "k3d_python_export.txt")