I’m rendering a 3D object to texture (2048×1600) and show this texture on a panel (1600×285) using a RawImage (2048×1600) component as child. This texture is rendered successfully on screen.
This 3d object contains several mountpoints as empty objects. Now I want to show several sprites to visualize those mountpoints on the texture (panel) at their corresponding screen position (must not pixel perfect).
I tried several camera transforms, but could not get the correct position values:
var main = camera.WorldToScreenPoint(slot.mountpoint.position); Debug.Log("Maincam screenpos: " + main.ToString()); RectTransform rect = this.GetComponentInParent<RectTransform>(); Debug.Log("Rect size delta: " + rect.sizeDelta.ToString()); Vector2 viewPos = camera.WorldToViewportPoint(slot.mountpoint.position); Debug.Log("Viewport pos : " + viewPos.ToString()); Vector2 localPos = new Vector2(viewPos.x * rect.sizeDelta.x, viewPos.y * rect.sizeDelta.y); Debug.Log("Viewport pos local : " + localPos.ToString());
How I could realize this?