Code: Select all
#!BPY
"""
Name: 'CMOD (.cmod)...'
Blender: 240
Group: 'Export'
Tooltip: 'cmod exporter'
"""
import Blender
from Blender import *
import sys
global MTL_DICT
MTL_DICT = {}
def write_obj(filepath):
out = file(filepath, 'w')
object = Blender.Object.GetSelected()[0]
#mesh = object.getData()
mesh = NMesh.GetRawFromObject(object.name)
mesh.transform(object.matrix)
a = 0
b = 0
c = 0
d = 0
# file header need to add real materials vertexdesc is dangerous may not have uvcoords
out.write('#celmodel__ascii\n\n')
out.write('material\n')
out.write('end_material\n\n')
out.write('mesh\n')
out.write('vertexdesc\n')
out.write('position f3\n')
out.write('normal f3\n')
out.write('texcoord0 f2\n')
out.write('end_vertexdesc\n\n')
#counter for vertice desc
#This part goes thru the list twice counting for a the verts 1,2,3 and 0,1,2
#it counts the number of triangles to build.
for face in mesh.faces:
d = 0
for vert in face.v:
if d <= 0:
d +=1
else:
a +=1
d +=1
d = 0
for face in mesh.faces:
for vert in face.v:
if d >= 3:
d +=1
else:
a +=1
d +=1
d = 0
out.write( 'vertices %i\n' % (a))
# writes a line for verts 2,3,0 and 0,1,2.
for face in mesh.faces:
out.write( '%f %f %f %f %f %f' % (face.v[2].co.x, face.v[2].co.y, face.v[2].co.z, face.v[2].no.x, face.v[2].no.z, face.v[2].no.y,))
out.write( ' %f %f\n' % face.uv[2])
out.write( '%f %f %f %f %f %f' % (face.v[3].co.x, face.v[3].co.y, face.v[3].co.z, face.v[3].no.x, face.v[3].no.z, face.v[3].no.y,))
out.write( ' %f %f\n' % face.uv[3])
out.write( '%f %f %f %f %f %f' % (face.v[0].co.x, face.v[0].co.y, face.v[0].co.z, face.v[0].no.x, face.v[0].no.z, face.v[0].no.y,))
out.write( ' %f %f\n' % face.uv[0])
out.write( '%f %f %f %f %f %f' % (face.v[0].co.x, face.v[0].co.y, face.v[0].co.z, face.v[0].no.x, face.v[0].no.z, face.v[0].no.y,))
out.write( ' %f %f\n' % face.uv[0])
out.write( '%f %f %f %f %f %f' % (face.v[1].co.x, face.v[1].co.y, face.v[1].co.z, face.v[1].no.x, face.v[1].no.z, face.v[1].no.y,))
out.write( ' %f %f\n' % face.uv[1])
out.write( '%f %f %f %f %f %f' % (face.v[2].co.x, face.v[2].co.y, face.v[2].co.z, face.v[2].no.x, face.v[2].no.z, face.v[2].no.y,))
out.write( ' %f %f\n' % face.uv[2])
out.write( '\n\ntrilist %i %i\n' % (b, a))
#write the triangle list 12 per line
while b < a:
if c <= 12:
if b <= a:
out.write( '%i ' % (b))
b +=1
c +=1
else:
out.write( '\n' )
else:
out.write( '\n' )
c = 0
out.write( '\n\nend_mesh' )
out.close()
Blender.Window.FileSelector(write_obj, "Export", Blender.sys.makename(ext='.cmod' ))
Here some screenshots of the 524288 model.
And a copy of the SSC file.
Code: Select all
"valley" "Sol/Mars"
{
Mesh "valley.cmod"
Texture "flipped-valley.png"
Radius 1220 #small
LongLat [ 291.75 -12.0 -255 ]
Albedo 0.150
}
cartrite