public void Init(float scale = 1f) { graph = TGraph.GlobalVariables.Graph; nodeCount = graph.nodes.Count; mesh = graph.edgeObject.GetComponent <MeshFilter>().sharedMesh; vertexCount = mesh.vertexCount; vertices = mesh.vertices; vertexCopies = (Vector3[])vertices.Clone(); RescaleSlider(scale); }
void Update() { if (OVRInput.GetDown(OVRInput.Button.PrimaryHandTrigger)) { if (TGraph.GlobalVariables.Beam) { GameObject.Find("LCone").GetComponent <MeshRenderer>().enabled = true; } } if (OVRInput.GetDown(OVRInput.Button.SecondaryHandTrigger)) { if (TGraph.GlobalVariables.Beam) { GameObject.Find("RCone").GetComponent <MeshRenderer>().enabled = true; } } if (OVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger)) { LeftStart = LeftHand.position; AvgStart = (LeftStart + RightStart) / 2; StartDist = Vector3.Magnitude(LeftStart - RightStart); CurScale = GraphParent.transform.localScale; CurRot = GraphParent.transform.localEulerAngles; CurPos = GraphParent.transform.localPosition; Manipulated = false; } if (OVRInput.GetDown(OVRInput.Button.SecondaryIndexTrigger)) { // if (graph == null) { graph = TGraph.GlobalVariables.Graph; nodeCount = graph.nodes.Count; mesh = graph.edgeObject.GetComponent <MeshFilter>().sharedMesh; vertexCount = mesh.vertexCount; vertices = mesh.vertices; vertexCopies = (Vector3[])vertices.Clone(); } Manipulated = false; CurScale = GraphParent.transform.localScale; CurRot = GraphParent.transform.localEulerAngles; CurPos = GraphParent.transform.localPosition; RightStart = RightHand.position; AvgStart = (LeftStart + RightStart) / 2; StartDist = Vector3.Magnitude(LeftStart - RightStart); var a = RightStart - GraphParent.transform.position; var b = RightHand.position - GraphParent.transform.position; StartAngle = Vector3.SignedAngle(a, b, Vector3.up); } if (OVRInput.Get(OVRInput.Button.PrimaryIndexTrigger) && OVRInput.Get(OVRInput.Button.SecondaryIndexTrigger)) { if (StartDist >= 0.01f) { float angle = Vector3.Angle(Vector3.up, RightStart - LeftStart); if (angle > 90) { angle = 180 - angle; } if (angle <= 25) { Rescale(1); } else if (angle <= 65) { Rescale(); } else { Rescale(0); Rescale(2); } } } //translate else if (!Manipulated && OVRInput.Get(OVRInput.Button.PrimaryIndexTrigger)) { GraphParent.transform.localPosition = CurPos + (LeftHand.transform.position - LeftStart) * 30; if (OVRInput.GetUp(OVRInput.Button.PrimaryIndexTrigger)) { CurPos = GraphParent.transform.localPosition; } } //rotate else if (!Manipulated && OVRInput.Get(OVRInput.Button.SecondaryIndexTrigger)) { var yRot = CurRot.y; //if (yRot < 0) yRot = 360 + yRot; var a = RightStart - GraphParent.transform.position; var b = RightHand.position - GraphParent.transform.position; //var perp = Vector3.Cross(a, Vector3.up); //b = Vector3.Project(perp, b); a.y = 0; b.y = 0; var newYRot = (yRot + 50 * Vector3.SignedAngle(a, b, Vector3.up)) % 360; if (newYRot < 0) { newYRot = 360 + newYRot; } GraphParent.transform.localEulerAngles = new Vector3(0, newYRot, 0); // Debug.Log(CurRot.y + " new: " + newYRot+a+" "+b+" dangle "+( 50 * Vector3.SignedAngle(a, b, Vector3.up))); if (OVRInput.GetUp(OVRInput.Button.SecondaryIndexTrigger)) { CurRot = GraphParent.transform.localEulerAngles; } } if (Manipulated && (OVRInput.GetUp(OVRInput.Button.PrimaryIndexTrigger) || OVRInput.GetUp(OVRInput.Button.SecondaryIndexTrigger))) { /* * * for (; j < nodeCount; ++j) * { * NodeParent.GetChild(j).transform.localPosition = factor * graph.nodes[j].pos; * } * for (; e < vertexCount; ++e) * { * vertices[e] = vertexCopies[e] * factor; * } * j = e = 0; */ vertexCopies = (Vector3[])vertices.Clone(); for (int i = 0; i < nodeCount; ++i) { graph.nodes[i].pos = graph.nodes[i].nodeObject.transform.localPosition; } } }
public static void Convert(string s, string name) { var text = s.Replace("@value", "id"); text = text.Replace("@", ""); text = text.Replace("specified-in", "specified"); text = text.Replace("instance-of", "instanceof"); text = text.Replace("https://mathhub.info/ulo", ""); text = text.Replace("tmpuri:/", ""); if (text[0] == '[') { text = text.Remove(0, 1); } if (text[text.Length - 1] == ']') { text = text.Remove(text.Length - 1, 1); } //text.Replace("?", "/"); // Debug.Log(text); // var gSingle = JsonUtility.FromJson<RDFGraphSingle>(text); RDFGraph g = JsonUtility.FromJson <RDFGraph>(text); /* * for (int i = 0; i < g.graph.Count; ++i) * { * var node = g.graph[i]; * * if(node.name ==""||node.name == null) * { * node.name = node.id; * } * * if (node.uses == null) * { * var at = new List<RDFID>(); * at.Add(gSingle.graph[i].uses); * node.uses = at; * } * if (node.justifies == null) * { * var at = new List<RDFID>(); * at.Add(gSingle.graph[i].justifies); * node.justifies = at; * } * * if (node.specifies == null) * { * var at = new List<RDFID>(); * at.Add(gSingle.graph[i].specifies); * node.specifies = at; * } * if (node.instanceof == null) * { * var at = new List<RDFID>(); * at.Add(gSingle.graph[i].instanceof); * node.instanceof = at; * } * * * * }*/ var rdfEdges = new List <TGraph.ReadJSON.MyEdge>(); var rdfNodes = new List <TGraph.ReadJSON.MyNode>(); var rdfChapters = new List <TGraph.ReadJSON.MyChapter>(); List <string> sourceRefs = new List <string>(); /* var mainNode = new TGraph.ReadJSON.MyNode * { * label = name, * id = name, * radius = Mathf.Sqrt(g.graph.Count) * 0.05f, * }; * * rdfNodes.Add(mainNode); */ for (int i = 0; i < g.graph.Count; i++) { var node = g.graph[i]; // Debug.Log(node.name.id +" "+node.id); if (node.name.Count == 0) { node.name = new List <RDFID> { new RDFID(node.id) }; } if (node.specifies.Count == 0 && node.uses.Count == 0) { continue; } // Debug.Log(node.specifies.Count); rdfNodes.Add(new TGraph.ReadJSON.MyNode { label = node.name[0].id, id = node.id, radius = Mathf.Sqrt(node.specifies.Count) * 0.05f, // style = node.paratype[0].id }); foreach (var to in node.specifies) { rdfEdges.Add(new TGraph.ReadJSON.MyEdge { from = node.id, to = to.id, style = "specifies" }); } foreach (var to in node.uses) { rdfEdges.Add(new TGraph.ReadJSON.MyEdge { from = node.id, to = to.id, style = "uses" }); } /* * if (node.specifies.Count > 0) * { * var specifiedNodes = new List<string>(); * var specifiedChapters = new List<string>(); * foreach (var s in node.specifies) * { * if (g.graph.Find(n => n.id == s.id).specifies.Count == 0) //rdf node has no other chapters = > isNode * specifiedNodes.Add(s.id); * else * specifiedChapters.Add(s.id); * } * rdfChapters.Add(new TGraph.ReadJSON.MyChapter * { * label = node.name, * id = node.id, * highlevel = true, * chapters = specifiedChapters, * nodes = specifiedNodes * }); * } * * else * { * rdfNodes.Add(new TGraph.ReadJSON.MyNode * { * label = node.name, * id = node.id, * style = node.paratype * }); * }*/ /* * string origin = node.id; * if (node.specifiedin.Count > 0) * { * origin = node.specifiedin[0].id; * }*/ /* * //other variant * string origin = mainNode.id; * * foreach (var to in node.uses) * { * * string target = to.id; * var toNode = g.graph.Find(n => n.id == target); * if (toNode != null) target = mainNode.id;// if (toNode != null) target =toNode.specifiedin[0].id; * else * { * var splitted = target.Split('?'); * target = splitted[1]; * // Debug.Log(target); * } * * * if (target!=origin&&rdfEdges.Find(e=>e.id == (origin+target))==null) * rdfEdges.Add(new TGraph.ReadJSON.MyEdge * { * from = origin, * to = target, * style = "uses", * id = origin+target * * }); * }*/ /* * foreach (var to in node.instanceof) * { * rdfEdges.Add(new TGraph.ReadJSON.MyEdge * { * from = node.id, * to = to.id, * style = "instanceof" * }); * } * * if (node.sourceref != null && node.sourceref != "") * { * * rdfEdges.Add(new TGraph.ReadJSON.MyEdge * { * to = node.id, * from = node.sourceref, * style = "sourceref" * }); * /* * if (!sourceRefs.Contains(node.sourceref)) * { * sourceRefs.Add(node.sourceref); * rdfChapters.Add(new TGraph.ReadJSON.MyChapter * { * label = node.sourceref, * id = node.sourceref, * highlevel = true, * nodes = new List<string>() * }); * } * rdfChapters.Find(c => c.id == node.sourceref).nodes.Add(node.id); * / * * }*/ /* * foreach (var to in node.justifies) * { * rdfEdges.Add(new TGraph.ReadJSON.MyEdge * { * from = node.id, * to = to.id, * style = "justifies" * }); * * }*/ } var tGraph = new TGraph.ReadJSON.MyGraph { nodes = rdfNodes, edges = rdfEdges, chapters = rdfChapters }; string json = JsonUtility.ToJson(tGraph, true); if (Path == "" || Path == null) { Path = Application.dataPath + "/"; } File.WriteAllText(Path + name + ".json", json); Debug.Log("completed " + Path + name + ".json"); }
protected override void GrabBegin() { DistanceGrabbable closestGrabbable = m_target; Collider closestGrabbableCollider = m_targetCollider; GrabVolumeEnable(false); if (closestGrabbable != null) { if (closestGrabbable.isGrabbed) { ((DistanceGrabber)closestGrabbable.grabbedBy).OffhandGrabbed(closestGrabbable); } m_grabbedObj = closestGrabbable; m_grabbedObj.GetComponent <Rigidbody>().constraints = RigidbodyConstraints.None; if (graph == null) { graph = TGraph.GlobalVariables.Graph; handIndex = graph.handIndex; graph.handIndex++; } SelectNode(closestGrabbable.transform.GetSiblingIndex()); Debug.Log(graph.selectedNodes[handIndex] + " other:" + graph.selectedNodes[(handIndex + 1) % 2]); /* * for (int i = 0; i < removeList.Count; i++) * { * int idx = removeList[i]; * * graph.selectedNodes.Remove(graph.nodes[idx]); * * if (!graph.selectedNodes.Contains(graph.nodes[idx])) * { * graph.nodes[idx].labelObject.GetComponent<TextMesh>().color = new Color(0.87f, 0.87f, 0.7f); * foreach (int nidx in graph.nodes[idx].connectedNodes) * { * graph.nodes[nidx].labelObject.layer = 18; * graph.nodes[nidx].labelObject.GetComponent<TextMesh>().color = new Color(0.87f, 0.87f, 0.7f); * } * GameObject.Destroy(graph.nodes[idx].nodeEdgeObject); * } * * * removeList.Remove(idx); * i--; * * } * * * * if (!graph.selectedNodes.Contains(graph.nodes[nodeId])) * { * var edges = new List<TGraph.ReadJSON.MyEdge>(); * // foreach (TGraph.ReadJSON.MyNode node in graph.selectedNodes) * { * TGraph.ReadJSON.MyNode node = graph.nodes[nodeId]; * * node.labelObject.GetComponent<TextMesh>().color = new Color(0.6f, 0.6f, 0.05f); * foreach (int nidx in node.connectedNodes) * { * graph.nodes[nidx].labelObject.layer = 0; * graph.nodes[nidx].labelObject.GetComponent<TextMesh>().color = new Color(0.6f, 0.6f, 0.05f); * } * foreach (int idx in node.edgeIndicesIn) * { * edges.Add(graph.edges[idx]); * } * foreach (int idx in node.edgeIndicesOut) * { * edges.Add(graph.edges[idx]); * } * } * * graph.nodes[nodeId].nodeEdgeObject = TGraph.ReadJSON.BuildEdges(edges, graph, graph.nodeDict, graph.edgeObject.GetComponent<MeshRenderer>().sharedMaterial); * graph.selectedNodes.Add(graph.nodes[nodeId]); * }*/ m_grabbedObj.GrabBegin(this, closestGrabbableCollider); m_movingObjectToHand = true; m_lastPos = transform.position; m_lastRot = transform.rotation; // If it's within a certain distance respect the no-snap. Vector3 closestPointOnBounds = closestGrabbableCollider.ClosestPointOnBounds(m_gripTransform.position); if (!m_grabbedObj.snapPosition && !m_grabbedObj.snapOrientation && m_noSnapThreshhold > 0.0f && (closestPointOnBounds - m_gripTransform.position).magnitude < m_noSnapThreshhold) { Vector3 relPos = m_grabbedObj.transform.position - transform.position; m_movingObjectToHand = false; relPos = Quaternion.Inverse(transform.rotation) * relPos; m_grabbedObjectPosOff = relPos; Quaternion relOri = Quaternion.Inverse(transform.rotation) * m_grabbedObj.transform.rotation; m_grabbedObjectRotOff = relOri; } else { // Set up offsets for grabbed object desired position relative to hand. m_grabbedObjectPosOff = m_gripTransform.localPosition; if (m_grabbedObj.snapOffset) { Vector3 snapOffset = m_grabbedObj.snapOffset.position; if (m_controller == OVRInput.Controller.LTouch) { snapOffset.x = -snapOffset.x; } m_grabbedObjectPosOff += snapOffset; } m_grabbedObjectRotOff = m_gripTransform.localRotation; if (m_grabbedObj.snapOffset) { m_grabbedObjectRotOff = m_grabbedObj.snapOffset.rotation * m_grabbedObjectRotOff; } } } }
public static void ConvertCoq(TextAsset file) { Path = Application.dataPath + "/Graphs/coqConv" + file.name + ".json"; var text = file.text.Replace("@", ""); text = text.Replace("https://mathhub.info/ulo#", ""); text = text.Replace("-", ""); text = text.Replace("ulo:", ""); text = text.Replace("tmpuri:/", ""); //text.Replace("?", "/"); text = text.Replace("dcterms:", ""); if (text[0] == '[') { text = text.Remove(0, 1); } if (text[text.Length - 1] == ']') { text = text.Remove(text.Length - 1, 1); } var gSingle = JsonUtility.FromJson <CoqGraphSingle>(text); // var gDeclares = JsonUtility.FromJson<CoqGraphDeclares>(text); CoqGraph g = JsonUtility.FromJson <CoqGraph>(text); for (int i = 0; i < g.graph.Count; ++i) { var node = g.graph[i]; if (node.title.id == "" || node.title.id == null) { node.title.id = node.id; } if (node.uses == null) { var at = new List <RDFID>(); at.Add(gSingle.graph[i].uses); node.uses = at; } if (node.declares == null) { var at = new List <RDFID>(); at.Add(gSingle.graph[i].declares); node.declares = at; } /* * if (node.HasMainHypothesis == null) * { * var at = new List<RDFID>(); * at.Add(gSingle.graph[i].HasMainHypothesis); * node.HasMainHypothesis = at; * } * if (node.HasInHypothesis == null) * { * var at = new List<RDFID>(); * at.Add(gSingle.graph[i].HasInHypothesis); * node.HasInHypothesis = at; * } * * if (node.HasMainConclusion == null) * { * var at = new List<RDFID>(); * at.Add(gSingle.graph[i].HasMainConclusion); * node.HasMainConclusion = at; * }*/ } var rdfEdges = new List <TGraph.ReadJSON.MyEdge>(); var rdfNodes = new List <TGraph.ReadJSON.MyNode>(); var rdfChapters = new List <TGraph.ReadJSON.MyChapter>(); foreach (var node in g.graph) { /* * string pid = ""; * * var splitted = node.id.id.Split('/'); * * for(int i= 0; i < splitted.Length - 2;i++) * { * pid += splitted[i]; * } * * * rdfNodes.Add(new TGraph.ReadJSON.MyNode * { * label = node.title.id, * id = node.id.id, * }); * * * * var chapter = rdfChapters.Find(c => c.id == pid); * if (chapter == null) * { * * rdfChapters.Add(new TGraph.ReadJSON.MyChapter * { * label = splitted[splitted.Length-2], * id = pid, * highlevel = true, * chapters = , * nodes = specifiedNodes * }); * } */ if (node.declares.Count > 0) { var specifiedNodes = new List <string>(); var specifiedChapters = new List <string>(); foreach (var d in node.declares) { var s = d.id; if (g.graph.Find(n => n.id == s).declares.Count == 0) // rdf node has no other chapters = > isNode { specifiedNodes.Add(s); } else { Debug.Log("chapter " + s + " of " + node.id); specifiedChapters.Add(s); } } var splitted = node.id.Split('/'); var name = splitted[splitted.Length - 1]; rdfChapters.Add(new TGraph.ReadJSON.MyChapter { label = name, id = node.id, highlevel = true, chapters = specifiedChapters, nodes = specifiedNodes }); } else { var splitted = node.title.id.Split('/'); var name = splitted[splitted.Length - 1]; rdfNodes.Add(new TGraph.ReadJSON.MyNode { label = name, id = node.id, }); } foreach (var to in node.uses) { rdfEdges.Add(new TGraph.ReadJSON.MyEdge { from = node.id, to = to.id, style = "uses" }); } /* * foreach (var to in node.HasMainHypothesis) * { * rdfEdges.Add(new TGraph.ReadJSON.MyEdge * { * from = node.id, * to = g.graph.Find(n=>n.id==to.id).Target.id, * style = "HasMainHypthesis" * }); * }*/ } var tGraph = new TGraph.ReadJSON.MyGraph { nodes = rdfNodes, edges = rdfEdges, chapters = rdfChapters }; string json = JsonUtility.ToJson(tGraph, true); File.WriteAllText(Path, json); }