Jan 21, 2010

Blender to OGRE Perl Script

Complex scenes hold lots of meshes (in xml format after you export to ogre meshes from blender). You need to convert it one by one. But I have written a script that converts all mesh.xml files into ogre meshes and save them to desired directories.

[Script]
#!/usr/bin/perl

$directoryName=$ARGV[0];
$outputMesh=$ARGV[1];
$outputMat=$ARGV[2];

print "Looking for: $directoryName\n";

chdir($directoryName) or die "Cant chdir to $directoryName !";

opendir(DIR, ".");
@xmlFiles = grep(/\.xml$/,readdir(DIR));
closedir(DIR);

foreach $file (@xmlFiles) {
print "$file\n";
system("OgreXMLConverter $file");
}

opendir(DIR, ".");
@meshFiles = grep(/\.mesh$/,readdir(DIR));
closedir(DIR);

printf "Meshes: $outputMesh\n";
printf "Materials: $outputMat\n";

foreach $file (@meshFiles) {
system("cp $file $outputMesh");
}

opendir(DIR, ".");
@material = grep(/\.material$/,readdir(DIR));
closedir(DIR);

foreach $file (@material) {
print "$file\n";
system("cp $file $outputMat");
}

[Remark] Save the script as ogreXML.perl

[Terminal] perl ogreXML.perl /path to your xml files/ /output directory for meshes/ /output directory for material/

[Remark] Don't forget to remember that you need to put your mesh files and materials in special directories in OGRE.

No comments:

Post a Comment

Visual Studio Keyboard Shortcuts

Playing with keyboard shortcuts is very interesting and reduce the headache of using the mouse again and again while programming with visu...