Irrlicht Scene Exporter for Maya

A forum to store posts deemed exceptionally wise and useful
Post Reply
killthesand
Posts: 42
Joined: Sat Sep 29, 2007 3:33 am
Contact:

Irrlicht Scene Exporter for Maya

Post by killthesand »

Hello, I wanted to use Maya as a scene editor for Irrlicht. I found it a bit troublesome to get from Maya to Irrlicht so I wrote this MEL script to help out. Still a work in progress but it can successfully export polygon objects, materials, textures, and point lights. It also creates a handy .irr file. I'll put this script on Highend3d.com, but right now they're having website troubles. For now you can copy this into notepad and save it as a .mel file, or copy it into Maya's script editor directly.

Code: Select all

// Irrlicht Scene Exporter for Maya
// Version 0.6180
// Written by Steven Olmsted

// This script will export your Maya scene to .irr format for use in the Irrlicht 3D Engine.
// Tested and works in Autodesk Maya 8.5.
// Use as you wish.
// Please report and release any additions or corrections made to this script on the Irrlicht community forums.

// Usage:
// Step 1: Save your Maya scene.  (This script will mess up all the objects.)
// Step 2: Make certain the Obj Export plugin is loaded.  (Window - Settings/Preferences - Plug-in Manager)
// Step 3: Open the Script Editor.  (Button in lower right corner)
// Step 4: File - Source Script, browse to the location of this script.
// Step 5: Choose an export location and press Export.
// All meshes, materials, and textures should now be in the export folder.
// The scene is saved to scene.irr.

// Notes:
// Only works on static polygon objects.  No NURBS, no subdivision surfaces, no animation, etc.
// All lights are converted to point lights and saved to the scene file.
// Irrlicht renders lights differently than Maya.  Light attributes may need to be adjusted.
// Instead of exporting lights, both Mental Ray and Maya Software Renderer are capible of creating Lightmaps.  Be aware that Irrlicht can't read Iff or Tiff images.
// If you export a scene without any lights, your objects will appear black in Irrlicht.  Edit the material files.  Change every Ka value to 0.5.
// Lambert shaders work best for exporting textures.  You probably want to set Duffuse to 1.
// Maya polygons are two-sided by default.  Irrlicht polygons are one-sided.  If your object is inside out, reverse the normals before exporting.
// If you need two-sided polygons in Irrlicht, duplicate your object, then reverse the normals on one of them.
// After export, you can use Undo to set the scene back to how it was.
// If you have very complex objects, you load your scene in Irrlicht and all you get is crazy triangles, try splitting your objects into several smaller objects
// scene.irr will have hard paths to your objects.  You may need to edit these.  Make paths relative to your Irrlicht executable.
// scene.irr can be renamed.  No other files can be renamed, unless you also update the references from other files.
// There are a couple variables below that can be adjusted as needed.  Look for the comments.

global proc irrExport() {
	string $saveto = (`workspace -q -rd` + "data");
	if (`window -q -ex irrscreen`) { deleteUI irrscreen; }
	window -t "Irrlicht Scene Exporter" -s 100 irrscreen;
		frameLayout -l "" -borderStyle "etchedIn" -mw 5 -mh 5;
		columnLayout -adj 1;
		textFieldButtonGrp -l "Folder" -tx $saveto -bl "..." -bc "browseForFolder()" -cw 1 60 -cw 2 300 folderCtrl;
		button -l "Export" -c "exportIrr()";
	showWindow irrscreen;
}

global proc browseForFolder() {
	fileBrowserDialog -m 4 -ds 1 -fc "saveto" -ft "folder" -an "Select";
}

