public JObject GetJSONLine() { JObject jsonLine = new JObject(); jsonLine[JSON_TOP] = UtilScript.Vector3ToJson(top); jsonLine[JSON_BOTTOM] = UtilScript.Vector3ToJson(bottom); jsonLine[JSON_MATERIAL] = material; jsonLine[JSON_HAS_DOT] = hasDots; return(jsonLine); }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Space)) { Debug.Log("tolerance: " + tolerance); Debug.Log("End count:" + lines.Count); part1 = !part1; SetColorToPart(); int part = 2; if (part1) { part = 1; } StartCoroutine(UploadPNG("Lumarca" + Camera.main.pixelWidth + "x" + Camera.main.pixelHeight + "_DotSize" + dotSize + "Depth" + numDepths + "Part" + part)); JSONArray jPositions = new JSONArray(); for (int i = 0; i < lines.Count; i++) { jPositions[i] = UtilScript.Vector3ToJson(lines[i]); } BinaryWriter writer = new BinaryWriter(File.Open("positions.json", FileMode.Create)); jPositions.Serialize(writer); writer.Close(); BinaryReader reader = new BinaryReader(File.Open("positions.json", FileMode.Open)); JSONNode ja = SimpleJSON.JSONNode.Deserialize(reader); Debug.Log("Vec3: " + ja[0].ToString()); Debug.Log("Vec3: " + JSON.Parse(ja[0])["x"]); for (int i = 0; i < ja.Count; i++) { Debug.Log("jn: " + i + " : " + JSON.Parse(ja[i])["x"]); } } // DrawBox(); }
public void printToXML() { LoadLumarca ll = Camera.main.GetComponent <LoadLumarca>(); JObject result = new JObject(); Vector3[] front = ll.front; Vector3[] back = ll.back; JObject top = new JObject(); JObject bottom = new JObject(); result["top"] = top; result["bottom"] = bottom; // ArgumentException: Can not add Newtonsoft.Json.Linq.JObject to Newtonsoft.Json.Linq.JObject. // Newtonsoft.Json.Linq.JObject.ValidateToken (Newtonsoft.Json.Linq.JToken o, Newtonsoft.Json.Linq.JToken existing) (at Assets/Scripts/JsonDotNet/Source/Linq/JObject.cs:185) // Newtonsoft.Json.Linq.JContainer.InsertItem (Int32 index, Newtonsoft.Json.Linq.JToken item) (at Assets/Scripts/JsonDotNet/Source/Linq/JContainer.cs:296) // Newtonsoft.Json.Linq.JObject.InsertItem (Int32 index, Newtonsoft.Json.Linq.JToken item) (at Assets/Scripts/JsonDotNet/Source/Linq/JObject.cs:177) // Newtonsoft.Json.Linq.JContainer.AddInternal (Int32 index, System.Object content) (at Assets/Scripts/JsonDotNet/Source/Linq/JContainer.cs:521) // Newtonsoft.Json.Linq.JContainer.Add (System.Object content) (at Assets/Scripts/JsonDotNet/Source/Linq/JContainer.cs:492) // CalcLinePositions.printToXML () (at Assets/Princeton/scripts/CalcLinePositions.cs:101) // CalcLinePositions.Update () (at Assets/Princeton/scripts/CalcLinePositions.cs:24) JArray topCorners = new JArray(); top["topCorners"] = topCorners; topCorners.Add(UtilScript.Vector3ToJson(front[3])); topCorners.Add(UtilScript.Vector3ToJson(front[2])); topCorners.Add(UtilScript.Vector3ToJson(back[2])); topCorners.Add(UtilScript.Vector3ToJson(back[3])); JArray botCorners = new JArray(); bottom["botCorners"] = botCorners; botCorners.Add(UtilScript.Vector3ToJson(front[0])); botCorners.Add(UtilScript.Vector3ToJson(front[1])); //Back Corners Vector3 pivot = new Vector3(back[1].x, frontBottomY, front[1].z); float dist = Vector3.Distance(pivot, back[1]); Vector3 backCorner1 = new Vector3(back[1].x, frontBottomY, dist + frontBottomZ); Vector3 backCorner2 = new Vector3(back[0].x, frontBottomY, dist + frontBottomZ); botCorners.Add(UtilScript.Vector3ToJson(backCorner1)); botCorners.Add(UtilScript.Vector3ToJson(backCorner2)); // // for(int i = 0; i < back.Length; i++){ // print("back[" + i + "]: " + UtilScript.ActualVector3(back[i])); // botCorners.Add(UtilScript.Vector3ToJson(back[i])); // } print("Count:" + topList.Count); JArray topLines = new JArray(); top["topLines"] = topLines; JArray botLines = new JArray(); bottom["botLines"] = botLines; for (int i = 0; i < topList.Count; i++) { topLines.Add(UtilScript.Vector3ToJson(topList[i])); botLines.Add(UtilScript.Vector3ToJson(botList[i])); // print("->500: " + UtilScript.ActualVector3(top[i]) + "->" + UtilScript.ActualVector3(bottom[i])); } UtilScript.WritePrettyJSONToFile("LumarcaFrustum-LinePositions.json", result); }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Space)) { // if(Input.mousePosition.x > 300 && !once){ once = true; Debug.Log("tolerance: " + tolerance); Debug.Log("End count:" + lines.Count); part1 = !part1; SetColorToPart(); int part = 2; if (part1) { part = 1; } StartCoroutine(UploadPNG(fileNamePre + "Lumarca" + Camera.main.pixelWidth + "x" + Camera.main.pixelHeight + "_DotSize" + yarnWidth + "Depth" + numDepths + "Part" + part)); BinaryWriter writer; StringReader reader; switch (lumarcaMode) { case LUMARCA_MODE.VLines: JObject jObject = new JObject(); jObject[PROP_LUMARCA_SIZE] = cfs.physicalWidth; jObject[PROP_PROJ_POS] = UtilScript.Vector3ToJson(cfs.transform.position); jObject[PROP_THROW_RATIO] = cfs.throwRatio; jObject[PROP_PHYSICAL_WIDTH] = cfs.physicalWidth; jObject[PROP_CEILING_MOUNT] = cfs.ceilingMounted; JArray jPositions = new JArray(); jObject[PROP_POSITIONS] = jPositions; for (int i = 0; i < lines.Count; i++) { jPositions.Add(UtilScript.Vector3ToJson(lines[i])); } string positionFile = System.IO.Path.Combine(Application.dataPath, fileNamePre + "-positions.json"); writer = new BinaryWriter(File.Open(positionFile, FileMode.Create)); string objStr = JsonConvert.SerializeObject(jObject, Formatting.Indented); writer.Write(objStr); writer.Close(); string exportPath = Application.dataPath + "/" + fileNamePre + "-" + cfs.physicalWidth + "-export.json"; UtilScript.SaveStringToFile(exportPath, objStr); JObject o1 = JObject.Parse(File.ReadAllText(exportPath)); Debug.Log("Save File: " + positionFile); Debug.Log("exportPath File: " + exportPath); Debug.Log("Vec3: " + o1["ThrowRatio"]); break; case LUMARCA_MODE.Dots: // for(int i = 0; i < dots.Count; i++){ // jPositions[i] = UtilScript.Vector3ToJson(dots[i]); // } // // string dotFile = System.IO.Path.Combine(Application.dataPath, "DotPositions.json"); // // writer = new BinaryWriter(File.Open(dotFile, FileMode.Create)); // jPositions.Serialize(writer); // writer.Close(); // // reader = new BinaryReader(File.Open(dotFile, FileMode.Open)); // ja = SimpleJSON.JSONNode.Deserialize(reader); // // reader.Close(); // // // for(int i = 0; i < ja.Count; i++){ // Debug.Log ("jn: " + i + " : " + JSON.Parse(ja[i])["x"]); // } break; } } // DrawBox(); }