Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by mbougaa · May 20, 2013 at 09:58 AM · camera-movementworldtoscreenpointprojection-matrixcamera.screentoworld

How to get the 2d Poisition (in camera) of the mesh vertices

Hi

I have to take 4 screenshots of a 3d object (diffrent point of view) using 04 fixed unity camera in the scene. i did this and i can save the pictures as png.

the problem is that, i want for each vertex in the mesh (my character object) to have the exact 2d position in each picture.

any solution please?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by PedramAUS · May 20, 2013 at 10:03 AM

From each camera you should calculate the projection of the point on the screen using Camera.WorldToScreenPoint.

For intance:

 Vector3 ProjectFromCam1 = Camera1.WorldToScreenPoint(target.position);
 Vector3 ProjectFromCam2 = Camera2.WorldToScreenPoint(target.position);
 Vector3 ProjectFromCam3 = Camera3.WorldToScreenPoint(target.position);
 Vector3 ProjectFromCam4 = Camera4.WorldToScreenPoint(target.position);


Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Bunny83 · May 20, 2013 at 10:09 AM

After reading your question for the 5th time i guess all you want is:

  • Transform.TransformPoint for converting the vertex positions into world space

  • Camera.WorldToScreenPoint for projecting the world space positions into screenspace.

So a script like this should do what you want:

 // C#
 using UnityEngine;
 using System.Collections;
 
 public class MeshVertexPositions : MonoBehaviour
 {
     public Vector2[] Calculate2DPositions(Camera aCam)
     {
         Mesh m = null;
         var MF = Getcomponent<MeshFilter>();
         if (MF != null)
             m = MF.sharedMesh;
         var SMR = GetComponent<SkinnedMeshRenderer>():
         if (SMR != null) 
             m = SMR.sharedMesh;
         if (m == null)
             return null;
         Transform obj = transform;
         Vector3[] verts = m.vertices;
         Vector2[] result = new Vector2[verts.Length];
         for(int i = 0; i < verts.Length; +ii)
         {
             result[i] = aCam.WorldToScreenPoint(obj.TransformPoint(verts[i]));
         }
         return result;
     }
 }

If your character is made up of several meshes you have to do this for everyone.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by mbougaa · May 20, 2013 at 11:07 AM

Thanks for your replay and sorry for not being clear a lot, i'll try to be more clear - My object is a 3d human body - Suppose that i use only one camera (positionned in the scene to get the frontal picture) - I want to have the exact 2d positions (pixels) in this image that matches with the object vertices (to simplify, i say the 2d projection of all vertices in the screenshot). - i use the main camera with the default view (perspective) - i tried to use WorldToScreenPoint an print the 2d position i get on the picture, but the problem is that it dont give me the projection i wanted - the camera gives me this screenshot (picture1) - and when i print the vertices projection that i get like that Vector3 screenpose = Camera.main.WorldToScreenPoint(vertices[l])
it gives me the (picture2) - as you can see the 2d projection are not in the correct place thanks in advance


picture1.png (45.8 kB)
picture2.jpg (25.7 kB)
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

WorldToViewportPoint and ViewportToWorldPoint math 2 Answers

fluent animation from orthographic to perspective projection 2 Answers

Zoom to center of Pinch Gesture 1 Answer

Modified Mobile TapControl.js logic flow works, but No Apparent Cam Zoom/Rotate Response 1 Answer

Isometric game camera limits 4 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges