Posts

Post not yet marked as solved
1 Replies
492 Views
I have some strange behavior in my app. When I set the position to .zero you can see the sphere normally. But when I change it to any number it doesn't matter which and how small. The Sphere isn't visible or in the view. The RealityView import SwiftUI import RealityKit import RealityKitContent struct TheSphereOfDoomRV: View { @StateObject var viewModel: SphereViewModel = SphereViewModel() let sphere = SphereEntity(radius: 0.25, materials: [SimpleMaterial(color: .red, isMetallic: true)], name: "TheSphere") var body: some View { RealityView { content, attachments in content.add(sphere) } update: { content, attachments in sphere.scale = SIMD3<Float>(x: viewModel.scale, y: viewModel.scale, z: viewModel.scale) } attachments: { VStack { Text("The Sphere of Doom is one of the most powerful Objects. You can interact with him in every way you can imagine ").multilineTextAlignment(.center) Button { } label: { Text("Play Video!") } }.tag("description") }.modifier(GestureModifier()).environmentObject(viewModel) } } SphereEntity: import Foundation import RealityKit import RealityKitContent class SphereEntity: Entity { private let sphere: ModelEntity @MainActor required init() { sphere = ModelEntity() super.init() } init(radius: Float, materials: [Material], name: String) { sphere = ModelEntity(mesh: .generateSphere(radius: radius), materials: materials) sphere.generateCollisionShapes(recursive: false) sphere.components.set(InputTargetComponent()) sphere.components.set(HoverEffectComponent()) sphere.components.set(CollisionComponent(shapes: [.generateSphere(radius: radius)])) sphere.name = name super.init() self.addChild(sphere) self.position = .zero // .init(x: Float, y: Float, z: Float) and [Float, Float, Float] doesn't work ... } }
Posted Last updated
.
Post not yet marked as solved
2 Replies
546 Views
Hello, Yesterday I updated xCode 15.2 Beta to 15.5. Now i tried to run my App but after starting i I recognized that when I open my volumetric window that the USDA scene in my RealityView doesn't file doesn't appear anymore. RealityView will be executed.+ When I use a 3D Model in my volumetric window the USDA appears without any problems. Here is my code: // // // // Created by Patrick Schnitzer on 30.07.23. // import SwiftUI import RealityKit import RealityKitContent struct MyWindow: View { var body: some View { RealityView { content in async let object = ModelEntity(named: "testScene", in: realityKitContentBundle) print("I exec") guard let object1 = try? await cloudyWeather else {return } object1.generateCollisionShapes(recursive: false) object1.components.set(InputTargetComponent()) object1.location = .init(0,0.5,0) object1.scale *= 1 content.add(object1) }.gesture(dragGesture) } var dragGesture: some Gesture { DragGesture() .targetedToAnyEntity() .onChanged { value in print(value.entity.name) value.entity.position = value.convert(value.location3D, from: .local, to: value.entity.parent!) } } } #Preview { MyWindow() }
Posted Last updated
.
Post marked as solved
4 Replies
1.7k Views
Hello, Right now I am learning some RealityKit for VisionOS. I do not receive any errors in my code so it seems okay. But I can't drag my object around. Does the SIM supports gestures in general? // // ImmersiveView.swift // NewDimensionn // // Created by Patrick Schnitzer on 18.07.23. // import SwiftUI import RealityKit import RealityKitContent struct ImmersiveView: View { var earth: Entity = Entity() var moon: Entity = Entity() var body: some View { RealityView { content in async let earth = ModelEntity(named: "EarthScene", in: realityKitContentBundle) async let moon = ModelEntity(named: "MoonScene", in: realityKitContentBundle) if let earth = try? await earth, let moon = try? await moon { content.add(earth) content.add(moon) } } .gesture(DragGesture() .targetedToEntity(earth) .onChanged{ value in earth.position = value.convert(value.location3D, from: .local, to: earth.parent!) } ) } } #Preview { ImmersiveView() .previewLayout(.sizeThatFits) }```
Posted Last updated
.