using UnityEngine; using System.Collections; using ProceduralToolkit; public class Stylus : MonoBehaviour { public bool bStylus_Enabled; private MeshDraft stylus_MD; private MeshDraft boundary_MD; public Vector3[] vSphereCenters = new Vector3[12]; public Vector3[] vSphereWorldPositions = new Vector3[12]; public float[] fRadii = new float[12]; UI_Ladder ui_Ladder; Vector3 vMarker_Position; public GameObject boundary_Render; private Argos_Particle_Spawner argos_Particle_Spawner; public int myController_ID; void Awake() { ui_Ladder = UI_Ladder.Instance; argos_Particle_Spawner = ui_Ladder.argos_Particle_Spawner; stylus_MD = new MeshDraft(); boundary_MD = new MeshDraft(); GetComponent<MeshFilter>().mesh = stylus_MD.ToMesh(); vMarker_Position = GetComponentInChildren<Marker_Stylus>().transform.localPosition; } public void setID(int id) { myController_ID = id; } public Vector3[] getBrushElement_Positions() { int num_ATT = UI_Ladder.Instance.stylus_Num_Attractors; Vector3 vMarkerPos = GetComponentInChildren<Marker_Stylus>().transform.position; Vector3 vMarkerForward = GetComponentInChildren<Marker_Stylus>().transform.forward; for (int i = 0; i < num_ATT; i++) { vSphereWorldPositions[i] = vSphereCenters[i].z * vMarkerForward + vMarkerPos; } return vSphereWorldPositions; } public void Update_Stylus_From_UI() { float r1 = UI_Ladder.Instance.stylus_Radius_Root; float r2 = UI_Ladder.Instance.stylus_Radius_Tip; int num_ATT = UI_Ladder.Instance.stylus_Num_Attractors; float stylus_Len = UI_Ladder.Instance.stylus_Length; float stylus_Boundary = UI_Ladder.Instance.stylus_Boundary; float sum = 0f; for (int i = 0; i<num_ATT; i++) { fRadii[i] = r1 + i * (r2 - r1) / num_ATT; sum += fRadii[i]; } float wLen = 0; stylus_MD.Clear(); boundary_MD.Clear(); for (int j = 0; j< num_ATT; j++) { wLen += fRadii[j]; vSphereCenters[j] = Vector3.forward * (wLen / sum) * stylus_Len; stylus_MD.Add(MeshDraft.Sphere_Offset(fRadii[j], 12, 12, vSphereCenters[j] + vMarker_Position)); boundary_MD.Add(MeshDraft.Sphere_Offset(fRadii[j]*(1 + stylus_Boundary), 24, 24, vSphereCenters[j] + vMarker_Position)); } GetComponent<MeshFilter>().mesh = stylus_MD.ToMesh(); boundary_Render.GetComponent<MeshFilter>().mesh = boundary_MD.ToMesh(); } }