Esempio n. 1
0
        public bool Load(string res, AssetLoadedCallback callback)
        {
            res = fullResPath(res);
            AssetBundleInfo abInfo = _cfg.GetAssetBundle(res);

            if (abInfo == null)
            {
                BugReport.Report("ResLoader::Load not find res:" + res);
                return(false);
            }

            bool isimmediate = (abInfo.flag & LoadABFlag.IMMEDIATE) == LoadABFlag.IMMEDIATE;
            bool isfixed     = (abInfo.flag & LoadABFlag.FIXED) == LoadABFlag.FIXED;

            if (isimmediate)
            {
                AssetBundle ab = immediateLoadAssetBundle(abInfo);
                callback(ab.LoadAsset(res));
            }
            else
            {
                preImmediateLoadDependAssetBundle(abInfo);
                AssetBundleManager.loadAssetBundle(ResConfig.assetBundleUrlBasePath + abInfo.assetbundlename, abInfo.version, isfixed, (AssetBundle ab) => {
                    callback(ab.LoadAsset(res));
                });
            }

            return(true);
        }
Esempio n. 2
0
        public void LoadAllFromAsset <T>(string bundle, AssetLoadedCallback callback)
        {
            AssetBundleLoadRequest loadRequest = new AssetBundleLoadRequest();

            loadRequest.callback = callback;
            loadRequest.request  = mLoadedAssets[bundle].bundle.LoadAllAssetsAsync <T>();
            mPendingAssetBundleRequests.Add(loadRequest);
        }
Esempio n. 3
0
        public static void UnpackageArchive(string filename, AssetLoadedCallback assetCallback, TerrainLoadedCallback terrainCallback, SceneObjectLoadedCallback objectCallback)
        {
            int successfulAssetRestores = 0;
            int failedAssetRestores = 0;

            try
            {
                using (FileStream fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read))
                {
                    using (GZipStream loadStream = new GZipStream(fileStream, CompressionMode.Decompress))
                    {
                        TarArchiveReader archive = new TarArchiveReader(loadStream);

                        string filePath = "ERROR";

                        byte[] data;
                        TarArchiveReader.TarEntryType entryType;

                        while ((data = archive.ReadEntry(out filePath, out entryType)) != null)
                        {
                            if (filePath.StartsWith(ArchiveConstants.OBJECTS_PATH))
                            {
                                // Deserialize the XML bytes
                                LoadObjects(data, objectCallback, fileStream.Position, fileStream.Length);
                            }
                            else if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH))
                            {
                                if (LoadAsset(filePath, data, assetCallback, fileStream.Position, fileStream.Length))
                                    successfulAssetRestores++;
                                else
                                    failedAssetRestores++;
                            }
                            else if (filePath.StartsWith(ArchiveConstants.TERRAINS_PATH))
                            {
                                LoadTerrain(filePath, data, terrainCallback, fileStream.Position, fileStream.Length);
                            }
                            else if (filePath.StartsWith(ArchiveConstants.SETTINGS_PATH))
                            {
                                // FIXME: Support this
                                //LoadRegionSettings(filePath, data);
                            }
                        }

                        archive.Close();
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Log("[OarFile] Error loading OAR file: " + e.Message, Helpers.LogLevel.Error);
                return;
            }

            if (failedAssetRestores > 0)
                Logger.Log(String.Format("[OarFile]: Failed to load {0} assets", failedAssetRestores), Helpers.LogLevel.Warning);
        }
