Since I hit a pothole with my other script, I decided to try out Assimp with the Python bindings.
Here's the script itself:
# -- coding: utf-8 --
import pyassimp
import os,sys
from os import path
from sys import argv
import string
#print argv
input = ""
output = ""
if len(argv) == 1: sys.exit()
elif len(argv) == 2:
input = argv[1]
output = input[input.find(".")+1:] + ".ago"
else:
input = argv[1]
output = argv[2]
fileOut = open(output,'w')
obj = pyassimp.load(input)
fileOut.write("Object\n{\n")
fileOut.write("RightHand{0}\n")
fileOut.write("Position{0,0,0}\n")
fileOut.write("RotationQ{1,0,0,0}\n\n")
#vertices
verts = 0
for i,mesh in enumerate(obj.meshes):
verts += len(mesh.vertices)
fileOut.write("VertexCount{" + str(verts) + "}\n")
fileOut.write("VertexAttrib\n{\nName{\"position\"}\nType{\"Float\"}\nComponents{3}\nNormalize{\"no\"}\nData\n{\n")
inc = 0
for i,mesh in enumerate(obj.meshes):
for j in mesh.vertices:
inc += 1
d = str(j).strip("[]")
fileOut.write(d)
if inc == verts:
fileOut.write("\n")
else:
fileOut.write(",\n")
fileOut.write("}\n\n")
normals = 0
for i,mesh in enumerate(obj.meshes):
normals += len(mesh.normals)
fileOut.write("VertexAttrib\n{\nName{\"normal\"}\nType{\"Float\"}\nComponents{3}\nNormalize{\"no\"}\nData\n{\n")
inc = 0
for i,mesh in enumerate(obj.meshes):
for j in mesh.normals:
inc += 1
d = str(j).strip("[]")
fileOut.write(d)
if inc == normals:
fileOut.write("\n")
else:
fileOut.write(",\n")
fileOut.write("}\n\n")
uvs = 0
for i,mesh in enumerate(obj.meshes):
for j in mesh.texcoords:
for k in j:
if str(k) != "None":
uvs += 1
fileOut.write("VertexAttrib\n{\nName{\"uv\"}\nType{\"Float\"}\nComponents{2}\nNormalize{\"no\"}\nData\n{\n")
inc = 0
write = 0
for i,mesh in enumerate(obj.meshes):
for j in mesh.texcoords:
for k in j:
if str(k) != "None":
d = str(k).strip("[]")
fileOut.write(d)
inc += 1
if inc == uvs:
fileOut.write("\n")
else:
fileOut.write(",\n")
fileOut.write("}\n\n")
indices = 0
for i,mesh in enumerate(obj.meshes):
for j in mesh.faces:
indices += len(j.indices)
fileOut.write("IndexCount{"+str(indices)+"}\n")
fileOut.write("Indices\n{\n")
inc = 0
for i,mesh in enumerate(obj.meshes):
for j in mesh.faces:
inc += 1
x = int(j.indices[0])
y = int(j.indices[1])
z = int(j.indices[2])
v = [x,y,z]
d = str(v).strip("[]")
fileOut.write(d)
if inc == indices:
fileOut.write("\n")
else:
fileOut.write(",\n")
fileOut.write("}\n\n")
for i,mat in enumerate(obj.materials):
props = pyassimp.GetMaterialProperties(mat)
texture = props['$tex.file']
fileOut.write("Texture\n{\n")
fileOut.write("Stage{"+str(i)+"}\n")
fileOut.write("Filename{\""+texture+"\"}\n")
fileOut.write("}\n")
fileOut.write("\n")
fileOut.write("}\n")
pyassimp.release(obj)
And here's the output for a basic cube(3ds format with a single assigned texture):
Object
{
RightHand{0}
Position{0,0,0}
RotationQ{1,0,0,0}
VertexCount{36}
VertexAttrib
{
Name{"position"}
Type{"Float"}
Components{3}
Normalize{"no"}
Data
{
-25.0, -25.0, 0.0,
-25.0, 25.0, 0.0,
25.0, 25.0, 9.094947017729282e-13,
25.0, 25.0, 9.094947017729282e-13,
25.0, -25.0, 0.0,
-25.0, -25.0, 0.0,
-25.0, -25.0, 50.0,
25.0, -25.0, 49.999996185302734,
25.0, 25.0, 50.0,
25.0, 25.0, 50.0,
-25.0, 25.0, 50.000003814697266,
-25.0, -25.0, 50.0,
-25.0, -25.0, 0.0,
25.0, -25.0, 0.0,
25.0, -25.0, 49.999996185302734,
25.0, -25.0, 49.999996185302734,
-25.0, -25.0, 50.0,
-25.0, -25.0, 0.0,
25.0, -25.0, 0.0,
25.0, 25.0, 9.094947017729282e-13,
25.0, 25.0, 50.0,
25.0, 25.0, 50.0,
25.0, -25.0, 49.999996185302734,
25.0, -25.0, 0.0,
25.0, 25.0, 9.094947017729282e-13,
-25.0, 25.0, 0.0,
-25.0, 25.0, 50.000003814697266,
-25.0, 25.0, 50.000003814697266,
25.0, 25.0, 50.0,
25.0, 25.0, 9.094947017729282e-13,
-25.0, 25.0, 0.0,
-25.0, -25.0, 0.0,
-25.0, -25.0, 50.0,
-25.0, -25.0, 50.0,
-25.0, 25.0, 50.000003814697266,
-25.0, 25.0, 0.0
}
VertexAttrib
{
Name{"normal"}
Type{"Float"}
Components{3}
Normalize{"no"}
Data
{
-1.954051434481757e-15, 3.552713678800501e-15, -1.0,
-1.9540512227235202e-15, 0.0, -1.0,
-1.954051434481757e-15, 3.552713678800501e-15, -1.0,
-1.954051434481757e-15, 3.552713678800501e-15, -1.0,
-1.9540518579982307e-15, 1.0658141036401503e-14, -1.0,
-1.954051434481757e-15, 3.552713678800501e-15, -1.0,
1.0332787070410632e-08, -3.2582555320459505e-08, 1.0,
1.0332787070410632e-08, -3.2582555320459505e-08, 1.0,
1.0332787070410632e-08, -3.2582555320459505e-08, 1.0,
1.0332787070410632e-08, -3.2582555320459505e-08, 1.0,
1.0332787070410632e-08, -3.2582555320459505e-08, 1.0,
1.0332787070410632e-08, -3.2582555320459505e-08, 1.0,
6.556508225230573e-09, -1.0, 5.564416483139212e-09,
6.556508225230573e-09, -1.0, 5.564416483139212e-09,
6.556508225230573e-09, -1.0, 5.564416483139212e-09,
6.556508225230573e-09, -1.0, 5.564416483139212e-09,
6.556508225230573e-09, -1.0, 5.564416483139212e-09,
6.556508225230573e-09, -1.0, 5.564416483139212e-09,
1.0, 4.470347292340193e-08, -1.0332797728551668e-08,
1.0, 4.470347647611561e-08, -1.0332811939406383e-08,
1.0, 4.470347292340193e-08, -1.0332797728551668e-08,
1.0, 4.470347292340193e-08, -1.0332797728551668e-08,
1.0, 4.470347292340193e-08, -1.0332797728551668e-08,
1.0, 4.470347292340193e-08, -1.0332797728551668e-08,
-6.556508225230573e-09, 1.0, -5.564416483139212e-09,
-6.556508225230573e-09, 1.0, -5.564416483139212e-09,
-6.556508225230573e-09, 1.0, -5.564416483139212e-09,
-6.556508225230573e-09, 1.0, -5.564416483139212e-09,
-6.556508225230573e-09, 1.0, -5.564416483139212e-09,
-6.556508225230573e-09, 1.0, -5.564416483139212e-09,
-1.0, -4.470347292340193e-08, 1.0332797728551668e-08,
-1.0, -4.470347647611561e-08, 1.0332783517696953e-08,
-1.0, -4.470347292340193e-08, 1.0332797728551668e-08,
-1.0, -4.470347292340193e-08, 1.0332797728551668e-08,
-1.0, -4.470347292340193e-08, 1.0332797728551668e-08,
-1.0, -4.470347292340193e-08, 1.0332797728551668e-08
}
VertexAttrib
{
Name{"uv"}
Type{"Float"}
Components{2}
Normalize{"no"}
Data
{
0.6936095952987671, 0.3082272410392761, 0.0,
0.6936095952987671, 0.645868182182312, 0.0,
0.351714551448822, 0.645868182182312, 0.0,
0.351714551448822, 0.645868182182312, 0.0,
0.351714551448822, 0.3082272410392761, 0.0,
0.6936095952987671, 0.3082272410392761, 0.0,
-3.3104251978555155e-11, 0.6524245738983154, 0.0,
0.3475855588912964, 0.6524245738983154, 0.0,
0.3475855588912964, 1.0, 0.0,
0.3475855588912964, 1.0, 0.0,
-3.3104251978555155e-11, 1.0, 0.0,
-3.3104251978555155e-11, 0.6524245738983154, 0.0,
0.34779873490333557, 0.6524086594581604, 0.0,
0.6952096819877625, 0.6524086594581604, 0.0,
0.6952096819877625, 1.0, 0.0,
0.6952096819877625, 1.0, 0.0,
0.34779873490333557, 1.0, 0.0,
0.34779873490333557, 0.6524086594581604, 0.0,
0.3557146191596985, 0.007936698384582996, 0.0,
0.6539586186408997, 0.007936698384582996, 0.0,
0.6539586186408997, 0.29903289675712585, 0.0,
0.6539586186408997, 0.29903289675712585, 0.0,
0.3557146191596985, 0.29903289675712585, 0.0,
0.3557146191596985, 0.007936698384582996, 0.0,
0.28715628385543823, 0.002442082855850458, 0.0,
0.003663074690848589, 0.002442082855850458, 0.0,
0.003663074690848589, 0.29920879006385803, 0.0,
0.003663074690848589, 0.29920879006385803, 0.0,
0.28715628385543823, 0.29920879006385803, 0.0,
0.28715628385543823, 0.002442082855850458, 0.0,
0.0023606165777891874, 0.3059607744216919, 0.0,
0.34674692153930664, 0.3059607744216919, 0.0,
0.34674692153930664, 0.6515564322471619, 0.0,
0.34674692153930664, 0.6515564322471619, 0.0,
0.0023606165777891874, 0.6515564322471619, 0.0,
0.0023606165777891874, 0.3059607744216919, 0.0
}
IndexCount{36}
Indices
{
0, 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,
}
Texture
{
Stage{0}
Filename{"TEST.PNG"}
}
}
I've attached a ZIP containing all the necessary files.
To use the script, you can either drop a file onto it and it'll create a new file with the same name but extension ".ago" or you can use the commandline and designate an entirely new filename.