Work in progress...
Vääntöjen vääntö, mutta alkaa olla valoa tunnelin päässä.
Updatea. Sanotaan, että alpha 1.
Max toolit
Mesh export
struct meshExportStruct
(
fn exportMesh m strName =
(
t = m.transform
m.transform = (matrix3 [1,0,0] [0,1,0] [0,0,1] [0,0,0])
strMeshData = StringStream ""
iVertCount = m.numVerts
iFaceCount = m.numFaces
aVerts = #()
aFaces = #()
for i=1 to iVertCount do
append aVerts (getVert m i)
for i=1 to iFaceCount do
append aFaces (getFace m i)
format "%\n" strName to:strMeshData
format "%\n" iVertCount to:strMeshData
format "%\n" iFaceCount to:strMeshData
format "%\n" (t.position) to:strMeshData
r = (t.rotation as eulerangles)
format "[%,%,%]\n" (degtorad r.x) (degtorad r.y) (degtorad r.z) to:strMeshData
for i=1 to iVertCount do format "%\n" (aVerts[i]) to:strMeshData
for i=1 to iFaceCount do format "%\n" (aFaces[i]) to:strMeshData
(strMeshData as string)
),
fn export file =
(
strData = StringStream ""
iMeshCount = 0
--try
(
for o in selection do
(
m = snapshot o
iMeshCount += 1
format "%" (exportMesh m (o.name)) to:strData
)
format "%\n" iMeshCount to:file
format "%" (strData as string) to:file
)
--catch
--(
-- messageBox "Can not export meshes. Some object may not be geometry."
-- return undefined
--)
)
)
holdMaxFile()
s = meshExportStruct()
strFile = getSaveFileName "Save mesh file" types:"*.msa|*.msa"
if (strFile != undefined) then
(
format "Exporting mesh...\n"
file = createFile strFile
if (s.export file) != undefined then
messageBox "Mesh exported."
else
messageBox "Mesh export failed. Check your MaxScript listener for details."
close file
format "Mesh exported.\n"
)
else
format "Mesh export cancelled.\n"
fetchMaxFile quiet:true
Animation export
/*
Text animation format export.
Version 1.1
Version list:
1.0
- Basic KF animation export.
- Rotation choices
- euler angles
- angle axis
- quaternions
- Simple UI.
1.1
- Can save transformations as matrices.
*/
rollout DialogRollout "Rollout"
(
group ""
(
label l1 "Ascii animation export"
label l2 "1.1"
label l3 ""
label l4 "Bake animations to every frame and export animation as"
label l5 "custom file format (*.aca)."
)
group "Rotations"
(
radiobuttons rotformat_rbn labels:#("Euler", "Angle axis", "Quaternion")
)
checkbox matrix_chk "Export transforms as matrices." checked:true
label l61
button export_btn " Export animation "
label l7 "Progress" align:#left
progressBar prgbar
on export_btn pressed do
(
objs = #()
transforms = #()
strFile = getSaveFileName "Save TXT" types:"*.txt|*.txt"
if ( strFile != "" ) do
(
format "Writing animation to file % ... please wait...\n" strFile
file = createFile strFile
for o in selection do
append objs o
fProgress = 0.0
fProgressStep = 100.0 / ((abs(animationRange.start - animationRange.end)) as float)
for f=animationRange.start to animationRange.end do
(
at time f
(
in coordsys #world
(
for o in objs do
(
try
(
strLine = (o.name)
strLine += " " + (f.frame as string)
if ( matrix_chk.checked ) then
(
t = o.transform
strLine += " " + (t.row1.x as string) + "," + (t.row1.y as string) + "," + (t.row1.z as string)
strLine += " " + (t.row2.x as string) + "," + (t.row2.y as string) + "," + (t.row2.z as string)
strLine += " " + (t.row3.x as string) + "," + (t.row3.y as string) + "," + (t.row3.z as string)
strLine += " " + (t.row4.x as string) + "," + (t.row4.y as string) + "," + (t.row4.z as string)
)
else
(
p = o.position
strLine += " " + (p.x as string) + "," + (p.y as string) + "," + (p.z as string)
r = o.rotation
case (rotformat_rbn.state) of
(
1: -- Euler
(
r = r as EulerAngles
strLine += " " + ((degToRad r.x) as string) + "," + ((degToRad r.y) as string) + "," + ((degToRad r.z) as string)
)
2: -- Angle axis
(
r = r as AngleAxis
strLine += " " + (r.axis.x as string) + "," + (r.axis.y as string) + "," + (r.axis.z as string) + "," + ((degtorad r.angle) as string)
)
3: -- Quaternion
(
strLine += " " + (r.x as string) + "," + (r.y as string) + "," + (r.z as string) + "," + (r.w as string)
)
)
)
format "%\n" strLine to:file
)
catch
(
format "Error when writing a file.\n"
close file
)
)
)
)
fProgress += fProgressStep
prgbar.value = (fProgress as integer)
)
format "Done\n"
close file
destroyDialog DialogRollout
)
)
)
if ( selection.count > 0 ) do
createDialog DialogRollout 300 280 modal:true
Import animation
file = openFile ( "c:/temp/testAnimation.txt" )
in coordsys #world
(
while (not eof file) do
(
with animate on
(
strLine = readLine file
a = filterString strLine " "
strName = a[1]
strFrame = a[2]
strPos = a[3]
strRot = a[4]
at time ( strFrame as integer )
(
sp = filterString strPos ","
sr = filterString strRot ","
p = Point3 (sp[1] as float) (sp[2] as float) (sp[3] as float)
r = Quat ((sr[1] as float)) ((sr[2] as float)) ((sr[3] as float)) ((sr[4] as float))
n = getNodeByName strName exact:true
n.rotation = r
n.position = p
)
)
)
)
close file
Blender toolit
Mesh import
import Blender
import bpy
def importMesh(filename):
file = open (filename)
strMeshCount = file.readline();
iMeshCount = int ( strMeshCount );
print "Mesh count: " + str (iMeshCount) + "\n";
print "Reading mesh\n";
for i in range (0, iMeshCount):
strMeshName = file.readline();
strMeshName = strMeshName.strip();
print "\tMesh name: " + strMeshName;
strVertCount = file.readline();
iVertCount = int ( strVertCount );
print "\tVertex count: " + str ( iVertCount );
strFaceCount = file.readline();
iFaceCount = int ( strFaceCount );
print "\tFace count: " + str ( iFaceCount );
strPosition = file.readline();
positionArray = [];
a = strPosition.split("[");
a = a[1].split("]");
strXYZ = a[0].split(",");
strX = strXYZ[0];
strY = strXYZ[1];
strZ = strXYZ[2];
positionArray.append(float(strX));
positionArray.append(float(strY));
positionArray.append(float(strZ));
strRotation = file.readline();
rotationArray = [];
a = strRotation.split("[");
a = a[1].split("]");
strXYZ = a[0].split(",");
strX = strXYZ[0];
strY = strXYZ[1];
strZ = strXYZ[2];
rotationArray.append(float(strX));
rotationArray.append(float(strY));
rotationArray.append(float(strZ));
print "\tReading vertices data\n";
verticesArray = [];
for j in range (0, iVertCount):
strVert = file.readline();
a = strVert.split("[");
a = a[1].split("]");
strXYZ = a[0].split(",");
strX = strXYZ[0];
strY = strXYZ[1];
strZ = strXYZ[2];
vertArray = [];
vertArray.append(float(strX));
vertArray.append(float(strY));
vertArray.append(float(strZ));
verticesArray.append( vertArray );
#print (vertArray);
print "\tReading face data\n"
facesArray = [];
for j in range (0, iFaceCount):
strFace = file.readline();
a = strFace.split("[");
a = a[1].split("]");
strABC = a[0].split(",");
strA = strABC[0];
strB = strABC[1];
strC = strABC[2];
faceArray = [];
faceArray.append(int(strA)-1);
faceArray.append(int(strB)-1);
faceArray.append(int(strC)-1);
facesArray.append( faceArray );
#print (faceArray);
print "\tCreating mesh\n"
me = bpy.data.meshes.new(strMeshName);
me.verts.extend( verticesArray );
me.faces.extend( facesArray );
scn = bpy.data.scenes.active;
obj = scn.objects.new(me, strMeshName);
obj.RotX = rotationArray[0];
obj.RotY = rotationArray[1];
obj.RotZ = rotationArray[2];
obj.LocX = positionArray[0];
obj.LocY = positionArray[1];
obj.LocZ = positionArray[2];
print "Mesh readed.\n";
Blender.Window.FileSelector(importMesh, "Import")
Blender.Redraw()
Animation import
import Blender
from Blender import Mathutils
def importAnimation(filename):
iFrame = 0
fProgress = 0.0
iNumLines = sum(1 for line in open(filename))
fProgressStep = 100.0 / iNumLines
file = open (filename)
for strLine in file:
a = strLine.split(" ")
strName = a[0]
strFrame = a[1]
strRow1 = a[2]
strRow2 = a[3]
strRow3 = a[4]
strRow4 = a[5]
obj = Blender.Object.Get(strName)
Blender.Set("curframe",int(float(strFrame)))
iFrame += 1
row1X = float( strRow1.split(",")[0] )
row1Y = float( strRow1.split(",")[1] )
row1Z = float( strRow1.split(",")[2] )
row1 = [row1X, row1Y, row1Z, 0]
row2X = float( strRow2.split(",")[0] )
row2Y = float( strRow2.split(",")[1] )
row2Z = float( strRow2.split(",")[2] )
row2 = [row2X, row2Y, row2Z, 0]
row3X = float( strRow3.split(",")[0] )
row3Y = float( strRow3.split(",")[1] )
row3Z = float( strRow3.split(",")[2] )
row3 = [row3X, row3Y, row3Z, 0]
row4X = float( strRow4.split(",")[0] )
row4Y = float( strRow4.split(",")[1] )
row4Z = float( strRow4.split(",")[2] )
row4 = [row4X, row4Y, row4Z, 1]
m = Mathutils.Matrix(row1, row2, row3, row4)
obj.setMatrix(m)
obj.insertIpoKey(Blender.Object.LOCROT)
fProgress += fProgressStep
Blender.Window.DrawProgressBar(fProgress,"Importing animation")
Blender.Window.FileSelector(importAnimation, "Import")
print "Done"
Blender.Redraw()