Assets generator
From OpenSimulator
(Difference between revisions)
Line 61: | Line 61: | ||
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 92: | Line 92: | ||
} | } | ||
} | } | ||
− | |||
} | } | ||
Line 115: | Line 114: | ||
$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); | ||
Line 130: | Line 129: | ||
walkTree($parent, ($thisDir . "/" . $_), $level, $assetType); | walkTree($parent, ($thisDir . "/" . $_), $level, $assetType); | ||
} | } | ||
− | + | ||
print("\n"); | print("\n"); | ||
− | + | ||
} | } | ||
− | + | ||
sub getType() { | sub getType() { | ||
Line 187: | Line 186: | ||
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 207: | Line 206: | ||
print ASSETDATOUT "</Section>\n"; | print ASSETDATOUT "</Section>\n"; | ||
print ASSETDATOUT "\n"; | print ASSETDATOUT "\n"; | ||
− | |||
− | |||
+ | return $assetID; | ||
+ | |||
} | } |
Revision as of 06:11, 20 February 2008
###################################### # # genassets.pl # # by: Illuminous Beltran/IBM # # 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. # # Requires the Data::UUID module # # http://search.cpan.org/~rjbs/Data-UUID-1.148/UUID.pm # ###################################### use Data::UUID; # Library name $libName = "My Cool OpenSim 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 OpenSim 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; }