Esempio n. 1
0
        /// <summary>
        /// Pull the texture descriptors from the camera subsystem, and update the texture information maintained by
        /// this component.
        /// </summary>
        /// <param name="frame">The latest updated camera frame.</param>
        void UpdateTexturesInfos(XRCameraFrame frame)
        {
            var textureDescriptors = subsystem.GetTextureDescriptors(Allocator.Temp);

            try
            {
                int numUpdated = Math.Min(m_TextureInfos.Count, textureDescriptors.Length);

                // Update the existing textures that are in common between the two arrays.
                for (int i = 0; i < numUpdated; ++i)
                {
                    m_TextureInfos[i] = ARTextureInfo.GetUpdatedTextureInfo(m_TextureInfos[i], textureDescriptors[i]);
                }

                // If there are fewer textures in the current frame than we had previously, destroy any remaining unneeded
                // textures.
                if (numUpdated < m_TextureInfos.Count)
                {
                    for (int i = numUpdated; i < m_TextureInfos.Count; ++i)
                    {
                        m_TextureInfos[i].Reset();
                    }
                    m_TextureInfos.RemoveRange(numUpdated, (m_TextureInfos.Count - numUpdated));
                }
                // Else, if there are more textures in the current frame than we have previously, add new textures for any
                // additional descriptors.
                else if (textureDescriptors.Length > m_TextureInfos.Count)
                {
                    for (int i = numUpdated; i < textureDescriptors.Length; ++i)
                    {
                        m_TextureInfos.Add(new ARTextureInfo(textureDescriptors[i]));
                    }
                }
            }
            finally
            {
                if (textureDescriptors.IsCreated)
                {
                    textureDescriptors.Dispose();
                }
            }
        }
        /// <summary>
        /// Update the human segmentation image information if the subsystem has human segmentation images.
        /// </summary>
        void UpdateTexturesInfos()
        {
            XRTextureDescriptor humanStencilDescriptor;

            if (subsystem.TryGetHumanStencil(out humanStencilDescriptor))
            {
                m_HumanStencilInfo = ARTextureInfo.GetUpdatedTextureInfo(m_HumanStencilInfo, humanStencilDescriptor);
            }
            else
            {
                m_HumanStencilInfo.Reset();
            }

            XRTextureDescriptor humanDepthDescriptor;

            if (subsystem.TryGetHumanDepth(out humanDepthDescriptor))
            {
                m_HumanDepthInfo = ARTextureInfo.GetUpdatedTextureInfo(m_HumanDepthInfo, humanDepthDescriptor);
            }
            else
            {
                m_HumanDepthInfo.Reset();
            }
        }