// Use this for initialization void Start() { mPointList = new List <Transform>(); mLineList = new List <LineRenderer>(); OT = FindObjectOfType <OctTree>(); for (int i = 0; i < PointNum; i++) { mPointList.Add(GameObject.Instantiate(Point, new Vector3(RandomValue(SpaceScale), RandomValue(SpaceScale), RandomValue(SpaceScale)), Quaternion.identity).transform); mLineList.Add(mPointList[i].GetComponent <LineRenderer>()); } OT.GenerateTree(mPointList); }
// Start is called before the first frame update void Start() { OctTree <string, TestDataClass> .OctTreeNode root = new OctTree <string, TestDataClass> .OctTreeNode(Vector3.zero, new Vector3(50.0f, 50.0f, 50.0f)); m_octTree = new OctTree <string, TestDataClass>(root); Profiler.BeginSample("generate octtree"); m_octTree.GenerateTree(4); Profiler.EndSample(); List <TestDataClass> dataList = new List <TestDataClass>(100); for (int i = 0; i < dataList.Capacity; ++i) { TestDataClass testData = new TestDataClass(); testData.Key = "testString" + i.ToString(); testData.Position = new Vector3(Random.Range(-25.0f, 25.0f), Random.Range(-25.0f, 25.0f), Random.Range(-25.0f, 25.0f)); dataList.Add(testData); } m_pointCloud = new PointCloud <TestDataClass>(dataList); m_octTree.AddPointCloudData(m_pointCloud); //m_ray = new Ray(Vector3.zero, Vector3.up); //m_cachedResults = m_octTree.QueryAgainstNodesRay(m_ray, 3); m_trajectory = new Trajectory(); Vector3 origin = Vector3.zero; Vector3 dir = Vector3.up; float time = 0.0f; for (int i = 0; i < 50; ++i) { Ray ray = new Ray(origin, dir); m_trajectory.AddSegment(time, ray); time += 0.5f; origin += dir; dir = new Vector3(Random.Range(-5.0f, 5.0f), Random.Range(-10.0f, 10.0f), Random.Range(5.0f, 5.0f)).normalized; } Profiler.BeginSample("Query result"); m_cachedResults = new List <CachedResult>(); foreach (var segment in m_trajectory.TrajectorySegments.Values) { var result = m_octTree.QueryAgainstNodesRay(segment.Ray, 4); if (result.Count > 0) { m_cachedResults.Add(new CachedResult { Time = segment.Time, Result = result }); } } Profiler.EndSample(); m_testPlayer = FindObjectOfType <TestPlayer>(); }