RealityKit 的文档包括 structs: OcclusionMaterial, SimpleMaterial, 和UnlitMaterial用于将材料添加到ModelEntity.
或者,您可以加载一个带有材料的模型。
我想以ModelEntity编程方式向 a 添加自定义材料/纹理。如何在不将材质添加到 Reality Composer 或其他一些 3D 软件中的模型的情况下即时实现这一点?
从 Apple 网站安装 USDZ 工具后,我遇到了这个问题。我对 Python 有点生疏,并尝试安装所有底层软件包。
我设置了我PYTHONPATH已经在使用export PYTHONPATH="/Users/gt/usdpython/USD/lib/python:$PYTHONPATH"
USD git:(master) ? usdzconvert
Traceback (most recent call last):
File "/Users/gt/usdpython/usdzconvert/usdzconvert", line 17, in <module>
usdUtils.printError("failed to import pxr module. Please add path to USD Python bindings to your PYTHONPATH.")
NameError: name 'usdUtils' is not defined
Run Code Online (Sandbox Code Playgroud) 在 iOS 14 中,hitTest(_:types:)已弃用。看来你现在应该使用raycastQuery(from:allowing:alignment:)了。从文档:
光线投射是在现实世界环境中寻找表面位置的首选方法,但为了兼容性,命中测试功能仍然存在。通过跟踪光线投射,ARKit 会继续优化结果,以提高您使用光线投射放置的虚拟内容的位置精度。
但是,如何SCNNode使用光线投射命中 test ?我只看到测试飞机的选项。
这是我当前的代码,它使用命中测试来检测多维数据集节点上的点击并将其变为蓝色。
class ViewController: UIViewController {
@IBOutlet weak var sceneView: ARSCNView!
override func viewDidLoad() {
super.viewDidLoad()
/// Run the configuration
let worldTrackingConfiguration = ARWorldTrackingConfiguration()
sceneView.session.run(worldTrackingConfiguration)
/// Make the red cube
let cube = SCNBox(width: 0.1, height: 0.1, length: 0.1, chamferRadius: 0)
cube.materials.first?.diffuse.contents = UIColor.red
let cubeNode = SCNNode(geometry: cube)
cubeNode.position = SCNVector3(0, 0, -0.2) /// …Run Code Online (Sandbox Code Playgroud) 这可能是一个晦涩的问题,但我在网上看到很多非常酷的示例,展示人们如何使用 ARKit 3 中新的 ARKit 人物遮挡技术来有效地将人物与背景“分离”,并对“人物”应用某种过滤。人”(见此处)。
在查看 Apple 提供的源代码和文档时,我发现我可以segmentationBuffer从 ARFrame 中检索 ,我已经这样做了,如下所示;
func session(_ session: ARSession, didUpdate frame: ARFrame) {
let image = frame.capturedImage
if let segementationBuffer = frame.segmentationBuffer {
// Get the segmentation's width
let segmentedWidth = CVPixelBufferGetWidth(segementationBuffer)
// Create the mask from that pixel buffer.
let sementationMaskImage = CIImage(cvPixelBuffer: segementationBuffer, options: [:])
// Smooth edges to create an alpha matte, then upscale it to the RGB resolution.
let alphaUpscaleFactor = Float(CVPixelBufferGetWidth(image)) / Float(segmentedWidth)
let …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 RealityKit AR 场景中添加照明。我在 Reality Composer 中找不到灯光选项。如果有办法添加Directional Light或编辑它,请告诉我。我尝试过 Apple 文档,但不明白如何添加它们。
我试图在不改变任何枢轴点的情况下制作一个带有三角形的六边形网格,但我似乎无法正确定位三角形以制作单个六边形。我正在SCNNodes创建UIBezierPaths三角形,然后旋转贝塞尔曲线路径。这似乎工作得很好,直到我尝试使用参数方程将三角形围绕圆定位以形成六边形,然后它们最终不会处于正确的位置。你能帮我找出我做错的地方吗?
class TrianglePlane: SCNNode {
var size: CGFloat = 0.1
var coords: SCNVector3 = SCNVector3Zero
var innerCoords: Int = 0
init(coords: SCNVector3, innerCoords: Int, identifier: Int) {
super.init()
self.coords = coords
self.innerCoords = innerCoords
setup()
}
init(identifier: Int) {
super.init()
// super.init(identifier: identifier)
setup()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setup() {
let myPath = path()
let geo = SCNShape(path: myPath, extrusionDepth: 0)
geo.firstMaterial?.diffuse.contents = UIColor.red
geo.firstMaterial?.blendMode = .multiply …Run Code Online (Sandbox Code Playgroud) 我想创建自己的框架来使用 RealityKit 功能。框架项目正确编译,没有错误,但是当我将其导入到新项目并尝试编译时,出现错误
“找不到模块‘RealityKit’”
我可以以某种方式将 RealityKit 添加到我的框架中,以便将其包含在内,还是应该在某处更改路径?
当我将 RealityKit 直接导入到新项目时,它可以工作,但是当我尝试导入我的框架时,我收到此错误。
我此时在 MyFramework-Swift.h 中收到错误
#if __has_feature(modules)
#if __has_warning("-Watimport-in-framework-header")
#pragma clang diagnostic ignored "-Watimport-in-framework-header"
#endif
@import ARKit;
@import CoreGraphics;
@import Foundation;
@import QuartzCore;
@import RealityKit; // Module 'RealityKit' not found
@import UIKit;
#endif
Run Code Online (Sandbox Code Playgroud) 这段代码的工作原理:
let entity = try! Entity.load(named: "toy_robot_vintage")
anchorEntity.addChild(entity)
Run Code Online (Sandbox Code Playgroud)
但这并没有:
_ = Entity.loadAsync(named: "toy_robot_vintage")
.sink(receiveCompletion: { loadCompletion in
print("This is never executed")
}, receiveValue: { entity in
print("This is never executed")
anchorEntity.addChild(entity)
})
Run Code Online (Sandbox Code Playgroud)
可能是什么问题?
摘要:添加 AR 对象后删除其上的触摸手势?
AR 查看代码(仅相关位)。其中 arObject 是具有网格、材质和碰撞形状的模型实体。
func updateUIView(_ uiView: ARView, context: Context) {
arObject = CreateCustomModelEntity()
uiView.installGestures([.translation, .rotation], for: arObject)
}
Run Code Online (Sandbox Code Playgroud)
上面的代码可以向我的 arObject 添加触摸手势,并允许它在锚定平面上旋转和移动。
但是,我想在添加后删除触摸手势。
用户流程:
用户可以单击一个模型,将其移动并将其放置在他们想要的位置,然后触摸“确认”按钮。触摸确认按钮后,arObject 将无法再移动。
查看Apple文档,有一个installGestures,但没有等效的removeGestures。这可能吗?
一些想法,
有没有办法知道 SIMD3 的 ModelEntity 的大小?一旦我获得了大小,我想将其传递给 CollisionComponent。
let box = ModelEntity(mesh: MeshResource.generateBox(size: 0.2),
materials: [SimpleMaterial(color: .green, isMetallic: true)])
box.position.y = 0.3
box.generateCollisionShapes(recursive: true)
box.physicsBody = PhysicsBodyComponent(massProperties: .default,
material: .default,
mode: .dynamic)
// I know I can use the following
box.collision = CollisionComponent(shapes: [.generateBox(size: [0.2,0.2,0.2])],
mode: .trigger,
filter: .sensor)
// but why not just pass the size of the box I created earlier.
box.collision = CollisionComponent(shapes: [PASS BOX SIZE HERE],
mode: .trigger,
filter: .sensor)
Run Code Online (Sandbox Code Playgroud) realitykit ×10
swift ×8
arkit ×6
scenekit ×3
ios ×2
asynchronous ×1
bash ×1
frameworks ×1
macos ×1
swiftui ×1
usdz ×1
xcode ×1