After adding TextComponents to my Entities on visionOS, I have observed that visualBounds will ignore the TextComponents.
Documentation states that it should render a rounded rectangle mesh. These mashes are visible on the device, but not visible in the debugger ("Capture Entity Hierarchy") and ignored by visualBounds.
Am I missing something?
static func makeDirection(_ direction: Direction) -> Entity {
let text = Entity()
text.name = direction.rawValue
text.setScale(SIMD3(repeating: 5), relativeTo: nil)
text.transform.rotation = direction.rotation
text.components.set(direction.textComponent)
return text
}
My workaround is to add a disabled ModelEntity and take its bounds 😬
Hey @RK123,
In terms of the visualBounds not including the bounds of the TextComponent, I'd greatly appreciate it if you could open a bug report, include as much information about your use case as possible, and post the FB number here once you do. Bug Reporting: How and Why? has tips on creating your bug report.
If you wanted to visualize the size of the TextComponent canvas, that is possible using physicalMetrics and pixelLength environment values:
@Environment(\.physicalMetrics) var physicalMetrics
@Environment(\.pixelLength) var pixelLength
Using the provided canvas size of the text component, you can convert this into meters and then adjust it by any scale that is applied to it's parent entity and the pixelLength:
entity.components.set(textComponent)
let scale = entity.scale(relativeTo: nil)
let modelEntity = ModelEntity(
mesh: .generateBox(
width: physicalMetrics.convert(Float(textComponent.size.width), to: .meters) * scale.x * Float(pixelLength),
height: physicalMetrics.convert(Float(textComponent.size.height), to: .meters) * scale.y * Float(pixelLength),
depth: 0.1
),
materials: [SimpleMaterial(color: .red, isMetallic: false)]
)
content.add(modelEntity)
modelEntity.components.set(OpacityComponent(opacity: 0.0))
Let me know if this helps,
Michael