类型'[vector_float3]'(又名'Array <float3>')的值没有成员'advanced'

时间:2017-09-21 09:58:27

标签: swift4 arkit

在arkit示例代码中,我得到了这个错误类型'[vector_float3]'(又名'Array')的值没有成员'advanced' 它与XCode 9 beta版或GM版

一起运行良好

我正在使用此代码

func hitTestWithFeatures(_ point: CGPoint, coneOpeningAngleInDegrees: Float,
                             minDistance: Float = 0,
                             maxDistance: Float = Float.greatestFiniteMagnitude,
                             maxResults: Int = 1) -> [FeatureHitTestResult] {

        var results = [FeatureHitTestResult]()

        guard let features = self.session.currentFrame?.rawFeaturePoints else {
            return results
        }

        guard let ray = hitTestRayFromScreenPos(point) else {
            return results
        }

        let maxAngleInDeg = min(coneOpeningAngleInDegrees, 360) / 2
        let maxAngle = ((maxAngleInDeg / 180) * Float.pi)

        let points = features.points

        for i in 0...features.__count {

            let feature = points.advanced(by: Int(i))
            let featurePos = SCNVector3(feature.pointee)

            let originToFeature = featurePos - ray.origin

            let crossProduct = originToFeature.cross(ray.direction)
            let featureDistanceFromResult = crossProduct.length()

            let hitTestResult = ray.origin + (ray.direction * ray.direction.dot(originToFeature))
            let hitTestResultDistance = (hitTestResult - ray.origin).length()


            // All tests passed: Add the hit against this feature to the results.
            results.append(FeatureHitTestResult(position: hitTestResult,
                                                distanceToRayOrigin: hitTestResultDistance,
                                                featureHit: featurePos,
                                                featureDistanceToHitResult: featureDistanceFromResult))
        }

        // Sort the results by feature distance to the ray.
        results = results.sorted(by: { (first, second) -> Bool in
            return first.distanceToRayOrigin < second.distanceToRayOrigin
        })

        return cappedResults
    }

1 个答案:

答案 0 :(得分:9)

我遇到了同样的问题,愉快地解决了。 Apple已在此处更新此示例:https://developer.apple.com/library/content/samplecode/AudioInARKit/Listings/Audio_in_ARKit_ARSCNView_HitTests_swift.html

只需做一点改变,你就可以了:

let points = features.__points

而不是:

let points = features.points

希望这有帮助