小编Jok*_*ker的帖子

从 SCNView 录制视频的最快方法

我有 SCNView,屏幕中间有一些对象,用户可以旋转它、缩放等。

我想在视频中记录所有这些动作并实时添加一些声音。另外,我只想记录SCNView的中间部分(例如SCNView框架是375x812,但我只想中间375x375,没有顶部和底部边框)。我还想在视频捕获的同时将其显示在屏幕上。

我当前的变体是:

func renderer(_ renderer: SCNSceneRenderer, didRenderScene scene: SCNScene, atTime time: TimeInterval) {
    DispatchQueue.main.async {
        if let metalLayer = self.sceneView.layer as? CAMetalLayer, let texture = metalLayer.currentSceneDrawable?.texture, let pixelBufferPool = self.pixelBufferPool {
            //1
            var maybePixelBuffer: CVPixelBuffer? = nil
            let status  = CVPixelBufferPoolCreatePixelBuffer(nil, pixelBufferPool, &maybePixelBuffer)

            guard let pixelBuffer = maybePixelBuffer else { return }

            CVPixelBufferLockBaseAddress(pixelBuffer, [])

            let bytesPerRow = CVPixelBufferGetBytesPerRow(pixelBuffer)
            let region = MTLRegionMake2D(Int(self.fieldOfView.origin.x * UIScreen.main.scale),
                                         Int(self.fieldOfView.origin.y * UIScreen.main.scale),
                                         Int(self.fieldOfView.width * UIScreen.main.scale),
                                         Int(self.fieldOfView.height * UIScreen.main.scale))

            let pixelBufferBytes = CVPixelBufferGetBaseAddress(pixelBuffer)!
            texture.getBytes(pixelBufferBytes, …
Run Code Online (Sandbox Code Playgroud)

ios avassetwriter scenekit metal cvpixelbuffer

5
推荐指数
1
解决办法
1069
查看次数

如何通过代码在 SceneKit 中设置基于物理的渲染?

我想用 PBR 呈现一些场景。我创建了金属度和粗糙度纹理,并希望将其应用于网格。当我尝试在 Xcode 中执行此操作时 - 一切都很好。我可以将此模型添加到场景中,然后将此纹理添加到模型中。 在 Xcode 中

但我想以编程方式进行。这是我的代码:

NSData *vertices = [[NSData alloc] initWithBytes:modelPly->vertices length:modelPly->vertexCount * 3 * sizeof(float)];
SCNGeometrySource *vertexSource = [SCNGeometrySource geometrySourceWithData:vertices
                                                                   semantic:SCNGeometrySourceSemanticVertex
                                                                vectorCount:modelPly->vertexCount
                                                            floatComponents:YES
                                                        componentsPerVector:3
                                                          bytesPerComponent:sizeof(float)
                                                                 dataOffset:0
                                                                 dataStride:sizeof(float) * 3];

// Normal source
NSData *normals = [[NSData alloc] initWithBytes:modelPly->normals length:modelPly->vertexCount * 3 * sizeof(float)];
SCNGeometrySource *normalSource = [SCNGeometrySource geometrySourceWithData:normals
                                                                   semantic:SCNGeometrySourceSemanticNormal
                                                                vectorCount:modelPly->vertexCount
                                                            floatComponents:YES
                                                        componentsPerVector:3
                                                          bytesPerComponent:sizeof(float)
                                                                 dataOffset:0
                                                                 dataStride:sizeof(float) * 3];


// Texture coordinates source
NSData *facesTextures = [[NSData alloc] initWithBytes:modelPly->texCoord length:modelPly->vertexCount * 2 * sizeof(float)];
SCNGeometrySource *texcoordSource = [SCNGeometrySource …
Run Code Online (Sandbox Code Playgroud)

objective-c scenekit swift ios11 arkit

4
推荐指数
1
解决办法
1283
查看次数