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