Mesh GenerateMeshCloud() { Mesh mesh = new Mesh(); mesh.name = "phantom_workspace_cloud"; mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; int n = 200; List <Vector3> verts = new List <Vector3>(n * n * n); for (int i1 = 0; i1 < n; ++i1) { float t1 = (float)i1 / (float)(n - 1); for (int i2 = 0; i2 < n; ++i2) { float t2 = (float)i2 / (float)(n - 1); for (int i3 = 0; i3 < n; ++i3) { float t3 = (float)i3 / (float)(n - 1); float q1 = Mathf.Lerp(-90, 90, t1) + Random.Range(-1, 1); float q2 = Mathf.Lerp(-85, 120, t2) + Random.Range(-1, 1); float q3 = Mathf.Lerp(-30, 175, t3) + Random.Range(-1, 1); if ((q3 - q2) <= 55 && (q2 - q3) <= 65) { verts.Add(PhantomModel.ToUnity(PhantomModel.ForwardKinematics(q1, q2, q3))); } } } } mesh.SetVertices(verts); mesh.SetIndices(Enumerable.Range(0, verts.Count).ToArray(), MeshTopology.Points, 0); return(mesh); }
void Update() { if (Time.time > nextTime) { fps = frames / deltaTime; nextTime += deltaTime; frames = 0; } frames++; // tau[0] = 0.05 * Input.GetAxis("Horizontal"); // tau[1] = 0.1 * Input.GetAxis("Vertical"); // tau[2] = 0.1 * Input.GetAxis("Vertical2"); Plugin.get_positions(radians); Vector3 target_pos = PhantomModel.FromUnity(target.transform.localPosition); Plugin.set_target(target_pos.x, target_pos.y, target_pos.z); for (int i = 0; i < 3; ++i) { model.Q[i] = Mathf.Rad2Deg * (float)radians[i]; } if (Input.GetKeyDown(KeyCode.R)) { Restart(); } if (Input.GetKeyDown(KeyCode.G)) { Plugin.open_tuner(); } }
Mesh GenerateMeshHull() { Mesh mesh = new Mesh(); mesh.name = "phantom_workspace_hull"; mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; float[] q2s = { 120, -85, 35, 120 }; float[] q3s = { 175, -30, -30, 55 }; float[] ns = { 1000, 200, 80, 200 }; int n = 200; List <Vector3> verts = new List <Vector3>(n * n * n); for (int i1 = 0; i1 < 1000; ++i1) { float t1 = (float)i1 / (float)(1000 - 1); int mult = 1; if (t1 == 0 || t1 == 1) { mult = 50; } for (int k = 0; k < 4; ++k) { int j = (k + 1) % 4; for (int i3 = 0; i3 < mult * ns[k]; ++i3) { float t3 = (float)i3 / (float)(mult * ns[k] - 1); float q1 = Mathf.Lerp(-90, 90, t1) + Random.Range(-0.1f, 0.1f); float q2 = Mathf.Lerp(q2s[k], q2s[j], t3); float q3 = Mathf.Lerp(q3s[k], q3s[j], t3); verts.Add(PhantomModel.ToUnity(PhantomModel.ForwardKinematics(q1, q2, q3))); } } } n = 100; for (int i1 = 0; i1 < n; ++i1) { float t1 = (float)i1 / (float)(n - 1); for (int i2 = 0; i2 < n; ++i2) { float t2 = (float)i2 / (float)(n - 1); for (int i3 = 0; i3 < n; ++i3) { float t3 = (float)i3 / (float)(n - 1); float q1 = Mathf.Lerp(-90, 90, t1) + Random.Range(-1, 1); float q2 = Mathf.Lerp(-85, 120, t2) + Random.Range(-1, 1); float q3 = Mathf.Lerp(-30, 175, t3) + Random.Range(-1, 1); if ((q3 - q2) <= 55 && (q2 - q3) <= 65) { verts.Add(PhantomModel.ToUnity(PhantomModel.ForwardKinematics(q1, q2, q3))); } } } } mesh.SetVertices(verts); mesh.SetIndices(Enumerable.Range(0, verts.Count).ToArray(), MeshTopology.Points, 0); return(mesh); }