Assets generator

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
(New page: ###################################### # # genassets.pl # # by: Illuminous Beltran/IBM # # This script generates the XML files # needed to create a new asset set # and associated ...)
 
m (Robot: Replacing 'OpenSim' to 'OpenSimulator', which is the precise name)
 
(11 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 +
__NOTOC__
 +
{{Quicklinks}}
 +
 +
== 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 [http://github.com/tokuhirom/data-uuid/downloads 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 ==
 
  ######################################
 
  ######################################
 
  #
 
  #
Line 8: Line 29:
 
  # needed to create a new asset set
 
  # needed to create a new asset set
 
  # and associated inventory libraries
 
  # and associated inventory libraries
  # for OpenSim.
+
  # for OpenSimulator.
 
  #
 
  #
 
  # Given a directory tree of jp2 and lsl
 
  # Given a directory tree of jp2 and lsl
Line 18: Line 39:
 
  # Requires the Data::UUID module
 
  # Requires the Data::UUID module
 
  #
 
  #
  # http://search.cpan.org/~rjbs/Data-UUID-1.148/UUID.pm
+
  # http://github.com/tokuhirom/data-uuid/downloads
 
  #
 
  #
 
  ######################################
 
  ######################################
Line 24: Line 45:
 
   
 
   
 
  # Library name
 
  # Library name
  $libName = "My Cool OpenSim Library";
+
  $libName = "My Cool OpenSimulator Library";
 
   
 
   
 
  # Root of your library, where your
 
  # Root of your library, where your
Line 36: Line 57:
 
  $assetOutputDir="/opt/opensim/production/bin/assets/MyCoolOpenSimAssetSet/";
 
  $assetOutputDir="/opt/opensim/production/bin/assets/MyCoolOpenSimAssetSet/";
 
   
 
   
  # Root key for OpenSim library folder
+
  # Root key for OpenSimulator library folder
 
  # This is a static value fixed in opensim
 
  # This is a static value fixed in opensim
 
  # so you should not have to change it unless
 
  # so you should not have to change it unless
Line 61: Line 82:
 
   
 
   
 
  walkTree($parent, $inputRoot, 0, "0");
 
  walkTree($parent, $inputRoot, 0, "0");
 
+
 
  print INVFDATOUT "</Nini>\n";
 
  print INVFDATOUT "</Nini>\n";
 
  print INVIDATOUT "</Nini>\n";
 
  print INVIDATOUT "</Nini>\n";
Line 78: Line 99:
 
     local @dirs = ();
 
     local @dirs = ();
 
     local @files = ();
 
     local @files = ();
 
+
 
+
 
     opendir(HOMEDIR, $thisDir) || die("unable to open directory");
 
     opendir(HOMEDIR, $thisDir) || die("unable to open directory");
 
   
 
   
Line 88: Line 108:
 
             push(@dirs, $filename);
 
             push(@dirs, $filename);
 
  }
 
  }
else {
+
    else {
 
           if( substr($filename, -4) eq ".jp2" || substr($filename, -4) eq ".lsl") {
 
           if( substr($filename, -4) eq ".jp2" || substr($filename, -4) eq ".lsl") {
 
               push(@files, $filename);
 
               push(@files, $filename);
 
           }
 
           }
 
         }
 
         }
 
 
     }
 
     }
 
+
 
     closedir(HOMEDIR);
 
     closedir(HOMEDIR);
 
+
 
     $uuidGen = new Data::UUID;
 
     $uuidGen = new Data::UUID;
 
     $thisFolder = $uuidGen->create_str();
 
     $thisFolder = $uuidGen->create_str();
 
+
 
     print("Processing:" . $fName . "\n");
 
     print("Processing:" . $fName . "\n");
 
+
 
     if($_ eq "") {
 
     if($_ eq "") {
 
         $fName = $libName;
 
         $fName = $libName;
Line 114: Line 133:
 
     }
 
     }
 
     else {
 
     else {
        $assetType = $atype;
+
    $assetType = $atype;
 
     }
 
     }
 
+
 
     writeFolder($fName, $thisFolder, $parent, $assetType);
 
     writeFolder($fName, $thisFolder, $parent, $assetType);
 
+
 
     foreach(@files) {
 
     foreach(@files) {
 
+
    $assetID = writeAsset($thisDir, $_, $assetType);
$assetID = writeAsset($thisDir, $_, $assetType);
+
    writeItem($_, $assetID, $thisFolder, $assetType);
        writeItem($_, $assetID, $thisFolder, $assetType);
+
 
+
 
     }
 
     }
 
