ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/txtprt.py
Revision: 1.4
Committed: Sun Oct 3 05:07:01 2004 UTC (19 years, 8 months ago) by root
Content type: text/x-python
Branch: MAIN
Changes since 1.3: +9 -3 lines
Log Message:
Getting location information from blender

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