public static void LoadAndConstruct <T>(string dir, Action <float> onProgress, Action <T> onDone, Action <string> onError) where T : Model { try { var serializer = new XmlSerializer(typeof(Manifest)); var stream = new FileStream(dir + "/manifest.xml", FileMode.Open); instance = serializer.Deserialize(stream) as Manifest; stream.Close(); } catch { if (onError != null) { onError("Failed to deserialize manifest."); } return; } LoadModelDelegate loadModelCallback = delegate(ModelEntry entry) { try { Type type = TypeHelper.GetGlobalType(entry.Type); var entrySerializer = new XmlSerializer(type); var entryStream = new FileStream(dir + "/" + entry.Id + ".xml", FileMode.Open); Model model = entrySerializer.Deserialize(entryStream) as Model; entryStream.Close(); return(model); } catch { return(null); } }; Coroutiner.Start(ConstructAsync <T>(loadModelCallback, onProgress, onDone, onError)); }
public static void LoadAndConstruct <T>(ModelBlobs modelBlobs, Action <float> onProgress, Action <T> onDone, Action <string> onError) where T : Model { if (!modelBlobs.ContainsKey("manifest")) { if (onError != null) { onError("Failed to load modelBlobs as it does not contain a manifest."); } return; } instance = modelBlobs["manifest"].XmlDeserializeFromString <Manifest>(); if (instance == null) { if (onError != null) { onError("Failed to deserialize manifest."); } return; } LoadModelDelegate loadModelCallback = delegate(ModelEntry entry) { return(modelBlobs[entry.Id].XmlDeserializeFromString(TypeHelper.GetGlobalType(entry.Type)) as Model); }; Coroutiner.Start(ConstructAsync <T>(loadModelCallback, onProgress, onDone, onError)); }
protected override void OnLoad() { _load = GetMethod <LoadDelegate>("hcp_Load", true); _unload = GetMethod <UnloadDelegate>("hcp_Unload", false); _toValue = GetMethod <ToValueDelegate>("hcp_tovalue", false); _getArgumentHandle = GetMethod <GetArgumentHandleDelegate>("hcp_argat", false); _getMessage = GetMethod <GetMessageDelegate>("hcp_GetMessage", false); _encode = GetMethod <EncodeDelegate>("hcp_Encode", false); _decode = GetMethod <DecodeDelegate>("hcp_Decode", false); _newCodec = GetMethod <NewCodecDelegate>("hcp_NewCodec", false); _closeCodec = GetMethod <CloseCodecDelegate>("hcp_CloseCodec", false); _loadCodec = GetMethod <LoadCodecDelegate>("hcp_LoadCodec", false); _loadModel = GetMethod <LoadModelDelegate>("hcp_LoadModel", false); try { _state = _load(); } catch (Exception x) { throw new Exception("Error occured while calling 'hcp_Load': " + x.Message); } }
private static IEnumerator ConstructAsync <T>(LoadModelDelegate loadModelCallback, Action <float> onProgress, Action <T> onDone, Action <string> onError) where T : Model { int i = 0; float startTime = Time.realtimeSinceStartup; T rootModel = null; while (i < instance.Entries.Count) { Model model = loadModelCallback(instance.Entries[i]); if (model == null) { if (onError != null) { onError("Failed to deserialize type '" + instance.Entries[i].Type + "' with id '" + instance.Entries[i].Id + "'"); } yield break; } if (model is T) { rootModel = model as T; } i++; if (Time.realtimeSinceStartup - startTime > Time.smoothDeltaTime) { if (onProgress != null) { onProgress((float)i / (float)instance.Entries.Count); } yield return(new WaitForEndOfFrame()); } } if (onDone != null) { onDone(rootModel); } }
public static extern IntPtr mleap_transformer_load_ex(string c_path, LoadModelDelegate c_load_model, TransformDelegate c_transform);