我正在 Swift 中使用 RealityKit 加载 USDZ 模型。模型加载良好,具有纹理。
但是,我无法更改材质的漫反射属性,材质总是以AnyMaterial.
我可以用 a 完全覆盖材质,SimpleMaterial或者我可以在运行应用程序之前更改 USDZ 漫反射颜色,但在运行时似乎无法做到这一点,有什么想法吗?
我只想能够改变一个属性
/*
Find an entity within the parent, and find the material, test to try and change it's material
**/
private func updateColor(entity: Entity) {
guard
let found = entity.findEntity(named: "MyItem"),
var modelComponent = found.components[ModelComponent] as? ModelComponent,
let existingMaterial = modelComponent.materials.first else {
return
}
// This is `AnyMaterial` - no diffuse property
// What can I use here to change the diffuse? …Run Code Online (Sandbox Code Playgroud) 如果您打开 Xcode,创建一个新的增强现实项目并运行该项目,您将更好地理解这个问题。
项目开始在设备上运行后,您将看到来自后置摄像头的图像,拍摄您的房间。
3 或 4 秒后,会出现一个立方体。
我的问题是:
在立方体出现之前应用程序在做什么?我的意思是,我想该应用程序正在寻找场景中的跟踪点,因此它可以锚定立方体,对吗?
如果这是真的,应用程序要寻找哪些元素?
假设我对立方体出现的点不满意。是否有任何功能可以通过点击屏幕触发,以便跟踪可以在我在屏幕上点击的位置附近再次搜索新点?
我知道我的问题很笼统,所以请给我正确的方向。
这段代码的工作原理:
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)
可能是什么问题?
我正在使用 SceneKit 制作一个简单的 ARKit 应用程序,需要添加一些粒子效果。通常我可以创建一个 SceneKit 粒子文件,设计一些粒子效果并像这样使用它
let smoke = SCNParticleSystem(named: "xxx.scnp", inDirectory: nil)!
let hole = SCNNode()
hole.addParticleSystem(smoke)
Run Code Online (Sandbox Code Playgroud)
但从Xcode12开始,我只能创建后缀为.spritkit的SpritKit粒子文件.sks。上面的代码无法再使用此文件。我是 ARKit 的新手。谁能告诉我如何将粒子效果集成到我的 SceneKit 项目中?多谢。
我想在 Reality Composer 中创建实体后以编程方式更改实体的颜色。
由于 Reality Composer 不会创建 ModelEntity(它创建通用实体),因此我似乎无权更改其颜色。当我类型转换为 ModelEntity 时,我现在可以访问 ModelComponent 材质。但是,当我尝试将其添加到场景中时,出现 Thread 1: signal SIGABART 错误。无法将“RealityKit.Entity”(0x1fcebe6e8)类型的值转换为“RealityKit.ModelEntity”(0x1fceba970)。下面的示例代码。
import UIKit
import RealityKit
class ViewController: UIViewController {
@IBOutlet var arView: ARView!
override func viewDidLoad() {
super.viewDidLoad()
// Load the "Box" scene from the "Experience" Reality File
let boxAnchor = try! Experience.loadBox()
// Typecast Steelbox as ModelEntity to change its color
let boxModelEntity = boxAnchor.steelBox as! ModelEntity
// Remove materials and create new material
boxModelEntity.model?.materials.removeAll()
let blueMaterial = SimpleMaterial(color: .blue, isMetallic: false) …Run Code Online (Sandbox Code Playgroud) 我知道您可以View按照以下步骤将 iOS SwiftUI 转换为图像,但这会使用 SwiftUI 扩展中的 UIKit 内容,而您无法在 macOS 的 SwiftUI 中使用这些内容。
有谁知道如何对 macOS SwiftUI 视图进行快照/屏幕截图?
简单的问题。令人惊讶的是,谷歌的高层并没有给我答案。
我知道 ARSCNView 使用 Scenekit 而 ARView 使用 Realitykit。据我了解,RealityKit 比 SceneKit 更新且级别更高。
但用例有什么区别呢?
人们会选择 ARView 的原因/原因是什么类型的应用程序,以及人们会选择 ARSCNView 的原因/原因是什么类型的应用程序?
RealityKit 有相机选项.nonAR,但缺乏构建 3D 非 AR 应用程序的基本选项,例如相机控制 ( .allowsCameraComtrol)。
使用 RealityKit 替代 SceneKit 是否可行(过去几年没有更新,可能很快就会被亵渎)?
有没有办法知道 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) 我有以下代码:
while ( /* Some condition that will not be met in this example */ ) {
if( shouldSendRequest ) {
[launchpad getRequestToken];
}
else {
// Next step
}
}
- (void)getRequestToken {
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
[self requestForRequestTokenDidComplete:data withResponse:response withError:error];
}];
}
-(void)requestForRequestTokenDidComplete:(NSData *)data
withResponse:(NSURLResponse *)response withError:(NSError *)error {
// Deal with the returned token
}
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是,getRequestToken只要getRequestToken在while循环中,就不会调用完成处理程序.一旦我注释掉while循环,一切正常.
这里发生了什么,有可能阻止它吗?我已经计划使用while循环来防止执行流程在此(和其他)完成处理程序完成之前继续进行.
swift ×9
realitykit ×7
arkit ×5
scenekit ×3
arcamera ×1
asynchronous ×1
macos ×1
nsimage ×1
objective-c ×1
screenshot ×1
sprite-kit ×1
swiftui ×1
usdz ×1