0

我正在尝试访问目标 C 中ARMeshGeometry缓冲区内容的内容。

到目前为止,我正在访问缓冲区的内容如下:

@interface ARMeshGeometry (miniExtension)
-(void)                         getVertices;

@end


@implementation ARMeshGeometry (miniExtension)
-(void)                         getVertices{

    size_t stride = size_t(self.vertices.stride);
    size_t offset = size_t(self.vertices.offset);
    size_t offsetComponent = size_t(stride / self.vertices.componentsPerVector);


    for(int i = self.vertices.count-1; i > -1 ; i--){
        
        void* vBuffPointer = [self.vertices.buffer contents];
        vBuffPointer = static_cast<float*>(vBuffPointer) + offset + stride * i;
        float x = *static_cast<float*>(vBuffPointer);
        vBuffPointer = static_cast<float*>(vBuffPointer) + offsetComponent;
        float y = *static_cast<float*>(vBuffPointer);
        vBuffPointer = static_cast<float*>(vBuffPointer) + offsetComponent;
        float z = *static_cast<float*>(vBuffPointer);    
    }

}

@end

我在通过顶点时遇到内存访问错误,并且它似乎是随机的 - 或者当顶点数量大于 1500 时至少是随机的 - 。

我尝试使用Visualizing and Interacting with a Reconstructed Scene中提供的示例代码来做同样的事情:

// in Extensions.swift : extensions of the ARMeshGeometry
func seeAllVec(){
        let index = 0;
            
        for index in 0..<vertices.count {
            let vertexPointer = vertices.buffer.contents().advanced(by: vertices.offset + (vertices.stride * Int(index)))
            let vertex = vertexPointer.assumingMemoryBound(to: (Float, Float, Float).self).pointee
            NSLog("vertex = %f, %f, %f", vertex.0, vertex.1, vertex.2);
            
        }
    }

它在 swift 中完美地工作,但在 Objective C 中却没有,我不知道为什么......

有什么帮助吗?

最好的,

4

0 回答 0