/// <summary> /// Serialize the current object to storage /// </summary> /// <param name="predictions">predictions</param> /// <param name="captureNum">integer to make the file unique</param> public void SaveHologram(int captureNum) { var texture = GetComponent <Renderer>().sharedMaterial.GetTexture("_MainTex") as Texture2D; var imageBytes = texture.GetRawTextureData(); var holoObj = new Holo() { confidences = Predictions.Select(p => p.Confidence).ToList(), labels = Predictions.Select(p => p.Label).ToList(), predictedRects = Predictions.Select(p => p.Rect).ToList(), image = imageBytes, cameraToWorldMatrix = camera2WorldFloat, projectionMatrix = projectionFloat, x = transform.position.x, y = transform.position.y, z = transform.position.z, qx = transform.rotation.x, qy = transform.rotation.y, qz = transform.rotation.z, qw = transform.rotation.w, width = texture.width, height = texture.height, headX = HeadPos.x, headY = HeadPos.y, headZ = HeadPos.z }; string path = Path.Combine(Application.persistentDataPath, $"{FilePrefix}{captureNum++}.json"); HoloSaver.Instance.SaveHologram(holoObj, path); }
public static HologramJsonSchema FromHolo(Holo hologram) => new HologramJsonSchema { X = hologram.Position.X, Y = hologram.Position.Y, Z = hologram.Position.Z, Id = hologram.Id, Name = hologram.Name, Body = hologram.Body };
public override void Tick() { base.Tick(); if (DataRecived) { BaseRotSave = Rsave; BaseSaveStat = savestat; DataRecived = false; } Thing Holo; ThingDef HoloImageDef = ThingDef.Named("HoloOne"); Holo = Find.ThingGrid.ThingAt(base.Position, ThingDef.Named("HoloOne")); if ((!powerComp.PowerOn && Holo != null) || (powerComp.PowerOn && !Toggle && Holo != null)) { Holo.Destroy(); } if (powerComp.PowerOn && Toggle && Holo == null) { GenSpawn.Spawn(HoloImageDef, base.Position); savestat = BaseSaveStat; Rsave = BaseRotSave; if (Holoimage != null) { if (savestat == 0) { Holoimage.holostatus = Hologram.HoloStatus.piramid; } else if (savestat == 1) { Holoimage.holostatus = Hologram.HoloStatus.plant; } else if (savestat == 2) { Holoimage.holostatus = Hologram.HoloStatus.balls; } if (Rsave) { Holoimage.Rswitch = true; } else if (!Rsave) { Holoimage.Rswitch = false; } } } }
public void SaveHologram(Holo holo, string path) { try { #if UNITY_WSA && !UNITY_EDITOR holo.rects = ConvertToWindowsRects(holo.predictedRects); #endif string json = JsonConvert.SerializeObject(holo, Formatting.Indented); File.WriteAllText(path, json); // now the image string imagePath = Path.ChangeExtension(path, ".jpg"); File.WriteAllBytes(imagePath, holo.image); } catch (Exception e) { Debug.Log(e.Message); } }
public Holo RestoreHologram(string path) { string imagePath = Path.ChangeExtension(path, ".jpg"); try { var json = File.ReadAllText(path); Holo holo = JsonConvert.DeserializeObject <Holo>(json); holo.image = File.ReadAllBytes(imagePath); #if UNITY_WSA && !UNITY_EDITOR holo.predictedRects = ConvertToUnityRects(holo.rects); #endif return(holo); } catch (Exception e) { Debug.Log(e.Message); throw; } }
public static bool TryGetHologram(Guid id, out Holo hologram) => Holograms.TryGetValue(id, out hologram);
public static Guid AddHologram(Holo holo) { _listener(holo, null); Holograms[holo.Id] = holo; return(holo.Id); }