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.



print "Looking for: $directoryName\n";

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

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

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

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

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

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

opendir(DIR, ".");
@material = grep(/\.material$/,readdir(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