ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/libgender/txtprt.py
Revision: 1.9
Committed: Thu Jan 6 02:15:17 2005 UTC (21 years, 9 months ago) by root
Content type: text/x-python
Branch: MAIN
CVS Tags: HEAD
Changes since 1.8: +4 -32 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 #!BPY
2    
3     """
4 root 1.2 Name: 'Textport save'
5 root 1.1 Blender: 234
6     Group: 'Export'
7     Tooltip: 'Textport exporter for libgender'
8     """
9    
10     # Blender Text Export Module
11     # Version 0.0
12     # Colin Peart
13     # Released under GPL (insert license text here)
14    
15     import Blender
16 root 1.5 from Blender import Types, Object, NMesh, Camera, Lamp, Mathutils
17     from Blender.Mathutils import *
18    
19 root 1.1 import sys
20    
21     # dump -- the object dumper f: File, o: object
22 root 1.4 def dump(f, o, od):
23 root 1.1 if o.block_type == 'NMesh' :
24     mesh = Blender.NMesh.GetRaw(o.name)
25     f.write("M " + o.name + "\n")
26 root 1.4 loc = od.getLocation ()
27 root 1.7 f.write("L L\n" + `loc[0]` + " " + `loc[1]` + " " + `loc[2]` + "\n")
28 root 1.2 f.write("T Material\n");
29    
30     if len (mesh.materials) > 0:
31     material = mesh.materials[0]
32     c0 = material.rgbCol[0]
33     c1 = material.rgbCol[1]
34     c2 = material.rgbCol[2]
35     f.write(`c0` + " " + `c1` + " " + `c2` + " " + `material.alpha` + "\n");
36     s0 = material.specCol[0]
37     s1 = material.specCol[1]
38     s2 = material.specCol[2]
39     f.write(`s0` + " " + `s1` + " " + `s2` + " " + `material.specTransp` + "\n");
40     s0 *= material.emit
41     s1 *= material.emit
42     s2 *= material.emit
43     f.write(`s0` + " " + `s1` + " " + `s2` + " 1\n");
44 root 1.3 f.write(`material.spec` + "\n");
45 root 1.2 else:
46     f.write("1 1 1 1\n");
47     f.write("0 0 0 1\n");
48     f.write("0 0 0 1\n");
49 root 1.3 f.write("0\n");
50 root 1.2
51 root 1.1
52     # Vertex Coordinate header
53     f.write("V " + `len(mesh.verts)` + "\n")
54    
55     # Verticies
56     for vert in mesh.verts:
57 root 1.7 f.write(`vert.co[0]` + " " + `vert.co[1]` + " " + `vert.co[2]` + "\n")
58 root 1.1
59     # Vertex Normal Header
60     f.write("N " + `len(mesh.verts)` + "\n")
61     # Vertex Normals
62     for vert in mesh.verts:
63 root 1.7 f.write(`vert.no[0]` + " " + `vert.no[1]` + " " + `vert.no[2]` + "\n")
64 root 1.1
65     # Faces: Take two passes: First, count the total number of faces,
66     # second: output them. Tessalate quads to triangles. Discard edges (which
67     # have only two vertices)
68     # Modified to use only one pass, by building a variable with the text
69     faces = len(mesh.faces)
70     data = ""
71     colordata = ""
72     for face in mesh.faces:
73 root 1.5 if len (face.v) < 3:
74     faces = faces - 1
75     elif len (face.v) == 3:
76 root 1.2 # triangle
77 root 1.8 data = data + `face.v[0].index` + " " + `face.v[1].index` + " " + `face.v[2].index` + "\n"
78 root 1.5 data = data + `face.smooth` + "\n"
79 root 1.6 data = data + `face.uv[0][0]` + " " + `face.uv[0][1]` + "\n"
80 root 1.7 data = data + `face.uv[1][0]` + " " + `face.uv[1][1]` + "\n"
81 root 1.6 data = data + `face.uv[2][0]` + " " + `face.uv[2][1]` + "\n"
82 root 1.1 else:
83     # this one is a quad
84     # Break it up into two triangles
85     # Hence one additional face
86     faces = faces + 1
87 root 1.2
88 root 1.7 data = data + `face.v[0].index` + " " + `face.v[1].index` + " " + `face.v[3].index` + "\n"
89 root 1.5 data = data + `face.smooth` + "\n"
90 root 1.6 data = data + `face.uv[0][0]` + " " + `face.uv[0][1]` + "\n"
91 root 1.7 data = data + `face.uv[1][0]` + " " + `face.uv[1][1]` + "\n"
92 root 1.6 data = data + `face.uv[3][0]` + " " + `face.uv[3][1]` + "\n"
93 root 1.5
94 root 1.7 data = data + `face.v[1].index` + " " + `face.v[2].index` + " " + `face.v[3].index` + "\n"
95 root 1.5 data = data + `face.smooth` + "\n"
96 root 1.6 data = data + `face.uv[1][0]` + " " + `face.uv[1][1]` + "\n"
97 root 1.7 data = data + `face.uv[2][0]` + " " + `face.uv[2][1]` + "\n"
98 root 1.6 data = data + `face.uv[3][0]` + " " + `face.uv[3][1]` + "\n"
99 root 1.1 # Now I can write the header with the correct face count, and then the data
100     f.write("A " + `faces` + "\n")
101     f.write(data)
102    
103 root 1.9 ################################################################################
104 root 1.1
105    
106     objectsToExport = Blender.Object.GetSelected()
107    
108     startFrame = Blender.Get('staframe')
109     endFrame = Blender.Get('endframe')
110     frameset = range(startFrame, endFrame + 1)
111    
112    
113     filename = Blender.Get('filename') + '.blasc'
114     print('Exporting ' + filename + ' frames:')
115     print(frameset)
116    
117     fout = open(filename, 'w')
118    
119     ob = objectsToExport[0]
120 root 1.4 objs = len (objectsToExport)
121 root 1.9
122 root 1.1 print('Exporting Object ' + ob.name)
123 root 1.4 fout.write("O " + `objs` + "\n")
124    
125     for i in objectsToExport:
126     dump (fout, i.data, i)
127 root 1.1
128     fout.close();
129    
130     print('Done!')
131 root 1.9
132