Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 borispavlov0 · May 28, 2015 at 08:05 PM · unity 5texturemeshspriteprocedural mesh

Unity distort a sprite to match a mesh

I am relatively new to Unity, so I am not sure how to do things with graphics very much. I have generated a procedural mesh along a spline. It's a race track where each piece is made of two triangles

alt text

Because of the nature of the track, the piece sides are deformed based on the angle of the next vector in the path like so:

alt text

When I apply the piece texture it gets applied straight, as it is meant for my first example. However, I would like to have the sprite curved with respect to the sides of my mesh piece, so that the transition of graphics between the pieces is not chopped.

Is that something that is possible?

Feel free to ask me more questions in case I didn't explain it well.

Thanks!

example-1.png (3.0 kB)
example-2.png (3.8 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

2 Replies

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

Answer by Eno-Khaon · May 28, 2015 at 08:23 PM

As far as realtime 3D rendering is generally concerned, anything being displayed only makes sense as triangles. With this in mind, the way your ground is constructed is at risk. Some easy ways of mitigating this are to either add more vertices/triangles/faces to the segments (which would reduce the distortion, but not eliminate it) or modify the uv coordinates to resemble the distorted shape of the mesh (which eliminates simple texture tiling).

As an example, if the uv coordinates are shifted, though, the texture could instead come in the form of a projection (i.e. texture coordinates are based on worldspace position rather than texture coordinates on the object), but making it look reasonable is still very limited.

Comment
Add comment · Show 1 · 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 borispavlov0 · May 28, 2015 at 08:30 PM 0
Share

Thanks!

I will try playing with adding a bit more triangles in each piece. The problem is not really critical at this stage but you can totally see choppiness in the track pieces as they slide out behind the car and into the camera. I was just wondering if there is an obvious way to do this skewing of the texture. I will mark your answer as correct since I will most likely end up using your suggestions.

avatar image
0
Wiki

Answer by hu90 · May 28, 2015 at 08:40 PM

A mesh contains, along with the vertices and triangles, an array of uvs. See http://docs.unity3d.com/ScriptReference/Mesh-uv.html .

The uv array consists of uv coordinates, that I'll call uvs for convenience.

  • A uv tells to what point on the texture a vertex is attached. That's why its type is Vector2. Vector2.zero is the bottom-left point on the texture, and Vector2.one is the top-right point. It typically loops so that between Vector(0, 0) and Vector3(2, 0) the texture will repeat twice on x.

  • Each uv is associated with a vertex. This association is one-to-one. myMesh.uv [n] is associated with ``myMesh.vertices [n]``. It follows that Mesh.uv should always have the same length as Mesh.vertices.

So where on the texture each vertex is attached is all the graphic cards needs to know to work out what each triagle contains. You need to write to Mesh.uv to override the default "flat" texture-mapping.

EDIT: The image will be interpolated in the most simple way possible. This means that your two-triangle example might not look very good. Solution: more triangles (so more vertices and more uvs).

Comment
Add comment · Show 1 · 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 borispavlov0 · May 28, 2015 at 08:47 PM 0
Share

I will definitely try this! I accepted the other answer earlier since it was something I was more familiar with and it seems to do the job to a certain extent. $$anonymous$$aybe this will work better. I will try both. Thanks for the help!

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

Patch on a sphere of varying size 0 Answers

multiple textures on one mesh + different Albedos 1 Answer

Procedual quad doesnt display texture - only single color 1 Answer

How to scroll a region of texture (which is an atlas) on a mesh (which is a sprite) 2 Answers

Converting 2d sprite to mesh - looking better algorithm 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