Assets generator

# # # by: Illuminous Beltran/IBM # # # # # use Data::UUID; $libName = "My Cool OpenSim Library"; $inputRoot="/opt/opensim/library"; $invOutputDir="/opt/opensim/production/bin/inventory/MyCoolOpenSimLibrary/"; $assetOutputDir="/opt/opensim/production/bin/assets/MyCoolOpenSimAssetSet/"; $rootFolder = "00000112-000f-0000-0000-000100bba000"; # # $parent = $rootFolder; $treeLevel = 0; print("ROOT FOLDER:" . $rootFolder . "\n"); open(INVFDATOUT,">" . $invOutputDir . "3DDCInventoryFolders.xml") || die("Cannot Open Folders File"); print INVFDATOUT "\n"; open(INVIDATOUT,">" . $invOutputDir . "3DDCInventoryItems.xml") || die("Cannot Open Items File"); print INVIDATOUT "\n"; open(ASSETDATOUT,">" . $assetOutputDir . "3DDCAssetSet.xml") || die("Cannot Open Asset File"); print ASSETDATOUT "\n"; walkTree($parent, $inputRoot, 0, "0"); print INVFDATOUT "\n"; print INVIDATOUT "\n"; print ASSETDATOUT "\n"; close(INVFDATOUT); close(INVIDATOUT); close(ASSETDATOUT); sub walkTree { local $parent = shift; local $thisDir = shift; local $level = shift; local $atype = shift; local @dirs = ; local @files = ;
 * 1) genassets.pl
 * 1) This script generates the XML files
 * 2) needed to create a new asset set
 * 3) and associated inventory libraries
 * 4) for OpenSim.
 * 1) Given a directory tree of jp2 and lsl
 * 2) files, and it will traverse the tree
 * 3) and generate the assets file, the
 * 4) inventory folder file, and the
 * 5) inventory items file.
 * 1) Requires the Data::UUID module
 * 1) http://search.cpan.org/~rjbs/Data-UUID-1.148/UUID.pm
 * 1) Library name
 * 1) Root of your library, where your
 * 2) jp2 and lsl files are
 * 1) Where to put the inventory files
 * 1) Where to put the asset set file
 * 1) Root key for OpenSim library folder
 * 2) This is a static value fixed in opensim
 * 3) so you should not have to change it unless
 * 4) it changes
 * 1) No user servicable parts below

opendir(HOMEDIR, $thisDir) || die("unable to open directory"); while($filename = readdir(HOMEDIR)) { if( -d ($thisDir. "/" . $filename) ) { if( ($filename eq ".") || ($filename eq "..") || ($filename eq ".svn")) {next;} push(@dirs, $filename); } else { if( substr($filename, -4) eq ".jp2" || substr($filename, -4) eq ".lsl") { push(@files, $filename); }       }

}

closedir(HOMEDIR);

$uuidGen = new Data::UUID; $thisFolder = $uuidGen->create_str;

print("Processing:" . $fName . "\n");

if($_ eq "") { $fName = $libName; }   else {       $fName = $_; }   if($level == 1) { $assetType = getType($fName); }   else { $assetType = $atype; }

writeFolder($fName, $thisFolder, $parent, $assetType);

foreach(@files) {

$assetID = writeAsset($thisDir, $_, $assetType); writeItem($_, $assetID, $thisFolder, $assetType);

}

$parent = $thisFolder;

$level ++; foreach(@dirs) { walkTree($parent, ($thisDir. "/" . $_), $level, $assetType); }

print("\n");

}

sub getType {

$assetType = shift;

if( index($assetType, "lsl", 0) > 0 || index($assetType, "script", 0) > 0 ) {       return "10"; }   else {       return "0"; } }

sub writeFolder {

$name = shift; $folderID = shift; $parentID = shift; $type = shift;

print INVFDATOUT "\n"; print INVFDATOUT "\n"; print INVFDATOUT "\n"; print INVFDATOUT "\n"; print INVFDATOUT "\n"; print INVFDATOUT "\n"; print INVFDATOUT "\n";

}

sub writeItem {

$name = shift; $assetID = shift; $folderID = shift; $type = shift;

$uuidGen = new Data::UUID; $inventoryID = $uuidGen->create_str;

print INVIDATOUT "\n"; print INVIDATOUT "\n"; print INVIDATOUT "\n"; print INVIDATOUT "\n"; print INVIDATOUT "<Key Name=\"name\" Value=\"" . $name . "\" />\n"; print INVIDATOUT "<Key Name=\"description\" Value=\"" . $name . "\" />\n"; print INVIDATOUT "<Key Name=\"assetType\" Value=\"".$type."\" />\n"; print INVIDATOUT "<Key Name=\"inventoryType\" Value=\"".$type."\" />\n"; print INVIDATOUT "<Key Name=\"currentPermissions\" Value=\"2147483647\" />\n"; print INVIDATOUT "<Key Name=\"nextPermissions\" Value=\"2147483647\" />\n"; print INVIDATOUT "<Key Name=\"everyonePermissions\" Value=\"2147483647\" />\n"; print INVIDATOUT "<Key Name=\"basePermissions\" Value=\"2147483647\" />\n"; print INVIDATOUT "</Section>\n"; print INVIDATOUT "\n";

}

sub writeAsset {

$dir = shift; $name = shift; $type = shift;

$uuidGen = new Data::UUID; $assetID = $uuidGen->create_str;

print ASSETDATOUT "\n"; print ASSETDATOUT "<Key Name=\"assetID\" Value=\"" . $assetID . "\" />\n"; print ASSETDATOUT "<Key Name=\"name\" Value=\"" . $name . "\" />\n"; print ASSETDATOUT "<Key Name=\"assetType\" Value=\"".$type."\" />\n"; print ASSETDATOUT "<Key Name=\"inventoryType\" Value=\"".$type."\" />\n"; print ASSETDATOUT "<Key Name=\"fileName\" Value=\"" . $dir . "/" . $name . "\" />\n"; print ASSETDATOUT "</Section>\n"; print ASSETDATOUT "\n";

return $assetID;

}