Greetings to all. I've been working on an XSI exporter.

Moderators: GSH, VSMIT, Red Devil, Commando

Post Reply
Col Klink
Sabre
Posts: 368
Joined: Fri Apr 15, 2011 8:24 am
Contact:

Greetings to all. I've been working on an XSI exporter.

Post by Col Klink »

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. */

Col Klink
Sabre
Posts: 368
Joined: Fri Apr 15, 2011 8:24 am
Contact:

Re: Greetings to all. I've been working on an XSI exporter.

Post by Col Klink »

The exporter works well enough to get a Sabre Tank in the game minus the texture which I'm still trying to work the bugs out of for now. The weapons work okay, but I need to scale down the model in Anim8or a bit or do it in the models ODF. I up to my eyeballs in frustration with the texture issue some body help me. LOL Just Kidding though I don't have a clue yet but I know part of the problem is that the MSH model file is dropping the .bmp file extension when it converts the XSI to MSH. Any thoughts on what might cause this issue? Here's a screeny of the model in the map editor.

Image
User avatar
Zax
Attila
Posts: 1388
Joined: Sat Feb 19, 2011 6:56 am

Re: Greetings to all. I've been working on an XSI exporter.

Post by Zax »

How is 1.3 handling it? dxtbz2 or whatnot may behave differently.
alpfha max power
Scrap
Posts: 4
Joined: Sat Mar 31, 2012 1:10 pm

Re: Greetings to all. I've been working on an XSI exporter.

Post by alpfha max power »

ecscuse me but dosent this belong in bz2 mod making forum??
User avatar
Ded10c
Recycler
Posts: 3815
Joined: Sun Feb 20, 2011 11:05 am
Location: Stoke-on-Trent
Contact:

Re: Greetings to all. I've been working on an XSI exporter.

Post by Ded10c »

If it was about mod making, it probably should. It's not about mod making. The only think I see him making is an XSI exporter.
Col Klink
Sabre
Posts: 368
Joined: Fri Apr 15, 2011 8:24 am
Contact:

Re: Greetings to all. I've been working on an XSI exporter.

Post by Col Klink »

Zax wrote:How is 1.3 handling it? dxtbz2 or whatnot may behave differently.
It loads in PB6 with the default rainbow looking missing texture thingy. The model itself works okay, but I think the problem is in the texture write out of the Anim8or XSI exporter script. 3DEX, reads and displays the model without errors.

This guy Raxx created this exporter from a modified X exporter that he fixed for me a while back; that script works to create an X model that can be converted with 3DEX to XSI, but I can already do that with Truespaces export tools with better results.

This XSI script has gone through several revisions and I've tweaked them all as Raxx released them for testing. I posted the script for others to look at and possibly offer some sugestions on what to change in the script to resolve the missing texture issue. I'm not a programmer, so I limited to making copies of the working scripts itself and trying small undoable changes to the script copies and retest them in Anim8or. I have a simple syntax checker that alerts me when I create an error condition within the script itself as I make changes, but it won't tell me what to change in the script itself. Anim8or, is not the best BZII model creation, but seem to have potential via the the export plugin features it supports. I mostly posted because I wanted to get the ball rolling. Raxx, created a decent base script that needs tweaking, but now basically it's needs some others to keep the ball rolling to get it finished. I still monkey around with the script, but I don't have enough knowledge in this area to do more then ask for some feedback (you know assitance) hint hint? It's not really a priority issue for me. It's just yet another BZII related project requires a group effort to go much further. Thanks, Leroy.
User avatar
MrTwosheds
Recycler
Posts: 3059
Joined: Sat Feb 19, 2011 8:37 am
Location: Outer Space
Contact:

Re: Greetings to all. I've been working on an XSI exporter.

Post by MrTwosheds »

This sort of implies that it is indeed working in pb6, as it displays the texture (dxtbz2) that is used when it finds an unsupported texture format such as bmp.
Col Klink
Sabre
Posts: 368
Joined: Fri Apr 15, 2011 8:24 am
Contact:

Re: Greetings to all. I've been working on an XSI exporter.

Post by Col Klink »

I finally got a BMP texture to show up on the model by creating a new 512x512 in MS Paint and used that on the model; the original issue may have related to the BZII squared in powers of two thingy? Also with Anim8or you have to copy the texture to your addon folder manually as the exporter won't do this by default. Now I need to get back with Raxx to modify the script to group objects the way BZII needs to read them. By default, A8 can export a single group of objects, but Raxx informs me that the exporter can be configured to link sub groups together. Here's a screen grab of a crude Sabre tank in the map editor. The tank weapons work okay.
PS: I got an assault Tank into the map editor, but the Turret_y and x are not working right due to the single grouping issue. Raxx, tells me he'll have time this weekend to make some changes to the XSI script to make sub grouping possible. Cheers!
Image
Image
Image
Col Klink
Sabre
Posts: 368
Joined: Fri Apr 15, 2011 8:24 am
Contact:

Re: Greetings to all. I've been working on an XSI exporter.

Post by Col Klink »

Just to update all on the Anim8or BZII XSI exporter progress. Raxx, tells me he is about 50% finished with adding support for object sub grouping for models like assault Tanks and other BZII models that require sub grouping to work correctly.

For you new modelers looking for an easy to use modeling software you're going to enjoy using Anim8or. It can produce some beautiful models for BZII.. I've been monkeying around with it a lot lately and making stuff is pretty easy compared to other software. It doesn't have a ton of features, but seems like a good basic starter for those new to 3d modeling in general. Where it really seems to excel is in it's many available free ASL user created scripts. Any interested parties should visit the Anim8or forum to see what it is capable of producing and any limitations of the software. I go by the user name lppena on that forum. Cheers to all. Leroy aka Col Klink.
Post Reply