Esempio n. 4
0
        static public int load(IntPtr ctx)
        {
            try
            {
                string prefabPath = Native.duk_require_string_s(ctx, 0);

                IntPtr callbackptr = Native.duk_get_heapptr(ctx, 1);
                Native.duk_push_heapptr(ctx, callbackptr);
                int        callbackref = Native.duv_ref(ctx);
                Context    context     = Engine.GetContent(ctx);
                TsDelegate td          = new TsDelegate(context, callbackref, 1);
                td.AddArgType(0, ARG_TYPE.CSOBJECT, -1, "GameEngine.CsObject");
                AssetLoadedCallback callback = Delegate.CreateDelegate(typeof(AssetLoadedCallback), td, "Deleg", true, true) as AssetLoadedCallback;
                Global.resLoader.Load(prefabPath, callback);

                return(0);
            }
            catch (Exception e)
            {
                return(Native.duk_throw_error(ctx, e.ToString()));
            }
        }
        private static bool LoadAsset(string assetPath, byte[] data, AssetLoadedCallback assetCallback, long bytesRead, long totalBytes)
        {
            // Right now we're nastily obtaining the UUID from the filename
            string filename = assetPath.Remove(0, ArchiveConstants.ASSETS_PATH.Length);
            int i = filename.LastIndexOf(ArchiveConstants.ASSET_EXTENSION_SEPARATOR);

            if (i == -1)
            {
                Logger.Log(String.Format(
                    "[OarFile]: Could not find extension information in asset path {0} since it's missing the separator {1}.  Skipping",
                    assetPath, ArchiveConstants.ASSET_EXTENSION_SEPARATOR), Helpers.LogLevel.Warning);
                return false;
            }

            string extension = filename.Substring(i);
            UUID uuid;
            UUID.TryParse(filename.Remove(filename.Length - extension.Length), out uuid);

            if (ArchiveConstants.EXTENSION_TO_ASSET_TYPE.ContainsKey(extension))
            {
                AssetType assetType = ArchiveConstants.EXTENSION_TO_ASSET_TYPE[extension];
                Asset asset = null;

                switch (assetType)
                {
                    case AssetType.Animation:
                        asset = new AssetAnimation(uuid, data);
                        break;
                    case AssetType.Bodypart:
                        asset = new AssetBodypart(uuid, data);
                        break;
                    case AssetType.Clothing:
                        asset = new AssetClothing(uuid, data);
                        break;
                    case AssetType.Gesture:
                        asset = new AssetGesture(uuid, data);
                        break;
                    case AssetType.Landmark:
                        asset = new AssetLandmark(uuid, data);
                        break;
                    case AssetType.LSLBytecode:
                        asset = new AssetScriptBinary(uuid, data);
                        break;
                    case AssetType.LSLText:
                        asset = new AssetScriptText(uuid, data);
                        break;
                    case AssetType.Notecard:
                        asset = new AssetNotecard(uuid, data);
                        break;
                    case AssetType.Object:
                        asset = new AssetPrim(uuid, data);
                        break;
                    case AssetType.Sound:
                        asset = new AssetSound(uuid, data);
                        break;
                    case AssetType.Texture:
                        asset = new AssetTexture(uuid, data);
                        break;
                    default:
                        Logger.Log("[OarFile] Unhandled asset type " + assetType, Helpers.LogLevel.Error);
                        break;
                }

                if (asset != null)
                {
                    assetCallback(asset, bytesRead, totalBytes);
                    return true;
                }
            }

            Logger.Log("[OarFile] Failed to load asset", Helpers.LogLevel.Warning);
            return false;
        }
Esempio n. 6
0
        public static void UnpackageArchive(string filename, AssetLoadedCallback assetCallback, TerrainLoadedCallback terrainCallback,
                                            SceneObjectLoadedCallback objectCallback, SettingsLoadedCallback settingsCallback)
        {
            int successfulAssetRestores = 0;
            int failedAssetRestores     = 0;

            try
            {
                using (FileStream fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read))
                {
                    using (GZipStream loadStream = new GZipStream(fileStream, CompressionMode.Decompress))
                    {
                        TarArchiveReader archive = new TarArchiveReader(loadStream);

                        string filePath;
                        byte[] data;
                        TarArchiveReader.TarEntryType entryType;

                        while ((data = archive.ReadEntry(out filePath, out entryType)) != null)
                        {
                            if (filePath.StartsWith(ArchiveConstants.OBJECTS_PATH))
                            {
                                // Deserialize the XML bytes
                                if (objectCallback != null)
                                {
                                    LoadObjects(data, objectCallback, fileStream.Position, fileStream.Length);
                                }
                            }
                            else if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH))
                            {
                                if (assetCallback != null)
                                {
                                    if (LoadAsset(filePath, data, assetCallback, fileStream.Position, fileStream.Length))
                                    {
                                        successfulAssetRestores++;
                                    }
                                    else
                                    {
                                        failedAssetRestores++;
                                    }
                                }
                            }
                            else if (filePath.StartsWith(ArchiveConstants.TERRAINS_PATH))
                            {
                                if (terrainCallback != null)
                                {
                                    LoadTerrain(filePath, data, terrainCallback, fileStream.Position, fileStream.Length);
                                }
                            }
                            else if (filePath.StartsWith(ArchiveConstants.SETTINGS_PATH))
                            {
                                if (settingsCallback != null)
                                {
                                    LoadRegionSettings(filePath, data, settingsCallback);
                                }
                            }
                        }

                        archive.Close();
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Log("[OarFile] Error loading OAR file: " + e.Message, Helpers.LogLevel.Error);
                return;
            }

            if (failedAssetRestores > 0)
            {
                Logger.Log(String.Format("[OarFile]: Failed to load {0} assets", failedAssetRestores), Helpers.LogLevel.Warning);
            }
        }
