General Category > ASL Scripts
I'm working on an XSI export script modifying Raxx's BZII X exporter script.
lppena:
This is what I have so far. 3D Exploration shows these errors.
--- Code: ---/*
* This plugin pieced together from Joe Cooning and Zaidon's
* .X exporters with some independent work.
*
* Written by Raxx, this is compatible with the Battlezone II
* Combat Commander game engine and being modified by BNG for use with BZII as an XSI variant of Raxx's X variant.
*
* 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\nSI_CoordinateSystem coord\n\n {\n1;\n0;\n1;\n0;\n2;\n5;\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());
while ($shapes.size > 0) {
$shape = $shapes.pop();
/* If $shape is a group push child shapes onto stack: */
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 Frm-%s {\nFrameTransformMatrix {\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 %s_mesh {\n", $shape.name);
$numPoints = $mdata.GetNumPoints();
$output.print("%d;\n", $numPoints);
for $ii = 0 to $numPoints-1 do {
$point = $mdata.GetPoint($ii);
$point.z =$point.z * -1;
$output.print("%.6f; %.6f; %.6f;", $point);
if ($ii<$numPoints-1){
$output.print(",\n");
} else {
$output.print(";\n");
}
}
$numFaces = $mdata.GetNumTriangles();
$output.print("%d;\n", $numFaces);
for $ii = 0 to $numFaces - 1 do {
$output.print("3;%d,%d,%d;", $mdata.GetIndex($ii*3 + 2), $mdata.GetIndex($ii*3 + 1), $mdata.GetIndex($ii*3));
if ($ii<$numFaces-1){
$output.print(",\n");
} else {
$output.print(";\n");
}
}
$output.print("MeshMaterialList {\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 %s {\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);
$texFile = $tex.GetFileName();
if ($texFile != ""){
$output.print("TextureFilename {\n\"%s.%s\";\n}\n", $texFile.GetRoot(), $texFile.GetExt());
}
$output.print("}\n");
}
$output.print("}\n");
$output.print("}\n}\n");
$output.print("SI_MeshNormals {\n%d;\n", $numPoints);
for $ii = 0 to $numPoints - 1 do {
$normal = $mdata.GetNormal($ii);
$normal.z = $normal.z * -1;
$output.print("%.6f; %.6f; %.6f;", $normal);
if ($ii<$numPoints-1){
$output.print(",\n");
} else {
$output.print(";\n");
}
}
$output.print("%d;\n", $numFaces);
for $ii = 0 to $numFaces - 1 do {
$output.print("3; %d,%d,%d;", $mdata.GetIndex($ii*3 + 2), $mdata.GetIndex($ii*3 + 1), $mdata.GetIndex($ii*3));
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);
$uv.y = 1.0-$uv.y;
$output.print("%.5f; %.5f;", $uv);
if ($ii<$numPoints - 1){
$output.print(",\n");
} else {
$output.print(";\n");
}
}
$output.print("}\n");
}
}
$result = 1; /* Assume export will succeed. */
--- End code ---
Raxx:
Sorry I haven't been able to get back to this yet, I've been pretty swamped. Can you attached a simple .xsi file that loads 100% error-free in the game? I'll try to get to it, but it probably won't be until Thursday-Friday (again). Until then maybe I can give you some tips.
lppena:
This sample cube was exported from Truespace as an X model and converted to XSI with 3D Exploration; these models always load correctly in Battlezone II. Thanks Raxx, I could use some pointers on how to rearrange blocks in the X exporter you fixed up for me last week. I've made a backup of the original script and am working on a copy fixed up for use with Anim8or. Leroy. PS: There is no hurry to get it done. I just am working on it in my spare time, so when you have some free time please take a look at what I've done so far.
--- Code: ---xsi 0101txt 0032
SI_CoordinateSystem coord {
1;
0;
1;
0;
2;
5;
}
Frame Cube-0 {
FrameTransformMatrix {
1.000000,0.000000,0.000000,0.000000,
0.000000,1.000000,0.000000,0.000000,
0.000000,0.000000,1.000000,0.000000,
0.000000,0.000000,0.000000,1.000000;;
}
Mesh CubeMesh {
8;
1.000000;-1.000000;1.000000;,
1.000000;1.000000;1.000000;,
-1.000000;-1.000000;1.000000;,
-1.000000;1.000000;1.000000;,
1.000000;-1.000000;-1.000000;,
-1.000000;-1.000000;-1.000000;,
-1.000000;1.000000;-1.000000;,
1.000000;1.000000;-1.000000;;
12;
3;1,3,2;,
3;0,1,2;,
3;2,5,4;,
3;0,2,4;,
3;2,3,6;,
3;5,2,6;,
3;1,7,6;,
3;3,1,6;,
3;4,5,6;,
3;7,4,6;,
3;4,7,1;,
3;0,4,1;;
MeshMaterialList {
1;
12;
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0;
SI_Material {
0.168627;0.537255;0.549020;1.000000;;
2.000000;
0.100000;0.100000;0.100000;;
0.000000;0.000000;0.000000;;
1;
0.000000;0.000000;0.000000;;
TextureFilename {
"Gslxtoxsicube_0.bmp";
}
}
}
SI_MeshNormals {
6;
0.000000;0.000000;1.000000;,
0.000000;-1.000000;0.000000;,
-1.000000;0.000000;0.000000;,
0.000000;1.000000;0.000000;,
0.000000;0.000000;-1.000000;,
1.000000;0.000000;0.000000;;
12;
0;3;0,0,0;,
1;3;0,0,0;,
2;3;1,1,1;,
3;3;1,1,1;,
4;3;2,2,2;,
5;3;2,2,2;,
6;3;3,3,3;,
7;3;3,3,3;,
8;3;4,4,4;,
9;3;4,4,4;,
10;3;5,5,5;,
11;3;5,5,5;;
}
SI_MeshTextureCoords {
14;
0.000000;-0.333333;,
0.250000;-0.333333;,
0.250000;-0.666667;,
0.000000;-0.666667;,
0.500000;-0.666667;,
0.500000;-1.000000;,
0.250000;-1.000000;,
0.500000;-0.333333;,
0.500000;-1.333333;,
0.250000;-1.333333;,
0.750000;-0.666667;,
0.750000;-0.333333;,
1.000000;-0.333333;,
1.000000;-0.666667;;
12;
0;3;0,1,2;,
1;3;3,0,2;,
2;3;2,4,5;,
3;3;6,2,5;,
4;3;2,1,7;,
5;3;4,2,7;,
6;3;6,5,8;,
7;3;9,6,8;,
8;3;10,4,7;,
9;3;11,10,7;,
10;3;10,11,12;,
11;3;13,10,12;;
}
}
}
--- End code ---
Raxx:
Ok, this *might* fix it. When you rearrange stuff in code, you have to make sure you have all of the brackets and parenthesis ( { and } ) properly placed.
Also, the XSI file that you included needed the ambient color as well, so I added that to the script.
There is one final discrepancy in that the UV coordinates in the XSI version need an extra set of data. I didn't implement that yet, but go ahead and test it to see if it works without it.
Export script is attached below.
lppena:
Will do and thank you Raxx for taking the time to make the changes for the XSI format. I'm going to compare the changes so that I might see what I need to do as far as modifying the scripts themselves and writing them out more correctly. I guess the task requires more knowledge then I currently understand.
Are there some general guidelines that I can check for as far as placing brackets and pare thesis? In my modified version I basically changed the header entries and moved the material section to above meshnormals entry thinking this would do the trick, but it only made the geometry disappear when viewed in 3DEX. After that the confusion factor took over. Thanks again and I'll DL the script and test it out. Leroy.
Navigation
[0] Message Index
[#] Next page
Go to full version