0
\$\begingroup\$

I'm rendering a 3D object to texture (2048x1600) and show this texture on a panel (1600x285) using a RawImage (2048x1600) 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?

\$\endgroup\$
  • \$\begingroup\$ This looks similar to this question from yesterday - any relation? \$\endgroup\$ – DMGregory Nov 10 '17 at 12:58
  • \$\begingroup\$ You are right, this is similar. Sorry I've overseen this question. Relating to your comment in the other thread, I want to get the corresponding local position of the 3d mountpoint position on the texture (panel). \$\endgroup\$ – Hellhound Nov 10 '17 at 13:15
  • \$\begingroup\$ A few more hours on it, more doubts, but absolutely no clue yet on how to solve it. I am going nuts ... \$\endgroup\$ – Hellhound Nov 13 '17 at 13:21
  • \$\begingroup\$ If you want to bump your question to attract more attention, commenting alone won't do it. If you edit the post though — say adding an image of your scene setup & inspector properties for the RawImage and its Canvas — that both gives users more information to go on and pushes your question back onto the front page. \$\endgroup\$ – DMGregory Nov 13 '17 at 13:50
1
\$\begingroup\$

I could solve this problem by using a WorldSpace-Canvas for each mountpoint. Each mountpoint sprite is rendered as billboard facing towards the camera. To render any sprite on top I've overwritten the default UI shader as described by this link.

Weapon mountpoints

The only thing I dislike is that I've now mixed a 2D UI with some 3D UI elements placed somewhere in the hierarchy at the objects.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.