Greetings to all. I've been working on an XSI exporter.
Posted: Thu Apr 05, 2012 5:47 pm
It's for a modeling software called Anim8or. I've partially completed it, but it's still a WIP. I could use some feedback on what to change in the script to get a texture on the models. Haven't really tested it on the latest beta yet, but it will load a model in 1.2 minus the texture. It's actually a plugin exporter script for Anim8or. An A8 user named Raxx did most of the work by modifying an exist X exporter script, and I am testing it in the map editor. I've tweaked the script a bit to make it more BZII friendly. Perhaps someone with C or C++ skills can take a look at the script and offer some suggestions on what to try next. FYI: ASL scripts are plain text based user created scripts read by Anim8or when they are loaded. I use a third party script editor called ASL editor to modify existing scripts to make them compatible for use with BZII. This is more or less a just a personal project, but would provide an alternative way to get models created for BZII if it goes any where. Here's the script I have so far. You can cut and paste the script in Notepad to take a closer look at the script. ASL scripts can use either the .a8s or txt extension and still load in Anim8or. Here's the link to the Anim8or site if anyone is interested or wants to help develop the BZII XSI exporter. Anim8or, is a simple one file executable and ASL Scripts are stored and run from the same folder. You can configure A8 to auto load ASL scripts. The program is very compact at just under 1 megabyte and the scripts are very small in size as well. Thanks, Leroy aka Col Klink.
Code: Select all
/*
* Original .X plugin pieced together from Joe Cooning and Zaidon's
* .X exporters with a bit of independent work by Raxx.
*
* Originally written by Raxx as a .X exporter, then further
* modified by Raxx and BNG for .XSI compatibility with
* the Battlezone II Combat Commander game engine.
*
* Copyright 2012 Randall Bezant. Permission granted for
* modification and use, including commercial use. Source
* distribution must include this copyright.
*/
#plugin("object", "export", "BZ II XSI", ".xsi");
#file($output, "text");
#return($result);
file $output;
int $result;
object $curObject;
$curObject = project.curObject;
$output.print("xsi 0101txt 0032\n\nSI_CoordinateSystem coord {\n 1;\n 0;\n 1;\n 0;\n 2;\n 5;\n }\n\n");
shape $shape, $shapes[1], $childShapes[1];
tridata $mdata;
int $numPoints, $numFaces, $numMaterials;
int $ii;
point3 $point, $normal, $tr1, $tr2, $tr3, $tr4;
point2 $uv;
float4x4 $transformMat;
string $matName, $texFile;
material $material;
texture $tex;
/* The shapes in $shapes are processed in reverse order so */
/* reverse the array of values that GeetShapes returns: */
$curObject.GetShapes($childShapes);
$shapes.size = 0;
while ($childShapes.size > 0)
$shapes.push($childShapes.pop());
$output.print("Frame Frm {\n FrameTransformMatrix {\n1.000000,0.000000,0.000000,0.000000,\n0.000000,1.000000,0.000000,0.000000,\n0.000000,0.000000,1.000000,0.000000,\n0.000000,0.000000,0.000000,1.000000;;\n }\n");
while ($shapes.size > 0) {
$shape = $shapes.pop();
if ($shape.GetKind() == SHAPE_KIND_GROUP) {
$shape.GetShapes($childShapes);
while ($childShapes.size > 0) {
$shapes.push($childShapes.pop());
}
} else if ($shape.GetKind() == SHAPE_KIND_PATH ||
$shape.GetKind() == SHAPE_KIND_MODIFIER ||
$shape.GetKind() == SHAPE_KIND_TEXT)
{
/* No 3D mesh to output. */
} else {
$mdata = $shape.GetTriangleData();
$output.print("Frame %s {\n FrameTransformMatrix {\n", $shape.name);
$transformMat = $shape.GetGlobalTransform();
$tr4=$transformMat.Project((0.0,0.0,0.0));
$tr1=$transformMat.Project((1.0,0.0,0.0))-$tr4;
$tr2=$transformMat.Project((0.0,1.0,0.0))-$tr4;
$tr3=$transformMat.Project((0.0,0.0,1.0))-$tr4;
$output.print("%.6f,%.6f,%.6f,0.000000,\n",$tr1);
$output.print("%.6f,%.6f,%.6f,0.000000,\n",$tr2);
$output.print("%.6f,%.6f,%.6f,0.000000,\n",$tr3);
$output.print("%.6f,%.6f,%.6f,1.000000;;\n}\n",$tr4);
$output.print("Mesh %sMesh {\n", $shape.name);
$numPoints = $mdata.GetNumPoints();
$output.print(" %d;\n", $numPoints);
for $ii = 0 to $numPoints-1 do {
$point = $mdata.GetPoint($ii);
$output.print("%.6f;%.6f;%.6f;", $point);
if ($ii<$numPoints-1){
$output.print(",\n");
} else {
$output.print(";\n");
}
}
$numFaces = $mdata.GetNumTriangles();
$output.print("\n %d;\n", $numFaces);
for $ii = 0 to $numFaces - 1 do {
$output.print("3;%d,%d,%d;", $mdata.GetIndex($ii*3), $mdata.GetIndex($ii*3+1), $mdata.GetIndex($ii*3+2));
if ($ii<$numFaces-1){
$output.print(",\n");
} else {
$output.print(";\n");
}
}
$output.print("\nMeshMaterialList {\n");
$numMaterials = $mdata.GetNumMaterials();
$output.print("%d;\n", $numMaterials);
$output.print("%d;\n", $numFaces);
for $ii = 0 to $numFaces - 1 do {
$output.print("%d", $mdata.GetMatIndex($ii));
if ($ii<$numFaces - 1) {
$output.print(",\n");
} else {
$output.print(";\n");
}
}
for $ii = 0 to $numMaterials - 1 do {
$material = $mdata.GetMaterial($ii);
$tex = $material.GetTexture(TEXTURE_DIFFUSE);
$matName = $material.name;
if ($matName == " -- default --") {
$matName = "___default___";
}
$output.print("SI_Material {\n", $matName);
$output.print("%.6f;%.6f;%.6f;%.6f;;\n", $material.diffuse, $material.alpha);
$output.print("%.6f;\n", $material.Ks);
$output.print("%.6f;%.6f;%.6f;;\n", $material.specular);
$output.print("%.6f;%.6f;%.6f;;\n", $material.emissive);
$output.print("1;\n");
$output.print("%.6f;%.6f;%.6f;;\n", $material.ambient);
$texFile = $tex.GetFileName();
if ($texFile != ""){
$output.print("TextureFilename {\n\"%s.%s\";\n}\n", $texFile.GetRoot(), $texFile.GetExt());
}
$output.print("}\n");
}
$output.print("}\n\n");
/*$output.print("}\n"); */
$output.print("SI_MeshNormals {\n%d;\n", $numPoints);
for $ii = 0 to $numPoints - 1 do {
$normal = $mdata.GetNormal($ii);
$output.print("%.6f;%.6f;%.6f;", $normal);
if ($ii<$numPoints-1){
$output.print(",\n");
} else {
$output.print(";\n\n");
}
}
$output.print("%d;\n", $numFaces);
for $ii = 0 to $numFaces - 1 do {
$output.print("%d;", $ii);
$output.print("3;%d,%d,%d;", $mdata.GetIndex($ii*3), $mdata.GetIndex($ii*3 + 1), $mdata.GetIndex($ii*3+2));
if ($ii<$numFaces-1){
$output.print(",\n");
} else {
$output.print(";\n");
}
}
$output.print("}\n\n");
$output.print("SI_MeshTextureCoords {\n %d;\n", $numPoints);
for $ii = 0 to $numPoints - 1 do {
$uv = $mdata.GetTexCoord($ii);
$output.print("%.5f;%.5f;", $uv);
if ($ii<$numPoints - 1){
$output.print(",\n");
} else {
$output.print(";\n");
}
}
$output.print("\n%d;\n", $numFaces);
for $ii = 0 to $numFaces - 1 do {
$output.print("%d;", $ii);
$output.print("3;%d,%d,%d;", $mdata.GetIndex($ii*3),$mdata.GetIndex($ii*3+1),$mdata.GetIndex($ii*3+2));
if ($ii<$numFaces-1){
$output.print(",\n");
} else {
$output.print(";\n");
}
}
$output.print("}\n");
$output.print("}\n");
}
$output.print("}\n");
}
/*$output.print("}");*/
$result = 1; /* Assume export will succeed. */