Пример #1
0
 /// <summary>
 /// Insert a point into the meshing volumes.
 /// </summary>
 /// <param name="p">The 3D point to be inserted.</param>
 /// <param name="obs">The direction of the observation vector from the camera toward the point.</param>
 /// <param name="weight">Weight of the observation.</param>
 public void InsertPoint(Vector3 p, Vector3 obs, float weight)
 {
     if (m_isClearing)
     {
         return;
     }
     m_meshStorage.InsertPoint(p, obs, weight, m_meshingCubePrefab, transform, m_voxelResolution);
     m_insertCount++;
 }
Пример #2
0
    /// <summary>
    /// Insert 3D point into the hash storage.  Creates a new meshing cube at the location if needed.
    /// </summary>
    /// <returns>The value of the voxel that received the insertion.</returns>
    /// <param name="hashkey">Hashkey index of the target node.</param>
    /// <param name="p">The 3D point.</param>
    /// <param name="obs">Observation vector from the camera to the point.</param>
    /// <param name="weight">Weight of the observation.</param>
    /// <param name="prefab">Unity Prefab to be instantiated at this node location if needed.</param>
    /// <param name="parent">Unity transform of the parent object for the prefab created at this node location.</param>
    /// <param name="voxelResolution">Resolution of the voxels for this meshing cube.</param>
    private float InsertPoint(int hashkey, Vector3 p, Vector3 obs, float weight, GameObject prefab, Transform parent, int voxelResolution)
    {
        if (m_hashKey == hashkey)
        {
            if (m_meshPrefab == null)
            {
                InstantiatePrefab(hashkey, prefab, parent, voxelResolution);
            }

            if (m_meshPrefab == null)
            {
                m_dynamicMeshCube = m_meshPrefab.GetComponent <DynamicMeshCube>();
            }

            if (m_meshPrefab == null)
            {
                Debug.Log("Error: cannot find DynamicMeshVolume");
                return(0);
            }

            if (m_dynamicMeshCube.IsRegenerating)
            {
                return(0);
            }

            // adjust weight of mutiple voxels along observation ray
            float   result       = m_dynamicMeshCube.InsertPoint(p, obs, weight, ref m_volumeIndex);
            Vector3 closerPoint  = p - (obs * m_dynamicMeshCube.VoxelSize);
            Vector3 furtherPoint = p + (obs * m_dynamicMeshCube.VoxelSize);

            // voxel was inside the surface, back out one, and insert in the next closest voxel
            if (result > 0)
            {
                m_dynamicMeshCube.InsertPoint(closerPoint, p, obs, weight);
            }
            else
            {
                m_dynamicMeshCube.InsertPoint(furtherPoint, p, obs, weight);
            }

            if (m_volumeIndex[0] == 0)
            {
                int neighborHashKey = hashkey - 1;
                result = m_rootHashTree.InsertPoint(neighborHashKey, p, obs, weight, prefab, parent, voxelResolution);
            }

            if (m_volumeIndex[1] == 0)
            {
                int neighborHashKey = hashkey - m_maximumVolumeIndexDimension;
                result = m_rootHashTree.InsertPoint(neighborHashKey, p, obs, weight, prefab, parent, voxelResolution);
            }

            if (m_volumeIndex[2] == 0)
            {
                int neighborHashKey = hashkey - (m_maximumVolumeIndexDimension * m_maximumVolumeIndexDimension);
                result = m_rootHashTree.InsertPoint(neighborHashKey, p, obs, weight, prefab, parent, voxelResolution);
            }

            return(result);
        }

        if (hashkey < m_hashKey)
        {
            if (m_leftHashTree == null)
            {
                m_leftHashTree = new VolumetricHashTree(m_rootHashTree, hashkey);
            }

            return(m_leftHashTree.InsertPoint(hashkey, p, obs, weight, prefab, parent, voxelResolution));
        }
        else
        {
            if (m_rightHashTree == null)
            {
                m_rightHashTree = new VolumetricHashTree(m_rootHashTree, hashkey);
            }

            return(m_rightHashTree.InsertPoint(hashkey, p, obs, weight, prefab, parent, voxelResolution));
        }
    }