Esempio n. 7
0
        private static bool LoadAsset(string assetPath, byte[] data, AssetLoadedCallback assetCallback, long bytesRead, long totalBytes)
        {
            // Right now we're nastily obtaining the UUID from the filename
            string filename = assetPath.Remove(0, ArchiveConstants.ASSETS_PATH.Length);
            int    i        = filename.LastIndexOf(ArchiveConstants.ASSET_EXTENSION_SEPARATOR);

            if (i == -1)
            {
                Logger.Log(String.Format(
                               "[OarFile]: Could not find extension information in asset path {0} since it's missing the separator {1}.  Skipping",
                               assetPath, ArchiveConstants.ASSET_EXTENSION_SEPARATOR), Helpers.LogLevel.Warning);
                return(false);
            }

            string extension = filename.Substring(i);
            UUID   uuid;

            UUID.TryParse(filename.Remove(filename.Length - extension.Length), out uuid);

            if (ArchiveConstants.EXTENSION_TO_ASSET_TYPE.ContainsKey(extension))
            {
                AssetType assetType = ArchiveConstants.EXTENSION_TO_ASSET_TYPE[extension];
                Asset     asset     = null;

                switch (assetType)
                {
                case AssetType.Animation:
                    asset = new AssetAnimation(uuid, data);
                    break;

                case AssetType.Bodypart:
                    asset = new AssetBodypart(uuid, data);
                    break;

                case AssetType.Clothing:
                    asset = new AssetClothing(uuid, data);
                    break;

                case AssetType.Gesture:
                    asset = new AssetGesture(uuid, data);
                    break;

                case AssetType.Landmark:
                    asset = new AssetLandmark(uuid, data);
                    break;

                case AssetType.LSLBytecode:
                    asset = new AssetScriptBinary(uuid, data);
                    break;

                case AssetType.LSLText:
                    asset = new AssetScriptText(uuid, data);
                    break;

                case AssetType.Notecard:
                    asset = new AssetNotecard(uuid, data);
                    break;

                case AssetType.Object:
                    asset = new AssetPrim(uuid, data);
                    break;

                case AssetType.Sound:
                    asset = new AssetSound(uuid, data);
                    break;

                case AssetType.Texture:
                    asset = new AssetTexture(uuid, data);
                    break;

                default:
                    Logger.Log("[OarFile] Unhandled asset type " + assetType, Helpers.LogLevel.Error);
                    break;
                }

                if (asset != null)
                {
                    assetCallback(asset, bytesRead, totalBytes);
                    return(true);
                }
            }

            Logger.Log("[OarFile] Failed to load asset", Helpers.LogLevel.Warning);
            return(false);
        }
Esempio n. 8
0
        private static void LoadObjects(byte[] objectData, AssetLoadedCallback assetCallback)
        {
            // TODO: If we can get by without XmlDocument it will fix the memory problems when loading large XML files
            XmlDocument doc = new XmlDocument();

            using (XmlTextReader reader = new XmlTextReader(new MemoryStream(objectData)))
            {
                reader.WhitespaceHandling = WhitespaceHandling.None;
                doc.Load(reader);
            }

            XmlNode rootNode = doc.FirstChild;

            if (rootNode.LocalName.Equals("scene"))
            {
                foreach (XmlNode node in rootNode.ChildNodes)
                {
                    AssetPrim linkset = new AssetPrim(node.OuterXml);
                    if (linkset != null)
                        assetCallback(linkset);
                }
            }
            else
            {
                AssetPrim linkset = new AssetPrim(rootNode.OuterXml);
                if (linkset != null)
                    assetCallback(linkset);
            }
        }