+
 
     $parent = $thisFolder;
 
     $parent = $thisFolder;
 
+
 
     $level ++;
 
     $level ++;
 
     foreach(@dirs) {
 
     foreach(@dirs) {
Line 133: Line 150:
 
           walkTree($parent, ($thisDir . "/" . $_), $level, $assetType);
 
           walkTree($parent, ($thisDir . "/" . $_), $level, $assetType);
 
     }
 
     }
 
+
 
     print("\n");
 
     print("\n");
 
+
}
+
}
 
+
sub getType() {
+
sub getType() {
 
+
    $assetType = shift;
+
$assetType = shift;
 
+
 
     if( index($assetType, "lsl", 0) > 0 || index($assetType, "script", 0) > 0 )
 
     if( index($assetType, "lsl", 0) > 0 || index($assetType, "script", 0) > 0 )
 
     {
 
     {
Line 150: Line 167:
 
         return "0";
 
         return "0";
 
     }
 
     }
}
+
}
 
+
sub writeFolder() {
+
sub writeFolder() {
 
+
 
     $name = shift;
 
     $name = shift;
 
     $folderID = shift;
 
     $folderID = shift;
 
     $parentID = shift;
 
     $parentID = shift;
 
     $type = shift;
 
     $type = shift;
 
+
 
     print INVFDATOUT "<Section Name=\"" . $name . " \">\n";
 
     print INVFDATOUT "<Section Name=\"" . $name . " \">\n";
 
     print INVFDATOUT "<Key Name=\"folderID\" Value=\"" . $folderID . "\" />\n";
 
     print INVFDATOUT "<Key Name=\"folderID\" Value=\"" . $folderID . "\" />\n";
Line 166: Line 183:
 
     print INVFDATOUT "</Section>\n";
 
     print INVFDATOUT "</Section>\n";
 
     print INVFDATOUT "\n";
 
     print INVFDATOUT "\n";
 
+
}
}
+
 
+
sub writeItem() {
sub writeItem() {
+
 
+
 
     $name = shift;
 
     $name = shift;
 
     $assetID = shift;
 
     $assetID = shift;
 
     $folderID = shift;
 
     $folderID = shift;
 
     $type = shift;
 
     $type = shift;
 
+
 
     $uuidGen = new Data::UUID;
 
     $uuidGen = new Data::UUID;
 
     $inventoryID = $uuidGen->create_str();
 
     $inventoryID = $uuidGen->create_str();
 
 
     print INVIDATOUT "<Section Name=\"" . $name . "\">\n";
 
     print INVIDATOUT "<Section Name=\"" . $name . "\">\n";
 
     print INVIDATOUT "<Key Name=\"inventoryID\" Value=\"" . $inventoryID . "\" />\n";
 
     print INVIDATOUT "<Key Name=\"inventoryID\" Value=\"" . $inventoryID . "\" />\n";
Line 193: Line 207:
 
     print INVIDATOUT "</Section>\n";
 
     print INVIDATOUT "</Section>\n";
 
     print INVIDATOUT "\n";
 
     print INVIDATOUT "\n";
 
+
}
+
}
 
+
   
   
+
sub writeAsset() {
sub writeAsset() {
+
 
+
 
     $dir = shift;
 
     $dir = shift;
 
     $name = shift;
 
     $name = shift;
 
     $type = shift;
 
     $type = shift;
 
+
 
     $uuidGen = new Data::UUID;
 
     $uuidGen = new Data::UUID;
 
     $assetID = $uuidGen->create_str();
 
     $assetID = $uuidGen->create_str();
 
+
 
     print ASSETDATOUT "<Section Name=\"" . $name . "\">\n";
 
     print ASSETDATOUT "<Section Name=\"" . $name . "\">\n";
 
     print ASSETDATOUT "<Key Name=\"assetID\" Value=\"" . $assetID . "\" />\n";
 
     print ASSETDATOUT "<Key Name=\"assetID\" Value=\"" . $assetID . "\" />\n";
Line 214: Line 227:
 
     print ASSETDATOUT "</Section>\n";
 
     print ASSETDATOUT "</Section>\n";
 
     print ASSETDATOUT "\n";
 
     print ASSETDATOUT "\n";
 
+
 
     return $assetID;
 
     return $assetID;
 
+
 
}
+
}

Latest revision as of 23:13, 3 March 2012

[edit] 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.

[edit] 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

[edit] 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