Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Chronicler · Sep 12, 2016 at 04:38 AM · voxeluv mappingdynamic mesh

How to calculate UVs for a mesh created in runtime based on Vertex position

So I'm creating a 3d first person shooter game based on an older 2d game called Liero. The central element to the game is that both players are underground, and must blast their way through dirt to reach each other.

I've achieved this effect through the use of voxels, but I'm stumped as to how to shade them. I've looked up a lot of different techniques for mapping uvs, such as Tri-planar, but either I haven't understood them or they haven't worked (maybe both).

Currently in my implementation I calculate out the vertices for my mesh and then assign some UV value to that vertice which sticks with it. Note that I don't neccesarily have 3 vertices per triangle, as multiple triangles may share a single vertice (and be facing different directions).

I don't need it to be super precise, and in fact I like the somewhat random look I get when the UVs aren't super precise. However, as can be seen in the screen shot, when I have certain angles I get a sort of stretched look which is very unnatural looking. I believe this is caused by the UVs of two vertices being identical or near identical. So my question is really thus. Is there some good way of converting 3d vertices into 2d uvs in a way that doesn't produce adjacent symmetries or stretch out the UV unnaturally?

Currently my code for calculating the UV (as seen in the picture) is:

  private Vector2 calculateUV(Vector3 position)
     {
         float greatest;
         float middle;
         float smallest;
         position = new Vector3 ((position.x)*15f/17f+ voxelRadius/7f*5f, (position.y)*13f/17f + voxelRadius/7f*3f, (position.z)*11f/17f + voxelRadius/7f);
         if (position.x > position.y) {
             if (position.x > position.z) {
                 greatest = position.x;
                 if (position.y > position.z) {
                     middle = position.y;
                     smallest = position.z;
                 } else {
                     middle = position.z;
                     smallest = position.y;
                 }
             } else {
                 greatest = position.z;
                 middle = position.x;
                 smallest = position.y;
             }
         } else if (position.x > position.z) {
             greatest = position.y;
             middle = position.x;
             smallest = position.z;
         } else {
             if (position.y > position.z) {
                 greatest = position.y;
                 middle = position.z;
                 smallest = position.x;
             } else {
                 greatest = position.z;
                 middle = position.y;
                 smallest = position.x;
             }
         }
         return new Vector2 (greatest/25+smallest/25, middle/25+smallest/25);
     }

Yes, the code is pretty random, and was made up on the fly in order to try and remove as much stretching as possible (and it has some) Thanks in advance!!

[1]: /storage/temp/78055-dirt.png

dirt.png (398.5 kB)
Comment
Add comment · Show 1
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 Chronicler · Sep 14, 2016 at 03:05 AM 0
Share

Update: I've played with my code a bit and have discovered two potential solutions. One produces a good mapping except at the "seams" as I've labeled them (see picture) and the other also produces a good mapping but is stretched out quite badly. I'm still interested if anyone has better solutions. return new Vector2((position.x%25)(3/5)/25+(position.y%25)(2/5)/25,(position.z%25)(3/5)/25+(position.y%25)(2/25)/25); And the second code return new Vector2((position.x%200)*5/(200*9)+(position.y%200)*4/(200*9),(position.z%200)*5/(200*9)+(position.y%200)*4/(200*9)); 200 is the width (and height and depth) of my arena. !alt text

boundarysmallfile.png (402.2 kB)
stretchedcontinoussmallfile.png (237.9 kB)

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How can i achieve texturing of a dynamic generated Hex? 0 Answers

Merging faces without effecting texture mapping 2 Answers

Changing Texture of one side of cube when raycast is colliding with it. 1 Answer

How do I assign different parts of model to different materials during runtime? 1 Answer

Voxel terrain wont appear 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