Hello Everyone,
I'm currently facing a challenge related to detecting taps on an entity that features video material.
Based on the information I found online, it appears that in order to enable touch functionality, the recommended approach is to clone the entity and add an InputTargetComponent while also enabling collision shapes.
Here's a snippet of my code:
RealityView { content, attachments in
// The following code doesn't trigger the tapGesture
let videoEntity = ImmersivePlayerEntity(configuration: configuration)
content.add(videoEntity)
//
if let attachment = attachments.entity(for: "player-controls") {
anchorEntity.addChild(attachment)
content.add(anchorEntity)
}
/* This code triggers the tapGesture
let boxResource = MeshResource.generateBox(size: 2)
let itemMaterial = SimpleMaterial(color: .red, roughness: 0, isMetallic: false)
let entity = ModelEntity(mesh: boxResource, materials: [itemMaterial]).addTappable()
content.add(entity)
*/
}
update: { _, _ in
}
attachments: {
Attachment(id: "player-controls") {
ImmersivePlayerControlsView(coordinator: coordinator)
.frame(width: 1280)
.opacity(areControlsVisible ? 1 : 0)
.animation(.easeInOut, value: areControlsVisible)
}
}
.gesture(
SpatialTapGesture()
.targetedToAnyEntity()
.onEnded { value in
areControlsVisible.toggle()
}
)
extension Entity
{
func addTappable() -> Entity {
let newModelEntity = self.clone(recursive: true)
newModelEntity.components.set(InputTargetComponent())
newModelEntity.generateCollisionShapes(recursive: true)
return newModelEntity
}
}
I'm seeking guidance and assistance on how to enable touch functionality on the video entity. Your insights and suggestions would be greatly appreciated. Thank you in advance for your help!
Post
Replies
Boosts
Views
Activity
Hello Everyone,
I'm facing a challenge related to resizing an entity built from a 3D model.
Although I can manipulate the size of the mesh, the entity's overall dimensions seem to remain static and unchangeable.
Here's a snippet of my code:
let giftEntity = try await Entity(named: "gift")
I've come across an operator that allows for scaling the entity. However, I'm uncertain about the appropriate value to employ, especially since the realityView is encapsulated within an HStack, which is further nested inside a ScrollView.
Would anyone have experience or guidance on this matter? Any recommendations or resources would be invaluable.
Thank you in advance for your assistance!
I'm looking for a method or notification to detect window resizing. While I found didResizeNotification for macOS, it's not available in visionPro
Hi,
I've been working on a spatial image design, guided by this Apple developer video:
https://developer.apple.com/videos/play/wwdc2023/10081?time=792.
I've hit a challenge: I'm trying to position a label to the left of the portal. Although I've used an attachment for the label within the content, pinpointing the exact starting position of the portal to align the label is proving challenging.
Any insights or suggestions would be appreciated.
Below is the URL of the image used:
https://cdn.polyhaven.com/asset_img/primary/rural_asphalt_road.png?height=780
struct PortalView: View {
let radius = Float(0.3)
var world = Entity()
var portal = Entity()
init() {
world = makeWorld()
portal = makePortal(world: world)
}
var body: some View {
RealityView { content, attachments in
content.add(world)
content.add(portal)
if let attachment = attachments.entity(for: 0) {
portal.addChild(attachment)
attachment.position.x = -radius/2.0
attachment.position.y = radius/2.0
}
} attachments: {
Attachment(id: 0) {
Text("Title")
.background(Color.red)
}
}
}
func makeWorld() -> Entity {
let world = Entity()
world.components[WorldComponent.self] = .init()
let imageEntity = Entity()
var material = UnlitMaterial()
let texture = try! TextureResource.load(named: "road")
material.color = .init(texture: .init(texture))
imageEntity.components.set(
ModelComponent(mesh: .generateSphere(radius: radius), materials: [material])
)
imageEntity.position = .zero
imageEntity.scale = .init(x: -1, y: 1, z: 1)
world.addChild(imageEntity)
return world
}
func makePortal(world: Entity) -> Entity {
let portal = Entity()
let portalMaterial = PortalMaterial()
let planeMesh = MeshResource.generatePlane(width: radius, height: radius, cornerRadius: 0)
portal.components[ModelComponent.self] = .init(mesh: planeMesh, materials: [portalMaterial])
portal.components[PortalComponent.self] = .init(
target: world
)
return portal
}
}
#Preview {
PortalView()
}