Apple RealityKit:如何使用 ModelEntity 绘制多边形平面?

问题描述 投票:0回答:2

我曾经使用过一些 SceneKit API,例如

SCNGeometrySource(vertices: vertices)

SCNGeometryElement(data: indexData,
                   primitiveType: .polygon,
                   primitiveCount: 1,
                   bytesPerIndex: MemoryLayout<Int32>.size)

SCNShape(path: bezierPath, extrusionDepth: 0.0003)

实现在场景中绘制多边形。

现在我正在尝试通过 RealityKit 重写实现。 但我只找到了一些基本的网格 API,例如

generatePlane(width: Float, height: Float, cornerRadius: Float = 0) -> MeshResource
generatePlane(width: Float, depth: Float, cornerRadius: Float = 0) -> MeshResource
generateBox(size: Float, cornerRadius: Float = 0) -> MeshResource
generateSphere(radius: Float) -> MeshResource
...

我希望有更接近 SceneKit 便利性的东西。

ios scenekit augmented-reality realitykit
2个回答
1
投票

RealityKit 没有用于在运行时创建自定义几何体的 API。


编辑: RealityKit 2 引入了对动态网格的支持。请参阅 WWDC21 中的使用 RealityKit 2 探索高级渲染。


0
投票
这里有一些代码演示了如何使用

MeshDescriptor 以编程方式从顶点生成网格:

let positions: [SIMD3<Float>] = [SIMD3(x:0.0, y:0.0, z:0.0), SIMD3(x:0.1, y:0.01, z:0.0), SIMD3(x:0.07, y:0.07, z:0.05), SIMD3(x:0.0, y:0.1, z:0.0), SIMD3(x:0.05, y:0.05, z:0.0)] let counts: [UInt8] = [5] let indices: [UInt32] = [0, 1, 2, 3, 4] var meshDescriptor = MeshDescriptor() meshDescriptor.positions = .init(positions) meshDescriptor.primitives = .polygons(counts, indices) let polygon = try! MeshResource.generate(from: [meshDescriptor])
除了

polygons

之外,RealityKit目前还有另外两种原始类型:
triangles
trianglesAndQuads

© www.soinside.com 2019 - 2024. All rights reserved.