This repository has been archived by the owner on Jan 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rogimodel_export.py
59 lines (42 loc) · 1.56 KB
/
rogimodel_export.py
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
#!BPY
"""
Name: 'Rogi Model Export'
Blender: 243
Group: 'Export'
Tooltip: 'Rogi Model Exporter'
"""
import Blender
from Blender import *
from struct import *
def writemodel(filepath):
out = file(filepath, 'wb')
scene = Blender.Scene.GetCurrent()
objects = scene.objects.selected
if objects[0].getType() != 'Mesh':
return -1
model = objects[0].data
out.write(pack('=I', len(model.materials)))
print("%ld materials;" %(len(model.materials)))
for material in model.materials:
out.write(pack('=4f', material.R, material.G, material.B, material.alpha))
out.write(pack('=4f', material.R, material.G, material.B, material.alpha))
out.write(pack('=4f', material.specR, material.specG, material.specB, material.alpha))
#out.write(pack('=4f', material.specR, material.specG, material.specB, material.alpha))
out.write(pack('=1f', material.spec))
out.write(pack('=4f', 0, 0, 0, 1))
#out.write(pack('=4f', material.R, material.G, material.B, material.alpha))
out.write(pack('=L', len(model.faces)))
print("%ld polygons;" %(len(model.faces)))
for face in model.faces:
out.write(pack('=I', len(face.v)))
for vert in face.v:
out.write(pack('=3d', vert.co[0], vert.co[1], vert.co[2]))
out.write(pack('=3d', vert.no[0], vert.no[1], vert.no[2]))
out.write(pack('=3d', face.no[0], face.no[1], face.no[2]))
out.write(pack('=I', face.mat))
# out.write(pack('=L', 0))
# out.write(pack('=L', face.image))
# out.write(pack('=L', face.uv))
out.write(pack('=6d', 0, 0, 0, 0, 0, 0))
return 0
Blender.Window.FileSelector(writemodel, 'Export', 'model.r3m')