// Given a hash for an SOG, return a handle for the SOG entry. // If there is no SOG info in the database, return 'null'. public async Task <LHandle> GetHandle(BHash pHash) { LHandle ret = null; string filename = PersistRules.GetFilename(PersistRules.AssetType.Scene, _scene.RegionInfo.RegionName, pHash.ToString(), _context.parms); filename = Path.GetFileNameWithoutExtension(filename); string dir = PersistRules.StorageDirectory(pHash.ToString(), _context.parms); // Heavy handed async stuff but the checks for existance could take a while // if the storage system is remote. if (await Task.Run(() => { return(Directory.Exists(dir) && (File.Exists(Path.Combine(dir, pHash + ".gltf")) || File.Exists(Path.Combine(dir, pHash + ".glb")))); })) { ret = new LHandle(pHash, dir); } return(ret); }
private async Task ConvertRegionAssets() { _assetTools = new LodenAssets(_scene, LContext); // Subscribe to changes in the region so we know when to start rebuilding // TODO: BHash regionHash = LodenRegion.CreateRegionHash(_scene); LContext.log.DebugFormat("{0} SOGs in region: {1}", _logHeader, _scene.GetSceneObjectGroups().Count); LContext.log.DebugFormat("{0} Computed region hash: {1}", _logHeader, regionHash.ToString()); // Cleaned up region identifier string regionIdentifier = _scene.RegionInfo.RegionID.ToString().Replace("-", ""); using (AssetManager assetManager = new AssetManager(_scene.AssetService, LContext.log, LContext.parms)) { string specFilename = regionIdentifier + ".json"; RegionTopLevelSpecURL = CreateFileURI(regionIdentifier + ".json", LContext.parms); // See if region specification file has been built bool buildRegion = true; try { string regionSpec = await assetManager.AssetStorage.FetchText(specFilename); if (!String.IsNullOrEmpty(regionSpec)) { // Read in the spec file TileSet regionTiles = TileSet.FromString(regionSpec); if (regionTiles.root.content.extras.ContainsKey("contentHash")) { // If the content hash matches, the region doesn't need rebuilding if ((string)regionTiles.root.content.extras["contentHash"] == regionHash.ToString()) { LContext.log.DebugFormat("{0} Content hash matches. Not rebuilding", _logHeader); buildRegion = false; } else { LContext.log.DebugFormat("{0} Content hash does not match. Rebuilding", _logHeader); } } } } catch (Exception e) { LContext.log.ErrorFormat("{0} Exception reading region spec file: {1}", _logHeader, e); buildRegion = true; } if (buildRegion) { // The region has not been built. LContext.log.DebugFormat("{0}: region does not match. Rebuilding", _logHeader); // Convert the OpenSimulator scene to BScene object for manipulation BScene bScene = await ConvertSceneToBScene(assetManager); // Write out the 'top level' (highest quality) version of the region LHandle topLevelHandle = await WriteOutLevel(regionHash, bScene, assetManager); // Create the region specification which defines the top of the region LOD tree LHandle regionSpecFile = await WriteRegionSpec(assetManager, regionHash, specFilename, topLevelHandle.Filename); } else { LContext.log.DebugFormat("{0}: region spec file exists.", _logHeader); } } // Partition region and verify all partitions have been created and not different. // TODO: // Walk up the LOD chain and verify existance or build each LOD level // TODO: // Wait for changes and do rebuilds of necessary // TODO: }