// Use this for initialization void Start() { cloudContainer = pointCloudContainer.GetComponent <RenderedCloudContainer>(); drawer = GetComponent <Drawer>(); inputField = filePathInputObject.GetComponent <InputField>(); subsampleDropDown = subsampleDropDownObject.GetComponent <Dropdown>(); features = new List <GameObject>(); drawer.width = 10f; }
private GameObject GetPositionOnSurface(Ray ray, PointCloud cloud, Vector3 cameraPos, out int xIndex, out int yIndex, out float zIndex) { xIndex = 0; yIndex = 0; zIndex = 0; RenderedCloudContainer container = pointCloudContainer.GetComponent <RenderedCloudContainer>(); // TODO: Need a KD Tree or something to speed up this O(n^2) solution: Vector3 p00 = container.GetPointObject(0, 0).transform.position; Vector3 p11 = container.GetPointObject(1, 1).transform.position; p00.y = 0; p11.y = 0; float distThreshold = Vector3.Distance(p00, p11) / 2f; // Get points close to ray List <Point> points = new List <Point>(); for (int y = 0; y < container.Height; y++) { for (int x = 0; x < container.Width; x++) { float dist = Vector3.Cross(ray.direction, container.GetPointObject(x, y).transform.position - ray.origin).magnitude; if (dist < distThreshold) { points.Add(container.GetPointCloudPosition(x, y)); } } } // Debug.Log("Selected Points:" + points.Count); // foreach (var p in points) // { // Debug.Log(string.Format("({0}, {1})", p.X, p.Y)); // } if (points.Count == 0) { return(null); } // Order Points by closest to camera points = points.OrderBy(o => Vector3.Distance(container.GetPointObject(o.X, o.Y).transform.position, cameraPos)).ToList(); xIndex = points[0].X; yIndex = points[0].Y; return(container.GetPointObject(points[0].X, points[0].Y)); }
public void DrawCloud(PointCloud cloud, int scalingFactor, Transform parent) { RenderedCloudContainer container = parent.gameObject.GetComponent <RenderedCloudContainer>(); container.ResetCloud(cloud.Width / scalingFactor, cloud.Height / scalingFactor); float offset = width / (cloud.Width - 1); float scale = 0.25f * 32f / cloud.Width * scalingFactor; Vector3 scaleVec = new Vector3(scale, scale, scale); for (int yi = 0; yi < cloud.Height; yi += scalingFactor) { for (int xi = 0; xi < cloud.Width; xi += scalingFactor) { GameObject point = Instantiate(pointPrefab, new Vector3(xi * offset, cloud.Get(xi, yi) * offset, yi * offset), Quaternion.identity); point.name = string.Format("point ({0}, {1})", xi, yi); point.transform.parent = parent; point.transform.localScale = scaleVec; container.SetPoint(point, xi / scalingFactor, yi / scalingFactor, xi, yi, cloud.Get(xi, yi)); } } }