ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/txtprt.py
Revision: 1.5
Committed: Sun Oct 3 23:34:02 2004 UTC (19 years, 8 months ago) by root
Content type: text/x-python
Branch: MAIN
CVS Tags: knowngood, old_matrix
Changes since 1.4: +10 -2 lines
Log Message:
und es laeuft

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    
22     # dump -- the object dumper f: File, o: object
23 root 1.4 def dump(f, o, od):
24 root 1.1 if o.block_type == 'NMesh' :
25     mesh = Blender.NMesh.GetRaw(o.name)
26     f.write("M " + o.name + "\n")
27 root 1.4 loc = od.getLocation ()
28     f.write("L L\n" + `loc[0]` + " " + `loc[2]` + " " + `loc[1]` + "\n")
29 root 1.2 f.write("T Material\n");
30    
31     if len (mesh.materials) > 0:
32     material = mesh.materials[0]
33     c0 = material.rgbCol[0]
34     c1 = material.rgbCol[1]
35     c2 = material.rgbCol[2]
36     f.write(`c0` + " " + `c1` + " " + `c2` + " " + `material.alpha` + "\n");
37     s0 = material.specCol[0]
38     s1 = material.specCol[1]
39     s2 = material.specCol[2]
40     f.write(`s0` + " " + `s1` + " " + `s2` + " " + `material.specTransp` + "\n");
41     s0 *= material.emit
42     s1 *= material.emit
43     s2 *= material.emit
44     f.write(`s0` + " " + `s1` + " " + `s2` + " 1\n");
45 root 1.3 f.write(`material.spec` + "\n");
46 root 1.2 else:
47     f.write("1 1 1 1\n");
48     f.write("0 0 0 1\n");
49     f.write("0 0 0 1\n");
50 root 1.3 f.write("0\n");
51 root 1.2
52 root 1.1
53     # Vertex Coordinate header
54     f.write("V " + `len(mesh.verts)` + "\n")
55    
56     # Verticies
57     for vert in mesh.verts:
58 root 1.3 f.write(`vert.co[0]` + " " + `vert.co[2]` + " " + `vert.co[1]` + "\n")
59 root 1.1
60     # Vertex Normal Header
61     f.write("N " + `len(mesh.verts)` + "\n")
62     # Vertex Normals
63     for vert in mesh.verts:
64 root 1.3 f.write(`vert.no[0]` + " " + `vert.no[2]` + " " + `vert.no[1]` + "\n")
65 root 1.1
66     # uv coordinates
67     if mesh.hasVertexUV:
68     # UV header
69     f.write("U " + `len(mesh.verts)` + "\n")
70     for vert in mesh.verts:
71     f.write(`vert.uvco[0]` + " " + `vert.uvco[1]` + "\n")
72    
73    
74     # Faces: Take two passes: First, count the total number of faces,
75     # second: output them. Tessalate quads to triangles. Discard edges (which
76     # have only two vertices)
77     # Modified to use only one pass, by building a variable with the text
78     faces = len(mesh.faces)
79     data = ""
80     colordata = ""
81     for face in mesh.faces:
82 root 1.5 if len (face.v) < 3:
83     faces = faces - 1
84     elif len (face.v) == 3:
85 root 1.2 # triangle
86 root 1.3 data = data + `face.v[0].index` + " " + `face.v[2].index` + " " + `face.v[1].index` + "\n"
87 root 1.5 data = data + `face.smooth` + "\n"
88 root 1.1 else:
89     # this one is a quad
90     # Break it up into two triangles
91     # Hence one additional face
92     faces = faces + 1
93 root 1.2
94 root 1.3 data = data + `face.v[0].index` + " " + `face.v[3].index` + " " + `face.v[1].index` + "\n"
95 root 1.5 data = data + `face.smooth` + "\n"
96    
97 root 1.3 data = data + `face.v[1].index` + " " + `face.v[3].index` + " " + `face.v[2].index` + "\n"
98 root 1.5 data = data + `face.smooth` + "\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    
104    
105     #Stage 1:
106     # Gather information -- which objects, which frames, what type of export
107    
108     # Objects to export: Use the set of selected objects
109     objectsToExport = Blender.Object.GetSelected()
110    
111     # Which frames:
112     startFrame = Blender.Get('staframe')
113     endFrame = Blender.Get('endframe')
114     frameset = range(startFrame, endFrame + 1)
115    
116    
117     # Create a file for output
118     filename = Blender.Get('filename') + '.blasc'
119     print('Exporting ' + filename + ' frames:')
120     print(frameset)
121    
122     fout = open(filename, 'w')
123    
124     # Go through the objects and export them
125    
126     # output file header
127    
128     #for ob in objectsToExport:
129     ob = objectsToExport[0]
130 root 1.4 objs = len (objectsToExport)
131 root 1.1 # output object header
132     print('Exporting Object ' + ob.name)
133 root 1.4 fout.write("O " + `objs` + "\n")
134    
135     for i in objectsToExport:
136     dump (fout, i.data, i)
137 root 1.1 #for fr in frameset:
138     # Blender.Set('curframe', fr)
139     #print('Exporting Frame ' + `fr`)
140    
141     # output frame header
142     #fout.write("F " + `fr` + "\n")
143    
144     # Write out common items
145     #fout.write("Y " + `ob.data.block_type` + "\n")
146     #fout.write("L " + `ob.LocX + ob.dLocX` + " " + `ob.LocY + ob.dLocY` + " " + `ob.LocZ + ob.dLocZ` + "\n")
147     #fout.write("R " + `ob.RotX + ob.dRotX` + " " + `ob.RotY + ob.dRotY` + " " + `ob.RotZ + ob.dRotZ` + "\n")
148     #fout.write("S " + `ob.SizeX + ob.dSizeX` + " " + `ob.SizeY + ob.dSizeY` + " " + `ob.SizeZ + ob.dSizeZ` + "\n")
149    
150     # Write out the data
151    
152     # output Frame footer
153     #fout.write("/F\n")
154     #Output object footer
155    
156     # Close the file
157     fout.close();
158    
159     print('Done!')