Post

Replies

Boosts

Views

Activity

RealityKit: Scale generalText based on distance from Anchor
I would like to make text change size as I move towards/away from the image anchor I created. as I move towards the image, the text gets smaller as I move away from the image, the gets bigger My current function to create the text is below: func addTitleToAnchor(text:String, color:SimpleMaterial.Color, isMetallic:Bool, anchor: AnchorEntity, height: Float) {   let mesh = MeshResource.generateText(         text,         extrusionDepth: 0.02,         font: .init(descriptor: .init(name: "Helvetica", size: 1), size: 1),         containerFrame: .zero,         alignment: .center,         lineBreakMode: .byWordWrapping)   let material = SimpleMaterial(color: color, isMetallic: isMetallic)   let entity = ModelEntity(mesh: mesh, materials: [material])   entity.name = "title"   entity.setScale(SIMD3<Float>(0.015 ,0.015,0.015), relativeTo: anchor)   anchor.addChild(entity)   entity.setPosition(SIMD3<Float>(-0.05, 0.03, -height), relativeTo: anchor)   entity.transform.rotation = simd_quatf(angle: -.pi/2, axis: [1,0,0])   return }
2
0
1.9k
May ’21
RealityKit: Scale generalText based on distance from Anchor
I would like to make text change size as I move towards/away from the image anchor I created. as I move towards the image, the text gets smaller as I move away from the image, the gets bigger My current function to create the text is below: func addTitleToAnchor(text:String, color:SimpleMaterial.Color, isMetallic:Bool, anchor: AnchorEntity, height: Float) {   let mesh = MeshResource.generateText(         text,         extrusionDepth: 0.02,         font: .init(descriptor: .init(name: "Helvetica", size: 1), size: 1),         containerFrame: .zero,         alignment: .center,         lineBreakMode: .byWordWrapping)   let material = SimpleMaterial(color: color, isMetallic: isMetallic)   let entity = ModelEntity(mesh: mesh, materials: [material])   entity.name = "title"   entity.setScale(SIMD3<Float>(0.015 ,0.015,0.015), relativeTo: anchor)   anchor.addChild(entity)   entity.setPosition(SIMD3<Float>(-0.05, 0.03, -height), relativeTo: anchor)   entity.transform.rotation = simd_quatf(angle: -.pi/2, axis: [1,0,0])   return }
Replies
2
Boosts
0
Views
1.9k
Activity
May ’21