Extending the built-in Geometry types in RealityKit, for iOS and visionOS.
扩展 RealityKit 中的内置几何体类型,适用于 iOS 和 visionOS。
- visionOS 1.0+/iOS 15.0+
//iOS
var m = PhysicallyBasedMaterial()
m.baseColor = .init(tint: .white, texture:.init(try! TextureResource.load(named: "number.jpeg", in: nil)))
do {
let mesh = try MeshResource.generateCirclePlane(radius:0.1, angularResolution: 30, radialResolution: 5, circleUV: true)
let model = ModelEntity(mesh:mesh, materials: [m])
model.position.y = 0.1
model.name = "model"
} catch {
print(error)
}
//visionOS
RealityView { content in
var m = PhysicallyBasedMaterial()
let texture = try! await TextureResource.init(named: "number.jpeg")
m.baseColor = .init(tint: .white, texture:.init(texture))
do {
let mesh = try MeshResource.generateCirclePlane(radius:0.1, angularResolution: 30, radialResolution: 5, circleUV: true)
let modelEntity = ModelEntity(mesh:mesh, materials: [m])
modelEntity.name = "model"
content.add(modelEntity)
} catch {
print(error)
}
}
In the Demo, you can see the shape of every Geometry type. And you can also choose to display DebugOptions of normal
and uv
.
在演示 Demo 中,你可以看到所有几何体形状,并且可以选择调试选项,以可视化方式查看 法线
和 贴图坐标(UV)
。
To integrate using Apple's Swift package manager, add the following as a dependency to your Package.swift
:
使用苹果 Swift package manager 集成,可在项目中的 Package.swift
中添加依赖:
.package(url: "https://github.com/XanderXu/RealityMoreShape.git", .upToNextMajor(from: "0.1.0"))
Download the project and copy the RealityMoreShape
folder into your project to use it.
下载项目源码,并拖动到你的工程文件中使用。
Xander: API 搬运工
This project is inspired by the following two frameworks, particularly Euclid, and is greatly appreciated:
本项目思路来自于以下两个框架,受它们激发而产生,尤其是 Euclid
,非常感谢:
- RealityGeometries:Add more geometries to your RealityKit projects
- Euclid:Euclid is a Swift library for creating and manipulating 3D geometry using techniques such as extruding or "lathing" 2D paths to create solid 3D shapes, and CSG (Constructive Solid Geometry) to combine or subtract those shapes from one another.
RealityMoreShape is released under an MIT license. See LICENSE for more information.