/// <summary>
        /// Constructor invoked by the <see cref="ARFaceManager"/> which triggered the event.
        /// </summary>
        /// <param name="face">The <see cref="ARFace"/> component that was updated.</param>
        public ARFaceUpdatedEventArgs(ARFace face)
        {
            if (face == null)
            {
                throw new ArgumentNullException("face");
            }

            this.face = face;
        }
 void OnUpdated(ARFace face)
 {
     UpdateVisibility();
     if (!m_TopologyUpdatedThisFrame)
     {
         SetMeshTopology();
     }
     m_TopologyUpdatedThisFrame = false;
 }
Exemplo n.º 3
0
        void RemoveFace(ARFace face)
        {
            if (faceRemoved != null)
            {
                faceRemoved(new ARFaceRemovedEventArgs(face));
            }

            face.OnRemove();
            m_Faces.Remove(face.xrFace.trackableId);
        }
Exemplo n.º 4
0
        void BakeTexture(UnityEngine.XR.ARFoundation.ARFace face)
        {
            int length = face.vertices.Length;

            if (positionBuffer == null || positionBuffer.count != length * 3)
            {
                positionBuffer?.Dispose();
                normalBuffer?.Dispose();

                positionBuffer = new ComputeBuffer(length * 3, sizeof(float));
                normalBuffer   = new ComputeBuffer(length * 3, sizeof(float));
            }

            if (positionTextureRW == null)
            {
                positionTextureRW = CreateRenderTextureRW(positionTexture);
                normalTextureRW   = CreateRenderTextureRW(normalTexture);
            }


            compute.SetInt("VertexCount", length);
            compute.SetMatrix("Transform", face.transform.localToWorldMatrix);
            compute.SetFloat("FrameRate", 1 / Time.deltaTime);

            positionBuffer.SetData(face.vertices);
            var mesh = face.GetComponent <MeshFilter>().sharedMesh;

            normalBuffer.SetData(mesh?.normals);

            compute.SetBuffer(0, "PositionBuffer", positionBuffer);
            compute.SetBuffer(0, "NormalBuffer", normalBuffer);

            compute.SetTexture(0, "PositionMap", positionTextureRW);
            compute.SetTexture(0, "NormalMap", normalTextureRW);

            compute.Dispatch(0, positionTexture.width / 8, positionTexture.height / 8, 1);

            Graphics.CopyTexture(positionTextureRW, positionTexture);
            Graphics.CopyTexture(normalTextureRW, normalTexture);
        }