小编Nil*_*epa的帖子

如何使用 Metal IOS 正确渲染 3D 模型?

我使用 Blender 创建了一个 3D 对象并将其导出为 OBJ 文件,并尝试按照此http://metalbyexample.com/modern-metal-1教程使用 Metal 渲染它。但我的一些 3D 物体部件丢失了。它们未正确呈现。

这是我在搅拌机中的 3D 对象:- 在此输入图像描述

这是我在 Metal 中渲染的对象:- 在此输入图像描述

这是我的搅拌机文件:- https://gofile.io/?c=XfQYLK

我应该如何解决这个问题?

我已经成功渲染了一些其他形状,如矩形、圆形、星形。但问题就出在这个形状上。我没有改变创建形状的方式,也没有改变从搅拌机导出形状的方式。即使我以同样的方式做了所有事情,问题仍然存在。

这是我加载 OBJ 文件的方法

private var vertexDescriptor: MTLVertexDescriptor!
private var meshes: [MTKMesh] = []

private func loadResource() {
        let modelUrl = Bundle.main.url(forResource: self.meshName, withExtension: "obj")
        let vertexDescriptor = MDLVertexDescriptor()
        vertexDescriptor.attributes[0] = MDLVertexAttribute(name: MDLVertexAttributePosition, format: .float3, offset: 0, bufferIndex: 0)
        vertexDescriptor.attributes[1] = MDLVertexAttribute(name: MDLVertexAttributeNormal, format: .float3, offset: MemoryLayout<Float>.size * 3, bufferIndex: 0)
        vertexDescriptor.attributes[2] = MDLVertexAttribute(name: MDLVertexAttributeTextureCoordinate, format: .float2, offset: …
Run Code Online (Sandbox Code Playgroud)

ios swift metal metalkit

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

启用金属验证后,IOS Metal Stencil Buffer项目崩溃

我正在尝试学习如何在Metal IOS中实现模板缓冲区。目前,无需金属验证即可正常工作。但是,一旦我打开“金属验证”,项目就会崩溃。

这是我的代码:-金属视图:-

import MetalKit

class DrawingView: MTKView {

    //Renderer to handle all the rendering of the Drawing View
    public var renderer: Renderer!

    override init(frame frameRect: CGRect, device: MTLDevice?) {
        super.init(frame: frameRect, device: device)
        self.configDrawingView()
    }

    required init(coder: NSCoder) {
        super.init(coder: coder)
        self.configDrawingView()
    }

    private func configDrawingView() {
        //Setting system default GPU
        self.device = MTLCreateSystemDefaultDevice()
        //Setting pixel format for the view
        self.colorPixelFormat = MTLPixelFormat.bgra8Unorm
        //Setting clear color of the view. View will be cleared in every frame
        self.clearColor = MTLClearColorMake(1.0, …
Run Code Online (Sandbox Code Playgroud)

stencil-buffer ios metal

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

标签 统计

ios ×2

metal ×2

metalkit ×1

stencil-buffer ×1

swift ×1