/// <summary> /// Unity start. /// </summary> public void Start() { m_AllVoxels = new GameObject("AllVoxels"); m_Reconstructor = new Reconstructor(); m_Reconstructor.Start(); m_Reconstructor.GetSpatialHashing().SetSubVoxelPrefab(m_SubVoxelPrefab); m_Mesh = GetComponent <MeshFilter>().mesh; m_Mesh.Clear(); m_Confidences = new float[k_MaxPointCount]; }
public void Update() { UpdateVoxelDistances(Camera.main.transform.position); if (!m_ActiveReconstruction) { return; } // Fill in the data to draw the point cloud. if (Frame.PointCloud.IsUpdatedThisFrame) { // Copy the point cloud points for mesh verticies. NumberOfPoints += Frame.PointCloud.PointCount; for (int i = 0; i < Frame.PointCloud.PointCount; i++) { UnityEngine.Profiling.Profiler.BeginSample("PointCloud"); m_Points[i] = Frame.PointCloud.GetPoint(i); detected_point = Frame.PointCloud.GetPoint(i); int hash = m_Reconstructor.GetSpatialHashing().GetHash(detected_point, m_Reconstructor.GetSpatialHashing().GetScale(), m_Reconstructor.GetSpatialHashing().GetHashTableSize()); if (detected_point.w < Constants.CONFIDENCE_THRESHOLD) { continue; } if (Vector3.Distance(Camera.main.transform.position, detected_point) > m_Reconstructor.GetSpatialHashing().GetMaxReconstructionDistance()) { continue; } if (!m_Reconstructor.GetSpatialHashing().Contains(hash)) { //Debug.Log("Reconstructor" + ": " + "Point > " + m_Points[i].ToString("G4") + ", NEW Hash: " + hash + ", Size: " + reconstructor.spatialHashing.Size()); Vector3 point = Optimization.ScalePoint(detected_point, m_Reconstructor.GetSpatialHashing().GetScale()); pose.position = point; pose.rotation = zeroQuaternion; Anchor anchor = Session.CreateAnchor(pose); GameObject voxelObject = Instantiate(m_VoxelPrefab, pose.position, pose.rotation); float voxelSize = 1.00f / m_Reconstructor.GetSpatialHashing().GetScale(); voxelObject.GetComponent <Renderer>().enabled = m_ActiveRenderer; voxelObject.transform.localScale = new Vector3(voxelSize, voxelSize, voxelSize); GameObject parentVoxelGameObject = new GameObject("_voxel_" + hash); GameObject lodContainer = new GameObject("_levelOfDetail_0"); voxelObject.transform.SetParent(lodContainer.transform); lodContainer.transform.SetParent(anchor.transform); anchor.transform.SetParent(parentVoxelGameObject.transform); parentVoxelGameObject.transform.SetParent(m_AllVoxels.transform); m_TempHashEntry = m_Reconstructor.GetSpatialHashing().CreateHash(detected_point, new Voxel(voxelObject), lodContainer); m_Reconstructor.GetSpatialHashing().AddToTable(m_TempHashEntry); } else { m_TempHashEntry = (HashEntry)m_Reconstructor.GetSpatialHashing().GetFromTable(hash); m_Reconstructor.GetSpatialHashing().AddPointToEntry(detected_point); } UnityEngine.Profiling.Profiler.EndSample(); if (DebugText.Instance.UpdateDistances) { m_Reconstructor.GetSpatialHashing().UpdateDistanceResolution(m_TempHashEntry); } if (!m_ActiveRenderer) { GameObject gameObject = GameObject.Find("_voxel_" + hash); foreach (Renderer r in gameObject.GetComponentsInChildren <Renderer>()) { r.enabled = false; } } CheckPointCloseToPlanes(m_TempHashEntry); } if (m_ActiveRenderer) { DrawPointCloud(); } else { m_Mesh.Clear(); } } GetCubeInfoOnTouch(); }