global proc exportIrr() {
	string $irrFolder = `textFieldButtonGrp -q -tx folderCtrl`;
	$irrFile = ($irrFolder + "/scene.irr");
	$file = `fopen $irrFile "w"`;
	fprint $file "<?xml version=\"1.0\"?>\n<irr_scene>\n\t<attributes>\n\t\t<string name=\"Name\" value=\"root\" />\n\t\t<int name=\"Id\" value=\"-1\" />\n\t\t<colorf name=\"AmbientLight\" value=\"1.000000, 1.000000, 1.000000, 0.000000\" />\n\t</attributes>\n\n";
	string $objects[] = `ls -g`;
	select $objects;
	select `filterExpand -sm 12`;
	$objects = `ls -sl`;
	select -cl;
	string $object;
	string $val;
// Play with scaler value to adjust overall scale in the Irrlicht engine.
	int $scaler = 10;
	sysFile -md $irrFolder;
	for ($object in $objects) {
		select -r $object;
		string $objFilename = ($irrFolder + "/" + $object + ".obj");
		$objFilename = substituteAllString($objFilename, "|", "");
		fprint $file "\t<node type=\"mesh\">\n\t\t<attributes>\n\t\t\t<string name=\"Name\" value=\"";
		fprint $file $object;
		fprint $file "\" />\n\t\t\t<int name=\"Id\" value=\"-1\" />\n\t\t\t<vector3d name=\"Position\" value=\"";
		$val = `getAttr $object.translateX` * $scaler;
		fprint $file $val;
		fprint $file ", ";
		$val = `getAttr $object.translateY` * $scaler;
		fprint $file $val;
		fprint $file ", ";
		$val = `getAttr $object.translateZ` * $scaler * -1;
		fprint $file $val;
		fprint $file "\" />\n\t\t\t<vector3d name=\"Rotation\" value=\"";
		$val = `getAttr $object.rotateX` * -1;
		fprint $file $val;
		fprint $file ", ";
		$val = `getAttr $object.rotateY` * -1;
		fprint $file $val;
		fprint $file ", ";
		$val = `getAttr $object.rotateZ`;
		fprint $file $val;
		fprint $file "\" />\n\t\t\t<vector3d name=\"Scale\" value=\"";
		$val = `getAttr $object.scaleX` * $scaler;
		fprint $file $val;
		fprint $file ", ";
		$val = `getAttr $object.scaleY` * $scaler;
		fprint $file $val;
		fprint $file ", ";
		$val = `getAttr $object.scaleZ` * $scaler;
		fprint $file $val;
		fprint $file "\" />\n\t\t\t<bool name=\"Visible\" value=\"true\" />\n\t\t\t<enum name=\"AutomaticCulling\" value=\"box\" />\n\t\t\t<int name=\"DebugDataVisible\" value=\"0\" />\n\t\t\t<bool name=\"IsDebugObject\" value=\"false\" />\n\t\t\t<string name=\"Mesh\" value=\"";
		fprint $file $objFilename;
		fprint $file "\" />\n\t\t\t<bool name=\"ReadOnlyMaterials\" value=\"false\" />\n\t\t</attributes>\n\t</node>\n\n";
		ResetTransformations;
		setAttr($object + ".scaleZ", -1);
		FreezeTransformations;
		polyNormal -normalMode 0 -userNormalMode 0 -ch 1 $object;
		file -op "groups=0;ptgroups=0" -chn 1 -sh 0 -exp 0 -con 0 -ch 0 -typ "OBJexport" -pr -es $objFilename;
	}
	string $lightShapes[];
	string $lights[];
// Play with lightScale value to adjust overall lighting.
// Use lightScale together with Radius.
	float $lightScale = 2;
	$lightShapes = `ls -lights`;
	string $light;
	for ($light in $lightShapes) {
		$lights = `listRelatives -p $light`;
		$light = $lights[0];
		select -r $light;
		fprint $file "\t<node type=\"light\">\n\t\t<attributes>\n\t\t\t<string name=\"Name\" value=\"";
		fprint $file $light;
		fprint $file "\" />\n\t\t\t<int name=\"Id\" value=\"-1\" />\n\t\t\t<vector3d name=\"Position\" value=\"";
		$val = `getAttr $light.translateX` * $scaler;
		fprint $file $val;
		fprint $file ", ";
		$val = `getAttr $light.translateY` * $scaler;
		fprint $file $val;
		fprint $file ", ";
		$val = `getAttr $light.translateZ` * $scaler * -1;
		fprint $file $val;
		fprint $file "\" />\n\t\t\t<vector3d name=\"Rotation\" value=\"";
		$val = `getAttr $light.rotateX` * -1;
		fprint $file $val;
		fprint $file ", ";
		$val = `getAttr $light.rotateY` * -1;
		fprint $file $val;
		fprint $file ", ";
		$val = `getAttr $light.rotateZ`;
		fprint $file $val;
		fprint $file "\" />\n\t\t\t<vector3d name=\"Scale\" value=\"";
		$val = `getAttr $light.scaleX` * $scaler;
		fprint $file $val;
		fprint $file ", ";
		$val = `getAttr $light.scaleY` * $scaler;
		fprint $file $val;
		fprint $file ", ";
		$val = `getAttr $light.scaleZ` * $scaler;
		fprint $file $val;
		fprint $file "\" />\n\t\t\t<bool name=\"Visible\" value=\"true\" />\n\t\t\t<enum name=\"AutomaticCulling\" value=\"box\" />\n\t\t\t<int name=\"DebugDataVisible\" value=\"0\" />\n\t\t\t<bool name=\"IsDebugObject\" value=\"false\" />\n\t\t\t<colorf name=\"AmbientColor\" value=\"";
		$val = 0;
		fprint $file $val;
		fprint $file ", ";
		$val = 0;
		fprint $file $val;
		fprint $file ", ";
		$val = 0;
		fprint $file $val;
		fprint $file ", ";
		$val = 0;
		fprint $file $val;
		fprint $file "\" />\n\t\t\t<colorf name=\"DiffuseColor\" value=\"";
		$val = `getAttr $light.colorR` * `getAttr $light.intensity` * $lightScale;
		fprint $file $val;
		fprint $file ", ";
		$val = `getAttr $light.colorG` * `getAttr $light.intensity` * $lightScale;
		fprint $file $val;
		fprint $file ", ";
		$val = `getAttr $light.colorB` * `getAttr $light.intensity` * $lightScale;
		fprint $file $val;
		fprint $file ", ";
		$val = 1;
		fprint $file $val;
		fprint $file "\" />\n\t\t\t<colorf name=\"SpecularColor\" value=\"";
		$val = `getAttr $light.intensity` * $lightScale;
		fprint $file $val;
		fprint $file ", ";
		$val = `getAttr $light.intensity` * $lightScale;
		fprint $file $val;
		fprint $file ", ";
		$val = `getAttr $light.intensity` * $lightScale;
		fprint $file $val;
		fprint $file ", ";
		$val = 1;
		fprint $file $val;
		fprint $file "\" />\n\t\t\t<float name=\"Radius\" value=\"";
// Play with Radius value to adjust overall lighting.
// Set DebugDataVisible value to -1 to see the light's area of effect in the Irrlicht engine.
		$val = 15;
		fprint $file $val;
		fprint $file "\" />\n\t\t\t<bool name=\"CastShadows\" value=\"";
		if (`getAttr $light.useRayTraceShadows` || `getAttr $light.useDepthMapShadows`) {
			fprint $file "true";
		} else {
			fprint $file "false";
		}
		fprint $file "\" />\n\t\t\t<enum name=\"LightType\" value=\"Point\" />\n\t\t</attributes>\n\t</node>\n\n";
	}
	fprint $file "</irr_scene>";
	fclose $file;
}

irrExport();
WaxyChicken
Posts: 95
Joined: Sat Jun 25, 2011 6:15 am

Re: Irrlicht Scene Exporter for Maya

Post by WaxyChicken »

has there been an update to the IRR file format since this was posted in 07?
with some research I may be able to make something useful of this for Maya 2012 / ire 1.7.2
_______________________________________________________
You could argue with me all day long about which language is best.
But what it comes down to is:
which language is best for YOU and which language is best for ME.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Irrlicht Scene Exporter for Maya

Post by hybrid »

Yes, some things have been renamed or split into several items, some things were just added. But this depends on the type of objects you want to export.
Post Reply