Assets generator

From OpenSimulator

Jump to: navigation, search

Description

This script generates the XML files needed to create a new asset set and associated inventory libraries for OpenSim.Given a directory tree of jp2 and lsl files, and it will traverse the tree and generate the assets file, the inventory folder file, and the inventory items file.

Usage

  • Put the code in a file named genassets.pl, and copy it to your library preparation directory (/opt/opensim/library)
  • Download the perl UUID module
  • Install the UUID module
perl Makefile.PL
make
make test
make install
  • Create Asset directories
mkdir /opt/opensim/production/bin/inventory/MyCoolOpenSimLibrary/
mkdir /opt/opensim/production/bin/assets/MyCoolOpenSimAssetSet/
  • Launch script (Adds the content in /opt/opensim/production/library to the OpenSimulator inventory/asset storage)
perl /opt/opensim/production/library/genassets.pl

Code

######################################
#
# genassets.pl
#
# by: Illuminous Beltran/IBM
#
# This script generates the XML files
# needed to create a new asset set
# and associated inventory libraries
# for OpenSimulator.
#
# Given a directory tree of jp2 and lsl
# files, and it will traverse the tree
# and generate the assets file, the 
# inventory folder file, and the
# inventory items file.
#
# Requires the Data::UUID module
#
# http://github.com/tokuhirom/data-uuid/downloads
#
######################################
use Data::UUID;

# Library name
$libName = "My Cool OpenSimulator Library";

# Root of your library, where your
# jp2 and lsl files are
$inputRoot="/opt/opensim/library";

# Where to put the inventory files
$invOutputDir="/opt/opensim/production/bin/inventory/MyCoolOpenSimLibrary/";

# Where to put the asset set file
$assetOutputDir="/opt/opensim/production/bin/assets/MyCoolOpenSimAssetSet/";

# Root key for OpenSimulator library folder
# This is a static value fixed in opensim
# so you should not have to change it unless
# it changes
$rootFolder = "00000112-000f-0000-0000-000100bba000";

#
# No user servicable parts below
#

$parent = $rootFolder;
$treeLevel = 0;

print("ROOT FOLDER:" . $rootFolder . "\n");

open(INVFDATOUT,">" . $invOutputDir . "3DDCInventoryFolders.xml") || die("Cannot Open Folders File");
print INVFDATOUT "<Nini>\n";

open(INVIDATOUT,">" . $invOutputDir . "3DDCInventoryItems.xml") || die("Cannot Open Items File");
print INVIDATOUT "<Nini>\n";

open(ASSETDATOUT,">" . $assetOutputDir . "3DDCAssetSet.xml") || die("Cannot Open Asset File");
print ASSETDATOUT "<Nini>\n";

walkTree($parent, $inputRoot, 0, "0");

print INVFDATOUT "</Nini>\n";
print INVIDATOUT "</Nini>\n";
print ASSETDATOUT "</Nini>\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 = ();

    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 "<Section Name=\"" . $name . " \">\n";
   print INVFDATOUT "<Key Name=\"folderID\" Value=\"" . $folderID . "\" />\n";
   print INVFDATOUT "<Key Name=\"parentFolderID\" Value=\"" . $parentID . "\" />\n";
   print INVFDATOUT "<Key Name=\"name\" Value=\"" . $name . "\" />\n";
   print INVFDATOUT "<Key Name=\"type\" Value=\"".$type."\" />\n";
   print INVFDATOUT "</Section>\n";
   print INVFDATOUT "\n";
}

sub writeItem() {
   $name = shift;
   $assetID = shift;
   $folderID = shift;
   $type = shift;

   $uuidGen = new Data::UUID;
   $inventoryID = $uuidGen->create_str();
   print INVIDATOUT "<Section Name=\"" . $name . "\">\n";
   print INVIDATOUT "<Key Name=\"inventoryID\" Value=\"" . $inventoryID . "\" />\n";
   print INVIDATOUT "<Key Name=\"assetID\" Value=\"" . $assetID . "\" />\n";
   print INVIDATOUT "<Key Name=\"folderID\" Value=\"" . $folderID . "\" />\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 "<Section Name=\"" . $name . "\">\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;
 
}
Personal tools
General
About This Wiki