Beispiel #1
0
        public void Initialize(ARBody body)
        {
            m_body             = body;
            m_skeletonMaterial = new Material(Shader.Find("Diffuse"));
            m_cameraConfig     = ARSession.GetCameraConfig();

            for (int i = 0; i < m_maxSkeletonCnt; i++)
            {
                m_skeletonPointObject[i] = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                m_skeletonPointObject[i].transform.localScale = new Vector3(0.08f, 0.08f, 0.08f);
                m_skeletonPointObject[i].SetActive(false);
            }

            for (int i = 0; i < m_maxSkeletonConnectionCnt; i++)
            {
                m_lines[i] = new GameObject("Lines");
                m_lines[i].transform.localScale    = new Vector3(1f, 1f, 1f);
                m_lines[i].transform.position      = new Vector3(0f, 0f, 0f);
                m_lines[i].transform.localPosition = new Vector3(0, 0, 0);
                m_lines[i].SetActive(false);

                m_skeletonConnectionRenderer[i] = m_lines[i].AddComponent <LineRenderer>();
                m_skeletonConnectionRenderer[i].positionCount = 2;
                m_skeletonConnectionRenderer[i].startWidth    = 0.03f;
                m_skeletonConnectionRenderer[i].endWidth      = 0.03f;
            }
            m_skeletonCamera = Camera.main;
            Update();
        }
        /// <summary>
        /// Update gesture-related data for display.
        /// </summary>
        /// <param name="sb">String buffer.</param>
        /// <param name="body">ARBody</param>
        private void UpdateMessageData(StringBuilder sb, ARBody body)
        {
            float fpsResult = DoFpsCalculate();

            sb.Append("FPS=").Append(fpsResult).Append(System.Environment.NewLine);
            int bodyAction = body.BodyAction;

            sb.Append("bodyAction=").Append(bodyAction).Append(System.Environment.NewLine);
        }
Beispiel #3
0
        public ARTrackable ARTrackableFactory(IntPtr nativeHandle, bool isCreate = false)
        {
            if (nativeHandle == IntPtr.Zero)
            {
                return(null);
            }
            ARTrackable result;

            if (m_trackableDict.TryGetValue(nativeHandle, out result))
            {
                m_ndkSession.TrackableAdapter.Release(nativeHandle);
                return(result);
            }
            if (isCreate)
            {
                NDKARTrackableType ndkTrackableType = m_ndkSession.TrackableAdapter.GetType(nativeHandle);
                ARDebug.LogInfo("trackable type {0}", ndkTrackableType.ToString());
                switch (ndkTrackableType)
                {
                case NDKARTrackableType.Plane:
                    result = new ARPlane(nativeHandle, m_ndkSession);
                    break;

                case NDKARTrackableType.Point:
                    result = new ARPoint(nativeHandle, m_ndkSession);
                    break;

                case NDKARTrackableType.Body:
                    result = new ARBody(nativeHandle, m_ndkSession);
                    break;

                case NDKARTrackableType.Hand:
                    result = new ARHand(nativeHandle, m_ndkSession);
                    break;

                case NDKARTrackableType.Face:
                    result = new ARFace(nativeHandle, m_ndkSession);
                    break;

                case NDKARTrackableType.AugmentedImage:
                    result = new ARAugmentedImage(nativeHandle, m_ndkSession);
                    break;

                //todo add more trackable
                default:
                    m_ndkSession.TrackableAdapter.Release(nativeHandle);
                    throw new NotImplementedException("ARTrackableFactory: no constructor for requested type");
                }

                m_trackableDict.Add(nativeHandle, result);
                return(result);
            }
            return(null);
        }
 /// <summary>
 /// Update body connection data.
 /// </summary>
 private void UpdateBodySkeletonLineData(ARBody body)
 {
     FindValidConnectionSkeletonLines(body);
     ShaderUtil.CheckGlError(TAG, "Update body skeleton line data start.");
     GLES20.GlBindBuffer(GLES20.GlArrayBuffer, mVbo);
     mNumPoints = mPointsLineNum;
     if (mVboSize < mNumPoints * BYTES_PER_POINT)
     {
         while (mVboSize < mNumPoints * BYTES_PER_POINT)
         {
             // If the storage space is insufficient, allocate double the space.
             mVboSize *= 2;
         }
         GLES20.GlBufferData(GLES20.GlArrayBuffer, mVboSize, null, GLES20.GlDynamicDraw);
     }
     GLES20.GlBufferSubData(GLES20.GlArrayBuffer, 0, mNumPoints * BYTES_PER_POINT, mLinePoints);
     GLES20.GlBindBuffer(GLES20.GlArrayBuffer, 0);
     ShaderUtil.CheckGlError(TAG, "Update body skeleton line data end.");
 }
