Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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
0
Question by Turboloser · Jul 06, 2017 at 04:52 PM · texturevector3uvvector2

Calculate UV-coordinates based on known vertices and their respective UVs

A (probably simple) question, but after hours of thinking, i barely can wrap my mind around it anymore. Short: i am stuck.

Background: i am developing a small feature to cut one mesh into two new meshes at runtime, using a customizable plane. This works well so far. Method is: create two copys of the original mesh and "collapse" the vertices, which are on the off-side of the plane relative to the new meshes side, onto the plane. The method is not part of the question, its just background information. For this method to look nice and clean, i have to recalculate some UV-coodrinates in the cut-process and thats were things get tricky.

Consider the following: I have a minimalistic mesh, containing 3 Vector3s A, B and C, forming a single triangle in 3D-space (see image below). Their respective world- and UV-coordinates are known. A 4. Vector3 D is calculated at runtime, its coordinates (world coordinates, as well as distance to A, B and C) are known. This new Vector3 D is guaranteed to be on the plane, which is spun up by A, B and C. The only thing unknown is the UV-coordinates of D, which have to be relative to the distance of D to A, B and C.

Question: How do I calculate the UV-coordinates of D (relative to A, B and C) using the Positions of A, B, C and D, UV-Coordinates of A, B and C and the Distances AD, BD and CD?

alt text

alt text

vertices.png (9.3 kB)
texture.png (122.5 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Bunny83 · Jul 06, 2017 at 05:45 PM

You can use my Barycentric struct(download). Just pass in the 3 vertex positions and the point inside the triangle. Then you can use Interpolate to interpolate the UV coordinates based on the barycentric coordinates:

 var b = new Barycentric(A, B, C, D);
 Vector2 uv_D = b.Interpolate(uv_A, uv_B, uv_C);

You can use the barycentric coordinates to interpolate any vertex attribute.

edit
I forgot that i also added that script to the unity wiki. In case the DB link above doesn't work anymore, see here on the wiki (Barycentric)

Comment
Add comment · Show 2 · 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 Turboloser · Jul 07, 2017 at 09:56 AM 0
Share

Used your code and tested it. Works like a charm! UV-coordinates of D are calculated perfectly using your snippet. Fast, understandable and easy-to-use answer. $$anonymous$$any thanks!

$$anonymous$$aybe you could also add the Barycentric-code as part of your answer, so the post becomes more persistent (since Dropbox-links tend to get lost over the years, whenever the free dropbox-space becomes critical).

avatar image Bunny83 Turboloser · Jul 08, 2017 at 03:14 PM 0
Share

Yes, I just realised that i already added the script to the wiki (Dec. 2015). I added the wiki link to my answer.

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

97 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Assigning UV Map to model at runtime 0 Answers

unity Vector2 problem 1 Answer

Procedural Uniform UVs On a Plane 2 Answers

greater or less than with vector coordinates 0 Answers

How to scale a texture in a shader without tiling? 1 Answer


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