Exemple #1
0
    private void DestroySurfaceGeometries(bool addBackToDeferredQueue = false)
    {
        foreach (KeyValuePair <GameObject, PassthroughMeshInstance> el in surfaceGameObjects)
        {
            if (el.Value.meshHandle != 0)
            {
                OVRPlugin.DestroyInsightPassthroughGeometryInstance(el.Value.instanceHandle);
                OVRPlugin.DestroyInsightTriangleMesh(el.Value.meshHandle);

                // When DestroySurfaceGeometries is called from OnDisable, we want to keep track of the existing
                // surface geometries so we can add them back when the script gets enabled again. We simply reinsert
                // them into deferredSurfaceGameObjects for that purpose.
                if (addBackToDeferredQueue)
                {
                    deferredSurfaceGameObjects.Add(
                        new DeferredPassthroughMeshAddition
                    {
                        gameObject      = el.Key,
                        updateTransform = el.Value.updateTransform
                    });
                }
            }
        }
        surfaceGameObjects.Clear();
    }
Exemple #2
0
    /// <summary>
    /// Removes a GameObject that was previously added using `AddSurfaceGeometry` from the projection surface.
    /// </summary>
    /// <param name="obj">The Gameobject to remove. </param>
    public void RemoveSurfaceGeometry(GameObject obj)
    {
        PassthroughMeshInstance passthroughMeshInstance;

        if (surfaceGameObjects.TryGetValue(obj, out passthroughMeshInstance))
        {
            if (OVRPlugin.DestroyInsightPassthroughGeometryInstance(passthroughMeshInstance.instanceHandle) &&
                OVRPlugin.DestroyInsightTriangleMesh(passthroughMeshInstance.meshHandle))
            {
                surfaceGameObjects.Remove(obj);
            }
            else
            {
                Debug.LogError("GameObject could not be removed from passthrough surface.");
            }
        }
        else
        {
            int count = deferredSurfaceGameObjects.RemoveAll(x => x.gameObject == obj);
            if (count == 0)
            {
                Debug.LogError("Specified GameObject has not been added as passthrough surface.");
            }
        }
    }