Beispiel #5
0
        private void FindValidSkeletonPoints(ARBody arBody)
        {
            int index = 0;

            int[] isExists;
            int   validPointNum = 0;

            float[] points;
            float[] skeletonPoints;

            // Determine whether the data returned by the algorithm is 3D human
            // skeleton data or 2D human skeleton data, and obtain valid skeleton points.
            if (arBody.CoordinateSystemType == ARCoordinateSystemType.CoordinateSystemType3dCamera)
            {
                isExists       = arBody.GetSkeletonPointIsExist3D();
                points         = new float[isExists.Length * 3];
                skeletonPoints = arBody.GetSkeletonPoint3D();
            }
            else
            {
                isExists       = arBody.GetSkeletonPointIsExist2D();
                points         = new float[isExists.Length * 3];
                skeletonPoints = arBody.GetSkeletonPoint2D();
            }

            // Save the three coordinates of each joint point(each point has three coordinates).
            for (int i = 0; i < isExists.Length; i++)
            {
                if (isExists[i] != 0)
                {
                    points[index++] = skeletonPoints[3 * i];
                    points[index++] = skeletonPoints[3 * i + 1];
                    points[index++] = skeletonPoints[3 * i + 2];
                    validPointNum++;
                }
            }
            mSkeletonPoints = FloatBuffer.Wrap(points);
            mPointsNum      = validPointNum;
        }
        private void FindValidConnectionSkeletonLines(ARBody arBody)
        {
            mPointsLineNum = 0;
            int[]   connections = arBody.GetBodySkeletonConnection();
            float[] linePoints  = new float[LINE_POINT_RATIO * connections.Length];
            float[] coors;
            int[]   isExists;

            if (arBody.CoordinateSystemType == ARCoordinateSystemType.CoordinateSystemType3dCamera)
            {
                coors    = arBody.GetSkeletonPoint3D();
                isExists = arBody.GetSkeletonPointIsExist3D();
            }
            else
            {
                coors    = arBody.GetSkeletonPoint2D();
                isExists = arBody.GetSkeletonPointIsExist2D();
            }

            // Filter out valid skeleton connection lines based on the returned results,
            // which consist of indexes of two ends, for example, [p0,p1;p0,p3;p0,p5;p1,p2].
            // The loop takes out the 3D coordinates of the end points of the valid connection
            // line and saves them in sequence.
            for (int j = 0; j < connections.Length; j += 2)
            {
                if (isExists[connections[j]] != 0 && isExists[connections[j + 1]] != 0)
                {
                    linePoints[mPointsLineNum * 3]     = coors[3 * connections[j]];
                    linePoints[mPointsLineNum * 3 + 1] = coors[3 * connections[j] + 1];
                    linePoints[mPointsLineNum * 3 + 2] = coors[3 * connections[j] + 2];
                    linePoints[mPointsLineNum * 3 + 3] = coors[3 * connections[j + 1]];
                    linePoints[mPointsLineNum * 3 + 4] = coors[3 * connections[j + 1] + 1];
                    linePoints[mPointsLineNum * 3 + 5] = coors[3 * connections[j + 1] + 2];
                    mPointsLineNum += 2;
                }
            }
            mLinePoints = FloatBuffer.Wrap(linePoints);
        }