Universe.Framework.SceneInfo.UuidGatherer.GatherAssetUuids C# (CSharp) Method

GatherAssetUuids() public method

Gather all the asset uuids associated with a given object.
public GatherAssetUuids ( ISceneEntity sceneObject, AssetType>.IDictionary assetUuids ) : void
sceneObject ISceneEntity The scene object for which to gather assets
assetUuids AssetType>.IDictionary The assets gathered
return void
        public void GatherAssetUuids (ISceneEntity sceneObject, IDictionary<UUID, AssetType> assetUuids)
        {
            //MainConsole.Instance.DebugFormat("[Asset Gatherer]: Getting assets for object {0}, {1}", sceneObject.Name, sceneObject.UUID);

            ISceneChildEntity [] parts = sceneObject.ChildrenEntities ().ToArray ();
            foreach (ISceneChildEntity part in parts) {
                //MainConsole.Instance.DebugFormat("[Archiver]: Getting part {0}, {1} for object {2}", part.Name, part.UUID, sceneObject.UUID);

                try {
                    Primitive.TextureEntry textureEntry = part.Shape.Textures;
                    if (textureEntry != null) {
                        // Get the prim's default texture.  This will be used for faces which don't have their own texture
                        if (textureEntry.DefaultTexture != null)
                            assetUuids [textureEntry.DefaultTexture.TextureID] = AssetType.Texture;

                        if (textureEntry.FaceTextures != null)
                        {
                            // Loop through the rest of the texture faces (a non-null face means the face is different from DefaultTexture)
                            foreach (
                                Primitive.TextureEntryFace texture in textureEntry.FaceTextures.Where (texture => texture != null)) {
                                assetUuids [texture.TextureID] = AssetType.Texture;
                            }
                        }
                    }

                    // If the prim is a sculpt then preserve this information too
                    if (part.Shape.SculptTexture != UUID.Zero)
                        assetUuids [part.Shape.SculptTexture] = AssetType.Texture;

                    TaskInventoryDictionary taskDictionary = (TaskInventoryDictionary)part.TaskInventory.Clone ();

                    // Now analyze this prim's inventory items to preserve all the uuids that they reference
                    foreach (
                        TaskInventoryItem tii in taskDictionary.Values.Where (tii => !assetUuids.ContainsKey (tii.AssetID))) {
                        if (!assetUuids.ContainsKey (tii.AssetID))
                            GatherAssetUuids (tii.AssetID, (AssetType)tii.Type, assetUuids);
                    }

                    GatherMaterialsUuids (part, assetUuids);
                } catch (Exception e) {
                    MainConsole.Instance.ErrorFormat ("[UUID Gatherer]: Failed to get part - {0}", e);
                    MainConsole.Instance.DebugFormat ("[UUID Gatherer]: Texture entry length for prim was {0} (min is 46)", part.Shape.TextureEntry.Length);
                }
            }
        }

Same methods

UuidGatherer::GatherAssetUuids ( UUID assetUuid, AssetType assetType, AssetType>.IDictionary assetUuids ) : void

Usage Example

        /// <summary>
        ///     Archive the region requested.
        /// </summary>
        /// <exception cref="System.IO.IOException">if there was an io problem with creating the file</exception>
        public void ArchiveRegion()
        {
            Dictionary<UUID, AssetType> assetUuids = new Dictionary<UUID, AssetType>();

            ISceneEntity[] entities = m_scene.Entities.GetEntities();
            List<ISceneEntity> sceneObjects = new List<ISceneEntity>();
            int numObjectsSkippedPermissions = 0;

            // Filter entities so that we only have scene objects.
            // FIXME: Would be nicer to have this as a proper list in SceneGraph, since lots of methods
            // end up having to do this
            foreach (ISceneEntity entity in entities.Where(entity => !entity.IsDeleted && !entity.IsAttachment))
            {
                if (!CanUserArchiveObject(m_scene.RegionInfo.EstateSettings.EstateOwner, entity, m_checkPermissions))
                    // The user isn't allowed to copy/transfer this object, so it will not be included in the OAR.
                    ++numObjectsSkippedPermissions;
                else
                    sceneObjects.Add(entity);
            }

            UuidGatherer assetGatherer = new UuidGatherer(m_scene.AssetService);

            foreach (ISceneEntity sceneObject in sceneObjects)
            {
                assetGatherer.GatherAssetUuids(sceneObject, assetUuids);
            }

            MainConsole.Instance.InfoFormat(
                "[ARCHIVER]: {0} scene objects to serialize requiring save of {1} assets",
                sceneObjects.Count, assetUuids.Count);

            if (numObjectsSkippedPermissions > 0)
            {
                MainConsole.Instance.DebugFormat(
                    "[ARCHIVER]: {0} scene objects skipped due to lack of permissions",
                    numObjectsSkippedPermissions);
            }

            // Make sure that we also request terrain texture assets
            RegionSettings regionSettings = m_scene.RegionInfo.RegionSettings;

            if (regionSettings.TerrainTexture1 != RegionSettings.DEFAULT_TERRAIN_TEXTURE_1)
                assetUuids[regionSettings.TerrainTexture1] = AssetType.Texture;

            if (regionSettings.TerrainTexture2 != RegionSettings.DEFAULT_TERRAIN_TEXTURE_2)
                assetUuids[regionSettings.TerrainTexture2] = AssetType.Texture;

            if (regionSettings.TerrainTexture3 != RegionSettings.DEFAULT_TERRAIN_TEXTURE_3)
                assetUuids[regionSettings.TerrainTexture3] = AssetType.Texture;

            if (regionSettings.TerrainTexture4 != RegionSettings.DEFAULT_TERRAIN_TEXTURE_4)
                assetUuids[regionSettings.TerrainTexture4] = AssetType.Texture;

            TarArchiveWriter archiveWriter = new TarArchiveWriter(m_saveStream);

            // Asynchronously request all the assets required to perform this archive operation
            ArchiveWriteRequestExecution awre
                = new ArchiveWriteRequestExecution(
                    sceneObjects,
                    m_scene.RequestModuleInterface<ITerrainModule>(),
                    m_scene.RequestModuleInterface<IRegionSerialiserModule>(),
                    m_scene,
                    archiveWriter,
                    m_requestId);

            new AssetsRequest(
                new AssetsArchiver(archiveWriter), assetUuids,
                m_scene.AssetService, awre.ReceivedAllAssets).Execute();
        }
All Usage Examples Of Universe.Framework.SceneInfo.UuidGatherer::GatherAssetUuids