Ejemplo n.º 1
0
            public override unsafe XRPointCloudData GetPointCloudData(
                TrackableId trackableId,
                Allocator allocator)
            {
                void *positionsPtr, identifiersPtr;
                int   numPoints;
                var   pointCloud = UnityARKit_depth_acquirePointCloud(
                    trackableId,
                    out positionsPtr, out identifiersPtr, out numPoints);

                try
                {
                    var positions       = new NativeArray <Vector3>(numPoints, allocator);
                    var positionsHandle = new TransformPositionsJob
                    {
                        positionsIn  = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <Quaternion>(positionsPtr, numPoints, Allocator.None),
                        positionsOut = positions
                    }.Schedule(numPoints, 32);

                    var identifiers = new NativeArray <ulong>(numPoints, allocator);
                    identifiers.CopyFrom(NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <ulong>(identifiersPtr, numPoints, Allocator.None));

                    positionsHandle.Complete();
                    return(new XRPointCloudData
                    {
                        positions = positions,
                        identifiers = identifiers
                    });
                }
                finally
                {
                    UnityARKit_depth_releasePointCloud(pointCloud);
                }
            }
Ejemplo n.º 2
0
            public override unsafe XRPointCloudData GetPointCloudData(
                TrackableId trackableId,
                Allocator allocator)
            {
                void *dataPtr, identifierPtr;
                int   numPoints = NativeApi.UnityARCore_depth_getPointCloudPtrs(
                    trackableId,
                    out dataPtr, out identifierPtr);

                var data = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <Quaternion>(dataPtr, numPoints, Allocator.None);

                var positions    = new NativeArray <Vector3>(numPoints, allocator);
                var positionsJob = new TransformPositionsJob
                {
                    positionsIn  = data,
                    positionsOut = positions
                };
                var positionsHandle = positionsJob.Schedule(numPoints, 32);

                var confidenceValues = new NativeArray <float>(numPoints, allocator);
                var confidenceJob    = new ExtractConfidenceValuesJob
                {
                    confidenceIn  = data,
                    confidenceOut = confidenceValues
                };
                var confidenceHandle = confidenceJob.Schedule(numPoints, 32);

                var identifiers    = new NativeArray <ulong>(numPoints, allocator);
                var identifiersJob = new CopyIdentifiersJob
                {
                    identifiersIn  = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <int>(identifierPtr, numPoints, Allocator.None),
                    identifiersOut = identifiers
                };
                var identifiersHandle = identifiersJob.Schedule(numPoints, 32);

                JobHandle.CombineDependencies(positionsHandle, confidenceHandle, identifiersHandle).Complete();
                return(new XRPointCloudData
                {
                    positions = positions,
                    identifiers = identifiers,
                    confidenceValues = confidenceValues
                });
            }